* Moved all diagnostic output to stderr
[citadel.git] / webcit / mainmenu.c
1 /* $Id$ */
2
3
4
5
6 #include <ctype.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <stdio.h>
10 #include <fcntl.h>
11 #include <signal.h>
12 #include <sys/types.h>
13 #include <sys/wait.h>
14 #include <sys/socket.h>
15 #include <sys/time.h>
16 #include <limits.h>
17 #include <netinet/in.h>
18 #include <netdb.h>
19 #include <string.h>
20 #include <pwd.h>
21 #include <errno.h>
22 #include <stdarg.h>
23 #include <pthread.h>
24 #include <signal.h>
25 #include "webcit.h"
26
27
28
29
30
31 /* 
32  * menu of commands (just the menu html itself)
33  */
34
35 void embed_main_menu(void)
36 {
37         wprintf("<CENTER><TABLE border=0><TR>");
38
39         wprintf("<TD>");        /* start of first column */
40
41         wprintf("<UL>");
42         wprintf("<LI><B><A HREF=\"/knrooms\">\n");
43         wprintf("List known rooms</B></A><BR>\n");
44         wprintf("Where can I go from here?</LI>\n");
45
46         wprintf("<LI><B><A HREF=\"/gotonext\">\n");
47         wprintf("Goto next room</B></A><BR>\n");
48         wprintf("...with <EM>unread</EM> messages</LI>\n");
49
50         wprintf("<LI><B><A HREF=\"/skip\">\n");
51         wprintf("Skip to next room</B></A><BR>\n");
52         wprintf("(come back here later)</LI>\n");
53
54         if ((strlen(WC->ugname) > 0) && (strcasecmp(WC->ugname, WC->wc_roomname))) {
55                 wprintf("<LI><B><A HREF=\"/ungoto\">\n");
56                 wprintf("Ungoto</B></A><BR>\n");
57                 wprintf("(oops! Back to %s)</LI>\n", WC->ugname);
58         }
59         wprintf("</UL>\n");
60
61         wprintf("</TD><TD>\n"); /* start of second column */
62
63         wprintf("<UL>");
64         wprintf("<LI><B><A HREF=\"/readnew\">\n");
65         wprintf("Read new messages</B></A><BR>...in this room</LI>\n");
66
67         wprintf("<LI><B><A HREF=\"/readfwd\">\n");
68         wprintf("Read all messages</B></A><BR>...old <EM>and</EM> new</LI>\n");
69
70         wprintf("<LI><B><A HREF=\"/display_enter\">\n");
71         wprintf("Enter a message</B></A><BR>(post in this room)</LI>");
72         wprintf("</UL>\n");
73
74         wprintf("</TD><TD>");   /* start of third column */
75
76         wprintf("<UL>");
77         wprintf("<LI><B><A HREF=\"/whobbs\">\n");
78         wprintf("Who is online?</B></A><BR>(users <EM>currently</EM> logged on)</LI>\n");
79
80         wprintf("<LI><B><A HREF=\"/userlist\">\n");
81         wprintf("User list</B></A><BR>(all registered users)</LI>\n");
82
83         wprintf("<LI><B><A HREF=\"/advanced\">\n");
84         wprintf("Advanced options</B></A><BR>...and maintenance</LI>\n");
85
86         wprintf("<LI><B><A HREF=\"/termquit\">\n");
87         wprintf("Log off</B></A><BR>Bye!</LI>\n");
88         wprintf("</UL>\n");
89
90         wprintf("</TR></TABLE>\n");
91
92         wprintf("</CENTER>\n");
93 }
94
95 /*
96  * advanced options
97  */
98 void embed_advanced_menu(void)
99 {
100
101         wprintf("<TABLE WIDTH=100%><TR VALIGN=TOP><TD>");
102
103
104         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
105         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
106         wprintf("<B>Interaction</B>\n");
107         wprintf("</FONT></TD></TR></TABLE>\n");
108
109         wprintf("<UL>");
110         wprintf("<LI><A HREF=\"/display_page\">\n");
111         wprintf("Page another user</A>\n");
112
113         wprintf("<LI><A HREF=\"/chat\">");
114         wprintf("Chat with other online users</A>\n");
115
116         wprintf("<LI><A HREF=\"/display_generic\">\n");
117         wprintf("<FONT SIZE=-2>Generic server command</FONT></A>\n");
118
119         wprintf("</UL>\n");
120
121         wprintf("</TD><TD>");
122
123         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
124         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
125         wprintf("<B>Your info</B>\n");
126         wprintf("</FONT></TD></TR></TABLE>\n");
127
128         wprintf("<UL>");
129         wprintf("<LI><A HREF=\"/display_editbio\">\n");
130         wprintf("Enter your 'bio' (a few words about yourself)</A>\n");
131
132         wprintf("<LI><A HREF=\"/display_editpic\">\n");
133         wprintf("Edit your online photo</A>\n");
134
135         wprintf("<LI><A HREF=\"/display_reg\">\n");
136         wprintf("Re-enter your registration info (name, address, etc.)</A>\n");
137
138         wprintf("<LI><A HREF=\"/display_changepw\">\n");
139         wprintf("Change your password</A>\n");
140
141         wprintf("</UL>\n");
142
143
144         wprintf("</TD></TR><TR VALIGN=TOP><TD>");
145
146         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=000077><TR><TD>");
147         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
148         wprintf("<B>Advanced room commands</B>\n");
149         wprintf("</FONT></TD></TR></TABLE>\n");
150
151         wprintf("<UL>");
152         wprintf("<LI><A HREF=\"/display_private\">\n");
153         wprintf("Go to a 'hidden' room</A>\n");
154
155         wprintf("<LI><A HREF=\"/display_entroom\">");
156         wprintf("Create a new room</A>\n");
157
158         wprintf("<LI><A HREF=\"/display_zap\">");
159         wprintf("Zap (forget) this room (%s)</A>\n", WC->wc_roomname);
160
161         wprintf("<LI><A HREF=\"/zapped_list\">");
162         wprintf("List all forgotten rooms</A>\n");
163
164         wprintf("</UL>\n");
165
166         wprintf("</TD><TD>");
167
168         if ((WC->axlevel >= 6) || (WC->is_room_aide)) {
169                 wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007777><TR><TD>");
170                 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
171                 wprintf("<B>Administrative functions</B>\n");
172                 wprintf("</FONT></TD></TR></TABLE>\n");
173
174                 wprintf("<UL>");
175                 wprintf("<LI><A HREF=\"/display_editroom\">\n");
176                 wprintf("Edit or delete this room</A>\n");
177
178                 wprintf("<LI><A HREF=\"/display_siteconfig\">\n");
179                 wprintf("Edit site-wide configuration</A>\n");
180
181                 if (WC->axlevel >= 6) {
182                         wprintf("<LI><A HREF=\"/validate\">\n");
183                         wprintf("Validate new users</A>\n");
184
185                         wprintf("<LI><A HREF=\"/select_floor_to_edit_pic\">\n");
186                         wprintf("Set or change a floor label graphic</A>\n");
187
188                         wprintf("<LI><A HREF=\"/display_netconf\">\n");
189                         wprintf("Configure networking with other systems</A>\n");
190                 }
191                 wprintf("</UL>\n");
192         }
193         wprintf("</TD></TR></TABLE>");
194
195         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770077><TR><TD>");
196         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
197         wprintf("<B>Basic commands</B>\n");
198         wprintf("</FONT></TD></TR></TABLE>\n");
199
200 }
201
202
203
204
205 /*
206  * menu of commands (as a page)
207  */
208 void display_main_menu(void)
209 {
210         output_headers(1);
211         embed_main_menu();
212         wDumpContent(2);
213 }
214
215
216 void display_advanced_menu(void)
217 {
218         output_headers(1);
219         embed_advanced_menu();
220         embed_main_menu();
221         wDumpContent(2);
222 }
223
224
225 /*
226  * Display the screen to enter a generic server command
227  */
228 void display_generic(void)
229 {
230         output_headers(1);
231
232         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770077><TR><TD>");
233         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
234         wprintf("<B>Enter a server command</B>\n");
235         wprintf("</FONT></TD></TR></TABLE>\n");
236
237         wprintf("<CENTER>");
238         wprintf("This screen allows you to enter Citadel server commands which are\n");
239         wprintf("not supported by WebCit.  If you do not know what that means,\n");
240         wprintf("then this screen will not be of much use to you.<BR>\n");
241
242         wprintf("<FORM METHOD=\"POST\" ACTION=\"/do_generic\">\n");
243
244         wprintf("Enter command:<BR>\n");
245         wprintf("<INPUT TYPE=\"text\" NAME=\"g_cmd\" SIZE=80 MAXLENGTH=\"250\"><BR>\n");
246
247         wprintf("Command input (if requesting SEND_LISTING transfer mode):<BR>\n");
248         wprintf("<TEXTAREA NAME=\"g_input\" ROWS=10 COLS=80 WIDTH=80></TEXTAREA>\n");
249
250         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Send command\">");
251         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
252
253         wprintf("</FORM></CENTER>\n");
254         wDumpContent(1);
255 }
256
257 void do_generic(void)
258 {
259         char buf[256];
260         char gcontent[256];
261         char *junk;
262         size_t len;
263
264         if (strcasecmp(bstr("sc"), "Send command")) {
265                 display_main_menu();
266                 return;
267         }
268
269         output_headers(1);
270
271         serv_printf("%s", bstr("g_cmd"));
272         serv_gets(buf);
273
274         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770077><TR><TD>");
275         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
276         wprintf("<B>Server command results</B>\n");
277         wprintf("</FONT></TD></TR></TABLE>\n");
278
279         wprintf("<TABLE border=0><TR><TD>Command:</TD><TD><TT>");
280         escputs(bstr("g_cmd"));
281         wprintf("</TT></TD></TR><TR><TD>Result:</TD><TD><TT>");
282         escputs(buf);
283         wprintf("</TT></TD></TR></TABLE><BR>\n");
284
285         if (buf[0] == '8') {
286                 serv_printf("\n\n000");
287         }
288         if ((buf[0] == '1') || (buf[0] == '8')) {
289                 while (serv_gets(gcontent), strcmp(gcontent, "000")) {
290                         escputs(gcontent);
291                         wprintf("<BR>\n");
292                 }
293                 wprintf("000");
294         }
295         if (buf[0] == '4') {
296                 text_to_server(bstr("g_input"));
297                 serv_puts("000");
298         }
299         if (buf[0] == '6') {
300                 len = atol(&buf[4]);
301                 junk = malloc(len);
302                 serv_read(junk, len);
303                 free(junk);
304         }
305         if (buf[0] == '7') {
306                 len = atol(&buf[4]);
307                 junk = malloc(len);
308                 bzero(junk, len);
309                 serv_write(junk, len);
310                 free(junk);
311         }
312         wprintf("<HR>");
313         wprintf("<A HREF=\"/display_generic\">Enter another command</A><BR>\n");
314         wprintf("<A HREF=\"/display_advanced\">Return to menu</A>\n");
315         wDumpContent(1);
316 }
317
318
319
320
321 /*
322  * Display the menubar.  Set as_single_page to
323  * display HTML headers and footers -- otherwise it's assumed
324  * that the menubar is being embedded in another page.
325  */
326 void display_menubar(int as_single_page) {
327         FILE *menubar_body;
328         char buf[256];
329
330         if (as_single_page) {
331                 output_headers(0);
332                 wprintf("<HTML>\n"
333                         "<HEAD>\n"
334                         "<TITLE>MenuBar</TITLE>\n"
335                         "<STYLE TYPE=\"text/css\">\n"
336                         "BODY   { text-decoration: none; }\n"
337                         "</STYLE>\n"
338                         "</HEAD>\n"
339                         "<BODY BACKGROUND=\"/image&name=background\" "
340                         "TEXT=\"#000000\" LINK=\"#FFFFFF\" "
341                         "ALINK=\"#FFFFFF\" VLINK=\"#FFFFFF\">\n");
342         }
343
344         menubar_body = fopen("static/menubar.html", "r");
345         if (menubar_body == NULL) {
346                 wprintf("menubar<BR>%s", strerror(errno));
347         } else {
348                 while (fgets(buf, sizeof(buf), menubar_body) != NULL) {
349                         wprintf("%s", buf);
350                 }
351                 fclose(menubar_body);
352         }
353                 
354
355         if (as_single_page) {
356                 wDumpContent(2);
357         }
358
359
360 }