Webinterface
This commit is contained in:
25
.gitignore
vendored
25
.gitignore
vendored
@@ -1,12 +1,33 @@
|
||||
# Alles ignorieren
|
||||
*
|
||||
!/*.gitignore
|
||||
|
||||
# .gitignore selbst tracken
|
||||
!.gitignore
|
||||
|
||||
# Virtuelle Umgebung ignorieren
|
||||
venv/
|
||||
__pycache__/
|
||||
|
||||
# Logfiles ignorieren
|
||||
*.log
|
||||
|
||||
# Systemd Services tracken
|
||||
!etc/
|
||||
!etc/systemd/
|
||||
!etc/systemd/system
|
||||
!etc/systemd/system/
|
||||
!etc/systemd/system/rpi*.service
|
||||
!etc/systemd/system/rpi*.timer
|
||||
|
||||
# Custom Scripts tracken
|
||||
!usr/
|
||||
!usr/local/
|
||||
!usr/local/bin/
|
||||
!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
|
||||
|
||||
@@ -1,19 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
USER=""
|
||||
PASS=""
|
||||
IP_FILE="/usr/local/bin/custom/ips.list"
|
||||
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() {
|
||||
local switch_ip=$1
|
||||
local port=$2
|
||||
local switch_port=$2
|
||||
local username=$3
|
||||
local password=$4
|
||||
expect <<EOF
|
||||
set timeout 5
|
||||
spawn ssh $USER@$switch_ip
|
||||
spawn ssh $username@$switch_ip
|
||||
|
||||
expect {
|
||||
"assword:" { send "$PASS\r"; exp_continue }
|
||||
"assword:" { send "$password\r"; exp_continue }
|
||||
"Press any key" { send "\r"; exp_continue }
|
||||
-re ".*> $" { }
|
||||
}
|
||||
@@ -37,13 +51,15 @@ EOF
|
||||
|
||||
function enable_poe() {
|
||||
local switch_ip=$1
|
||||
local port=$2
|
||||
local switch_port=$2
|
||||
local username=$3
|
||||
local password=$4
|
||||
expect <<EOF
|
||||
set timeout 5
|
||||
spawn ssh $USER@$switch_ip
|
||||
spawn ssh $username@$switch_ip
|
||||
|
||||
expect {
|
||||
"assword:" { send "$PASS\r"; exp_continue }
|
||||
"assword:" { send "$password\r"; exp_continue }
|
||||
"Press any key" { send "\r"; exp_continue }
|
||||
-re ".*> $" { }
|
||||
}
|
||||
@@ -67,19 +83,21 @@ EOF
|
||||
|
||||
echo "" > $LOGFILE
|
||||
while true; do
|
||||
echo "--------------------------------------------------------------------" >> $LOGFILE
|
||||
while IFS=: read -r ip switch port hap; do
|
||||
ping -c 1 -W 2 $ip &> /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') $hap ist nicht erreichbar!" >> $LOGFILE
|
||||
disable_poe $switch $port
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') $hap PoE auf Port $port für IP $ip am Switch $switch deaktiviert." >> $LOGFILE
|
||||
sleep 2
|
||||
enable_poe $switch $port
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') $hap PoE auf Port $port für IP $ip am Switch $switch aktiviert." >> $LOGFILE
|
||||
else
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') $hap ist erreichbar!" >> $LOGFILE
|
||||
fi
|
||||
done < "$IP_FILE"
|
||||
sleep 300
|
||||
done
|
||||
echo "--------------------------------------------------------------------" >> $LOGFILE
|
||||
IP_FILE=$(python3 /srv/poe_manager/generate_ips.py)
|
||||
while IFS=: read -r rpi_ip dev_name switch_ip switch_hostname switch_port switch_user switch_pass; do
|
||||
ping -c 1 -W 2 "$rpi_ip" &> /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') $dev_name ist nicht erreichbar!" >> $LOGFILE
|
||||
disable_poe "$switch_ip" "$switch_port" "$switch_user" "$switch_pass"
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') $dev_name PoE auf Port $switch_port am Switch $switch_hostname deaktiviert." >> $LOGFILE
|
||||
sleep 2
|
||||
enable_poe "$switch_ip" "$switch_port" "$switch_user" "$switch_pass"
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') $dev_name PoE auf Port $switch_port am Switch $switch_hostname aktiviert." >> $LOGFILE
|
||||
else
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') $dev_name ist erreichbar!" >> $LOGFILE
|
||||
fi
|
||||
done < "$IP_FILE"
|
||||
rm -f "$IP_FILE"
|
||||
sleep $SLEEP
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user