diff --git a/off.sh b/off.sh index 235dadc..0848495 100644 --- a/off.sh +++ b/off.sh @@ -20,6 +20,24 @@ gabi_check() doas loginctl terminate-user gabi } +gaja_check() +{ + ping -c 1 -W 1 192.168.1.122 2>&1 >/dev/null || { echo "Gaja's PC is unreachable."; return; } + + # Check if Gaja has any sessions + sshpass -p Nagaja ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no -F /dev/null gaja@192.168.1.122 \ + "loginctl list-sessions --no-pager 2>/dev/null | grep -q gaja" 2>&1 + if [ $? -ne 0 ]; then + echo "Gaja is not online." + return + fi + + # Terminate all of Gaja's sessions (SSH drops = success) + sshpass -p Nagaja ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no -F /dev/null gaja@192.168.1.122 \ + "loginctl terminate-user gaja" 2>/dev/null + echo "Gaja's PC: logged out." +} + S=$(date -d "$TIME_START" +%s) T=$(date -d "$TIME_STOP" +%s) C=$(date +%s) @@ -32,6 +50,7 @@ then else echo "ACTIVE: Executing for the next $((T - C)) seconds." gabi_check + gaja_check tv_check fi diff --git a/server.py b/server.py index 21b3088..d317db9 100755 --- a/server.py +++ b/server.py @@ -51,13 +51,26 @@ def parse_output(text: str) -> list[dict]: # User checks if "Gabi is not online" in line: - actions.append({"icon": "👤", "title": "Gabi's PC", "detail": "Not logged in — no action needed"}) + actions.append({"icon": "💻", "title": "Gabi's PC", "detail": "Not logged in — no action needed"}) continue - if "terminate-user gabi" in line or "terminated" in line.lower(): + m = re.match(r"terminate-user gabi\b", line) + if m or "session terminated" in line.lower(): actions.append({"icon": "💻", "title": "Gabi's PC", "detail": "Session terminated"}) continue + if "Gaja is not online" in line: + actions.append({"icon": "💻", "title": "Gaja's PC", "detail": "Not logged in — no action needed"}) + continue + + if "Gaja's PC is unreachable" in line: + actions.append({"icon": "❌", "title": "Gaja's PC", "detail": "Unreachable (ping failed)"}) + continue + + if "Gaja's PC: logged out" in line: + actions.append({"icon": "💻", "title": "Gaja's PC", "detail": "Logged out"}) + continue + # If no structured items found, fallback to raw if not actions: actions.append({"icon": "📜", "title": "Output", "detail": text.strip() or "(empty)"})