wg-client-status.sh aktualisiert

This commit is contained in:
2026-03-24 21:00:02 +01:00
parent b423e2dc3b
commit 525e95fa84

View File

@@ -1,27 +1,29 @@
#!/bin/bash
URL="https://node-red.mgnt.vmd55888.de/vpn-status"
URL="http://10.10.20.225:1880/vpn-status"
MY_HOSTNAME=$(hostname)
echo "Starte VPN Status Sync..."
# Ausgabe von netclient ping speichern
mapfile -t LINES < <(netclient ping)
# Ausgabe in temporäre Datei
TMPFILE=$(mktemp)
netclient ping > "$TMPFILE"
for line in "${LINES[@]}"; do
# Spalte 2 = Clientname, Spalte 4 = CONNECTED
# Zeilenweise verarbeiten
while IFS= read -r line; do
# Spalte 2 = Clientname, Spalte 4 = Status
CLIENT_RAW=$(echo "$line" | awk -F'|' '{print $2}' | xargs)
STATUS_RAW=$(echo "$line" | awk -F'|' '{print $4}' | xargs)
# Zeilen ohne Clientname berspringen
# Zeilen ohne Clientname überspringen
[[ -z "$CLIENT_RAW" ]] && continue
# Nur Clients ber cksichtigen, die 'vpn' im Namen enthalten
# Nur Clients mit 'vpn' im Namen berücksichtigen
if [[ "$CLIENT_RAW" != *vpn* ]]; then
continue
fi
# Leerzeichen/Emojis/Sonderzeichen f r Key entfernen
# Leerzeichen/Emojis/Sonderzeichen für Key entfernen
CLIENT=$(echo "$CLIENT_RAW" | sed 's/[^a-zA-Z0-9._-]//g')
# Status in Boolean
@@ -31,12 +33,16 @@ for line in "${LINES[@]}"; do
STATUS=false
fi
echo "Sende: $CLIENT ^f^r $STATUS ..."
echo "Sende: $CLIENT $STATUS ..."
# POST an Node-RED
curl -s -X POST -H "Content-Type: application/json" \
-d "{\"server\": \"$MY_HOSTNAME\", \"client\": \"$CLIENT\", \"status\": $STATUS}" \
"$URL" > /dev/null
done
done < "$TMPFILE"
# Tempdatei löschen
rm -f "$TMPFILE"
echo "Fertig."