#!/bin/bash
export LC_ALL=C
printf '\n----- SERVICE -----\n'
systemctl is-active proxylab-serve.service
systemctl show proxylab-serve.service -p NRestarts -p ActiveEnterTimestamp --value | head -2

printf '\n----- LISTENERS -----\n'
ss -tlnp 2>/dev/null | grep -E ':(20808|10808|10809|8118)\s' | sed 's/  */ /g' | cut -c1-95

printf '\n----- END-TO-END PROBE -----\n'
for a in 127.0.0.1 172.19.0.1 172.17.0.1; do
  code=$(curl -s -o /dev/null -w '%{http_code} %{time_total}' --max-time 15 -x "http://$a:20808" https://www.gstatic.com/generate_204 2>/dev/null)
  printf '  %-12s -> %s\n' "$a" "$code"
done

printf '\n----- REAL PROVIDER PROBE (through proxy) -----\n'
for u in https://api.openai.com/v1/models https://generativelanguage.googleapis.com/ https://openrouter.ai/api/v1/models; do
  printf '  %-46s ' "$u"
  curl -s -o /dev/null -w '%{http_code} %{time_total}s\n' --max-time 20 -x http://127.0.0.1:20808 "$u" 2>/dev/null || echo fail
done

printf '\n----- EXIT IP (through proxy) -----\n'
curl -s --max-time 20 -x http://127.0.0.1:20808 https://api.ipify.org 2>/dev/null; echo

printf '\n----- CYCLE / WATCHDOG LOG -----\n'
tail -n 6 /var/log/proxylab-cycle.log 2>/dev/null
tail -n 6 /var/log/proxylab-watchdog.log 2>/dev/null

printf '\n----- TIMERS -----\n'
systemctl list-timers proxylab-cycle.timer proxylab-watchdog.timer --no-pager 2>/dev/null | head -4
