From b465bd9c5443ac1d1593cb039e3daeb53ab41225 Mon Sep 17 00:00:00 2001 From: Tim Eertmoed Date: Mon, 29 Sep 2025 17:54:03 +0000 Subject: [PATCH 001/144] Devices is_active + Table --- srv/poe_manager/app.py | 22 +++++-- srv/poe_manager/generate_ips.py | 12 +++- srv/poe_manager/sqlite.db | Bin 40960 -> 40960 bytes srv/poe_manager/static/css/style.css | 49 +++++++++++++++- srv/poe_manager/templates/devices.html | 77 +++++++++++++++---------- 5 files changed, 119 insertions(+), 41 deletions(-) diff --git a/srv/poe_manager/app.py b/srv/poe_manager/app.py index d694755..3b867d9 100644 --- a/srv/poe_manager/app.py +++ b/srv/poe_manager/app.py @@ -47,7 +47,7 @@ def get_devices(): Liefert eine Liste aller Devices aus der Datenbank als Dictionaries. """ conn = get_db_connection() - devices = conn.execute("SELECT mac, rpi_ip, port, name, switch_hostname FROM devices").fetchall() + devices = conn.execute("SELECT mac, rpi_ip, port, name, switch_hostname, is_active FROM devices").fetchall() conn.close() return devices @@ -150,14 +150,19 @@ def devices(): if not current_user.is_admin: flash("Zugriff verweigert!") return redirect(url_for('devices')) + mac = request.form['mac'] rpi_ip = request.form['rpi_ip'] port = request.form['port'] name = request.form['name'] switch_hostname = request.form['switch_hostname'] + is_active = 1 if 'is_active' in request.form else 0 + try: - conn.execute("INSERT INTO devices (mac, rpi_ip, port, name, switch_hostname) VALUES (?, ?, ?, ?, ?)", - (mac, rpi_ip, port, name, switch_hostname)) + conn.execute(""" + INSERT INTO devices (mac, rpi_ip, port, name, switch_hostname, is_active) + VALUES (?, ?, ?, ?, ?, ?) + """, (mac, rpi_ip, port, name, switch_hostname, is_active)) conn.commit() flash(f"Gerät {name} hinzugefügt.") except sqlite3.IntegrityError: @@ -168,18 +173,21 @@ def devices(): if not current_user.is_admin: flash("Zugriff verweigert!") return redirect(url_for('devices')) + old_mac = request.form['old_mac'] mac = request.form['mac'] rpi_ip = request.form['rpi_ip'] port = request.form['port'] name = request.form['name'] switch_hostname = request.form['switch_hostname'] + is_active = 1 if 'is_active' in request.form else 0 + try: conn.execute(""" UPDATE devices - SET mac=?, rpi_ip=?, port=?, name=?, switch_hostname=? + SET mac=?, rpi_ip=?, port=?, name=?, switch_hostname=?, is_active=? WHERE mac=? - """, (mac, rpi_ip, port, name, switch_hostname, old_mac)) + """, (mac, rpi_ip, port, name, switch_hostname, is_active, old_mac)) conn.commit() flash(f"Gerät {name} aktualisiert.") except sqlite3.IntegrityError: @@ -196,10 +204,12 @@ def devices(): flash(f"Gerät {del_mac} gelöscht.") devices = conn.execute(""" - SELECT devices.mac, devices.rpi_ip, devices.port, devices.name, switches.hostname AS switch_hostname + SELECT devices.mac, devices.rpi_ip, devices.port, devices.name, devices.is_active, + switches.hostname AS switch_hostname FROM devices JOIN switches ON devices.switch_hostname = switches.hostname """).fetchall() + conn.close() interval_min = get_interval_seconds() // 60 return render_template('devices.html', devices=devices, switches=switches) diff --git a/srv/poe_manager/generate_ips.py b/srv/poe_manager/generate_ips.py index 60ec98f..53409ec 100644 --- a/srv/poe_manager/generate_ips.py +++ b/srv/poe_manager/generate_ips.py @@ -11,8 +11,16 @@ def generate_ips_list(): # Alle Switches laden switches = {row['hostname']: row for row in conn.execute("SELECT hostname, ip, username, password FROM switches")} - # Alle Geräte laden - devices = conn.execute("SELECT mac, rpi_ip, port, name, switch_hostname FROM devices").fetchall() +# # Alle Geräte laden +# devices = conn.execute("SELECT mac, rpi_ip, port, name, switch_hostname FROM devices").fetchall() +# conn.close() + + # Nur aktive Geräte laden + devices = conn.execute(""" + SELECT mac, rpi_ip, port, name, switch_hostname + FROM devices + WHERE is_active=1 + """).fetchall() conn.close() tmp = tempfile.NamedTemporaryFile(delete=False, mode='w', prefix='ips_', suffix='.list') diff --git a/srv/poe_manager/sqlite.db b/srv/poe_manager/sqlite.db index 39a3341712ea868ef9b03e216448350840277fe5..5b2147921f4a5b977d07c48cd053abbff80d9e29 100644 GIT binary patch delta 277 zcmZoTz|?SnX@az%J_7>-7ZAe$>qH%6d3^@GvQA#!Zw#E=q73{>{KvUP`9AXs^Pc88 z$fM6QVPoTTF0LkVW_EFDX~q`TNqie+6f%qB6O&6a%Tg6Q{X$&bU4s-{T-_W)eL@rr zCU4+#-mK4aoRNk92gBcqjX&9RS=huKr6*tHmDnuE|3N{N?<@m5-(m*7#r)U!SMXQy z`|!*0eb_9h(96fE!N|_9ttcqYIr+Z5A`8%!$`c#qId#~9qN<`m(W`cU_WW&TbY|*v`kH&CbTJttu)$`KO&Khc+9Oqizr6 rutGVZAPx(Z(+uJ;Lpd9P9CaojM^R9G@_lDevices -{% with messages = get_flashed_messages() %} - {% if messages %} -
- {% for message in messages %}{{ message }}
{% endfor %} -
- {% endif %} -{% endwith %} - {% if current_user.is_admin %}

Neues Gerät hinzufügen

-
-
-
-
+
+
+
+
+
+ + +
{% endif %} - +
- - - + + + - + + {% if current_user.is_admin %}{% endif %} {% for d in devices %} - {% if current_user.is_admin %} - - - + + + + - - + + {% if current_user.is_admin %} + + {% endif %} - {% else %} - - - - - - {% endif %} {% endfor %}
HostnameIP-AdresseMAC-AdresseHostnameIP-AdresseMAC-Adresse SwitchPortPortAktivAktionen
+ + + + + + - {% for sw in switches %} - + + + + + + + {{ d['name'] }}{{ d['rpi_ip'] }}{{ d['mac'] }}{{ d['switch_hostname'] }}{{ d['port'] }}
+ + {% endblock %} -- 2.49.1 From a10343d37e58196a9f446ede6ad4ec847b9d3ff9 Mon Sep 17 00:00:00 2001 From: Tim Eertmoed Date: Mon, 29 Sep 2025 18:17:58 +0000 Subject: [PATCH 002/144] Devices is_active + Table --- srv/poe_manager/app.py | 3 +- srv/poe_manager/sqlite.db | Bin 40960 -> 40960 bytes srv/poe_manager/static/css/style.css | 9 ++-- srv/poe_manager/templates/index.html | 12 +++++- srv/poe_manager/templates/switche.html | 55 +++++++++++++++++-------- srv/poe_manager/templates/users.html | 14 +++---- 6 files changed, 62 insertions(+), 31 deletions(-) diff --git a/srv/poe_manager/app.py b/srv/poe_manager/app.py index 3b867d9..689a13d 100644 --- a/srv/poe_manager/app.py +++ b/srv/poe_manager/app.py @@ -86,7 +86,8 @@ def logout(): def index(): conn = sqlite3.connect("sqlite.db") c = conn.cursor() - c.execute("SELECT mac, name FROM devices") + # is_active mit abfragen + c.execute("SELECT mac, name, is_active FROM devices") devices = c.fetchall() conn.close() diff --git a/srv/poe_manager/sqlite.db b/srv/poe_manager/sqlite.db index 5b2147921f4a5b977d07c48cd053abbff80d9e29..e52fe2841b153a39d7eb7385837d6b321d5b5613 100644 GIT binary patch delta 26 icmZoTz|?SnX@WGP!9*EnMuUwBGwc{SHvhC^PXqvX$Oyy$ delta 26 icmZoTz|?SnX@WGP{zMsPM*WQmGwc{SH~+L_PXqvXu?WKe diff --git a/srv/poe_manager/static/css/style.css b/srv/poe_manager/static/css/style.css index 2ad9bdf..997de8a 100644 --- a/srv/poe_manager/static/css/style.css +++ b/srv/poe_manager/static/css/style.css @@ -117,13 +117,14 @@ pre { } .custom-table .col-ip { - width: 120px; /* IP-Adresse schmaler */ + width: 140px; /* IP-Adresse schmaler */ } .custom-table .col-mac { - width: 120px; /* MAC-Adresse schmaler */ + width: 140px; /* MAC-Adresse schmaler */ } + /* Checkbox sichtbar auch bei disabled */ .checkbox-visible:disabled { opacity: 1; /* nicht ausgegraut */ @@ -145,7 +146,7 @@ label.text-white { } .custom-actions { - gap: 0.5rem; /* horizontaler Abstand zwischen Buttons */ - margin: auto 0; + margin: auto 0; background: #fff; } + diff --git a/srv/poe_manager/templates/index.html b/srv/poe_manager/templates/index.html index 2e8f299..0ef9f3d 100644 --- a/srv/poe_manager/templates/index.html +++ b/srv/poe_manager/templates/index.html @@ -8,8 +8,16 @@
{{ d[1] }}
- - {% if status[d[0]] %}{{ status[d[0]]|capitalize }}{% else %}unbekannt{% endif %} + + {% if d[2] == 0 %} + Deaktiviert + {% else %} + {% if status[d[0]] %}{{ status[d[0]]|capitalize }}{% else %}Unbekannt{% endif %} + {% endif %}
diff --git a/srv/poe_manager/templates/switche.html b/srv/poe_manager/templates/switche.html index 6f106e9..a98ed81 100644 --- a/srv/poe_manager/templates/switche.html +++ b/srv/poe_manager/templates/switche.html @@ -7,20 +7,21 @@

Neuen Switch hinzufügen

-
-
-
+
+
+
{% endif %} - +
- - - + + + + {% if current_user.is_admin %}{% endif %} @@ -28,26 +29,46 @@ {% for s in switches %} {% if current_user.is_admin %} - - - - - - - + + + + - + + {% else %} + {% endif %} {% endfor %}
HostnameIP-AdresseUsernameHostnameIP-AdresseUsernamePasswordAktionen
- + + + + + + + + + + + + +
-
{{ s['hostname'] }} {{ s['ip'] }} {{ s['username'] }}******
+ + {% endblock %} diff --git a/srv/poe_manager/templates/users.html b/srv/poe_manager/templates/users.html index 339e0e2..12188cf 100644 --- a/srv/poe_manager/templates/users.html +++ b/srv/poe_manager/templates/users.html @@ -8,21 +8,21 @@ {% endif %} - +
- - + + {% if current_user.is_admin %}{% endif %} {% for u in users %} - - + + {% if current_user.is_admin %} -
UsernameRolleUsernameRolleAktionen
{{ u['username'] }}{% if u['is_admin'] %}Admin{% else %}User{% endif %}{{ u['username'] }}{% if u['is_admin'] %}Admin{% else %}User{% endif %} +
+ @@ -141,7 +141,7 @@ @@ -168,7 +168,7 @@ -- 2.49.1 From a24b09e18d4268370523069aad5c36c40f62c35b Mon Sep 17 00:00:00 2001 From: Tim Eertmoed Date: Tue, 7 Oct 2025 07:53:09 +0200 Subject: [PATCH 027/144] srv/poe_manager/templates/devices.html aktualisiert --- srv/poe_manager/templates/devices.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/srv/poe_manager/templates/devices.html b/srv/poe_manager/templates/devices.html index c60af95..bc474d1 100644 --- a/srv/poe_manager/templates/devices.html +++ b/srv/poe_manager/templates/devices.html @@ -95,7 +95,7 @@
- {% for sw in switches %} {% endfor %} @@ -161,7 +161,7 @@