code wiki / _hdl_build / nx_video_diag_stage.nx
nx_video_diag_stage.nx source
↩ module page · 27 lines · 2914 B
1// nx_video_diag_stage.nx -- READ-ONLY stage step for a /video-backend diagnostic over the sovereign SSH path.
2// Sibling of nx_edge_recon_stage.nx, but the staged remote command is
3// STRICTLY READ-ONLY (curl-read/sed/grep/ss/netstat/tail only -- no kill/start/mv/deploy/cron/sudo-write). Reads the
4// decrypted secret from /tmp/nxsecret.out (produced by nx_machine_key + _offc/nx_vault.elf open), copies it to
5// /tmp/nxpw, and writes the read-only diagnostic to /tmp/nxcmd. Then nx_ssh_cmd consumes both. Nothing is
6// mutated on the NAS. license_tier: ORIGINAL
7import "nx_syscalls.nx"
8
9const DIAG_CMD: *u8 = "for P in 7443 443; do echo \"=== PORT $P /video ===\"; curl -sk --max-time 8 -i --resolve nishifamily.com:$P:127.0.0.1 https://nishifamily.com:$P/video 2>&1 | sed -n '1,20p'; echo \"--- markers ---\"; curl -sk --max-time 8 --resolve nishifamily.com:$P:127.0.0.1 https://nishifamily.com:$P/video 2>&1 | grep -ioE 'app.js|vroom|WebSocket|/signal|getUserMedia|Nishi Family Video' | sort -u; echo \"=== PORT $P /signal WS-UPGRADE ===\"; curl -sk --max-time 8 -i --resolve nishifamily.com:$P:127.0.0.1 -H \"Connection: Upgrade\" -H \"Upgrade: websocket\" -H \"Sec-WebSocket-Version: 13\" -H \"Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\" \"https://nishifamily.com:$P/signal/testroom\" 2>&1 | sed -n '1,20p'; done; echo \"=== SIGNALING BACKEND :8445 ===\"; (ss -tlnp 2>/dev/null||netstat -tlnp 2>/dev/null) | grep 8445; echo \"--- signaling.log tail ---\"; tail -15 /volume1/homes/elderwesto/nishihost/signaling.log 2>/dev/null; echo \"=== sites.elf /signal impl check ===\"; grep -c \"/signal\" /volume1/homes/elderwesto/nishihost/sites.elf 2>/dev/null\n"
10
11func slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
12func pw(s: *u8) -> i64 { sys_write(1,s,slen(s)); return 0 }
13func pn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(1,bb,k); return 0 }
14
15func main() -> i64 {
16 let box: *i64 = sys_mmap(16) as *i64
17 let sec: *u8 = sys_read_file("/tmp/nxsecret.out" as *u8, box)
18 if (sec as i64)==0 { pw("VIDEO-DIAG-STAGE: no /tmp/nxsecret.out -- run nx_machine_key + _offc/nx_vault.elf open first\n"); sys_exit(1); return 1 }
19 let pf: i64 = sys_openat_wr("/tmp/nxpw" as *u8, 0x180)
20 if pf<0 { pw("VIDEO-DIAG-STAGE: cannot write /tmp/nxpw\n"); sys_exit(1); return 1 }
21 sys_write(pf, sec, box[0]); sys_close(pf)
22 let cf: i64 = sys_openat_wr("/tmp/nxcmd" as *u8, 0x180)
23 if cf<0 { pw("VIDEO-DIAG-STAGE: cannot write /tmp/nxcmd\n"); sys_exit(1); return 1 }
24 sys_write(cf, DIAG_CMD, slen(DIAG_CMD)); sys_close(cf)
25 pw("VIDEO-DIAG-STAGE: credential -> /tmp/nxpw ("); pn(box[0]); pw(" bytes) + READ-ONLY diagnostic staged -> /tmp/nxcmd. Run nx_ssh_cmd.\n")
26 sys_exit(0); return 0
27}