]> code.citadel.org Git - citadel.git/blob - webcit/roomops.c
* Rewrote the HTTP engine and application coupling to run in a worker thread
[citadel.git] / webcit / roomops.c
1 /* $Id$ */
2
3
4 #include <ctype.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <stdio.h>
8 #include <fcntl.h>
9 #include <signal.h>
10 #include <sys/types.h>
11 #include <sys/wait.h>
12 #include <sys/socket.h>
13 #include <sys/time.h>
14 #include <limits.h>
15 #include <netinet/in.h>
16 #include <netdb.h>
17 #include <string.h>
18 #include <pwd.h>
19 #include <errno.h>
20 #include <stdarg.h>
21 #include <pthread.h>
22 #include <signal.h>
23 #include "webcit.h"
24
25
26
27
28
29
30
31
32 /*
33  * This struct holds a list of rooms for <G>oto operations.
34  */
35 struct march {
36         struct march *next;
37         char march_name[32];
38         int march_floor;
39         int march_order;
40 };
41
42 /* 
43  * This struct holds a list of rooms for client display.
44  * (oooh, a tree!)
45  */
46 struct roomlisting {
47         struct roomlisting *lnext;
48         struct roomlisting *rnext;
49         char rlname[64];
50         unsigned rlflags;
51         int rlfloor;
52         int rlorder;
53 };
54
55
56 char floorlist[128][256];
57
58 struct march *march = NULL;
59
60 /*
61  * load the list of floors
62  */
63 void load_floorlist(void)
64 {
65         int a;
66         char buf[256];
67
68         for (a = 0; a < 128; ++a)
69                 floorlist[a][0] = 0;
70
71         serv_puts("LFLR");
72         serv_gets(buf);
73         if (buf[0] != '1') {
74                 strcpy(floorlist[0], "Main Floor");
75                 return;
76         }
77         while (serv_gets(buf), strcmp(buf, "000")) {
78                 extract(floorlist[extract_int(buf, 0)], buf, 1);
79         }
80 }
81
82
83 /*
84  * remove a room from the march list
85  */
86 void remove_march(char *aaa)
87 {
88         struct march *mptr, *mptr2;
89
90         if (march == NULL)
91                 return;
92
93         if (!strcasecmp(march->march_name, aaa)) {
94                 mptr = march->next;
95                 free(march);
96                 march = mptr;
97                 return;
98         }
99         mptr2 = march;
100         for (mptr = march; mptr != NULL; mptr = mptr->next) {
101                 if (!strcasecmp(mptr->march_name, aaa)) {
102                         mptr2->next = mptr->next;
103                         free(mptr);
104                         mptr = mptr2;
105                 } else {
106                         mptr2 = mptr;
107                 }
108         }
109 }
110
111
112
113
114
115 void room_tree_list(struct roomlisting *rp)
116 {
117         char rmname[64];
118         int f;
119
120         if (rp == NULL)
121                 return;
122
123         if (rp->lnext != NULL) {
124                 room_tree_list(rp->lnext);
125         }
126         strcpy(rmname, rp->rlname);
127         f = rp->rlflags;
128
129         wprintf("<A HREF=\"/dotgoto&room=");
130         urlescputs(rmname);
131         wprintf("\"");
132         wprintf(">");
133         escputs1(rmname, 1);
134         if ((f & QR_DIRECTORY) && (f & QR_NETWORK))
135                 wprintf("}");
136         else if (f & QR_DIRECTORY)
137                 wprintf("]");
138         else if (f & QR_NETWORK)
139                 wprintf(")");
140         else
141                 wprintf("&gt;");
142         wprintf("</A><TT> </TT>\n");
143
144         if (rp->rnext != NULL) {
145                 room_tree_list(rp->rnext);
146         }
147         free(rp);
148 }
149
150
151 /* 
152  * Room ordering stuff (compare first by floor, then by order)
153  */
154 int rordercmp(struct roomlisting *r1, struct roomlisting *r2)
155 {
156         if ((r1 == NULL) && (r2 == NULL))
157                 return (0);
158         if (r1 == NULL)
159                 return (-1);
160         if (r2 == NULL)
161                 return (1);
162         if (r1->rlfloor < r2->rlfloor)
163                 return (-1);
164         if (r1->rlfloor > r2->rlfloor)
165                 return (1);
166         if (r1->rlorder < r2->rlorder)
167                 return (-1);
168         if (r1->rlorder > r2->rlorder)
169                 return (1);
170         return (0);
171 }
172
173
174 /*
175  * Common code for all room listings
176  */
177 void listrms(char *variety)
178 {
179         char buf[256];
180         int num_rooms = 0;
181
182         struct roomlisting *rl = NULL;
183         struct roomlisting *rp;
184         struct roomlisting *rs;
185
186
187         /* Ask the server for a room list */
188         serv_puts(variety);
189         serv_gets(buf);
190         if (buf[0] != '1') {
191                 wprintf("&nbsp;");
192                 return;
193         }
194         while (serv_gets(buf), strcmp(buf, "000")) {
195                 ++num_rooms;
196                 rp = malloc(sizeof(struct roomlisting));
197                 extract(rp->rlname, buf, 0);
198                 rp->rlflags = extract_int(buf, 1);
199                 rp->rlfloor = extract_int(buf, 2);
200                 rp->rlorder = extract_int(buf, 3);
201                 rp->lnext = NULL;
202                 rp->rnext = NULL;
203
204                 rs = rl;
205                 if (rl == NULL) {
206                         rl = rp;
207                 } else
208                         while (rp != NULL) {
209                                 if (rordercmp(rp, rs) < 0) {
210                                         if (rs->lnext == NULL) {
211                                                 rs->lnext = rp;
212                                                 rp = NULL;
213                                         } else {
214                                                 rs = rs->lnext;
215                                         }
216                                 } else {
217                                         if (rs->rnext == NULL) {
218                                                 rs->rnext = rp;
219                                                 rp = NULL;
220                                         } else {
221                                                 rs = rs->rnext;
222                                         }
223                                 }
224                         }
225         }
226
227         room_tree_list(rl);
228
229         /* If no rooms were listed, print an nbsp to make the cell
230          * borders show up anyway.
231          */
232         if (num_rooms == 0) wprintf("&nbsp;");
233 }
234
235
236
237
238
239
240
241
242
243 /*
244  * list all rooms by floor
245  */
246 void list_all_rooms_by_floor(void)
247 {
248         int a;
249         char buf[256];
250
251         load_floorlist();
252
253         wprintf("HTTP/1.0 200 OK\n");
254         output_headers(1);
255
256         wprintf("<TABLE width=100% border><TR><TH>Floor</TH>");
257         wprintf("<TH><FONT FACE=\"Arial,Helvetica,sans-serif\">Rooms with new messages</FONT></TH>");
258         wprintf("<TH><FONT FACE=\"Arial,Helvetica,sans-serif\">Rooms with no new messages</FONT></TH></TR>\n");
259
260         for (a = 0; a < 128; ++a)
261                 if (floorlist[a][0] != 0) {
262
263                         /* Floor name column */
264                         wprintf("<TR><TD><FONT FACE=\"Arial,Helvetica,sans-serif\">");
265
266                         serv_printf("OIMG _floorpic_|%d", a);
267                         serv_gets(buf);
268                         if (buf[0] == '2') {
269                                 serv_puts("CLOS");
270                                 serv_gets(buf);
271                                 wprintf("<IMG SRC=\"/image&name=_floorpic_&parm=%d\" ALT=\"%s\">",
272                                         a, &floorlist[a][0]);
273                         } else {
274                                 escputs(&floorlist[a][0]);
275                         }
276
277                         wprintf("</FONT></TD>");
278
279                         /* Rooms with new messages column */
280                         wprintf("<TD><FONT FACE=\"Arial,Helvetica,sans-serif\">");
281                         sprintf(buf, "LKRN %d", a);
282                         listrms(buf);
283                         wprintf("</FONT></TD>\n<TD><FONT FACE=\"Arial,Helvetica,sans-serif\">");
284
285                         /* Rooms with old messages column */
286                         sprintf(buf, "LKRO %d", a);
287                         listrms(buf);
288                         wprintf("</FONT></TD></TR>\n");
289                 }
290         wprintf("</TABLE>\n");
291         wDumpContent(1);
292 }
293
294
295 /*
296  * list all forgotten rooms
297  */
298 void zapped_list(void)
299 {
300         wprintf("HTTP/1.0 200 OK\n");
301         output_headers(1);
302         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
303         wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\" SIZE=+1 COLOR=\"FFFFFF\"");
304         wprintf("<B>Zapped (forgotten) rooms</B>\n");
305         wprintf("</FONT></TD></TR></TABLE><BR>\n");
306         listrms("LZRM -1");
307         wprintf("<BR><BR>\n");
308         wprintf("Click on any room to un-zap it and goto that room.\n");
309         wDumpContent(1);
310 }
311
312
313 /*
314  * read this room's info file (set v to 1 for verbose mode)
315  */
316 void readinfo(int v)
317 {
318         char buf[256];
319
320         serv_puts("RINF");
321         serv_gets(buf);
322         if (buf[0] == '1')
323                 fmout(NULL);
324         else {
325                 if (v == 1)
326                         wprintf("<EM>%s</EM><BR>\n", &buf[4]);
327         }
328 }
329
330
331
332 void embed_room_banner(char *got) {
333         char buf[256];
334         char fakegot[256];
335         static int remember_new_mail = (-1);
336
337         /* We need to have the information returned by a GOTO server command.
338          * If it isn't supplied, we fake it by issuing our own GOTO.
339          */
340         if (got == NULL) {
341                 serv_printf("GOTO %s", WC->wc_roomname);
342                 serv_gets(fakegot);
343                 got = fakegot;
344         }
345
346         /* Check for new mail. */
347         WC->new_mail = extract_int(&got[4], 9);
348
349         /* Now start spewing HTML. */
350         wprintf("<CENTER><TABLE border=0><TR>");
351
352         if ((strlen(WC->ugname) > 0) && (strcasecmp(WC->ugname, WC->wc_roomname))) {
353                 wprintf("<TD VALIGN=TOP><A HREF=\"/ungoto\">");
354                 wprintf("<IMG SRC=\"/static/back.gif\" BORDER=0></A></TD>");
355         }
356         wprintf("<TD VALIGN=TOP><FONT FACE=\"Arial,Helvetica,sans-serif\"><FONT SIZE=+2>%s</FONT><BR>", WC->wc_roomname);
357         wprintf("%d new of %d messages</FONT></TD>\n",
358                 extract_int(&got[4], 1),
359                 extract_int(&got[4], 2));
360
361         /* Display room graphic.  The server doesn't actually
362          * need the room name, but we supply it in order to
363          * keep the browser from using a cached graphic from 
364          * another room.
365          */
366         serv_puts("OIMG _roompic_");
367         serv_gets(buf);
368         if (buf[0] == '2') {
369                 wprintf("<TD><FONT FACE=\"Arial,Helvetica,sans-serif\">");
370                 wprintf("<IMG SRC=\"/image&name=_roompic_&room=");
371                 urlescputs(WC->wc_roomname);
372                 wprintf("\"></FONT></TD>");
373                 serv_puts("CLOS");
374                 serv_gets(buf);
375         }
376         wprintf("<TD VALIGN=TOP><FONT FACE=\"Arial,Helvetica,sans-serif\">");
377         readinfo(0);
378         wprintf("</FONT></TD>");
379
380         /* Let the user know if new mail has arrived */
381         if ( (WC->new_mail > remember_new_mail) && (WC->new_mail>0) ) {
382                 wprintf("<TD VALIGN=TOP>"
383                         "<IMG SRC=\"/static/mail.gif\" border=0 "
384                         "ALT=\"You have new mail\">"
385                         "<BR><BLINK>%d</BLINK></TD>", WC->new_mail);
386                 remember_new_mail = WC->new_mail;
387         }
388
389         wprintf("<TD VALIGN=TOP><A HREF=\"/gotonext\">");
390         wprintf("<IMG SRC=\"/static/forward.gif\" border=0></A></TD>");
391         wprintf("</TR></TABLE></CENTER>\n");
392 }
393
394
395
396
397
398 /*
399  * generic routine to take the session to a new room
400  *
401  * display_name values:  0 = goto only
402  *                       1 = goto and display
403  *                       2 = display only
404  */
405 void gotoroom(char *gname, int display_name)
406 {
407         char buf[256];
408         static long ls = (-1L);
409
410
411         if (display_name) {
412                 wprintf("HTTP/1.0 200 OK\n");
413                 printf("Pragma: no-cache\n");
414                 printf("Cache-Control: no-store\n");
415                 output_headers(0);
416
417                 wprintf("<HTML><HEAD>\n"
418                         "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n"
419                         "</HEAD>\n<BODY ");
420                 wprintf("BACKGROUND=\"/image&name=background\" TEXT=\"#000000\" LINK=\"#004400\">\n");
421         }
422         if (display_name != 2) {
423                 /* store ungoto information */
424                 strcpy(WC->ugname, WC->wc_roomname);
425                 WC->uglsn = ls;
426         }
427         /* move to the new room */
428         serv_printf("GOTO %s", gname);
429         serv_gets(buf);
430         if (buf[0] != '2') {
431                 serv_puts("GOTO _BASEROOM_");
432                 serv_gets(buf);
433         }
434         if (buf[0] != '2') {
435                 if (display_name) {
436                         wprintf("<EM>%s</EM><BR>\n", &buf[4]);
437                         wDumpContent(1);
438                 }
439                 return;
440         }
441         extract(WC->wc_roomname, &buf[4], 0);
442         WC->room_flags = extract_int(&buf[4], 4);
443         /* highest_msg_read = extract_int(&buf[4],6);
444            maxmsgnum = extract_int(&buf[4],5);
445            is_mail = (char) extract_int(&buf[4],7); */
446         ls = extract_long(&buf[4], 6);
447
448         if (WC->is_aide)
449                 WC->is_room_aide = WC->is_aide;
450         else
451                 WC->is_room_aide = (char) extract_int(&buf[4], 8);
452
453         remove_march(WC->wc_roomname);
454         if (!strcasecmp(gname, "_BASEROOM_"))
455                 remove_march(gname);
456
457         /* Display the room banner */
458         if (display_name) {
459                 embed_room_banner(buf);
460                 wDumpContent(1);
461         }
462         strcpy(WC->wc_roomname, WC->wc_roomname);
463 }
464
465
466 /*
467  * Locate the room on the march list which we most want to go to.  Each room
468  * is measured given a "weight" of preference based on various factors.
469  */
470 char *pop_march(int desired_floor)
471 {
472         static char TheRoom[64];
473         int TheFloor = 0;
474         int TheOrder = 32767;
475         int TheWeight = 0;
476         int weight;
477         struct march *mptr = NULL;
478
479         strcpy(TheRoom, "_BASEROOM_");
480         if (march == NULL)
481                 return (TheRoom);
482
483         for (mptr = march; mptr != NULL; mptr = mptr->next) {
484                 weight = 0;
485                 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
486                         weight = weight + 10000;
487                 if (mptr->march_floor == desired_floor)
488                         weight = weight + 5000;
489
490                 weight = weight + ((128 - (mptr->march_floor)) * 128);
491                 weight = weight + (128 - (mptr->march_order));
492
493                 if (weight > TheWeight) {
494                         TheWeight = weight;
495                         strcpy(TheRoom, mptr->march_name);
496                         TheFloor = mptr->march_floor;
497                         TheOrder = mptr->march_order;
498                 }
499         }
500         return (TheRoom);
501 }
502
503
504
505 /* Goto next room having unread messages.
506  * We want to skip over rooms that the user has already been to, and take the
507  * user back to the lobby when done.  The room we end up in is placed in
508  * newroom - which is set to 0 (the lobby) initially.
509  * We start the search in the current room rather than the beginning to prevent
510  * two or more concurrent users from dragging each other back to the same room.
511  */
512 void gotonext(void)
513 {
514         char buf[256];
515         struct march *mptr, *mptr2;
516         char next_room[32];
517
518         /* First check to see if the march-mode list is already allocated.
519          * If it is, pop the first room off the list and go there.
520          */
521
522         if (march == NULL) {
523                 serv_puts("LKRN");
524                 serv_gets(buf);
525                 if (buf[0] == '1')
526                         while (serv_gets(buf), strcmp(buf, "000")) {
527                                 mptr = (struct march *) malloc(sizeof(struct march));
528                                 mptr->next = NULL;
529                                 extract(mptr->march_name, buf, 0);
530                                 mptr->march_floor = extract_int(buf, 2);
531                                 mptr->march_order = extract_int(buf, 3);
532                                 if (march == NULL) {
533                                         march = mptr;
534                                 } else {
535                                         mptr2 = march;
536                                         while (mptr2->next != NULL)
537                                                 mptr2 = mptr2->next;
538                                         mptr2->next = mptr;
539                                 }
540                         }
541 /* add _BASEROOM_ to the end of the march list, so the user will end up
542  * in the system base room (usually the Lobby>) at the end of the loop
543  */
544                 mptr = (struct march *) malloc(sizeof(struct march));
545                 mptr->next = NULL;
546                 strcpy(mptr->march_name, "_BASEROOM_");
547                 if (march == NULL) {
548                         march = mptr;
549                 } else {
550                         mptr2 = march;
551                         while (mptr2->next != NULL)
552                                 mptr2 = mptr2->next;
553                         mptr2->next = mptr;
554                 }
555 /*
556  * ...and remove the room we're currently in, so a <G>oto doesn't make us
557  * walk around in circles
558  */
559                 remove_march(WC->wc_roomname);
560         }
561         if (march != NULL) {
562                 strcpy(next_room, pop_march(-1));
563         } else {
564                 strcpy(next_room, "_BASEROOM_");
565         }
566
567
568         smart_goto(next_room);
569 }
570
571
572 void smart_goto(char *next_room) {
573         gotoroom(next_room, 0);
574         readloop("readnew");
575 }
576
577
578
579 /*
580  * mark all messages in current room as having been read
581  */
582 void slrp_highest(void)
583 {
584         char buf[256];
585
586         /* set pointer */
587         serv_puts("SLRP HIGHEST");
588         serv_gets(buf);
589         if (buf[0] != '2') {
590                 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
591                 return;
592         }
593 }
594
595
596 /*
597  * un-goto the previous room
598  */
599 void ungoto(void)
600 {
601         char buf[256];
602
603         if (!strcmp(WC->ugname, "")) {
604                 smart_goto(WC->wc_roomname);
605                 return;
606         }
607         serv_printf("GOTO %s", WC->ugname);
608         serv_gets(buf);
609         if (buf[0] != '2') {
610                 smart_goto(WC->wc_roomname);
611                 return;
612         }
613         if (WC->uglsn >= 0L) {
614                 serv_printf("SLRP %ld", WC->uglsn);
615                 serv_gets(buf);
616         }
617         strcpy(buf, WC->ugname);
618         strcpy(WC->ugname, "");
619         smart_goto(buf);
620 }
621
622 /*
623  * display the form for editing a room
624  */
625 void display_editroom(void)
626 {
627         char buf[256];
628         char er_name[20];
629         char er_password[10];
630         char er_dirname[15];
631         char er_roomaide[26];
632         unsigned er_flags;
633         int er_floor;
634         int i;
635
636         serv_puts("GETR");
637         serv_gets(buf);
638
639         if (buf[0] != '2') {
640                 display_error(&buf[4]);
641                 return;
642         }
643         extract(er_name, &buf[4], 0);
644         extract(er_password, &buf[4], 1);
645         extract(er_dirname, &buf[4], 2);
646         er_flags = extract_int(&buf[4], 3);
647         er_floor = extract_int(&buf[4], 4);
648
649
650         wprintf("HTTP/1.0 200 OK\n");
651         output_headers(1);
652
653         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=000077><TR><TD>");
654         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
655         wprintf("<B>Room administration</B>\n");
656         wprintf("</FONT></TD></TR></TABLE>\n");
657
658         wprintf("<UL>"
659                 "<LI><A HREF=\"/confirm_delete_room\">\n"
660                 "Delete this room</A>\n"
661                 "<LI><A HREF=\"/display_editroompic\">\n"
662                 "Set or change the graphic for this room's banner</A>\n"
663                 "<LI><A HREF=\"/display_editinfo\">\n"
664                 "Edit this room's Info file</A>\n"
665                 "</UL>");
666
667         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=000077><TR><TD>");
668         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
669         wprintf("<B>Room editing</B>\n");
670         wprintf("</FONT></TD></TR></TABLE>\n");
671
672         wprintf("<FORM METHOD=\"POST\" ACTION=\"/editroom\">\n");
673
674         wprintf("<UL><LI>Name of room: ");
675         wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", er_name);
676
677         wprintf("<LI>Resides on floor: ");
678         load_floorlist();
679         wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
680         for (i = 0; i < 128; ++i)
681                 if (strlen(floorlist[i]) > 0) {
682                         wprintf("<OPTION ");
683                         if (i == er_floor)
684                                 wprintf("SELECTED ");
685                         wprintf("VALUE=\"%d\">", i);
686                         escputs(floorlist[i]);
687                         wprintf("</OPTION>\n");
688                 }
689         wprintf("</SELECT>\n");
690
691         wprintf("<LI>Type of room:<UL>\n");
692
693         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
694         if ((er_flags & QR_PRIVATE) == 0)
695                 wprintf("CHECKED ");
696         wprintf("> Public room\n");
697
698         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
699         if ((er_flags & QR_PRIVATE) &&
700             (er_flags & QR_GUESSNAME))
701                 wprintf("CHECKED ");
702         wprintf("> Private - guess name\n");
703
704         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
705         if ((er_flags & QR_PRIVATE) &&
706             (er_flags & QR_PASSWORDED))
707                 wprintf("CHECKED ");
708         wprintf("> Private - require password:\n");
709         wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" VALUE=\"%s\" MAXLENGTH=\"9\">\n", er_password);
710
711         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
712         if ((er_flags & QR_PRIVATE)
713             && ((er_flags & QR_GUESSNAME) == 0)
714             && ((er_flags & QR_PASSWORDED) == 0))
715                 wprintf("CHECKED ");
716         wprintf("> Private - invitation only\n");
717
718         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"bump\" VALUE=\"yes\" ");
719         wprintf("> If private, cause current users to forget room\n");
720
721         wprintf("</UL>\n");
722
723         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"prefonly\" VALUE=\"yes\" ");
724         if (er_flags & QR_PREFONLY)
725                 wprintf("CHECKED ");
726         wprintf("> Preferred users only\n");
727
728         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"readonly\" VALUE=\"yes\" ");
729         if (er_flags & QR_READONLY)
730                 wprintf("CHECKED ");
731         wprintf("> Read-only room\n");
732
733 /* directory stuff */
734         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"directory\" VALUE=\"yes\" ");
735         if (er_flags & QR_DIRECTORY)
736                 wprintf("CHECKED ");
737         wprintf("> File directory room\n");
738
739         wprintf("<UL><LI>Directory name: ");
740         wprintf("<INPUT TYPE=\"text\" NAME=\"er_dirname\" VALUE=\"%s\" MAXLENGTH=\"14\">\n", er_dirname);
741
742         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"ulallowed\" VALUE=\"yes\" ");
743         if (er_flags & QR_UPLOAD)
744                 wprintf("CHECKED ");
745         wprintf("> Uploading allowed\n");
746
747         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"dlallowed\" VALUE=\"yes\" ");
748         if (er_flags & QR_DOWNLOAD)
749                 wprintf("CHECKED ");
750         wprintf("> Downloading allowed\n");
751
752         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"visdir\" VALUE=\"yes\" ");
753         if (er_flags & QR_VISDIR)
754                 wprintf("CHECKED ");
755         wprintf("> Visible directory</UL>\n");
756
757 /* end of directory stuff */
758
759         wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"network\" VALUE=\"yes\" ");
760         if (er_flags & QR_NETWORK)
761                 wprintf("CHECKED ");
762         wprintf("> Network shared room\n");
763
764 /* start of anon options */
765
766         wprintf("<LI>Anonymous messages<UL>\n");
767
768         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"no\" ");
769         if (((er_flags & QR_ANONONLY) == 0)
770             && ((er_flags & QR_ANONOPT) == 0))
771                 wprintf("CHECKED ");
772         wprintf("> No anonymous messages\n");
773
774         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anononly\" ");
775         if (er_flags & QR_ANONONLY)
776                 wprintf("CHECKED ");
777         wprintf("> All messages are anonymous\n");
778
779         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anon2\" ");
780         if (er_flags & QR_ANONOPT)
781                 wprintf("CHECKED ");
782         wprintf("> Prompt user when entering messages</UL>\n");
783
784 /* end of anon options */
785
786         wprintf("<LI>Room aide: \n");
787         serv_puts("GETA");
788         serv_gets(buf);
789         if (buf[0] != '2') {
790                 wprintf("<EM>%s</EM>\n", &buf[4]);
791         } else {
792                 extract(er_roomaide, &buf[4], 0);
793                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_roomaide\" VALUE=\"%s\" MAXLENGTH=\"25\">\n", er_roomaide);
794         }
795
796         wprintf("</UL><CENTER>\n");
797         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
798         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
799         wprintf("</CENTER>\n");
800
801         wDumpContent(1);
802 }
803
804
805 /*
806  * save new parameters for a room
807  */
808 void editroom(void)
809 {
810         char buf[256];
811         char er_name[20];
812         char er_password[10];
813         char er_dirname[15];
814         char er_roomaide[26];
815         int er_floor;
816         unsigned er_flags;
817         int bump;
818
819
820         if (strcmp(bstr("sc"), "OK")) {
821                 display_error("Cancelled.  Changes were not saved.");
822                 return;
823         }
824         serv_puts("GETR");
825         serv_gets(buf);
826
827         if (buf[0] != '2') {
828                 display_error(&buf[4]);
829                 return;
830         }
831         extract(er_name, &buf[4], 0);
832         extract(er_password, &buf[4], 1);
833         extract(er_dirname, &buf[4], 2);
834         er_flags = extract_int(&buf[4], 3);
835
836         strcpy(er_roomaide, bstr("er_roomaide"));
837         if (strlen(er_roomaide) == 0) {
838                 serv_puts("GETA");
839                 serv_gets(buf);
840                 if (buf[0] != '2') {
841                         strcpy(er_roomaide, "");
842                 } else {
843                         extract(er_roomaide, &buf[4], 0);
844                 }
845         }
846         strcpy(buf, bstr("er_name"));
847         buf[20] = 0;
848         if (strlen(buf) > 0)
849                 strcpy(er_name, buf);
850
851         strcpy(buf, bstr("er_password"));
852         buf[10] = 0;
853         if (strlen(buf) > 0)
854                 strcpy(er_password, buf);
855
856         strcpy(buf, bstr("er_dirname"));
857         buf[15] = 0;
858         if (strlen(buf) > 0)
859                 strcpy(er_dirname, buf);
860
861         strcpy(buf, bstr("type"));
862         er_flags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
863
864         if (!strcmp(buf, "invonly")) {
865                 er_flags |= (QR_PRIVATE);
866         }
867         if (!strcmp(buf, "guessname")) {
868                 er_flags |= (QR_PRIVATE | QR_GUESSNAME);
869         }
870         if (!strcmp(buf, "passworded")) {
871                 er_flags |= (QR_PRIVATE | QR_PASSWORDED);
872         }
873         if (!strcmp(bstr("prefonly"), "yes")) {
874                 er_flags |= QR_PREFONLY;
875         } else {
876                 er_flags &= ~QR_PREFONLY;
877         }
878
879         if (!strcmp(bstr("readonly"), "yes")) {
880                 er_flags |= QR_READONLY;
881         } else {
882                 er_flags &= ~QR_READONLY;
883         }
884
885         if (!strcmp(bstr("network"), "yes")) {
886                 er_flags |= QR_NETWORK;
887         } else {
888                 er_flags &= ~QR_NETWORK;
889         }
890
891         if (!strcmp(bstr("directory"), "yes")) {
892                 er_flags |= QR_DIRECTORY;
893         } else {
894                 er_flags &= ~QR_DIRECTORY;
895         }
896
897         if (!strcmp(bstr("ulallowed"), "yes")) {
898                 er_flags |= QR_UPLOAD;
899         } else {
900                 er_flags &= ~QR_UPLOAD;
901         }
902
903         if (!strcmp(bstr("dlallowed"), "yes")) {
904                 er_flags |= QR_DOWNLOAD;
905         } else {
906                 er_flags &= ~QR_DOWNLOAD;
907         }
908
909         if (!strcmp(bstr("visdir"), "yes")) {
910                 er_flags |= QR_VISDIR;
911         } else {
912                 er_flags &= ~QR_VISDIR;
913         }
914
915         strcpy(buf, bstr("anon"));
916
917         er_flags &= ~(QR_ANONONLY | QR_ANONOPT);
918         if (!strcmp(buf, "anononly"))
919                 er_flags |= QR_ANONONLY;
920         if (!strcmp(buf, "anon2"))
921                 er_flags |= QR_ANONOPT;
922
923         bump = 0;
924         if (!strcmp(bstr("bump"), "yes"))
925                 bump = 1;
926
927         er_floor = atoi(bstr("er_floor"));
928
929         sprintf(buf, "SETR %s|%s|%s|%u|%d|%d",
930              er_name, er_password, er_dirname, er_flags, bump, er_floor);
931         serv_puts(buf);
932         serv_gets(buf);
933         if (buf[0] != '2') {
934                 display_error(&buf[4]);
935                 return;
936         }
937         gotoroom(er_name, 0);
938
939         if (strlen(er_roomaide) > 0) {
940                 sprintf(buf, "SETA %s", er_roomaide);
941                 serv_puts(buf);
942                 serv_gets(buf);
943                 if (buf[0] != '2') {
944                         display_error(&buf[4]);
945                         return;
946                 }
947         }
948         smart_goto(er_name);
949 }
950
951
952
953 /*
954  * display the form for entering a new room
955  */
956 void display_entroom(void)
957 {
958         char buf[256];
959
960         serv_puts("CRE8 0");
961         serv_gets(buf);
962
963         if (buf[0] != '2') {
964                 display_error(&buf[4]);
965                 return;
966         }
967         wprintf("HTTP/1.0 200 OK\n");
968         output_headers(1);
969
970         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=000077><TR><TD>");
971         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
972         wprintf("<B>Enter (create) a new room</B>\n");
973         wprintf("</FONT></TD></TR></TABLE>\n");
974
975         wprintf("<FORM METHOD=\"POST\" ACTION=\"/entroom\">\n");
976
977         wprintf("<UL><LI>Name of room: ");
978         wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" MAXLENGTH=\"19\">\n");
979
980         wprintf("<LI>Type of room:<UL>\n");
981
982         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
983         wprintf("CHECKED > Public room\n");
984
985         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
986         wprintf("> Private - guess name\n");
987
988         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
989         wprintf("> Private - require password:\n");
990         wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" MAXLENGTH=\"9\">\n");
991
992         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
993         wprintf("> Private - invitation only\n");
994
995         wprintf("<CENTER>\n");
996         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
997         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
998         wprintf("</CENTER>\n");
999         wprintf("</FORM>\n");
1000         wDumpContent(1);
1001 }
1002
1003
1004
1005 /*
1006  * enter a new room
1007  */
1008 void entroom(void)
1009 {
1010         char buf[256];
1011         char er_name[20];
1012         char er_type[20];
1013         char er_password[10];
1014         int er_num_type;
1015
1016         if (strcmp(bstr("sc"), "OK")) {
1017                 display_error("Cancelled.  No new room was created.");
1018                 return;
1019         }
1020         strcpy(er_name, bstr("er_name"));
1021         strcpy(er_type, bstr("type"));
1022         strcpy(er_password, bstr("er_password"));
1023
1024         er_num_type = 0;
1025         if (!strcmp(er_type, "guessname"))
1026                 er_num_type = 1;
1027         if (!strcmp(er_type, "passworded"))
1028                 er_num_type = 2;
1029         if (!strcmp(er_type, "invonly"))
1030                 er_num_type = 3;
1031
1032         sprintf(buf, "CRE8 1|%s|%d|%s", er_name, er_num_type, er_password);
1033         serv_puts(buf);
1034         serv_gets(buf);
1035         if (buf[0] != '2') {
1036                 display_error(&buf[4]);
1037                 return;
1038         }
1039         smart_goto(er_name);
1040 }
1041
1042
1043 /*
1044  * display the screen to enter a private room
1045  */
1046 void display_private(char *rname, int req_pass)
1047 {
1048
1049         wprintf("HTTP/1.0 200 OK\n");
1050         output_headers(1);
1051
1052         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
1053         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1054         wprintf("<B>Goto a private room</B>\n");
1055         wprintf("</FONT></TD></TR></TABLE>\n");
1056
1057         wprintf("<CENTER>\n");
1058         wprintf("If you know the name of a hidden (guess-name) or\n");
1059         wprintf("passworded room, you can enter that room by typing\n");
1060         wprintf("its name below.  Once you gain access to a private\n");
1061         wprintf("room, it will appear in your regular room listings\n");
1062         wprintf("so you don't have to keep returning here.\n");
1063         wprintf("<BR><BR>");
1064
1065         wprintf("<FORM METHOD=\"POST\" ACTION=\"/goto_private\">\n");
1066
1067         wprintf("<TABLE border><TR><TD>");
1068         wprintf("Enter room name:</TD><TD>");
1069         wprintf("<INPUT TYPE=\"text\" NAME=\"gr_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", rname);
1070
1071         if (req_pass) {
1072                 wprintf("</TD></TR><TR><TD>");
1073                 wprintf("Enter room password:</TD><TD>");
1074                 wprintf("<INPUT TYPE=\"password\" NAME=\"gr_pass\" MAXLENGTH=\"9\">\n");
1075         }
1076         wprintf("</TD></TR></TABLE>\n");
1077
1078         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1079         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1080         wprintf("</FORM>\n");
1081         wDumpContent(1);
1082 }
1083
1084 /* 
1085  * goto a private room
1086  */
1087 void goto_private(void)
1088 {
1089         char hold_rm[32];
1090         char buf[256];
1091
1092         if (strcasecmp(bstr("sc"), "OK")) {
1093                 display_main_menu();
1094                 return;
1095         }
1096         strcpy(hold_rm, WC->wc_roomname);
1097         strcpy(buf, "GOTO ");
1098         strcat(buf, bstr("gr_name"));
1099         strcat(buf, "|");
1100         strcat(buf, bstr("gr_pass"));
1101         serv_puts(buf);
1102         serv_gets(buf);
1103
1104         if (buf[0] == '2') {
1105                 smart_goto(bstr("gr_name"));
1106                 return;
1107         }
1108         if (!strncmp(buf, "540", 3)) {
1109                 display_private(bstr("gr_name"), 1);
1110                 return;
1111         }
1112         wprintf("HTTP/1.0 200 OK\n");
1113         output_headers(1);
1114         wprintf("%s\n", &buf[4]);
1115         wDumpContent(1);
1116         return;
1117 }
1118
1119
1120 /*
1121  * display the screen to zap a room
1122  */
1123 void display_zap(void)
1124 {
1125         wprintf("HTTP/1.0 200 OK\n");
1126         output_headers(1);
1127
1128         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
1129         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1130         wprintf("<B>Zap (forget) the current room</B>\n");
1131         wprintf("</FONT></TD></TR></TABLE>\n");
1132
1133         wprintf("If you select this option, <em>%s</em> will ", WC->wc_roomname);
1134         wprintf("disappear from your room list.  Is this what you wish ");
1135         wprintf("to do?<BR>\n");
1136
1137         wprintf("<FORM METHOD=\"POST\" ACTION=\"/zap\">\n");
1138         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1139         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1140         wprintf("</FORM>\n");
1141         wDumpContent(1);
1142 }
1143
1144
1145 /* 
1146  * zap a room
1147  */
1148 void zap(void)
1149 {
1150         char buf[256];
1151         char final_destination[256];
1152
1153         /* If the forget-room routine fails for any reason, we fall back
1154          * to the current room; otherwise, we go to the Lobby
1155          */
1156         strcpy(final_destination, WC->wc_roomname);
1157
1158         if (!strcasecmp(bstr("sc"), "OK")) {
1159                 serv_printf("GOTO %s", WC->wc_roomname);
1160                 serv_gets(buf);
1161                 if (buf[0] != '2') {
1162                         ExpressMessageCat(&buf[4]);
1163                 } else {
1164                         serv_puts("FORG");
1165                         serv_gets(buf);
1166                         if (buf[0] != '2') {
1167                                 ExpressMessageCat(&buf[4]);
1168                         } else {
1169                                 strcpy(final_destination, "_BASEROOM_");
1170                         }
1171                 }
1172         }
1173         smart_goto(final_destination);
1174 }
1175
1176
1177
1178
1179 /*
1180  * Confirm deletion of the current room
1181  */
1182 void confirm_delete_room(void)
1183 {
1184         char buf[256];
1185
1186         serv_puts("KILL 0");
1187         serv_gets(buf);
1188         if (buf[0] != '2') {
1189                 display_error(&buf[4]);
1190                 return;
1191         }
1192         wprintf("HTTP/1.0 200 OK\n");
1193         output_headers(1);
1194         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
1195         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1196         wprintf("<B>Confirm deletion of room</B>\n");
1197         wprintf("</FONT></TD></TR></TABLE>\n");
1198
1199         wprintf("<CENTER>");
1200         wprintf("<FORM METHOD=\"POST\" ACTION=\"/delete_room\">\n");
1201
1202         wprintf("Are you sure you want to delete <FONT SIZE=+1>");
1203         escputs(WC->wc_roomname);
1204         wprintf("</FONT>?<BR>\n");
1205
1206         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">");
1207         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1208
1209         wprintf("</FORM></CENTER>\n");
1210         wDumpContent(1);
1211 }
1212
1213
1214 /*
1215  * Delete the current room
1216  */
1217 void delete_room(void)
1218 {
1219         char buf[256];
1220         char sc[256];
1221
1222         strcpy(sc, bstr("sc"));
1223
1224         if (strcasecmp(sc, "Delete")) {
1225                 display_error("Cancelled.  This room was not deleted.");
1226                 return;
1227         }
1228         serv_puts("KILL 1");
1229         serv_gets(buf);
1230         if (buf[0] != '2') {
1231                 display_error(&buf[4]);
1232         } else {
1233                 smart_goto("_BASEROOM_");
1234         }
1235 }