dev #2

Merged
alientim merged 32 commits from dev into main 2025-10-12 17:19:37 +02:00
Showing only changes of commit 7a1e9d88e5 - Show all commits

View File

@@ -222,7 +222,8 @@ def devices():
is_active = 1 if 'is_active' in request.form else 0 is_active = 1 if 'is_active' in request.form else 0
# --- Nur Switch ändern --- # --- Nur Switch ändern ---
if switch_hostname is not None and not any([mac, rpi_ip, name]): # Prüfen, ob nur das Switch-Feld gesendet wurde und die anderen Felder leer sind
if 'switch_hostname' in request.form and all(not f for f in [mac, rpi_ip, name]):
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!")
@@ -244,22 +245,30 @@ def devices():
return redirect(url_for('devices')) return redirect(url_for('devices'))
# --- Normales Gerät bearbeiten --- # --- Normales Gerät bearbeiten ---
# Pflichtfelder prüfen
if not all([old_mac, mac, rpi_ip, name]): if not all([old_mac, mac, rpi_ip, name]):
flash("Felder 'MAC', 'IP' und 'Name' müssen ausgefüllt sein!") flash("Felder 'MAC', 'IP' und 'Name' müssen ausgefüllt sein!")
return redirect(url_for('devices')) 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()
if ip_device: if ip_device:
flash(f"IP-Adresse existiert bereits für Gerät '{ip_device['name']}'!") flash(f"IP-Adresse existiert bereits für Gerät '{ip_device['name']}'!")
return redirect(url_for('devices')) return redirect(url_for('devices'))
# Prüfen auf doppelte MAC außer das aktuelle Gerät # Prüfen auf doppelte MAC außer das aktuelle Gerät
mac_device = conn.execute("SELECT name FROM devices WHERE mac=? AND mac<>?", (mac, old_mac)).fetchone() mac_device = conn.execute(
"SELECT name FROM devices WHERE mac=? AND mac<>?",
(mac, old_mac)
).fetchone()
if mac_device: if mac_device:
flash(f"MAC-Adresse existiert bereits für Gerät '{mac_device['name']}'!") flash(f"MAC-Adresse existiert bereits für Gerät '{mac_device['name']}'!")
return redirect(url_for('devices')) return redirect(url_for('devices'))
# Update durchführen
try: try:
conn.execute(""" conn.execute("""
UPDATE devices UPDATE devices
@@ -271,6 +280,7 @@ def devices():
except sqlite3.IntegrityError: except sqlite3.IntegrityError:
flash("Fehler beim Aktualisieren des Geräts!") flash("Fehler beim Aktualisieren des Geräts!")
# ----------------------- # -----------------------
# Gerät löschen # Gerät löschen
# ----------------------- # -----------------------