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