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