srv/poe_manager/app.py aktualisiert
This commit is contained in:
@@ -204,33 +204,33 @@ def devices():
|
|||||||
switch_hostname = request.form.get('switch_hostname') or None
|
switch_hostname = request.form.get('switch_hostname') or None
|
||||||
is_active = 1 if 'is_active' in request.form else 0
|
is_active = 1 if 'is_active' in request.form else 0
|
||||||
|
|
||||||
# --- Prüfen, ob es sich um eine Switch-Änderung handelt ---
|
# --- Prüfen, ob es sich um eine Switch-Änderung handelt ---
|
||||||
if mac is None and rpi_ip is None and port is None and name is None and switch_hostname:
|
if mac is None and rpi_ip is None and port is None and name is None and switch_hostname:
|
||||||
# Nur den Switch ändern
|
# Nur den Switch ändern
|
||||||
device = conn.execute("SELECT name, switch_hostname FROM devices WHERE mac=?", (old_mac,)).fetchone()
|
device = conn.execute("SELECT name, switch_hostname FROM devices WHERE mac=?", (old_mac,)).fetchone()
|
||||||
|
|
||||||
if not device:
|
if not device:
|
||||||
flash("Gerät nicht gefunden!")
|
flash("Gerät nicht gefunden!")
|
||||||
|
return redirect(url_for('devices'))
|
||||||
|
|
||||||
|
old_switch = device['switch_hostname'] or "unbekannt"
|
||||||
|
device_name = device['name']
|
||||||
|
|
||||||
|
try:
|
||||||
|
conn.execute("""
|
||||||
|
UPDATE devices
|
||||||
|
SET switch_hostname=?
|
||||||
|
WHERE mac=?
|
||||||
|
""", (switch_hostname, old_mac))
|
||||||
|
conn.commit()
|
||||||
|
flash(f"Switch von {device_name} geändert: {old_switch} → {switch_hostname}")
|
||||||
|
except sqlite3.IntegrityError:
|
||||||
|
flash("Fehler beim Ändern des Switch!")
|
||||||
return redirect(url_for('devices'))
|
return redirect(url_for('devices'))
|
||||||
|
|
||||||
old_switch = device['switch_hostname'] or "unbekannt"
|
if not all([old_mac, mac, rpi_ip, port, name]):
|
||||||
device_name = device['name']
|
flash("Alle Felder müssen ausgefüllt sein!")
|
||||||
|
return redirect(url_for('devices'))
|
||||||
try:
|
|
||||||
conn.execute("""
|
|
||||||
UPDATE devices
|
|
||||||
SET switch_hostname=?
|
|
||||||
WHERE mac=?
|
|
||||||
""", (switch_hostname, old_mac))
|
|
||||||
conn.commit()
|
|
||||||
flash(f"Switch von {device_name} geändert: {old_switch} → {switch_hostname}")
|
|
||||||
except sqlite3.IntegrityError:
|
|
||||||
flash("Fehler beim Ändern des Switch!")
|
|
||||||
return redirect(url_for('devices'))
|
|
||||||
|
|
||||||
if not all([old_mac, mac, rpi_ip, port, name]):
|
|
||||||
flash("Alle Felder müssen ausgefüllt sein!")
|
|
||||||
return redirect(url_for('devices'))
|
|
||||||
|
|
||||||
# Prüfen auf doppelte IP außer das aktuelle Gerät
|
# Prüfen auf doppelte IP außer das aktuelle Gerät
|
||||||
ip_device = conn.execute("SELECT name FROM devices WHERE rpi_ip=? AND mac<>?", (rpi_ip, old_mac)).fetchone()
|
ip_device = conn.execute("SELECT name FROM devices WHERE rpi_ip=? AND mac<>?", (rpi_ip, old_mac)).fetchone()
|
||||||
|
|||||||
Reference in New Issue
Block a user