diff --git a/srv/poe_manager/app.py b/srv/poe_manager/app.py index 54c1559..79d8e2a 100644 --- a/srv/poe_manager/app.py +++ b/srv/poe_manager/app.py @@ -221,9 +221,8 @@ def devices(): switch_hostname = request.form.get('switch_hostname') or None is_active = 1 if 'is_active' in request.form else 0 - # --- Prüfen, ob es sich um eine Switch-Änderung handelt --- + # --- Prüfen, ob nur der Switch geändert wurde --- if mac is None and rpi_ip is None and port is None and name is None and switch_hostname: - # Nur den Switch ändern device = conn.execute("SELECT name, switch_hostname FROM devices WHERE mac=?", (old_mac,)).fetchone() if not device: @@ -245,17 +244,18 @@ def devices(): flash("Fehler beim Ändern des Switch!") return redirect(url_for('devices')) + # --- Nur Pflichtfelder prüfen --- if not all([old_mac, mac, rpi_ip, name]): - flash("Alle Felder müssen ausgefüllt sein!") + flash("Felder 'MAC', 'IP' und 'Name' müssen ausgefüllt sein!") return redirect(url_for('devices')) - # Prüfen auf doppelte IP außer das aktuelle Gerät + # --- Prüfung auf doppelte IP --- ip_device = conn.execute("SELECT name FROM devices WHERE rpi_ip=? AND mac<>?", (rpi_ip, old_mac)).fetchone() if ip_device: flash(f"IP-Adresse existiert bereits für Gerät '{ip_device['name']}'!") return redirect(url_for('devices')) - # Prüfen auf doppelte MAC außer das aktuelle Gerät + # --- Prüfung auf doppelte MAC --- mac_device = conn.execute("SELECT name FROM devices WHERE mac=? AND mac<>?", (mac, old_mac)).fetchone() if mac_device: flash(f"MAC-Adresse existiert bereits für Gerät '{mac_device['name']}'!") @@ -264,14 +264,16 @@ def devices(): try: conn.execute(""" UPDATE devices - SET mac=?, rpi_ip=?, port=?, name=?, is_active=? + SET mac=?, rpi_ip=?, port=?, name=?, switch_hostname=?, is_active=? WHERE mac=? - """, (mac, rpi_ip, port, name, is_active, old_mac)) + """, (mac, rpi_ip, port, name, switch_hostname, is_active, old_mac)) conn.commit() flash(f"Gerät {name} aktualisiert.") except sqlite3.IntegrityError: flash("Fehler beim Aktualisieren des Geräts!") + return redirect(url_for('devices')) + # ----------------------- # Gerät löschen # -----------------------