Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/interplane-forge/blob/main/infra/ops/ipl-uptime-render.sh # interplane-forge INTERPLANE Forge Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `interplane-forge / infra / ops / ipl-uptime-render.sh` 108 lines ยท 5994 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # infra/ops/ipl-uptime-render.sh: render $STATE/probes.tsv and $STATE/cert.txt into one static page. 3 # Plain HTML, no script, no inline style (the interplane.io CSP is script-src 'none'; style-src 'self'). 4 # The page states what it is: an inside view from the Spark, not an outside check. It reports only 5 # counts inside the measured window (first to last probe of the last 24 h); it makes no claim about 6 # time between probes or outside the window, and prints no uptime percentage. 7 # Triggered by aien-onchange on the state dir (infra/ops/aien-run-ipl-uptime-page.service). 8 # 9 # Usage: ipl-uptime-render.sh write $OUT atomically 10 # ipl-uptime-render.sh --dry-run write the page to stdout instead 11 # Env: IPL_UPTIME_STATE (default ~/.local/state/interplane-uptime) 12 # IPL_UPTIME_OUT (default $STATE/www/index.html; deployed: /var/www/interplane-uptime/index.html) 13 # IPL_UPTIME_NOW fixed "now" (UTC, YYYY-MM-DDTHH:MM:SSZ) for tests 14 # IPL_UPTIME_STALE seconds after which the last probe is reported stale (default 900) 15 # Host tools: GNU awk/date. Omega replacement: an Omega page generator once seeded text/date words exist. 16 set -u 17 STATE=${IPL_UPTIME_STATE:-$HOME/.local/state/interplane-uptime} 18 OUT=${IPL_UPTIME_OUT:-$STATE/www/index.html} 19 NOW=${IPL_UPTIME_NOW:-$(date -u +%FT%TZ)} 20 STALE=${IPL_UPTIME_STALE:-900} 21 dry=0 22 case ${1:-} in --dry-run) dry=1;; '') ;; *) echo "usage: ipl-uptime-render.sh [--dry-run]" >&2; exit 2;; esac 23 24 now_s=$(date -u -d "$NOW" +%s) || { echo "ipl-uptime-render: bad IPL_UPTIME_NOW" >&2; exit 2; } 25 SINCE=$(date -u -d "@$((now_s - 86400))" +%FT%TZ) 26 TSV=$STATE/probes.tsv 27 [ -f "$TSV" ] || TSV=/dev/null 28 29 cert_na=-; cert_checked=-; cert_iss=-; cert_days= 30 if [ -s "$STATE/cert.txt" ]; then 31 IFS=$'\t' read -r cert_checked cert_na cert_iss <"$STATE/cert.txt" 32 if [ "$cert_na" != - ] && na_s=$(date -u -d "$cert_na" +%s 2>/dev/null); then 33 cert_days=$(( (na_s - now_s) / 86400 )) 34 fi 35 fi 36 37 render() { 38 gawk -F'\t' -v since="$SINCE" -v now="$NOW" -v now_s="$now_s" -v stale="$STALE" \ 39 -v cna="$cert_na" -v cchk="$cert_checked" -v ciss="$cert_iss" -v cdays="$cert_days" ' 40 function esc(s) { gsub(/&/, "\\&", s); gsub(//, "\\>", s); gsub(/"/, "\\"", s); return s } 41 function epoch(t, c) { c = t; gsub(/[-T:Z]/, " ", c); return mktime(c, 1) } 42 NF >= 4 && $1 >= since && $1 <= now { 43 p = $2 44 if (!(p in n)) { order[++np] = p } 45 n[p]++; total++ 46 if (first == "" || $1 < first) first = $1 47 if ($1 > last) last = $1 48 if ($3 ~ /^[23][0-9][0-9]$/) { 49 ok[p]++; oks++ 50 ms = $4 + 0; sum[p] += ms 51 if (!(p in mn) || ms < mn[p]) mn[p] = ms 52 if (ms > mx[p]) mx[p] = ms 53 } else { 54 fails++; fu[fails] = $1; fp[fails] = p; fs[fails] = $3; fm[fails] = $4 55 } 56 lastu[p] = $1; lasts[p] = $3 57 } 58 END { 59 print "" 60 print "" 61 print "" 62 print "" 63 print "interplane.io probes: inside view from the Spark" 64 print "

interplane.io probes

" 65 print "

Inside view from the Spark; not an outside check. The Spark asks for each page by its public name; the router turns the connection back to the Spark itself. A pass here does not show that the site is reachable from outside the house.

" 66 print "

Generated " now ". Each probe is one GET with a 15 s limit; OK means status 2xx or 3xx.

" 67 if (total == 0) { 68 print "

No probes in the 24 h before " now ". Nothing is claimed for that period.

" 69 } else { 70 wh = int((epoch(last) - epoch(first)) / 3600); wm = int(((epoch(last) - epoch(first)) % 3600) / 60) 71 print "

Measured window: " first " to " last " (" wh " h " wm " min), " total " probes, " oks " OK, " fails " failed. Nothing on this page covers the time between probes or outside this window.

" 72 age = now_s - epoch(last) 73 if (age > stale) print "

Stale: the last probe is " int(age / 60) " min old; the prober may be stopped.

" 74 print "" 75 print "" 76 for (i = 1; i <= np; i++) { 77 p = order[i]; k = ok[p] + 0 78 lat = (k > 0) ? mn[p] " / " int(sum[p] / k + 0.5) " / " mx[p] : "-" 79 print "" 80 } 81 print "
Per path, last 24 h
pathprobesOKfailedlast probelast statuslatency of OK probes, ms (min / mean / max)
" esc(p) "" n[p] "" k "" n[p] - k "" lastu[p] "" esc(lasts[p]) "" lat "
" 82 if (fails > 0) { 83 print "

Failed probes (newest 30)

" 84 print "" 85 lo = fails - 29; if (lo < 1) lo = 1 86 for (i = fails; i >= lo; i--) print "" 87 print "
utcpathstatus (000 = no answer)ms
" fu[i] "" esc(fp[i]) "" esc(fs[i]) "" esc(fm[i]) "
" 88 } 89 } 90 print "

Certificate

" 91 if (cna == "-" || cna == "") { 92 print "

No certificate expiry recorded" (cchk != "-" ? " (last attempt " esc(cchk) ")" : "") ".

" 93 } else { 94 print "

The certificate served for interplane.io expires " esc(cna) (cdays != "" ? " (" cdays " days after this page was generated)" : "") ". Read with openssl s_client at " esc(cchk) "; issuer " esc(ciss) ".

" 95 } 96 print "" 97 }' "$TSV" 98 } 99 100 if [ "$dry" = 1 ]; then render; exit; fi 101 mkdir -p "$(dirname "$OUT")" 2>/dev/null 102 [ -d "$(dirname "$OUT")" ] || { echo "ipl-uptime-render: output dir missing: $(dirname "$OUT")" >&2; exit 1; } 103 tmp=$(mktemp "$(dirname "$OUT")/.index.XXXXXX") || exit 1 104 if render >"$tmp"; then 105 chmod 644 "$tmp" && mv -f "$tmp" "$OUT" 106 else 107 rm -f "$tmp"; exit 1 108 fi