]> code.citadel.org Git - citadel.git/blob - webcit/roomops.c
* Turned the room editing page into a tabbed dialog
[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
27
28
29
30
31 char floorlist[128][SIZ];
32
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                 wprintf("<FONT SIZE=-1>");
296                 fmout(NULL);
297                 wprintf("</FONT>");
298         }
299 }
300
301
302
303
304 /* Display room graphic.  The server doesn't actually
305  * need the room name, but we supply it in order to
306  * keep the browser from using a cached graphic from 
307  * another room.
308  */
309 void embed_room_graphic(void) {
310         char buf[SIZ];
311
312         serv_puts("OIMG _roompic_");
313         serv_gets(buf);
314         if (buf[0] == '2') {
315                 wprintf("<TD>");
316                 wprintf("<IMG SRC=\"/image&name=_roompic_&room=");
317                 urlescputs(WC->wc_roomname);
318                 wprintf("\"></TD>");
319                 serv_puts("CLOS");
320                 serv_gets(buf);
321         }
322
323 }
324
325
326 /* Let the user know if new mail has arrived 
327  */
328 void embed_newmail_button(void) {
329         if ( (WC->new_mail > WC->remember_new_mail) && (WC->new_mail>0) ) {
330                 wprintf("<TD VALIGN=TOP>"
331                         "<IMG SRC=\"/static/mail.gif\" border=0 "
332                         "ALT=\"You have new mail\">"
333                         "<BR><BLINK>%d</BLINK>", WC->new_mail);
334                 wprintf("<FONT SIZE=-2> new mail messages</FONT></TD>");
335                 WC->remember_new_mail = WC->new_mail;
336         }
337 }
338
339
340
341 void embed_room_banner(char *got) {
342         char fakegot[SIZ];
343
344         /* We need to have the information returned by a GOTO server command.
345          * If it isn't supplied, we fake it by issuing our own GOTO.
346          */
347         if (got == NULL) {
348                 serv_printf("GOTO %s", WC->wc_roomname);
349                 serv_gets(fakegot);
350                 got = fakegot;
351         }
352
353         /* Check for new mail. */
354         WC->new_mail = extract_int(&got[4], 9);
355
356         svprintf("ROOMNAME", WCS_STRING, "%s", WC->wc_roomname);
357         svprintf("NEWMSGS", WCS_STRING, "%d", extract_int(&got[4], 1));
358         svprintf("TOTALMSGS", WCS_STRING, "%d", extract_int(&got[4], 2));
359         svcallback("ROOMPIC", embed_room_graphic);
360         svcallback("ROOMINFO", readinfo);
361         svcallback("YOUHAVEMAIL", embed_newmail_button);
362
363         do_template("roombanner.html");
364         clear_local_substs();
365 }
366
367
368
369
370
371 /*
372  * generic routine to take the session to a new room
373  *
374  * display_name values:  0 = goto only
375  *                       1 = goto and display
376  *                       2 = display only
377  */
378 void gotoroom(char *gname, int display_name)
379 {
380         char buf[SIZ];
381         static long ls = (-1L);
382
383
384         if (display_name) {
385                 output_headers(0);
386                 wprintf("Pragma: no-cache\n");
387                 wprintf("Cache-Control: no-store\n");
388
389                 wprintf("<HTML><HEAD>\n"
390                         "<META HTTP-EQUIV=\"refresh\" CONTENT=\"500363689;\">\n"
391                         "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n"
392                         "<META HTTP-EQUIV=\"expired\" CONTENT=\"28-May-1971 18:10:00 GMT\">\n"
393                         "<meta name=\"MSSmartTagsPreventParsing\" content=\"TRUE\">\n"
394                         "</HEAD>\n");
395                 do_template("background.html");
396         }
397         if (display_name != 2) {
398                 /* store ungoto information */
399                 strcpy(WC->ugname, WC->wc_roomname);
400                 WC->uglsn = ls;
401         }
402         /* move to the new room */
403         serv_printf("GOTO %s", gname);
404         serv_gets(buf);
405         if (buf[0] != '2') {
406                 serv_puts("GOTO _BASEROOM_");
407                 serv_gets(buf);
408         }
409         if (buf[0] != '2') {
410                 if (display_name) {
411                         wprintf("<EM>%s</EM><BR>\n", &buf[4]);
412                         wDumpContent(1);
413                 }
414                 return;
415         }
416         extract(WC->wc_roomname, &buf[4], 0);
417         WC->room_flags = extract_int(&buf[4], 4);
418         /* highest_msg_read = extract_int(&buf[4],6);
419            maxmsgnum = extract_int(&buf[4],5);
420            is_mail = (char) extract_int(&buf[4],7); */
421         ls = extract_long(&buf[4], 6);
422
423         if (WC->is_aide)
424                 WC->is_room_aide = WC->is_aide;
425         else
426                 WC->is_room_aide = (char) extract_int(&buf[4], 8);
427
428         remove_march(WC->wc_roomname);
429         if (!strcasecmp(gname, "_BASEROOM_"))
430                 remove_march(gname);
431
432         /* Display the room banner */
433         if (display_name) {
434                 embed_room_banner(buf);
435                 wDumpContent(1);
436         }
437         strcpy(WC->wc_roomname, WC->wc_roomname);
438 }
439
440
441 /*
442  * Locate the room on the march list which we most want to go to.  Each room
443  * is measured given a "weight" of preference based on various factors.
444  */
445 char *pop_march(int desired_floor)
446 {
447         static char TheRoom[64];
448         int TheFloor = 0;
449         int TheOrder = 32767;
450         int TheWeight = 0;
451         int weight;
452         struct march *mptr = NULL;
453
454         strcpy(TheRoom, "_BASEROOM_");
455         if (WC->march == NULL)
456                 return (TheRoom);
457
458         for (mptr = WC->march; mptr != NULL; mptr = mptr->next) {
459                 weight = 0;
460                 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
461                         weight = weight + 10000;
462                 if (mptr->march_floor == desired_floor)
463                         weight = weight + 5000;
464
465                 weight = weight + ((128 - (mptr->march_floor)) * 128);
466                 weight = weight + (128 - (mptr->march_order));
467
468                 if (weight > TheWeight) {
469                         TheWeight = weight;
470                         strcpy(TheRoom, mptr->march_name);
471                         TheFloor = mptr->march_floor;
472                         TheOrder = mptr->march_order;
473                 }
474         }
475         return (TheRoom);
476 }
477
478
479
480 /* Goto next room having unread messages.
481  * We want to skip over rooms that the user has already been to, and take the
482  * user back to the lobby when done.  The room we end up in is placed in
483  * newroom - which is set to 0 (the lobby) initially.
484  * We start the search in the current room rather than the beginning to prevent
485  * two or more concurrent users from dragging each other back to the same room.
486  */
487 void gotonext(void)
488 {
489         char buf[SIZ];
490         struct march *mptr, *mptr2;
491         char next_room[32];
492
493         /* First check to see if the march-mode list is already allocated.
494          * If it is, pop the first room off the list and go there.
495          */
496
497         if (WC->march == NULL) {
498                 serv_puts("LKRN");
499                 serv_gets(buf);
500                 if (buf[0] == '1')
501                         while (serv_gets(buf), strcmp(buf, "000")) {
502                                 mptr = (struct march *) malloc(sizeof(struct march));
503                                 mptr->next = NULL;
504                                 extract(mptr->march_name, buf, 0);
505                                 mptr->march_floor = extract_int(buf, 2);
506                                 mptr->march_order = extract_int(buf, 3);
507                                 if (WC->march == NULL) {
508                                         WC->march = mptr;
509                                 } else {
510                                         mptr2 = WC->march;
511                                         while (mptr2->next != NULL)
512                                                 mptr2 = mptr2->next;
513                                         mptr2->next = mptr;
514                                 }
515                         }
516 /* add _BASEROOM_ to the end of the march list, so the user will end up
517  * in the system base room (usually the Lobby>) at the end of the loop
518  */
519                 mptr = (struct march *) malloc(sizeof(struct march));
520                 mptr->next = NULL;
521                 strcpy(mptr->march_name, "_BASEROOM_");
522                 if (WC->march == NULL) {
523                         WC->march = mptr;
524                 } else {
525                         mptr2 = WC->march;
526                         while (mptr2->next != NULL)
527                                 mptr2 = mptr2->next;
528                         mptr2->next = mptr;
529                 }
530 /*
531  * ...and remove the room we're currently in, so a <G>oto doesn't make us
532  * walk around in circles
533  */
534                 remove_march(WC->wc_roomname);
535         }
536         if (WC->march != NULL) {
537                 strcpy(next_room, pop_march(-1));
538         } else {
539                 strcpy(next_room, "_BASEROOM_");
540         }
541
542
543         smart_goto(next_room);
544 }
545
546
547 void smart_goto(char *next_room) {
548         gotoroom(next_room, 0);
549         readloop("readnew");
550 }
551
552
553
554 /*
555  * mark all messages in current room as having been read
556  */
557 void slrp_highest(void)
558 {
559         char buf[SIZ];
560
561         /* set pointer */
562         serv_puts("SLRP HIGHEST");
563         serv_gets(buf);
564         if (buf[0] != '2') {
565                 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
566                 return;
567         }
568 }
569
570
571 /*
572  * un-goto the previous room
573  */
574 void ungoto(void)
575 {
576         char buf[SIZ];
577
578         if (!strcmp(WC->ugname, "")) {
579                 smart_goto(WC->wc_roomname);
580                 return;
581         }
582         serv_printf("GOTO %s", WC->ugname);
583         serv_gets(buf);
584         if (buf[0] != '2') {
585                 smart_goto(WC->wc_roomname);
586                 return;
587         }
588         if (WC->uglsn >= 0L) {
589                 serv_printf("SLRP %ld", WC->uglsn);
590                 serv_gets(buf);
591         }
592         strcpy(buf, WC->ugname);
593         strcpy(WC->ugname, "");
594         smart_goto(buf);
595 }
596
597 /*
598  * display the form for editing a room
599  */
600 void display_editroom(void)
601 {
602         char buf[SIZ];
603         char node[SIZ];
604         char er_name[20];
605         char er_password[10];
606         char er_dirname[15];
607         char er_roomaide[26];
608         unsigned er_flags;
609         int er_floor;
610         int i;
611         char *tab;
612
613         tab = bstr("tab");
614         if (strlen(tab) == 0) tab = "admin";
615
616         serv_puts("GETR");
617         serv_gets(buf);
618
619         if (buf[0] != '2') {
620                 display_error(&buf[4]);
621                 return;
622         }
623         extract(er_name, &buf[4], 0);
624         extract(er_password, &buf[4], 1);
625         extract(er_dirname, &buf[4], 2);
626         er_flags = extract_int(&buf[4], 3);
627         er_floor = extract_int(&buf[4], 4);
628
629
630         output_headers(1);
631
632         /* print the tabbed dialog */
633         wprintf("<TABLE border=0 width=100%%><TR BGCOLOR=FFFFFF><TD> </TD>");
634
635         if (!strcmp(tab, "admin")) {
636                 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
637         }
638         else {
639                 wprintf("<TD><A HREF=\"/display_editroom&tab=admin\">");
640         }
641         wprintf("Room administration");
642         if (!strcmp(tab, "admin")) {
643                 wprintf("</B></FONT></TD>\n");
644         }
645         else {
646                 wprintf("</A></TD>\n");
647         }
648
649         wprintf("<TD> </TD>\n");
650
651         if (!strcmp(tab, "config")) {
652                 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
653         }
654         else {
655                 wprintf("<TD><A HREF=\"/display_editroom&tab=config\">");
656         }
657         wprintf("Room configuration");
658         if (!strcmp(tab, "config")) {
659                 wprintf("</B></FONT></TD>\n");
660         }
661         else {
662                 wprintf("</A></TD>\n");
663         }
664
665         wprintf("<TD> </TD>\n");
666
667         if (!strcmp(tab, "sharing")) {
668                 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
669         }
670         else {
671                 wprintf("<TD><A HREF=\"/display_editroom&tab=sharing\">");
672         }
673         wprintf("Sharing");
674         if (!strcmp(tab, "sharing")) {
675                 wprintf("</B></FONT></TD>\n");
676         }
677         else {
678                 wprintf("</A></TD>\n");
679         }
680
681         wprintf("<TD> </TD>\n");
682
683         if (!strcmp(tab, "listserv")) {
684                 wprintf("<TD BGCOLOR=000077><FONT SIZE=+1 COLOR=\"FFFFFF\"><B>");
685         }
686         else {
687                 wprintf("<TD><A HREF=\"/display_editroom&tab=listserv\">");
688         }
689         wprintf("Mailing list service");
690         if (!strcmp(tab, "listserv")) {
691                 wprintf("</B></FONT></TD>\n");
692         }
693         else {
694                 wprintf("</A></TD>\n");
695         }
696
697         wprintf("<TD> </TD></TR></TABLE>\n");
698
699         /* end tabbed dialog */ 
700
701
702         if (!strcmp(tab, "admin")) {
703                 wprintf("<UL>"
704                         "<LI><A HREF=\"/confirm_delete_room\">\n"
705                         "Delete this room</A>\n"
706                         "<LI><A HREF=\"/display_editroompic\">\n"
707                         "Set or change the graphic for this room's banner</A>\n"
708                         "<LI><A HREF=\"/display_editinfo\">\n"
709                         "Edit this room's Info file</A>\n"
710                         "</UL>");
711         }
712
713         if (!strcmp(tab, "config")) {
714                 wprintf("<FORM METHOD=\"POST\" ACTION=\"/editroom\">\n");
715         
716                 wprintf("<UL><LI>Name of room: ");
717                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", er_name);
718         
719                 wprintf("<LI>Resides on floor: ");
720                 load_floorlist();
721                 wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
722                 for (i = 0; i < 128; ++i)
723                         if (strlen(floorlist[i]) > 0) {
724                                 wprintf("<OPTION ");
725                                 if (i == er_floor)
726                                         wprintf("SELECTED ");
727                                 wprintf("VALUE=\"%d\">", i);
728                                 escputs(floorlist[i]);
729                                 wprintf("</OPTION>\n");
730                         }
731                 wprintf("</SELECT>\n");
732         
733                 wprintf("<LI>Type of room:<UL>\n");
734
735                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
736                 if ((er_flags & QR_PRIVATE) == 0)
737                 wprintf("CHECKED ");
738                 wprintf("> Public room\n");
739
740                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
741                 if ((er_flags & QR_PRIVATE) &&
742                     (er_flags & QR_GUESSNAME))
743                         wprintf("CHECKED ");
744                 wprintf("> Private - guess name\n");
745         
746                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
747                 if ((er_flags & QR_PRIVATE) &&
748                     (er_flags & QR_PASSWORDED))
749                         wprintf("CHECKED ");
750                 wprintf("> Private - require password:\n");
751                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" VALUE=\"%s\" MAXLENGTH=\"9\">\n", er_password);
752         
753                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
754                 if ((er_flags & QR_PRIVATE)
755                     && ((er_flags & QR_GUESSNAME) == 0)
756                     && ((er_flags & QR_PASSWORDED) == 0))
757                         wprintf("CHECKED ");
758                 wprintf("> Private - invitation only\n");
759         
760                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"bump\" VALUE=\"yes\" ");
761                 wprintf("> If private, cause current users to forget room\n");
762         
763                 wprintf("</UL>\n");
764         
765                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"prefonly\" VALUE=\"yes\" ");
766                 if (er_flags & QR_PREFONLY)
767                         wprintf("CHECKED ");
768                 wprintf("> Preferred users only\n");
769         
770                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"readonly\" VALUE=\"yes\" ");
771                 if (er_flags & QR_READONLY)
772                         wprintf("CHECKED ");
773                 wprintf("> Read-only room\n");
774         
775         /* directory stuff */
776                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"directory\" VALUE=\"yes\" ");
777                 if (er_flags & QR_DIRECTORY)
778                         wprintf("CHECKED ");
779                 wprintf("> File directory room\n");
780
781                 wprintf("<UL><LI>Directory name: ");
782                 wprintf("<INPUT TYPE=\"text\" NAME=\"er_dirname\" VALUE=\"%s\" MAXLENGTH=\"14\">\n", er_dirname);
783
784                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"ulallowed\" VALUE=\"yes\" ");
785                 if (er_flags & QR_UPLOAD)
786                         wprintf("CHECKED ");
787                 wprintf("> Uploading allowed\n");
788         
789                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"dlallowed\" VALUE=\"yes\" ");
790                 if (er_flags & QR_DOWNLOAD)
791                         wprintf("CHECKED ");
792                 wprintf("> Downloading allowed\n");
793         
794                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"visdir\" VALUE=\"yes\" ");
795                 if (er_flags & QR_VISDIR)
796                         wprintf("CHECKED ");
797                 wprintf("> Visible directory</UL>\n");
798         
799         /* end of directory stuff */
800         
801                 wprintf("<LI><INPUT TYPE=\"checkbox\" NAME=\"network\" VALUE=\"yes\" ");
802                 if (er_flags & QR_NETWORK)
803                         wprintf("CHECKED ");
804                 wprintf("> Network shared room\n");
805
806         /* start of anon options */
807         
808                 wprintf("<LI>Anonymous messages<UL>\n");
809         
810                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"no\" ");
811                 if (((er_flags & QR_ANONONLY) == 0)
812                     && ((er_flags & QR_ANONOPT) == 0))
813                         wprintf("CHECKED ");
814                 wprintf("> No anonymous messages\n");
815         
816                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anononly\" ");
817                 if (er_flags & QR_ANONONLY)
818                         wprintf("CHECKED ");
819                 wprintf("> All messages are anonymous\n");
820         
821                 wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"anon\" VALUE=\"anon2\" ");
822                 if (er_flags & QR_ANONOPT)
823                         wprintf("CHECKED ");
824                 wprintf("> Prompt user when entering messages</UL>\n");
825         
826         /* end of anon options */
827         
828                 wprintf("<LI>Room aide: \n");
829                 serv_puts("GETA");
830                 serv_gets(buf);
831                 if (buf[0] != '2') {
832                         wprintf("<EM>%s</EM>\n", &buf[4]);
833                 } else {
834                         extract(er_roomaide, &buf[4], 0);
835                         wprintf("<INPUT TYPE=\"text\" NAME=\"er_roomaide\" VALUE=\"%s\" MAXLENGTH=\"25\">\n", er_roomaide);
836                 }
837         
838                 wprintf("</UL><CENTER>\n");
839                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
840                 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
841                 wprintf("</CENTER>\n");
842         }
843
844
845
846         if (!strcmp(tab, "sharing")) {
847
848                 wprintf("<CENTER>"
849                         "<FORM METHOD=\"POST\" ACTION=\"/edit_sharing\">"
850                         "<TABLE border=0><TR>"
851                         "<TD><B><I>Neighbor node</I></B></TD>"
852                         "<TD><B><I>Shared?</I></B></TD></TR>\n");
853
854                 serv_puts("CONF getsys|application/x-citadel-ignet-config");
855                 serv_gets(buf);
856                 if (buf[0]=='1') while (serv_gets(buf), strcmp(buf, "000")) {
857                         extract(node, buf, 0);
858                         wprintf("<TR>");
859                         wprintf("<TD>%s</TD>", node);
860                         wprintf("<TD>fixme</TD>");
861                         wprintf("</TR>\n");
862                 }
863
864                 wprintf("</TABLE></FORM>\n"
865                         "<I><B>Reminder:</B> When sharing a room, "
866                         "it must be shared from both ends.  Checking these "
867                         "boxes sends messages out, but in order to receive "
868                         "messages, the other nodes must be configured to send "
869                         "messages out to this system.</I><BR>"
870                         "</CENTER>\n");
871
872         }
873
874
875         wDumpContent(1);
876 }
877
878
879 /*
880  * save new parameters for a room
881  */
882 void editroom(void)
883 {
884         char buf[SIZ];
885         char er_name[20];
886         char er_password[10];
887         char er_dirname[15];
888         char er_roomaide[26];
889         int er_floor;
890         unsigned er_flags;
891         int bump;
892
893
894         if (strcmp(bstr("sc"), "OK")) {
895                 display_error("Cancelled.  Changes were not saved.");
896                 return;
897         }
898         serv_puts("GETR");
899         serv_gets(buf);
900
901         if (buf[0] != '2') {
902                 display_error(&buf[4]);
903                 return;
904         }
905         extract(er_name, &buf[4], 0);
906         extract(er_password, &buf[4], 1);
907         extract(er_dirname, &buf[4], 2);
908         er_flags = extract_int(&buf[4], 3);
909
910         strcpy(er_roomaide, bstr("er_roomaide"));
911         if (strlen(er_roomaide) == 0) {
912                 serv_puts("GETA");
913                 serv_gets(buf);
914                 if (buf[0] != '2') {
915                         strcpy(er_roomaide, "");
916                 } else {
917                         extract(er_roomaide, &buf[4], 0);
918                 }
919         }
920         strcpy(buf, bstr("er_name"));
921         buf[20] = 0;
922         if (strlen(buf) > 0)
923                 strcpy(er_name, buf);
924
925         strcpy(buf, bstr("er_password"));
926         buf[10] = 0;
927         if (strlen(buf) > 0)
928                 strcpy(er_password, buf);
929
930         strcpy(buf, bstr("er_dirname"));
931         buf[15] = 0;
932         if (strlen(buf) > 0)
933                 strcpy(er_dirname, buf);
934
935         strcpy(buf, bstr("type"));
936         er_flags &= !(QR_PRIVATE | QR_PASSWORDED | QR_GUESSNAME);
937
938         if (!strcmp(buf, "invonly")) {
939                 er_flags |= (QR_PRIVATE);
940         }
941         if (!strcmp(buf, "guessname")) {
942                 er_flags |= (QR_PRIVATE | QR_GUESSNAME);
943         }
944         if (!strcmp(buf, "passworded")) {
945                 er_flags |= (QR_PRIVATE | QR_PASSWORDED);
946         }
947         if (!strcmp(bstr("prefonly"), "yes")) {
948                 er_flags |= QR_PREFONLY;
949         } else {
950                 er_flags &= ~QR_PREFONLY;
951         }
952
953         if (!strcmp(bstr("readonly"), "yes")) {
954                 er_flags |= QR_READONLY;
955         } else {
956                 er_flags &= ~QR_READONLY;
957         }
958
959         if (!strcmp(bstr("network"), "yes")) {
960                 er_flags |= QR_NETWORK;
961         } else {
962                 er_flags &= ~QR_NETWORK;
963         }
964
965         if (!strcmp(bstr("directory"), "yes")) {
966                 er_flags |= QR_DIRECTORY;
967         } else {
968                 er_flags &= ~QR_DIRECTORY;
969         }
970
971         if (!strcmp(bstr("ulallowed"), "yes")) {
972                 er_flags |= QR_UPLOAD;
973         } else {
974                 er_flags &= ~QR_UPLOAD;
975         }
976
977         if (!strcmp(bstr("dlallowed"), "yes")) {
978                 er_flags |= QR_DOWNLOAD;
979         } else {
980                 er_flags &= ~QR_DOWNLOAD;
981         }
982
983         if (!strcmp(bstr("visdir"), "yes")) {
984                 er_flags |= QR_VISDIR;
985         } else {
986                 er_flags &= ~QR_VISDIR;
987         }
988
989         strcpy(buf, bstr("anon"));
990
991         er_flags &= ~(QR_ANONONLY | QR_ANONOPT);
992         if (!strcmp(buf, "anononly"))
993                 er_flags |= QR_ANONONLY;
994         if (!strcmp(buf, "anon2"))
995                 er_flags |= QR_ANONOPT;
996
997         bump = 0;
998         if (!strcmp(bstr("bump"), "yes"))
999                 bump = 1;
1000
1001         er_floor = atoi(bstr("er_floor"));
1002
1003         sprintf(buf, "SETR %s|%s|%s|%u|%d|%d",
1004              er_name, er_password, er_dirname, er_flags, bump, er_floor);
1005         serv_puts(buf);
1006         serv_gets(buf);
1007         if (buf[0] != '2') {
1008                 display_error(&buf[4]);
1009                 return;
1010         }
1011         gotoroom(er_name, 0);
1012
1013         if (strlen(er_roomaide) > 0) {
1014                 sprintf(buf, "SETA %s", er_roomaide);
1015                 serv_puts(buf);
1016                 serv_gets(buf);
1017                 if (buf[0] != '2') {
1018                         display_error(&buf[4]);
1019                         return;
1020                 }
1021         }
1022         smart_goto(er_name);
1023 }
1024
1025 /*
1026  * Invite, Kick, and show Who Knows a room
1027  */
1028 void display_whok(void)
1029 {
1030         char buf[SIZ], room[SIZ], username[SIZ];
1031
1032         serv_puts("GETR");
1033         serv_gets(buf);
1034
1035         if (buf[0] != '2') {
1036                 display_error(&buf[4]);
1037                 return;
1038         }
1039         extract(room, &buf[4], 0);
1040
1041         strcpy(username, bstr("username"));
1042
1043         output_headers(1);
1044
1045         if(!strcmp(bstr("sc"), "Kick")) {
1046                 sprintf(buf, "KICK %s", username);
1047                 serv_puts(buf);
1048                 serv_gets(buf);
1049
1050                 if (buf[0] != '2') {
1051                         display_error(&buf[4]);
1052                         return;
1053                 } else {
1054                         wprintf("User %s kicked out of room %s.\n", 
1055                                 username, room);
1056                 }
1057         } else if(!strcmp(bstr("sc"), "Invite")) {
1058                 sprintf(buf, "INVT %s", username);
1059                 serv_puts(buf);
1060                 serv_gets(buf);
1061
1062                 if (buf[0] != '2') {
1063                         display_error(&buf[4]);
1064                         return;
1065                 } else {
1066                         wprintf("User %s invited to room %s.\n", 
1067                                 username, room);
1068                 }
1069         }
1070         
1071
1072         wprintf("<FORM METHOD=\"POST\" ACTION=\"/display_whok\">\n");
1073         wprintf("<SELECT NAME=\"username\" SIZE=10>\n");
1074         serv_puts("WHOK");
1075         serv_gets(buf);
1076         if (buf[0] == '1') {
1077                 while (serv_gets(buf), strcmp(buf, "000")) {
1078                         extract(username, buf, 0);
1079                         wprintf("<OPTION>");
1080                         escputs(username);
1081                         wprintf("\n");
1082                 }
1083         }
1084         wprintf("</SELECT>\n");
1085
1086         wprintf("<CENTER>\n");
1087         wprintf("<input type=submit name=sc value=\"Kick\">");
1088         wprintf("</CENTER>\n");
1089         wprintf("</FORM>\n");
1090         wprintf("<FORM METHOD=\"POST\" ACTION=\"/display_whok\">\n");
1091         wprintf("Invite: ");
1092         wprintf("<input type=text name=username>\n");
1093         wprintf("<input type=hidden name=sc value=\"Invite\">");
1094         wprintf("<input type=submit value=\"Invite\">");
1095         wDumpContent(1);
1096 }
1097
1098
1099
1100 /*
1101  * display the form for entering a new room
1102  */
1103 void display_entroom(void)
1104 {
1105         int i;
1106         char buf[SIZ];
1107
1108         serv_puts("CRE8 0");
1109         serv_gets(buf);
1110
1111         if (buf[0] != '2') {
1112                 display_error(&buf[4]);
1113                 return;
1114         }
1115         output_headers(1);
1116
1117         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=000077><TR><TD>");
1118         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1119         wprintf("<B>Enter (create) a new room</B>\n");
1120         wprintf("</FONT></TD></TR></TABLE>\n");
1121
1122         wprintf("<FORM METHOD=\"POST\" ACTION=\"/entroom\">\n");
1123
1124         wprintf("<UL><LI>Name of room: ");
1125         wprintf("<INPUT TYPE=\"text\" NAME=\"er_name\" MAXLENGTH=\"19\">\n");
1126
1127         wprintf("<LI>Type of room:<UL>\n");
1128
1129         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"public\" ");
1130         wprintf("CHECKED > Public room\n");
1131
1132         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"guessname\" ");
1133         wprintf("> Private - guess name\n");
1134
1135         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"passworded\" ");
1136         wprintf("> Private - require password:\n");
1137         wprintf("<INPUT TYPE=\"text\" NAME=\"er_password\" MAXLENGTH=\"9\">\n");
1138
1139         wprintf("<LI><INPUT TYPE=\"radio\" NAME=\"type\" VALUE=\"invonly\" ");
1140         wprintf("> Private - invitation only\n");
1141         wprintf("</UL>\n");
1142
1143         wprintf("<LI>Resides on floor: ");
1144         load_floorlist(); 
1145         wprintf("<SELECT NAME=\"er_floor\" SIZE=\"1\">\n");
1146         for (i = 0; i < 128; ++i)
1147                 if (strlen(floorlist[i]) > 0) {
1148                         wprintf("<OPTION ");
1149                         wprintf("VALUE=\"%d\">", i);
1150                         escputs(floorlist[i]);
1151                         wprintf("</OPTION>\n");
1152                 }
1153         wprintf("</SELECT>\n");                
1154         wprintf("</UL>\n");
1155
1156
1157         wprintf("<CENTER>\n");
1158         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1159         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1160         wprintf("</CENTER>\n");
1161         wprintf("</FORM>\n<HR>");
1162         serv_printf("MESG roomaccess");
1163         serv_gets(buf);
1164         if (buf[0] == '1') {
1165                 fmout(NULL);
1166         }
1167         wDumpContent(1);
1168 }
1169
1170
1171
1172 /*
1173  * enter a new room
1174  */
1175 void entroom(void)
1176 {
1177         char buf[SIZ];
1178         char er_name[20];
1179         char er_type[20];
1180         char er_password[10];
1181         int er_floor;
1182         int er_num_type;
1183
1184         if (strcmp(bstr("sc"), "OK")) {
1185                 display_error("Cancelled.  No new room was created.");
1186                 return;
1187         }
1188         strcpy(er_name, bstr("er_name"));
1189         strcpy(er_type, bstr("type"));
1190         strcpy(er_password, bstr("er_password"));
1191         er_floor = atoi(bstr("er_floor"));
1192
1193         er_num_type = 0;
1194         if (!strcmp(er_type, "guessname"))
1195                 er_num_type = 1;
1196         if (!strcmp(er_type, "passworded"))
1197                 er_num_type = 2;
1198         if (!strcmp(er_type, "invonly"))
1199                 er_num_type = 3;
1200
1201         sprintf(buf, "CRE8 1|%s|%d|%s|%d", 
1202                 er_name, er_num_type, er_password, er_floor);
1203         serv_puts(buf);
1204         serv_gets(buf);
1205         if (buf[0] != '2') {
1206                 display_error(&buf[4]);
1207                 return;
1208         }
1209         smart_goto(er_name);
1210 }
1211
1212
1213 /*
1214  * display the screen to enter a private room
1215  */
1216 void display_private(char *rname, int req_pass)
1217 {
1218
1219         output_headers(1);
1220
1221         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
1222         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1223         wprintf("<B>Goto a private room</B>\n");
1224         wprintf("</FONT></TD></TR></TABLE>\n");
1225
1226         wprintf("<CENTER>\n");
1227         wprintf("If you know the name of a hidden (guess-name) or\n");
1228         wprintf("passworded room, you can enter that room by typing\n");
1229         wprintf("its name below.  Once you gain access to a private\n");
1230         wprintf("room, it will appear in your regular room listings\n");
1231         wprintf("so you don't have to keep returning here.\n");
1232         wprintf("<BR><BR>");
1233
1234         wprintf("<FORM METHOD=\"POST\" ACTION=\"/goto_private\">\n");
1235
1236         wprintf("<TABLE border><TR><TD>");
1237         wprintf("Enter room name:</TD><TD>");
1238         wprintf("<INPUT TYPE=\"text\" NAME=\"gr_name\" VALUE=\"%s\" MAXLENGTH=\"19\">\n", rname);
1239
1240         if (req_pass) {
1241                 wprintf("</TD></TR><TR><TD>");
1242                 wprintf("Enter room password:</TD><TD>");
1243                 wprintf("<INPUT TYPE=\"password\" NAME=\"gr_pass\" MAXLENGTH=\"9\">\n");
1244         }
1245         wprintf("</TD></TR></TABLE>\n");
1246
1247         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1248         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1249         wprintf("</FORM>\n");
1250         wDumpContent(1);
1251 }
1252
1253 /* 
1254  * goto a private room
1255  */
1256 void goto_private(void)
1257 {
1258         char hold_rm[32];
1259         char buf[SIZ];
1260
1261         if (strcasecmp(bstr("sc"), "OK")) {
1262                 display_main_menu();
1263                 return;
1264         }
1265         strcpy(hold_rm, WC->wc_roomname);
1266         strcpy(buf, "GOTO ");
1267         strcat(buf, bstr("gr_name"));
1268         strcat(buf, "|");
1269         strcat(buf, bstr("gr_pass"));
1270         serv_puts(buf);
1271         serv_gets(buf);
1272
1273         if (buf[0] == '2') {
1274                 smart_goto(bstr("gr_name"));
1275                 return;
1276         }
1277         if (!strncmp(buf, "540", 3)) {
1278                 display_private(bstr("gr_name"), 1);
1279                 return;
1280         }
1281         output_headers(1);
1282         wprintf("%s\n", &buf[4]);
1283         wDumpContent(1);
1284         return;
1285 }
1286
1287
1288 /*
1289  * display the screen to zap a room
1290  */
1291 void display_zap(void)
1292 {
1293         output_headers(1);
1294
1295         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
1296         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1297         wprintf("<B>Zap (forget) the current room</B>\n");
1298         wprintf("</FONT></TD></TR></TABLE>\n");
1299
1300         wprintf("If you select this option, <em>%s</em> will ", WC->wc_roomname);
1301         wprintf("disappear from your room list.  Is this what you wish ");
1302         wprintf("to do?<BR>\n");
1303
1304         wprintf("<FORM METHOD=\"POST\" ACTION=\"/zap\">\n");
1305         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"OK\">");
1306         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1307         wprintf("</FORM>\n");
1308         wDumpContent(1);
1309 }
1310
1311
1312 /* 
1313  * zap a room
1314  */
1315 void zap(void)
1316 {
1317         char buf[SIZ];
1318         char final_destination[SIZ];
1319
1320         /* If the forget-room routine fails for any reason, we fall back
1321          * to the current room; otherwise, we go to the Lobby
1322          */
1323         strcpy(final_destination, WC->wc_roomname);
1324
1325         if (!strcasecmp(bstr("sc"), "OK")) {
1326                 serv_printf("GOTO %s", WC->wc_roomname);
1327                 serv_gets(buf);
1328                 if (buf[0] != '2') {
1329                         /* ExpressMessageCat(&buf[4]);   FIXME    */
1330                 } else {
1331                         serv_puts("FORG");
1332                         serv_gets(buf);
1333                         if (buf[0] != '2') {
1334                                 /* ExpressMessageCat(&buf[4]);  FIXME   */
1335                         } else {
1336                                 strcpy(final_destination, "_BASEROOM_");
1337                         }
1338                 }
1339         }
1340         smart_goto(final_destination);
1341 }
1342
1343
1344
1345
1346 /*
1347  * Confirm deletion of the current room
1348  */
1349 void confirm_delete_room(void)
1350 {
1351         char buf[SIZ];
1352
1353         serv_puts("KILL 0");
1354         serv_gets(buf);
1355         if (buf[0] != '2') {
1356                 display_error(&buf[4]);
1357                 return;
1358         }
1359         output_headers(1);
1360         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
1361         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
1362         wprintf("<B>Confirm deletion of room</B>\n");
1363         wprintf("</FONT></TD></TR></TABLE>\n");
1364
1365         wprintf("<CENTER>");
1366         wprintf("<FORM METHOD=\"POST\" ACTION=\"/delete_room\">\n");
1367
1368         wprintf("Are you sure you want to delete <FONT SIZE=+1>");
1369         escputs(WC->wc_roomname);
1370         wprintf("</FONT>?<BR>\n");
1371
1372         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">");
1373         wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
1374
1375         wprintf("</FORM></CENTER>\n");
1376         wDumpContent(1);
1377 }
1378
1379
1380 /*
1381  * Delete the current room
1382  */
1383 void delete_room(void)
1384 {
1385         char buf[SIZ];
1386         char sc[SIZ];
1387
1388         strcpy(sc, bstr("sc"));
1389
1390         if (strcasecmp(sc, "Delete")) {
1391                 display_error("Cancelled.  This room was not deleted.");
1392                 return;
1393         }
1394         serv_puts("KILL 1");
1395         serv_gets(buf);
1396         if (buf[0] != '2') {
1397                 display_error(&buf[4]);
1398         } else {
1399                 smart_goto("_BASEROOM_");
1400         }
1401 }