2002-10-21 04:41:00 -04:00
|
|
|
(define-structure servlet servlet-interface
|
2002-12-08 10:49:27 -05:00
|
|
|
(open scheme-with-scsh
|
2002-10-21 04:41:00 -04:00
|
|
|
servlets
|
|
|
|
servlet-handler/admin
|
|
|
|
httpd-responses
|
|
|
|
handle-fatal-error
|
|
|
|
let-opt
|
|
|
|
srfi-1 ;filter-map
|
|
|
|
sort
|
|
|
|
)
|
|
|
|
(begin
|
|
|
|
|
|
|
|
(define remove-servlet-path
|
|
|
|
(let ((regexp (rx ,(file-name-as-directory (options-servlet-path))
|
|
|
|
(submatch (* any)))))
|
|
|
|
(lambda (file-name)
|
|
|
|
(let ((match (regexp-search regexp file-name)))
|
|
|
|
(if match
|
|
|
|
(match:substring match 1)
|
|
|
|
file-name)))))
|
|
|
|
|
|
|
|
;; returns two values: an action to perform out of ACTIONS and a
|
|
|
|
;; list of selected elements out of TABLE-ELEMENTS.
|
|
|
|
(define (select-table title header header-row
|
|
|
|
table-elements selector actions footer)
|
|
|
|
(let* ((checkboxes (map (lambda (_)
|
|
|
|
(make-checkbox-input-field))
|
|
|
|
table-elements))
|
|
|
|
(action-title "Choose an action")
|
|
|
|
(select (make-select-input-field (cons action-title actions)
|
|
|
|
'(@ (size 1))))
|
|
|
|
(req
|
|
|
|
(send-html/suspend
|
|
|
|
(lambda (new-url)
|
|
|
|
`(html
|
|
|
|
(title ,title)
|
|
|
|
(body
|
|
|
|
,header
|
|
|
|
(servlet-form
|
|
|
|
,new-url
|
|
|
|
(table
|
|
|
|
,@(cons '(th) header-row)
|
|
|
|
,@(map (lambda (checkbox table-element)
|
|
|
|
`(tr
|
|
|
|
(td ,checkbox)
|
|
|
|
,@(selector table-element)))
|
|
|
|
checkboxes
|
|
|
|
table-elements))
|
|
|
|
(p ,select
|
|
|
|
,(make-submit-button "Do it")))
|
|
|
|
,footer)))))
|
|
|
|
(bindings (get-bindings req))
|
|
|
|
(action (input-field-value select bindings)))
|
|
|
|
|
|
|
|
(if (string=? action action-title)
|
|
|
|
(select-table title header header-row table-elements selector actions footer)
|
|
|
|
(values
|
|
|
|
action
|
|
|
|
(filter-map (lambda (checkbox table-element)
|
2002-11-07 15:41:35 -05:00
|
|
|
(if (input-field-value checkbox bindings)
|
|
|
|
table-element
|
|
|
|
#f))
|
2002-10-21 04:41:00 -04:00
|
|
|
checkboxes
|
|
|
|
table-elements)))))
|
|
|
|
|
|
|
|
(define (unload-servlets outdated? servlet-names)
|
|
|
|
(if-outdated outdated?
|
|
|
|
(show-outdated (make-callback servlets))
|
|
|
|
(for-each unload-servlet servlet-names)))
|
|
|
|
|
|
|
|
(define (no-servlets)
|
|
|
|
`(p "Currently, there are no servlets loaded "
|
|
|
|
(URL ,(make-callback servlets) "(reload).")))
|
|
|
|
|
|
|
|
(define (servlets req . maybe-update-text)
|
|
|
|
(let* ((update-text (:optional maybe-update-text ""))
|
|
|
|
(loaded-servlets (sort-list! (get-loaded-servlets) string<?))
|
|
|
|
(outdated? (make-outdater))
|
|
|
|
(title "Servlet-Administration -- Servlets")
|
|
|
|
(header `((h1 "Servlet Administration")
|
|
|
|
(h2 "Servlets")
|
|
|
|
(p (font (@ (color "red")) ,update-text))))
|
|
|
|
(footer `((hr)
|
|
|
|
(URL ,(make-callback return-to-main-page) "Return to main page")))
|
2002-12-07 17:26:40 -05:00
|
|
|
(actions '("unload" "unload all" "view sessions")))
|
2002-10-21 04:41:00 -04:00
|
|
|
(if (null? loaded-servlets)
|
|
|
|
(send-html `(html (title ,title) (body ,header ,(no-servlets) ,footer)))
|
|
|
|
(receive (action selected-servlets)
|
|
|
|
(select-table title ; title
|
|
|
|
header ; header
|
|
|
|
'((th "Name")) ; table-header
|
|
|
|
loaded-servlets ; list of elements
|
|
|
|
(lambda (servlet) ; selector
|
|
|
|
`((td
|
|
|
|
,(remove-servlet-path servlet))))
|
|
|
|
actions ; actions to perform
|
|
|
|
(cons ; footer
|
|
|
|
`(p "Note that unloading the servlets does not imply "
|
2002-12-07 17:26:40 -05:00
|
|
|
"the unloading of sessions of this servlet."
|
2002-10-21 04:41:00 -04:00
|
|
|
"This can be done on the "
|
2002-12-07 17:26:40 -05:00
|
|
|
(URL ,(make-callback sessions)
|
|
|
|
"sessions adminstration page."))
|
2002-10-21 04:41:00 -04:00
|
|
|
footer))
|
|
|
|
(if (null? selected-servlets)
|
|
|
|
(servlets 'no-req "You must choose at least one element.")
|
|
|
|
(cond
|
|
|
|
((string=? action "unload")
|
|
|
|
(unload-servlets outdated? selected-servlets)
|
|
|
|
(servlets 'no-req "Servlets unloaded."))
|
|
|
|
((string=? action "unload all")
|
|
|
|
(unload-servlets outdated? loaded-servlets)
|
|
|
|
(servlets 'no-req "Servlets unloaded."))
|
2002-12-07 17:26:40 -05:00
|
|
|
((string=? action "view sessions")
|
2002-10-21 04:41:00 -04:00
|
|
|
(format #t "~s~%" selected-servlets)
|
|
|
|
(let* ((path-stripped-selected-servlets
|
|
|
|
(map remove-servlet-path selected-servlets))
|
2002-12-07 17:26:40 -05:00
|
|
|
(selected-sessions
|
|
|
|
(filter (lambda (session-pair)
|
|
|
|
(member (session-servlet-name (cdr session-pair))
|
2002-10-21 04:41:00 -04:00
|
|
|
path-stripped-selected-servlets))
|
2002-12-07 17:26:40 -05:00
|
|
|
(get-sessions))))
|
2002-10-21 04:41:00 -04:00
|
|
|
;; this does not return
|
2002-12-07 17:26:40 -05:00
|
|
|
(real-sessions (sort-list! selected-sessions
|
|
|
|
session-servlet-name<?)
|
2002-10-21 04:41:00 -04:00
|
|
|
"")))
|
|
|
|
(else
|
|
|
|
(error "unknown action" action))))))))
|
|
|
|
|
2002-12-07 17:26:40 -05:00
|
|
|
(define (session-servlet-name<? entry1 entry2)
|
|
|
|
(let ((name1 (session-servlet-name (cdr entry1)))
|
|
|
|
(name2 (session-servlet-name (cdr entry2))))
|
|
|
|
;; handle multiple session names
|
2002-10-21 04:41:00 -04:00
|
|
|
(if (string=? name1 name2)
|
2002-12-07 17:26:40 -05:00
|
|
|
(session-id<? entry1 entry2)
|
2002-10-21 04:41:00 -04:00
|
|
|
(string<? name1 name2))))
|
2002-12-07 17:26:40 -05:00
|
|
|
(define (session-id<? entry1 entry2)
|
|
|
|
;; there are no multiple session-ids
|
2002-10-21 04:41:00 -04:00
|
|
|
(< (car entry1) (car entry2)))
|
2002-12-07 17:26:40 -05:00
|
|
|
(define (session-id>? entry1 entry2)
|
|
|
|
(session-id<? entry2 entry1))
|
|
|
|
(define (session-servlet-name>? entry1 entry2)
|
|
|
|
(session-servlet-name<? entry2 entry1))
|
2002-10-21 04:41:00 -04:00
|
|
|
|
2002-12-07 17:26:40 -05:00
|
|
|
(define (no-current-sessions)
|
2002-10-21 04:41:00 -04:00
|
|
|
;; Avoid using send/suspend in this context as there
|
2002-12-07 17:26:40 -05:00
|
|
|
;; are no sessions available any more.
|
|
|
|
'(p "Currently, there are no sessions, "
|
2002-10-21 04:41:00 -04:00
|
|
|
"i.e. the administration servlet is no longer running. "
|
2002-12-07 17:26:40 -05:00
|
|
|
;; Can't use callback here, as there are no valid sessions left.
|
2002-10-21 04:41:00 -04:00
|
|
|
(URL "admin.scm" "Go back to main page.")))
|
|
|
|
|
2002-12-07 17:26:40 -05:00
|
|
|
(define (sessions req . maybe-update-text)
|
2002-10-21 04:41:00 -04:00
|
|
|
(let* ((update-text (:optional maybe-update-text ""))
|
2002-12-07 17:26:40 -05:00
|
|
|
(current-sessions (sort-list! (get-sessions) session-servlet-name<?)))
|
|
|
|
(real-sessions current-sessions update-text)))
|
2002-10-21 04:41:00 -04:00
|
|
|
|
2002-12-07 17:26:40 -05:00
|
|
|
(define (real-sessions current-sessions update-text)
|
2002-10-21 04:41:00 -04:00
|
|
|
(let ((outdated? (make-outdater))
|
2002-12-07 17:26:40 -05:00
|
|
|
(title "Servlet Adminstration - Sessions")
|
2002-10-21 04:41:00 -04:00
|
|
|
(header `((h1 "Servlet Administration")
|
2002-12-07 17:26:40 -05:00
|
|
|
(h2 "Sessions")
|
2002-10-21 04:41:00 -04:00
|
|
|
(p (font (@ (color "red")) ,update-text))))
|
|
|
|
(footer `((hr)
|
|
|
|
(URL ,(make-callback return-to-main-page) "Return to main page")))
|
|
|
|
(actions '("kill"
|
|
|
|
"adjust timeout"
|
|
|
|
"view continuations"))
|
2002-12-07 17:26:40 -05:00
|
|
|
(sessions-callback (make-callback sessions)))
|
|
|
|
(if (null? current-sessions)
|
2002-10-21 04:41:00 -04:00
|
|
|
(send-html `(html (title ,title)
|
2002-12-07 17:26:40 -05:00
|
|
|
(body ,@header ,(no-current-sessions) ,footer)))
|
|
|
|
(receive (action selected-sessions)
|
2002-10-21 04:41:00 -04:00
|
|
|
(select-table title
|
|
|
|
header
|
2002-12-07 17:26:40 -05:00
|
|
|
`((th "Servlet Name") (th "Session-Id"))
|
|
|
|
current-sessions
|
|
|
|
(lambda (session-pair)
|
|
|
|
(let ((session-id (car session-pair))
|
|
|
|
(session-entry (cdr session-pair)))
|
|
|
|
`((td ,(session-servlet-name session-entry))
|
|
|
|
(td ,session-id))))
|
2002-10-21 04:41:00 -04:00
|
|
|
actions
|
|
|
|
footer)
|
|
|
|
(let ((new-update-text
|
|
|
|
(cond
|
|
|
|
((string=? action "kill")
|
|
|
|
(if-outdated outdated?
|
2002-12-07 17:26:40 -05:00
|
|
|
(show-outdated sessions-callback)
|
|
|
|
(for-each delete-session!
|
|
|
|
(map car selected-sessions)))
|
|
|
|
"Sessions killed.")
|
2002-10-21 04:41:00 -04:00
|
|
|
((string=? action "adjust timeout")
|
|
|
|
(if-outdated outdated?
|
2002-12-07 17:26:40 -05:00
|
|
|
(show-outdated sessions-callback)
|
|
|
|
(for-each session-adjust-timeout!
|
|
|
|
(map car selected-sessions)))
|
|
|
|
"Sessions killed.")
|
2002-10-21 04:41:00 -04:00
|
|
|
((string=? action "view continuations")
|
|
|
|
(if-outdated outdated?
|
2002-12-07 17:26:40 -05:00
|
|
|
(show-outdated sessions-callback)
|
|
|
|
(if (zero? (length selected-sessions))
|
|
|
|
"You must choose at least one session."
|
2002-10-21 04:41:00 -04:00
|
|
|
;; this does not return
|
2002-12-07 17:26:40 -05:00
|
|
|
(continuations selected-sessions))))
|
2002-10-21 04:41:00 -04:00
|
|
|
(else
|
|
|
|
(error "unknown action" action)))))
|
2002-12-07 17:26:40 -05:00
|
|
|
(sessions 'no-req new-update-text))))))
|
2002-10-21 04:41:00 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2002-12-07 17:26:40 -05:00
|
|
|
(define (no-current-continuations session)
|
|
|
|
`((p "Currently, there are no continuations for this session. ")
|
2002-10-21 04:41:00 -04:00
|
|
|
(p "You may " (URL ,(make-callback
|
2002-12-07 17:26:40 -05:00
|
|
|
(lambda (req) (continuations (list session))))
|
2002-10-21 04:41:00 -04:00
|
|
|
"reload")
|
|
|
|
" this page or go back to the "
|
2002-12-07 17:26:40 -05:00
|
|
|
(URL ,(make-callback sessions) "session table overview."))))
|
2002-10-21 04:41:00 -04:00
|
|
|
|
2002-12-07 17:26:40 -05:00
|
|
|
(define (no-more-than-one-session title header1)
|
2002-10-21 04:41:00 -04:00
|
|
|
(send-html
|
|
|
|
`(html (title ,title)
|
|
|
|
(body (h1 "Servlet Administration")
|
|
|
|
(p "Currently, you may only view the continuations of "
|
2002-12-07 17:26:40 -05:00
|
|
|
"one session at a time. This will be changed in "
|
2002-10-21 04:41:00 -04:00
|
|
|
"future revisions. Sorry for any inconvenience.")
|
|
|
|
(p "You may choose to go back to the "
|
2002-12-07 17:26:40 -05:00
|
|
|
(URL ,(make-callback sessions)
|
|
|
|
"sessions administration page")
|
|
|
|
" where you can choose one session.")))))
|
2002-10-21 04:41:00 -04:00
|
|
|
|
|
|
|
(define (continuation-id<? entry1 entry2)
|
|
|
|
(< (car entry1) (car entry2)))
|
|
|
|
|
2002-12-07 17:26:40 -05:00
|
|
|
(define (continuations sessions . maybe-update-text)
|
2002-10-21 04:41:00 -04:00
|
|
|
(let ((title "Servlet Adminstration - Continuations")
|
|
|
|
(header1 '(h1 "Servlet Administration")))
|
2002-12-07 17:26:40 -05:00
|
|
|
(if (not (= 1 (length sessions)))
|
|
|
|
(no-more-than-one-session title header1)
|
|
|
|
(let* ((session-pair (car sessions))
|
|
|
|
(session-id (car session-pair))
|
|
|
|
(session-entry (cdr session-pair))
|
2002-10-21 04:41:00 -04:00
|
|
|
(update-text (:optional maybe-update-text "")))
|
|
|
|
(let ((current-continuations
|
2002-12-07 17:26:40 -05:00
|
|
|
(sort-list! (get-continuations session-id)
|
2002-10-21 04:41:00 -04:00
|
|
|
continuation-id<?))
|
|
|
|
(outdated? (make-outdater))
|
|
|
|
|
|
|
|
(header (cons header1
|
2002-12-07 17:26:40 -05:00
|
|
|
`((h2 "Continuations of " ,session-id)
|
2002-10-21 04:41:00 -04:00
|
|
|
(p "(belongs to the servlet '"
|
2002-12-07 17:26:40 -05:00
|
|
|
,(session-servlet-name session-entry) "')")
|
2002-10-21 04:41:00 -04:00
|
|
|
(p (font (@ (color "red")) ,update-text)))))
|
|
|
|
(footer
|
|
|
|
`((hr)
|
2002-12-07 17:26:40 -05:00
|
|
|
(URL ,(make-callback sessions) "Return to sessions page.") (br)
|
2002-10-21 04:41:00 -04:00
|
|
|
(URL ,(make-callback return-to-main-page) "Return to main page.")))
|
|
|
|
(actions '("delete" "delete all"))
|
|
|
|
(continuations-callback (make-callback (lambda (req)
|
2002-12-07 17:26:40 -05:00
|
|
|
(continuations sessions)))))
|
2002-10-21 04:41:00 -04:00
|
|
|
(if (null? current-continuations)
|
|
|
|
(send-html `(html (title ,title)
|
|
|
|
(body ,header
|
2002-12-07 17:26:40 -05:00
|
|
|
,(no-current-continuations session-pair)
|
2002-10-21 04:41:00 -04:00
|
|
|
,footer)))
|
|
|
|
(receive (action selected-continuations)
|
|
|
|
(select-table title
|
|
|
|
header
|
|
|
|
'((th "Continuation-Id"))
|
|
|
|
current-continuations
|
|
|
|
(lambda (continuation-pair)
|
|
|
|
(let ((continuation-id (car continuation-pair)))
|
|
|
|
`((td ,continuation-id))))
|
|
|
|
actions
|
|
|
|
footer)
|
|
|
|
(cond
|
|
|
|
((string=? action "delete")
|
|
|
|
(delete-continuations outdated? continuations-callback
|
2002-12-07 17:26:40 -05:00
|
|
|
session-id selected-continuations))
|
2002-10-21 04:41:00 -04:00
|
|
|
((string=? action "delete all")
|
|
|
|
(delete-continuations outdated? continuations-callback
|
2002-12-07 17:26:40 -05:00
|
|
|
session-id current-continuations))
|
2002-10-21 04:41:00 -04:00
|
|
|
(else
|
|
|
|
(error "unknown action" action)))
|
2002-12-07 17:26:40 -05:00
|
|
|
(continuations sessions "Deleted."))))))))
|
2002-10-21 04:41:00 -04:00
|
|
|
|
|
|
|
(define (delete-continuations outdated? continuations-callback
|
2002-12-07 17:26:40 -05:00
|
|
|
session-id continuations)
|
2002-10-21 04:41:00 -04:00
|
|
|
(if-outdated outdated?
|
|
|
|
(show-outdated continuations-callback)
|
2002-12-07 17:26:40 -05:00
|
|
|
;; Do it this way to easily expand to more sessions in the
|
2002-10-21 04:41:00 -04:00
|
|
|
;; future.
|
|
|
|
(for-each delete-continuation!
|
|
|
|
(make-list (length continuations)
|
2002-12-07 17:26:40 -05:00
|
|
|
session-id)
|
2002-10-21 04:41:00 -04:00
|
|
|
(map car continuations))))
|
|
|
|
|
|
|
|
(define (return-to-main-page req)
|
2003-01-10 04:52:35 -05:00
|
|
|
(send/finish (make-error-response (status-code moved-perm) req
|
|
|
|
"admin.scm" "admin.scm")))
|
2002-10-21 04:41:00 -04:00
|
|
|
|
|
|
|
(define (main req)
|
|
|
|
(servlets req))
|
|
|
|
|
|
|
|
))
|