2002-08-22 11:35:51 -04:00
|
|
|
#!/bin/sh
|
2002-08-27 09:58:54 -04:00
|
|
|
echo "Loading..."
|
2003-02-17 10:46:45 -05:00
|
|
|
exec scsh +lpsd -ll packages.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
|
|
|
|
scheme-with-scsh)
|
2002-08-22 11:35:51 -04:00
|
|
|
|
|
|
|
(begin
|
|
|
|
|
2002-08-27 09:58:54 -04:00
|
|
|
(define (usage)
|
|
|
|
(format #f
|
|
|
|
"Usage: start-web-server [-h htdocs-dir] [-c cgi-bin-dir] [-p port]
|
2002-09-20 15:23:17 -04:00
|
|
|
[-l log-file-name] [--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
|
|
|
|
(default: web-server/httpd.log)
|
|
|
|
--help show this help
|
|
|
|
"
|
|
|
|
))
|
|
|
|
|
2002-08-29 06:51:47 -04:00
|
|
|
(define htdocs-dir #f)
|
|
|
|
(define cgi-bin-dir #f)
|
|
|
|
(define port #f)
|
|
|
|
(define log-file-name #f)
|
|
|
|
(define root #f)
|
|
|
|
|
|
|
|
(define (init)
|
|
|
|
(set! htdocs-dir "web-server/root/htdocs")
|
|
|
|
(set! cgi-bin-dir "web-server/root/cgi-bin")
|
|
|
|
(set! port "8080")
|
|
|
|
(set! log-file-name "web-server/httpd.log")
|
2002-09-20 15:23:17 -04:00
|
|
|
(set! root "web-server/root"))
|
2002-08-27 09:58:54 -04:00
|
|
|
|
|
|
|
(define get-options
|
|
|
|
(let* ((unknown-option-error
|
|
|
|
(lambda (option)
|
|
|
|
(format (error-output-port)
|
|
|
|
"unknown option `~A'~%try `start-web-server --help'~%"
|
|
|
|
option)
|
|
|
|
(exit 1)))
|
|
|
|
(missing-argument-error
|
|
|
|
(lambda (option)
|
|
|
|
(format (error-output-port)
|
|
|
|
"option `~A' requires an argument~%try `start-web-server --help'~%"
|
|
|
|
option)
|
|
|
|
(exit 1))))
|
|
|
|
(lambda (options)
|
|
|
|
(let loop ((options options))
|
|
|
|
(if (null? options)
|
|
|
|
(begin
|
|
|
|
(set! htdocs-dir (absolute-file-name htdocs-dir))
|
|
|
|
(set! log-file-name (absolute-file-name log-file-name))
|
|
|
|
(set! cgi-bin-dir (absolute-file-name cgi-bin-dir))
|
2002-09-20 15:23:17 -04:00
|
|
|
(set! port (string->number port)))
|
2002-08-27 09:58:54 -04:00
|
|
|
(cond
|
|
|
|
((string=? (car options) "-h")
|
|
|
|
(if (null? (cdr options))
|
|
|
|
(missing-argument-error (car options))
|
|
|
|
(set! htdocs-dir (cadr options)))
|
|
|
|
(loop (cddr options)))
|
|
|
|
((string=? (car options) "-c")
|
|
|
|
(if (null? (cdr options))
|
|
|
|
(missing-argument-error (car options))
|
|
|
|
(set! cgi-bin-dir (cadr options)))
|
|
|
|
(loop (cddr options)))
|
|
|
|
((string=? (car options) "-p")
|
|
|
|
(if (null? (cdr options))
|
|
|
|
(missing-argument-error (car options))
|
|
|
|
(set! port (cadr options)))
|
|
|
|
(loop (cddr options)))
|
|
|
|
((string=? (car options) "-l")
|
|
|
|
(if (null? (cdr options))
|
|
|
|
(missing-argument-error (car options))
|
|
|
|
(set! log-file-name (cadr options)))
|
|
|
|
(loop (cddr options)))
|
|
|
|
((string=? (car options) "--help")
|
|
|
|
(display (usage))
|
|
|
|
(exit 0))
|
2002-08-28 11:42:15 -04:00
|
|
|
((string=? (car options) "--dump")
|
|
|
|
(let ((image-name (if (null? (cdr options))
|
2002-09-20 15:23:17 -04:00
|
|
|
"web-server"
|
2002-08-28 11:42:15 -04:00
|
|
|
(cadr options))))
|
|
|
|
(dump-scsh-program main image-name))
|
|
|
|
(exit 0))
|
2002-08-27 09:58:54 -04:00
|
|
|
(else
|
|
|
|
(unknown-option-error (car options)))))))))
|
2002-08-22 11:35:51 -04:00
|
|
|
|
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)
|
2002-08-29 06:51:47 -04:00
|
|
|
(init)
|
2002-09-19 07:07:37 -04:00
|
|
|
(format #t "reading options: ~s~%" (cdr args))
|
2002-08-27 09:58:54 -04:00
|
|
|
(get-options (cdr args))
|
|
|
|
|
|
|
|
(format #t "Going to run Webserver with:
|
|
|
|
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
|
|
|
"
|
|
|
|
htdocs-dir
|
|
|
|
cgi-bin-dir
|
|
|
|
port
|
2002-09-20 15:23:17 -04:00
|
|
|
log-file-name)
|
2002-08-27 09:58:54 -04:00
|
|
|
|
2003-01-28 16:58:33 -05:00
|
|
|
(httpd (make-httpd-options
|
|
|
|
with-port port
|
|
|
|
with-root-directory (cwd)
|
|
|
|
with-syslog? #t
|
2003-02-17 04:52:21 -05:00
|
|
|
with-log-file log-file-name
|
2003-04-22 09:14:50 -04:00
|
|
|
with-post-bind-thunk become-nobody-if-root
|
2003-01-28 16:58:33 -05:00
|
|
|
with-request-handler
|
|
|
|
(alist-path-dispatcher
|
|
|
|
(list (cons "cgi-bin" (cgi-handler cgi-bin-dir)))
|
|
|
|
(tilde-home-dir-handler "public_html"
|
|
|
|
(rooted-file-or-directory-handler
|
2003-02-20 11:37:11 -05:00
|
|
|
htdocs-dir))))))
|
2002-08-22 11:35:51 -04:00
|
|
|
))
|
|
|
|
;; EOF
|
2002-08-29 06:51:47 -04:00
|
|
|
|
|
|
|
;;; Local Variables:
|
|
|
|
;;; mode:scheme
|
|
|
|
;;; End:
|