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