2003-01-19 11:57:27 -05:00
|
|
|
(define-structure surflet surflet-interface
|
2002-12-08 10:49:27 -05:00
|
|
|
(open scheme-with-scsh
|
2003-01-19 11:57:27 -05:00
|
|
|
surflets
|
2003-04-14 05:10:54 -04:00
|
|
|
surflets/callbacks ;make-callback
|
+ Splitting file surflets.scm into several packages
- Removing surflets.scm
+ The surflets package remains and collects the most usual used packages
It does not export any more the outdaters, the access to IDs
(like session-id), callbacks, form-query-list.
(and maybe some other stuff I've forgot to mention here, see list
below).
The new packages are (not included in surflets are marked (*)):
+ surflets/addresses: MAKE-ADDRESS, MAKE-ANNOTATED-ADDRESS
+ surflets/bindings: GET-BINDINGS, EXTRACT-BINDINGS and stuff
+ surflets/ids (*): MY-SESSION-ID, .., INSTANCE-SESSION-ID
+ surflets/input-fields: MAKE-INPUT-FIELD, MAKE-NUMBER-INPUT-FIELD...
+ surflets/outdaters(*): MAKE-OUTDATER, OUTDATER?...
+ surflets/returned-via: RETURNED-VIA, CASE-RETURNED-VIA
+ surflets/send-html: SEND-HTML/SUSPEND...
+ surflets/surflet-sxml: URL-RULE,..., SURLFET-SXML-RULES, ...
+ surflets/sxml: SXML->STRING, DEFAULT-RULE,...
+ surflets/typed-optionals(*): TYPED-OPTIONALS, OPTIONALS
+ surflets/utilities(*): MAKE-CALLBACK, FORM-QUERY-LIST,
GENERATE-UNIQUE-NAME...
2003-03-10 11:29:32 -05:00
|
|
|
surflets/outdaters
|
|
|
|
surflets/ids
|
2003-03-13 06:36:49 -05:00
|
|
|
surflets/error
|
2003-01-19 11:57:27 -05:00
|
|
|
surflet-handler/admin
|
2002-10-02 09:39:55 -04:00
|
|
|
handle-fatal-error
|
|
|
|
let-opt
|
2003-01-16 07:53:10 -05:00
|
|
|
srfi-1 ;filter-map, last
|
2002-10-01 13:44:58 -04:00
|
|
|
sort
|
|
|
|
)
|
|
|
|
(begin
|
|
|
|
|
2003-01-19 11:57:27 -05:00
|
|
|
(define remove-surflet-path
|
|
|
|
(let ((regexp (rx ,(file-name-as-directory (options-surflet-path))
|
2002-10-01 13:44:58 -04:00
|
|
|
(submatch (* any)))))
|
|
|
|
(lambda (file-name)
|
|
|
|
(let ((match (regexp-search regexp file-name)))
|
|
|
|
(if match
|
|
|
|
(match:substring match 1)
|
|
|
|
file-name)))))
|
2002-10-02 09:39:55 -04:00
|
|
|
|
|
|
|
;; 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)
|
2003-07-08 17:22:06 -04:00
|
|
|
(let* ((checkboxes (map make-annotated-checkbox
|
2002-10-02 09:39:55 -04:00
|
|
|
table-elements))
|
2003-07-08 17:22:06 -04:00
|
|
|
(select (make-annotated-select
|
2003-07-09 13:18:57 -04:00
|
|
|
actions #f '(@ (size 1))))
|
2002-10-02 09:39:55 -04:00
|
|
|
(req
|
|
|
|
(send-html/suspend
|
|
|
|
(lambda (new-url)
|
|
|
|
`(html
|
|
|
|
(title ,title)
|
|
|
|
(body
|
|
|
|
,header
|
2003-01-19 11:57:27 -05:00
|
|
|
(surflet-form
|
2002-10-02 09:39:55 -04:00
|
|
|
,new-url
|
2002-10-09 11:14:54 -04:00
|
|
|
POST
|
2002-10-02 09:39:55 -04:00
|
|
|
(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))
|
2003-04-16 13:11:47 -04:00
|
|
|
(selected (filter-map (lambda (checkbox)
|
|
|
|
(input-field-value checkbox bindings))
|
|
|
|
checkboxes))
|
2002-10-02 09:39:55 -04:00
|
|
|
(action (input-field-value select bindings)))
|
2003-04-16 13:11:47 -04:00
|
|
|
(action req selected)))
|
2002-10-02 09:39:55 -04:00
|
|
|
|
2003-04-16 13:11:47 -04:00
|
|
|
(define (unload-surflets outdated?)
|
|
|
|
(lambda (req surflet-names)
|
|
|
|
(if (null? surflet-names)
|
|
|
|
(show-surflets req "You must choose at least one element.")
|
|
|
|
(if-outdated outdated?
|
|
|
|
(show-outdated (make-callback show-surflets))
|
|
|
|
(begin
|
|
|
|
(for-each unload-surflet surflet-names)
|
|
|
|
(show-surflets req "SUrflets unloaded."))))))
|
|
|
|
|
2003-04-16 12:03:06 -04:00
|
|
|
(define (no-surflets callback)
|
2003-01-19 11:57:27 -05:00
|
|
|
`(p "Currently, there are no SUrflets loaded "
|
2003-04-16 12:03:06 -04:00
|
|
|
(url ,(callback show-surflets) "(reload)")
|
2003-01-16 07:53:10 -05:00
|
|
|
", but there may be "
|
2003-04-16 12:03:06 -04:00
|
|
|
(url ,(callback show-sessions) "sessions")
|
2003-01-16 07:53:10 -05:00
|
|
|
" you want to administer."))
|
2002-10-01 13:44:58 -04:00
|
|
|
|
2003-04-16 13:11:47 -04:00
|
|
|
(define (choose-an-action show)
|
|
|
|
(lambda (req _)
|
|
|
|
(show req "Choose an action.")))
|
|
|
|
|
2003-01-19 11:57:27 -05:00
|
|
|
(define (show-surflets req . maybe-update-text)
|
2002-10-02 09:39:55 -04:00
|
|
|
(let* ((update-text (:optional maybe-update-text ""))
|
2003-01-19 11:57:27 -05:00
|
|
|
(loaded-surflets (sort-list! (get-loaded-surflets) string<?))
|
2002-10-02 09:39:55 -04:00
|
|
|
(outdated? (make-outdater))
|
2003-08-01 11:02:43 -04:00
|
|
|
(callback (make-annotated-callback callback-function))
|
2003-01-19 11:57:27 -05:00
|
|
|
(title "SUrflet-Administration -- SUrflets")
|
|
|
|
(header `((h1 "SUrflet Administration")
|
|
|
|
(h2 "SUrflets")
|
2002-10-02 09:39:55 -04:00
|
|
|
(p (font (@ (color "red")) ,update-text))))
|
|
|
|
(footer `((hr)
|
2003-04-16 12:03:06 -04:00
|
|
|
(url ,(callback return-to-main-page)
|
|
|
|
"Return to administration menu.")
|
2002-10-21 04:38:46 -04:00
|
|
|
(br)
|
2003-04-16 13:11:47 -04:00
|
|
|
(url "/" "Return to main menu."))))
|
2003-01-19 11:57:27 -05:00
|
|
|
(if (null? loaded-surflets)
|
2003-04-16 12:03:06 -04:00
|
|
|
(send-html `(html (title ,title)
|
|
|
|
(body ,header ,(no-surflets callback) ,footer)))
|
2003-04-16 13:11:47 -04:00
|
|
|
(let ((actions
|
|
|
|
(map (lambda (action-pair)
|
2003-07-08 17:22:06 -04:00
|
|
|
(make-annotated-select-option
|
2003-04-16 13:11:47 -04:00
|
|
|
(car action-pair)
|
|
|
|
(cdr action-pair)))
|
|
|
|
`(("Choose an action" . ,(choose-an-action show-surflets))
|
|
|
|
("unload" . ,(unload-surflets outdated?))
|
|
|
|
("unload all" . ,(lambda (req _)
|
|
|
|
((unload-surflets outdated?)
|
|
|
|
req loaded-surflets)))))))
|
|
|
|
(select-table title ; title
|
|
|
|
header ; header
|
|
|
|
'((th "Name")) ; table-header
|
|
|
|
loaded-surflets ; list of elements
|
|
|
|
(lambda (surflet) ; selector
|
|
|
|
`((td
|
|
|
|
,(remove-surflet-path surflet))))
|
|
|
|
actions ; actions to perform
|
|
|
|
(cons ; footer
|
|
|
|
`(p "Note that unloading the SUrflets does not imply "
|
|
|
|
"the unloading of sessions of this SUrflet. " (br)
|
|
|
|
"This can be done on the "
|
|
|
|
(url ,(callback show-sessions)
|
|
|
|
"sessions adminstration page."))
|
|
|
|
footer))))))
|
2002-10-01 13:44:58 -04:00
|
|
|
|
2003-04-16 12:03:06 -04:00
|
|
|
(define (session-surflet-name<? session1 session2)
|
|
|
|
(let ((name1 (session-surflet-name session1))
|
|
|
|
(name2 (session-surflet-name session2)))
|
2002-12-07 17:26:40 -05:00
|
|
|
;; handle multiple session names
|
2002-10-02 09:39:55 -04:00
|
|
|
(if (string=? name1 name2)
|
2003-04-16 12:03:06 -04:00
|
|
|
(session-id<? session1 session2)
|
2002-10-02 09:39:55 -04:00
|
|
|
(string<? name1 name2))))
|
2003-04-16 12:03:06 -04:00
|
|
|
(define (session-id<? session1 session2)
|
2002-12-07 17:26:40 -05:00
|
|
|
;; there are no multiple session-ids
|
2003-04-16 12:03:06 -04:00
|
|
|
(< (session-session-id session1)
|
|
|
|
(session-session-id session2)))
|
|
|
|
(define (session-surflet-name>? session1 session2)
|
|
|
|
(session-surflet-name<? session2 session1))
|
|
|
|
(define (session-id>? session1 session2)
|
|
|
|
(session-id<? session2 session1))
|
2002-10-01 13:44:58 -04:00
|
|
|
|
2002-12-07 17:26:40 -05:00
|
|
|
(define (no-current-sessions)
|
2002-10-01 13:44:58 -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, "
|
2003-01-19 11:57:27 -05:00
|
|
|
"i.e. the administration SUrflet is no longer running. "
|
2002-12-07 17:26:40 -05:00
|
|
|
;; Can't use callback here, as there are no valid sessions left.
|
2003-03-10 04:23:41 -05:00
|
|
|
(url "admin.scm" "Go back to main page.")))
|
2002-10-01 13:44:58 -04:00
|
|
|
|
2002-12-07 17:26:40 -05:00
|
|
|
(define (show-sessions req . maybe-update-text)
|
2002-10-02 09:39:55 -04:00
|
|
|
(let* ((update-text (:optional maybe-update-text ""))
|
2003-01-19 11:57:27 -05:00
|
|
|
(current-sessions (sort-list! (get-sessions) session-surflet-name<?)))
|
2003-01-16 07:53:10 -05:00
|
|
|
(real-sessions current-sessions update-text
|
2003-03-09 14:44:09 -05:00
|
|
|
(my-session-id req))))
|
2002-10-02 09:39:55 -04:00
|
|
|
|
2003-04-16 13:11:47 -04:00
|
|
|
(define (kill-sessions outdated? sessions-callback)
|
|
|
|
(lambda (req selected-sessions)
|
|
|
|
(if-outdated outdated?
|
|
|
|
(show-outdated sessions-callback)
|
|
|
|
(for-each delete-session!
|
|
|
|
selected-sessions))
|
|
|
|
(show-sessions req "Sessions killed.")))
|
|
|
|
|
|
|
|
(define (adjust-session-timeout outdated? sessions-callback)
|
|
|
|
(lambda (req selected-sessions)
|
|
|
|
(if-outdated outdated?
|
|
|
|
(show-outdated sessions-callback)
|
|
|
|
(for-each session-adjust-timeout!
|
|
|
|
selected-sessions))
|
|
|
|
(show-sessions req "Timeout adjusted.")))
|
|
|
|
|
|
|
|
(define (view-continuations outdated? sessions-callback)
|
|
|
|
(lambda (req selected-sessions)
|
|
|
|
(if-outdated outdated?
|
|
|
|
(show-outdated sessions-callback)
|
|
|
|
(if (zero? (length selected-sessions))
|
|
|
|
(show-sessions req "You must choose at least one session.")
|
|
|
|
;; this does not return
|
|
|
|
(show-continuations req selected-sessions)))))
|
|
|
|
|
2003-01-16 07:53:10 -05:00
|
|
|
(define (real-sessions current-sessions update-text this-session-id)
|
2003-04-16 12:03:06 -04:00
|
|
|
(let* ((outdated? (make-outdater))
|
2003-08-01 11:02:43 -04:00
|
|
|
(callback (make-annotated-callback callback-function))
|
2003-04-16 13:11:47 -04:00
|
|
|
(title "SUrflet Adminstration - Sessions")
|
|
|
|
(header `((h1 "SUrflet Administration")
|
|
|
|
(h2 "Sessions")
|
|
|
|
(p (font (@ (color "red")) ,update-text))))
|
|
|
|
(footer `(,(if (not (null? current-sessions))
|
|
|
|
`(p "Be careful not to kill this adminstration's "
|
|
|
|
"session (id: " ,this-session-id ").")
|
|
|
|
#f)
|
|
|
|
(hr)
|
|
|
|
(url ,(callback show-surflets)
|
|
|
|
"Return to SUrflets menu.")
|
|
|
|
(br) (url ,(callback return-to-main-page)
|
|
|
|
"Return to administration menu.")
|
|
|
|
(br) (url "/" "Return to main menu.")))
|
2003-04-16 12:03:06 -04:00
|
|
|
(sessions-callback (callback show-sessions)))
|
2002-12-07 17:26:40 -05:00
|
|
|
(if (null? current-sessions)
|
2002-10-02 09:39:55 -04:00
|
|
|
(send-html `(html (title ,title)
|
2002-12-07 17:26:40 -05:00
|
|
|
(body ,@header ,(no-current-sessions) ,footer)))
|
2003-04-16 13:11:47 -04:00
|
|
|
(let ((actions
|
|
|
|
(map (lambda (action-pair)
|
2003-07-08 17:22:06 -04:00
|
|
|
(make-annotated-select-option
|
2003-04-16 13:11:47 -04:00
|
|
|
(car action-pair)
|
|
|
|
(cdr action-pair)))
|
|
|
|
`(("Choose an action" . ,(choose-an-action show-sessions))
|
|
|
|
("kill" . ,(kill-sessions outdated? sessions-callback))
|
|
|
|
("adjust timeout" .
|
|
|
|
,(adjust-session-timeout outdated?
|
|
|
|
sessions-callback))
|
|
|
|
("view continuations" .
|
|
|
|
,(view-continuations outdated?
|
|
|
|
sessions-callback))))))
|
|
|
|
(select-table title
|
|
|
|
header
|
|
|
|
`((th "SUrflet Name") (th "Session-Id"))
|
|
|
|
current-sessions
|
|
|
|
(lambda (session)
|
|
|
|
`((td ,(session-surflet-name session))
|
|
|
|
(td (@ (align "right"))
|
|
|
|
,(session-session-id session))))
|
|
|
|
actions
|
|
|
|
footer)))))
|
2002-10-02 09:39:55 -04:00
|
|
|
|
2003-04-16 12:03:06 -04:00
|
|
|
(define (no-current-continuations callback session req)
|
2002-12-07 17:26:40 -05:00
|
|
|
`((p "Currently, there are no continuations for this session. ")
|
2003-04-16 12:03:06 -04:00
|
|
|
(p "You may " (url ,(callback show-continuations (list session))
|
2002-10-01 13:44:58 -04:00
|
|
|
"reload")
|
2002-10-02 09:39:55 -04:00
|
|
|
" this page or go back to the "
|
2003-04-16 12:03:06 -04:00
|
|
|
(url ,(callback show-sessions) "session table overview."))))
|
2002-10-01 13:44:58 -04:00
|
|
|
|
2003-01-16 07:53:10 -05:00
|
|
|
(define (no-more-than-one-session title header1 sessions req)
|
2003-04-13 17:31:41 -04:00
|
|
|
(let* ((address (make-annotated-address))
|
|
|
|
(req (send-html/suspend
|
|
|
|
(lambda (k-url)
|
|
|
|
`(html
|
|
|
|
(title ,title)
|
|
|
|
(body
|
|
|
|
(h1 "SUrflet Administration")
|
|
|
|
(p "Currently, you may only view the continuations of "
|
|
|
|
"one session at a time. This will be changed in "
|
|
|
|
"future revisions. Sorry for any inconvenience.")
|
|
|
|
(p "You may choose to go back to the "
|
|
|
|
(url ,(make-callback show-sessions)
|
|
|
|
"sessions administration page")
|
|
|
|
" where you can select one session"
|
|
|
|
" or select one session from your chosen sessions:" (br)
|
|
|
|
(ul
|
2003-04-16 12:03:06 -04:00
|
|
|
,@(map
|
|
|
|
(lambda (session)
|
|
|
|
`(li (url ,(address k-url session)
|
|
|
|
,(session-surflet-name session)
|
|
|
|
" (" ,(session-session-id session) ")")))
|
2003-04-13 17:31:41 -04:00
|
|
|
sessions))))))))
|
|
|
|
(bindings (get-bindings req))
|
|
|
|
(chosen-session (returned-via address bindings)))
|
2003-04-16 12:03:06 -04:00
|
|
|
(show-continuations req (list chosen-session))))
|
2002-10-02 09:39:55 -04:00
|
|
|
|
2003-04-16 12:03:06 -04:00
|
|
|
(define (continuation-id<? cont1 cont2)
|
|
|
|
(< (continuation-id cont1)
|
|
|
|
(continuation-id cont2)))
|
2002-10-01 13:44:58 -04:00
|
|
|
|
2003-04-16 12:03:06 -04:00
|
|
|
(define (show-continuations req sessions . maybe-update-text)
|
2003-01-19 11:57:27 -05:00
|
|
|
(let ((title "SUrflet Adminstration - Continuations")
|
|
|
|
(header1 '(h1 "SUrflet Administration")))
|
2002-12-07 17:26:40 -05:00
|
|
|
(if (not (= 1 (length sessions)))
|
2003-01-16 07:53:10 -05:00
|
|
|
(no-more-than-one-session title header1 sessions req)
|
2003-04-16 12:03:06 -04:00
|
|
|
(let* ((session (car sessions))
|
|
|
|
(session-id (session-session-id session))
|
2003-03-09 14:44:09 -05:00
|
|
|
(this-continuation-id (my-continuation-id req))
|
2003-04-16 12:03:06 -04:00
|
|
|
(update-text (:optional maybe-update-text ""))
|
|
|
|
(current-continuations
|
|
|
|
(sort-list! (get-continuations session-id)
|
|
|
|
continuation-id<?))
|
|
|
|
(outdated? (make-outdater))
|
2003-08-01 11:02:43 -04:00
|
|
|
(callback (make-annotated-callback callback-function))
|
2003-04-16 12:03:06 -04:00
|
|
|
(header (cons header1
|
|
|
|
`((h2 "Continuations of " ,session-id)
|
|
|
|
(p "(belongs to the SUrflet '"
|
|
|
|
,(session-surflet-name session) "')")
|
|
|
|
(p (font (@ (color "red")) ,update-text)))))
|
|
|
|
(footer
|
|
|
|
`(,(if (not (null? current-continuations))
|
|
|
|
`(p "Be careful not to delete this adminstration's "
|
|
|
|
"continuation (id: " ,this-continuation-id ").")
|
|
|
|
#f)
|
|
|
|
(hr)
|
2003-04-16 13:11:47 -04:00
|
|
|
(url ,(callback show-sessions)
|
|
|
|
"Return to sessions menu.")
|
|
|
|
(br) (url ,(callback show-surflets)
|
|
|
|
"Return to SUrflets menu.")
|
2003-04-16 12:03:06 -04:00
|
|
|
(br) (url ,(callback return-to-main-page)
|
|
|
|
"Return to administration menu.")
|
|
|
|
(br) (url "/" "Return to main menu.")))
|
|
|
|
(continuations-callback (callback show-continuations sessions)))
|
|
|
|
(if (null? current-continuations)
|
|
|
|
(send-html
|
|
|
|
`(html (title ,title)
|
|
|
|
(body ,header
|
|
|
|
,(no-current-continuations callback session req)
|
|
|
|
,footer)))
|
2003-04-16 13:11:47 -04:00
|
|
|
(let ((actions
|
|
|
|
(map (lambda (action-pair)
|
2003-07-08 17:22:06 -04:00
|
|
|
(make-annotated-select-option
|
2003-04-16 13:11:47 -04:00
|
|
|
(car action-pair)
|
|
|
|
(cdr action-pair)))
|
|
|
|
`(("Choose an action" .
|
|
|
|
,(lambda (req _)
|
|
|
|
(show-continuations req sessions
|
|
|
|
"Choose an action.")))
|
|
|
|
("delete" .
|
|
|
|
,(lambda (req selected-continuations)
|
|
|
|
(delete-continuations outdated?
|
|
|
|
continuations-callback
|
|
|
|
selected-continuations)
|
|
|
|
(show-continuations req sessions
|
|
|
|
"Deleted.")))
|
|
|
|
("delete all" .
|
|
|
|
,(lambda (req _)
|
|
|
|
(delete-continuations outdated?
|
|
|
|
continuations-callback
|
|
|
|
current-continuations)
|
|
|
|
(show-continuations req sessions
|
|
|
|
"Deleted.")))))))
|
|
|
|
(select-table title
|
|
|
|
header
|
|
|
|
'((th "Continuation-Id"))
|
|
|
|
current-continuations
|
|
|
|
(lambda (continuation)
|
|
|
|
`((td (@ (align "right"))
|
|
|
|
,(continuation-id continuation))))
|
|
|
|
actions
|
|
|
|
footer)))))))
|
2002-10-02 09:39:55 -04:00
|
|
|
|
|
|
|
(define (delete-continuations outdated? continuations-callback
|
2003-04-16 13:11:47 -04:00
|
|
|
continuations)
|
2002-10-02 09:39:55 -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-02 09:39:55 -04:00
|
|
|
;; future.
|
2003-04-16 12:03:06 -04:00
|
|
|
(for-each delete-continuation! continuations)))
|
2002-10-01 13:44:58 -04:00
|
|
|
|
|
|
|
(define (return-to-main-page req)
|
2003-01-25 08:24:22 -05:00
|
|
|
(send-error (status-code moved-perm) req
|
|
|
|
"admin.scm" "admin.scm"))
|
2002-10-01 13:44:58 -04:00
|
|
|
|
|
|
|
(define (main req)
|
2003-01-19 11:57:27 -05:00
|
|
|
(show-surflets req))
|
2002-10-01 13:44:58 -04:00
|
|
|
|
|
|
|
))
|