c67f715c85003e8860b627ad22915e0a97782a32
[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  * The Main Menu
31  */
32 void display_main_menu(void)
33 {
34         output_headers(1);
35
36         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770077><TR><TD>");
37         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
38         wprintf("<B>Basic commands</B>\n");
39         wprintf("</FONT></TD></TR></TABLE>\n");
40         wprintf("<CENTER><TABLE border=0><TR>");
41
42         wprintf("<TD>");        /* start of first column */
43
44         wprintf("<UL>");
45         wprintf("<LI><B><A HREF=\"/knrooms\">\n");
46         wprintf("List known rooms</B></A><BR>\n");
47         wprintf("Where can I go from here?</LI>\n");
48
49         wprintf("<LI><B><A HREF=\"/gotonext\">\n");
50         wprintf("Goto next room</B></A><BR>\n");
51         wprintf("...with <EM>unread</EM> messages</LI>\n");
52
53         wprintf("<LI><B><A HREF=\"/skip\">\n");
54         wprintf("Skip to next room</B></A><BR>\n");
55         wprintf("(come back here later)</LI>\n");
56
57         if ((strlen(WC->ugname) > 0) && (strcasecmp(WC->ugname, WC->wc_roomname))) {
58                 wprintf("<LI><B><A HREF=\"/ungoto\">\n");
59                 wprintf("Ungoto</B></A><BR>\n");
60                 wprintf("(oops! Back to %s)</LI>\n", WC->ugname);
61         }
62         wprintf("</UL>\n");
63
64         wprintf("</TD><TD>\n"); /* start of second column */
65
66         wprintf("<UL>");
67         wprintf("<LI><B><A HREF=\"/readnew\">\n");
68         wprintf("Read new messages</B></A><BR>...in this room</LI>\n");
69
70         wprintf("<LI><B><A HREF=\"/readfwd\">\n");
71         wprintf("Read all messages</B></A><BR>...old <EM>and</EM> new</LI>\n");
72
73         wprintf("<LI><B><A HREF=\"/display_enter\">\n");
74         wprintf("Enter a message</B></A><BR>(post in this room)</LI>");
75         wprintf("</UL>\n");
76
77         wprintf("</TD><TD>");   /* start of third column */
78
79         wprintf("<UL>");
80         wprintf("<LI><B><A HREF=\"/whobbs\">\n");
81         wprintf("Who is online?</B></A><BR>(users <EM>currently</EM> logged on)</LI>\n");
82
83         wprintf("<LI><B><A HREF=\"/userlist\">\n");
84         wprintf("User list</B></A><BR>(all registered users)</LI>\n");
85
86         wprintf("<LI><B><A HREF=\"/termquit\" TARGET=\"_top\">\n");
87         wprintf("Log off</B></A><BR>Bye!</LI>\n");
88         wprintf("</UL>\n");
89
90         wprintf("</TR></TABLE>\n");
91
92         wprintf("<TABLE WIDTH=100%%><TR VALIGN=TOP><TD>");
93
94         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
95         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
96         wprintf("<B>Interaction</B>\n");
97         wprintf("</FONT></TD></TR></TABLE>\n");
98
99         wprintf("<UL>");
100         wprintf("<LI><A HREF=\"/display_page\">\n");
101         wprintf("Page another user</A>\n");
102
103         wprintf("<LI><A HREF=\"/chat\">");
104         wprintf("Chat with other online users</A>\n");
105
106         wprintf("<LI><A HREF=\"/display_generic\">\n");
107         wprintf("<FONT SIZE=-2>Generic server command</FONT></A>\n");
108
109         wprintf("</UL>\n");
110
111         wprintf("</TD><TD>");
112
113         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>");
114         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
115         wprintf("<B>Your info</B>\n");
116         wprintf("</FONT></TD></TR></TABLE>\n");
117
118         wprintf("<UL>");
119         wprintf("<LI><A HREF=\"/display_editbio\">\n");
120         wprintf("Enter your 'bio' (a few words about yourself)</A>\n");
121
122         wprintf("<LI><A HREF=\"/display_editpic\">\n");
123         wprintf("Edit your online photo</A>\n");
124
125         wprintf("<LI><A HREF=\"/display_reg\">\n");
126         wprintf("Re-enter your registration info (name, address, etc.)</A>\n");
127
128         wprintf("<LI><A HREF=\"/display_changepw\">\n");
129         wprintf("Change your password</A>\n");
130
131         wprintf("</UL>\n");
132
133
134         wprintf("</TD></TR><TR VALIGN=TOP><TD>");
135
136         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>");
137         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
138         wprintf("<B>Advanced room commands</B>\n");
139         wprintf("</FONT></TD></TR></TABLE>\n");
140
141         wprintf("<UL>");
142         wprintf("<LI><A HREF=\"/display_private\">\n");
143         wprintf("Go to a 'hidden' room</A>\n");
144
145         wprintf("<LI><A HREF=\"/display_entroom\">");
146         wprintf("Create a new room</A>\n");
147
148         wprintf("<LI><A HREF=\"/display_zap\">");
149         wprintf("Zap (forget) this room (%s)</A>\n", WC->wc_roomname);
150
151         wprintf("<LI><A HREF=\"/display_whok\">\n");
152         wprintf("Access controls for this room</A>\n");
153
154         wprintf("<LI><A HREF=\"/zapped_list\">");
155         wprintf("List all forgotten rooms</A>\n");
156
157         wprintf("</UL>\n");
158
159         wprintf("</TD><TD>");
160
161         if ((WC->axlevel >= 6) || (WC->is_room_aide)) {
162                 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007777><TR><TD>");
163                 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
164                 wprintf("<B>Administrative functions</B>\n");
165                 wprintf("</FONT></TD></TR></TABLE>\n");
166
167                 wprintf("<UL>");
168                 wprintf("<LI><A HREF=\"/display_editroom\">\n");
169                 wprintf("Edit or delete this room</A>\n");
170
171                 wprintf("<LI><A HREF=\"/display_siteconfig\">\n");
172                 wprintf("Edit site-wide configuration</A>\n");
173
174                 if (WC->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         wDumpContent(2);
188 }
189
190
191
192
193
194 /*
195  * Display the screen to enter a generic server command
196  */
197 void display_generic(void)
198 {
199         output_headers(1);
200
201         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770077><TR><TD>");
202         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
203         wprintf("<B>Enter a server command</B>\n");
204         wprintf("</FONT></TD></TR></TABLE>\n");
205
206         wprintf("<CENTER>");
207         wprintf("This screen allows you to enter Citadel server commands which are\n");
208         wprintf("not supported by WebCit.  If you do not know what that means,\n");
209         wprintf("then this screen will not be of much use to you.<BR>\n");
210
211         wprintf("<FORM METHOD=\"POST\" ACTION=\"/do_generic\">\n");
212
213         wprintf("Enter command:<BR>\n");
214         wprintf("<INPUT TYPE=\"text\" NAME=\"g_cmd\" SIZE=80 MAXLENGTH=\"250\"><BR>\n");
215
216         wprintf("Command input (if requesting SEND_LISTING transfer mode):<BR>\n");
217         wprintf("<TEXTAREA NAME=\"g_input\" ROWS=10 COLS=80 WIDTH=80></TEXTAREA>\n");
218
219         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Send command\">");
220         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
221
222         wprintf("</FORM></CENTER>\n");
223         wDumpContent(1);
224 }
225
226 void do_generic(void)
227 {
228         char buf[SIZ];
229         char gcontent[SIZ];
230         char *junk;
231         size_t len;
232
233         if (strcasecmp(bstr("sc"), "Send command")) {
234                 display_main_menu();
235                 return;
236         }
237
238         output_headers(1);
239
240         serv_printf("%s", bstr("g_cmd"));
241         serv_gets(buf);
242
243         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770077><TR><TD>");
244         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
245         wprintf("<B>Server command results</B>\n");
246         wprintf("</FONT></TD></TR></TABLE>\n");
247
248         wprintf("<TABLE border=0><TR><TD>Command:</TD><TD><TT>");
249         escputs(bstr("g_cmd"));
250         wprintf("</TT></TD></TR><TR><TD>Result:</TD><TD><TT>");
251         escputs(buf);
252         wprintf("</TT></TD></TR></TABLE><BR>\n");
253
254         if (buf[0] == '8') {
255                 serv_printf("\n\n000");
256         }
257         if ((buf[0] == '1') || (buf[0] == '8')) {
258                 while (serv_gets(gcontent), strcmp(gcontent, "000")) {
259                         escputs(gcontent);
260                         wprintf("<BR>\n");
261                 }
262                 wprintf("000");
263         }
264         if (buf[0] == '4') {
265                 text_to_server(bstr("g_input"));
266                 serv_puts("000");
267         }
268         if (buf[0] == '6') {
269                 len = atol(&buf[4]);
270                 junk = malloc(len);
271                 serv_read(junk, len);
272                 free(junk);
273         }
274         if (buf[0] == '7') {
275                 len = atol(&buf[4]);
276                 junk = malloc(len);
277                 memset(junk, 0, len);
278                 serv_write(junk, len);
279                 free(junk);
280         }
281         wprintf("<HR>");
282         wprintf("<A HREF=\"/display_generic\">Enter another command</A><BR>\n");
283         wprintf("<A HREF=\"/display_advanced\">Return to menu</A>\n");
284         wDumpContent(1);
285 }
286
287
288
289
290 /*
291  * Display the menubar.  Set as_single_page to
292  * display HTML headers and footers -- otherwise it's assumed
293  * that the menubar is being embedded in another page.
294  */
295 void display_menubar(int as_single_page) {
296
297         if (as_single_page) {
298                 output_headers(0);
299                 wprintf("<HTML>\n"
300                         "<HEAD>\n"
301                         "<TITLE>MenuBar</TITLE>\n"
302                         "<STYLE TYPE=\"text/css\">\n"
303                         "BODY   { text-decoration: none; }\n"
304                         "</STYLE>\n"
305                         "</HEAD>\n");
306                 do_template("background.html");
307         }
308
309         do_template("menubar.html");
310
311         if (as_single_page) {
312                 wDumpContent(2);
313         }
314
315
316 }