code wiki / _hdl_build / nx_vroom_html.nx
nx_vroom_html.nx source
↩ module page · 69 lines · 3742 B
1// nx_vroom_html.nx -- fast HTML-only deploy: streams web_assets/vroom_client.html to the NAS
2// over the sovereign SSH client. With the daemon's per-request client read, the new page is
3// LIVE on the next request (no daemon rebuild/restart). pw from /tmp/nxpw. license_tier: ORIGINAL
4import "nx_syscalls.nx"
5import "nx_ssh_lib.nx"
6const K_MAGIC_1048576: i64 = 1048576
7const K_MAGIC_16384: i64 = 16384
8const K_MAGIC_65536: i64 = 65536
9const K_MAGIC_1024: i64 = 1024
10
11func slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=0 as u8 { n=n+1 } return n }
12
13// stream data to remote run as `wcmd` (copied from nx_ssh_put.nx -- not exported by nx_ssh_lib)
14func ssh_put_file(st: *SshState, wcmd: *u8, wcmdlen: i64, data: *u8, datalen: i64) -> i64 {
15 let co: *u8 = sys_mmap(64); var c: i64 = 0
16 c = ssh_put_byte(co, c, 90); c = ssh_put_str(co, c, "session" as *u8, 7)
17 c = ssh_put_u32(co, c, 0); c = ssh_put_u32(co, c, K_MAGIC_1048576); c = ssh_put_u32(co, c, K_MAGIC_16384)
18 ssh_enc_send(st, co, c)
19 let rep: *u8 = sys_mmap(K_MAGIC_65536); var rcid: i64 = 0 - 1; var guard: i64 = 0
20 while rcid < 0 {
21 if guard > 16 { return 0 - 1 }
22 let rl: i64 = ssh_enc_recv(st, rep); if rl < 0 { return 0 - 1 }
23 if rep[0] == 91 as u8 { rcid = ssh_u32be(rep, 5) }
24 if rep[0] == 92 as u8 { return 0 - 2 }
25 guard = guard + 1
26 }
27 let cr: *u8 = sys_mmap(K_MAGIC_1024); var q: i64 = 0
28 q = ssh_put_byte(cr, q, 98); q = ssh_put_u32(cr, q, rcid); q = ssh_put_str(cr, q, "exec" as *u8, 4); q = ssh_put_byte(cr, q, 1); q = ssh_put_str(cr, q, wcmd, wcmdlen)
29 ssh_enc_send(st, cr, q)
30 var off: i64 = 0
31 while off < datalen {
32 var nn: i64 = datalen - off; if nn > K_MAGIC_16384 { nn = K_MAGIC_16384 }
33 let dp: *u8 = sys_mmap(nn + 64); var p: i64 = 0
34 p = ssh_put_byte(dp, p, 94); p = ssh_put_u32(dp, p, rcid); p = ssh_put_u32(dp, p, nn)
35 var i: i64 = 0; while i < nn { dp[p + i] = data[off + i]; i = i + 1 } p = p + nn
36 ssh_enc_send(st, dp, p)
37 off = off + nn
38 }
39 let eo: *u8 = sys_mmap(16); var e: i64 = 0; e = ssh_put_byte(eo, e, 96); e = ssh_put_u32(eo, e, rcid); ssh_enc_send(st, eo, e)
40 var done: i64 = 0; var loops: i64 = 0
41 while done == 0 {
42 if loops > K_MAGIC_16384 { done = 1 }
43 let rl: i64 = ssh_enc_recv(st, rep); if rl < 0 { done = 1 } else { if rep[0] == 97 as u8 { done = 1 } }
44 loops = loops + 1
45 }
46 let clo: *u8 = sys_mmap(16); var k: i64 = 0; k = ssh_put_byte(clo, k, 97); k = ssh_put_u32(clo, k, rcid); ssh_enc_send(st, clo, k)
47 return 0
48}
49
50func main() -> i64 {
51 let pwbox: *i64 = sys_mmap(16) as *i64
52 let pw: *u8 = sys_read_file("/tmp/nxpw" as *u8, pwbox)
53 if (pw as i64) == 0 { ssh_puts("no /tmp/nxpw\n" as *u8); return 1 }
54 var pwlen: i64 = pwbox[0]
55 while pwlen > 0 { if pw[pwlen-1] == 10 as u8 { pwlen = pwlen - 1 } else { if pw[pwlen-1] == 13 as u8 { pwlen = pwlen - 1 } else { break } } }
56
57 let hbox: *i64 = sys_mmap(16) as *i64
58 let html: *u8 = sys_read_file("web_assets/vroom_client.html" as *u8, hbox)
59 if (html as i64) == 0 { ssh_puts("no vroom_client.html\n" as *u8); return 4 }
60
61 let st: *SshState = sys_mmap(SSH_STATE_BYTES) as *SshState
62 if ssh_open_session(st, (192 << 24) | (168 << 16) | (8 << 8) | 227) != 0 { ssh_puts("session fail\n" as *u8); return 2 }
63 if ssh_userauth_password(st, "elderwesto" as *u8, 10, pw, pwlen) != 1 { ssh_puts("auth fail\n" as *u8); sys_close(st.fd); return 3 }
64 let wcmd: *u8 = "cat > /volume1/homes/elderwesto/nishihost/vroom_client.html" as *u8
65 ssh_put_file(st, wcmd, slen(wcmd), html, hbox[0])
66 ssh_puts("[vroom_client.html uploaded -- live via per-request read]\n" as *u8)
67 sys_close(st.fd)
68 return 0
69}