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 / visits.om

964 lines · 17653 bytes Raw Blame History
1om2
2note visits.om: the owner's view of who visited INTERPLANE. Its own program.
3note visits LOG
4note LOG is forged's access log, one request per line:
5note <epoch> <address> <method> <path> <status> <bytes> <ms>
6note Lines with another shape are counted as skipped. It writes two files in the working directory,
7note each to a .tmp name first, readable by the owner only (mode 0600):
8note visits.tsv every figure as tab-separated lines (T totals, D days, P projects, V visitors)
9note visits.html the same figures as one page with no script
10note A visitor is one network address. The log has no browser name, so people and crawlers are not
11note told apart. A project is the first two segments of the path (/owner/repo), "/" for the home page.
12note Limits: 65,536 visitors, 8,192 projects, 512 days; past a limit the extra are counted under
13note "not listed". Requests whose UTC day is before the first request's day or 512 or more days
14note after it are in the totals and counted as outside the day table.
15note Exit 0 written, 1 usage, 2 log unreadable, 3 write failed.
16const NV ulong 65536
17const NP ulong 8192
18global rb uchar 1048576
19global ln uchar 4096
20global lnl ulong 1
21global fp ulong 20
22global gs ulong 26
23global vkh ulong 65536
24global vrq ulong 65536
25global vby ulong 65536
26global vfs ulong 65536
27global vls ulong 65536
28global vdn ulong 65536
29global vkd uchar 65536
30global vip uchar 3145728
31global pkh ulong 8192
32global prq ulong 8192
33global pun ulong 8192
34global pdn ulong 8192
35global ptx uchar 786432
36global ptl ulong 8192
37global s1 ulong 2097152
38global s2 ulong 1048576
39global drq ulong 512
40global dun ulong 512
41global ob uchar 2097152
42global obl ulong 1
43global pa uchar 1100
44global pl uchar 64
45note gs: 0 requests, 1 bytes, 2 skipped lines, 3 first epoch, 4 last epoch, 5 visitors, 6 projects,
46note 7 visitors not listed, 8 projects not listed, 9 status 2xx, 10 3xx, 11 4xx, 12 5xx, 13 first day,
47note 14 line too long flag, 15 new-slot flag, 16 requests outside the day table, 17 requests from
48note crawlers and tools, 18 from other named agents (browsers), 19 with no agent name, 20 from lines
49note written before forged logged the agent (seven fields), 21 fields in the current line, 22 visitors
50note that are crawlers or tools, 23 visitors that are browsers, 24 the current line's visitor slot
51note vkd: 0 no agent name seen for the visitor, 1 a crawler or tool name seen, 2 only other names seen
52note kws: an agent that contains one of these words, in any letter case, is a crawler or a tool. Lower
53note case, one space between words, each at most 32 bytes. GoogleOther is Google's general crawler and
54note has none of the usual words in it; on the first day of logging it was 525 of 553 named requests.
55text kws "bot crawl spider slurp googleother google- mediapartners feedfetcher facebookexternalhit preview curl wget python go-http java/ scrapy httpclient libwww headless okhttp aiohttp axios node-fetch"
56text fhtml "visits.html"
57text fhtmp "visits.html.tmp"
58text ftsv "visits.tsv"
59text fttmp "visits.tsv.tmp"
60text x01 "<!doctype html><html lang='en' data-theme='dark'><head><meta charset='utf-8'><meta name='viewport' content='width=device-width,initial-scale=1'><meta name='robots' content='noindex'>"
61text x02 "<title>Who visited INTERPLANE</title><link rel='stylesheet' href='tokens.css'><link rel='stylesheet' href='visits.css'></head><body><main>\n"
62text x03 "<p class='eyebrow'>Owner only</p><h1>Who visited INTERPLANE</h1><p class='sub'>From the server's own log on your machine. Nothing here leaves it. A visitor is one network address. A crawler or tool is a visitor whose name says so (bot, crawl, spider, GoogleOther, curl, python and the like); any other name counts as a browser, and a tool can still call itself one.</p>\n<dl class='stats'>"
63text x04 "<div><dt>Requests</dt><dd>"
64text x05 "</dd></div><div><dt>Visitors</dt><dd>"
65text x06 "</dd></div><div><dt>Projects visited</dt><dd>"
66text x07 "</dd></div><div><dt>Megabytes served</dt><dd>"
67text x08 "</dd></div></dl>\n<p class='sub'>From "
68text x09 " to "
69text x10 " UTC. Answers: "
70text x11 " fine, "
71text x12 " redirected, "
72text x13 " refused or not found, "
73text x14 " server errors. Lines not understood: "
74text y1 ".</p>\n<p class='sub'>Who asked: "
75text y2 " requests from crawlers and tools, "
76text y3 " from browsers, "
77text y4 " gave no name, "
78text y5 " are from before names were recorded. Visitors: "
79text y6 " crawlers and tools, "
80text y7 " browsers"
81text ykc "crawler or tool"
82text yko "browser"
83text x15 ".</p>\n<h2>By day</h2><table><thead><tr><th>Day (UTC)</th><th>Requests</th><th>Visitors</th></tr></thead><tbody>\n"
84text x16 "</tbody></table>\n<h2>Most visited projects</h2><table><thead><tr><th>Project</th><th>Requests</th><th>Visitors</th></tr></thead><tbody>\n"
85text x17 "</tbody></table>\n<h2>Most active visitors</h2><table><thead><tr><th>Address</th><th>Requests</th><th>Megabytes</th><th>First seen (UTC)</th><th>Last seen (UTC)</th><th>Kind</th></tr></thead><tbody>\n"
86text x18 "</tbody></table>\n<p class='sub'>Not listed above: "
87text x19 " visitors and "
88text x20 " projects past the table limits; "
89text x21 " requests outside the 512-day table.</p></main></body></html>\n"
90text xtr "<tr><td>"
91text xtd "</td><td>"
92text xte "</td></tr>\n"
93text xamp "&amp;"
94text xlt "&lt;"
95text xgt "&gt;"
96note ---- output buffer
97fn wb c uchar to void
98o = get obl 0
99if lt o 2097151
100put ob o c
101put obl 0 add o 1
102end
103end
104fn wt t view uchar * to void
105for i ulong len t bound 400
106wb get t i
107end
108end
109fn wn v ulong to void
110d = new uchar 20 0
111n = ulong 0
112x = v
113if eq x 0
114wb 48
115end
116while gt x 0 bound 20
117put d n uchar add 48 rem x 10
118x = div x 10
119n = add n 1
120end
121while gt n 0 bound 20
122n = sub n 1
123wb get d n
124end
125end
126fn w2 v ulong to void
127wb uchar add 48 rem div v 10 10
128wb uchar add 48 rem v 10
129end
130note wnc: a number for reading, digits grouped in threes (1,417,491); the page uses it, the TSV does not
131fn wnc v ulong to void
132d = new uchar 20 0
133n = ulong 0
134x = v
135if eq x 0
136wb 48
137end
138while gt x 0 bound 20
139put d n uchar add 48 rem x 10
140x = div x 10
141n = add n 1
142end
143while gt n 0 bound 20
144n = sub n 1
145wb get d n
146if gt n 0
147if eq rem n 3 0
148wb 44
149end
150end
151end
152end
153note wesc: one byte, HTML-escaped; a quote or control byte becomes "?"
154fn wesc c uchar to void
155if eq c 38
156wt xamp
157ret
158end
159if eq c 60
160wt xlt
161ret
162end
163if eq c 62
164wt xgt
165ret
166end
167if or or lt c 32 gt c 126 or eq c 34 eq c 39
168wb 63
169ret
170end
171wb c
172end
173note wcell: one byte of a name; as it is in the TSV, HTML-escaped in the page
174fn wcell c uchar tsv bool to void
175if tsv
176wb c
177else
178wesc c
179end
180end
181fn wymd days ulong to void
182z = add days 719468
183era = div z 146097
184doe = sub z mul era 146097
185t = sub doe div doe 1460
186t = add t div doe 36524
187t = sub t div doe 146096
188yoe = div t 365
189y = add yoe mul era 400
190doy = sub doe sub add mul 365 yoe div yoe 4 div yoe 100
191mp = div add mul 5 doy 2 153
192d = add sub doy div add mul 153 mp 2 5 1
193m = add mp 3
194if ge mp 10
195m = sub mp 9
196end
197if le m 2
198y = add y 1
199end
200wn y
201wb 45
202w2 m
203wb 45
204w2 d
205end
206fn wtime s ulong to void
207r = rem s 86400
208wymd div s 86400
209wb 32
210w2 div r 3600
211wb 58
212w2 div rem r 3600 60
213end
214note ---- the current line
215note psplit: field starts and ends into fp (start k at 2k, end at 2k+1); true for seven fields (lines
216note written before forged logged the agent) or nine; the count goes to gs 21
217fn psplit to bool
218n = get lnl 0
219k = ulong 0
220a = ulong 0
221i = ulong 0
222while lt i n bound 4096
223if eq get ln i 32
224if ge k 9
225ret false
226end
227put fp mul k 2 a
228put fp add mul k 2 1 i
229k = add k 1
230a = add i 1
231end
232i = add i 1
233end
234if and ne k 6 ne k 8
235ret false
236end
237put fp mul k 2 a
238put fp add mul k 2 1 n
239put gs 21 add k 1
240ret true
241end
242note pnum: field k as a number; a non-digit gives 2^63
243fn pnum k ulong to ulong
244a = get fp mul k 2
245b = get fp add mul k 2 1
246if ge a b
247ret 9223372036854775808
248end
249if gt sub b a 18
250ret 9223372036854775808
251end
252v = ulong 0
253i = a
254while lt i b bound 18
255c = get ln i
256if or lt c 48 gt c 57
257ret 9223372036854775808
258end
259v = add mul v 10 ulong sub c 48
260i = add i 1
261end
262ret v
263end
264note hspan: FNV-1a 64 of ln a..b, started from seed; never 0
265fn hspan a ulong b ulong seed ulong to ulong
266h = seed
267i = a
268while lt i b bound 4096
269h = mul xor h ulong get ln i 1099511628211
270i = add i 1
271end
272if eq h 0
273ret 1
274end
275ret h
276end
277note pkey: the end of the project key in the path a..b: two segments, cut at "?"
278fn pkey a ulong b ulong to ulong
279i = add a 1
280s = ulong 0
281while lt i b bound 4096
282c = get ln i
283if eq c 63
284ret i
285end
286if eq c 47
287s = add s 1
288if ge s 2
289ret i
290end
291end
292i = add i 1
293end
294ret b
295end
296note sadd1, sadd2: add a hash to a set; true when it was not there. A full set answers false.
297fn sadd1 h ulong to bool
298i = and h 2097151
299n = ulong 0
300while lt n 2097152 bound 2097152
301k = get s1 i
302if eq k h
303ret false
304end
305if eq k 0
306put s1 i h
307ret true
308end
309i = and add i 1 2097151
310n = add n 1
311end
312ret false
313end
314fn sadd2 h ulong to bool
315i = and h 1048575
316n = ulong 0
317while lt n 1048576 bound 1048576
318k = get s2 i
319if eq k h
320ret false
321end
322if eq k 0
323put s2 i h
324ret true
325end
326i = and add i 1 1048575
327n = add n 1
328end
329ret false
330end
331note vslot: the visitor slot for hash h, claimed when new (gs 15 = 1 then); NV when the table is full
332fn vslot h ulong to ulong
333i = and h 65535
334n = ulong 0
335put gs 15 0
336while lt n 65536 bound 65536
337k = get vkh i
338if eq k h
339ret i
340end
341if eq k 0
342put vkh i h
343put gs 15 1
344ret i
345end
346i = and add i 1 65535
347n = add n 1
348end
349ret NV
350end
351fn pslot h ulong to ulong
352i = and h 8191
353n = ulong 0
354put gs 15 0
355while lt n 8192 bound 8192
356k = get pkh i
357if eq k h
358ret i
359end
360if eq k 0
361put pkh i h
362put gs 15 1
363ret i
364end
365i = and add i 1 8191
366n = add n 1
367end
368ret NP
369end
370note vname: keep the address ln a..b (at most 47 bytes) for visitor slot v
371fn vname v ulong a ulong b ulong to void
372n = sub b a
373if gt n 47
374n = ulong 47
375end
376o = mul v 48
377i = ulong 0
378while lt i n bound 47
379c = get ln add a i
380put vip add o i c
381i = add i 1
382end
383put vip add o 47 uchar n
384end
385note pvisit: count this request for its visitor; the visitor hash
386fn pvisit t ulong by ulong to ulong
387a = get fp 2
388b = get fp 3
389h = hspan a b 14695981039346656037
390v = vslot h
391put gs 24 v
392if eq v NV
393put gs 7 add get gs 7 1
394ret h
395end
396if eq get gs 15 1
397put gs 5 add get gs 5 1
398put vfs v t
399vname v a b
400end
401put vrq v add get vrq v 1
402put vby v add get vby v by
403put vls v t
404ret h
405end
406note phas: ln[a, b) contains kws[s, e), in any letter case; e - s is at most 32. A position is
407note left at its first byte that differs, so most positions cost one compare.
408fn phas a ulong b ulong s ulong e ulong to bool
409m = sub e s
410i = a
411while le add i m b bound 4096
412hit = true
413j = ulong 0
414while and hit lt j m bound 32
415x = ulong get ln add i j
416if and ge x 65 le x 90
417x = add x 32
418end
419if ne x ulong get kws add s j
420hit = false
421end
422j = add j 1
423end
424if hit
425ret true
426end
427i = add i 1
428end
429ret false
430end
431note pauto: ln[a, b) contains one of the words of kws
432fn pauto a ulong b ulong to bool
433n = len kws
434s = ulong 0
435i = ulong 0
436while le i n bound 512
437cut = eq i n
438if lt i n
439cut = eq get kws i 32
440end
441if cut
442if and gt i s le sub i s 32
443if phas a b s i
444ret true
445end
446end
447s = add i 1
448end
449i = add i 1
450end
451ret false
452end
453note pagent: count the request by its agent name (field 8) and mark its visitor. A crawler name
454note wins over any other name the same address used.
455fn pagent to void
456if ne get gs 21 9
457put gs 20 add get gs 20 1
458ret
459end
460a = get fp 14
461b = get fp 15
462v = get gs 24
463if or ge a b and eq sub b a 1 eq get ln a 45
464put gs 19 add get gs 19 1
465ret
466end
467if pauto a b
468put gs 17 add get gs 17 1
469if lt v NV
470put vkd v 1
471end
472ret
473end
474put gs 18 add get gs 18 1
475if lt v NV
476if eq get vkd v 0
477put vkd v 2
478end
479end
480end
481note pname: keep the project key ln a..e (at most 95 bytes) for project slot p
482fn pname p ulong a ulong e ulong to void
483n = sub e a
484if gt n 95
485n = ulong 95
486end
487o = mul p 96
488i = ulong 0
489while lt i n bound 95
490c = get ln add a i
491put ptx add o i c
492i = add i 1
493end
494put ptl p n
495end
496note pproj: count this request for its project; vh is the visitor hash
497fn pproj vh ulong to void
498a = get fp 6
499b = get fp 7
500e = pkey a b
501h = hspan a e 14695981039346656037
502p = pslot h
503if eq p NP
504put gs 8 add get gs 8 1
505ret
506end
507if eq get gs 15 1
508put gs 6 add get gs 6 1
509pname p a e
510end
511put prq p add get prq p 1
512if sadd2 xor mul h 1099511628211 vh
513put pun p add get pun p 1
514end
515end
516note pline: one log line
517fn pline to void
518if not psplit
519put gs 2 add get gs 2 1
520ret
521end
522t = pnum 0
523st = pnum 4
524by = pnum 5
525if or or ge t 9223372036854775808 ge st 9223372036854775808 ge by 9223372036854775808
526put gs 2 add get gs 2 1
527ret
528end
529if ge get fp 6 get fp 7
530put gs 2 add get gs 2 1
531ret
532end
533if ne get ln get fp 6 47
534put gs 2 add get gs 2 1
535ret
536end
537if eq get gs 0 0
538put gs 3 t
539put gs 13 div t 86400
540end
541put gs 0 add get gs 0 1
542put gs 1 add get gs 1 by
543put gs 4 t
544c = div st 100
545if and ge c 2 le c 5
546put gs add 7 c add get gs add 7 c 1
547end
548vh = pvisit t by
549pagent
550day = div t 86400
551if ge day get gs 13
552d = sub day get gs 13
553if lt d 512
554put drq d add get drq d 1
555if sadd1 xor mul vh 1099511628211 day
556put dun d add get dun d 1
557end
558else
559put gs 16 add get gs 16 1
560end
561else
562put gs 16 add get gs 16 1
563end
564pproj vh
565end
566note pbytes: n bytes of the read buffer
567fn pbytes n ulong to void
568i = ulong 0
569while lt i n bound 1048576
570c = get rb i
571if eq c 10
572if eq get gs 14 0
573pline
574else
575put gs 2 add get gs 2 1
576end
577put lnl 0 0
578put gs 14 0
579else
580m = get lnl 0
581if lt m 4095
582put ln m c
583put lnl 0 add m 1
584else
585put gs 14 1
586end
587end
588i = add i 1
589end
590end
591note ---- report
592fn rdays tsv bool to void
593d = ulong 0
594while lt d 512 bound 512
595if gt get drq d 0
596if tsv
597wb 68
598wb 9
599wymd add get gs 13 d
600wb 9
601wn get drq d
602wb 9
603wn get dun d
604wb 10
605else
606wt xtr
607wymd add get gs 13 d
608wt xtd
609wnc get drq d
610wt xtd
611wnc get dun d
612wt xte
613end
614end
615d = add d 1
616end
617end
618note ptop: the unprinted project with the most requests, or NP
619fn ptop to ulong
620best = NP
621m = ulong 0
622i = ulong 0
623while lt i 8192 bound 8192
624if eq get pdn i 0
625if gt get prq i m
626m = get prq i
627best = i
628end
629end
630i = add i 1
631end
632ret best
633end
634fn rproj tsv bool to void
635k = ulong 0
636while lt k 25 bound 25
637p = ptop
638if lt p NP
639put pdn p 1
640if tsv
641wb 80
642wb 9
643else
644wt xtr
645end
646n = get ptl p
647i = ulong 0
648while lt i n bound 96
649wcell get ptx add mul p 96 i tsv
650i = add i 1
651end
652if tsv
653wb 9
654wn get prq p
655wb 9
656wn get pun p
657wb 10
658else
659wt xtd
660wnc get prq p
661wt xtd
662wnc get pun p
663wt xte
664end
665end
666k = add k 1
667end
668end
669fn vtop to ulong
670best = NV
671m = ulong 0
672i = ulong 0
673while lt i 65536 bound 65536
674if eq get vdn i 0
675if gt get vrq i m
676m = get vrq i
677best = i
678end
679end
680i = add i 1
681end
682ret best
683end
684fn rvis tsv bool to void
685k = ulong 0
686while lt k 40 bound 40
687v = vtop
688if lt v NV
689put vdn v 1
690if tsv
691wb 86
692wb 9
693else
694wt xtr
695end
696n = ulong get vip add mul v 48 47
697i = ulong 0
698while lt i n bound 48
699wcell get vip add mul v 48 i tsv
700i = add i 1
701end
702if tsv
703wb 9
704wn get vrq v
705wb 9
706wn get vby v
707wb 9
708wn get vfs v
709wb 9
710wn get vls v
711wb 9
712wb vkc get vkd v
713wb 10
714else
715wt xtd
716wnc get vrq v
717wt xtd
718wnc div get vby v 1048576
719wt xtd
720wtime get vfs v
721wt xtd
722wtime get vls v
723wt xtd
724if eq get vkd v 1
725wt ykc
726end
727if eq get vkd v 2
728wt yko
729end
730wt xte
731end
732end
733k = add k 1
734end
735end
736fn rclear to void
737i = ulong 0
738while lt i 65536 bound 65536
739put vdn i 0
740i = add i 1
741end
742j = ulong 0
743while lt j 8192 bound 8192
744put pdn j 0
745j = add j 1
746end
747end
748note rkinds: visitors by kind into gs 22 and 23
749fn rkinds to void
750put gs 22 0
751put gs 23 0
752i = ulong 0
753while lt i 65536 bound 65536
754if ne get vkh i 0
755if eq get vkd i 1
756put gs 22 add get gs 22 1
757end
758if eq get vkd i 2
759put gs 23 add get gs 23 1
760end
761end
762i = add i 1
763end
764end
765note vkc: the kind letter of the TSV: c crawler, o other named agent, - no name seen
766fn vkc k uchar to uchar
767if eq k 1
768ret 99
769end
770if eq k 2
771ret 111
772end
773ret 45
774end
775fn rtsv to void
776put obl 0 0
777rkinds
778wb 65
779wb 9
780wn get gs 17
781wb 9
782wn get gs 18
783wb 9
784wn get gs 19
785wb 9
786wn get gs 20
787wb 9
788wn get gs 22
789wb 9
790wn get gs 23
791wb 10
792wb 84
793wb 9
794wn get gs 0
795wb 9
796wn get gs 5
797wb 9
798wn get gs 6
799wb 9
800wn get gs 1
801wb 9
802wn get gs 3
803wb 9
804wn get gs 4
805wb 9
806wn get gs 9
807wb 9
808wn get gs 10
809wb 9
810wn get gs 11
811wb 9
812wn get gs 12
813wb 9
814wn get gs 2
815wb 9
816wn get gs 7
817wb 9
818wn get gs 8
819wb 9
820wn get gs 16
821wb 10
822rdays true
823rproj true
824rvis true
825end
826fn rhtml to void
827put obl 0 0
828wt x01
829wt x02
830wt x03
831wt x04
832wnc get gs 0
833wt x05
834wnc get gs 5
835wt x06
836wnc get gs 6
837wt x07
838wnc div get gs 1 1048576
839wt x08
840wtime get gs 3
841wt x09
842wtime get gs 4
843wt x10
844wnc get gs 9
845wt x11
846wnc get gs 10
847wt x12
848wnc get gs 11
849wt x13
850wnc get gs 12
851wt x14
852wnc get gs 2
853wt y1
854wnc get gs 17
855wt y2
856wnc get gs 18
857wt y3
858wnc get gs 19
859wt y4
860wnc get gs 20
861wt y5
862wnc get gs 22
863wt y6
864wnc get gs 23
865wt y7
866wt x15
867rdays false
868wt x16
869rproj false
870wt x17
871rvis false
872wt x18
873wnc get gs 7
874wt x19
875wnc get gs 8
876wt x20
877wnc get gs 16
878wt x21
879end
880note ---- files
881fn wren a view uchar * b view uchar * to bool
882la = len a
883lb = len b
884put pl 0 2
885put pl 1 0
886put pl 2 uchar la
887put pl 3 0
888i = ulong 0
889while lt i la bound 28
890put pl add 4 i get a i
891i = add i 1
892end
893o = add 4 la
894put pl o uchar lb
895put pl add o 1 0
896k = ulong 0
897while lt k lb bound 28
898put pl add add o 2 k get b k
899k = add k 1
900end
901ret eq renames pl 0 add add o 2 lb 0 0
902end
903fn wfile tmp view uchar * fin view uchar * to bool
904fd = int fopen tmp 0 len tmp 577 384
905if lt fd 0
906ret false
907end
908r = fchmod fd 384
909n = get obl 0
910o = ulong 0
911ok = true
912while lt o n bound 2097152
913k = write fd ob o sub n o
914if le k 0
915ok = false
916o = n
917else
918o = add o ulong k
919end
920end
921r = fsync fd
922r = fclose fd
923if not ok
924ret false
925end
926ret wren tmp fin
927end
928fn main to int
929if ne argcnt 2
930ret 1
931end
932n = argread 1 pa 0 1023
933if lt n 1
934ret 1
935end
936fd = int fopen pa 0 ulong n 0 0
937if lt fd 0
938ret 2
939end
940k = long 1
941while gt k 0 bound 9223372036854775807
942k = read fd rb 0 1048576
943if gt k 0
944pbytes ulong k
945end
946end
947r = fclose fd
948if lt k 0
949ret 2
950end
951if gt get lnl 0 0
952put gs 2 add get gs 2 1
953end
954rtsv
955if not wfile fttmp ftsv
956ret 3
957end
958rclear
959rhtml
960if not wfile fhtmp fhtml
961ret 3
962end
963ret 0
964end