nx_live_governor_run.nx source
↩ module page · 77 lines · 3815 B
1// nx_live_governor_run.nx -- THE LIVE BOARD. Probe each catalogued route
2// over our OWN sovereign TLS-1.3 client and print LIVE / BROKEN / WRONG_WALL
3// -- the autonomous answer to "what is actually live right now?". Read-only
4// (HTTPS GETs, like any uptime monitor). Run directly.
5
6import "nx_syscalls.nx"
7import "nx_x509_trust_store.nx"
8import "nx_trust_store_load_from_certdata.nx"
9import "nx_https_fetch_follow.nx"
10import "nx_live_governor.nx"
11const K_MAGIC_4194304: i64 = 4194304
12
13func vp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
14func vpn(v: i64) -> i64 {
15 let b: *u8=sys_mmap(28); var x: i64=v; if x<0 {b[0]=45;sys_write(1,b,1);x=0-x}
16 if x==0 {b[0]=48;sys_write(1,b,1);return 0}
17 var d: i64=0; var y: i64=x; while y>0 {d=d+1;y=y/10}
18 var i: i64=d-1; y=x; while i>=0 {b[i]=(48+(y%10)) as u8; y=y/10; i=i-1}
19 sys_write(1,b,d); return 0
20}
21func contains(buf: *u8, n: i64, needle: *u8) -> i64 {
22 var nl: i64=0; while needle[nl]!=(0 as u8){nl=nl+1}
23 if nl==0 { return 1 } // empty needle = liveness-only (any body)
24 var i: i64=0
25 while i + nl <= n {
26 var j: i64=0; var ok: i64=1
27 while j<nl { if buf[i+j]!=needle[j] { ok=0; j=nl } else { j=j+1 } }
28 if ok==1 { return 1 }
29 i=i+1
30 }
31 return 0
32}
33
34// probe one route, grade it, print a board row; return the verdict.
35func lg_row(url: *u8, store: *TrustStore, out: *u8, cap: i64,
36 expected_auth: i64, marker: *u8, min_bytes: i64) -> i64 {
37 let status: *i64 = sys_mmap(8) as *i64
38 let n: i64 = nx_https_fetch_follow(url, store, out, cap, 6, status)
39 let s: i64 = status[0]
40 var mk: i64 = 0
41 var wall: i64 = 0
42 if n > 0 {
43 if min_bytes > 0 {
44 if n >= min_bytes { mk = 1 } // liveness: a real page is substantial
45 } else {
46 mk = contains(out, n, marker) // content marker
47 }
48 wall = contains(out, n, "OPAQUE login" as *u8)
49 }
50 let v: i64 = nx_lg_grade(200, expected_auth, s, mk, wall)
51 vp(nx_lg_verdict_name(v)); vp(" " as *u8); vp(url)
52 vp(" (status=" as *u8); vpn(s); vp(" bytes=" as *u8); vpn(n); vp(")\n" as *u8)
53 return v
54}
55
56func main() -> i64 {
57 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304)
58 if r <= 0 { vp("certdata load failed\n" as *u8); return 1 }
59 let store: *TrustStore = r as *TrustStore
60 let cap: i64 = K_MAGIC_4194304
61 let out: *u8 = sys_mmap(cap)
62
63 vp("=== NISHI LIVENESS BOARD ===\n" as *u8)
64 var broken: i64 = 0
65
66 if lg_row("https://nishifamily.com/" as *u8, store, out, cap, NX_LG_PUBLIC, "" as *u8, 800) != NX_LG_LIVE { broken = broken + 1 }
67 if lg_row("https://nishifamily.com/listen" as *u8, store, out, cap, NX_LG_PUBLIC, "<audio" as *u8, 0) != NX_LG_LIVE { broken = broken + 1 }
68 if lg_row("https://nishifamily.com/video" as *u8, store, out, cap, NX_LG_PUBLIC, "" as *u8, 800) != NX_LG_LIVE { broken = broken + 1 }
69 if lg_row("https://nishifamily.com/login" as *u8, store, out, cap, NX_LG_WALLED, "" as *u8, 800) != NX_LG_LIVE { broken = broken + 1 }
70 if lg_row("https://nishifamily.com/hub" as *u8, store, out, cap, NX_LG_WALLED, "" as *u8, 800) != NX_LG_LIVE { broken = broken + 1 }
71 if lg_row("https://nishifamily.com/games" as *u8, store, out, cap, NX_LG_PUBLIC, "" as *u8, 800) != NX_LG_LIVE { broken = broken + 1 }
72 if lg_row("https://nishifamily.com/games/" as *u8, store, out, cap, NX_LG_PUBLIC, "" as *u8, 800) != NX_LG_LIVE { broken = broken + 1 }
73 if lg_row("https://andelinwest.com/" as *u8, store, out, cap, NX_LG_PUBLIC, "" as *u8, 800) != NX_LG_LIVE { broken = broken + 1 }
74
75 vp("=== BROKEN/WRONG count = " as *u8); vpn(broken); vp(" ===\n" as *u8)
76 return 0
77}