850e10845755dbfbd44ecd2b45f3b7a3a191ff76
[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                 "<SPAN CLASS=\"titlebar\">Basic commands</SPAN>\n"
38                 "</TD></TR></TABLE>\n"
39                 "<CENTER><TABLE border=0><TR>"
40         );
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=\"/summary\">\n");
81         wprintf("Summary page</B></A><BR>Summary of my account</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("<SPAN CLASS=\"titlebar\">Interaction</SPAN>\n");
96         wprintf("</TD></TR></TABLE>\n");
97
98         wprintf("<UL>");
99         wprintf("<LI><A HREF=\"/whobbs\">\n");
100         wprintf("Who is online?</A><font size=-2> "
101                 "(users <EM>currently</EM> logged on)</font>\n");
102         wprintf("<LI><A HREF=\"/chat\">");
103         wprintf("Chat with other online users</A>\n");
104
105         wprintf("<LI><A HREF=\"/display_generic\">\n");
106         wprintf("<FONT SIZE=-2>Generic server command</FONT></A>\n");
107
108         wprintf("</UL>\n");
109
110         wprintf("</TD><TD>");
111
112         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#007700\"><TR><TD>");
113         wprintf("<SPAN CLASS=\"titlebar\">Your info</SPAN>\n");
114         wprintf("</TD></TR></TABLE>\n");
115
116         wprintf("<UL>");
117         wprintf("<LI><A HREF=\"/display_editbio\">\n");
118         wprintf("Enter your 'bio' (a few words about yourself)</A>\n");
119
120         wprintf("<LI><A HREF=\"/display_editpic\">\n");
121         wprintf("Edit your online photo</A>\n");
122
123         wprintf("<LI><A HREF=\"/display_reg\">\n");
124         wprintf("Re-enter your registration info (name, address, etc.)</A>\n");
125
126         wprintf("<LI><A HREF=\"/display_changepw\">\n");
127         wprintf("Change your password</A>\n");
128
129         wprintf("</UL>\n");
130
131
132         wprintf("</TD></TR><TR VALIGN=TOP><TD>");
133
134         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#000077\"><TR><TD>");
135         wprintf("<SPAN CLASS=\"titlebar\">Advanced room commands</SPAN>\n");
136         wprintf("</TD></TR></TABLE>\n");
137
138         wprintf("<UL>");
139         wprintf("<LI><A HREF=\"/display_private\">\n");
140         wprintf("Go to a 'hidden' room</A>\n");
141
142         wprintf("<LI><A HREF=\"/display_entroom\">");
143         wprintf("Create a new room</A>\n");
144
145         wprintf("<LI><A HREF=\"/display_zap\">");
146         wprintf("Zap (forget) this room (%s)</A>\n", WC->wc_roomname);
147
148         wprintf("<LI><A HREF=\"/display_whok\">\n");
149         wprintf("Access controls for this room</A>\n");
150
151         wprintf("<LI><A HREF=\"/zapped_list\">");
152         wprintf("List all forgotten rooms</A>\n");
153
154         wprintf("</UL>\n");
155
156         wprintf("</TD><TD>");
157
158         if ((WC->axlevel >= 6) || (WC->is_room_aide)) {
159                 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#007777\"><TR><TD>");
160                 wprintf("<SPAN CLASS=\"titlebar\">Administrative functions</SPAN>\n");
161                 wprintf("</TD></TR></TABLE>\n");
162
163                 wprintf("<UL>");
164                 wprintf("<LI><A HREF=\"/display_editroom\">\n");
165                 wprintf("Edit or delete this room</A>\n");
166
167                 wprintf("<LI><A HREF=\"/display_siteconfig\">\n");
168                 wprintf("Edit site-wide configuration</A>\n");
169
170                 if (WC->axlevel >= 6) {
171                         wprintf("<LI><A HREF=\"/select_user_to_edit\">\n");
172                         wprintf("Add, change, delete user accounts</A>\n");
173
174                         wprintf("<LI><A HREF=\"/validate\">\n");
175                         wprintf("Validate new users</A>\n");
176
177                         wprintf("<LI><A HREF=\"/display_floorconfig\">\n");
178                         wprintf("Add, change, or delete floors</A>\n");
179
180                         wprintf("<LI><A HREF=\"/display_netconf\">\n");
181                         wprintf("Configure networking with other systems</A>\n");
182                         wprintf("<LI><A HREF=\"/static/colorpicker.html\">\n");
183                         wprintf("Reconfigure color scheme</A>\n");
184                 }
185                 wprintf("</UL>\n");
186         }
187         wprintf("</TD></TR></TABLE>");
188         wDumpContent(2);
189 }
190
191
192
193
194
195 /*
196  * Display the screen to enter a generic server command
197  */
198 void display_generic(void)
199 {
200         output_headers(1);
201
202         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770077\"><TR><TD>");
203         wprintf("<SPAN CLASS=\"titlebar\">Enter a server command</SPAN>\n");
204         wprintf("</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><BR>\n");
218
219         wprintf("<FONT SIZE=-2>Detected host header is http://%s</FONT>\n",
220                 WC->http_host);
221         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Send command\">");
222         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
223
224         wprintf("</FORM></CENTER>\n");
225         wDumpContent(1);
226 }
227
228 void do_generic(void)
229 {
230         char buf[SIZ];
231         char gcontent[SIZ];
232         char *junk;
233         size_t len;
234
235         if (strcasecmp(bstr("sc"), "Send command")) {
236                 display_main_menu();
237                 return;
238         }
239
240         output_headers(1);
241
242         serv_printf("%s", bstr("g_cmd"));
243         serv_gets(buf);
244
245         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770077\"><TR><TD>");
246         wprintf("<SPAN CLASS=\"titlebar\">Server command results</SPAN>\n");
247         wprintf("</TD></TR></TABLE>\n");
248
249         wprintf("<TABLE border=0><TR><TD>Command:</TD><TD><TT>");
250         escputs(bstr("g_cmd"));
251         wprintf("</TT></TD></TR><TR><TD>Result:</TD><TD><TT>");
252         escputs(buf);
253         wprintf("</TT></TD></TR></TABLE><BR>\n");
254
255         if (buf[0] == '8') {
256                 serv_printf("\n\n000");
257         }
258         if ((buf[0] == '1') || (buf[0] == '8')) {
259                 while (serv_gets(gcontent), strcmp(gcontent, "000")) {
260                         escputs(gcontent);
261                         wprintf("<BR>\n");
262                 }
263                 wprintf("000");
264         }
265         if (buf[0] == '4') {
266                 text_to_server(bstr("g_input"), 0);
267                 serv_puts("000");
268         }
269         if (buf[0] == '6') {
270                 len = atol(&buf[4]);
271                 junk = malloc(len);
272                 serv_read(junk, len);
273                 free(junk);
274         }
275         if (buf[0] == '7') {
276                 len = atol(&buf[4]);
277                 junk = malloc(len);
278                 memset(junk, 0, len);
279                 serv_write(junk, len);
280                 free(junk);
281         }
282         wprintf("<HR>");
283         wprintf("<A HREF=\"/display_generic\">Enter another command</A><BR>\n");
284         wprintf("<A HREF=\"/display_advanced\">Return to menu</A>\n");
285         wDumpContent(1);
286 }
287
288
289
290
291 /*
292  * Display the menubar.  Set as_single_page to
293  * display HTML headers and footers -- otherwise it's assumed
294  * that the menubar is being embedded in another page.
295  */
296 void display_menubar(int as_single_page) {
297
298         if (as_single_page) {
299                 output_headers(0);
300                 wprintf("<HTML>\n"
301                         "<HEAD>\n"
302                         "<TITLE>MenuBar</TITLE>\n"
303                         "<STYLE TYPE=\"text/css\">\n"
304                         "BODY   { text-decoration: none; }\n"
305                         "</STYLE>\n"
306                         "</HEAD>\n");
307                 do_template("background");
308         }
309
310         do_template("menubar");
311
312         if (as_single_page) {
313                 wDumpContent(2);
314         }
315
316
317 }
318
319