2002-09-20 15:23:17 -04:00
|
|
|
#!/bin/sh
|
|
|
|
echo "Loading..."
|
2002-09-26 08:13:01 -04:00
|
|
|
fullpath=`which $0`
|
2003-11-21 14:05:02 -05:00
|
|
|
# $sunet is either $SUNET or created out of fullpath
|
|
|
|
# Kind of a hack, I know. We're still waiting for this library
|
|
|
|
#installing system.
|
|
|
|
sunethome=${SUNET:-`dirname $fullpath`/../..}
|
|
|
|
ssaxhome=${SSAX:-`dirname $fullpath`/../../../SSAX} # path to SSAX
|
2002-09-26 08:13:01 -04:00
|
|
|
|
2003-11-21 14:05:02 -05:00
|
|
|
exec scsh -lm $sunethome/packages.scm -lm $ssaxhome/lib/packages.scm -lm $sunethome/httpd/surflets/packages.scm -dm -o surflet-server -e main -s "$0" "$@"
|
2002-09-20 15:23:17 -04:00
|
|
|
!#
|
|
|
|
|
2003-01-19 11:57:27 -05:00
|
|
|
(define-structure surflet-server
|
2002-09-26 08:13:01 -04:00
|
|
|
(export main ; sh jump entry point
|
|
|
|
server) ; scsh entry point
|
2002-09-20 15:23:17 -04:00
|
|
|
(open httpd-core
|
|
|
|
httpd-make-options
|
|
|
|
httpd-basic-handlers
|
|
|
|
httpd-file-directory-handlers
|
|
|
|
; cgi-server
|
|
|
|
; seval-handler
|
|
|
|
; rman-gateway
|
|
|
|
; info-gateway
|
2003-01-19 11:57:27 -05:00
|
|
|
surflet-handler
|
2003-07-18 11:06:53 -04:00
|
|
|
surflet-handler/options
|
2002-09-20 15:23:17 -04:00
|
|
|
let-opt
|
|
|
|
scsh
|
|
|
|
scheme)
|
|
|
|
|
|
|
|
(begin
|
|
|
|
|
|
|
|
(define (usage)
|
|
|
|
(format #f
|
2003-01-22 07:53:46 -05:00
|
|
|
"Usage: start-surflet-server [-h htdocs-dir] [-s surflet-dir] [-i images-dir]
|
2002-10-22 12:01:25 -04:00
|
|
|
[-p port] [-l log-file-name]
|
|
|
|
[-r requests] [--help]
|
2002-09-20 15:23:17 -04:00
|
|
|
|
|
|
|
with
|
2002-09-26 08:13:01 -04:00
|
|
|
htdocs-dir directory of html files (default: ./web-server/root/htdocs)
|
2003-01-22 07:53:46 -05:00
|
|
|
surflet-dir directory of SUrflet files (default: ./web-server/root/surflets)
|
2002-10-22 12:01:25 -04:00
|
|
|
images-dir directory of images files (default: ./web-server/root/img)
|
2003-11-21 14:05:02 -05:00
|
|
|
port port server is listening to (default: 8008)
|
2002-09-20 15:23:17 -04:00
|
|
|
log-file-name directory where to store the logfile in CLF
|
2002-09-26 08:13:01 -04:00
|
|
|
(default: ./web-server/httpd.log)
|
2002-09-20 15:23:17 -04:00
|
|
|
requests maximal amount of simultaneous requests (default 5)
|
|
|
|
--help show this help
|
|
|
|
|
2003-01-19 11:57:27 -05:00
|
|
|
NOTE: This is the SUrflet-server. It does not support cgi-bin.
|
2002-09-20 15:23:17 -04:00
|
|
|
"
|
|
|
|
))
|
|
|
|
|
|
|
|
(define htdocs-dir #f)
|
2002-10-22 12:01:25 -04:00
|
|
|
(define images-dir #f)
|
2002-09-26 08:13:01 -04:00
|
|
|
; (define cgi-bin-dir #f)
|
2002-09-20 15:23:17 -04:00
|
|
|
(define port #f)
|
|
|
|
(define log-file-name #f)
|
|
|
|
(define root #f)
|
2003-01-19 11:57:27 -05:00
|
|
|
(define surflet-dir #f)
|
2002-09-20 15:23:17 -04:00
|
|
|
(define simultaneous-requests #f)
|
|
|
|
|
|
|
|
(define (init)
|
2002-09-26 08:13:01 -04:00
|
|
|
(set! htdocs-dir "./web-server/root/htdocs")
|
2002-10-22 12:01:25 -04:00
|
|
|
(set! images-dir "./web-server/root/img")
|
2002-09-26 08:13:01 -04:00
|
|
|
; (set! cgi-bin-dir "./web-server/root/cgi-bin")
|
2003-11-21 14:05:02 -05:00
|
|
|
(set! port "8008")
|
2002-09-26 08:13:01 -04:00
|
|
|
(set! log-file-name "./web-server/httpd.log")
|
|
|
|
(set! root "./web-server/root")
|
2003-01-22 07:53:46 -05:00
|
|
|
(set! surflet-dir "./web-server/root/surflets")
|
2002-09-20 15:23:17 -04:00
|
|
|
(set! simultaneous-requests "5"))
|
|
|
|
|
2002-09-26 08:13:01 -04:00
|
|
|
(define (normalize-options)
|
|
|
|
(set! htdocs-dir (absolute-file-name htdocs-dir))
|
2002-10-22 12:01:25 -04:00
|
|
|
(set! images-dir (absolute-file-name images-dir))
|
2002-09-26 08:13:01 -04:00
|
|
|
(set! log-file-name (absolute-file-name log-file-name))
|
|
|
|
; (set! cgi-bin-dir (absolute-file-name cgi-bin-dir))
|
|
|
|
(set! port (string->number port))
|
2003-01-19 11:57:27 -05:00
|
|
|
(set! surflet-dir (absolute-file-name surflet-dir))
|
2002-09-26 08:13:01 -04:00
|
|
|
(set! simultaneous-requests (string->number simultaneous-requests)))
|
|
|
|
|
2002-09-20 15:23:17 -04:00
|
|
|
(define get-options
|
|
|
|
(let* ((unknown-option-error
|
|
|
|
(lambda (option)
|
|
|
|
(format (error-output-port)
|
2003-01-19 11:57:27 -05:00
|
|
|
"unknown option `~A'~%try `surflet-server --help'~%"
|
2002-09-20 15:23:17 -04:00
|
|
|
option)
|
|
|
|
(exit 1)))
|
|
|
|
(missing-argument-error
|
|
|
|
(lambda (option)
|
|
|
|
(format (error-output-port)
|
2003-01-19 11:57:27 -05:00
|
|
|
"option `~A' requires an argument~%try `surflet-server --help'~%"
|
2002-09-20 15:23:17 -04:00
|
|
|
option)
|
|
|
|
(exit 1))))
|
|
|
|
(lambda (options)
|
|
|
|
(let loop ((options options))
|
|
|
|
(if (null? options)
|
2002-09-26 08:13:01 -04:00
|
|
|
(normalize-options)
|
2002-09-20 15:23:17 -04:00
|
|
|
(cond
|
|
|
|
((string=? (car options) "-h")
|
|
|
|
(if (null? (cdr options))
|
|
|
|
(missing-argument-error (car options))
|
|
|
|
(set! htdocs-dir (cadr options)))
|
|
|
|
(loop (cddr options)))
|
2002-10-22 12:01:25 -04:00
|
|
|
((string=? (car options) "-i")
|
|
|
|
(if (null? (cdr options))
|
|
|
|
(missing-argument-error (car options))
|
|
|
|
(set! images-dir (cadr options)))
|
|
|
|
(loop (cddr options)))
|
2002-09-20 15:23:17 -04:00
|
|
|
((string=? (car options) "-c")
|
|
|
|
(format (error-output-port)
|
2003-01-19 11:57:27 -05:00
|
|
|
"This is the SUrflet server. It does not support cgi.~%")
|
2002-09-20 15:23:17 -04:00
|
|
|
; (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) "-s")
|
|
|
|
(if (null? (cdr options))
|
|
|
|
(missing-argument-error (car options))
|
2003-01-19 11:57:27 -05:00
|
|
|
(set! surflet-dir (cadr options)))
|
2002-09-20 15:23:17 -04:00
|
|
|
(loop (cddr options)))
|
|
|
|
((string=? (car options) "-r")
|
|
|
|
(if (null? (cdr options))
|
|
|
|
(missing-argument-error (car options))
|
|
|
|
(set! simultaneous-requests (cadr options)))
|
|
|
|
(loop (cddr options)))
|
|
|
|
((string=? (car options) "--help")
|
|
|
|
(display (usage))
|
|
|
|
(exit 0))
|
|
|
|
((string=? (car options) "--dump")
|
|
|
|
(let ((image-name (if (null? (cdr options))
|
2003-01-19 11:57:27 -05:00
|
|
|
"surflet-server"
|
2002-09-20 15:23:17 -04:00
|
|
|
(cadr options))))
|
|
|
|
(dump-scsh-program main image-name))
|
|
|
|
(exit 0))
|
|
|
|
(else
|
|
|
|
(unknown-option-error (car options)))))))))
|
|
|
|
|
2002-09-26 08:13:01 -04:00
|
|
|
(define (server . args)
|
|
|
|
(if (pair? args)
|
|
|
|
(main `(main ,@(car args)))
|
|
|
|
(main '(main))))
|
2002-09-20 15:23:17 -04:00
|
|
|
|
|
|
|
(define (main args)
|
|
|
|
(init)
|
|
|
|
(format #t "reading options: ~s~%" (cdr args))
|
|
|
|
(get-options (cdr args))
|
|
|
|
(cond ((zero? (user-uid))
|
|
|
|
(set-gid (->gid "nobody"))
|
|
|
|
(set-uid (->uid "nobody"))))
|
|
|
|
|
2003-01-19 11:57:27 -05:00
|
|
|
(format #t "Going to run SUrflet server with:
|
2002-09-20 15:23:17 -04:00
|
|
|
htdocs-dir: ~a
|
2003-01-19 11:57:27 -05:00
|
|
|
surflet-dir: ~a
|
2002-10-22 12:01:25 -04:00
|
|
|
images-dir: ~a
|
2002-09-20 15:23:17 -04:00
|
|
|
port: ~a
|
|
|
|
log-file-name: ~a
|
|
|
|
a maximum of ~a simultaneous requests, syslogging activated,
|
|
|
|
and home-dir-handler (public_html) activated.
|
|
|
|
|
2003-01-19 11:57:27 -05:00
|
|
|
NOTE: This is the SUrflet server. It does not support cgi.
|
2002-09-20 15:23:17 -04:00
|
|
|
"
|
|
|
|
htdocs-dir
|
2003-01-19 11:57:27 -05:00
|
|
|
surflet-dir
|
2002-10-22 12:01:25 -04:00
|
|
|
images-dir
|
2002-09-20 15:23:17 -04:00
|
|
|
port
|
|
|
|
log-file-name
|
|
|
|
simultaneous-requests)
|
|
|
|
|
2003-01-28 16:58:33 -05:00
|
|
|
(httpd (make-httpd-options
|
|
|
|
with-port port
|
|
|
|
with-root-directory (cwd)
|
|
|
|
with-simultaneous-requests simultaneous-requests
|
|
|
|
with-syslog? #t
|
2003-02-17 04:52:21 -05:00
|
|
|
with-log-file log-file-name
|
2003-01-28 16:58:33 -05:00
|
|
|
;; The following settings are made to avoid dns lookups.
|
|
|
|
with-reported-port port
|
|
|
|
with-fqdn "localhost"
|
|
|
|
with-resolve-ips? #f
|
|
|
|
with-request-handler
|
2002-09-20 15:23:17 -04:00
|
|
|
(alist-path-dispatcher
|
2003-02-17 04:08:27 -05:00
|
|
|
(list (cons "h" (home-dir-handler "public_html"))
|
2002-09-20 15:23:17 -04:00
|
|
|
; (cons "seval" seval-handler)
|
|
|
|
; (cons "man" (rman-handler #f "man?%s(%s)"
|
|
|
|
; "Generated by rman-gateway"))
|
|
|
|
; (cons "info" (info-handler #f #f #f
|
|
|
|
; "Generated by info-gateway"))
|
|
|
|
; (cons "cgi-bin" (cgi-handler cgi-bin-dir))
|
2003-01-28 16:58:33 -05:00
|
|
|
(cons "source" (rooted-file-or-directory-handler
|
|
|
|
surflet-dir
|
|
|
|
(with-file-name->content-type
|
|
|
|
(lambda (file-name)
|
|
|
|
(if (string-ci=? (file-name-extension file-name)
|
|
|
|
".scm")
|
|
|
|
"text/plain"))
|
|
|
|
(make-file-directory-options))))
|
2003-02-17 04:08:27 -05:00
|
|
|
(cons "img" (rooted-file-handler images-dir))
|
2003-07-18 11:06:53 -04:00
|
|
|
(cons "surflet" (surflet-handler
|
2003-07-18 12:10:57 -04:00
|
|
|
(with-surflet-path surflet-dir))))
|
2003-02-17 04:08:27 -05:00
|
|
|
(rooted-file-or-directory-handler htdocs-dir))))
|
2003-01-28 16:58:33 -05:00
|
|
|
)
|
2002-09-20 15:23:17 -04:00
|
|
|
))
|
|
|
|
;; EOF
|
|
|
|
|
|
|
|
;;; Local Variables:
|
|
|
|
;;; mode:scheme
|
2003-01-18 12:56:18 -05:00
|
|
|
;;; End:
|