f4420d978805626864bd98c32889894656f656f7
[citadel.git] / webcit / mainmenu.c
1 /*
2  * $Id$
3  */
4
5 #include "webcit.h"
6
7 /*
8  * The Main Menu
9  */
10 void display_main_menu(void)
11 {
12         begin_burst();
13         output_headers(1, 0, 0, 0, 1, 0);
14         DoTemplate(HKEY("display_main_menu"), NULL, &NoCtx);
15         end_burst();
16
17 /*
18         char buf[SIZ];
19         output_headers(1, 1, 1, 0, 0, 0);
20
21         wprintf("<div class=\"fix_scrollbar_bug\">"
22                 "<table width=\"100%%\" cellspacing=\"10\" cellpadding=\"0\">"
23                 "<tr><td colspan=\"2\" class=\"advanced\">\n");
24
25         svput("BOXTITLE", WCS_STRING, _("Basic commands"));
26         do_template("beginbox", NULL);
27
28         / * start of first column * /
29         wprintf("<ul class=\"adminitems col1\">");
30
31         wprintf("<li><a href=\"knrooms\">");
32         wprintf(_("List known rooms"));
33         wprintf("</a><span>");
34         wprintf(_("Where can I go from here?"));
35         wprintf("</span></li>\n");
36
37         wprintf("<li><a href=\"gotonext\">");
38         wprintf(_("Goto next room"));
39         wprintf("</a><span>");
40         wprintf(_("...with <em>unread</em> messages"));
41         wprintf("</span></li>\n");
42
43         wprintf("<li><a href=\"skip\">");
44         wprintf(_("Skip to next room"));
45         wprintf("</a><span>");
46         wprintf(_("(come back here later)"));
47         wprintf("</span></li>\n");
48
49         if ((!IsEmptyStr(WC->ugname)) && (strcasecmp(WC->ugname, WC->wc_roomname))) {
50                 wprintf("<li><a href=\"ungoto\">");
51                 wprintf(_("Ungoto"));
52                 wprintf("</a><span>");
53                 wprintf(_("(oops! Back to %s)"), WC->ugname);
54                 wprintf("</span></li>\n");
55         }
56
57         wprintf("</ul>\n");
58
59         / * start of second column * /
60
61         wprintf("<ul class=\"adminitems col2\">");
62
63         wprintf("<li><a href=\"readnew\">");
64         wprintf(_("Read new messages"));
65         wprintf("</a><span>");
66         wprintf(_("...in this room"));
67         wprintf("</span></li>\n");
68
69         wprintf("<li><a href=\"readfwd\">");
70         wprintf(_("Read all messages"));
71         wprintf("</a><span>");
72         wprintf(_("...old <EM>and</EM> new"));
73         wprintf("</span></li>\n");
74
75         wprintf("<li><a href=\"display_enter\">");
76         wprintf(_("Enter a message"));
77         wprintf("</a><span>");
78         wprintf(_("(post in this room)"));
79         wprintf("</span></li>\n");
80
81         if (WC->room_flags & QR_VISDIR) {
82                 wprintf("<li><a href=\"display_room_directory\">");
83                 wprintf(_("File library"));
84                 wprintf("</a><span>");
85                 wprintf(_("(List files available for download)"));
86                 wprintf("</span></li>\n");
87         }
88
89         wprintf("</ul>\n");
90
91         / * start of third column * /
92
93         wprintf("<ul class=\"adminitems lastcol\">");
94
95         wprintf("<li><a href=\"summary\">");
96         wprintf(_("Summary page"));
97         wprintf("</a><span>");
98         wprintf(_("Summary of my account"));
99         wprintf("</span></li>\n");
100
101         wprintf("<li><a href=\"userlist\">\n");
102         wprintf(_("User list"));
103         wprintf("</a><span>");
104         wprintf(_("(all registered users)"));
105         wprintf("</span></li>\n");
106
107         wprintf("<li><a href=\"termquit\" TARGET=\"_top\">");
108         wprintf(_("Log off"));
109         wprintf("</a><span>");
110         wprintf(_("Bye!"));
111         wprintf("</span></li>\n");
112
113         wprintf("</ul>\n");
114
115         wprintf("&nbsp;");
116
117         do_template("endbox", NULL);
118
119         wprintf("</td></tr>"
120                 "<tr valign=top><td width=50%%>");
121
122         print_menu_box(_("Your info"), "adminitems", 8,
123                        "display_preferences", _("Change your preferences and settings"),
124                        "display_reg", _("Update your contact information"),
125                        "display_changepw", _("Change your password"),
126                        "display_editbio", _("Enter your 'bio'"),
127                        "display_editpic", _("Edit your online photo"), 
128                        "display_sieve", _("View/edit server-side mail filters"),
129                        "display_pushemail", _("Edit your push email settings"),
130                        "display_openids", _("Manage your OpenIDs")
131         );
132
133         wprintf("</td><td width=50%%>");
134
135         snprintf(buf, SIZ, _("Zap (forget) this room (%s)"), WC->wc_roomname);
136
137         if ( (WC->axlevel >= 6) || (WC->is_room_aide) || (WC->is_mailbox) )
138                 print_menu_box(_("Advanced room commands"),"adminitems", 5,
139                                "display_editroom", _("Edit or delete this room"),
140                                "display_private", _("Go to a 'hidden' room"),
141                                "display_entroom", _("Create a new room"),
142                                "display_zap",buf,
143                                "zapped_list",_("List all forgotten rooms"));
144         else
145                 print_menu_box(_("Advanced room commands"),"adminitems", 4,
146                                "display_private", _("Go to a 'hidden' room"),
147                                "display_entroom", _("Create a new room"),
148                                "display_zap",buf,
149                                "zapped_list",_("List all forgotten rooms"));
150
151         wprintf("</td></tr></table></div>");
152         wDumpContent(2);
153 */
154 }
155
156
157 /*
158  * System administration menu
159  */
160 void display_aide_menu(void)
161 {
162         begin_burst();
163         output_headers(1, 0, 0, 0, 1, 0);
164         DoTemplate(HKEY("display_aide_menu"), NULL, &NoCtx);
165         end_burst();
166 /*
167         output_headers(1, 1, 2, 0, 0, 0);
168
169         wprintf("<div id=\"banner\">\n");
170         wprintf("<h1>");
171         wprintf(_("System Administration Menu"));
172         wprintf("</h1>");
173         wprintf("</div>\n");
174
175         wprintf("<div id=\"content\" class=\"service\">");
176
177         wprintf("<div class=\"fix_scrollbar_bug\">"
178                 "<table> "
179                 "<tr valign=top><td width=50%% valign=\"top\">");
180
181         print_menu_box(_("Global Configuration"), "adminitems", 4,
182                        "display_siteconfig", _("Edit site-wide configuration"), 
183                        "display_inetconf",_("Domain names and Internet mail configuration"),
184                        "display_netconf", _("Configure replication with other Citadel servers"), 
185                        "display_smtpqueue", _("View the outbound SMTP queue"));
186         
187         wprintf("</td><td width=50%% valign=\"top\">");
188
189         print_menu_box(_("User account management"), "adminitems", 2, 
190                        "select_user_to_edit", _("Add, change, delete user accounts"),
191                        "validate", _("Validate new users"));
192
193         wprintf("</td></tr><tr><td width=50%% valign=\"top\">");
194
195
196         print_menu_box(_("Shutdown Citadel"), "adminitems", 3, 
197                        "server_shutdown?when=now", _("Restart Now"),
198                        "server_shutdown?when=page", _("Restart after paging users"),
199                        "server_shutdown?when=idle", _("Restart when all users are idle"));
200
201         wprintf("</td><td width=50%% valign=\"top\">");
202
203         print_menu_box(_("Rooms and Floors"), "adminitems", 1, 
204                        "display_floorconfig", _("Add, change, or delete floors"));
205
206         wprintf("</td></tr></table></div>");
207         wDumpContent(2);
208 */
209 }
210
211
212
213 /*
214  * Display the screen to enter a generic server command
215  */
216 void display_generic(void)
217 {
218         output_headers(1, 1, 2, 0, 0, 0);
219         wprintf("<div id=\"banner\">\n");
220         wprintf("<h1>");
221         wprintf(_("Enter a server command"));
222         wprintf("</h1>");
223         wprintf("</div>\n");
224
225         wprintf("<div id=\"content\" class=\"service\">\n");
226
227         wprintf("<div class=\"fix_scrollbar_bug\">"
228                 "<table class=\"mainmenu_background\"><tr><td>\n");
229
230         wprintf("<center>");
231         wprintf(_("This screen allows you to enter Citadel server commands which are "
232                 "not supported by WebCit.  If you do not know what that means, "
233                 "then this screen will not be of much use to you."));
234         wprintf("<br />\n");
235
236         wprintf("<form method=\"post\" action=\"do_generic\">\n");
237         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
238
239         wprintf(_("Enter command:"));
240         wprintf("<br /><input type=\"text\" name=\"g_cmd\" size=80 maxlength=\"250\"><br />\n");
241
242         wprintf(_("Command input (if requesting SEND_LISTING transfer mode):"));
243         wprintf("<br /><textarea name=\"g_input\" rows=10 cols=80 width=80></textarea><br />\n");
244
245         wprintf("<font size=-2>");
246         wprintf(_("Detected host header is %s://%s"), (is_https ? "https" : "http"), ChrPtr(WC->http_host));
247         wprintf("</font>\n");
248         wprintf("<input type=\"submit\" name=\"sc_button\" value=\"%s\">", _("Send command"));
249         wprintf("&nbsp;");
250         wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\"><br />\n", _("Cancel"));
251
252         wprintf("</form></center>\n");
253         wprintf("</td></tr></table></div>\n");
254         wDumpContent(1);
255 }
256
257 /*
258  * Interactive window to perform generic Citadel server commands.
259  */
260 void do_generic(void)
261 {
262
263         wcsession *WCC = WC;
264         int Done = 0;
265         StrBuf *Buf;
266         char *junk;
267         size_t len;
268
269         if (!havebstr("sc_button")) {
270                 display_main_menu();
271                 return;
272         }
273
274         output_headers(1, 1, 0, 0, 0, 0);
275
276         serv_puts(bstr("g_cmd"));
277
278         svput("BOXTITLE", WCS_STRING, _("Server command results"));
279         do_template("beginboxx", NULL);
280
281         wprintf("<table border=0><tr><td>Command:</td><td><tt>");
282         StrEscAppend(WCC->WBuf, sbstr("g_cmd"), NULL, 0, 0);
283         wprintf("</tt></td></tr><tr><td>Result:</td><td><tt>");
284         StrEscAppend(WCC->WBuf, Buf, NULL, 0, 0);
285         StrBufAppendBufPlain(WCC->WBuf, HKEY("<br>\n"), 0);
286         wprintf("</tt></td></tr></table><br />\n");
287         
288         switch (GetServerStatus(Buf, NULL)) {
289         case 8:
290                 serv_puts("\n\n000");
291                 if ( (StrLength(Buf)==3) && 
292                      !strcmp(ChrPtr(Buf), "000")) {
293                         StrBufAppendBufPlain(WCC->WBuf, HKEY("\000"), 0);
294                         break;
295                 }
296         case 1:
297                 while (!Done) {
298                         StrBuf_ServGetlnBuffered(Buf);
299                         if ( (StrLength(Buf)==3) && 
300                              !strcmp(ChrPtr(Buf), "000")) {
301                                 Done = 1;
302                         }
303                         StrEscAppend(WCC->WBuf, Buf, NULL, 0, 0);
304                         StrBufAppendBufPlain(WCC->WBuf, HKEY("<br>\n"), 0);
305                 }
306                 break;
307         case 4:
308                 text_to_server(bstr("g_input"));
309                 serv_puts("000");
310                 break;
311         case 6:
312                 len = atol(&ChrPtr(Buf)[4]);
313                 StrBuf_ServGetBLOBBuffered(Buf, len);
314                 break;
315         case 7:
316                 len = atol(&ChrPtr(Buf)[4]);
317                 junk = malloc(len);
318                 memset(junk, 0, len);
319                 serv_write(junk, len);
320                 free(junk);
321         }
322         
323         wprintf("<hr />");
324         wprintf("<a href=\"display_generic\">Enter another command</a><br />\n");
325         wprintf("<a href=\"display_advanced\">Return to menu</a>\n");
326         do_template("endbox", NULL);
327         wDumpContent(1);
328 }
329
330
331 /*
332  * Display the menubar.  
333  *
334  * Set 'as_single_page' to display HTML headers and footers -- otherwise it's assumed
335  * that the menubar is being embedded in another page.
336  */
337 void display_menubar(int as_single_page) {
338
339         if (as_single_page) {
340                 output_headers(0, 0, 0, 0, 0, 0);
341                 wprintf("<html>\n"
342                         "<head>\n"
343                         "<title>MenuBar</title>\n"
344                         "<style type=\"text/css\">\n"
345                         "body   { text-decoration: none; }\n"
346                         "</style>\n"
347                         "</head>\n");
348                 do_template("background", NULL);
349         }
350
351         do_template("menubar", NULL);
352
353         if (as_single_page) {
354                 wDumpContent(2);
355         }
356
357
358 }
359
360
361 /*
362  * Display the wait / input dialog while restarting the server.
363  */
364 void display_shutdown(void)
365 {
366         char buf[SIZ];
367         char *when;
368         
369         when=bstr("when");
370         if (strcmp(when, "now") == 0){
371                 serv_printf("DOWN 1");
372                 serv_getln(buf, sizeof buf);
373                 if (atol(buf) == 500)
374                 { /* upsie. maybe the server is not running as daemon? */
375                         
376                         safestrncpy(WC->ImportantMessage,
377                                     &buf[4],
378                                     sizeof WC->ImportantMessage);
379                 }
380                 begin_burst();
381                 output_headers(1, 0, 0, 0, 1, 0);
382                 DoTemplate(HKEY("display_serverrestart"), NULL, &NoCtx);
383                 end_burst();
384                 lingering_close(WC->http_sock);
385                 sleeeeeeeeeep(10);
386                 serv_printf("NOOP");
387                 serv_printf("NOOP");
388         }
389         else if (strcmp(when, "page") == 0) {
390                 char *message;
391                
392                 message = bstr("message");
393                 if ((message == NULL) || (IsEmptyStr(message)))
394                 {
395                         begin_burst();
396                         output_headers(1, 0, 0, 0, 1, 0);
397                         DoTemplate(HKEY("display_serverrestartpage"), NULL, &NoCtx);
398                         end_burst();
399                 }
400                 else
401                 {
402                         serv_printf("SEXP broadcast|%s", message);
403                         serv_getln(buf, sizeof buf); /* TODO: should we care? */
404                         begin_burst();
405                         output_headers(1, 0, 0, 0, 1, 0);
406                         DoTemplate(HKEY("display_serverrestartpagedo"), NULL, &NoCtx);
407                         end_burst();                    
408                 }
409         }
410         else if (!strcmp(when, "idle")) {
411                 serv_printf("SCDN 3");
412                 serv_getln(buf, sizeof buf);
413
414                 if (atol(buf) == 500)
415                 { /* upsie. maybe the server is not running as daemon? */
416                         safestrncpy(WC->ImportantMessage,
417                                     &buf[4],
418                                     sizeof WC->ImportantMessage);
419                 }
420                 begin_burst();
421                 output_headers(1, 0, 0, 0, 1, 0);
422                 DoTemplate(HKEY("display_aide_menu"), NULL, &NoCtx);
423                 end_burst();                    
424         }
425 }
426
427 void _display_menubar(void) { display_menubar(0); }
428
429 void 
430 InitModule_MAINMENU
431 (void)
432 {
433         WebcitAddUrlHandler(HKEY("display_aide_menu"), display_aide_menu, 0);
434         WebcitAddUrlHandler(HKEY("server_shutdown"), display_shutdown, 0);
435         WebcitAddUrlHandler(HKEY("display_main_menu"), display_main_menu, 0);
436         WebcitAddUrlHandler(HKEY("display_generic"), display_generic, 0);
437         WebcitAddUrlHandler(HKEY("do_generic"), do_generic, 0);
438         WebcitAddUrlHandler(HKEY("display_menubar"), _display_menubar, 0);
439 }