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