1 | ;;+----------------------------------------------------------------------------- |
---|
2 | ;;+ Isidorus |
---|
3 | ;;+ (c) 2008-2010 Marc Kuester, Christoph Ludwig, Lukas Georgieff |
---|
4 | ;;+ |
---|
5 | ;;+ Isidorus is freely distributable under the LLGPL license. |
---|
6 | ;;+ You can find a detailed description in trunk/docs/LLGPL-LICENSE.txt and |
---|
7 | ;;+ trunk/docs/LGPL-LICENSE.txt. |
---|
8 | ;;+----------------------------------------------------------------------------- |
---|
9 | |
---|
10 | (in-package :rest-interface) |
---|
11 | |
---|
12 | ;;TODO: add functions to export statement |
---|
13 | |
---|
14 | (defparameter *admin-local-backup* "/admin/local-backup") |
---|
15 | (defparameter *admin-remote-backup* "/admin/remote-backup") |
---|
16 | (defparameter *admin-shutdown* "/admin/shutdown") |
---|
17 | |
---|
18 | |
---|
19 | (defparameter *ready-to-die* nil) |
---|
20 | |
---|
21 | (defun set-up-admin-interface () |
---|
22 | (push |
---|
23 | (create-regex-dispatcher *admin-local-backup* #'admin-local-backup) |
---|
24 | hunchentoot:*dispatch-table*) |
---|
25 | (push |
---|
26 | (create-regex-dispatcher *admin-remote-backup* #'admin-remote-backup) |
---|
27 | hunchentoot:*dispatch-table*) |
---|
28 | (push |
---|
29 | (create-regex-dispatcher *admin-shutdown* #'admin-shutdown) |
---|
30 | hunchentoot:*dispatch-table*)) |
---|
31 | |
---|
32 | |
---|
33 | |
---|
34 | (defun admin-shutdown() |
---|
35 | (handler-case |
---|
36 | (if (string= *shutdown-remote-address* (hunchentoot:remote-addr*)) |
---|
37 | (progn |
---|
38 | (when elephant:*store-controller* |
---|
39 | (xtm-exporter:export-as-xtm |
---|
40 | (concat "backup_" (make-date-string (get-universal-time)) ".xtm") |
---|
41 | :revision 0)) |
---|
42 | (shutdown-json-engine) |
---|
43 | (shutdown-atom-engine) |
---|
44 | (shutdown-admin-server) |
---|
45 | (close-tm-store) ;in case the json and atom services are not running |
---|
46 | (setf *ready-to-die* t)) |
---|
47 | (setf (hunchentoot:return-code*) hunchentoot:+http-forbidden+)) |
---|
48 | (condition (err) |
---|
49 | (progn |
---|
50 | (tools:close-tm-store) |
---|
51 | (setf (hunchentoot:return-code*) hunchentoot:+http-internal-server-error+) |
---|
52 | (setf (hunchentoot:content-type*) "text") |
---|
53 | (format nil "closed the tm store, but:~%condition: \"~a\"" err))))) |
---|
54 | |
---|
55 | |
---|
56 | |
---|
57 | |
---|
58 | (defun admin-local-backup() |
---|
59 | (handler-case |
---|
60 | (if (string= *local-backup-remote-address* (hunchentoot:remote-addr*)) |
---|
61 | (let ((destination-path |
---|
62 | (hunchentoot:url-decode (hunchentoot:get-parameter "path")))) |
---|
63 | (xtm-exporter:export-as-xtm destination-path :revision 0)) |
---|
64 | (setf (hunchentoot:return-code*) hunchentoot:+http-forbidden+)) |
---|
65 | (condition (err) |
---|
66 | (progn |
---|
67 | (setf (hunchentoot:return-code*) hunchentoot:+http-internal-server-error+) |
---|
68 | (setf (hunchentoot:content-type*) "text") |
---|
69 | (format nil "Condition: \"~a\"" err))))) |
---|
70 | |
---|
71 | |
---|
72 | (defun admin-remote-backup() |
---|
73 | (handler-case |
---|
74 | (if (string= *remote-backup-remote-address* (hunchentoot:remote-addr*)) |
---|
75 | (progn (hunchentoot:url-decode (hunchentoot:get-parameter "path")) |
---|
76 | (setf (hunchentoot:content-type*) "application/xml") |
---|
77 | (xtm-exporter:export-as-xtm-string :revision 0)) |
---|
78 | (setf (hunchentoot:return-code*) hunchentoot:+http-forbidden+)) |
---|
79 | (condition (err) |
---|
80 | (progn |
---|
81 | (setf (hunchentoot:return-code*) hunchentoot:+http-internal-server-error+) |
---|
82 | (setf (hunchentoot:content-type*) "text") |
---|
83 | (format nil "Condition: \"~a\"" err))))) |
---|
84 | |
---|
85 | |
---|
86 | (defun make-date-string (universal-time) |
---|
87 | (tools:concat |
---|
88 | (write-to-string (nth-value 3 (decode-universal-time universal-time))) "." |
---|
89 | (write-to-string (nth-value 4 (decode-universal-time universal-time))) "." |
---|
90 | (write-to-string (nth-value 5 (decode-universal-time universal-time))) ":" |
---|
91 | (write-to-string (nth-value 2 (decode-universal-time universal-time))) ":" |
---|
92 | (write-to-string (nth-value 1 (decode-universal-time universal-time))) ":" |
---|
93 | (write-to-string (nth-value 0 (decode-universal-time universal-time))))) |
---|
94 | |
---|
95 | |
---|
96 | |
---|
97 | (defun die-when-finished() |
---|
98 | (do () (rest-interface:*ready-to-die*) |
---|
99 | (sleep 1)) |
---|
100 | (sb-ext:quit)) |
---|