code wiki / _hdl_build / nx_invite_issue_cli.nx

nx_invite_issue_cli.nx source

↩ module page · 27 lines · 1777 B

1// nx_invite_issue_cli.nx -- issue ONE single-use, expiring invite token into a doc-portal invite store and 2// print the 64-hex SECRET to hand the invitee. The store path = "<daemon-storefile>.invites" (the daemon's 3// dad_invite_path derives this). Run it against a local file then ship that file to the NAS invite path (first 4// invite), OR run it on the NAS. Composes inv_issue (nx_invite_token.nx). 5// nx_invite_issue_cli <invite_store_path> <realm> <level> <ttl_seconds> 6// license_tier: ORIGINAL 7import "nx_invite_token.nx" 8 9func iic_pe(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(2,s,n); return 0 } 10func iic_pp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 11func iic_strlen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 12func iic_atoi(s: *u8) -> i64 { var v: i64=0; var i: i64=0; while s[i]!=(0 as u8){ let c: i64=s[i] as i64; if c>=48 { if c<=57 { v=v*10+(c-48) } } i=i+1 } return v } 13 14func main(argc: i64, argv: *i64) -> i64 { 15 if argc < 5 { iic_pe("usage: nx_invite_issue_cli <invite_store_path> <realm> <level> <ttl_seconds>\n" as *u8); return 2 } 16 let store: *u8 = argv[1] as *u8 17 let realm: *u8 = argv[2] as *u8 18 let level: i64 = iic_atoi(argv[3] as *u8) 19 let ttl: i64 = iic_atoi(argv[4] as *u8) 20 let now: i64 = sys_now_realtime_sec() 21 let tok: *u8 = sys_mmap(NX_INV_TOKEN_HEX + 1) 22 let rc: i64 = inv_issue(store, realm, iic_strlen(realm), level, ttl, now, tok) 23 if rc != NX_INV_OK { iic_pe("inv_issue FAILED (check store path writable / realm space-free / level>=1 / ttl>=1)\n" as *u8); return 1 } 24 tok[NX_INV_TOKEN_HEX] = 0 as u8 25 iic_pp("INVITE-TOKEN " as *u8); sys_write(1, tok, NX_INV_TOKEN_HEX); iic_pp("\n" as *u8) 26 return 0 27}