Webinterface

This commit is contained in:
2025-09-26 15:17:37 +00:00
parent b95b1fbb9f
commit 26fb560aac
2 changed files with 66 additions and 27 deletions

25
.gitignore vendored
View File

@@ -1,12 +1,33 @@
# Alles ignorieren
* *
!/*.gitignore
# .gitignore selbst tracken
!.gitignore
# Virtuelle Umgebung ignorieren
venv/
__pycache__/
# Logfiles ignorieren
*.log
# Systemd Services tracken
!etc/ !etc/
!etc/systemd/ !etc/systemd/
!etc/systemd/system !etc/systemd/system/
!etc/systemd/system/rpi*.service !etc/systemd/system/rpi*.service
!etc/systemd/system/rpi*.timer !etc/systemd/system/rpi*.timer
# Custom Scripts tracken
!usr/ !usr/
!usr/local/ !usr/local/
!usr/local/bin/ !usr/local/bin/
!usr/local/bin/custom/ !usr/local/bin/custom/
!usr/local/bin/custom/* !usr/local/bin/custom/*
# Web-App Dateien im poe_manager tracken
!/srv/poe_manager/
!/srv/poe_manager/*
# Optional: SQLite DB ignorieren (falls du nicht willst, dass Passwörter im Repo landen)
# /srv/poe_manager/sqlite.db

View File

@@ -1,19 +1,33 @@
#!/bin/bash #!/bin/bash
USER=""
PASS=""
IP_FILE="/usr/local/bin/custom/ips.list"
LOGFILE="/var/log/rpi-$(date '+%Y%m%d%H%M%S').log" LOGFILE="/var/log/rpi-$(date '+%Y%m%d%H%M%S').log"
IP_FILE=$(python3 /srv/poe_manager/generate_ips.py)
# Intervall aus DB (Sekunden) abrufen
SLEEP=$(python3 - <<END
import sqlite3
conn = sqlite3.connect("/srv/poe_manager/sqlite.db")
row = conn.execute("SELECT value FROM settings WHERE key='check_interval'").fetchone()
conn.close()
print(row[0] if row else 300)
END
)
# Umrechnung falls nötig
SLEEP=${SLEEP:-300} # default 300 Sekunden
function disable_poe() { function disable_poe() {
local switch_ip=$1 local switch_ip=$1
local port=$2 local switch_port=$2
local username=$3
local password=$4
expect <<EOF expect <<EOF
set timeout 5 set timeout 5
spawn ssh $USER@$switch_ip spawn ssh $username@$switch_ip
expect { expect {
"assword:" { send "$PASS\r"; exp_continue } "assword:" { send "$password\r"; exp_continue }
"Press any key" { send "\r"; exp_continue } "Press any key" { send "\r"; exp_continue }
-re ".*> $" { } -re ".*> $" { }
} }
@@ -37,13 +51,15 @@ EOF
function enable_poe() { function enable_poe() {
local switch_ip=$1 local switch_ip=$1
local port=$2 local switch_port=$2
local username=$3
local password=$4
expect <<EOF expect <<EOF
set timeout 5 set timeout 5
spawn ssh $USER@$switch_ip spawn ssh $username@$switch_ip
expect { expect {
"assword:" { send "$PASS\r"; exp_continue } "assword:" { send "$password\r"; exp_continue }
"Press any key" { send "\r"; exp_continue } "Press any key" { send "\r"; exp_continue }
-re ".*> $" { } -re ".*> $" { }
} }
@@ -67,19 +83,21 @@ EOF
echo "" > $LOGFILE echo "" > $LOGFILE
while true; do while true; do
echo "--------------------------------------------------------------------" >> $LOGFILE echo "--------------------------------------------------------------------" >> $LOGFILE
while IFS=: read -r ip switch port hap; do IP_FILE=$(python3 /srv/poe_manager/generate_ips.py)
ping -c 1 -W 2 $ip &> /dev/null while IFS=: read -r rpi_ip dev_name switch_ip switch_hostname switch_port switch_user switch_pass; do
if [ $? -ne 0 ]; then ping -c 1 -W 2 "$rpi_ip" &> /dev/null
echo "$(date '+%Y-%m-%d %H:%M:%S') $hap ist nicht erreichbar!" >> $LOGFILE if [ $? -ne 0 ]; then
disable_poe $switch $port echo "$(date '+%Y-%m-%d %H:%M:%S') $dev_name ist nicht erreichbar!" >> $LOGFILE
echo "$(date '+%Y-%m-%d %H:%M:%S') $hap PoE auf Port $port für IP $ip am Switch $switch deaktiviert." >> $LOGFILE disable_poe "$switch_ip" "$switch_port" "$switch_user" "$switch_pass"
sleep 2 echo "$(date '+%Y-%m-%d %H:%M:%S') $dev_name PoE auf Port $switch_port am Switch $switch_hostname deaktiviert." >> $LOGFILE
enable_poe $switch $port sleep 2
echo "$(date '+%Y-%m-%d %H:%M:%S') $hap PoE auf Port $port für IP $ip am Switch $switch aktiviert." >> $LOGFILE enable_poe "$switch_ip" "$switch_port" "$switch_user" "$switch_pass"
else echo "$(date '+%Y-%m-%d %H:%M:%S') $dev_name PoE auf Port $switch_port am Switch $switch_hostname aktiviert." >> $LOGFILE
echo "$(date '+%Y-%m-%d %H:%M:%S') $hap ist erreichbar!" >> $LOGFILE else
fi echo "$(date '+%Y-%m-%d %H:%M:%S') $dev_name ist erreichbar!" >> $LOGFILE
done < "$IP_FILE" fi
sleep 300 done < "$IP_FILE"
done rm -f "$IP_FILE"
sleep $SLEEP
done