From 366ff7c78a30598b2e41fc87d6682566bc81c6e9 Mon Sep 17 00:00:00 2001 From: Bryan Cerrati Date: Wed, 12 Mar 2025 14:02:54 -0400 Subject: [PATCH] MGMT --- app/models.py | 36 +++++---- app/routes/clients.py | 4 + app/templates/client_detail.html | 36 ++++++++- app/templates/client_detail_print.html | 107 ++++++++++++++----------- app/templates/domains.html | 2 - app/templates/ssl.html | 4 +- 6 files changed, 118 insertions(+), 71 deletions(-) diff --git a/app/models.py b/app/models.py index 29650a5..7df81b5 100644 --- a/app/models.py +++ b/app/models.py @@ -1,6 +1,16 @@ from app import db -# Existing models… + +client_domains = db.Table('client_domains', + db.Column('client_id', db.Integer, db.ForeignKey('client.id', ondelete="CASCADE")), + db.Column('domain_id', db.Integer, db.ForeignKey('domain.id')) +) + +client_ssl = db.Table('client_ssl', + db.Column('client_id', db.Integer, db.ForeignKey('client.id', ondelete="CASCADE")), + db.Column('domain_id', db.Integer, db.ForeignKey('domain.id')) +) + class Domain(db.Model): __tablename__ = 'domain' __table_args__ = {'extend_existing': True} @@ -18,18 +28,21 @@ class Client(db.Model): name = db.Column(db.String(255), nullable=False) phone = db.Column(db.String(255)) address = db.Column(db.String(255)) + ip_address = db.Column(db.String(255)) + subnet_mask = db.Column(db.String(255)) + gateway = db.Column(db.String(255)) passwords = db.relationship('ClientPassword', backref='client', lazy=True, - cascade="all, delete-orphan") - domains = db.relationship('Domain', secondary='client_domains', + cascade="all, delete-orphan") + domains = db.relationship('Domain', secondary=client_domains, backref=db.backref('clients', lazy='dynamic')) - ssl_domains = db.relationship('Domain', secondary='client_ssl', + ssl_domains = db.relationship('Domain', secondary=client_ssl, backref=db.backref('ssl_clients', lazy='dynamic')) - # New relationship for remotes remotes = db.relationship('ClientRemote', backref='client', lazy=True, cascade="all, delete-orphan") def __repr__(self): return f"" + class ClientPassword(db.Model): __tablename__ = 'client_password' id = db.Column(db.Integer, primary_key=True) @@ -74,15 +87,4 @@ class ClientRemote(db.Model): details = db.Column(db.String(255)) remote_category = db.relationship('RemoteCategory') def __repr__(self): - return f"" - -# Association tables for domains remain unchanged. -client_domains = db.Table('client_domains', - db.Column('client_id', db.Integer, db.ForeignKey('client.id', ondelete="CASCADE")), - db.Column('domain_id', db.Integer, db.ForeignKey('domain.id')) -) - -client_ssl = db.Table('client_ssl', - db.Column('client_id', db.Integer, db.ForeignKey('client.id', ondelete="CASCADE")), - db.Column('domain_id', db.Integer, db.ForeignKey('domain.id')) -) + return f"" \ No newline at end of file diff --git a/app/routes/clients.py b/app/routes/clients.py index 326bbd1..71cc1be 100644 --- a/app/routes/clients.py +++ b/app/routes/clients.py @@ -56,9 +56,13 @@ def update_client_details(client_id): client = Client.query.get_or_404(client_id) client.phone = request.form.get('phone') client.address = request.form.get('address') + client.ip_address = request.form.get('ip_address') + client.subnet_mask = request.form.get('subnet_mask') + client.gateway = request.form.get('gateway') db.session.commit() return redirect(url_for('clients.client_detail', client_id=client.id)) + @clients_bp.route('/clients//add_password', methods=['POST']) def add_client_password(client_id): client = Client.query.get_or_404(client_id) diff --git a/app/templates/client_detail.html b/app/templates/client_detail.html index aee1cb2..d419f2a 100644 --- a/app/templates/client_detail.html +++ b/app/templates/client_detail.html @@ -7,10 +7,25 @@
-
- {% if client.phone or client.address %} -

Phone: {{ client.phone or "N/A" }} | Address: {{ client.address or "N/A" }}

- {% else %} +
+
    + {% if client.phone %} +
  • Phone: {{ client.phone }}
  • + {% endif %} + {% if client.address %} +
  • Address: {{ client.address }}
  • + {% endif %} + {% if client.ip_address %} +
  • IP Address: {{ client.ip_address }}
  • + {% endif %} + {% if client.subnet_mask %} +
  • Subnet Mask: {{ client.subnet_mask }}
  • + {% endif %} + {% if client.gateway %} +
  • Gateway: {{ client.gateway }}
  • + {% endif %} +
+ {% if client.phone is none and client.address is none and client.ip_address is none and client.subnet_mask is none and client.gateway is none %}

No details available.

{% endif %}
+
+ + +
+
+ + +
+
+ + +
+
diff --git a/app/templates/client_detail_print.html b/app/templates/client_detail_print.html index 1626c1c..bc81e5b 100644 --- a/app/templates/client_detail_print.html +++ b/app/templates/client_detail_print.html @@ -5,17 +5,35 @@

{{ client.name }}

- +
-

Details

-

Phone: {{ client.phone or "N/A" }} | Address: {{ client.address or "N/A" }}

+
    + {% if client.phone %} +
  • Phone: {{ client.phone }}
  • + {% endif %} + {% if client.address %} +
  • Address: {{ client.address }}
  • + {% endif %} + {% if client.ip_address %} +
  • IP Address: {{ client.ip_address }}
  • + {% endif %} + {% if client.subnet_mask %} +
  • Subnet Mask: {{ client.subnet_mask }}
  • + {% endif %} + {% if client.gateway %} +
  • Gateway: {{ client.gateway }}
  • + {% endif %} +
+ {% if client.phone is none and client.address is none and client.ip_address is none and client.subnet_mask is none and client.gateway is none %} +

No details available.

+ {% endif %}
- +
- +

Remote

@@ -53,33 +71,33 @@ {% for remote in remotes %} - - {% if category == 'RDP' %} - {{ remote.name }} - {{ remote.ip_address }} - {{ remote.port }} - {% elif category == 'SSL-VPN' %} - {{ remote.ip_address }} - {{ remote.port }} - {% elif category == 'VPN' %} - {{ remote.ip_address }} - {{ remote.psk }} - {% elif category == 'MGMT' %} - {{ remote.name }} - {{ remote.address }} - {% else %} - {{ remote.details }} - {% endif %} - + + {% if category == 'RDP' %} + {{ remote.name }} + {{ remote.ip_address }} + {{ remote.port }} + {% elif category == 'SSL-VPN' %} + {{ remote.ip_address }} + {{ remote.port }} + {% elif category == 'VPN' %} + {{ remote.ip_address }} + {{ remote.psk }} + {% elif category == 'MGMT' %} + {{ remote.name }} + {{ remote.address }} + {% else %} + {{ remote.details }} + {% endif %} + {% endfor %} {% endif %} {% endfor %}
- +
- +

Passwords

@@ -92,24 +110,26 @@ Item Username Password + IP Address {% for p in passwords %} - - {{ p.item }} - {{ p.username }} - {{ p.password }} - + + {{ p.item }} + {{ p.username }} + {{ p.password }} + {{ p.ip_address }} + {% endfor %} {% endif %} {% endfor %}
- +
- +

Domains

@@ -123,10 +143,10 @@ {% for d in client.domains %} - - {{ d.domain }} - {{ d.expiration_date }} - + + {{ d.domain }} + {{ d.expiration_date }} + {% endfor %} @@ -134,9 +154,9 @@

No domain associations.

{% endif %}
- +
- +

SSL

@@ -150,10 +170,10 @@ {% for d in client.ssl_domains %} - - {{ d.domain }} - {{ d.ssl_expiration_date }} - + + {{ d.domain }} + {{ d.ssl_expiration_date }} + {% endfor %} @@ -161,8 +181,5 @@

No SSL associations.

{% endif %}
- - - {% endblock %} diff --git a/app/templates/domains.html b/app/templates/domains.html index eceefee..425eb4e 100644 --- a/app/templates/domains.html +++ b/app/templates/domains.html @@ -11,7 +11,6 @@ Domain WHOIS Expiration - SSL Expiration Refresh Action @@ -21,7 +20,6 @@ {{ domain.domain }} {{ domain.expiration_date }} - {{ domain.ssl_expiration_date }} Refresh diff --git a/app/templates/ssl.html b/app/templates/ssl.html index 8a7ddf0..46c1557 100644 --- a/app/templates/ssl.html +++ b/app/templates/ssl.html @@ -10,7 +10,6 @@ Domain - WHOIS Expiration SSL Expiration Type Refresh @@ -21,11 +20,10 @@ {% for d in domains %} {{ d.domain }} - {{ d.expiration_date }} {{ d.ssl_expiration_date }} {% if d.ssl_only %} - Email + App Cert {% else %} Domain {% endif %}