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/
|
||||||
!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
|
||||||
|
|||||||
@@ -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 ".*> $" { }
|
||||||
}
|
}
|
||||||
@@ -68,18 +84,20 @@ 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
|
||||||
|
ping -c 1 -W 2 "$rpi_ip" &> /dev/null
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "$(date '+%Y-%m-%d %H:%M:%S') $hap ist nicht erreichbar!" >> $LOGFILE
|
echo "$(date '+%Y-%m-%d %H:%M:%S') $dev_name ist nicht erreichbar!" >> $LOGFILE
|
||||||
disable_poe $switch $port
|
disable_poe "$switch_ip" "$switch_port" "$switch_user" "$switch_pass"
|
||||||
echo "$(date '+%Y-%m-%d %H:%M:%S') $hap PoE auf Port $port für IP $ip am Switch $switch deaktiviert." >> $LOGFILE
|
echo "$(date '+%Y-%m-%d %H:%M:%S') $dev_name PoE auf Port $switch_port am Switch $switch_hostname deaktiviert." >> $LOGFILE
|
||||||
sleep 2
|
sleep 2
|
||||||
enable_poe $switch $port
|
enable_poe "$switch_ip" "$switch_port" "$switch_user" "$switch_pass"
|
||||||
echo "$(date '+%Y-%m-%d %H:%M:%S') $hap PoE auf Port $port für IP $ip am Switch $switch aktiviert." >> $LOGFILE
|
echo "$(date '+%Y-%m-%d %H:%M:%S') $dev_name PoE auf Port $switch_port am Switch $switch_hostname aktiviert." >> $LOGFILE
|
||||||
else
|
else
|
||||||
echo "$(date '+%Y-%m-%d %H:%M:%S') $hap ist erreichbar!" >> $LOGFILE
|
echo "$(date '+%Y-%m-%d %H:%M:%S') $dev_name ist erreichbar!" >> $LOGFILE
|
||||||
fi
|
fi
|
||||||
done < "$IP_FILE"
|
done < "$IP_FILE"
|
||||||
sleep 300
|
rm -f "$IP_FILE"
|
||||||
|
sleep $SLEEP
|
||||||
done
|
done
|
||||||
Reference in New Issue
Block a user