* we have now several bstrs:
[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 width=\"100%%\" cellspacing=\"10px\" cellpadding=\"0\">"
22                 "<tr><td colspan=\"2\" class=\"advanced\">\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", 7,
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                        "display_pushemail", _("Edit your push email settings"));
129
130         wprintf("</td><td width=50%%>");
131
132         snprintf(buf, SIZ, _("Zap (forget) this room (%s)"), WC->wc_roomname);
133
134         if ( (WC->axlevel >= 6) || (WC->is_room_aide) || (WC->is_mailbox) )
135                 print_menu_box(_("Advanced room commands"),"adminitems", 5,
136                                "display_editroom", _("Edit or delete this room"),
137                                "display_private", _("Go to a 'hidden' room"),
138                                "display_entroom", _("Create a new room"),
139                                "display_zap",buf,
140                                "zapped_list",_("List all forgotten rooms"));
141         else
142                 print_menu_box(_("Advanced room commands"),"adminitems", 4,
143                                "display_private", _("Go to a 'hidden' room"),
144                                "display_entroom", _("Create a new room"),
145                                "display_zap",buf,
146                                "zapped_list",_("List all forgotten rooms"));
147
148         wprintf("</td></tr></table></div>");
149         wDumpContent(2);
150 }
151
152
153 /**
154  * \brief System administration menu
155  */
156 void display_aide_menu(void)
157 {
158         output_headers(1, 1, 2, 0, 0, 0);
159
160         wprintf("<div id=\"banner\">\n");
161         wprintf("<h1>");
162         wprintf(_("System Administration Menu"));
163         wprintf("</h1>");
164         wprintf("</div>\n");
165
166         wprintf("<div id=\"content\" class=\"service\">");
167
168         wprintf("<div class=\"fix_scrollbar_bug\">"
169                 "<table> "
170                 "<tr valign=top><td width=50%% valign=\"top\">");
171
172         print_menu_box(_("Global Configuration"), "adminitems", 4,
173                        "display_siteconfig", _("Edit site-wide configuration"), 
174                        "display_inetconf",_("Domain names and Internet mail configuration"),
175                        "display_netconf", _("Configure replication with other Citadel servers"), 
176                        "display_smtpqueue", _("View the outbound SMTP queue"));
177         
178         wprintf("</td><td width=50%% valign=\"top\">");
179
180         print_menu_box(_("User account management"), "adminitems", 2, 
181                        "select_user_to_edit", _("Add, change, delete user accounts"),
182                        "validate", _("Validate new users"));
183
184         wprintf("</td></tr><tr><td width=50%% valign=\"top\">");
185
186
187         print_menu_box(_("Shutdown Citadel"), "adminitems", 3, 
188                        "server_shutdown?when=now", _("Restart Now"),
189                        "server_shutdown?when=page", _("Restart after paging users"),
190                        "server_shutdown?when=idle", _("Restart when all users are idle"));
191
192         wprintf("</td><td width=50%% valign=\"top\">");
193
194         print_menu_box(_("Rooms and Floors"), "adminitems", 1, 
195                        "display_floorconfig", _("Add, change, or delete floors"));
196
197         wprintf("</td></tr></table></div>");
198         wDumpContent(2);
199 }
200
201
202
203 /**
204  * \brief Display the screen to enter a generic server command
205  */
206 void display_generic(void)
207 {
208         output_headers(1, 1, 2, 0, 0, 0);
209         wprintf("<div id=\"banner\">\n");
210         wprintf("<h1>");
211         wprintf(_("Enter a server command"));
212         wprintf("</h1>");
213         wprintf("</div>\n");
214
215         wprintf("<div id=\"content\" class=\"service\">\n");
216
217         wprintf("<div class=\"fix_scrollbar_bug\">"
218                 "<table class=\"mainmenu_background\"><tr><td>\n");
219
220         wprintf("<center>");
221         wprintf(_("This screen allows you to enter Citadel server commands which are "
222                 "not supported by WebCit.  If you do not know what that means, "
223                 "then this screen will not be of much use to you."));
224         wprintf("<br />\n");
225
226         wprintf("<form method=\"post\" action=\"do_generic\">\n");
227         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
228
229         wprintf(_("Enter command:"));
230         wprintf("<br /><input type=\"text\" name=\"g_cmd\" size=80 maxlength=\"250\"><br />\n");
231
232         wprintf(_("Command input (if requesting SEND_LISTING transfer mode):"));
233         wprintf("<br /><textarea name=\"g_input\" rows=10 cols=80 width=80></textarea><br />\n");
234
235         wprintf("<font size=-2>");
236         wprintf(_("Detected host header is %s://%s"), (is_https ? "https" : "http"), WC->http_host);
237         wprintf("</font>\n");
238         wprintf("<input type=\"submit\" name=\"sc_button\" value=\"%s\">", _("Send command"));
239         wprintf("&nbsp;");
240         wprintf("<input type=\"submit\" name=\"cancel_button\" value=\"%s\"><br />\n", _("Cancel"));
241
242         wprintf("</form></center>\n");
243         wprintf("</td></tr></table></div>\n");
244         wDumpContent(1);
245 }
246
247 /**
248  * \brief Interactive window to perform generic Citadel server commands.
249  */
250 void do_generic(void)
251 {
252         char buf[SIZ];
253         char gcontent[SIZ];
254         char *junk;
255         size_t len;
256
257         if (!havebstr("sc_button")) {
258                 display_main_menu();
259                 return;
260         }
261
262         output_headers(1, 1, 0, 0, 0, 0);
263
264         serv_printf("%s", bstr("g_cmd"));
265         serv_getln(buf, sizeof buf);
266
267         svprintf("BOXTITLE", WCS_STRING, _("Server command results"));
268         do_template("beginbox");
269
270         wprintf("<table border=0><tr><td>Command:</td><td><tt>");
271         escputs(bstr("g_cmd"));
272         wprintf("</tt></td></tr><tr><td>Result:</td><td><tt>");
273         escputs(buf);
274         wprintf("</tt></td></tr></table><br />\n");
275
276         if (buf[0] == '8') {
277                 serv_printf("\n\n000");
278         }
279         if ((buf[0] == '1') || (buf[0] == '8')) {
280                 while (serv_getln(gcontent, sizeof gcontent), strcmp(gcontent, "000")) {
281                         escputs(gcontent);
282                         wprintf("<br />\n");
283                 }
284                 wprintf("000");
285         }
286         if (buf[0] == '4') {
287                 text_to_server(bstr("g_input"));
288                 serv_puts("000");
289         }
290         if (buf[0] == '6') {
291                 len = atol(&buf[4]);
292                 junk = malloc(len);
293                 serv_read(junk, len);
294                 free(junk);
295         }
296         if (buf[0] == '7') {
297                 len = atol(&buf[4]);
298                 junk = malloc(len);
299                 memset(junk, 0, len);
300                 serv_write(junk, len);
301                 free(junk);
302         }
303         wprintf("<hr />");
304         wprintf("<a href=\"display_generic\">Enter another command</a><br />\n");
305         wprintf("<a href=\"display_advanced\">Return to menu</a>\n");
306         do_template("endbox");
307         wDumpContent(1);
308 }
309
310
311 /**
312  * \brief Display the menubar.  
313  * \param as_single_page Set to display HTML headers and footers -- otherwise it's assumed
314  * that the menubar is being embedded in another page.
315  */
316 void display_menubar(int as_single_page) {
317
318         if (as_single_page) {
319                 output_headers(0, 0, 0, 0, 0, 0);
320                 wprintf("<html>\n"
321                         "<head>\n"
322                         "<title>MenuBar</title>\n"
323                         "<style type=\"text/css\">\n"
324                         "body   { text-decoration: none; }\n"
325                         "</style>\n"
326                         "</head>\n");
327                 do_template("background");
328         }
329
330         do_template("menubar");
331
332         if (as_single_page) {
333                 wDumpContent(2);
334         }
335
336
337 }
338
339
340 /**
341  * \brief Display the wait / input dialog while restarting the server.
342  */
343 void display_shutdown(void)
344 {
345         char buf[SIZ];
346         char *when;
347         
348         when=bstr("when");
349         if (!strcmp(when, "now")){
350                 serv_printf("DOWN 1");
351                 serv_getln(buf, sizeof buf);
352                 if (atol(buf) == 500)
353                 { /* upsie. maybe the server is not running as daemon? */
354                         wprintf("<html><head></head><body>Attention: %s</body></html>", &buf[4]);
355
356                 }
357                 else {
358                         wprintf("<html>\n"
359                                 "<head>\n"
360                                 "<meta http-equiv=\"refresh\" content=\"15; URL=knrooms\"/>\n"
361                                 "</head>\n"
362                                 "<body bgcolor=\"#FFFFFF\">\n"
363                                 "<img src=\"static/throbber.gif\" /> <font color=\"#AAAAAA\">%s </font>"
364                                 "</body>\n</html>\n",
365                                 _("Please wait while the Citadel server is restarted... ")
366                                 );
367                 }
368                 wDumpContent(0);
369                 lingering_close(WC->http_sock);
370                 sleeeeeeeeeep(10);
371                 serv_printf("NOOP");
372                 serv_printf("NOOP");
373         }
374         else if (!strcmp(when, "page")) {
375                 char *message;
376                
377                 message = bstr("message");
378                 if ((message == NULL) || (IsEmptyStr(message)))
379                 {
380                         output_headers(1, 1, 1, 0, 0, 0);
381                         svprintf("BOXTITLE", WCS_STRING, _("Message to your Users:"));
382                         do_template("beginbox");
383                         wprintf("<form action=\"server_shutdown\">\n"
384                                 "<input type=\"hidden\" name=\"when\" value=\"page\">\n"
385                                 "<input type=\"text\" name=\"message\" value=\"%s\">\n"
386                                 "<input type=\"submit\" value=\"go\">\n"
387                                 "</form>\n",
388                                 _("The citadel server has to be restarted. It 'll be back in a minute.")
389                                 );
390                         do_template("endbox");
391                         wDumpContent(1);
392
393                         
394                 }
395                 else
396                 {
397                         // TODO: page the users... wait longer...
398                         serv_printf("SEXP broadcast|%s", message);
399                         serv_getln(buf, sizeof buf); // should we care?
400                         wprintf("<html>\n"
401                                 "<head>\n"
402                                 "<meta http-equiv=\"refresh\" content=\"15; URL=knrooms\"/>\n"
403                                 "</head>\n"
404                                 "<body bgcolor=\"#FFFFFF\">\n"
405                                 "<img src=\"static/throbber.gif\" /> <font color=\"#AAAAAA\">%s </font>"
406                                 "</body>\n</html>\n",
407                                 _("Please wait while your users are being paged, the citadel server will be restarted after that... "));
408                         
409                 }
410         }
411         else if (!strcmp(when, "idle")) {
412                 serv_printf("SCDN 3");
413                 serv_getln(buf, sizeof buf);
414                 if (atol(buf) == 500)
415                 { /* upsie. maybe the server is not running as daemon? */
416                         wprintf("<html><head></head><body>Attention: %s</body></html>", &buf[4]);
417
418                 }
419         }
420 }
421
422
423 /*@}*/