nx_blocklist_view.nx source
↩ module page · 69 lines · 4695 B
1// nx_blocklist_view.nx -- renders the supervised blocklist (from seg_store) as a VIEWABLE HTML page: every entry with
2// its full justification (fingerprint / category / authority / date / ref / status) and, for PENDING entries, an
3// approve/reject ACTION link the operator clicks on the page. XSS-escaped. Now on the canonical nx_tabrec
4// (tr_cat/tr_field/tr_field_eq); only the view-specific helpers (blv_esc/blv_td) remain local. license_tier: ORIGINAL
5import "nx_blocklist_store.nx"
6import "nx_tabrec.nx"
7const K_MAGIC_1048576: i64 = 1048576
8
9// append src[0..slen) HTML-escaped
10func blv_esc(buf: *u8, off: i64, src: *u8, slen: i64) -> i64 {
11 var o: i64=off; var i: i64=0
12 while i<slen { let c: i64=src[i] as i64
13 if c==0x26 { o=tr_cat(buf,o,"&" as *u8) } else { if c==0x3c { o=tr_cat(buf,o,"<" as *u8) } else { if c==0x3e { o=tr_cat(buf,o,">" as *u8) } else { if c==0x22 { o=tr_cat(buf,o,""" as *u8) } else { buf[o]=src[i]; o=o+1 } } } }
14 i=i+1 }
15 return o
16}
17// emit "<td>" + escaped field `fidx` of record [0,rlen)
18func blv_td(out: *u8, o: i64, rec: *u8, rlen: i64, fidx: i64, f2: *i64) -> i64 {
19 var p: i64=tr_cat(out, o, "<td>" as *u8)
20 if tr_field(rec, 0, rlen, fidx, f2)==1 { p=blv_esc(out, p, ((rec as i64)+f2[0]) as *u8, f2[1]) }
21 return p
22}
23
24// render the whole blocklist under `prefix` into out; returns length.
25func bl_render_html(prefix: *u8, out: *u8) -> i64 {
26 var o: i64=0
27 o=tr_cat(out,o,"<!DOCTYPE html><meta charset=utf-8><meta name=viewport content='width=device-width,initial-scale=1'><title>do-not-recover blocklist</title>" as *u8)
28 o=tr_cat(out,o,"<style>body{font-family:system-ui,Arial;margin:18px;color:#111}table{border-collapse:collapse;width:100%}td,th{border:1px solid #cbd2d9;padding:6px 9px;font-size:13px;text-align:left}th{background:#f5f7fa}code{font-family:Menlo,monospace}tr.pending td{background:#fff3cd}tr.approved td{background:#e3f4e7}tr.retracted td{background:#eee;color:#888}a.btn{display:inline-block;padding:3px 9px;border-radius:5px;text-decoration:none;font-size:12px}a.ok{background:#1a7f37;color:#fff}a.no{background:#b42318;color:#fff}</style>" as *u8)
29 o=tr_cat(out,o,"<h2>Do-not-recover blocklist</h2><p>Supervised — every entry shows who authorized it and why. <b>PENDING entries do NOT block</b> until you approve them here. Stored append-only on seg_store; history is never deleted.</p>" as *u8)
30 o=tr_cat(out,o,"<table><tr><th>fingerprint<th>category<th>authority<th>date<th>ref<th>status<th>action</tr>" as *u8)
31 let idxbuf: *u8=sys_mmap(K_MAGIC_1048576)
32 let il: i64=bl_index_pfx(prefix, idxbuf)
33 let po: *i64=sys_mmap(16) as *i64
34 let lo: *i64=sys_mmap(16) as *i64
35 let f2: *i64=sys_mmap(16) as *i64
36 let idz: *u8=sys_mmap(512)
37 var ls: i64=0; var i: i64=0
38 while i<=il {
39 var eol: i64=0
40 if i==il { eol=1 } else { if idxbuf[i]==10 as u8 { eol=1 } }
41 if eol==1 { if i>ls {
42 var c: i64=0; while c<i-ls { idz[c]=idxbuf[ls+c]; c=c+1 } idz[i-ls]=0 as u8
43 if bl_get_pfx(prefix, idz, po, lo)==1 {
44 let rec: *u8=po[0] as *u8
45 let rlen: i64=lo[0]
46 let isp: i64=tr_field_eq(rec, rlen, 6, "pending" as *u8, f2)
47 let isa: i64=tr_field_eq(rec, rlen, 6, "approved" as *u8, f2)
48 o=tr_cat(out,o,"<tr class=" as *u8)
49 if isp==1 { o=tr_cat(out,o,"pending>" as *u8) } else { if isa==1 { o=tr_cat(out,o,"approved>" as *u8) } else { o=tr_cat(out,o,"retracted>" as *u8) } }
50 o=tr_cat(out,o,"<td><code>" as *u8)
51 if tr_field(rec,0,rlen,0,f2)==1 { o=blv_esc(out,o,((rec as i64)+f2[0]) as *u8, f2[1]) }
52 o=tr_cat(out,o,"</code>" as *u8)
53 o=blv_td(out,o,rec,rlen,2,f2)
54 o=blv_td(out,o,rec,rlen,3,f2)
55 o=blv_td(out,o,rec,rlen,4,f2)
56 o=blv_td(out,o,rec,rlen,5,f2)
57 o=blv_td(out,o,rec,rlen,6,f2)
58 o=tr_cat(out,o,"<td>" as *u8)
59 if isp==1 {
60 o=tr_cat(out,o,"<a class='btn ok' href=/blocklist/approve?id=" as *u8); o=blv_esc(out,o,idz,i-ls); o=tr_cat(out,o,">approve</a> <a class='btn no' href=/blocklist/retract?id=" as *u8); o=blv_esc(out,o,idz,i-ls); o=tr_cat(out,o,">reject</a>" as *u8)
61 } else { if isa==1 { o=tr_cat(out,o,"<a class='btn no' href=/blocklist/retract?id=" as *u8); o=blv_esc(out,o,idz,i-ls); o=tr_cat(out,o,">retract</a>" as *u8) } else { o=tr_cat(out,o,"—" as *u8) } }
62 o=tr_cat(out,o,"</tr>" as *u8)
63 }
64 } ls=i+1 }
65 i=i+1
66 }
67 o=tr_cat(out,o,"</table>" as *u8)
68 return o
69}