31aec39861201d1ab941a9dc5b0ebc399d66a754
[citadel] / webcit / mainmenu.c
1 #include "webcit.h"
2
3 /*
4  * The Main Menu
5  */
6 void display_main_menu(void)
7 {
8         begin_burst();
9         output_headers(1, 0, 0, 0, 1, 0);
10         DoTemplate(HKEY("display_main_menu"), NULL, &NoCtx);
11         end_burst();
12 }
13
14
15 /*
16  * System administration menu
17  */
18 void display_aide_menu(void)
19 {
20         begin_burst();
21         output_headers(1, 0, 0, 0, 1, 0);
22         DoTemplate(HKEY("aide_display_menu"), NULL, &NoCtx);
23         end_burst();
24 }
25
26
27 /*
28  * Interactive window to perform generic Citadel server commands.
29  */
30 void do_generic(void)
31 {
32         WCTemplputParams SubTP;
33         int Done = 0;
34         StrBuf *Buf;
35         StrBuf *LineBuf;
36         char *junk;
37         size_t len;
38
39         if (!havebstr("sc_button")) {
40                 display_main_menu();
41                 return;
42         }
43
44         Buf = NewStrBuf();
45         serv_puts(bstr("g_cmd"));
46         StrBuf_ServGetln(Buf);
47         
48         switch (GetServerStatus(Buf, NULL)) {
49         case 8:
50                 serv_puts("\n\n000");
51                 if ( (StrLength(Buf)==3) && 
52                      !strcmp(ChrPtr(Buf), "000")) {
53                         StrBufAppendBufPlain(Buf, HKEY("\000"), 0);
54                         break;
55                 }
56         case 1:
57                 LineBuf = NewStrBuf();
58                 StrBufAppendBufPlain(Buf, HKEY("\n"), 0);
59                 while (!Done) {
60                         if (StrBuf_ServGetln(LineBuf) < 0)
61                                 break;
62                         if ( (StrLength(LineBuf)==3) && 
63                              !strcmp(ChrPtr(LineBuf), "000")) {
64                                 Done = 1;
65                         }
66                         StrBufAppendBuf(Buf, LineBuf, 0);
67                         StrBufAppendBufPlain(Buf, HKEY("\n"), 0);
68                 }
69                 FreeStrBuf(&LineBuf);
70                 break;
71         case 2:
72                 break;
73         case 4:
74                 text_to_server(bstr("g_input"));
75                 serv_puts("000");
76                 break;
77         case 6:
78                 len = atol(&ChrPtr(Buf)[4]);
79                 StrBuf_ServGetBLOBBuffered(Buf, len);
80                 break;
81         case 7:
82                 len = atol(&ChrPtr(Buf)[4]);
83                 junk = malloc(len);
84                 memset(junk, 0, len);
85                 serv_write(junk, len);
86                 free(junk);
87                 break;
88         }
89         
90         begin_burst();
91         output_headers(1, 0, 0, 0, 1, 0);
92
93         StackContext(NULL, &SubTP, Buf, CTX_STRBUF, 0, NULL);
94         {
95                 DoTemplate(HKEY("aide_display_generic_result"), NULL, &SubTP);
96         }
97         UnStackContext(&SubTP);
98         wDumpContent(1);
99
100         FreeStrBuf(&Buf);
101 }
102
103 /*
104  * Display the wait / input dialog while restarting the server.
105  */
106 void display_shutdown(void)
107 {
108         StrBuf *Line;
109         char *when;
110         
111         Line = NewStrBuf();
112         when=bstr("when");
113         if (strcmp(when, "now") == 0){
114                 serv_printf("DOWN 1");
115                 StrBuf_ServGetln(Line);
116                 GetServerStatusMsg(Line, NULL, 1, 5);
117
118                 begin_burst();
119                 output_headers(1, 0, 0, 0, 1, 0);
120                 DoTemplate(HKEY("aide_display_serverrestart"), NULL, &NoCtx);
121                 end_burst();
122                 lingering_close(WC->Hdr->http_sock);
123                 sleeeeeeeeeep(10);
124                 serv_printf("NOOP");
125                 serv_printf("NOOP");
126         }
127         else if (strcmp(when, "page") == 0) {
128                 char *message;
129                
130                 message = bstr("message");
131                 if ((message == NULL) || (IsEmptyStr(message)))
132                 {
133                         begin_burst();
134                         output_headers(1, 0, 0, 0, 1, 0);
135                         DoTemplate(HKEY("aide_display_serverrestart_page"), NULL, &NoCtx);
136                         end_burst();
137                 }
138                 else
139                 {
140                         serv_printf("SEXP broadcast|%s", message);
141                         StrBuf_ServGetln(Line);
142                         GetServerStatusMsg(Line, NULL, 1, 0);
143
144                         begin_burst();
145                         output_headers(1, 0, 0, 0, 1, 0);
146                         DoTemplate(HKEY("aide_display_serverrestart_page"), NULL, &NoCtx);
147                         end_burst();                    
148                 }
149         }
150         else if (!strcmp(when, "idle")) {
151                 serv_printf("SCDN 3");
152                 StrBuf_ServGetln(Line);
153                 GetServerStatusMsg(Line, NULL, 1, 2);
154
155                 begin_burst();
156                 output_headers(1, 0, 0, 0, 1, 0);
157                 DoTemplate(HKEY("aide_display_menu"), NULL, &NoCtx);
158                 end_burst();                    
159         }
160         FreeStrBuf(&Line);
161 }
162
163 void 
164 InitModule_MAINMENU
165 (void)
166 {
167         WebcitAddUrlHandler(HKEY("display_aide_menu"), "", 0, display_aide_menu, 0);
168         WebcitAddUrlHandler(HKEY("server_shutdown"), "", 0, display_shutdown, 0);
169         WebcitAddUrlHandler(HKEY("display_main_menu"), "", 0, display_main_menu, 0);
170         WebcitAddUrlHandler(HKEY("do_generic"), "", 0, do_generic, 0);
171 }