* inetconf.c: added. Not finished yet.
[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%%>"
37                 "<TR><TD COLSPAN=2>\n");
38
39         svprintf("BOXTITLE", WCS_STRING, "Basic commands");
40         do_template("beginbox");
41
42         wprintf("\n"
43                 "<TABLE border=0 cellspacing=1 cellpadding=1 width=100%%>"
44                 "<TR>"
45                 "<TD>");        /* start of first column */
46
47         wprintf("<A HREF=\"/knrooms\">"
48                 "<span class=\"mainmenu\">"
49                 "List known rooms</span></A><BR>"
50                 "<span class=\"menudesc\">"
51                 "Where can I go from here?</span><BR>\n"
52         );
53
54         wprintf("<A HREF=\"/gotonext\">"
55                 "<span class=\"mainmenu\">"
56                 "Goto next room</span></A><BR>"
57                 "<span class=\"menudesc\">"
58                 "...with <EM>unread</EM> messages"
59                 "</span><BR>\n"
60         );
61
62         wprintf("<A HREF=\"/skip\">"
63                 "<span class=\"mainmenu\">"
64                 "Skip to next room</span></a><BR>"
65                 "<span class=\"menudesc\">"
66                 "(come back here later)"
67                 "</span>\n"
68         );
69
70         if ((strlen(WC->ugname) > 0) && (strcasecmp(WC->ugname, WC->wc_roomname))) {
71                 wprintf("<BR>"
72                         "<A HREF=\"/ungoto\">"
73                         "<span class=\"mainmenu\">"
74                         "Ungoto</span></A><BR>"
75                         "<span class=\"menudesc\">"
76                         "(oops! Back to %s)"
77                         "</span>\n", WC->ugname
78                 );
79         }
80
81         wprintf("</TD><TD>\n"); /* start of second column */
82
83         wprintf("<A HREF=\"/readnew\">"
84                 "<span class=\"mainmenu\">"
85                 "Read new messages</span></A><BR>"
86                 "<span class=\"menudesc\">"
87                 "...in this room</span><BR>\n"
88         );
89
90         wprintf("<A HREF=\"/readfwd\">"
91                 "<span class=\"mainmenu\">"
92                 "Read all messages</span></A><BR>"
93                 "<span class=\"menudesc\">"
94                 "...old <EM>and</EM> new</span><BR>\n"
95         );
96
97         wprintf("<A HREF=\"/display_enter\">"
98                 "<span class=\"mainmenu\">"
99                 "Enter a message</span></A><BR>"
100                 "<span class=\"menudesc\">"
101                 "(post in this room)</span>\n"
102         );
103
104         wprintf("</TD><TD>");   /* start of third column */
105
106         wprintf("<A HREF=\"/summary\">"
107                 "<span class=\"mainmenu\">"
108                 "Summary page</span></A><BR>"
109                 "<span class=\"menudesc\">"
110                 "Summary of my account</span><BR>\n"
111         );
112
113         wprintf("<A HREF=\"/userlist\">\n"
114                 "<span class=\"mainmenu\">"
115                 "User list</span></A><BR>"
116                 "<span class=\"menudesc\">"
117                 "(all registered users)</span><BR>\n"
118         );
119
120         wprintf("<A HREF=\"/termquit\" TARGET=\"_top\">"
121                 "<span class=\"mainmenu\">"
122                 "Log off</span></A><BR>"
123                 "<span class=\"menudesc\">"
124                 "Bye!</span>\n"
125         );
126
127         wprintf("</TD></TR></TABLE>\n");
128         do_template("endbox");
129
130         wprintf("</TD></TR>"
131                 "<TR VALIGN=TOP><TD>");
132
133         svprintf("BOXTITLE", WCS_STRING, "Interaction");
134         do_template("beginbox");
135
136         wprintf("<A HREF=\"/whobbs\">"
137                 "<span class=\"mainmenu\">"
138                 "Who is online?</span></A>"
139                 "<span class=\"menudesc\">"
140                 " (users <EM>currently</EM> logged on)"
141                 "</span><BR>\n"
142         );
143
144         wprintf("<A HREF=\"#\" onClick=\"window.open('/chat', "
145                 "'ctdl_chat_window', "
146                 "'toolbar=no,location=no,directories=no,copyhistory=no,"
147                 "status=no,scrollbars=yes,resizable=yes');\""
148                 ">"
149                 "<span class=\"mainmenu\">"
150                 "Chat with other users in <i>"
151         );
152         escputs(WC->wc_roomname);
153         wprintf("</i></span></A><BR>\n");
154
155         wprintf("<A HREF=\"/display_generic\">\n");
156         wprintf("<span class=\"menudesc\">"
157                 "Generic server command</span></A>\n");
158
159         do_template("endbox");
160
161         wprintf("</TD><TD>");
162
163         svprintf("BOXTITLE", WCS_STRING, "Your info");
164         do_template("beginbox");
165
166         wprintf("<A HREF=\"/display_reg\">"
167                 "<span class=\"mainmenu\">"
168                 "Update your contact information "
169                 "</span><span class=\"menudesc\">"
170                 "(name, address, etc.)</span></A><BR>\n");
171
172         wprintf("<A HREF=\"/display_changepw\">"
173                 "<span class=\"mainmenu\">"
174                 "Change your password</span></A><BR>\n");
175
176         wprintf("<A HREF=\"/display_editbio\">"
177                 "<span class=\"mainmenu\">"
178                 "Enter your 'bio' "
179                 "</span><span class=\"menudesc\">"
180                 "(a few words about yourself)"
181                 "</span></A><BR>\n");
182
183         wprintf("<A HREF=\"/display_editpic\">"
184                 "<span class=\"mainmenu\">"
185                 "Edit your online photo</span></a>\n");
186
187         do_template("endbox");
188
189         wprintf("</TD></TR><TR VALIGN=TOP><TD>");
190
191         svprintf("BOXTITLE", WCS_STRING, "Advanced room commands");
192         do_template("beginbox");
193
194         if ((WC->axlevel >= 6) || (WC->is_room_aide)) {
195                 wprintf("<A HREF=\"/display_editroom\">"
196                         "<span class=\"mainmenu\">"
197                         "Edit or delete this room</span></A><BR>\n");
198         }
199
200         wprintf("<A HREF=\"/display_private\">"
201                 "<span class=\"mainmenu\">"
202                 "Go to a &quot;hidden&quot; room</span></A><BR>\n");
203
204         wprintf("<A HREF=\"/display_entroom\">"
205                 "<span class=\"mainmenu\">"
206                 "Create a new room</span></A><BR>\n");
207
208         wprintf("<A HREF=\"/display_zap\">"
209                 "<span class=\"mainmenu\">"
210                 "Zap (forget) this room (%s)</span></A><BR>\n",
211                 WC->wc_roomname);
212
213         wprintf("<A HREF=\"/display_whok\">\n"
214                 "<span class=\"mainmenu\">"
215                 "Access controls for this room</span></A><BR>\n");
216
217         wprintf("<A HREF=\"/zapped_list\">"
218                 "<span class=\"mainmenu\">"
219                 "List all forgotten rooms</span></A>\n");
220
221         do_template("endbox");
222
223         wprintf("</TD><TD>");
224
225         if ((WC->axlevel >= 6) || (WC->is_room_aide)) {
226                 svprintf("BOXTITLE", WCS_STRING, "Administrative functions");
227                 do_template("beginbox");
228
229                 wprintf("<A HREF=\"/display_siteconfig\">"
230                         "<span class=\"mainmenu\">"
231                         "Edit site-wide configuration</span></A>\n");
232
233                 if (WC->axlevel >= 6) {
234                         wprintf("<BR>"
235                                 "<A HREF=\"/select_user_to_edit\">"
236                                 "<span class=\"mainmenu\">"
237                                 "Add, change, delete user accounts"
238                                 "</span></A><BR>\n");
239
240                         wprintf("<A HREF=\"/validate\">"
241                                 "<span class=\"mainmenu\">"
242                                 "Validate new users</span></A><BR>\n");
243
244                         wprintf("<A HREF=\"/display_floorconfig\">"
245                                 "<span class=\"mainmenu\">"
246                                 "Add, change, or delete floors"
247                                 "</span></A><BR>\n");
248
249                         wprintf("<A HREF=\"/display_netconf\">"
250                                 "<span class=\"mainmenu\">"
251                                 "Configure networking with other systems"
252                                 "</span></A><BR>\n");
253
254                         wprintf("<A HREF=\"/display_inetconf\">"
255                                 "<span class=\"mainmenu\">"
256                                 "Internet configuration "
257                                 "</span><span class=\"menudesc\">"
258                                 "(domain names, etc.)</span></A><BR>\n");
259                 }
260                 do_template("endbox");
261         }
262         wprintf("</TD></TR></TABLE>");
263         wDumpContent(2);
264 }
265
266
267
268
269
270 /*
271  * Display the screen to enter a generic server command
272  */
273 void display_generic(void)
274 {
275         output_headers(3);
276
277         svprintf("BOXTITLE", WCS_STRING, "Enter a server command");
278         do_template("beginbox");
279
280         wprintf("<CENTER>");
281         wprintf("This screen allows you to enter Citadel server commands which are\n");
282         wprintf("not supported by WebCit.  If you do not know what that means,\n");
283         wprintf("then this screen will not be of much use to you.<BR>\n");
284
285         wprintf("<FORM METHOD=\"POST\" ACTION=\"/do_generic\">\n");
286
287         wprintf("Enter command:<BR>\n");
288         wprintf("<INPUT TYPE=\"text\" NAME=\"g_cmd\" SIZE=80 MAXLENGTH=\"250\"><BR>\n");
289
290         wprintf("Command input (if requesting SEND_LISTING transfer mode):<BR>\n");
291         wprintf("<TEXTAREA NAME=\"g_input\" ROWS=10 COLS=80 WIDTH=80></TEXTAREA><BR>\n");
292
293         wprintf("<FONT SIZE=-2>Detected host header is http://%s</FONT>\n",
294                 WC->http_host);
295         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Send command\">");
296         wprintf("&nbsp;");
297         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
298
299         wprintf("</FORM></CENTER>\n");
300         do_template("endbox");
301         wDumpContent(1);
302 }
303
304 void do_generic(void)
305 {
306         char buf[SIZ];
307         char gcontent[SIZ];
308         char *junk;
309         size_t len;
310
311         if (strcasecmp(bstr("sc"), "Send command")) {
312                 display_main_menu();
313                 return;
314         }
315
316         output_headers(3);
317
318         serv_printf("%s", bstr("g_cmd"));
319         serv_gets(buf);
320
321         svprintf("BOXTITLE", WCS_STRING, "Server command results");
322         do_template("beginbox");
323
324         wprintf("<TABLE border=0><TR><TD>Command:</TD><TD><TT>");
325         escputs(bstr("g_cmd"));
326         wprintf("</TT></TD></TR><TR><TD>Result:</TD><TD><TT>");
327         escputs(buf);
328         wprintf("</TT></TD></TR></TABLE><BR>\n");
329
330         if (buf[0] == '8') {
331                 serv_printf("\n\n000");
332         }
333         if ((buf[0] == '1') || (buf[0] == '8')) {
334                 while (serv_gets(gcontent), strcmp(gcontent, "000")) {
335                         escputs(gcontent);
336                         wprintf("<BR>\n");
337                 }
338                 wprintf("000");
339         }
340         if (buf[0] == '4') {
341                 text_to_server(bstr("g_input"), 0);
342                 serv_puts("000");
343         }
344         if (buf[0] == '6') {
345                 len = atol(&buf[4]);
346                 junk = malloc(len);
347                 serv_read(junk, len);
348                 free(junk);
349         }
350         if (buf[0] == '7') {
351                 len = atol(&buf[4]);
352                 junk = malloc(len);
353                 memset(junk, 0, len);
354                 serv_write(junk, len);
355                 free(junk);
356         }
357         wprintf("<HR>");
358         wprintf("<A HREF=\"/display_generic\">Enter another command</A><BR>\n");
359         wprintf("<A HREF=\"/display_advanced\">Return to menu</A>\n");
360         do_template("endbox");
361         wDumpContent(1);
362 }
363
364
365
366
367 /*
368  * Display the menubar.  Set as_single_page to
369  * display HTML headers and footers -- otherwise it's assumed
370  * that the menubar is being embedded in another page.
371  */
372 void display_menubar(int as_single_page) {
373
374         if (as_single_page) {
375                 output_headers(0);
376                 wprintf("<HTML>\n"
377                         "<HEAD>\n"
378                         "<TITLE>MenuBar</TITLE>\n"
379                         "<STYLE TYPE=\"text/css\">\n"
380                         "BODY   { text-decoration: none; }\n"
381                         "</STYLE>\n"
382                         "</HEAD>\n");
383                 do_template("background");
384         }
385
386         do_template("menubar");
387
388         if (as_single_page) {
389                 wDumpContent(2);
390         }
391
392
393 }
394
395