nx_http_post_gate.nx source
↩ module page · 39 lines · 3180 B
1// nx_http_post_gate.nx -- proves the sovereign HTTP POST path against the LIVE server (no args, no shell-quoting
2// fragility): POST /blocklist with a form body -> server accepts (200) and returns the page. Composes nx_http_client's
3// POST builder + sockaddr. Requires nx_archive_server up on :18801 (ARCSRV_PORT; it moved off :8080 on
4// 2026-08-06 because redirect.elf owns 8080 -- see nx_archive_server.nx "PORT CONFLICT AVERTED").
5// license_tier: ORIGINAL
6import "nx_http_client.nx"
7import "nx_connect.nx" // bounded connect: a raw sys_connect hangs ~127s on a black-holed host
8import "nx_gate.nx"
9
10func g_atoi(buf: *u8, off: i64, len: i64) -> i64 { var v: i64=0; var i: i64=0; while i<len { let d: i64=buf[off+i] as i64; if d>=48 { if d<=57 { v=v*10+(d-48) } else { i=len } } else { i=len } i=i+1 } return v }
11func g_contains(buf: *u8, n: i64, needle: *u8) -> i64 { var nl: i64=0; while needle[nl]!=(0 as u8){nl=nl+1} if nl==0 {return 1} var i: i64=0; while i+nl<=n { var m: i64=1; var j: i64=0; while j<nl { if buf[i+j]!=needle[j] {m=0;j=nl} else {j=j+1} } if m==1 {return 1} i=i+1 } return 0 }
12func g_drain(fd: i64, buf: *u8, cap: i64) -> i64 { var off: i64=0; var go: i64=1; while go==1 { if off>=cap { go=0 } else { let r: i64=sys_read(fd, ((buf as i64)+off) as *u8, cap-off); if r<=0 { go=0 } else { off=off+r } } } return off }
13
14func main() -> i64 {
15 gw("=== nx_http_post_gate: sovereign POST to the live server ===\n" as *u8)
16 let addr: *u8 = sys_mmap(16)
17 nx_http_client_sockaddr_ipv4(addr, 127, 0, 0, 1, 18801) // 8080 is redirect.elf; archive_server moved to ARCSRV_PORT=18801 on 2026-08-06
18 let fd: i64 = sys_socket(2, 1, 0)
19 var pass: i64=0; var tot: i64=0
20 var status: i64=0; var n: i64=0
21 if fd < 0 { gw(" [FAIL] socket\n" as *u8) } else {
22 if nx_connect_bounded(fd, addr, 16, NX_CONN_DEFAULT_MS) < 0 { gw(" [FAIL] connect (is nx_archive_server up on :18801?)\n" as *u8) } else {
23 let body: *u8 = "user=x"; let ct: *u8 = "application/x-www-form-urlencoded"
24 let req: *u8 = sys_mmap(8192)
25 let reqlen: i64 = nx_http_client_build_request_post("/blocklist" as *u8, 10, "localhost" as *u8, 9, ct, 33, body, 6, req)
26 sys_write(fd, req, reqlen)
27 let cap: i64 = 2097152; let buf: *u8 = sys_mmap(cap)
28 n = g_drain(fd, buf, cap); sys_close(fd)
29 if n > 12 { status = g_atoi(buf, 9, 3) }
30 tot=tot+1; if status==200 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
31 gw("T1 server accepted POST -> status=" as *u8); gn(status); gw("\n" as *u8)
32 tot=tot+1; if g_contains(buf, n, "Do-not-recover" as *u8)==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
33 gw("T2 response body returned (" as *u8); gn(n); gw(" bytes, contains the page)\n" as *u8)
34 }
35 }
36 gw("\n=== nx_http_post_gate " as *u8); gn(pass); gw("/" as *u8); gn(tot); gw(" ===\n" as *u8)
37 if pass==tot { if tot>0 { gw("HTTP-POST GREEN -- sovereign POST proven live (retires Invoke-WebRequest POST)\n" as *u8); sys_exit(0); return 0 } }
38 gw("HTTP-POST RED\n" as *u8); sys_exit(1); return 1
39}