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.
10 ;(write-line 2 (string (date-value) " " (main-args)))
11 (unless (ends-with (main-args 0) ".cgi")
12 (load "siteconfig.lsp")
13 (if (exists file? (list (main-args 1)
14 (string (main-args 1) ".lsp")))
16 (write-line 2 (string "Unknown command " (main-args 1))))
19 ;; This script is executed in (protected) subdirectory www
22 (load "siteconfig.lsp")
24 ;; Needs an HTTP_AUTHORIZATION environment variable
25 (when (empty? (setf AUTH (env "HTTP_AUTHORIZATION")))
26 ;(write-line 2 "needs auth")
27 (write-line 1 (read-file "tmpl/unauthorized.http"))
30 ;; Must find that value in wui.passwd
31 (constant 'PASSWD SITE:wui.passwd)
32 (unless (ref (6 AUTH) (parse (read-file PASSWD) "\n"))
33 (write-line 1 (read-file "tmpl/unauthorized.http"))
36 ;; Determine actual script name respecting given role, if any.
37 (define (role-script (ROLE "."))
38 (let ((CMD (and (regex "([^/]*).cgi$" (main-args 0) 0) $1)))
39 (if (= "." ROLE) (string CMD ".lsp") (format "%s/%s.lsp" ROLE CMD))))
42 REMOTE_USER (and (regex "([^:]+):" (base64-dec (6 AUTH)) 0) $1)
45 (env "REMOTE_USER" REMOTE_USER)
48 (unless (file? SCRIPT)
49 (write 1 "\nBroken.\n")
52 ;(write-line 2 (string (list "script" SCRIPT)))