]> code.citadel.org Git - citadel.git/blob - webcit/roomops.c
* Repaired all my b0rken COLOR tags
[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 char *viewdefs[] = {
27         "Messages",
28         "Summary",
29         "Address Book",
30         "Calendar",
31         "Tasks"
32 };
33
34 char floorlist[128][SIZ];
35
36 /*
37  * load the list of floors
38  */
39 void load_floorlist(void)
40 {
41         int a;
42         char buf[SIZ];
43
44         for (a = 0; a < 128; ++a)
45                 floorlist[a][0] = 0;
46
47         serv_puts("LFLR");
48         serv_gets(buf);
49         if (buf[0] != '1') {
50                 strcpy(floorlist[0], "Main Floor");
51                 return;
52         }
53         while (serv_gets(buf), strcmp(buf, "000")) {
54                 extract(floorlist[extract_int(buf, 0)], buf, 1);
55         }
56 }
57
58
59 /*
60  * remove a room from the march list
61  */
62 void remove_march(char *aaa)
63 {
64         struct march *mptr, *mptr2;
65
66         if (WC->march == NULL)
67                 return;
68
69         if (!strcasecmp(WC->march->march_name, aaa)) {
70                 mptr = WC->march->next;
71                 free(WC->march);
72                 WC->march = mptr;
73                 return;
74         }
75         mptr2 = WC->march;
76         for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
77                 if (!strcasecmp(mptr->march_name, aaa)) {
78                         mptr2->next = mptr->next;
79                         free(mptr);
80                         mptr = mptr2;
81                 } else {
82                         mptr2 = mptr;
83                 }
84         }
85 }
86
87
88
89
90
91 void room_tree_list(struct roomlisting *rp)
92 {
93         char rmname[64];
94         int f;
95
96         if (rp == NULL)
97                 return;
98
99         if (rp->lnext != NULL) {
100                 room_tree_list(rp->lnext);
101         }
102         strcpy(rmname, rp->rlname);
103         f = rp->rlflags;
104
105         wprintf("<A HREF=\"/dotgoto&room=");
106         urlescputs(rmname);
107         wprintf("\"");
108         wprintf(">");
109         escputs1(rmname, 1);
110         if ((f & QR_DIRECTORY) && (f & QR_NETWORK))
111                 wprintf("}");
112         else if (f & QR_DIRECTORY)
113                 wprintf("]");
114         else if (f & QR_NETWORK)
115                 wprintf(")");
116         else
117                 wprintf("&gt;");
118         wprintf("</A><TT> </TT>\n");
119
120         if (rp->rnext != NULL) {
121                 room_tree_list(rp->rnext);
122         }
123         free(rp);
124 }
125
126
127 /* 
128  * Room ordering stuff (compare first by floor, then by order)
129  */
130 int rordercmp(struct roomlisting *r1, struct roomlisting *r2)
131 {
132         if ((r1 == NULL) && (r2 == NULL))
133                 return (0);
134         if (r1 == NULL)
135                 return (-1);
136         if (r2 == NULL)
137                 return (1);
138         if (r1->rlfloor < r2->rlfloor)
139                 return (-1);
140         if (r1->rlfloor > r2->rlfloor)
141                 return (1);
142         if (r1->rlorder < r2->rlorder)
143                 return (-1);
144         if (r1->rlorder > r2->rlorder)
145                 return (1);
146         return (0);
147 }
148
149
150 /*
151  * Common code for all room listings
152  */
153 void listrms(char *variety)
154 {
155         char buf[SIZ];
156         int num_rooms = 0;
157
158         struct roomlisting *rl = NULL;
159         struct roomlisting *rp;
160         struct roomlisting *rs;
161
162
163         /* Ask the server for a room list */
164         serv_puts(variety);
165         serv_gets(buf);
166         if (buf[0] != '1') {
167                 wprintf("&nbsp;");
168                 return;
169         }
170         while (serv_gets(buf), strcmp(buf, "000")) {
171                 ++num_rooms;
172                 rp = malloc(sizeof(struct roomlisting));
173                 extract(rp->rlname, buf, 0);
174                 rp->rlflags = extract_int(buf, 1);
175                 rp->rlfloor = extract_int(buf, 2);
176                 rp->rlorder = extract_int(buf, 3);
177                 rp->lnext = NULL;
178                 rp->rnext = NULL;
179
180                 rs = rl;
181                 if (rl == NULL) {
182                         rl = rp;
183                 } else
184                         while (rp != NULL) {
185                                 if (rordercmp(rp, rs) < 0) {
186                                         if (rs->lnext == NULL) {
187                                                 rs->lnext = rp;
188                                                 rp = NULL;
189                                         } else {
190                                                 rs = rs->lnext;
191                                         }
192                                 } else {
193                                         if (rs->rnext == NULL) {
194                                                 rs->rnext = rp;
195                                                 rp = NULL;
196                                         } else {
197                                                 rs = rs->rnext;
198                                         }
199                                 }
200                         }
201         }
202
203         room_tree_list(rl);
204
205         /* If no rooms were listed, print an nbsp to make the cell
206          * borders show up anyway.
207          */
208         if (num_rooms == 0) wprintf("&nbsp;");
209 }
210
211
212
213
214
215
216
217
218
219 /*
220  * list all rooms by floor (only should get called from knrooms() because
221  * that's where output_headers() is called from)
222  */
223 void list_all_rooms_by_floor(void)
224 {
225         int a;
226         char buf[SIZ];
227
228         wprintf("<TABLE width=100%% border><TR><TH>Floor</TH>");
229         wprintf("<TH>Rooms with new messages</TH>");
230         wprintf("<TH>Rooms with no new messages</TH></TR>\n");
231
232         for (a = 0; a < 128; ++a)
233                 if (floorlist[a][0] != 0) {
234
235                         /* Floor name column */
236                         wprintf("<TR><TD>");
237
238                         serv_printf("OIMG _floorpic_|%d", a);
239                         serv_gets(buf);
240                         if (buf[0] == '2') {
241                                 serv_puts("CLOS");
242                                 serv_gets(buf);
243                                 wprintf("<IMG SRC=\"/image&name=_floorpic_&parm=%d\" ALT=\"%s\">",
244                                         a, &floorlist[a][0]);
245                         } else {
246                                 escputs(&floorlist[a][0]);
247                         }
248
249                         wprintf("</TD>");
250
251                         /* Rooms with new messages column */
252                         wprintf("<TD>");
253                         sprintf(buf, "LKRN %d", a);
254                         listrms(buf);
255                         wprintf("</TD>\n<TD>");
256
257                         /* Rooms with old messages column */
258                         sprintf(buf, "LKRO %d", a);
259                         listrms(buf);
260                         wprintf("</TD></TR>\n");
261                 }
262         wprintf("</TABLE>\n");
263         wDumpContent(1);
264 }
265
266
267 /*
268  * list all forgotten rooms
269  */
270 void zapped_list(void)
271 {
272         output_headers(1);
273         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
274         wprintf("<SPAN CLASS=\"titlebar\">Zapped (forgotten) rooms</SPAN>\n");
275         wprintf("</TD></TR></TABLE><BR>\n");
276         listrms("LZRM -1");
277         wprintf("<BR><BR>\n");
278         wprintf("Click on any room to un-zap it and goto that room.\n");
279         wDumpContent(1);
280 }
281
282
283 /*
284  * read this room's info file (set v to 1 for verbose mode)
285  */
286 void readinfo(void)
287 {
288         char buf[SIZ];
289
290         serv_puts("RINF");
291         serv_gets(buf);
292         if (buf[0] == '1') {
293                 fmout(NULL);
294         }
295 }
296
297
298
299
300 /* Display room graphic.  The server doesn't actually
301  * need the room name, but we supply it in order to
302  * keep the browser from using a cached graphic from 
303  * another room.
304  */
305 void embed_room_graphic(void) {
306         char buf[SIZ];
307
308         serv_puts("OIMG _roompic_");
309         serv_gets(buf);
310         if (buf[0] == '2') {
311                 wprintf("<TD BGCOLOR=\"#444455\">");
312                 wprintf("<IMG SRC=\"/image&name=_roompic_&room=");
313                 urlescputs(WC->wc_roomname);
314                 wprintf("\"></TD>");
315                 serv_puts("CLOS");
316                 serv_gets(buf);
317         }
318
319 }
320
321
322 /* Let the user know if new mail has arrived 
323  */
324 void embed_newmail_button(void) {
325         if ( (WC->new_mail > WC->remember_new_mail) && (WC->new_mail>0) ) {
326                 wprintf(
327                         "<A HREF=\"/dotgoto?room=_MAIL_\">"
328                         "<IMG SRC=\"/static/mail.gif\" border=0 "
329                         "ALT=\"You have new mail\">"
330                         "<BR><SPAN CLASS=\"youhavemail\">"
331                         "%d new mail</SPAN></A>", WC->new_mail);
332                 WC->remember_new_mail = WC->new_mail;
333         }
334 }
335
336
337
338 /*
339  * Display the current view and offer an option to change it
340  */
341 void embed_view_o_matic(void) {
342         int i;
343
344         wprintf("<FORM NAME=\"viewomatic\">\n"
345                 "<SELECT NAME=\"newview\" SIZE=\"1\" "
346                 "OnChange=\"location.href=viewomatic.newview.options"
347                 "[selectedIndex].value\">\n");
348
349         for (i=0; i<(sizeof viewdefs / sizeof (char *)); ++i) {
350                 /*
351                  * Only offer the views that make sense, given the default
352                  * view for the room.  For example, don't offer a Calendar
353                  * view in a non-Calendar room.
354                  */
355                 if (
356                         (i == WC->wc_view)
357                    ||   (i == WC->wc_default_view)
358                    ||   ( (i == 0) && (WC->wc_default_view == 1) )
359                    ||   ( (i == 1) && (WC->wc_default_view == 0) )
360                 ) {
361
362                         wprintf("<OPTION %s VALUE=\"/changeview?view=%d\">",
363                                 ((i == WC->wc_view) ? "SELECTED" : ""),
364                                 i );
365                         escputs(viewdefs[i]);
366                         wprintf("</OPTION>\n");
367                 }
368         }
369         wprintf("</SELECT></FORM>\n");
370 }
371
372
373
374 void embed_room_banner(char *got) {
375         char fakegot[SIZ];
376
377         /* We need to have the information returned by a GOTO server command.
378          * If it isn't supplied, we fake it by issuing our own GOTO.
379          */
380         if (got == NULL) {
381                 serv_printf("GOTO %s", WC->wc_roomname);
382                 serv_gets(fakegot);
383                 got = fakegot;
384         }
385
386         /* If the user happens to select the "make this my start page" link,
387          * we want it to remember the URL as a "/dotskip" one instead of
388          * a "skip" or "gotonext" or something like that.
389          */
390         snprintf(WC->this_page, sizeof(WC->this_page), "/dotskip&room=%s",
391                 WC->wc_roomname);
392
393         /* Check for new mail. */
394         WC->new_mail = extract_int(&got[4], 9);
395         WC->wc_view = extract_int(&got[4], 11);
396
397         svprintf("ROOMNAME", WCS_STRING, "%s", WC->wc_roomname);
398         svprintf("NEWMSGS", WCS_STRING, "%d", extract_int(&got[4], 1));
399         svprintf("TOTALMSGS", WCS_STRING, "%d", extract_int(&got[4], 2));
400         svcallback("ROOMPIC", embed_room_graphic);
401         svcallback("ROOMINFO", readinfo);
402         svcallback("YOUHAVEMAIL", embed_newmail_button);
403         svcallback("VIEWOMATIC", embed_view_o_matic);
404         svcallback("START", offer_start_page);
405
406         do_template("roombanner");
407         clear_local_substs();
408 }
409
410
411
412
413
414 /*
415  * generic routine to take the session to a new room
416  *
417  * display_name values:  0 = goto only
418  *                       1 = goto and display
419  *                       2 = display only
420  */
421 void gotoroom(char *gname, int display_name)
422 {
423         char buf[SIZ];
424         static long ls = (-1L);
425
426
427         if (display_name) {
428                 output_headers(0);
429                 wprintf("Pragma: no-cache\n");
430                 wprintf("Cache-Control: no-store\n");
431
432                 wprintf("<HTML><HEAD>\n"
433                         "<META HTTP-EQUIV=\"refresh\" CONTENT=\"500363689;\">\n"
434                         "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n"
435                         "<META HTTP-EQUIV=\"expired\" CONTENT=\"28-May-1971 18:10:00 GMT\">\n"
436                         "<meta name=\"MSSmartTagsPreventParsing\" content=\"TRUE\">\n"
437                         "</HEAD>\n");
438                 do_template("background");
439         }
440         if (display_name != 2) {
441                 /* store ungoto information */
442                 strcpy(WC->ugname, WC->wc_roomname);
443                 WC->uglsn = ls;
444         }
445         /* move to the new room */
446         serv_printf("GOTO %s", gname);
447         serv_gets(buf);
448         if (buf[0] != '2') {
449                 serv_puts("GOTO _BASEROOM_");
450                 serv_gets(buf);
451         }
452         if (buf[0] != '2') {
453                 if (display_name) {
454                         wprintf("<EM>%s</EM><BR>\n", &buf[4]);
455                         wDumpContent(1);
456                 }
457                 return;
458         }
459         extract(WC->wc_roomname, &buf[4], 0);
460         WC->room_flags = extract_int(&buf[4], 4);
461         /* highest_msg_read = extract_int(&buf[4],6);
462            maxmsgnum = extract_int(&buf[4],5);
463            is_mail = (char) extract_int(&buf[4],7); */
464         ls = extract_long(&buf[4], 6);
465
466         if (WC->is_aide)
467                 WC->is_room_aide = WC->is_aide;
468         else
469                 WC->is_room_aide = (char) extract_int(&buf[4], 8);
470
471         remove_march(WC->wc_roomname);
472         if (!strcasecmp(gname, "_BASEROOM_"))
473                 remove_march(gname);
474
475         /* Display the room banner */
476         if (display_name) {
477                 embed_room_banner(buf);
478                 wDumpContent(1);
479         }
480         strcpy(WC->wc_roomname, WC->wc_roomname);
481         WC->wc_view = extract_int(&buf[4], 11);
482         WC->wc_default_view = extract_int(&buf[4], 12);
483 }
484
485
486 /*
487  * Locate the room on the march list which we most want to go to.  Each room
488  * is measured given a "weight" of preference based on various factors.
489  */
490 char *pop_march(int desired_floor)
491 {
492         static char TheRoom[128];
493         int TheFloor = 0;
494         int TheOrder = 32767;
495         int TheWeight = 0;
496         int weight;
497         struct march *mptr = NULL;
498
499         strcpy(TheRoom, "_BASEROOM_");
500         if (WC->march == NULL)
501                 return (TheRoom);
502
503         for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
504                 weight = 0;
505                 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
506                         weight = weight + 10000;
507                 if (mptr->march_floor == desired_floor)
508                         weight = weight + 5000;
509
510                 weight = weight + ((128 - (mptr->march_floor)) * 128);
511                 weight = weight + (128 - (mptr->march_order));
512
513                 if (weight > TheWeight) {
514                         TheWeight = weight;
515                         strcpy(TheRoom, mptr->march_name);
516                         TheFloor = mptr->march_floor;
517                         TheOrder = mptr->march_order;
518                 }
519         }
520         return (TheRoom);
521 }
522
523
524
525 /* Goto next room having unread messages.
526  * We want to skip over rooms that the user has already been to, and take the
527  * user back to the lobby when done.  The room we end up in is placed in
528  * newroom - which is set to 0 (the lobby) initially.
529  * We start the search in the current room rather than the beginning to prevent
530  * two or more concurrent users from dragging each other back to the same room.
531  */
532 void gotonext(void)
533 {
534         char buf[SIZ];
535         struct march *mptr, *mptr2;
536         char next_room[128];
537
538         /* First check to see if the march-mode list is already allocated.
539          * If it is, pop the first room off the list and go there.
540          */
541
542         if (WC->march == NULL) {
543                 serv_puts("LKRN");
544                 serv_gets(buf);
545                 if (buf[0] == '1')
546                         while (serv_gets(buf), strcmp(buf, "000")) {
547                                 mptr = (struct march *) malloc(sizeof(struct march));
548                                 mptr->next = NULL;
549                                 extract(mptr->march_name, buf, 0);
550                                 mptr->march_floor = extract_int(buf, 2);
551                                 mptr->march_order = extract_int(buf, 3);
552                                 if (WC->march == NULL) {
553                                         WC->march = mptr;
554                                 } else {
555                                         mptr2 = WC->march;
556                                         while (mptr2->next != NULL)
557                                                 mptr2 = mptr2->next;
558                                         mptr2->next = mptr;
559                                 }
560                         }
561 /* add _BASEROOM_ to the end of the march list, so the user will end up
562  * in the system base room (usually the Lobby>) at the end of the loop
563  */
564                 mptr = (struct march *) malloc(sizeof(struct march));
565                 mptr->next = NULL;
566                 strcpy(mptr->march_name, "_BASEROOM_");
567                 if (WC->march == NULL) {
568                         WC->march = mptr;
569                 } else {
570                         mptr2 = WC->march;
571                         while (mptr2->next != NULL)
572                                 mptr2 = mptr2->next;
573                         mptr2->next = mptr;
574                 }
575 /*
576  * ...and remove the room we're currently in, so a <G>oto doesn't make us
577  * walk around in circles
578  */
579                 remove_march(WC->wc_roomname);
580         }
581         if (WC->march != NULL) {
582                 strcpy(next_room, pop_march(-1));
583         } else {
584                 strcpy(next_room, "_BASEROOM_");
585         }
586
587
588         smart_goto(next_room);
589 }
590
591
592 void smart_goto(char *next_room) {
593         gotoroom(next_room, 0);
594         readloop("readnew");
595 }
596
597
598
599 /*
600  * mark all messages in current room as having been read
601  */
602 void slrp_highest(void)
603 {
604         char buf[SIZ];
605
606         /* set pointer */
607         serv_puts("SLRP HIGHEST");
608         serv_gets(buf);
609         if (buf[0] != '2') {
610                 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
611                 return;
612         }
613 }
614
615
616 /*
617  * un-goto the previous room
618  */
619 void ungoto(void)
620 {
621         char buf[SIZ];
622
623         if (!strcmp(WC->ugname, "")) {
624                 smart_goto(WC->wc_roomname);
625                 return;
626         }
627         serv_printf("GOTO %s", WC->ugname);
628         serv_gets(buf);
629         if (buf[0] != '2') {
630                 smart_goto(WC->wc_roomname);
631                 return;
632         }
633         if (WC->uglsn >= 0L) {
634                 serv_printf("SLRP %ld", WC->uglsn);
635                 serv_gets(buf);
636         }
637         strcpy(buf, WC->ugname);
638         strcpy(WC->ugname, "");
639         smart_goto(buf);
640 }
641
642
643
644
645
646 /*
647  * Set/clear/read the "self-service list subscribe" flag for a room
648  * 
649  * Set 'newval' to 0 to clear, 1 to set, any other value to leave unchanged.
650  * Always returns the new value.
651  */
652
653 int self_service(int newval) {
654         int current_value = 0;
655         char buf[SIZ];
656         
657         char name[SIZ];
658         char password[SIZ];
659         char dirname[SIZ];
660         int flags, floor, order, view, flags2;
661
662         serv_puts("GETR");
663         serv_gets(buf);
664         if (buf[0] != '2') return(0);
665
666         extract(name, &buf[4], 0);
667         extract(password, &buf[4], 1);
668         extract(dirname, &buf[4], 2);
669         flags = extract_int(&buf[4], 3);
670         floor = extract_int(&buf[4], 4);
671         order = extract_int(&buf[4], 5);
672         view = extract_int(&buf[4], 6);
673         flags2 = extract_int(&buf[4], 7);
674
675         if (flags2 & QR2_SELFLIST) {
676                 current_value = 1;
677         }
678         else {
679                 current_value = 0;
680         }
681
682         if (newval == 1) {
683                 flags2 = flags2 | QR2_SELFLIST;
684         }
685         else if (newval == 0) {
686                 flags2 = flags2 & ~QR2_SELFLIST;
687         }
688         else {
689                 return(current_value);
690         }
691
692         if (newval != current_value) {
693                 serv_printf("SETR %s|%s|%s|%d|0|%d|%d|%d|%d",
694                         name, password, dirname, flags,
695                         floor, order, view, flags2);
696                 serv_gets(buf);
697         }
698
699         return(newval);
700
701 }
702
703
704
705
706
707
708 /*
709  * display the form for editing a room
710  */
711 void display_editroom(void)
712 {
713         char buf[SIZ];
714         char cmd[SIZ];
715         char node[SIZ];
716         char recp[SIZ];
717         char er_name[20];
718         char er_password[10];
719         char er_dirname[15];
720         char er_roomaide[26];
721         unsigned er_flags;
722         int er_floor;
723         int i, j;
724         char *tab;
725         char *shared_with;
726         char *not_shared_with;
727
728         tab = bstr("tab");
729         if (strlen(tab) == 0) tab = "admin";
730
731         serv_puts("GETR");
732         serv_gets(buf);
733
734         if (buf[0] != '2') {
735                 display_error(&buf[4]);
736                 return;
737         }
738         extract(er_name, &buf[4], 0);
739         extract(er_password, &buf[4], 1);
740         extract(er_dirname, &buf[4], 2);
741         er_flags = extract_int(&buf[4], 3);
742         er_floor = extract_int(&buf[4], 4);
743
744         output_headers(1);
745
746         /* print the tabbed dialog */
747         wprintf("<TABLE border=0 cellspacing=0 cellpadding=0 width=100%%>"
748                 "<TR ALIGN=CENTER BGCOLOR=\"#FFFFFF\">"
749                 "<TD>&nbsp;</TD>\n");
750
751         if (!strcmp(tab, "admin")) {
752                 wprintf("<TD BGCOLOR=\"#000077\"><SPAN CLASS=\"tablabel\">");
753         }
754         else {
755                 wprintf("<TD BGCOLOR=\"#AAAAAA\"><A HREF=\"/display_editroom&tab=admin\">");
756         }
757         wprintf("Room administration");
758         if (!strcmp(tab, "admin")) {
759                 wprintf("</SPAN></TD>\n");
760         }
761         else {
762                 wprintf("</A></TD>\n");
763         }
764
765         wprintf("<TD>&nbsp;</TD>\n");
766
767         if (!strcmp(tab, "config")) {
768                 wprintf("<TD BGCOLOR=\"#000077\"><SPAN CLASS=\"tablabel\">");
769         }
770         else {
771                 wprintf("<TD BGCOLOR=\"#AAAAAA\"><A HREF=\"/display_editroom&tab=config\">");
772         }
773         wprintf("Room configuration");
774         if (!strcmp(tab, "config")) {
775                 wprintf("</SPAN></TD>\n");
776         }
777         else {
778                 wprintf("</A></TD>\n");
779         }
780
781         wprintf("<TD>&nbsp;</TD>\n");
782
783         if (!strcmp(tab, "sharing")) {
784                 wprintf("<TD BGCOLOR=\"#000077\"><SPAN CLASS=\"tablabel\">");
785         }
786         else {
787                 wprintf("<TD BGCOLOR=\"#AAAAAA\"><A HREF=\"/display_editroom&tab=sharing\">");
788         }
789         wprintf("Sharing");
790         if (!strcmp(tab, "sharing")) {
791                 wprintf("</SPAN></TD>\n");
792         }
793         else {
794                 wprintf("</A></TD>\n");
795         }
796
797         wprintf("<TD>&nbsp;</TD>\n");
798
799         if (!strcmp(tab, "listserv")) {
800                 wprintf("<TD BGCOLOR=\"#000077\"><SPAN CLASS=\"tablabel\">");
801         }
802         else {
803                 wprintf("<TD BGCOLOR=\"#AAAAAA\"><A HREF=\"/display_editroom&tab=listserv\">");
804         }
805         wprintf("Mailing list service");
806         if (!strcmp(tab, "listserv")) {
807                 wprintf("</SPAN></TD>\n");
808         }
809         else {
810                 wprintf("</A></TD>\n");
811         }
812
813         wprintf("<TD>&nbsp;</TD></TR>"
814                 "<TR><TD BGCOLOR=\"#000077\" COLSPAN=9 HEIGHT=5> </TD></TR>"
815                 "</TABLE>\n");
816
817         /* end tabbed dialog */ 
818
819
820         if (!strcmp(tab, "admin")) {
821                 wprintf("<UL>"
822                         "<LI><A HREF=\"/confirm_delete_room\">\n"
823                         "Delete this room</A>\n"
824                         "<LI><A HREF=\"/display_editroompic\">\n"
825                         "Set or change the graphic for this room's banner</A>\n"
826                         "<LI><A HREF=\"/display_editinfo\">\n"
827                         "Edit this room's Info file</A>\n"
828                         "</UL>");
829         }
830
831         if (!strcmp(tab, "config")) {
832                 wprintf("<FORM METHOD=\"POST\" ACTION=\"/editroom\">\n");
833         
834                 wprintf("<UL><LI>Name of room: ");
835                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", er_name);
836         
837                 wprintf("<LI>Resides on floor: ");
838                 load_floorlist();
839                 wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
840                 for (i = 0; i < 128; ++i)
841                         if (strlen(floorlist[i]) > 0) {
842                                 wprintf("<OPTION ");
843                                 if (i == er_floor)
844                                         wprintf("SELECTED ");
845                                 wprintf("VALUE=\"%d\">", i);
846                                 escputs(floorlist[i]);
847                                 wprintf("</OPTION>\n");
848                         }
849                 wprintf("</SELECT>\n");
850         
851                 wprintf("<LI>Type of room:<UL>\n");
852
853                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
854                 if ((er_flags & QR_PRIVATE) == 0)
855                 wprintf("CHECKED ");
856                 wprintf("> Public room\n");
857
858                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
859                 if ((er_flags & QR_PRIVATE) &&
860                     (er_flags & QR_GUESSNAME))
861                         wprintf("CHECKED ");
862                 wprintf("> Private - guess name\n");
863         
864                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
865                 if ((er_flags & QR_PRIVATE) &&
866                     (er_flags & QR_PASSWORDED))
867                         wprintf("CHECKED ");
868                 wprintf("> Private - require password:\n");
869                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" VALUE=\"%s\" MAXLENGTH=\"9\">\n", er_password);
870         
871                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
872                 if ((er_flags & QR_PRIVATE)
873                     && ((er_flags & QR_GUESSNAME) == 0)
874                     && ((er_flags & QR_PASSWORDED) == 0))
875                         wprintf("CHECKED ");
876                 wprintf("> Private - invitation only\n");
877         
878                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"bump\" VALUE=\"yes\" ");
879                 wprintf("> If private, cause current users to forget room\n");
880         
881                 wprintf("</UL>\n");
882         
883                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"prefonly\" VALUE=\"yes\" ");
884                 if (er_flags & QR_PREFONLY)
885                         wprintf("CHECKED ");
886                 wprintf("> Preferred users only\n");
887         
888                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"readonly\" VALUE=\"yes\" ");
889                 if (er_flags & QR_READONLY)
890                         wprintf("CHECKED ");
891                 wprintf("> Read-only room\n");
892         
893         /* directory stuff */
894                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"directory\" VALUE=\"yes\" ");
895                 if (er_flags & QR_DIRECTORY)
896                         wprintf("CHECKED ");
897                 wprintf("> File directory room\n");
898
899                 wprintf("<UL><LI>Directory name: ");
900                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_dirname\" VALUE=\"%s\" MAXLENGTH=\"14\">\n", er_dirname);
901
902                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"ulallowed\" VALUE=\"yes\" ");
903                 if (er_flags & QR_UPLOAD)
904                         wprintf("CHECKED ");
905                 wprintf("> Uploading allowed\n");
906         
907                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"dlallowed\" VALUE=\"yes\" ");
908                 if (er_flags & QR_DOWNLOAD)
909                         wprintf("CHECKED ");
910                 wprintf("> Downloading allowed\n");
911         
912                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"visdir\" VALUE=\"yes\" ");
913                 if (er_flags & QR_VISDIR)
914                         wprintf("CHECKED ");
915                 wprintf("> Visible directory</UL>\n");
916         
917         /* end of directory stuff */
918         
919                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"network\" VALUE=\"yes\" ");
920                 if (er_flags & QR_NETWORK)
921                         wprintf("CHECKED ");
922                 wprintf("> Network shared room\n");
923
924         /* start of anon options */
925         
926                 wprintf("<LI>Anonymous messages<UL>\n");
927         
928                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"no\" ");
929                 if (((er_flags & QR_ANONONLY) == 0)
930                     && ((er_flags & QR_ANONOPT) == 0))
931                         wprintf("CHECKED ");
932                 wprintf("> No anonymous messages\n");
933         
934                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anononly\" ");
935                 if (er_flags & QR_ANONONLY)
936                         wprintf("CHECKED ");
937                 wprintf("> All messages are anonymous\n");
938         
939                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anon2\" ");
940                 if (er_flags & QR_ANONOPT)
941                         wprintf("CHECKED ");
942                 wprintf("> Prompt user when entering messages</UL>\n");
943         
944         /* end of anon options */
945         
946                 wprintf("<LI>Room aide: \n");
947                 serv_puts("GETA");
948                 serv_gets(buf);
949                 if (buf[0] != '2') {
950                         wprintf("<EM>%s</EM>\n", &buf[4]);
951                 } else {
952                         extract(er_roomaide, &buf[4], 0);
953                         wprintf("<INPUT TYPE=\"text\" NAME=\"er_roomaide\" VALUE=\"%s\" MAXLENGTH=\"25\">\n", er_roomaide);
954                 }
955         
956                 wprintf("</UL><CENTER>\n");
957                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
958                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
959                 wprintf("</CENTER>\n");
960         }
961
962
963         /* Sharing the room with other Citadel nodes... */
964         if (!strcmp(tab, "sharing")) {
965
966                 shared_with = strdup("");
967                 not_shared_with = strdup("");
968
969                 /* Learn the current configuration */
970                 serv_puts("CONF getsys|application/x-citadel-ignet-config");
971                 serv_gets(buf);
972                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
973                         extract(node, buf, 0);
974                         not_shared_with = realloc(not_shared_with,
975                                         strlen(not_shared_with) + 32);
976                         strcat(not_shared_with, node);
977                         strcat(not_shared_with, "|");
978                 }
979
980                 serv_puts("GNET");
981                 serv_gets(buf);
982                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
983                         extract(cmd, buf, 0);
984                         extract(node, buf, 1);
985                         if (!strcasecmp(cmd, "ignet_push_share")) {
986                                 shared_with = realloc(shared_with,
987                                                 strlen(shared_with) + 32);
988                                 strcat(shared_with, node);
989                                 strcat(shared_with, "|");
990                         }
991                 }
992
993                 for (i=0; i<num_tokens(shared_with, '|'); ++i) {
994                         extract(node, shared_with, i);
995                         for (j=0; j<num_tokens(not_shared_with, '|'); ++j) {
996                                 extract(cmd, not_shared_with, j);
997                                 if (!strcasecmp(node, cmd)) {
998                                         remove_token(not_shared_with, j, '|');
999                                 }
1000                         }
1001                 }
1002
1003                 /* Display the stuff */
1004                 wprintf("<CENTER><BR>"
1005                         "<TABLE border=1 cellpadding=5><TR>"
1006                         "<TD><B><I>Shared with</I></B></TD>"
1007                         "<TD><B><I>Not shared with</I></B></TD></TR>\n"
1008                         "<TR><TD>\n");
1009
1010                 for (i=0; i<num_tokens(shared_with, '|'); ++i) {
1011                         extract(node, shared_with, i);
1012                         if (strlen(node) > 0) {
1013                                 wprintf("%s ", node);
1014                                 wprintf("<A HREF=\"/netedit&cmd=remove&line="
1015                                         "ignet_push_share|");
1016                                 urlescputs(node);
1017                                 wprintf("&tab=sharing\">(unshare)</A><BR>");
1018                         }
1019                 }
1020
1021                 wprintf("</TD><TD>\n");
1022
1023                 for (i=0; i<num_tokens(not_shared_with, '|'); ++i) {
1024                         extract(node, not_shared_with, i);
1025                         if (strlen(node) > 0) {
1026                                 wprintf("%s ", node);
1027                                 wprintf("<A HREF=\"/netedit&cmd=add&line="
1028                                         "ignet_push_share|");
1029                                 urlescputs(node);
1030                                 wprintf("&tab=sharing\">(share)</A><BR>");
1031                         }
1032                 }
1033
1034                 wprintf("</TD></TR>"
1035                         "</TABLE><BR>\n"
1036                         "<I><B>Reminder:</B> When sharing a room, "
1037                         "it must be shared from both ends.  Adding a node to "
1038                         "the 'shared' list sends messages out, but in order to"
1039                         " receive messages, the other nodes must be configured"
1040                         " to send messages out to your system as well.</I><BR>"
1041                         "</CENTER>\n");
1042
1043         }
1044
1045         /* Mailing list management */
1046         if (!strcmp(tab, "listserv")) {
1047
1048                 wprintf("<BR><center>"
1049                         "<TABLE BORDER=0 WIDTH=100%% CELLPADDING=5>"
1050                         "<TR><TD VALIGN=TOP>");
1051
1052                 wprintf("<i>The contents of this room are being "
1053                         "mailed <b>as individual messages</b> "
1054                         "to the following list recipients:"
1055                         "</i><br><br>\n");
1056
1057                 serv_puts("GNET");
1058                 serv_gets(buf);
1059                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
1060                         extract(cmd, buf, 0);
1061                         if (!strcasecmp(cmd, "listrecp")) {
1062                                 extract(recp, buf, 1);
1063                         
1064                                 escputs(recp);
1065                                 wprintf(" <A HREF=\"/netedit&cmd=remove&line="
1066                                         "listrecp|");
1067                                 urlescputs(recp);
1068                                 wprintf("&tab=listserv\">(remove)</A><BR>");
1069
1070                         }
1071                 }
1072                 wprintf("<BR><FORM METHOD=\"POST\" ACTION=\"/netedit\">\n"
1073                         "<INPUT TYPE=\"hidden\" NAME=\"tab\" VALUE=\"listserv\">\n"
1074                         "<INPUT TYPE=\"hidden\" NAME=\"prefix\" VALUE=\"listrecp|\">\n");
1075                 wprintf("<INPUT TYPE=\"text\" NAME=\"line\">\n");
1076                 wprintf("<INPUT TYPE=\"submit\" NAME=\"cmd\" VALUE=\"Add\">");
1077                 wprintf("</FORM>\n");
1078
1079                 wprintf("</TD><TD VALIGN=TOP>\n");
1080                 
1081                 wprintf("<i>The contents of this room are being "
1082                         "mailed <b>in digest form</b> "
1083                         "to the following list recipients:"
1084                         "</i><br><br>\n");
1085
1086                 serv_puts("GNET");
1087                 serv_gets(buf);
1088                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
1089                         extract(cmd, buf, 0);
1090                         if (!strcasecmp(cmd, "digestrecp")) {
1091                                 extract(recp, buf, 1);
1092                         
1093                                 escputs(recp);
1094                                 wprintf(" <A HREF=\"/netedit&cmd=remove&line="
1095                                         "digestrecp|");
1096                                 urlescputs(recp);
1097                                 wprintf("&tab=listserv\">(remove)</A><BR>");
1098
1099                         }
1100                 }
1101                 wprintf("<BR><FORM METHOD=\"POST\" ACTION=\"/netedit\">\n"
1102                         "<INPUT TYPE=\"hidden\" NAME=\"tab\" VALUE=\"listserv\">\n"
1103                         "<INPUT TYPE=\"hidden\" NAME=\"prefix\" VALUE=\"digestrecp|\">\n");
1104                 wprintf("<INPUT TYPE=\"text\" NAME=\"line\">\n");
1105                 wprintf("<INPUT TYPE=\"submit\" NAME=\"cmd\" VALUE=\"Add\">");
1106                 wprintf("</FORM>\n");
1107                 
1108                 wprintf("</TD></TR></TABLE><HR>\n");
1109
1110                 if (self_service(999) == 1) {
1111                         wprintf("This room is configured to allow "
1112                                 "self-service subscribe/unsubscribe requests."
1113                                 " <A HREF=\"/toggle_self_service?newval=0&"
1114                                 "tab=listserv\">"
1115                                 "Click to disable.</A><BR>\n"
1116                                 "The URL for subscribe/unsubscribe is: "
1117                                 "<TT>http://%s/listsub</TT><BR>\n",
1118                                 WC->http_host
1119                         );
1120                 }
1121                 else {
1122                         wprintf("This room is <i>not</i> configured to allow "
1123                                 "self-service subscribe/unsubscribe requests."
1124                                 " <A HREF=\"/toggle_self_service?newval=1&"
1125                                 "tab=listserv\">"
1126                                 "Click to enable.</A><BR>\n"
1127                         );
1128                 }
1129
1130
1131                 wprintf("</CENTER>\n");
1132         }
1133
1134         wDumpContent(1);
1135 }
1136
1137
1138 /* 
1139  * Toggle self-service list subscription
1140  */
1141 void toggle_self_service(void) {
1142         int newval = 0;
1143
1144         newval = atoi(bstr("newval"));
1145         self_service(newval);
1146         display_editroom();
1147 }
1148
1149
1150
1151 /*
1152  * save new parameters for a room
1153  */
1154 void editroom(void)
1155 {
1156         char buf[SIZ];
1157         char er_name[20];
1158         char er_password[10];
1159         char er_dirname[15];
1160         char er_roomaide[26];
1161         int er_floor;
1162         unsigned er_flags;
1163         int bump;
1164
1165
1166         if (strcmp(bstr("sc"), "OK")) {
1167                 display_error("Cancelled.  Changes were not saved.");
1168                 return;
1169         }
1170         serv_puts("GETR");
1171         serv_gets(buf);
1172
1173         if (buf[0] != '2') {
1174                 display_error(&buf[4]);
1175                 return;
1176         }
1177         extract(er_name, &buf[4], 0);
1178         extract(er_password, &buf[4], 1);
1179         extract(er_dirname, &buf[4], 2);
1180         er_flags = extract_int(&buf[4], 3);
1181
1182         strcpy(er_roomaide, bstr("er_roomaide"));
1183         if (strlen(er_roomaide) == 0) {
1184                 serv_puts("GETA");
1185                 serv_gets(buf);
1186                 if (buf[0] != '2') {
1187                         strcpy(er_roomaide, "");
1188                 } else {
1189                         extract(er_roomaide, &buf[4], 0);
1190                 }
1191         }
1192         strcpy(buf, bstr("er_name"));
1193         buf[20] = 0;
1194         if (strlen(buf) > 0)
1195                 strcpy(er_name, buf);
1196
1197         strcpy(buf, bstr("er_password"));
1198         buf[10] = 0;
1199         if (strlen(buf) > 0)
1200                 strcpy(er_password, buf);
1201
1202         strcpy(buf, bstr("er_dirname"));
1203         buf[15] = 0;
1204         if (strlen(buf) > 0)
1205                 strcpy(er_dirname, buf);
1206
1207         strcpy(buf, bstr("type"));
1208         er_flags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
1209
1210         if (!strcmp(buf, "invonly")) {
1211                 er_flags |= (QR_PRIVATE);
1212         }
1213         if (!strcmp(buf, "guessname")) {
1214                 er_flags |= (QR_PRIVATE | QR_GUESSNAME);
1215         }
1216         if (!strcmp(buf, "passworded")) {
1217                 er_flags |= (QR_PRIVATE | QR_PASSWORDED);
1218         }
1219         if (!strcmp(bstr("prefonly"), "yes")) {
1220                 er_flags |= QR_PREFONLY;
1221         } else {
1222                 er_flags &= ~QR_PREFONLY;
1223         }
1224
1225         if (!strcmp(bstr("readonly"), "yes")) {
1226                 er_flags |= QR_READONLY;
1227         } else {
1228                 er_flags &= ~QR_READONLY;
1229         }
1230
1231         if (!strcmp(bstr("network"), "yes")) {
1232                 er_flags |= QR_NETWORK;
1233         } else {
1234                 er_flags &= ~QR_NETWORK;
1235         }
1236
1237         if (!strcmp(bstr("directory"), "yes")) {
1238                 er_flags |= QR_DIRECTORY;
1239         } else {
1240                 er_flags &= ~QR_DIRECTORY;
1241         }
1242
1243         if (!strcmp(bstr("ulallowed"), "yes")) {
1244                 er_flags |= QR_UPLOAD;
1245         } else {
1246                 er_flags &= ~QR_UPLOAD;
1247         }
1248
1249         if (!strcmp(bstr("dlallowed"), "yes")) {
1250                 er_flags |= QR_DOWNLOAD;
1251         } else {
1252                 er_flags &= ~QR_DOWNLOAD;
1253         }
1254
1255         if (!strcmp(bstr("visdir"), "yes")) {
1256                 er_flags |= QR_VISDIR;
1257         } else {
1258                 er_flags &= ~QR_VISDIR;
1259         }
1260
1261         strcpy(buf, bstr("anon"));
1262
1263         er_flags &= ~(QR_ANONONLY | QR_ANONOPT);
1264         if (!strcmp(buf, "anononly"))
1265                 er_flags |= QR_ANONONLY;
1266         if (!strcmp(buf, "anon2"))
1267                 er_flags |= QR_ANONOPT;
1268
1269         bump = 0;
1270         if (!strcmp(bstr("bump"), "yes"))
1271                 bump = 1;
1272
1273         er_floor = atoi(bstr("er_floor"));
1274
1275         sprintf(buf, "SETR %s|%s|%s|%u|%d|%d",
1276              er_name, er_password, er_dirname, er_flags, bump, er_floor);
1277         serv_puts(buf);
1278         serv_gets(buf);
1279         if (buf[0] != '2') {
1280                 display_error(&buf[4]);
1281                 return;
1282         }
1283         gotoroom(er_name, 0);
1284
1285         if (strlen(er_roomaide) > 0) {
1286                 sprintf(buf, "SETA %s", er_roomaide);
1287                 serv_puts(buf);
1288                 serv_gets(buf);
1289                 if (buf[0] != '2') {
1290                         display_error(&buf[4]);
1291                         return;
1292                 }
1293         }
1294         smart_goto(er_name);
1295 }
1296
1297 /*
1298  * Invite, Kick, and show Who Knows a room
1299  */
1300 void display_whok(void)
1301 {
1302         char buf[SIZ], room[SIZ], username[SIZ];
1303
1304         serv_puts("GETR");
1305         serv_gets(buf);
1306
1307         if (buf[0] != '2') {
1308                 display_error(&buf[4]);
1309                 return;
1310         }
1311         extract(room, &buf[4], 0);
1312
1313         strcpy(username, bstr("username"));
1314
1315         output_headers(1);
1316
1317         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#007700\"><TR><TD>");
1318         wprintf("<SPAN CLASS=\"titlebar\">Access control list for ");
1319         escputs(WC->wc_roomname);
1320         wprintf("</SPAN></TD></TR></TABLE>\n");
1321
1322         if(!strcmp(bstr("sc"), "Kick")) {
1323                 sprintf(buf, "KICK %s", username);
1324                 serv_puts(buf);
1325                 serv_gets(buf);
1326
1327                 if (buf[0] != '2') {
1328                         display_error(&buf[4]);
1329                         return;
1330                 } else {
1331                         wprintf("<B><I>User %s kicked out of room %s.</I></B>\n", 
1332                                 username, room);
1333                 }
1334         } else if(!strcmp(bstr("sc"), "Invite")) {
1335                 sprintf(buf, "INVT %s", username);
1336                 serv_puts(buf);
1337                 serv_gets(buf);
1338
1339                 if (buf[0] != '2') {
1340                         display_error(&buf[4]);
1341                         return;
1342                 } else {
1343                         wprintf("<B><I>User %s invited to room %s.</I></B>\n", 
1344                                 username, room);
1345                 }
1346         }
1347         
1348
1349
1350         wprintf("<TABLE border=0 CELLSPACING=10><TR VALIGN=TOP>"
1351                 "<TD>The users listed below have access to this room.  "
1352                 "To remove a user from the access list, select the user "
1353                 "name from the list and click 'Kick'.<BR><BR>");
1354         
1355         wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/display_whok\">\n");
1356         wprintf("<SELECT NAME=\"username\" SIZE=10>\n");
1357         serv_puts("WHOK");
1358         serv_gets(buf);
1359         if (buf[0] == '1') {
1360                 while (serv_gets(buf), strcmp(buf, "000")) {
1361                         extract(username, buf, 0);
1362                         wprintf("<OPTION>");
1363                         escputs(username);
1364                         wprintf("\n");
1365                 }
1366         }
1367         wprintf("</SELECT><BR>\n");
1368
1369         wprintf("<input type=submit name=sc value=\"Kick\">");
1370         wprintf("</FORM></CENTER>\n");
1371
1372         wprintf("</TD><TD>"
1373                 "To grant another user access to this room, enter the "
1374                 "user name in the box below and click 'Invite'.<BR><BR>");
1375
1376         wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/display_whok\">\n");
1377         wprintf("Invite: ");
1378         wprintf("<input type=text name=username><BR>\n"
1379                 "<input type=hidden name=sc value=\"Invite\">"
1380                 "<input type=submit value=\"Invite\">"
1381                 "</FORM></CENTER>\n");
1382
1383         wprintf("</TD></TR></TABLE>\n");
1384         wDumpContent(1);
1385 }
1386
1387
1388
1389 /*
1390  * display the form for entering a new room
1391  */
1392 void display_entroom(void)
1393 {
1394         int i;
1395         char buf[SIZ];
1396
1397         serv_puts("CRE8 0");
1398         serv_gets(buf);
1399
1400         if (buf[0] != '2') {
1401                 display_error(&buf[4]);
1402                 return;
1403         }
1404         output_headers(1);
1405
1406         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#000077\"><TR><TD>");
1407         wprintf("<SPAN CLASS=\"titlebar\">Enter (create) a new room</SPAN>\n");
1408         wprintf("</TD></TR></TABLE>\n");
1409
1410         wprintf("<FORM METHOD=\"POST\" ACTION=\"/entroom\">\n");
1411
1412         wprintf("<UL><LI>Name of room: ");
1413         wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" MAXLENGTH=\"19\">\n");
1414
1415         wprintf("<LI>Type of room:<UL>\n");
1416
1417         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
1418         wprintf("CHECKED > Public room\n");
1419
1420         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
1421         wprintf("> Private - guess name\n");
1422
1423         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
1424         wprintf("> Private - require password:\n");
1425         wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" MAXLENGTH=\"9\">\n");
1426
1427         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
1428         wprintf("> Private - invitation only\n");
1429         wprintf("</UL>\n");
1430
1431         wprintf("<LI>Resides on floor: ");
1432         load_floorlist(); 
1433         wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
1434         for (i = 0; i < 128; ++i)
1435                 if (strlen(floorlist[i]) > 0) {
1436                         wprintf("<OPTION ");
1437                         wprintf("VALUE=\"%d\">", i);
1438                         escputs(floorlist[i]);
1439                         wprintf("</OPTION>\n");
1440                 }
1441         wprintf("</SELECT>\n");                
1442         wprintf("</UL>\n");
1443
1444
1445         wprintf("<CENTER>\n");
1446         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1447         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1448         wprintf("</CENTER>\n");
1449         wprintf("</FORM>\n<HR>");
1450         serv_printf("MESG roomaccess");
1451         serv_gets(buf);
1452         if (buf[0] == '1') {
1453                 fmout(NULL);
1454         }
1455         wDumpContent(1);
1456 }
1457
1458
1459
1460 /*
1461  * enter a new room
1462  */
1463 void entroom(void)
1464 {
1465         char buf[SIZ];
1466         char er_name[20];
1467         char er_type[20];
1468         char er_password[10];
1469         int er_floor;
1470         int er_num_type;
1471
1472         if (strcmp(bstr("sc"), "OK")) {
1473                 display_error("Cancelled.  No new room was created.");
1474                 return;
1475         }
1476         strcpy(er_name, bstr("er_name"));
1477         strcpy(er_type, bstr("type"));
1478         strcpy(er_password, bstr("er_password"));
1479         er_floor = atoi(bstr("er_floor"));
1480
1481         er_num_type = 0;
1482         if (!strcmp(er_type, "guessname"))
1483                 er_num_type = 1;
1484         if (!strcmp(er_type, "passworded"))
1485                 er_num_type = 2;
1486         if (!strcmp(er_type, "invonly"))
1487                 er_num_type = 3;
1488
1489         sprintf(buf, "CRE8 1|%s|%d|%s|%d", 
1490                 er_name, er_num_type, er_password, er_floor);
1491         serv_puts(buf);
1492         serv_gets(buf);
1493         if (buf[0] != '2') {
1494                 display_error(&buf[4]);
1495                 return;
1496         }
1497         smart_goto(er_name);
1498 }
1499
1500
1501 /*
1502  * display the screen to enter a private room
1503  */
1504 void display_private(char *rname, int req_pass)
1505 {
1506
1507         output_headers(1);
1508
1509         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
1510         wprintf("<SPAN CLASS=\"titlebar\">Goto a private room</SPAN>\n");
1511         wprintf("</TD></TR></TABLE>\n");
1512
1513         wprintf("<CENTER>\n");
1514         wprintf("If you know the name of a hidden (guess-name) or\n");
1515         wprintf("passworded room, you can enter that room by typing\n");
1516         wprintf("its name below.  Once you gain access to a private\n");
1517         wprintf("room, it will appear in your regular room listings\n");
1518         wprintf("so you don't have to keep returning here.\n");
1519         wprintf("<BR><BR>");
1520
1521         wprintf("<FORM METHOD=\"GET\" ACTION=\"/goto_private\">\n");
1522
1523         wprintf("<TABLE border><TR><TD>");
1524         wprintf("Enter room name:</TD><TD>");
1525         wprintf("<INPUT TYPE=\"text\" NAME=\"gr_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", rname);
1526
1527         if (req_pass) {
1528                 wprintf("</TD></TR><TR><TD>");
1529                 wprintf("Enter room password:</TD><TD>");
1530                 wprintf("<INPUT TYPE=\"password\" NAME=\"gr_pass\" MAXLENGTH=\"9\">\n");
1531         }
1532         wprintf("</TD></TR></TABLE>\n");
1533
1534         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1535         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1536         wprintf("</FORM>\n");
1537         wDumpContent(1);
1538 }
1539
1540 /* 
1541  * goto a private room
1542  */
1543 void goto_private(void)
1544 {
1545         char hold_rm[SIZ];
1546         char buf[SIZ];
1547
1548         if (strcasecmp(bstr("sc"), "OK")) {
1549                 display_main_menu();
1550                 return;
1551         }
1552         strcpy(hold_rm, WC->wc_roomname);
1553         strcpy(buf, "GOTO ");
1554         strcat(buf, bstr("gr_name"));
1555         strcat(buf, "|");
1556         strcat(buf, bstr("gr_pass"));
1557         serv_puts(buf);
1558         serv_gets(buf);
1559
1560         if (buf[0] == '2') {
1561                 smart_goto(bstr("gr_name"));
1562                 return;
1563         }
1564         if (!strncmp(buf, "540", 3)) {
1565                 display_private(bstr("gr_name"), 1);
1566                 return;
1567         }
1568         output_headers(1);
1569         wprintf("%s\n", &buf[4]);
1570         wDumpContent(1);
1571         return;
1572 }
1573
1574
1575 /*
1576  * display the screen to zap a room
1577  */
1578 void display_zap(void)
1579 {
1580         output_headers(1);
1581
1582         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
1583         wprintf("<SPAN CLASS=\"titlebar\">Zap (forget) the current room</SPAN>\n");
1584         wprintf("</TD></TR></TABLE>\n");
1585
1586         wprintf("If you select this option, <em>%s</em> will ", WC->wc_roomname);
1587         wprintf("disappear from your room list.  Is this what you wish ");
1588         wprintf("to do?<BR>\n");
1589
1590         wprintf("<FORM METHOD=\"GET\" ACTION=\"/zap\">\n");
1591         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1592         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1593         wprintf("</FORM>\n");
1594         wDumpContent(1);
1595 }
1596
1597
1598 /* 
1599  * zap a room
1600  */
1601 void zap(void)
1602 {
1603         char buf[SIZ];
1604         char final_destination[SIZ];
1605
1606         /* If the forget-room routine fails for any reason, we fall back
1607          * to the current room; otherwise, we go to the Lobby
1608          */
1609         strcpy(final_destination, WC->wc_roomname);
1610
1611         if (!strcasecmp(bstr("sc"), "OK")) {
1612                 serv_printf("GOTO %s", WC->wc_roomname);
1613                 serv_gets(buf);
1614                 if (buf[0] != '2') {
1615                         /* ExpressMessageCat(&buf[4]); */
1616                 } else {
1617                         serv_puts("FORG");
1618                         serv_gets(buf);
1619                         if (buf[0] != '2') {
1620                                 /* ExpressMessageCat(&buf[4]); */
1621                         } else {
1622                                 strcpy(final_destination, "_BASEROOM_");
1623                         }
1624                 }
1625         }
1626         smart_goto(final_destination);
1627 }
1628
1629
1630
1631
1632 /*
1633  * Confirm deletion of the current room
1634  */
1635 void confirm_delete_room(void)
1636 {
1637         char buf[SIZ];
1638
1639         serv_puts("KILL 0");
1640         serv_gets(buf);
1641         if (buf[0] != '2') {
1642                 display_error(&buf[4]);
1643                 return;
1644         }
1645         output_headers(1);
1646         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
1647         wprintf("<SPAN CLASS=\"titlebar\">Confirm deletion of room</SPAN>\n");
1648         wprintf("</TD></TR></TABLE>\n");
1649
1650         wprintf("<CENTER>");
1651         wprintf("<FORM METHOD=\"GET\" ACTION=\"/delete_room\">\n");
1652
1653         wprintf("Are you sure you want to delete <FONT SIZE=+1>");
1654         escputs(WC->wc_roomname);
1655         wprintf("</FONT>?<BR>\n");
1656
1657         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">");
1658         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1659
1660         wprintf("</FORM></CENTER>\n");
1661         wDumpContent(1);
1662 }
1663
1664
1665 /*
1666  * Delete the current room
1667  */
1668 void delete_room(void)
1669 {
1670         char buf[SIZ];
1671         char sc[SIZ];
1672
1673         strcpy(sc, bstr("sc"));
1674
1675         if (strcasecmp(sc, "Delete")) {
1676                 display_error("Cancelled.  This room was not deleted.");
1677                 return;
1678         }
1679         serv_puts("KILL 1");
1680         serv_gets(buf);
1681         if (buf[0] != '2') {
1682                 display_error(&buf[4]);
1683         } else {
1684                 smart_goto("_BASEROOM_");
1685         }
1686 }
1687
1688
1689
1690 /*
1691  * Perform changes to a room's network configuration
1692  */
1693 void netedit(void) {
1694         FILE *fp;
1695         char buf[SIZ];
1696         char line[SIZ];
1697
1698         if (strlen(bstr("line"))==0) {
1699                 display_editroom();
1700                 return;
1701         }
1702
1703         strcpy(line, bstr("prefix"));
1704         strcat(line, bstr("line"));
1705         strcat(line, bstr("suffix"));
1706
1707         fp = tmpfile();
1708         if (fp == NULL) {
1709                 display_editroom();
1710                 return;
1711         }
1712
1713         serv_puts("GNET");
1714         serv_gets(buf);
1715         if (buf[0] != '1') {
1716                 fclose(fp);
1717                 display_editroom();
1718                 return;
1719         }
1720
1721         /* This loop works for add *or* remove.  Spiffy, eh? */
1722         while (serv_gets(buf), strcmp(buf, "000")) {
1723                 if (strcasecmp(buf, line)) {
1724                         fprintf(fp, "%s\n", buf);
1725                 }
1726         }
1727
1728         rewind(fp);
1729         serv_puts("SNET");
1730         serv_gets(buf);
1731         if (buf[0] != '4') {
1732                 fclose(fp);
1733                 display_editroom();
1734                 return;
1735         }
1736
1737         while (fgets(buf, sizeof buf, fp) != NULL) {
1738                 buf[strlen(buf)-1] = 0;
1739                 serv_puts(buf);
1740         }
1741
1742         if (!strcasecmp(bstr("cmd"), "add")) {
1743                 serv_puts(line);
1744         }
1745
1746         serv_puts("000");
1747         fclose(fp);
1748         display_editroom();
1749 }
1750
1751
1752
1753 /*
1754  * Convert a room name to a folder-ish-looking name.
1755  */
1756 void room_to_folder(char *folder, char *room, int floor, int is_mailbox)
1757 {
1758         int i;
1759
1760         /*
1761          * For mailboxes, just do it straight...
1762          */
1763         if (is_mailbox) {
1764                 sprintf(folder, "My folders|%s", room);
1765         }
1766
1767         /*
1768          * Otherwise, prefix the floor name as a "public folders" moniker
1769          */
1770         else {
1771                 sprintf(folder, "%s|%s", floorlist[floor], room);
1772         }
1773
1774         /*
1775          * Replace "/" characters with "|" for pseudo-folder-delimiting
1776          */
1777         for (i=0; i<strlen(folder); ++i) {
1778                 if (folder[i] == '/') folder[i] = '|';
1779         }
1780 }
1781
1782
1783
1784
1785
1786
1787
1788 /*
1789  * Change the view for this room
1790  */
1791 void change_view(void) {
1792         int view;
1793         char buf[SIZ];
1794
1795         view = atol(bstr("view"));
1796
1797         serv_printf("VIEW %d", view);
1798         serv_gets(buf);
1799         smart_goto(WC->wc_roomname);
1800 }
1801
1802
1803 /*
1804  * Show the room list in "folders" format.  (only should get called by
1805  * knrooms() because that's where output_headers() is called from)
1806  */
1807 void folders(void) {
1808         char buf[SIZ];
1809
1810         int levels, oldlevels;
1811         int swap = 0;
1812
1813         struct folder {
1814                 char room[SIZ];
1815                 char name[SIZ];
1816                 int hasnewmsgs;
1817                 int is_mailbox;
1818                 int selectable;
1819         };
1820
1821         struct folder *fold = NULL;
1822         struct folder ftmp;
1823         int max_folders = 0;
1824         int alloc_folders = 0;
1825         int i, j, k, t;
1826         int p;
1827         int flags;
1828         int floor;
1829         int nests = 0;
1830
1831         /* Start with the mailboxes */
1832         max_folders = 1;
1833         alloc_folders = 1;
1834         fold = malloc(sizeof(struct folder));
1835         memset(fold, 0, sizeof(struct folder));
1836         strcpy(fold[0].name, "My folders");
1837         fold[0].is_mailbox = 1;
1838
1839         /* Then add floors */
1840         serv_puts("LFLR");
1841         serv_gets(buf);
1842         if (buf[0]=='1') while(serv_gets(buf), strcmp(buf, "000")) {
1843                 if (max_folders >= alloc_folders) {
1844                         alloc_folders = max_folders + 100;
1845                         fold = realloc(fold,
1846                                 alloc_folders * sizeof(struct folder));
1847                 }
1848                 memset(&fold[max_folders], 0, sizeof(struct folder));
1849                 extract(fold[max_folders].name, buf, 1);
1850                 ++max_folders;
1851         }
1852
1853         /* Now add rooms */
1854         for (p = 0; p < 2; ++p) {
1855                 if (p == 0) serv_puts("LKRN");
1856                 else if (p == 1) serv_puts("LKRO");
1857                 serv_gets(buf);
1858                 if (buf[0]=='1') while(serv_gets(buf), strcmp(buf, "000")) {
1859                         if (max_folders >= alloc_folders) {
1860                                 alloc_folders = max_folders + 100;
1861                                 fold = realloc(fold,
1862                                         alloc_folders * sizeof(struct folder));
1863                         }
1864                         memset(&fold[max_folders], 0, sizeof(struct folder));
1865                         extract(fold[max_folders].room, buf, 0);
1866                         if (p == 0) fold[max_folders].hasnewmsgs = 1;
1867                         flags = extract_int(buf, 1);
1868                         floor = extract_int(buf, 2);
1869                         if (flags & QR_MAILBOX) {
1870                                 fold[max_folders].is_mailbox = 1;
1871                         }
1872                         room_to_folder(fold[max_folders].name,
1873                                         fold[max_folders].room,
1874                                         floor,
1875                                         fold[max_folders].is_mailbox);
1876                         fold[max_folders].selectable = 1;
1877                         ++max_folders;
1878                 }
1879         }
1880
1881         /* Bubble-sort the folder list */
1882         for (i=0; i<max_folders; ++i) {
1883                 for (j=0; j<(max_folders-1)-i; ++j) {
1884                         if (fold[j].is_mailbox == fold[j+1].is_mailbox) {
1885                                 swap = strcasecmp(fold[j].name, fold[j+1].name);
1886                         }
1887                         else {
1888                                 if ( (fold[j+1].is_mailbox)
1889                                    && (!fold[j].is_mailbox)) {
1890                                         swap = 1;
1891                                 }
1892                                 else {
1893                                         swap = 0;
1894                                 }
1895                         }
1896                         if (swap > 0) {
1897                                 memcpy(&ftmp, &fold[j], sizeof(struct folder));
1898                                 memcpy(&fold[j], &fold[j+1],
1899                                                         sizeof(struct folder));
1900                                 memcpy(&fold[j+1], &ftmp,
1901                                                         sizeof(struct folder));
1902                         }
1903                 }
1904         }
1905
1906         /* Output */
1907         nests = 0;
1908         levels = 0;
1909         oldlevels = 0;
1910         for (i=0; i<max_folders; ++i) {
1911
1912                 levels = num_tokens(fold[i].name, '|');
1913                 if (levels > oldlevels) {
1914                         for (k=0; k<(levels-oldlevels); ++k) {
1915                                 ++nests;
1916                         }
1917                 }
1918                 if (levels < oldlevels) {
1919                         for (k=0; k<(oldlevels-levels); ++k) {
1920                                 --nests;
1921                         }
1922                 }
1923                 oldlevels = levels;
1924
1925                 for (t=0; t<nests; ++t) wprintf("&nbsp;&nbsp;&nbsp;");
1926                 if (fold[i].selectable) {
1927                         wprintf("<A HREF=\"/dotgoto?room=");
1928                         urlescputs(fold[i].room);
1929                         wprintf("\">");
1930                 }
1931                 else {
1932                         wprintf("<i>");
1933                 }
1934                 if (fold[i].hasnewmsgs) wprintf("<B>");
1935                 extract(buf, fold[i].name, levels-1);
1936                 escputs(buf);
1937                 if (fold[i].hasnewmsgs) wprintf("</B>");
1938                 if (fold[i].selectable) {
1939                         wprintf("</A>");
1940                 }
1941                 else {
1942                         wprintf("</i>");
1943                 }
1944                 if (!strcasecmp(fold[i].name, "My Folders|Mail")) {
1945                         wprintf(" (INBOX)");
1946                 }
1947                 wprintf("<BR>\n");
1948         }
1949         while (nests-- > 0) ;; 
1950
1951         free(fold);
1952         wDumpContent(1);
1953 }
1954
1955
1956 /* Do either a known rooms list or a folders list, depending on the
1957  * user's preference
1958  */
1959 void knrooms() {
1960         char listviewpref[SIZ];
1961
1962         output_headers(3);
1963         load_floorlist();
1964
1965         /* Determine whether the user is trying to change views */
1966         if (bstr("view") != NULL) {
1967                 if (strlen(bstr("view")) > 0) {
1968                         set_preference("roomlistview", bstr("view"));
1969                 }
1970         }
1971
1972         get_preference("roomlistview", listviewpref);
1973
1974         if (strcasecmp(listviewpref, "folders")) {
1975                 strcpy(listviewpref, "rooms");
1976         }
1977
1978         /* title bar */
1979         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#000077\"><TR><TD>"
1980                 "<SPAN CLASS=\"titlebar\">"
1981         );
1982         if (!strcasecmp(listviewpref, "rooms")) {
1983                 wprintf("Room list");
1984         }
1985         if (!strcasecmp(listviewpref, "folders")) {
1986                 wprintf("Folder list");
1987         }
1988         wprintf("</SPAN></TD>\n");
1989
1990
1991         /* offer the ability to switch views */
1992         wprintf("<TD><FORM NAME=\"roomlistomatic\">\n"
1993                 "<SELECT NAME=\"newview\" SIZE=\"1\" "
1994                 "OnChange=\"location.href=roomlistomatic.newview.options"
1995                 "[selectedIndex].value\">\n");
1996
1997         wprintf("<OPTION %s VALUE=\"/knrooms&view=rooms\">"
1998                 "View as room list"
1999                 "</OPTION>\n",
2000                 ( !strcasecmp(listviewpref, "rooms") ? "SELECTED" : "" )
2001         );
2002
2003         wprintf("<OPTION %s VALUE=\"/knrooms&view=folders\">"
2004                 "View as folder list"
2005                 "</OPTION>\n",
2006                 ( !strcasecmp(listviewpref, "folders") ? "SELECTED" : "" )
2007         );
2008
2009         wprintf("</SELECT></FORM></TD><TD>\n");
2010         offer_start_page();
2011         wprintf("</TD></TR></TABLE><BR>\n");
2012
2013         /* Display the room list in the user's preferred format */
2014         if (!strcasecmp(listviewpref, "folders")) {
2015                 folders();
2016         }
2017         else {
2018                 list_all_rooms_by_floor();
2019         }
2020 }