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