From 3feeffd680a6d4abfb63b15a40e5246e4969ddf4 Mon Sep 17 00:00:00 2001 From: Ralph Ronnquist Date: Sun, 2 Jan 2022 12:47:44 +1100 Subject: [PATCH] lifted out siteconfig loading to separate script --- command.lsp | 40 +--------------------------------------- manager/Makefile | 5 +++++ manager/basic_login.lsp | 2 ++ manager/hourglass-web | Bin 479008 -> 478589 bytes manager/install.lsp | 12 ++++++++++++ siteconfig.lsp | 38 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 58 insertions(+), 39 deletions(-) create mode 100644 siteconfig.lsp diff --git a/command.lsp b/command.lsp index 8751fc3..6045386 100644 --- a/command.lsp +++ b/command.lsp @@ -2,45 +2,7 @@ # This script is intended as main script for packnl embedding, it # dispatches to the command of the first argument. -(context 'MAIN:SITE) - -(define (set-int K V) (set K (int V 0 10))) - -(define (set-ints K V) - (map (curry set-int K) (clean empty? (parse V "\\s*,?\\s*" 0)))) - -(define (set-list K V) - (map (curry set K) (clean empty? (parse V "\\s*,?\\s*" 0)))) - -(constant - 'FILE "hourglass.conf" - 'KEYS '( - ("libc" set) - ("listener.ports" set-ints) - ("listener.ip" set) - ("listener.activity.dir" set) - ("control.action" set) - ("control.dat" set) - ("control.net" set) - ("control.extra.dat" set) - ("control.usage.dat" set) - ("control.usage.tmp" set) - - ("wui.port" set-int) - ("wui.roles" set) - ("wui.passwd" set) - ) - ) - -(define (setting LINE) - (when (regex "^\\s([^;#][^=]*)=(.*)" LINE 0) - (let ((KV (map trim (list $1 $2)))) - (if (lookup (KV 0) KEYS) (apply $it (list (sym (KV 0)) (KV 1))))))) - -(map setting (parse (or (read-file FILE) "") "\n")) - -#################### -(context MAIN) +(load "siteconfig.lsp") (if (exists file? (list (main-args 1) (string (main-args 1) ".lsp"))) diff --git a/manager/Makefile b/manager/Makefile index 5341048..5de00e0 100644 --- a/manager/Makefile +++ b/manager/Makefile @@ -5,5 +5,10 @@ MAIN = basic_login.lsp LSP = $(filter-out $(MAIN),$(wildcard *.lsp)) OTHER = www/hourglass.css www/images/hourglass.png +LSP += siteconfig.lsp +.INTERMEDIATE: siteconfig.lsp +siteconfig.lsp: ../siteconfig.lsp + cp $< $@ + hourglass-web: $(MAIN) $(LSP) $(TMPL) $(OTHER) packnl -w $@ $^ diff --git a/manager/basic_login.lsp b/manager/basic_login.lsp index f491a9e..8ca9920 100644 --- a/manager/basic_login.lsp +++ b/manager/basic_login.lsp @@ -8,6 +8,8 @@ ;; name to determine th actual script. That lookup will also use the ;; "role base" as declared in "roles.txt" +(load "siteconfig.lsp") + (write-line 2 (string (date-value) " " (main-args))) (unless (ends-with (main-args 0) ".cgi") (if (exists file? (list (main-args 1) diff --git a/manager/hourglass-web b/manager/hourglass-web index b8a4e56f64f058469dfc3a33c5de0934a9658ee2..42cbd571876026fa2e5119f3f423834e1295ef20 100755 GIT binary patch delta 544 zcmY+A&ui0g7{DB*0@hE~G2d26W`W_#i=fnFvFJBb)o)&gfDV0+tRnxI| z@J&_bY8CNAg%x$ZUdL;UvuMi?7`h%GxP6Sh$lvA|xLXV(7H>0;`#}$T{(Tl;6!zH# z^tA3?Ac}}*r>OevKbl{_;RB9LL-a2q$+=e|6uh$^?^%ufns22bL delta 925 zcmZva&1(}u7{wp7&G`gTCFOG%oxkbc+?YE7ZgG-jKEXtAu>X*+bYyY5b! z^iWU<6})+IL_z!uJPCX8=1CAedhw`u@#0ai=wxXmrOuvq_L=8-_BZe0^Zr*a`|meG zjc_Bc5KA|9))7`f@083W>HjJ+oUP4>@tU=R#?u7r!im<$L11$VlcEQ zH&;=q=ng8I7AkcW6-ReHighGYME&=wxKuY%o6Mw0nyy}&*Evy}8i$7M71CCXY0@P*^F+J~EIw9_6XlS<`cf&^uvgD7li8 z>1}P37UgZ{Ml$K(8J-~GeJ5NSWLDWs*$!v6DRLVvT0?`mw9IXH4{NoW|1J+7Lg9&V@uUD7=SVs|d}NoRb?)i`P5)N`E{4M6 zS#dQ11L9c%GQuyy`8%ya+L8!eTCruNs!UVcuU3u66=~^l-Qsaf&R@?jt;mt0mAlk! z*EN~By6J2aBqj^S=5rA)cao~7Z_%KKDqd?aIFQWUENSz{F1@X+2x)NTOev3w==yXt3{p(%@YvGMbqbAJ>8Vu{Ah^p4ha(c99t~MBeYlCZnby@D}tIndMYD@;!&n z5H48+p9ordMQ%tf!N7WkOwUQGCi5I@j?COFnT^K~k0_edkkEO}c6a>Wx8cFhzahaR Ay#N3J diff --git a/manager/install.lsp b/manager/install.lsp index c4193be..6cf0c87 100644 --- a/manager/install.lsp +++ b/manager/install.lsp @@ -6,6 +6,12 @@ (write-line 2 "** directory www exists. aborting") (exit 1)) +(unless (directory? SITE:listener.activity.dir) + (write-line 2 (format "** directory %s doesn't exists. aborting" + SITE:listener.activity.dir + )) + (exit 1)) + (define (copy-out F) (write-file F (read-file F))) @@ -18,3 +24,9 @@ (! "ln -sTf ../hourglass-web www/history.cgi") (! "ln -sTf ../hourglass-web www/usage.cgi") (! "ln -sTf ../hourglass-web www/controls.cgi") + +(define (maybe-touch F (D "")) (unless (file? F) (write-file F D))) + +(maybe-touch SITE:control.dat) +(maybe-touch SITE:control.usage.dat "(0 0)") +(maybe-touch SITE:wui.passwd) diff --git a/siteconfig.lsp b/siteconfig.lsp new file mode 100644 index 0000000..a3bb7b6 --- /dev/null +++ b/siteconfig.lsp @@ -0,0 +1,38 @@ +(context 'MAIN:SITE) + +(define (set-int K V) (set K (int V 0 10))) + +(define (set-ints K V) + (map (curry set-int K) (clean empty? (parse V "\\s*,?\\s*" 0)))) + +(define (set-list K V) + (map (curry set K) (clean empty? (parse V "\\s*,?\\s*" 0)))) + +(constant + 'FILE "hourglass.conf" + 'KEYS '( + ("libc" set) + ("listener.ports" set-ints) + ("listener.ip" set) + ("listener.activity.dir" set) + ("control.action" set) + ("control.dat" set) + ("control.net" set) + ("control.extra.dat" set) + ("control.usage.dat" set) + ("control.usage.tmp" set) + + ("wui.port" set-int) + ("wui.roles" set) + ("wui.passwd" set) + ) + ) + +(define (setting LINE) + (when (regex "^\\s([^;#][^=]*)=(.*)" LINE 0) + (let ((KV (map trim (list $1 $2)))) + (if (lookup (KV 0) KEYS) (apply $it (list (sym (KV 0)) (KV 1))))))) + +(map setting (parse (or (read-file FILE) "") "\n")) + +"siteconfig.lsp" -- 2.39.2