]> code.citadel.org Git - citadel.git/blob - webcit/roomops.c
* Enable a "make this my start page" link that works in lots of places.
[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  * display the form for editing a room
629  */
630 void display_editroom(void)
631 {
632         char buf[SIZ];
633         char cmd[SIZ];
634         char node[SIZ];
635         char recp[SIZ];
636         char er_name[20];
637         char er_password[10];
638         char er_dirname[15];
639         char er_roomaide[26];
640         unsigned er_flags;
641         int er_floor;
642         int i, j;
643         char *tab;
644         char *shared_with;
645         char *not_shared_with;
646
647         tab = bstr("tab");
648         if (strlen(tab) == 0) tab = "admin";
649
650         serv_puts("GETR");
651         serv_gets(buf);
652
653         if (buf[0] != '2') {
654                 display_error(&buf[4]);
655                 return;
656         }
657         extract(er_name, &buf[4], 0);
658         extract(er_password, &buf[4], 1);
659         extract(er_dirname, &buf[4], 2);
660         er_flags = extract_int(&buf[4], 3);
661         er_floor = extract_int(&buf[4], 4);
662
663         output_headers(1);
664
665         /* print the tabbed dialog */
666         wprintf("<TABLE border=0 width=100%%><TR BGCOLOR=FFFFFF><TD> </TD>");
667
668         if (!strcmp(tab, "admin")) {
669                 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
670         }
671         else {
672                 wprintf("<TD><A HREF=\"/display_editroom&tab=admin\">");
673         }
674         wprintf("Room administration");
675         if (!strcmp(tab, "admin")) {
676                 wprintf("</B></FONT></TD>\n");
677         }
678         else {
679                 wprintf("</A></TD>\n");
680         }
681
682         wprintf("<TD> </TD>\n");
683
684         if (!strcmp(tab, "config")) {
685                 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
686         }
687         else {
688                 wprintf("<TD><A HREF=\"/display_editroom&tab=config\">");
689         }
690         wprintf("Room configuration");
691         if (!strcmp(tab, "config")) {
692                 wprintf("</B></FONT></TD>\n");
693         }
694         else {
695                 wprintf("</A></TD>\n");
696         }
697
698         wprintf("<TD> </TD>\n");
699
700         if (!strcmp(tab, "sharing")) {
701                 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
702         }
703         else {
704                 wprintf("<TD><A HREF=\"/display_editroom&tab=sharing\">");
705         }
706         wprintf("Sharing");
707         if (!strcmp(tab, "sharing")) {
708                 wprintf("</B></FONT></TD>\n");
709         }
710         else {
711                 wprintf("</A></TD>\n");
712         }
713
714         wprintf("<TD> </TD>\n");
715
716         if (!strcmp(tab, "listserv")) {
717                 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
718         }
719         else {
720                 wprintf("<TD><A HREF=\"/display_editroom&tab=listserv\">");
721         }
722         wprintf("Mailing list service");
723         if (!strcmp(tab, "listserv")) {
724                 wprintf("</B></FONT></TD>\n");
725         }
726         else {
727                 wprintf("</A></TD>\n");
728         }
729
730         wprintf("<TD> </TD></TR></TABLE>\n");
731
732         /* end tabbed dialog */ 
733
734
735         if (!strcmp(tab, "admin")) {
736                 wprintf("<UL>"
737                         "<LI><A HREF=\"/confirm_delete_room\">\n"
738                         "Delete this room</A>\n"
739                         "<LI><A HREF=\"/display_editroompic\">\n"
740                         "Set or change the graphic for this room's banner</A>\n"
741                         "<LI><A HREF=\"/display_editinfo\">\n"
742                         "Edit this room's Info file</A>\n"
743                         "</UL>");
744         }
745
746         if (!strcmp(tab, "config")) {
747                 wprintf("<FORM METHOD=\"POST\" ACTION=\"/editroom\">\n");
748         
749                 wprintf("<UL><LI>Name of room: ");
750                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", er_name);
751         
752                 wprintf("<LI>Resides on floor: ");
753                 load_floorlist();
754                 wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
755                 for (i = 0; i < 128; ++i)
756                         if (strlen(floorlist[i]) > 0) {
757                                 wprintf("<OPTION ");
758                                 if (i == er_floor)
759                                         wprintf("SELECTED ");
760                                 wprintf("VALUE=\"%d\">", i);
761                                 escputs(floorlist[i]);
762                                 wprintf("</OPTION>\n");
763                         }
764                 wprintf("</SELECT>\n");
765         
766                 wprintf("<LI>Type of room:<UL>\n");
767
768                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
769                 if ((er_flags & QR_PRIVATE) == 0)
770                 wprintf("CHECKED ");
771                 wprintf("> Public room\n");
772
773                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
774                 if ((er_flags & QR_PRIVATE) &&
775                     (er_flags & QR_GUESSNAME))
776                         wprintf("CHECKED ");
777                 wprintf("> Private - guess name\n");
778         
779                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
780                 if ((er_flags & QR_PRIVATE) &&
781                     (er_flags & QR_PASSWORDED))
782                         wprintf("CHECKED ");
783                 wprintf("> Private - require password:\n");
784                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" VALUE=\"%s\" MAXLENGTH=\"9\">\n", er_password);
785         
786                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
787                 if ((er_flags & QR_PRIVATE)
788                     && ((er_flags & QR_GUESSNAME) == 0)
789                     && ((er_flags & QR_PASSWORDED) == 0))
790                         wprintf("CHECKED ");
791                 wprintf("> Private - invitation only\n");
792         
793                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"bump\" VALUE=\"yes\" ");
794                 wprintf("> If private, cause current users to forget room\n");
795         
796                 wprintf("</UL>\n");
797         
798                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"prefonly\" VALUE=\"yes\" ");
799                 if (er_flags & QR_PREFONLY)
800                         wprintf("CHECKED ");
801                 wprintf("> Preferred users only\n");
802         
803                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"readonly\" VALUE=\"yes\" ");
804                 if (er_flags & QR_READONLY)
805                         wprintf("CHECKED ");
806                 wprintf("> Read-only room\n");
807         
808         /* directory stuff */
809                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"directory\" VALUE=\"yes\" ");
810                 if (er_flags & QR_DIRECTORY)
811                         wprintf("CHECKED ");
812                 wprintf("> File directory room\n");
813
814                 wprintf("<UL><LI>Directory name: ");
815                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_dirname\" VALUE=\"%s\" MAXLENGTH=\"14\">\n", er_dirname);
816
817                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"ulallowed\" VALUE=\"yes\" ");
818                 if (er_flags & QR_UPLOAD)
819                         wprintf("CHECKED ");
820                 wprintf("> Uploading allowed\n");
821         
822                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"dlallowed\" VALUE=\"yes\" ");
823                 if (er_flags & QR_DOWNLOAD)
824                         wprintf("CHECKED ");
825                 wprintf("> Downloading allowed\n");
826         
827                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"visdir\" VALUE=\"yes\" ");
828                 if (er_flags & QR_VISDIR)
829                         wprintf("CHECKED ");
830                 wprintf("> Visible directory</UL>\n");
831         
832         /* end of directory stuff */
833         
834                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"network\" VALUE=\"yes\" ");
835                 if (er_flags & QR_NETWORK)
836                         wprintf("CHECKED ");
837                 wprintf("> Network shared room\n");
838
839         /* start of anon options */
840         
841                 wprintf("<LI>Anonymous messages<UL>\n");
842         
843                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"no\" ");
844                 if (((er_flags & QR_ANONONLY) == 0)
845                     && ((er_flags & QR_ANONOPT) == 0))
846                         wprintf("CHECKED ");
847                 wprintf("> No anonymous messages\n");
848         
849                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anononly\" ");
850                 if (er_flags & QR_ANONONLY)
851                         wprintf("CHECKED ");
852                 wprintf("> All messages are anonymous\n");
853         
854                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anon2\" ");
855                 if (er_flags & QR_ANONOPT)
856                         wprintf("CHECKED ");
857                 wprintf("> Prompt user when entering messages</UL>\n");
858         
859         /* end of anon options */
860         
861                 wprintf("<LI>Room aide: \n");
862                 serv_puts("GETA");
863                 serv_gets(buf);
864                 if (buf[0] != '2') {
865                         wprintf("<EM>%s</EM>\n", &buf[4]);
866                 } else {
867                         extract(er_roomaide, &buf[4], 0);
868                         wprintf("<INPUT TYPE=\"text\" NAME=\"er_roomaide\" VALUE=\"%s\" MAXLENGTH=\"25\">\n", er_roomaide);
869                 }
870         
871                 wprintf("</UL><CENTER>\n");
872                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
873                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
874                 wprintf("</CENTER>\n");
875         }
876
877
878         /* Sharing the room with other Citadel nodes... */
879         if (!strcmp(tab, "sharing")) {
880
881                 shared_with = strdup("");
882                 not_shared_with = strdup("");
883
884                 /* Learn the current configuration */
885                 serv_puts("CONF getsys|application/x-citadel-ignet-config");
886                 serv_gets(buf);
887                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
888                         extract(node, buf, 0);
889                         not_shared_with = realloc(not_shared_with,
890                                         strlen(not_shared_with) + 32);
891                         strcat(not_shared_with, node);
892                         strcat(not_shared_with, "|");
893                 }
894
895                 serv_puts("GNET");
896                 serv_gets(buf);
897                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
898                         extract(cmd, buf, 0);
899                         extract(node, buf, 1);
900                         if (!strcasecmp(cmd, "ignet_push_share")) {
901                                 shared_with = realloc(shared_with,
902                                                 strlen(shared_with) + 32);
903                                 strcat(shared_with, node);
904                                 strcat(shared_with, "|");
905                         }
906                 }
907
908                 for (i=0; i<num_tokens(shared_with, '|'); ++i) {
909                         extract(node, shared_with, i);
910                         for (j=0; j<num_tokens(not_shared_with, '|'); ++j) {
911                                 extract(cmd, not_shared_with, j);
912                                 if (!strcasecmp(node, cmd)) {
913                                         remove_token(not_shared_with, j, '|');
914                                 }
915                         }
916                 }
917
918                 /* Display the stuff */
919                 wprintf("<CENTER><BR>"
920                         "<TABLE border=1 cellpadding=5><TR>"
921                         "<TD><B><I>Shared with</I></B></TD>"
922                         "<TD><B><I>Not shared with</I></B></TD></TR>\n"
923                         "<TR><TD>\n");
924
925                 for (i=0; i<num_tokens(shared_with, '|'); ++i) {
926                         extract(node, shared_with, i);
927                         if (strlen(node) > 0) {
928                                 wprintf("%s ", node);
929                                 wprintf("<A HREF=\"/netedit&cmd=remove&line="
930                                         "ignet_push_share|");
931                                 urlescputs(node);
932                                 wprintf("&tab=sharing\">(unshare)</A><BR>");
933                         }
934                 }
935
936                 wprintf("</TD><TD>\n");
937
938                 for (i=0; i<num_tokens(not_shared_with, '|'); ++i) {
939                         extract(node, not_shared_with, i);
940                         if (strlen(node) > 0) {
941                                 wprintf("%s ", node);
942                                 wprintf("<A HREF=\"/netedit&cmd=add&line="
943                                         "ignet_push_share|");
944                                 urlescputs(node);
945                                 wprintf("&tab=sharing\">(share)</A><BR>");
946                         }
947                 }
948
949                 wprintf("</TD></TR></TABLE><BR>\n"
950                         "<I><B>Reminder:</B> When sharing a room, "
951                         "it must be shared from both ends.  Adding a node to "
952                         "the 'shared' list sends messages out, but in order to"
953                         " receive messages, the other nodes must be configured"
954                         " to send messages out to your system as well.</I><BR>"
955                         "</CENTER>\n");
956
957         }
958
959         /* Mailing list management */
960         if (!strcmp(tab, "listserv")) {
961
962                 wprintf("<BR><center><i>The contents of this room are being "
963                         "mailed to the following list recipients:"
964                         "</i><br><br>\n");
965
966                 serv_puts("GNET");
967                 serv_gets(buf);
968                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
969                         extract(cmd, buf, 0);
970                         if (!strcasecmp(cmd, "listrecp")) {
971                                 extract(recp, buf, 1);
972                         
973                                 escputs(recp);
974                                 wprintf(" <A HREF=\"/netedit&cmd=remove&line="
975                                         "listrecp|");
976                                 urlescputs(recp);
977                                 wprintf("&tab=listserv\">(remove)</A><BR>");
978
979                         }
980                 }
981                 wprintf("<BR><FORM METHOD=\"POST\" ACTION=\"/netedit\">\n"
982                         "<INPUT TYPE=\"hidden\" NAME=\"tab\" VALUE=\"listserv\">\n"
983                         "<INPUT TYPE=\"hidden\" NAME=\"prefix\" VALUE=\"listrecp|\">\n");
984                 wprintf("<INPUT TYPE=\"text\" NAME=\"line\">\n");
985                 wprintf("<INPUT TYPE=\"submit\" NAME=\"cmd\" VALUE=\"Add\">");
986                 wprintf("</FORM><BR></CENTER>\n");
987         }
988
989         wDumpContent(1);
990 }
991
992
993 /*
994  * save new parameters for a room
995  */
996 void editroom(void)
997 {
998         char buf[SIZ];
999         char er_name[20];
1000         char er_password[10];
1001         char er_dirname[15];
1002         char er_roomaide[26];
1003         int er_floor;
1004         unsigned er_flags;
1005         int bump;
1006
1007
1008         if (strcmp(bstr("sc"), "OK")) {
1009                 display_error("Cancelled.  Changes were not saved.");
1010                 return;
1011         }
1012         serv_puts("GETR");
1013         serv_gets(buf);
1014
1015         if (buf[0] != '2') {
1016                 display_error(&buf[4]);
1017                 return;
1018         }
1019         extract(er_name, &buf[4], 0);
1020         extract(er_password, &buf[4], 1);
1021         extract(er_dirname, &buf[4], 2);
1022         er_flags = extract_int(&buf[4], 3);
1023
1024         strcpy(er_roomaide, bstr("er_roomaide"));
1025         if (strlen(er_roomaide) == 0) {
1026                 serv_puts("GETA");
1027                 serv_gets(buf);
1028                 if (buf[0] != '2') {
1029                         strcpy(er_roomaide, "");
1030                 } else {
1031                         extract(er_roomaide, &buf[4], 0);
1032                 }
1033         }
1034         strcpy(buf, bstr("er_name"));
1035         buf[20] = 0;
1036         if (strlen(buf) > 0)
1037                 strcpy(er_name, buf);
1038
1039         strcpy(buf, bstr("er_password"));
1040         buf[10] = 0;
1041         if (strlen(buf) > 0)
1042                 strcpy(er_password, buf);
1043
1044         strcpy(buf, bstr("er_dirname"));
1045         buf[15] = 0;
1046         if (strlen(buf) > 0)
1047                 strcpy(er_dirname, buf);
1048
1049         strcpy(buf, bstr("type"));
1050         er_flags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
1051
1052         if (!strcmp(buf, "invonly")) {
1053                 er_flags |= (QR_PRIVATE);
1054         }
1055         if (!strcmp(buf, "guessname")) {
1056                 er_flags |= (QR_PRIVATE | QR_GUESSNAME);
1057         }
1058         if (!strcmp(buf, "passworded")) {
1059                 er_flags |= (QR_PRIVATE | QR_PASSWORDED);
1060         }
1061         if (!strcmp(bstr("prefonly"), "yes")) {
1062                 er_flags |= QR_PREFONLY;
1063         } else {
1064                 er_flags &= ~QR_PREFONLY;
1065         }
1066
1067         if (!strcmp(bstr("readonly"), "yes")) {
1068                 er_flags |= QR_READONLY;
1069         } else {
1070                 er_flags &= ~QR_READONLY;
1071         }
1072
1073         if (!strcmp(bstr("network"), "yes")) {
1074                 er_flags |= QR_NETWORK;
1075         } else {
1076                 er_flags &= ~QR_NETWORK;
1077         }
1078
1079         if (!strcmp(bstr("directory"), "yes")) {
1080                 er_flags |= QR_DIRECTORY;
1081         } else {
1082                 er_flags &= ~QR_DIRECTORY;
1083         }
1084
1085         if (!strcmp(bstr("ulallowed"), "yes")) {
1086                 er_flags |= QR_UPLOAD;
1087         } else {
1088                 er_flags &= ~QR_UPLOAD;
1089         }
1090
1091         if (!strcmp(bstr("dlallowed"), "yes")) {
1092                 er_flags |= QR_DOWNLOAD;
1093         } else {
1094                 er_flags &= ~QR_DOWNLOAD;
1095         }
1096
1097         if (!strcmp(bstr("visdir"), "yes")) {
1098                 er_flags |= QR_VISDIR;
1099         } else {
1100                 er_flags &= ~QR_VISDIR;
1101         }
1102
1103         strcpy(buf, bstr("anon"));
1104
1105         er_flags &= ~(QR_ANONONLY | QR_ANONOPT);
1106         if (!strcmp(buf, "anononly"))
1107                 er_flags |= QR_ANONONLY;
1108         if (!strcmp(buf, "anon2"))
1109                 er_flags |= QR_ANONOPT;
1110
1111         bump = 0;
1112         if (!strcmp(bstr("bump"), "yes"))
1113                 bump = 1;
1114
1115         er_floor = atoi(bstr("er_floor"));
1116
1117         sprintf(buf, "SETR %s|%s|%s|%u|%d|%d",
1118              er_name, er_password, er_dirname, er_flags, bump, er_floor);
1119         serv_puts(buf);
1120         serv_gets(buf);
1121         if (buf[0] != '2') {
1122                 display_error(&buf[4]);
1123                 return;
1124         }
1125         gotoroom(er_name, 0);
1126
1127         if (strlen(er_roomaide) > 0) {
1128                 sprintf(buf, "SETA %s", er_roomaide);
1129                 serv_puts(buf);
1130                 serv_gets(buf);
1131                 if (buf[0] != '2') {
1132                         display_error(&buf[4]);
1133                         return;
1134                 }
1135         }
1136         smart_goto(er_name);
1137 }
1138
1139 /*
1140  * Invite, Kick, and show Who Knows a room
1141  */
1142 void display_whok(void)
1143 {
1144         char buf[SIZ], room[SIZ], username[SIZ];
1145
1146         serv_puts("GETR");
1147         serv_gets(buf);
1148
1149         if (buf[0] != '2') {
1150                 display_error(&buf[4]);
1151                 return;
1152         }
1153         extract(room, &buf[4], 0);
1154
1155         strcpy(username, bstr("username"));
1156
1157         output_headers(1);
1158
1159         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>");
1160         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>Access control list for ");
1161         escputs(WC->wc_roomname);
1162         wprintf("</B></FONT></TD></TR></TABLE>\n");
1163
1164         if(!strcmp(bstr("sc"), "Kick")) {
1165                 sprintf(buf, "KICK %s", username);
1166                 serv_puts(buf);
1167                 serv_gets(buf);
1168
1169                 if (buf[0] != '2') {
1170                         display_error(&buf[4]);
1171                         return;
1172                 } else {
1173                         wprintf("<B><I>User %s kicked out of room %s.</I></B>\n", 
1174                                 username, room);
1175                 }
1176         } else if(!strcmp(bstr("sc"), "Invite")) {
1177                 sprintf(buf, "INVT %s", username);
1178                 serv_puts(buf);
1179                 serv_gets(buf);
1180
1181                 if (buf[0] != '2') {
1182                         display_error(&buf[4]);
1183                         return;
1184                 } else {
1185                         wprintf("<B><I>User %s invited to room %s.</I></B>\n", 
1186                                 username, room);
1187                 }
1188         }
1189         
1190
1191
1192         wprintf("<TABLE border=0 CELLSPACING=10><TR VALIGN=TOP>"
1193                 "<TD>The users listed below have access to this room.  "
1194                 "To remove a user from the access list, select the user "
1195                 "name from the list and click 'Kick'.<BR><BR>");
1196         
1197         wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/display_whok\">\n");
1198         wprintf("<SELECT NAME=\"username\" SIZE=10>\n");
1199         serv_puts("WHOK");
1200         serv_gets(buf);
1201         if (buf[0] == '1') {
1202                 while (serv_gets(buf), strcmp(buf, "000")) {
1203                         extract(username, buf, 0);
1204                         wprintf("<OPTION>");
1205                         escputs(username);
1206                         wprintf("\n");
1207                 }
1208         }
1209         wprintf("</SELECT><BR>\n");
1210
1211         wprintf("<input type=submit name=sc value=\"Kick\">");
1212         wprintf("</FORM></CENTER>\n");
1213
1214         wprintf("</TD><TD>"
1215                 "To grant another user access to this room, enter the "
1216                 "user name in the box below and click 'Invite'.<BR><BR>");
1217
1218         wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/display_whok\">\n");
1219         wprintf("Invite: ");
1220         wprintf("<input type=text name=username><BR>\n"
1221                 "<input type=hidden name=sc value=\"Invite\">"
1222                 "<input type=submit value=\"Invite\">"
1223                 "</FORM></CENTER>\n");
1224
1225         wprintf("</TD></TR></TABLE>\n");
1226         wDumpContent(1);
1227 }
1228
1229
1230
1231 /*
1232  * display the form for entering a new room
1233  */
1234 void display_entroom(void)
1235 {
1236         int i;
1237         char buf[SIZ];
1238
1239         serv_puts("CRE8 0");
1240         serv_gets(buf);
1241
1242         if (buf[0] != '2') {
1243                 display_error(&buf[4]);
1244                 return;
1245         }
1246         output_headers(1);
1247
1248         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>");
1249         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1250         wprintf("<B>Enter (create) a new room</B>\n");
1251         wprintf("</FONT></TD></TR></TABLE>\n");
1252
1253         wprintf("<FORM METHOD=\"POST\" ACTION=\"/entroom\">\n");
1254
1255         wprintf("<UL><LI>Name of room: ");
1256         wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" MAXLENGTH=\"19\">\n");
1257
1258         wprintf("<LI>Type of room:<UL>\n");
1259
1260         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
1261         wprintf("CHECKED > Public room\n");
1262
1263         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
1264         wprintf("> Private - guess name\n");
1265
1266         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
1267         wprintf("> Private - require password:\n");
1268         wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" MAXLENGTH=\"9\">\n");
1269
1270         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
1271         wprintf("> Private - invitation only\n");
1272         wprintf("</UL>\n");
1273
1274         wprintf("<LI>Resides on floor: ");
1275         load_floorlist(); 
1276         wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
1277         for (i = 0; i < 128; ++i)
1278                 if (strlen(floorlist[i]) > 0) {
1279                         wprintf("<OPTION ");
1280                         wprintf("VALUE=\"%d\">", i);
1281                         escputs(floorlist[i]);
1282                         wprintf("</OPTION>\n");
1283                 }
1284         wprintf("</SELECT>\n");                
1285         wprintf("</UL>\n");
1286
1287
1288         wprintf("<CENTER>\n");
1289         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1290         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1291         wprintf("</CENTER>\n");
1292         wprintf("</FORM>\n<HR>");
1293         serv_printf("MESG roomaccess");
1294         serv_gets(buf);
1295         if (buf[0] == '1') {
1296                 fmout(NULL);
1297         }
1298         wDumpContent(1);
1299 }
1300
1301
1302
1303 /*
1304  * enter a new room
1305  */
1306 void entroom(void)
1307 {
1308         char buf[SIZ];
1309         char er_name[20];
1310         char er_type[20];
1311         char er_password[10];
1312         int er_floor;
1313         int er_num_type;
1314
1315         if (strcmp(bstr("sc"), "OK")) {
1316                 display_error("Cancelled.  No new room was created.");
1317                 return;
1318         }
1319         strcpy(er_name, bstr("er_name"));
1320         strcpy(er_type, bstr("type"));
1321         strcpy(er_password, bstr("er_password"));
1322         er_floor = atoi(bstr("er_floor"));
1323
1324         er_num_type = 0;
1325         if (!strcmp(er_type, "guessname"))
1326                 er_num_type = 1;
1327         if (!strcmp(er_type, "passworded"))
1328                 er_num_type = 2;
1329         if (!strcmp(er_type, "invonly"))
1330                 er_num_type = 3;
1331
1332         sprintf(buf, "CRE8 1|%s|%d|%s|%d", 
1333                 er_name, er_num_type, er_password, er_floor);
1334         serv_puts(buf);
1335         serv_gets(buf);
1336         if (buf[0] != '2') {
1337                 display_error(&buf[4]);
1338                 return;
1339         }
1340         smart_goto(er_name);
1341 }
1342
1343
1344 /*
1345  * display the screen to enter a private room
1346  */
1347 void display_private(char *rname, int req_pass)
1348 {
1349
1350         output_headers(1);
1351
1352         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
1353         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1354         wprintf("<B>Goto a private room</B>\n");
1355         wprintf("</FONT></TD></TR></TABLE>\n");
1356
1357         wprintf("<CENTER>\n");
1358         wprintf("If you know the name of a hidden (guess-name) or\n");
1359         wprintf("passworded room, you can enter that room by typing\n");
1360         wprintf("its name below.  Once you gain access to a private\n");
1361         wprintf("room, it will appear in your regular room listings\n");
1362         wprintf("so you don't have to keep returning here.\n");
1363         wprintf("<BR><BR>");
1364
1365         wprintf("<FORM METHOD=\"POST\" ACTION=\"/goto_private\">\n");
1366
1367         wprintf("<TABLE border><TR><TD>");
1368         wprintf("Enter room name:</TD><TD>");
1369         wprintf("<INPUT TYPE=\"text\" NAME=\"gr_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", rname);
1370
1371         if (req_pass) {
1372                 wprintf("</TD></TR><TR><TD>");
1373                 wprintf("Enter room password:</TD><TD>");
1374                 wprintf("<INPUT TYPE=\"password\" NAME=\"gr_pass\" MAXLENGTH=\"9\">\n");
1375         }
1376         wprintf("</TD></TR></TABLE>\n");
1377
1378         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1379         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1380         wprintf("</FORM>\n");
1381         wDumpContent(1);
1382 }
1383
1384 /* 
1385  * goto a private room
1386  */
1387 void goto_private(void)
1388 {
1389         char hold_rm[32];
1390         char buf[SIZ];
1391
1392         if (strcasecmp(bstr("sc"), "OK")) {
1393                 display_main_menu();
1394                 return;
1395         }
1396         strcpy(hold_rm, WC->wc_roomname);
1397         strcpy(buf, "GOTO ");
1398         strcat(buf, bstr("gr_name"));
1399         strcat(buf, "|");
1400         strcat(buf, bstr("gr_pass"));
1401         serv_puts(buf);
1402         serv_gets(buf);
1403
1404         if (buf[0] == '2') {
1405                 smart_goto(bstr("gr_name"));
1406                 return;
1407         }
1408         if (!strncmp(buf, "540", 3)) {
1409                 display_private(bstr("gr_name"), 1);
1410                 return;
1411         }
1412         output_headers(1);
1413         wprintf("%s\n", &buf[4]);
1414         wDumpContent(1);
1415         return;
1416 }
1417
1418
1419 /*
1420  * display the screen to zap a room
1421  */
1422 void display_zap(void)
1423 {
1424         output_headers(1);
1425
1426         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
1427         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1428         wprintf("<B>Zap (forget) the current room</B>\n");
1429         wprintf("</FONT></TD></TR></TABLE>\n");
1430
1431         wprintf("If you select this option, <em>%s</em> will ", WC->wc_roomname);
1432         wprintf("disappear from your room list.  Is this what you wish ");
1433         wprintf("to do?<BR>\n");
1434
1435         wprintf("<FORM METHOD=\"POST\" ACTION=\"/zap\">\n");
1436         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1437         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1438         wprintf("</FORM>\n");
1439         wDumpContent(1);
1440 }
1441
1442
1443 /* 
1444  * zap a room
1445  */
1446 void zap(void)
1447 {
1448         char buf[SIZ];
1449         char final_destination[SIZ];
1450
1451         /* If the forget-room routine fails for any reason, we fall back
1452          * to the current room; otherwise, we go to the Lobby
1453          */
1454         strcpy(final_destination, WC->wc_roomname);
1455
1456         if (!strcasecmp(bstr("sc"), "OK")) {
1457                 serv_printf("GOTO %s", WC->wc_roomname);
1458                 serv_gets(buf);
1459                 if (buf[0] != '2') {
1460                         /* ExpressMessageCat(&buf[4]); */
1461                 } else {
1462                         serv_puts("FORG");
1463                         serv_gets(buf);
1464                         if (buf[0] != '2') {
1465                                 /* ExpressMessageCat(&buf[4]); */
1466                         } else {
1467                                 strcpy(final_destination, "_BASEROOM_");
1468                         }
1469                 }
1470         }
1471         smart_goto(final_destination);
1472 }
1473
1474
1475
1476
1477 /*
1478  * Confirm deletion of the current room
1479  */
1480 void confirm_delete_room(void)
1481 {
1482         char buf[SIZ];
1483
1484         serv_puts("KILL 0");
1485         serv_gets(buf);
1486         if (buf[0] != '2') {
1487                 display_error(&buf[4]);
1488                 return;
1489         }
1490         output_headers(1);
1491         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
1492         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1493         wprintf("<B>Confirm deletion of room</B>\n");
1494         wprintf("</FONT></TD></TR></TABLE>\n");
1495
1496         wprintf("<CENTER>");
1497         wprintf("<FORM METHOD=\"POST\" ACTION=\"/delete_room\">\n");
1498
1499         wprintf("Are you sure you want to delete <FONT SIZE=+1>");
1500         escputs(WC->wc_roomname);
1501         wprintf("</FONT>?<BR>\n");
1502
1503         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">");
1504         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1505
1506         wprintf("</FORM></CENTER>\n");
1507         wDumpContent(1);
1508 }
1509
1510
1511 /*
1512  * Delete the current room
1513  */
1514 void delete_room(void)
1515 {
1516         char buf[SIZ];
1517         char sc[SIZ];
1518
1519         strcpy(sc, bstr("sc"));
1520
1521         if (strcasecmp(sc, "Delete")) {
1522                 display_error("Cancelled.  This room was not deleted.");
1523                 return;
1524         }
1525         serv_puts("KILL 1");
1526         serv_gets(buf);
1527         if (buf[0] != '2') {
1528                 display_error(&buf[4]);
1529         } else {
1530                 smart_goto("_BASEROOM_");
1531         }
1532 }
1533
1534
1535
1536 /*
1537  * Perform changes to a room's network configuration
1538  */
1539 void netedit(void) {
1540         FILE *fp;
1541         char buf[SIZ];
1542         char line[SIZ];
1543
1544         if (strlen(bstr("line"))==0) {
1545                 display_editroom();
1546                 return;
1547         }
1548
1549         strcpy(line, bstr("prefix"));
1550         strcat(line, bstr("line"));
1551         strcat(line, bstr("suffix"));
1552
1553         fp = tmpfile();
1554         if (fp == NULL) {
1555                 display_editroom();
1556                 return;
1557         }
1558
1559         serv_puts("GNET");
1560         serv_gets(buf);
1561         if (buf[0] != '1') {
1562                 fclose(fp);
1563                 display_editroom();
1564                 return;
1565         }
1566
1567         /* This loop works for add *or* remove.  Spiffy, eh? */
1568         while (serv_gets(buf), strcmp(buf, "000")) {
1569                 if (strcasecmp(buf, line)) {
1570                         fprintf(fp, "%s\n", buf);
1571                 }
1572         }
1573
1574         rewind(fp);
1575         serv_puts("SNET");
1576         serv_gets(buf);
1577         if (buf[0] != '4') {
1578                 fclose(fp);
1579                 display_editroom();
1580                 return;
1581         }
1582
1583         while (fgets(buf, sizeof buf, fp) != NULL) {
1584                 buf[strlen(buf)-1] = 0;
1585                 serv_puts(buf);
1586         }
1587
1588         if (!strcasecmp(bstr("cmd"), "add")) {
1589                 serv_puts(line);
1590         }
1591
1592         serv_puts("000");
1593         fclose(fp);
1594         display_editroom();
1595 }
1596
1597
1598
1599 /*
1600  * Convert a room name to a folder-ish-looking name.
1601  */
1602 void room_to_folder(char *folder, char *room, int floor, int is_mailbox)
1603 {
1604         int i;
1605
1606         /*
1607          * For mailboxes, just do it straight...
1608          */
1609         if (is_mailbox) {
1610                 sprintf(folder, "My folders|%s", room);
1611         }
1612
1613         /*
1614          * Otherwise, prefix the floor name as a "public folders" moniker
1615          */
1616         else {
1617                 sprintf(folder, "%s|%s", floorlist[floor], room);
1618         }
1619
1620         /*
1621          * Replace "/" characters with "|" for pseudo-folder-delimiting
1622          */
1623         for (i=0; i<strlen(folder); ++i) {
1624                 if (folder[i] == '/') folder[i] = '|';
1625         }
1626 }
1627
1628
1629
1630
1631
1632
1633
1634 /*
1635  * Change the view for this room
1636  */
1637 void change_view(void) {
1638         int view;
1639         char buf[SIZ];
1640
1641         view = atol(bstr("view"));
1642
1643         serv_printf("VIEW %d", view);
1644         serv_gets(buf);
1645         smart_goto(WC->wc_roomname);
1646 }
1647
1648
1649 /*
1650  * Show the room list in "folders" format.  (only should get called by
1651  * knrooms() because that's where output_headers() is called from)
1652  */
1653 void folders(void) {
1654         char buf[SIZ];
1655
1656         int levels, oldlevels;
1657
1658         struct folder {
1659                 char room[SIZ];
1660                 char name[SIZ];
1661                 int hasnewmsgs;
1662                 int is_mailbox;
1663                 int selectable;
1664         };
1665
1666         struct folder *fold = NULL;
1667         struct folder ftmp;
1668         int max_folders = 0;
1669         int alloc_folders = 0;
1670         int i, j, k;
1671         int p;
1672         int flags;
1673         int floor;
1674         int nests = 0;
1675
1676         /* Start with the mailboxes */
1677         max_folders = 1;
1678         alloc_folders = 1;
1679         fold = malloc(sizeof(struct folder));
1680         memset(fold, 0, sizeof(struct folder));
1681         strcpy(fold[0].name, "My folders");
1682
1683         /* Then add floors */
1684         serv_puts("LFLR");
1685         serv_gets(buf);
1686         if (buf[0]=='1') while(serv_gets(buf), strcmp(buf, "000")) {
1687                 if (max_folders >= alloc_folders) {
1688                         alloc_folders = max_folders + 100;
1689                         fold = realloc(fold,
1690                                 alloc_folders * sizeof(struct folder));
1691                 }
1692                 memset(&fold[max_folders], 0, sizeof(struct folder));
1693                 extract(fold[max_folders].name, buf, 1);
1694                 ++max_folders;
1695         }
1696
1697         /* Now add rooms */
1698         for (p = 0; p < 2; ++p) {
1699                 if (p == 0) serv_puts("LKRN");
1700                 else if (p == 1) serv_puts("LKRO");
1701                 serv_gets(buf);
1702                 if (buf[0]=='1') while(serv_gets(buf), strcmp(buf, "000")) {
1703                         if (max_folders >= alloc_folders) {
1704                                 alloc_folders = max_folders + 100;
1705                                 fold = realloc(fold,
1706                                         alloc_folders * sizeof(struct folder));
1707                         }
1708                         memset(&fold[max_folders], 0, sizeof(struct folder));
1709                         extract(fold[max_folders].room, buf, 0);
1710                         if (p == 0) fold[max_folders].hasnewmsgs = 1;
1711                         flags = extract_int(buf, 1);
1712                         floor = extract_int(buf, 2);
1713                         if (flags & QR_MAILBOX) {
1714                                 fold[max_folders].is_mailbox = 1;
1715                         }
1716                         room_to_folder(fold[max_folders].name,
1717                                         fold[max_folders].room,
1718                                         floor,
1719                                         fold[max_folders].is_mailbox);
1720                         fold[max_folders].selectable = 1;
1721                         ++max_folders;
1722                 }
1723         }
1724
1725         /* Bubble-sort the folder list */
1726         for (i=0; i<max_folders; ++i) {
1727                 for (j=0; j<(max_folders-1)-i; ++j) {
1728                         if (strcasecmp(fold[j].name, fold[j+1].name) > 0) {
1729                                 memcpy(&ftmp, &fold[j], sizeof(struct folder));
1730                                 memcpy(&fold[j], &fold[j+1],
1731                                                         sizeof(struct folder));
1732                                 memcpy(&fold[j+1], &ftmp,
1733                                                         sizeof(struct folder));
1734                         }
1735                 }
1736         }
1737
1738         /* Output */
1739         nests = 0;
1740         levels = 0;
1741         oldlevels = 0;
1742         for (i=0; i<max_folders; ++i) {
1743
1744                 levels = num_tokens(fold[i].name, '|');
1745                 if (levels > oldlevels) {
1746                         for (k=0; k<(levels-oldlevels); ++k) {
1747                                 wprintf("<UL>");
1748                                 ++nests;
1749                         }
1750                 }
1751                 if (levels < oldlevels) {
1752                         for (k=0; k<(oldlevels-levels); ++k) {
1753                                 wprintf("</UL>");
1754                                 --nests;
1755                         }
1756                 }
1757                 oldlevels = levels;
1758
1759                 wprintf("<LI>");
1760                 if (fold[i].selectable) {
1761                         wprintf("<A HREF=\"/dotgoto?room=");
1762                         urlescputs(fold[i].room);
1763                         wprintf("\">");
1764                 }
1765                 if (fold[i].hasnewmsgs) wprintf("<B>");
1766                 extract(buf, fold[i].name, levels-1);
1767                 escputs(buf);
1768                 if (fold[i].hasnewmsgs) wprintf("</B>");
1769                 if (fold[i].selectable) wprintf("</A>\n");
1770         }
1771         while (nests-- > 0) wprintf("</UL>\n");
1772
1773         free(fold);
1774         wDumpContent(1);
1775 }
1776
1777
1778 /* Do either a known rooms list or a folders list, depending on the
1779  * user's preference
1780  */
1781 void knrooms() {
1782         char listviewpref[SIZ];
1783
1784         output_headers(3);
1785         load_floorlist();
1786
1787         /* Determine whether the user is trying to change views */
1788         if (bstr("view") != NULL) {
1789                 if (strlen(bstr("view")) > 0) {
1790                         set_preference("roomlistview", bstr("view"));
1791                 }
1792         }
1793
1794         get_preference("roomlistview", listviewpref);
1795
1796         if (strcasecmp(listviewpref, "folders")) {
1797                 strcpy(listviewpref, "rooms");
1798         }
1799
1800         /* title bar */
1801         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>"
1802                 "<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>"
1803         );
1804         if (!strcasecmp(listviewpref, "rooms")) {
1805                 wprintf("Room list");
1806         }
1807         if (!strcasecmp(listviewpref, "folders")) {
1808                 wprintf("Folder list");
1809         }
1810         wprintf("</B></TD>\n");
1811
1812
1813         /* offer the ability to switch views */
1814         wprintf("<TD><FORM NAME=\"roomlistomatic\">\n"
1815                 "<SELECT NAME=\"newview\" SIZE=\"1\" "
1816                 "OnChange=\"location.href=roomlistomatic.newview.options"
1817                 "[selectedIndex].value\">\n");
1818
1819         wprintf("<OPTION %s VALUE=\"/knrooms&view=rooms\">"
1820                 "View as room list"
1821                 "</OPTION>\n",
1822                 ( !strcasecmp(listviewpref, "rooms") ? "SELECTED" : "" )
1823         );
1824
1825         wprintf("<OPTION %s VALUE=\"/knrooms&view=folders\">"
1826                 "View as folder list"
1827                 "</OPTION>\n",
1828                 ( !strcasecmp(listviewpref, "folders") ? "SELECTED" : "" )
1829         );
1830
1831         wprintf("</SELECT></FORM></TD><TD>\n");
1832         offer_start_page();
1833         wprintf("</TD></TR></TABLE><BR>\n");
1834
1835         /* Display the room list in the user's preferred format */
1836         if (!strcasecmp(listviewpref, "folders")) {
1837                 folders();
1838         }
1839         else {
1840                 list_all_rooms_by_floor();
1841         }
1842 }