2 ;; This script is written with the expectation that it is an embedded
3 ;; newlisp executable invked via .cgi links from within the
6 ;; Its (main-args 0) has a final path component X.cgi that links to
7 ;; this file as a packnl embedding that will use that X part of its
8 ;; name to determine th actual script. That lookup will also use the
9 ;; "role base" as declared in "roles.txt"
11 (unless (ends-with (main-args 0) ".cgi")
12 (if (exists file? (list (main-args 1)
13 (string (main-args 1) ".lsp")))
15 (write-line 2 (string "Unknown command " (main-args 1))))
18 ;; This script is executed in (protected) subdirectory www
21 ;; Needs an HTTP_AUTHORIZATION environment variable
22 (unless (setf AUTH (env "HTTP_AUTHORIZATION"))
23 (write-line 2 (read-file "tmpl/unauthorized.http"))
26 ;; Must find that value in .htpasswd
27 (unless (ref (6 AUTH) (parse (read-file ".htpasswd") "\n"))
28 (write-line 1 (read-file "tmpl/unauthorized.http"))
32 ROLES (map (fn (x) (parse x ":")) (parse (read-file "roles.txt") "\n"))
33 REMOTE_USER (and (regex "([^:]+):" (base64-dec (6 AUTH)) 0) $1)
34 ROLE (or (lookup REMOTE_USER ROLSE) "child")
35 SCRIPT (format "%s/%s" ROLE (main-args 1))
37 (env "REMOTE_USER" REMOTE_USER)
40 (unless (file? SCRIPT)
41 (write 1 "\nBroken.\n")