0cdc6ebc5bfdc5d8a21908e7b486a9982f7744ec
[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         wprintf("HTTP/1.0 200 OK\n");
211         output_headers(1);
212         embed_main_menu();
213         wDumpContent(2);
214 }
215
216
217 void display_advanced_menu(void)
218 {
219         wprintf("HTTP/1.0 200 OK\n");
220         output_headers(1);
221         embed_advanced_menu();
222         embed_main_menu();
223         wDumpContent(2);
224 }
225
226
227 /*
228  * Display the screen to enter a generic server command
229  */
230 void display_generic(void)
231 {
232         wprintf("HTTP/1.0 200 OK\n");
233         output_headers(1);
234
235         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770077><TR><TD>");
236         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
237         wprintf("<B>Enter a server command</B>\n");
238         wprintf("</FONT></TD></TR></TABLE>\n");
239
240         wprintf("<CENTER>");
241         wprintf("This screen allows you to enter Citadel server commands which are\n");
242         wprintf("not supported by WebCit.  If you do not know what that means,\n");
243         wprintf("then this screen will not be of much use to you.<BR>\n");
244
245         wprintf("<FORM METHOD=\"POST\" ACTION=\"/do_generic\">\n");
246
247         wprintf("Enter command:<BR>\n");
248         wprintf("<INPUT TYPE=\"text\" NAME=\"g_cmd\" SIZE=80 MAXLENGTH=\"250\"><BR>\n");
249
250         wprintf("Command input (if requesting SEND_LISTING transfer mode):<BR>\n");
251         wprintf("<TEXTAREA NAME=\"g_input\" ROWS=10 COLS=80 WIDTH=80></TEXTAREA>\n");
252
253         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Send command\">");
254         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
255
256         wprintf("</FORM></CENTER>\n");
257         wDumpContent(1);
258 }
259
260 void do_generic(void)
261 {
262         char buf[256];
263         char gcontent[256];
264         char *junk;
265         size_t len;
266
267         if (strcasecmp(bstr("sc"), "Send command")) {
268                 display_main_menu();
269                 return;
270         }
271
272         wprintf("HTTP/1.0 200 OK\n");
273         output_headers(1);
274
275         serv_printf("%s", bstr("g_cmd"));
276         serv_gets(buf);
277
278         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770077><TR><TD>");
279         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
280         wprintf("<B>Server command results</B>\n");
281         wprintf("</FONT></TD></TR></TABLE>\n");
282
283         wprintf("<TABLE border=0><TR><TD>Command:</TD><TD><TT>");
284         escputs(bstr("g_cmd"));
285         wprintf("</TT></TD></TR><TR><TD>Result:</TD><TD><TT>");
286         escputs(buf);
287         wprintf("</TT></TD></TR></TABLE><BR>\n");
288
289         if (buf[0] == '8') {
290                 serv_printf("\n\n000");
291         }
292         if ((buf[0] == '1') || (buf[0] == '8')) {
293                 while (serv_gets(gcontent), strcmp(gcontent, "000")) {
294                         escputs(gcontent);
295                         wprintf("<BR>\n");
296                 }
297                 wprintf("000");
298         }
299         if (buf[0] == '4') {
300                 text_to_server(bstr("g_input"));
301                 serv_puts("000");
302         }
303         if (buf[0] == '6') {
304                 len = atol(&buf[4]);
305                 junk = malloc(len);
306                 serv_read(junk, len);
307                 free(junk);
308         }
309         if (buf[0] == '7') {
310                 len = atol(&buf[4]);
311                 junk = malloc(len);
312                 bzero(junk, len);
313                 serv_write(junk, len);
314                 free(junk);
315         }
316         wprintf("<HR>");
317         wprintf("<A HREF=\"/display_generic\">Enter another command</A><BR>\n");
318         wprintf("<A HREF=\"/display_advanced\">Return to menu</A>\n");
319         wDumpContent(1);
320 }
321
322
323
324
325 /*
326  * Display the menubar.  Set as_single_page to
327  * display HTML headers and footers -- otherwise it's assumed
328  * that the menubar is being embedded in another page.
329  */
330 void display_menubar(int as_single_page) {
331         FILE *menubar_body;
332         char buf[256];
333
334         if (as_single_page) {
335                 wprintf("HTTP/1.0 200 OK\n");
336                 output_headers(0);
337                 wprintf("<HTML>\n"
338                         "<HEAD>\n"
339                         "<TITLE>MenuBar</TITLE>\n"
340                         "<STYLE TYPE=\"text/css\">\n"
341                         "BODY   { text-decoration: none; }\n"
342                         "</STYLE>\n"
343                         "</HEAD>\n"
344                         "<BODY BACKGROUND=\"/image&name=background\" "
345                         "TEXT=\"#000000\" LINK=\"#FFFFFF\" "
346                         "ALINK=\"#FFFFFF\" VLINK=\"#FFFFFF\">\n");
347         }
348
349         menubar_body = fopen("static/menubar.html", "r");
350         if (menubar_body == NULL) {
351                 wprintf("menubar<BR>%s", strerror(errno));
352         } else {
353                 while (fgets(buf, sizeof(buf), menubar_body) != NULL) {
354                         wprintf("%s", buf);
355                 }
356                 fclose(menubar_body);
357         }
358                 
359
360         if (as_single_page) {
361                 wDumpContent(2);
362         }
363
364
365 }