* move some more vars from the session context to strbuf (the use of StrBufAppendTemp...
[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"), 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         char buf[SIZ];
263         char gcontent[SIZ];
264         char *junk;
265         size_t len;
266
267         if (!havebstr("sc_button")) {
268                 display_main_menu();
269                 return;
270         }
271
272         output_headers(1, 1, 0, 0, 0, 0);
273
274         serv_printf("%s", bstr("g_cmd"));
275         serv_getln(buf, sizeof buf);
276
277         svput("BOXTITLE", WCS_STRING, _("Server command results"));
278         do_template("beginboxx", NULL);
279
280         wprintf("<table border=0><tr><td>Command:</td><td><tt>");
281         escputs(bstr("g_cmd"));
282         wprintf("</tt></td></tr><tr><td>Result:</td><td><tt>");
283         escputs(buf);
284         wprintf("</tt></td></tr></table><br />\n");
285
286         if (buf[0] == '8') {
287                 serv_printf("\n\n000");
288         }
289         if ((buf[0] == '1') || (buf[0] == '8')) {
290                 while (serv_getln(gcontent, sizeof gcontent), strcmp(gcontent, "000")) {
291                         escputs(gcontent);
292                         wprintf("<br />\n");
293                 }
294                 wprintf("000");
295         }
296         if (buf[0] == '4') {
297                 text_to_server(bstr("g_input"));
298                 serv_puts("000");
299         }
300         if (buf[0] == '6') {
301                 len = atol(&buf[4]);
302                 junk = malloc(len);
303                 serv_read(junk, len);
304                 free(junk);
305         }
306         if (buf[0] == '7') {
307                 len = atol(&buf[4]);
308                 junk = malloc(len);
309                 memset(junk, 0, len);
310                 serv_write(junk, len);
311                 free(junk);
312         }
313         wprintf("<hr />");
314         wprintf("<a href=\"display_generic\">Enter another command</a><br />\n");
315         wprintf("<a href=\"display_advanced\">Return to menu</a>\n");
316         do_template("endbox", NULL);
317         wDumpContent(1);
318 }
319
320
321 /*
322  * Display the menubar.  
323  *
324  * Set 'as_single_page' to display HTML headers and footers -- otherwise it's assumed
325  * that the menubar is being embedded in another page.
326  */
327 void display_menubar(int as_single_page) {
328
329         if (as_single_page) {
330                 output_headers(0, 0, 0, 0, 0, 0);
331                 wprintf("<html>\n"
332                         "<head>\n"
333                         "<title>MenuBar</title>\n"
334                         "<style type=\"text/css\">\n"
335                         "body   { text-decoration: none; }\n"
336                         "</style>\n"
337                         "</head>\n");
338                 do_template("background", NULL);
339         }
340
341         do_template("menubar", NULL);
342
343         if (as_single_page) {
344                 wDumpContent(2);
345         }
346
347
348 }
349
350
351 /*
352  * Display the wait / input dialog while restarting the server.
353  */
354 void display_shutdown(void)
355 {
356         char buf[SIZ];
357         char *when;
358         
359         when=bstr("when");
360         if (strcmp(when, "now") == 0){
361                 serv_printf("DOWN 1");
362                 serv_getln(buf, sizeof buf);
363                 if (atol(buf) == 500)
364                 { /* upsie. maybe the server is not running as daemon? */
365                         
366                         safestrncpy(WC->ImportantMessage,
367                                     &buf[4],
368                                     sizeof WC->ImportantMessage);
369                 }
370                 begin_burst();
371                 output_headers(1, 0, 0, 0, 1, 0);
372                 DoTemplate(HKEY("display_serverrestart"), NULL, &NoCtx);
373                 end_burst();
374                 lingering_close(WC->http_sock);
375                 sleeeeeeeeeep(10);
376                 serv_printf("NOOP");
377                 serv_printf("NOOP");
378         }
379         else if (strcmp(when, "page") == 0) {
380                 char *message;
381                
382                 message = bstr("message");
383                 if ((message == NULL) || (IsEmptyStr(message)))
384                 {
385                         begin_burst();
386                         output_headers(1, 0, 0, 0, 1, 0);
387                         DoTemplate(HKEY("display_serverrestartpage"), NULL, &NoCtx);
388                         end_burst();
389                 }
390                 else
391                 {
392                         serv_printf("SEXP broadcast|%s", message);
393                         serv_getln(buf, sizeof buf); /* TODO: should we care? */
394                         begin_burst();
395                         output_headers(1, 0, 0, 0, 1, 0);
396                         DoTemplate(HKEY("display_serverrestartpagedo"), NULL, &NoCtx);
397                         end_burst();                    
398                 }
399         }
400         else if (!strcmp(when, "idle")) {
401                 serv_printf("SCDN 3");
402                 serv_getln(buf, sizeof buf);
403
404                 if (atol(buf) == 500)
405                 { /* upsie. maybe the server is not running as daemon? */
406                         safestrncpy(WC->ImportantMessage,
407                                     &buf[4],
408                                     sizeof WC->ImportantMessage);
409                 }
410                 begin_burst();
411                 output_headers(1, 0, 0, 0, 1, 0);
412                 DoTemplate(HKEY("display_aide_menu"), NULL, &NoCtx);
413                 end_burst();                    
414         }
415 }
416
417 void _display_menubar(void) { display_menubar(0); }
418
419 void 
420 InitModule_MAINMENU
421 (void)
422 {
423         WebcitAddUrlHandler(HKEY("display_aide_menu"), display_aide_menu, 0);
424         WebcitAddUrlHandler(HKEY("server_shutdown"), display_shutdown, 0);
425         WebcitAddUrlHandler(HKEY("display_main_menu"), display_main_menu, 0);
426         WebcitAddUrlHandler(HKEY("display_generic"), display_generic, 0);
427         WebcitAddUrlHandler(HKEY("do_generic"), do_generic, 0);
428         WebcitAddUrlHandler(HKEY("display_menubar"), _display_menubar, 0);
429 }