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