interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / infra / ops / ipl-uptime-probe.sh

72 lines · 3877 bytes Raw Blame History
1#!/usr/bin/env bash
2# infra/ops/ipl-uptime-probe.sh: one probe round of the public interplane.io site, run on the Spark.
3# Appends one line per path to $STATE/probes.tsv: utc<TAB>path<TAB>status<TAB>latency_ms
4# (status 000 = no HTTP answer within 15 s; latency is curl's time_total for that request).
5# Writes the served certificate's expiry to $STATE/cert.txt: checked_utc<TAB>not_after_utc<TAB>issuer
6# Read-only towards the site: one GET per path, no cookies, no credentials.
7# INSIDE VIEW ONLY: the Spark resolves interplane.io to the public address and the router hairpins
8# the connection back to the Spark's own front door, so a pass here does not prove the site is
9# reachable from outside the house.
10# Driven by aien-loop (infra/ops/aien-run-ipl-uptime.service): reachability has no change signal.
11#
12# Usage: ipl-uptime-probe.sh one round
13# ipl-uptime-probe.sh --dry-run print the targets and files, touch nothing (no network)
14# Env: IPL_UPTIME_STATE state dir (default ~/.local/state/interplane-uptime)
15# IPL_UPTIME_BASE https origin (default https://interplane.io)
16# IPL_UPTIME_PATHS space-separated paths (default below; switch /forge/ to /protocol/
17# once the home switch has landed)
18# IPL_UPTIME_MAX_LINES probes.tsv keeps the newest N lines (default 50000, about 34 days)
19# Host tools: curl, openssl s_client/x509, GNU date. Omega replacement: an Omega probe once the
20# seeded runtime has a TLS client; TLS stays on vetted tools until then (Drake's rule).
21set -u
22STATE=${IPL_UPTIME_STATE:-$HOME/.local/state/interplane-uptime}
23BASE=${IPL_UPTIME_BASE:-https://interplane.io}
24PATHS=${IPL_UPTIME_PATHS:-/ /explore /forge/ /drakestapleton/cuda-crack /drakestapleton/cuda-crack/raw/main/README.md}
25MAX_LINES=${IPL_UPTIME_MAX_LINES:-50000}
26UA='interplane-uptime/1 (Spark inside view; read-only)'
27
28case $BASE in https://*) ;; *) echo "ipl-uptime-probe: IPL_UPTIME_BASE must be https://..." >&2; exit 2;; esac
29HOSTPORT=${BASE#https://}; HOSTPORT=${HOSTPORT%%/*}
30HOST=${HOSTPORT%%:*}
31PORT=443; [ "$HOSTPORT" != "$HOST" ] && PORT=${HOSTPORT#*:}
32
33if [ "${1:-}" = --dry-run ]; then
34 echo "dry-run: state dir $STATE (probes.tsv, cert.txt); nothing written, no request sent"
35 for p in $PATHS; do echo "would GET $BASE$p (curl -m 15, record utc/path/status/latency_ms)"; done
36 echo "would read the certificate of $HOST:$PORT with openssl s_client -servername $HOST"
37 exit 0
38fi
39[ $# -eq 0 ] || { echo "usage: ipl-uptime-probe.sh [--dry-run]" >&2; exit 2; }
40
41mkdir -p "$STATE"
42TSV=$STATE/probes.tsv
43batch=''
44for p in $PATHS; do
45 utc=$(date -u +%FT%TZ)
46 out=$(curl -s -o /dev/null -m 15 --proto =https -A "$UA" -w '%{http_code} %{time_total}' "$BASE$p" 2>/dev/null)
47 code=${out%% *}; t=${out#* }
48 [ -n "$code" ] || code=000
49 ms=$(awk -v t="${t:-0}" 'BEGIN { printf "%d", t * 1000 + 0.5 }')
50 batch+=$(printf '%s\t%s\t%s\t%s' "$utc" "$p" "$code" "$ms")$'\n'
51done
52printf '%s' "$batch" >>"$TSV"
53
54# Certificate actually served on the probed address (not the file on disk).
55checked=$(date -u +%FT%TZ)
56cert=$(timeout 20 openssl s_client -connect "$HOST:$PORT" -servername "$HOST" </dev/null 2>/dev/null \
57 | openssl x509 -noout -enddate -issuer 2>/dev/null)
58na=$(printf '%s\n' "$cert" | sed -n 's/^notAfter=//p')
59iss=$(printf '%s\n' "$cert" | sed -n 's/^issuer=//p' | tr '\t' ' ')
60if [ -n "$na" ] && na_iso=$(date -u -d "$na" +%FT%TZ 2>/dev/null); then
61 line=$(printf '%s\t%s\t%s' "$checked" "$na_iso" "${iss:-?}")
62else
63 line=$(printf '%s\t-\tno certificate read' "$checked")
64fi
65printf '%s\n' "$line" >"$STATE/.cert.txt.tmp" && mv -f "$STATE/.cert.txt.tmp" "$STATE/cert.txt"
66
67# Bound the log; the page only ever shows the last 24 h.
68n=$(wc -l <"$TSV")
69if [ "$n" -gt "$MAX_LINES" ]; then
70 tail -n "$MAX_LINES" "$TSV" >"$TSV.tmp" && mv -f "$TSV.tmp" "$TSV"
71fi
72printf '%s' "$batch"