Switche: optionaler SSH-Port statt fest 22
- Neue Spalte switches.ssh_port (nullable INTEGER), Migration für bestehende DBs in _ensure_schema(), Feld in create_db.py ergänzt. - Formular (Anlegen/Bearbeiten): optionales SSH-Port-Feld, Validierung 1-65535, leer -> NULL (= Standard 22 überall, SWITCH_DEFAULT_SSH_PORT). Switch-Liste zeigt den effektiven Port inkl. "(Standard)"-Hinweis. - generate_ips.py liefert den effektiven Port (Fallback 22) als eigenes Pipe-Feld an poe.sh; poe.sh übernimmt es in disable_poe/enable_poe und reicht es als "ssh -p <port>" an die expect-Skripte durch (Default weiterhin 22 falls Parameter fehlt). - Web-Terminal (Verbindungstest) sendet den im Formular eingetragenen Port statt hartkodiert 22. - Live getestet: gültiger/leerer/ungültiger Port beim Anlegen, korrekte Weitergabe durch generate_ips.py inkl. Feldreihenfolge, die poe.sh 'read' erwartet. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -30,9 +30,10 @@ function disable_poe() {
|
||||
local switch_port=$2
|
||||
local username=$3
|
||||
local password=$4
|
||||
local ssh_port=${5:-22}
|
||||
expect <<EOF
|
||||
set timeout 5
|
||||
spawn ssh $username@$switch_ip
|
||||
spawn ssh -p $ssh_port $username@$switch_ip
|
||||
expect {
|
||||
"assword:" { send "$password\r"; exp_continue }
|
||||
"Press any key" { send "\r"; exp_continue }
|
||||
@@ -60,9 +61,10 @@ function enable_poe() {
|
||||
local switch_port=$2
|
||||
local username=$3
|
||||
local password=$4
|
||||
local ssh_port=${5:-22}
|
||||
expect <<EOF
|
||||
set timeout 5
|
||||
spawn ssh $username@$switch_ip
|
||||
spawn ssh -p $ssh_port $username@$switch_ip
|
||||
expect {
|
||||
"assword:" { send "$password\r"; exp_continue }
|
||||
"Press any key" { send "\r"; exp_continue }
|
||||
@@ -87,16 +89,16 @@ EOF
|
||||
|
||||
function manual_restart() {
|
||||
local target_mac="$1"
|
||||
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 mac; do
|
||||
python3 /srv/poe_manager/generate_ips.py | while IFS='|' read -r rpi_ip dev_name switch_ip switch_ssh_port switch_hostname switch_port switch_user switch_pass mac; do
|
||||
if [[ "$mac" != "$target_mac" ]]; then
|
||||
continue
|
||||
fi
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') Manueller Neustart von $dev_name gestartet." >> "$LOGFILE"
|
||||
if [ -n "$switch_ip" ] && [ -n "$switch_port" ] && [ "$switch_port" != "None" ]; then
|
||||
disable_poe "$switch_ip" "$switch_port" "$switch_user" "$switch_pass"
|
||||
disable_poe "$switch_ip" "$switch_port" "$switch_user" "$switch_pass" "$switch_ssh_port"
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') $dev_name PoE deaktiviert." >> "$LOGFILE"
|
||||
sleep 2
|
||||
enable_poe "$switch_ip" "$switch_port" "$switch_user" "$switch_pass"
|
||||
enable_poe "$switch_ip" "$switch_port" "$switch_user" "$switch_pass" "$switch_ssh_port"
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') $dev_name PoE aktiviert." >> "$LOGFILE"
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') Manueller Neustart von $dev_name abgeschlossen." >> "$LOGFILE"
|
||||
else
|
||||
@@ -119,7 +121,7 @@ echo "" > "$LOGFILE"
|
||||
|
||||
while true; do
|
||||
echo "--------------------------------------------------------------------" >> "$LOGFILE"
|
||||
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 mac; do
|
||||
python3 /srv/poe_manager/generate_ips.py | while IFS='|' read -r rpi_ip dev_name switch_ip switch_ssh_port switch_hostname switch_port switch_user switch_pass mac; do
|
||||
if ping -c 1 -W 2 "$rpi_ip" &> /dev/null; then
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') $dev_name ist erreichbar!" >> "$LOGFILE"
|
||||
else
|
||||
@@ -130,10 +132,10 @@ while true; do
|
||||
# (switch_ip leer) darf keinen SSH-Versuch mit leeren
|
||||
# Zugangsdaten auslösen.
|
||||
if [ -n "$switch_ip" ] && [ -n "$switch_port" ] && [ "$switch_port" != "None" ]; then
|
||||
disable_poe "$switch_ip" "$switch_port" "$switch_user" "$switch_pass"
|
||||
disable_poe "$switch_ip" "$switch_port" "$switch_user" "$switch_pass" "$switch_ssh_port"
|
||||
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"
|
||||
enable_poe "$switch_ip" "$switch_port" "$switch_user" "$switch_pass" "$switch_ssh_port"
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') $dev_name PoE auf Port $switch_port am Switch $switch_hostname aktiviert." >> "$LOGFILE"
|
||||
fi
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user