interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / apps / interplane-forge / visits / owner.om

156 lines · 3530 bytes Raw Blame History
1note owner.om: the owner's pages, served inside the private network only. Composed after
2note seed/net/http.om and seed/net/notls.om.
3note owner A B C D PORT listen on the IPv4 address A.B.C.D
4note It starts only on a loopback address (127.x.x.x) or a tailnet address (100.64.0.0/10); any other
5note address is refused with exit 1, so the pages cannot be put on a public interface by mistake.
6note It serves three files from the working directory, GET only, one request per connection:
7note / visits.html text/html
8note /tokens.css tokens.css text/css
9note /visits.css visits.css text/css
10note Every other path is 404 and every other method 405. Each answer carries Cache-Control:
11note no-store, X-Robots-Tag: noindex and a policy that allows no script. A file is read whole, at
12note most 1,048,576 bytes. Exit 1 usage or refused address, 2 cannot listen.
13global oarg uchar 32
14text otget "GET"
15text otroot "/"
16text ottok "/tokens.css"
17text otcss "/visits.css"
18text ofhtm "visits.html"
19text oftok "tokens.css"
20text ofcss "visits.css"
21text octn "Content-Type"
22text octh "text/html; charset=utf-8"
23text octc "text/css; charset=utf-8"
24text occn "Cache-Control"
25text occv "no-store"
26text orbn "X-Robots-Tag"
27text orbv "noindex"
28text ocsn "Content-Security-Policy"
29text ocsv "default-src 'none'; style-src 'self'; frame-ancestors 'none'; base-uri 'none'; form-action 'none'"
30note oanum: argument idx as a decimal number; 99999999 when it is not 1 to 5 digits
31fn oanum idx ulong to ulong
32n = argread idx oarg 0 31
33if lt n 1
34ret 99999999
35end
36if gt n 5
37ret 99999999
38end
39v = ulong 0
40i = ulong 0
41while lt i ulong n bound 5
42c = get oarg i
43if or lt c 48 gt c 57
44ret 99999999
45end
46v = add mul v 10 ulong sub c 48
47i = add i 1
48end
49ret v
50end
51note oaddrok: loopback or tailnet only
52fn oaddrok a ulong b ulong to bool
53if eq a 127
54ret true
55end
56if eq a 100
57ret and ge b 64 le b 127
58end
59ret false
60end
61fn ofile cs edit ulong 320 io edit uchar 131072 f view uchar * ct view uchar * to long
62fb = new uchar 1048576 0
63fd = int fopen f 0 len f 0 0
64if lt fd 0
65ret hrsperr cs io 404
66end
67n = ulong 0
68k = long 1
69while gt k 0 bound 1048577
70k = read fd fb n sub 1048576 n
71if gt k 0
72n = add n ulong k
73end
74end
75c = fclose fd
76r = hrspst cs io 200
77r = hfe r hhname cs io octn
78r = hfe r hhval cs io ct
79r = hfe r hhname cs io occn
80r = hfe r hhval cs io occv
81r = hfe r hhname cs io orbn
82r = hfe r hhval cs io orbv
83r = hfe r hhname cs io ocsn
84r = hfe r hhval cs io ocsv
85r = hfe r hhend cs io 0 n
86if gt n 0
87r = hfe r hput cs io part fb 0 n
88end
89ret hfe r hwfin cs io
90end
91fn oserve c int cs edit ulong 320 io edit uchar 131072 to void
92r = hinit cs io c 1
93if lt r 0
94ret
95end
96hsettmo cs 5000000000 5000000000
97k = hreqrd cs io
98if lt k 0
99x = hreject cs io k
100end
101if gt k 0
102if not hismeth cs io otget
103x = hrsperr cs io 405
104else
105if hispath cs io otroot
106x = ofile cs io ofhtm octh
107else
108if hispath cs io ottok
109x = ofile cs io oftok octc
110else
111if hispath cs io otcss
112x = ofile cs io ofcss octc
113else
114x = hrsperr cs io 404
115end
116end
117end
118end
119end
120y = hclose cs
121end
122fn main to int
123cs = new ulong 320 0
124io = new uchar 131072 0
125ad = new uchar 16 0
126if ne argcnt 6
127ret 1
128end
129a = oanum 1
130b = oanum 2
131c = oanum 3
132d = oanum 4
133p = oanum 5
134if or or gt a 255 gt b 255 or gt c 255 gt d 255
135ret 1
136end
137if or lt p 1 gt p 65535
138ret 1
139end
140if not oaddrok a b
141ret 1
142end
143ip = uint add add add shl a 24 shl b 16 shl c 8 d
144r = haddr4 ad ip p
145lf = hlisten ad 16
146if lt lf 0
147ret 2
148end
149for it ulong 4000000000
150s = haccept int lf 1000000000
151if ge s 0
152oserve int s cs io
153end
154end
155ret 0
156end