2002-08-22 11:35:51 -04:00
|
|
|
#!/bin/sh
|
2002-08-27 09:58:54 -04:00
|
|
|
echo "Loading..."
|
2004-05-05 12:45:39 -04:00
|
|
|
exec scsh -lel SSAX-4.9/load.scm -lel sunet-2.1/load.scm -dm -o http-test -e main -s "$0" "$@"
|
2002-08-22 11:35:51 -04:00
|
|
|
!#
|
|
|
|
|
|
|
|
(define-structure http-test
|
|
|
|
(export main)
|
|
|
|
(open httpd-core
|
|
|
|
httpd-make-options
|
|
|
|
httpd-basic-handlers
|
2002-08-27 09:58:54 -04:00
|
|
|
httpd-file-directory-handlers
|
2002-12-29 14:10:48 -05:00
|
|
|
httpd-cgi-handlers
|
2003-04-23 03:29:37 -04:00
|
|
|
httpd-seval-handlers
|
2004-05-11 08:04:10 -04:00
|
|
|
scheme-with-scsh
|
|
|
|
srfi-37)
|
2002-08-22 11:35:51 -04:00
|
|
|
|
|
|
|
(begin
|
|
|
|
|
2002-08-27 09:58:54 -04:00
|
|
|
(define (usage)
|
|
|
|
(format #f
|
2004-05-11 08:04:10 -04:00
|
|
|
"Usage: start-web-server
|
|
|
|
[-h DIR | --htdocs-dir=DIR] [-c DIR | --cgi-bin-dir=DIR]
|
|
|
|
[-l FILE | --log-file-name=FILE] [-r NUM | --requests=NUM]
|
|
|
|
[-p NUM | --port=NUM]
|
|
|
|
[--help]
|
2002-08-27 09:58:54 -04:00
|
|
|
|
|
|
|
with
|
|
|
|
htdocs-dir directory of html files (default: web-server/root/htdocs)
|
|
|
|
cgi-bin-dir directory of cgi files (default: web-server/root/cgi-bin)
|
|
|
|
port port server is listening to (default: 8080)
|
|
|
|
log-file-name directory where to store the logfile in CLF
|
2004-05-11 08:10:13 -04:00
|
|
|
(default: /tmp/httpd.log)
|
2002-08-27 09:58:54 -04:00
|
|
|
--help show this help
|
2004-05-11 08:04:10 -04:00
|
|
|
"))
|
|
|
|
|
|
|
|
(define (display-usage)
|
|
|
|
(display (usage) (current-error-port))
|
|
|
|
(exit 1))
|
|
|
|
|
|
|
|
(define default-options
|
|
|
|
`((htdocs-dir . ,(absolute-file-name "web-server/root/htdocs"))
|
|
|
|
(cgi-bin-dir . ,(absolute-file-name "web-server/root/cgi-bin"))
|
|
|
|
(port . 8080)
|
2004-05-11 08:10:13 -04:00
|
|
|
(log-file-name . "/tmp/httpd.log")
|
2004-05-11 08:04:10 -04:00
|
|
|
(requests . 5)))
|
2002-08-27 09:58:54 -04:00
|
|
|
|
2004-05-11 08:04:10 -04:00
|
|
|
(define (raise-usage-error msg . info)
|
|
|
|
(display msg (current-error-port))
|
|
|
|
(for-each
|
|
|
|
(lambda (i)
|
|
|
|
(display i (current-error-port))
|
|
|
|
(display " " (current-error-port)))
|
|
|
|
info)
|
|
|
|
(display "\n" (current-error-port))
|
|
|
|
(exit 1))
|
2002-08-29 06:51:47 -04:00
|
|
|
|
2004-05-11 08:04:10 -04:00
|
|
|
(define (parse-arguments arg-list)
|
|
|
|
(let ((number-option-proc
|
|
|
|
(lambda (alist-key)
|
|
|
|
(lambda (option name arg ops)
|
|
|
|
(cond
|
|
|
|
((not arg)
|
|
|
|
(raise-usage-error "Option requires a number" name arg))
|
|
|
|
((string->number arg)
|
|
|
|
=> (lambda (n) (cons (cons alist-key n) ops)))
|
|
|
|
(else
|
|
|
|
(raise-usage-error "Not a number" arg))))))
|
|
|
|
(absolute-file-name-proc
|
|
|
|
(lambda (alist-key)
|
|
|
|
(lambda (option name arg ops)
|
|
|
|
(cons (cons alist-key
|
|
|
|
(absolute-file-name arg)) ops)))))
|
2002-08-27 09:58:54 -04:00
|
|
|
|
2004-05-11 08:04:10 -04:00
|
|
|
(let ((htdocs-dir-option
|
|
|
|
(option '(#\h "htdocs-dir") #t #f
|
|
|
|
(absolute-file-name-proc 'htdocs-dir)))
|
|
|
|
(cgi-bin-dir-option
|
|
|
|
(option '(#\c "cgi-bin-dir") #t #f
|
|
|
|
(absolute-file-name-proc 'cgi-bin-dir)))
|
|
|
|
(port-option
|
|
|
|
(option '(#\p "port") #t #f
|
|
|
|
(number-option-proc 'port)))
|
|
|
|
(log-file-name-option
|
|
|
|
(option '(#\l "log-file-name") #t #f
|
|
|
|
(absolute-file-name-proc 'log-file-name)))
|
|
|
|
(requests-option
|
|
|
|
(option '(#\r "requests") #t #f
|
|
|
|
(number-option-proc 'requests)))
|
|
|
|
(help-option
|
|
|
|
(option '(#f "help") #f #f
|
|
|
|
(lambda (option name arg ops)
|
|
|
|
(display-usage)))))
|
|
|
|
(args-fold arg-list
|
|
|
|
(list htdocs-dir-option cgi-bin-dir-option
|
|
|
|
port-option log-file-name-option
|
|
|
|
requests-option help-option)
|
|
|
|
(lambda (op name arg ops)
|
|
|
|
(raise-usage-error
|
|
|
|
"Unknown command line argument: " name))
|
|
|
|
cons
|
|
|
|
'()))))
|
2002-08-22 11:35:51 -04:00
|
|
|
|
2004-05-11 08:04:10 -04:00
|
|
|
(define (make-options-from-args cmd-line-args)
|
|
|
|
(let ((given (parse-arguments cmd-line-args)))
|
|
|
|
(map (lambda (p)
|
|
|
|
(or (assoc (car p) given) p))
|
|
|
|
default-options)))
|
|
|
|
|
|
|
|
(define (lookup-option alist option)
|
|
|
|
(cond
|
|
|
|
((assoc option alist)
|
|
|
|
=> cdr)
|
|
|
|
(else
|
|
|
|
(error "Internal error, option not found" option alist))))
|
|
|
|
|
2003-04-22 09:14:50 -04:00
|
|
|
(define (become-nobody-if-root)
|
|
|
|
(cond ((zero? (user-uid))
|
|
|
|
(set-gid (->gid "nobody"))
|
|
|
|
(set-uid (->uid "nobody")))))
|
2002-08-27 09:58:54 -04:00
|
|
|
|
|
|
|
(define (main args)
|
2004-02-03 09:11:26 -05:00
|
|
|
(with-cwd
|
2004-05-11 08:04:10 -04:00
|
|
|
(file-name-directory (car (command-line)))
|
|
|
|
(let ((options (make-options-from-args (cdr args))))
|
2002-08-27 09:58:54 -04:00
|
|
|
|
2004-05-11 08:04:10 -04:00
|
|
|
(format #t "Going to run Webserver with:
|
2002-08-27 09:58:54 -04:00
|
|
|
htdocs-dir: ~a
|
|
|
|
cgi-bin-dir: ~a
|
|
|
|
port: ~a
|
|
|
|
log-file-name: ~a
|
2002-09-20 15:23:17 -04:00
|
|
|
syslogging activated.
|
2002-08-27 09:58:54 -04:00
|
|
|
"
|
2004-05-11 08:04:10 -04:00
|
|
|
(lookup-option options 'htdocs-dir)
|
|
|
|
(lookup-option options 'cgi-bin-dir)
|
|
|
|
(lookup-option options 'port)
|
|
|
|
(lookup-option options 'log-file-name))
|
2002-08-27 09:58:54 -04:00
|
|
|
|
2004-05-11 08:04:10 -04:00
|
|
|
(httpd (make-httpd-options
|
|
|
|
with-port (lookup-option options 'port)
|
|
|
|
with-root-directory (cwd)
|
|
|
|
with-syslog? #t
|
|
|
|
with-log-file (lookup-option options 'log-file-name)
|
|
|
|
with-post-bind-thunk become-nobody-if-root
|
|
|
|
with-request-handler
|
|
|
|
(alist-path-dispatcher
|
|
|
|
(list (cons "cgi-bin" (cgi-handler (lookup-option options 'cgi-bin-dir)))
|
|
|
|
(cons "seval" seval-handler))
|
|
|
|
(tilde-home-dir-handler "public_html"
|
|
|
|
(rooted-file-or-directory-handler
|
|
|
|
(lookup-option options 'htdocs-dir)))))))))
|
|
|
|
))
|
2002-08-22 11:35:51 -04:00
|
|
|
;; EOF
|
2002-08-29 06:51:47 -04:00
|
|
|
|
|
|
|
;;; Local Variables:
|
|
|
|
;;; mode:scheme
|
2004-02-03 08:51:51 -05:00
|
|
|
;;; End:
|