]> code.citadel.org Git - citadel.git/blob - citadel/citadel.c
* NULLify 'roomrec' before attempting partial match in <G>oto
[citadel.git] / citadel / citadel.c
1 /*
2  * $Id$
3  *
4  * Main source module for the client program.
5  */
6
7 #include "sysdep.h"
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <fcntl.h>
11 #include <stdio.h>
12 #include <ctype.h>
13 #include <string.h>
14
15 #if TIME_WITH_SYS_TIME
16 # include <sys/time.h>
17 # include <time.h>
18 #else
19 # if HAVE_SYS_TIME_H
20 #  include <sys/time.h>
21 # else
22 #  include <time.h>
23 # endif
24 #endif
25
26 #include <limits.h>
27 #include <sys/types.h>
28 #include <sys/wait.h>
29 #include <sys/stat.h>
30 #include <sys/ioctl.h>
31 #include <signal.h>
32 #include <pwd.h>
33 #include <setjmp.h>
34 #include <stdarg.h>
35
36 #include "citadel.h"
37 #include "axdefs.h"
38 #include "routines.h"
39 #include "routines2.h"
40 #include "rooms.h"
41 #include "messages.h"
42 #include "commands.h"
43 #include "ipc.h"
44 #include "citadel_ipc.h"
45 #include "client_chat.h"
46 #include "client_passwords.h"
47 #include "citadel_decls.h"
48 #include "tools.h"
49 #include "acconfig.h"
50 #include "client_crypto.h"
51 #ifndef HAVE_SNPRINTF
52 #include "snprintf.h"
53 #endif
54 #include "screen.h"
55
56 #include "md5.h"
57
58 #define IFEXPERT if (userflags&US_EXPERT)
59 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
60 #define IFAIDE if (axlevel>=6)
61 #define IFNAIDE if (axlevel<6)
62
63 struct march *march = NULL;
64
65 /* globals associated with the client program */
66 char temp[PATH_MAX];            /* Name of general temp file */
67 char temp2[PATH_MAX];           /* Name of general temp file */
68 char tempdir[PATH_MAX];         /* Name of general temp dir */
69 char editor_path[SIZ];          /* path to external editor */
70 char printcmd[SIZ];             /* print command */
71 int editor_pid = (-1);
72 char fullname[32];
73 jmp_buf nextbuf;
74 struct CtdlServInfo serv_info;  /* Info on the server connected */
75 int screenwidth;
76 int screenheight;
77 unsigned room_flags;
78 char room_name[ROOMNAMELEN];
79 char *uglist[UGLISTLEN]; /* size of the ungoto list */
80 long uglistlsn[UGLISTLEN]; /* current read position for all the ungoto's. Not going to make any friends with this one. */
81 int uglistsize = 0;
82 char is_mail = 0;               /* nonzero when we're in a mail room */
83 char axlevel = 0;               /* access level */
84 char is_room_aide = 0;          /* boolean flag, 1 if room aide */
85 int timescalled;
86 int posted;
87 unsigned userflags;
88 long usernum = 0L;              /* user number */
89 time_t lastcall = 0L;           /* Date/time of previous login */
90 char newnow;
91 long highest_msg_read;          /* used for <A>bandon room cmd */
92 long maxmsgnum;                 /* used for <G>oto */
93 char sigcaught = 0;
94 char have_xterm = 0;            /* are we running on an xterm? */
95 char rc_username[32];
96 char rc_password[32];
97 char hostbuf[SIZ];
98 char portbuf[SIZ];
99 char rc_floor_mode;
100 char floor_mode;
101 char curr_floor = 0;            /* number of current floor */
102 char floorlist[128][SIZ];       /* names of floors */
103 int termn8 = 0;                 /* Set to nonzero to cause a logoff */
104 int secure;                     /* Set to nonzero when wire is encrypted */
105
106 extern char express_msgs;       /* express messages waiting! */
107 extern int rc_ansi_color;       /* ansi color value from citadel.rc */
108 extern int next_lazy_cmd;
109
110 /*
111  * here is our 'clean up gracefully and exit' routine
112  */
113 void logoff(int code)
114 {
115     int lp;
116         if (editor_pid > 0) {   /* kill the editor if it's running */
117                 kill(editor_pid, SIGHUP);
118         }
119
120     /* Free the ungoto list */
121     for (lp = 0; lp < uglistsize; lp++)
122       free (uglist[lp]);
123
124 /* shut down the server... but not if the logoff code is 3, because
125  * that means we're exiting because we already lost the server
126  */
127         if (code != 3)
128                 CtdlIPCQuit();
129
130 /*
131  * now clean up various things
132  */
133
134         screen_delete();
135
136         unlink(temp);
137         unlink(temp2);
138         nukedir(tempdir);
139
140         /* Violently kill off any child processes if Citadel is
141          * the login shell. 
142          */
143         if (getppid() == 1) {
144                 kill(0 - getpgrp(), SIGTERM);
145                 sleep(1);
146                 kill(0 - getpgrp(), SIGKILL);
147         }
148         sttybbs(SB_RESTORE);    /* return the old terminal settings */
149         exit(code);             /* exit with the proper exit code */
150 }
151
152
153
154 /*
155  * signal catching function for hangups...
156  */
157 void dropcarr(int signum)
158 {
159         logoff(SIGHUP);
160 }
161
162
163
164 /*
165  * catch SIGCONT to reset terminal modes when were are put back into the
166  * foreground.
167  */
168 void catch_sigcont(int signum)
169 {
170         sttybbs(SB_LAST);
171         signal(SIGCONT, catch_sigcont);
172 }
173
174
175
176 /* general purpose routines */
177 /* display a file */
178 void formout(char *name)
179 {
180         int r;                  /* IPC return code */
181         char buf[SIZ];
182         char *text = NULL;
183
184         r = CtdlIPCSystemMessage(name, &text, buf);
185         if (r / 100 != 1) {
186                 scr_printf("%s\n", buf);
187                 return;
188         }
189         if (text) {
190                 fmout(screenwidth, NULL, text, NULL,
191                       ((userflags & US_PAGINATOR) ? 1 : 0),
192                       screenheight, 1, 1);
193                 free(text);
194         }
195 }
196
197
198 void userlist(char *patn)
199 {
200         char buf[SIZ];
201         char fl[SIZ];
202         struct tm *tmbuf;
203         time_t lc;
204         int r;                          /* IPC response code */
205         char *listing = NULL;
206
207         r = CtdlIPCUserListing(&listing, buf);
208         if (r / 100 != 1) {
209                 pprintf("%s\n", buf);
210                 return;
211         }
212
213         pprintf("       User Name           Num  L  LastCall  Calls Posts\n");
214         pprintf("------------------------- ----- - ---------- ----- -----\n");
215         while (strlen(listing) > 0) {
216                 extract_token(buf, listing, 0, '\n');
217                 remove_token(listing, 0, '\n');
218
219                 if (sigcaught == 0) {
220                     extract(fl, buf, 0);
221                     if (pattern(fl, patn) >= 0) {
222                         pprintf("%-25s ", fl);
223                         pprintf("%5ld %d ", extract_long(buf, 2),
224                                extract_int(buf, 1));
225                         lc = extract_long(buf, 3);
226                         tmbuf = (struct tm *) localtime(&lc);
227                         pprintf("%02d/%02d/%04d ",
228                                (tmbuf->tm_mon + 1),
229                                tmbuf->tm_mday,
230                                (tmbuf->tm_year + 1900));
231                         pprintf("%5ld %5ld\n", extract_long(buf, 4), extract_long(buf, 5));
232                     }
233
234                 }
235         }
236         free(listing);
237         pprintf("\n");
238 }
239
240
241 /*
242  * grab assorted info about the user...
243  */
244 void load_user_info(char *params)
245 {
246         extract(fullname, params, 0);
247         axlevel = extract_int(params, 1);
248         timescalled = extract_int(params, 2);
249         posted = extract_int(params, 3);
250         userflags = extract_int(params, 4);
251         usernum = extract_long(params, 5);
252         lastcall = extract_long(params, 6);
253 }
254
255
256 /*
257  * Remove a room from the march list.  'floornum' is ignored unless
258  * 'roomname' is set to _FLOOR_, in which case all rooms on the requested
259  * floor will be removed from the march list.
260  */
261 void remove_march(char *roomname, int floornum)
262 {
263         struct march *mptr, *mptr2;
264
265         if (march == NULL)
266                 return;
267
268         if ((!strcasecmp(march->march_name, roomname))
269             || ((!strcasecmp(roomname, "_FLOOR_")) && (march->march_floor == floornum))) {
270                 mptr = march->next;
271                 free(march);
272                 march = mptr;
273                 return;
274         }
275         mptr2 = march;
276         for (mptr = march; mptr != NULL; mptr = mptr->next) {
277
278                 if ((!strcasecmp(mptr->march_name, roomname))
279                     || ((!strcasecmp(roomname, "_FLOOR_"))
280                         && (mptr->march_floor == floornum))) {
281
282                         mptr2->next = mptr->next;
283                         free(mptr);
284                         mptr = mptr2;
285                 } else {
286                         mptr2 = mptr;
287                 }
288         }
289 }
290
291
292 /*
293  * Locate the room on the march list which we most want to go to.  Each room
294  * is measured given a "weight" of preference based on various factors.
295  */
296 char *pop_march(int desired_floor)
297 {
298         static char TheRoom[ROOMNAMELEN];
299         int TheFloor = 0;
300         int TheOrder = 32767;
301         int TheWeight = 0;
302         int weight;
303         struct march *mptr = NULL;
304
305         strcpy(TheRoom, "_BASEROOM_");
306         if (march == NULL)
307                 return (TheRoom);
308
309         for (mptr = march; mptr != NULL; mptr = mptr->next) {
310                 weight = 0;
311                 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
312                         weight = weight + 10000;
313                 if (mptr->march_floor == desired_floor)
314                         weight = weight + 5000;
315
316                 weight = weight + ((128 - (mptr->march_floor)) * 128);
317                 weight = weight + (128 - (mptr->march_order));
318
319                 if (weight > TheWeight) {
320                         TheWeight = weight;
321                         strcpy(TheRoom, mptr->march_name);
322                         TheFloor = mptr->march_floor;
323                         TheOrder = mptr->march_order;
324                 }
325         }
326         return (TheRoom);
327 }
328
329
330 /*
331  * jump directly to a room
332  */
333 void dotgoto(char *towhere, int display_name, int fromungoto)
334 {
335         char aaa[SIZ], bbb[SIZ], psearch[SIZ];
336         static long ls = 0L;
337         int newmailcount = 0;
338         static int oldmailcount = (-1);
339         int partial_match, best_match;
340         char from_floor;
341         int ugpos = uglistsize;
342         int r;                          /* IPC result code */
343         struct ctdlipcroom *roomrec = NULL;
344
345         /* store ungoto information */
346         if (fromungoto == 0) {
347                 /* sloppy slide them all down, hey it's the client, who cares. :-) */
348                 if (uglistsize >= (UGLISTLEN-1)) {
349                         int lp;
350                         free (uglist[0]);
351                         for (lp = 0; lp < (UGLISTLEN-1); lp++) {
352                                 uglist[lp] = uglist[lp+1];
353                                 uglistlsn[lp] = uglistlsn[lp+1];
354                         }
355                         ugpos--;
356                 } else
357                         uglistsize++;
358         
359                 uglist[ugpos] = malloc(strlen(room_name)+1);
360                 strcpy(uglist[ugpos], room_name);
361                 uglistlsn[ugpos] = ls;
362         }
363       
364         /* first try an exact match */
365         r = CtdlIPCGotoRoom(towhere, "", &roomrec, aaa);
366         if (r / 10 == 54) {
367                 newprompt("Enter room password: ", bbb, 9);
368                 r = CtdlIPCGotoRoom(towhere, bbb, &roomrec, aaa);
369                 if (r / 10 == 54) {
370                         scr_printf("Wrong password.\n");
371                         return;
372                 }
373         }       
374
375         /*
376          * If a match is not found, try a partial match.
377          * Partial matches anywhere in the string carry a weight of 1,
378          * left-aligned matches carry a weight of 2.  Pick the room that
379          * has the highest-weighted match.
380          */
381         if (r / 100 != 2) {
382                 best_match = 0;
383                 strcpy(bbb, "");
384                 serv_puts("LKRA");
385                 serv_gets(aaa);
386                 if (aaa[0] == '1')
387                         while (serv_gets(aaa), strcmp(aaa, "000")) {
388                                 extract(psearch, aaa, 0);
389                                 partial_match = 0;
390                                 if (pattern(psearch, towhere) >= 0) {
391                                         partial_match = 1;
392                                 }
393                                 if (!strncasecmp(towhere, psearch, strlen(towhere))) {
394                                         partial_match = 2;
395                                 }
396                                 if (partial_match > best_match) {
397                                         strcpy(bbb, psearch);
398                                         best_match = partial_match;
399                                 }
400                         }
401                 if (strlen(bbb) == 0) {
402                         scr_printf("No room '%s'.\n", towhere);
403                         return;
404                 }
405                 roomrec = NULL;
406                 r = CtdlIPCGotoRoom(bbb, "", &roomrec, aaa);
407         }
408         if (r / 100 != 2) {
409                 scr_printf("%s\n", aaa);
410                 return;
411         }
412         safestrncpy(room_name, roomrec->RRname, ROOMNAMELEN);
413         room_flags = roomrec->RRflags;
414         from_floor = curr_floor;
415         curr_floor = roomrec->RRfloor;
416
417         remove_march(room_name, 0);
418         if (!strcasecmp(towhere, "_BASEROOM_"))
419                 remove_march(towhere, 0);
420         if (!roomrec->RRunread)
421                 next_lazy_cmd = 5;      /* Don't read new if no new msgs */
422         if ((from_floor != curr_floor) && (display_name > 0) && (floor_mode == 1)) {
423                 if (floorlist[(int) curr_floor][0] == 0)
424                         load_floorlist();
425                 scr_printf("(Entering floor: %s)\n", &floorlist[(int) curr_floor][0]);
426         }
427         if (display_name == 1) {
428                 color(BRIGHT_WHITE);
429                 scr_printf("%s ", room_name);
430                 color(DIM_WHITE);
431                 scr_printf("- ");
432         }
433         if (display_name != 2) {
434                 color(BRIGHT_YELLOW);
435                 scr_printf("%d ", roomrec->RRunread);
436                 color(DIM_WHITE);
437                 scr_printf("new of ");
438                 color(BRIGHT_YELLOW);
439                 scr_printf("%d ", roomrec->RRtotal);
440                 color(DIM_WHITE);
441                 scr_printf("messages.\n");
442         }
443         highest_msg_read = roomrec->RRlastread;
444         maxmsgnum = roomrec->RRhighest;
445         is_mail = roomrec->RRismailbox;
446         is_room_aide = roomrec->RRaide;
447         ls = roomrec->RRlastread;
448
449         /* read info file if necessary */
450         if (roomrec->RRinfoupdated > 0)
451                 readinfo();
452
453         /* check for newly arrived mail if we can */
454         newmailcount = roomrec->RRnewmail;
455         if (newmailcount > 0) {
456                 color(BRIGHT_RED);
457                 scr_printf("*** You have %d new mail message%s\n",
458                                 newmailcount - oldmailcount,
459                                 (newmailcount - oldmailcount == 1) ?
460                                 "" : "s");
461                 color(DIM_WHITE);
462         }
463         status_line(serv_info.serv_humannode, serv_info.serv_bbs_city,
464                         room_name, secure, newmailcount);
465 }
466
467 /* Goto next room having unread messages.
468  * We want to skip over rooms that the user has already been to, and take the
469  * user back to the lobby when done.  The room we end up in is placed in
470  * newroom - which is set to 0 (the lobby) initially.
471  */
472 void gotonext(void)
473 {
474         char buf[SIZ];
475         struct march *mptr, *mptr2;
476         char next_room[ROOMNAMELEN];
477         int r;                          /* IPC response code */
478
479         /* Check to see if the march-mode list is already allocated.
480          * If it is, pop the first room off the list and go there.
481          */
482         if (march == NULL) {
483                 r = CtdlIPCKnownRooms(1, -1, &march, buf);
484 /* add _BASEROOM_ to the end of the march list, so the user will end up
485  * in the system base room (usually the Lobby>) at the end of the loop
486  */
487                 mptr = (struct march *) malloc(sizeof(struct march));
488                 mptr->next = NULL;
489                 strcpy(mptr->march_name, "_BASEROOM_");
490                 if (march == NULL) {
491                         march = mptr;
492                 } else {
493                         mptr2 = march;
494                         while (mptr2->next != NULL)
495                                 mptr2 = mptr2->next;
496                         mptr2->next = mptr;
497                 }
498 /*
499  * ...and remove the room we're currently in, so a <G>oto doesn't make us
500  * walk around in circles
501  */
502                 remove_march(room_name, 0);
503         }
504         if (march != NULL) {
505                 strcpy(next_room, pop_march(curr_floor));
506         } else {
507                 strcpy(next_room, "_BASEROOM_");
508         }
509         remove_march(next_room, 0);
510         dotgoto(next_room, 1, 0);
511 }
512
513 /*
514  * forget all rooms on a given floor
515  */
516 void forget_all_rooms_on(int ffloor)
517 {
518         char buf[SIZ];
519         struct march *flist, *fptr;
520         struct ctdlipcroom *roomrec;    /* Ignored */
521         int r;                          /* IPC response code */
522
523         scr_printf("Forgetting all rooms on %s...\r", &floorlist[ffloor][0]);
524         scr_flush();
525         snprintf(buf, sizeof buf, "LKRA %d", ffloor);
526         serv_puts(buf);
527         serv_gets(buf);
528         if (buf[0] != '1') {
529                 scr_printf("%-72s\n", &buf[4]);
530                 return;
531         }
532         flist = NULL;
533         while (serv_gets(buf), strcmp(buf, "000")) {
534                 fptr = (struct march *) malloc(sizeof(struct march));
535                 fptr->next = flist;
536                 flist = fptr;
537                 extract(fptr->march_name, buf, 0);
538         }
539         while (flist != NULL) {
540                 r = CtdlIPCGotoRoom(flist->march_name, "", &roomrec, buf);
541                 if (r / 100 == 2) {
542                         r = CtdlIPCForgetRoom(buf);
543                 }
544                 fptr = flist;
545                 flist = flist->next;
546                 free(fptr);
547         }
548         scr_printf("%-72s\r", "");
549 }
550
551
552 /*
553  * routine called by gotofloor() to move to a new room on a new floor
554  */
555 void gf_toroom(char *towhere, int mode)
556 {
557         int floor_being_left;
558
559         floor_being_left = curr_floor;
560
561         if (mode == GF_GOTO) {  /* <;G>oto mode */
562                 updatels();
563                 dotgoto(towhere, 1, 0);
564         }
565         if (mode == GF_SKIP) {  /* <;S>kip mode */
566                 dotgoto(towhere, 1, 0);
567                 remove_march("_FLOOR_", floor_being_left);
568         }
569         if (mode == GF_ZAP) {   /* <;Z>ap mode */
570                 dotgoto(towhere, 1, 0);
571                 remove_march("_FLOOR_", floor_being_left);
572                 forget_all_rooms_on(floor_being_left);
573         }
574 }
575
576
577 /*
578  * go to a new floor
579  */
580 void gotofloor(char *towhere, int mode)
581 {
582         int a, tofloor;
583         struct march *mptr;
584         char buf[SIZ], targ[SIZ];
585
586         if (floorlist[0][0] == 0)
587                 load_floorlist();
588         tofloor = (-1);
589         for (a = 0; a < 128; ++a)
590                 if (!strcasecmp(&floorlist[a][0], towhere))
591                         tofloor = a;
592
593         if (tofloor < 0) {
594                 for (a = 0; a < 128; ++a) {
595                         if (!strncasecmp(&floorlist[a][0], towhere, strlen(towhere))) {
596                                 tofloor = a;
597                         }
598                 }
599         }
600         if (tofloor < 0) {
601                 for (a = 0; a < 128; ++a)
602                         if (pattern(towhere, &floorlist[a][0]) > 0)
603                                 tofloor = a;
604         }
605         if (tofloor < 0) {
606                 scr_printf("No floor '%s'.\n", towhere);
607                 return;
608         }
609         for (mptr = march; mptr != NULL; mptr = mptr->next) {
610                 if ((mptr->march_floor) == tofloor)
611                         gf_toroom(mptr->march_name, mode);
612                 return;
613         }
614
615         strcpy(targ, "");
616         snprintf(buf, sizeof buf, "LKRA %d", tofloor);
617         serv_puts(buf);
618         serv_gets(buf);
619         if (buf[0] == '1')
620                 while (serv_gets(buf), strcmp(buf, "000")) {
621                         if ((extract_int(buf, 2) == tofloor) && (strlen(targ) == 0))
622                                 extract(targ, buf, 0);
623                 }
624         if (strlen(targ) > 0) {
625                 gf_toroom(targ, mode);
626         } else {
627                 scr_printf("There are no rooms on '%s'.\n", &floorlist[tofloor][0]);
628         }
629 }
630
631
632 /*
633  * forget all rooms on current floor
634  */
635 void forget_this_floor(void)
636 {
637
638         if (curr_floor == 0) {
639                 scr_printf("Can't forget this floor.\n");
640                 return;
641         }
642         if (floorlist[0][0] == 0)
643                 load_floorlist();
644         scr_printf("Are you sure you want to forget all rooms on %s? ",
645                &floorlist[(int) curr_floor][0]);
646         if (yesno() == 0)
647                 return;
648
649         gf_toroom("_BASEROOM_", GF_ZAP);
650 }
651
652
653 /* 
654  * Figure out the physical screen dimensions, if we can
655  * WARNING:  this is now called from a signal handler!
656  */
657 void check_screen_dims(void)
658 {
659 #ifdef TIOCGWINSZ
660         struct {
661                 unsigned short height;  /* rows */
662                 unsigned short width;   /* columns */
663                 unsigned short xpixels;
664                 unsigned short ypixels;         /* pixels */
665         } xwinsz;
666
667         if (have_xterm) {       /* dynamically size screen if on an xterm */
668                 if (ioctl(0, TIOCGWINSZ, &xwinsz) == 0) {
669                         if (xwinsz.height)
670                                 screenheight = is_curses_enabled() ? (int)xwinsz.height - 1 : (int) xwinsz.height;
671                         if (xwinsz.width)
672                                 screenwidth = (int) xwinsz.width;
673                 }
674         }
675 #endif
676 }
677
678
679 /*
680  * set floor mode depending on client, server, and user settings
681  */
682 void set_floor_mode(void)
683 {
684         if (serv_info.serv_ok_floors == 0) {
685                 floor_mode = 0; /* Don't use floors if the server */
686         }
687         /* doesn't support them!          */
688         else {
689                 if (rc_floor_mode == RC_NO) {   /* never use floors */
690                         floor_mode = 0;
691                 }
692                 if (rc_floor_mode == RC_YES) {  /* always use floors */
693                         floor_mode = 1;
694                 }
695                 if (rc_floor_mode == RC_DEFAULT) {      /* user choice */
696                         floor_mode = ((userflags & US_FLOORS) ? 1 : 0);
697                 }
698         }
699 }
700
701 /*
702  * Set or change the user's password
703  */
704 int set_password(void)
705 {
706         char pass1[20];
707         char pass2[20];
708         char buf[SIZ];
709
710         if (strlen(rc_password) > 0) {
711                 strcpy(pass1, rc_password);
712                 strcpy(pass2, rc_password);
713         } else {
714                 IFNEXPERT formout("changepw");
715                 newprompt("Enter a new password: ", pass1, -19);
716                 newprompt("Enter it again to confirm: ", pass2, -19);
717         }
718         strproc(pass1);
719         strproc(pass2);
720         if (!strcasecmp(pass1, pass2)) {
721                 CtdlIPCChangePassword(pass1, buf);
722                 scr_printf("%s\n", buf);
723                 offer_to_remember_password(hostbuf, portbuf, fullname, pass1);
724                 return (0);
725         } else {
726                 scr_printf("*** They don't match... try again.\n");
727                 return (1);
728         }
729 }
730
731
732
733 /*
734  * get info about the server we've connected to
735  */
736 void get_serv_info(char *supplied_hostname)
737 {
738         char buf[SIZ];
739
740         CtdlIPCServerInfo(&serv_info, buf);
741
742         /* be nice and identify ourself to the server */
743         CtdlIPCIdentifySoftware(SERVER_TYPE, 0, REV_LEVEL,
744                  (server_is_local ? "local" : CITADEL),
745                  (supplied_hostname) ? supplied_hostname : "", buf);
746                  /* (locate_host(buf), buf)); */
747 }
748
749
750
751
752
753 /*
754  * Display list of users currently logged on to the server
755  */
756 void who_is_online(int longlist)
757 {
758         char buf[SIZ], username[SIZ], roomname[SIZ], fromhost[SIZ];
759         char flags[SIZ];
760         char actual_user[SIZ], actual_room[SIZ], actual_host[SIZ];
761         char tbuf[SIZ], clientsoft[SIZ];
762         time_t timenow = 0;
763         time_t idletime, idlehours, idlemins, idlesecs;
764         int last_session = (-1);
765         int skipidle = 0;
766         char *listing = NULL;
767         int r;                          /* IPC response code */
768     
769         if (longlist == 2) {
770                 longlist = 0;
771                 skipidle = 1;
772         }
773
774         if (!longlist) {
775                 color(BRIGHT_WHITE);
776                 pprintf("FLG ###        User Name                 Room                 From host\n");
777                 color(DIM_WHITE);
778                 pprintf("--- --- ------------------------- -------------------- ------------------------\n");
779         }
780         r = CtdlIPCOnlineUsers(&listing, &timenow, buf);
781         if (r / 100 == 1) {
782                 while (strlen(listing) > 0) {
783                         int isidle = 0;
784                         
785                         /* Get another line */
786                         extract_token(buf, listing, 0, '\n');
787                         remove_token(listing, 0, '\n');
788
789                         extract(username, buf, 1);
790                         extract(roomname, buf, 2);
791                         extract(fromhost, buf, 3);
792                         extract(clientsoft, buf, 4);
793                         extract(flags, buf, 7);
794
795                         idletime = timenow - extract_long(buf, 5);
796                         idlehours = idletime / 3600;
797                         idlemins = (idletime - (idlehours * 3600)) / 60;
798                         idlesecs = (idletime - (idlehours * 3600) - (idlemins * 60));
799
800                         if (idletime > rc_idle_threshold) {
801                                 while (strlen(roomname) < 20) {
802                                         strcat(roomname, " ");
803                                 }
804                                 strcpy(&roomname[14], "[idle]");
805                                 if (skipidle)
806                                         isidle = 1;
807                         }
808
809                         if (longlist) {
810                                 extract(actual_user, buf, 8);
811                                 extract(actual_room, buf, 9);
812                                 extract(actual_host, buf, 10);
813
814                                 pprintf("  Flags: %s\n", flags);
815                                 pprintf("Session: %d\n", extract_int(buf, 0));
816                                 pprintf("   Name: %s\n", username);
817                                 pprintf("In room: %s\n", roomname);
818                                 pprintf("   Host: %s\n", fromhost);
819                                 pprintf(" Client: %s\n", clientsoft);
820                                 pprintf("   Idle: %ld:%02ld:%02ld\n",
821                                         (long) idlehours,
822                                         (long) idlemins,
823                                         (long) idlesecs);
824
825                                 if ( (strlen(actual_user)+strlen(actual_room)+strlen(actual_host)) > 0) {
826                                         pprintf("(really ");
827                                         if (strlen(actual_user)>0) pprintf("<%s> ", actual_user);
828                                         if (strlen(actual_room)>0) pprintf("in <%s> ", actual_room);
829                                         if (strlen(actual_host)>0) pprintf("from <%s> ", actual_host);
830                                         pprintf(")\n");
831                                 }
832                                 pprintf("\n");
833
834                         } else {
835                     if (isidle == 0) {
836                                 if (extract_int(buf, 0) == last_session) {
837                                         pprintf("        ");
838                                 } else {
839                                         color(BRIGHT_MAGENTA);
840                                         pprintf("%-3s ", flags);
841                                         color(DIM_WHITE);
842                                         pprintf("%-3d ", extract_int(buf, 0));
843                                 }
844                                 last_session = extract_int(buf, 0);
845                                 color(BRIGHT_CYAN);
846                                 pprintf("%-25s ", username);
847                                 color(BRIGHT_MAGENTA);
848                                 roomname[20] = 0;
849                                 pprintf("%-20s ", roomname);
850                                 color(BRIGHT_CYAN);
851                                 fromhost[24] = '\0';
852                                 pprintf("%-24s\n", fromhost);
853                                 color(DIM_WHITE);
854                         }
855                         }
856                 }
857         }
858         free(listing);
859 }
860
861 void enternew(char *desc, char *buf, int maxlen)
862 {
863         char bbb[128];
864         snprintf(bbb, sizeof bbb, "Enter in your new %s: ", desc);
865         newprompt(bbb, buf, maxlen);
866 }
867
868
869
870 int shift(int argc, char **argv, int start, int count) {
871         int i;
872
873         for (i=start; i<(argc-count); ++i) {
874                 argv[i] = argv[i+count];
875         }
876         argc = argc - count;
877         return argc;
878 }
879
880 static void statusHook(char *s) {
881         sln_printf(s);
882         sln_flush();
883 }
884
885 /*
886  * main
887  */
888 int main(int argc, char **argv)
889 {
890         int a, b, mcmd;
891         char aaa[100], bbb[100];/* general purpose variables */
892         char argbuf[32];        /* command line buf */
893         char nonce[NONCE_SIZE];
894         char *telnet_client_host = NULL;
895         char *sptr, *sptr2;     /* USed to extract the nonce */
896         char hexstring[MD5_HEXSTRING_SIZE];
897         int stored_password = 0;
898         char password[SIZ];
899         struct ctdlipcmisc chek;
900         struct usersupp *myself = NULL;
901         int r;                          /* IPC result code */
902
903         setIPCDeathHook(screen_delete);
904         setIPCErrorPrintf(err_printf);
905         setCryptoStatusHook(statusHook);
906         
907         /* Permissions sanity check - don't run citadel setuid/setgid */
908         if (getuid() != geteuid()) {
909                 err_printf("Please do not run citadel setuid!\n");
910                 logoff(3);
911         } else if (getgid() != getegid()) {
912                 err_printf("Please do not run citadel setgid!\n");
913                 logoff(3);
914         }
915
916         sttybbs(SB_SAVE);       /* Store the old terminal parameters */
917         load_command_set();     /* parse the citadel.rc file */
918         sttybbs(SB_NO_INTR);    /* Install the new ones */
919         signal(SIGHUP, dropcarr);       /* Cleanup gracefully if carrier is dropped */
920         signal(SIGTERM, dropcarr);      /* Cleanup gracefully if terminated */
921         signal(SIGCONT, catch_sigcont); /* Catch SIGCONT so we can reset terminal */
922 #ifdef SIGWINCH
923         signal(SIGWINCH, scr_winch);    /* Window resize signal */
924 #endif
925
926 #ifdef HAVE_OPENSSL
927         arg_encrypt = RC_DEFAULT;
928 #endif
929 #ifdef HAVE_CURSES_H
930         arg_screen = RC_DEFAULT;
931 #endif
932
933         /* 
934          * Handle command line options as if we were called like /bin/login
935          * (i.e. from in.telnetd)
936          */
937         for (a=0; a<argc; ++a) {
938                 if ((argc > a+1) && (!strcmp(argv[a], "-h")) ) {
939                         telnet_client_host = argv[a+1];
940                         argc = shift(argc, argv, a, 2);
941                 }
942                 if (!strcmp(argv[a], "-x")) {
943 #ifdef HAVE_OPENSSL
944                         arg_encrypt = RC_NO;
945 #endif
946                         argc = shift(argc, argv, a, 1);
947                 }
948                 if (!strcmp(argv[a], "-X")) {
949 #ifdef HAVE_OPENSSL
950                         arg_encrypt = RC_YES;
951                         argc = shift(argc, argv, a, 1);
952 #else
953                         fprintf(stderr, "Not compiled with encryption support");
954                         return 1;
955 #endif
956                 }
957                 if (!strcmp(argv[a], "-s")) {
958 #ifdef HAVE_CURSES_H
959                         arg_screen = RC_NO;
960 #endif
961                         argc = shift(argc, argv, a, 1);
962                 }
963                 if (!strcmp(argv[a], "-S")) {
964 #ifdef HAVE_CURSES_H
965                         arg_screen = RC_YES;
966 #endif
967                         argc = shift(argc, argv, a, 1);
968                 }
969                 if (!strcmp(argv[a], "-p")) {
970                         struct stat st;
971                 
972                         if (chdir(BBSDIR) < 0) {
973                                 perror("can't change to " BBSDIR);
974                                 logoff(3);
975                         }
976
977                         /*
978                          * Drop privileges if necessary. We stat
979                          * citadel.config to get the uid/gid since it's
980                          * guaranteed to have the uid/gid we want.
981                          */
982                         if (!getuid() || !getgid()) {
983                                 if (stat(BBSDIR "/citadel.config", &st) < 0) {
984                                         perror("couldn't stat citadel.config");
985                                         logoff(3);
986                                 }
987                                 if (!getgid() && (setgid(st.st_gid) < 0)) {
988                                         perror("couldn't change gid");
989                                         logoff(3);
990                                 }
991                                 if (!getuid() && (setuid(st.st_uid) < 0)) {
992                                         perror("couldn't change uid");
993                                         logoff(3);
994                                 }
995                                 /*
996                                 scr_printf("Privileges changed to uid %d gid %d\n",
997                                                 getuid(), getgid());
998                                 */
999                         }
1000                         argc = shift(argc, argv, a, 1);
1001                 }
1002         }
1003
1004         screen_new();
1005
1006         sln_printf("Attaching to server... \r");
1007         sln_flush();
1008         attach_to_server(argc, argv, hostbuf, portbuf);
1009
1010         serv_gets(aaa);
1011         if (aaa[0] != '2') {
1012                 scr_printf("%s\n", &aaa[4]);
1013                 logoff(atoi(aaa));
1014         }
1015
1016 /* If there is a [nonce] at the end, put the nonce in <nonce>, else nonce
1017  * is zeroized.
1018  */
1019         
1020         if ((sptr = strchr(aaa, '<')) == NULL)
1021         {
1022            nonce[0] = '\0';
1023         }
1024         else
1025         {
1026            if ((sptr2 = strchr(sptr, '>')) == NULL)
1027            {
1028               nonce[0] = '\0';
1029            }
1030            else
1031            {
1032               sptr2++;
1033               *sptr2 = '\0';
1034               strncpy(nonce, sptr, NONCE_SIZE);
1035            }
1036         }
1037
1038         get_serv_info(telnet_client_host);
1039
1040         scr_printf("%-24s\n%s\n%s\n", serv_info.serv_software, serv_info.serv_humannode,
1041                 serv_info.serv_bbs_city);
1042         scr_flush();
1043
1044         secure = starttls();
1045         status_line(serv_info.serv_humannode, serv_info.serv_bbs_city, NULL,
1046                         secure, -1);
1047
1048         screenwidth = 80;       /* default screen dimensions */
1049         screenheight = 24;
1050         
1051         scr_printf(" pause    next    stop\n");
1052         scr_printf(" ctrl-s  ctrl-o  ctrl-c\n\n");
1053         formout("hello");       /* print the opening greeting */
1054         scr_printf("\n");
1055
1056 GSTA:   /* See if we have a username and password on disk */
1057         if (rc_remember_passwords) {
1058                 get_stored_password(hostbuf, portbuf, fullname, password);
1059                 if (strlen(fullname) > 0) {
1060                         snprintf(aaa, sizeof(aaa)-1, "USER %s", fullname);
1061                         serv_puts(aaa);
1062                         serv_gets(aaa);
1063                         if (nonce[0])
1064                         {
1065                                 snprintf(aaa, sizeof aaa, "PAS2 %s", make_apop_string(password, nonce, hexstring, sizeof hexstring));
1066                         }
1067                         else    /* Else no APOP */
1068                         {
1069                                 snprintf(aaa, sizeof(aaa)-1, "PASS %s", password);
1070                         }
1071                         
1072                         serv_puts(aaa);
1073                         serv_gets(aaa);
1074                         if (aaa[0] == '2') {
1075                                 load_user_info(&aaa[4]);
1076                                 stored_password = 1;
1077                                 goto PWOK;
1078                         }
1079                         else {
1080                                 set_stored_password(hostbuf, portbuf, "", "");
1081                         }
1082                 }
1083         }
1084
1085         termn8 = 0;
1086         newnow = 0;
1087         do {
1088                 if (strlen(rc_username) > 0) {
1089                         strcpy(fullname, rc_username);
1090                 } else {
1091                         newprompt("Enter your name: ", fullname, 29);
1092                 }
1093                 strproc(fullname);
1094                 if (!strcasecmp(fullname, "new")) {     /* just in case */
1095                         scr_printf("Please enter the name you wish to log in with.\n");
1096                 }
1097         } while (
1098                         (!strcasecmp(fullname, "bbs"))
1099                         || (!strcasecmp(fullname, "new"))
1100                         || (strlen(fullname) == 0));
1101
1102         if (!strcasecmp(fullname, "off")) {
1103                 mcmd = 29;
1104                 goto TERMN8;
1105         }
1106         /* sign on to the server */
1107         r = CtdlIPCTryLogin(fullname, aaa);
1108         if (r / 100 != 3)
1109                 goto NEWUSR;
1110
1111         /* password authentication */
1112         if (strlen(rc_password) > 0) {
1113                 strcpy(password, rc_password);
1114         } else {
1115                 newprompt("\rPlease enter your password: ", password, -19);
1116         }
1117         strproc(password);
1118
1119         if (nonce[0])
1120         {
1121                 snprintf(aaa, sizeof aaa, "PAS2 %s", make_apop_string(password, nonce, hexstring, sizeof hexstring));
1122         }
1123         else    /* Else no APOP */
1124         {
1125                 snprintf(aaa, sizeof aaa, "PASS %s", password);
1126         }
1127         
1128         serv_puts(aaa);
1129         serv_gets(aaa);
1130         if (aaa[0] == '2') {
1131                 load_user_info(&aaa[4]);
1132                 offer_to_remember_password(hostbuf, portbuf,
1133                                         fullname, password);
1134                 goto PWOK;
1135         }
1136         scr_printf("<< wrong password >>\n");
1137         if (strlen(rc_password) > 0)
1138                 logoff(0);
1139         goto GSTA;
1140
1141 NEWUSR: if (strlen(rc_password) == 0) {
1142                 scr_printf("No record. Enter as new user? ");
1143                 if (yesno() == 0)
1144                         goto GSTA;
1145         }
1146         snprintf(aaa, sizeof aaa, "NEWU %s", fullname);
1147         serv_puts(aaa);
1148         serv_gets(aaa);
1149         if (aaa[0] != '2') {
1150                 scr_printf("%s\n", aaa);
1151                 goto GSTA;
1152         }
1153         load_user_info(&aaa[4]);
1154
1155         while (set_password() != 0);;
1156         newnow = 1;
1157
1158         enter_config(1);
1159
1160 PWOK:
1161         /* Switch color support on or off if we're in user mode */
1162         if (rc_ansi_color == 3) {
1163                 if (userflags & US_COLOR)
1164                         enable_color = 1;
1165                 else
1166                         enable_color = 0;
1167         }
1168
1169         scr_printf("%s\nAccess level: %d (%s)\n"
1170                 "User #%ld / Login #%d",
1171                 fullname, axlevel, axdefs[(int) axlevel],
1172                 usernum, timescalled);
1173         if (lastcall > 0L) {
1174                 scr_printf(" / Last login: %s\n",
1175                         asctime(localtime(&lastcall)) );
1176         }
1177         scr_printf("\n");
1178
1179         r = CtdlIPCMiscCheck(&chek, aaa);
1180         if (r / 100 == 2) {
1181                 b = chek.newmail;
1182                 if (b > 0) {
1183                         color(BRIGHT_RED);
1184                         if (b == 1)
1185                                 scr_printf("*** You have a new private message in Mail>\n");
1186                         if (b > 1)
1187                                 scr_printf("*** You have %d new private messages in Mail>\n", b);
1188                         color(DIM_WHITE);
1189                 }
1190                 if ((axlevel >= 6) && (chek.needvalid > 0)) {
1191                         scr_printf("*** Users need validation\n");
1192                 }
1193                 if (chek.needregis > 0) {
1194                         scr_printf("*** Please register.\n");
1195                         formout("register");
1196                         entregis();
1197                 }
1198         }
1199         /* Make up some temporary filenames for use in various parts of the
1200          * program.  Don't mess with these once they've been set, because we
1201          * will be unlinking them later on in the program and we don't
1202          * want to delete something that we didn't create. */
1203         snprintf(temp, sizeof temp, tmpnam(NULL));
1204         snprintf(temp2, sizeof temp2, tmpnam(NULL));
1205         snprintf(tempdir, sizeof tempdir, tmpnam(NULL));
1206
1207         /* Get screen dimensions.  First we go to a default of 80x24.  Then
1208          * we try to get the user's actual screen dimensions off the server.
1209          * However, if we're running on an xterm, all this stuff is
1210          * irrelevant because we're going to dynamically size the screen
1211          * during the session.
1212          */
1213         screenwidth = 80;
1214         screenheight = 24;
1215         r = CtdlIPCGetConfig(&myself, aaa);
1216         if (r == 2) {
1217                 screenwidth = myself->USscreenwidth;
1218                 screenheight = myself->USscreenheight;
1219         }
1220         if (getenv("TERM") != NULL)
1221                 if (!strcmp(getenv("TERM"), "xterm")) {
1222                         have_xterm = 1;
1223                 }
1224 #ifdef TIOCGWINSZ
1225         check_screen_dims();
1226 #endif
1227
1228         set_floor_mode();
1229
1230
1231         /* Enter the lobby */
1232         dotgoto("_BASEROOM_", 1, 0);
1233
1234 /* Main loop for the system... user is logged in. */
1235     uglistsize = 0;
1236
1237         if (newnow == 1)
1238                 readmsgs(3, 1, 5);
1239         else
1240                 readmsgs(1, 1, 0);
1241
1242         /* MAIN COMMAND LOOP */
1243         do {
1244                 mcmd = getcmd(argbuf);          /* Get keyboard command */
1245
1246 #ifdef TIOCGWINSZ
1247                 check_screen_dims();            /* if xterm, get screen size */
1248 #endif
1249
1250                 if (termn8 == 0)
1251                         switch (mcmd) {
1252                         case 1:
1253                                 formout("help");
1254                                 break;
1255                         case 4:
1256                                 entmsg(0, 0);
1257                                 break;
1258                         case 36:
1259                                 entmsg(0, 1);
1260                                 break;
1261                         case 46:
1262                                 entmsg(0, 2);
1263                                 break;
1264                         case 78:
1265                                 newprompt("What do you want your username to be? ", aaa, 32);
1266                                 snprintf(bbb, sizeof bbb, "ENT0 2|0|0|0|%s", aaa);
1267                                 serv_puts(bbb);
1268                                 serv_gets(aaa);
1269                                 if (strncmp("200", aaa, 3))
1270                                         scr_printf("\n%s\n", aaa);
1271                                 else
1272                                         entmsg(0, 0);
1273                                 break;
1274                         case 5:
1275                                 updatels();
1276                                 gotonext();
1277                                 break;
1278                         case 47:
1279                                 if (!rc_alt_semantics)
1280                                         updatelsa();
1281                                 gotonext();
1282                                 break;
1283                         case 90:
1284                                 if (!rc_alt_semantics)
1285                                         updatelsa();
1286                                 dotgoto(argbuf, 0, 0);
1287                                 break;
1288                         case 58:
1289                                 updatelsa();
1290                                 dotgoto("_MAIL_", 1, 0);
1291                                 break;
1292                         case 20:
1293                                 updatels();
1294                                 dotgoto(argbuf, 0, 0);
1295                                 break;
1296                         case 52:
1297                                 if (rc_alt_semantics)
1298                                         updatelsa();
1299                                 dotgoto(argbuf, 0, 0);
1300                                 break;
1301                         case 10:
1302                                 readmsgs(0, 1, 0);
1303                                 break;
1304                         case 9:
1305                                 readmsgs(3, 1, 5);
1306                                 break;
1307                         case 13:
1308                                 readmsgs(1, 1, 0);
1309                                 break;
1310                         case 11:
1311                                 readmsgs(0, (-1), 0);
1312                                 break;
1313                         case 12:
1314                                 readmsgs(2, (-1), 0);
1315                                 break;
1316                         case 71:
1317                                 readmsgs(3, 1, atoi(argbuf));
1318                                 break;
1319                         case 7:
1320                                 forget();
1321                                 break;
1322                         case 18:
1323                                 subshell();
1324                                 break;
1325                         case 38:
1326                                 updatels();
1327                                 entroom();
1328                                 break;
1329                         case 22:
1330                                 killroom();
1331                                 break;
1332                         case 32:
1333                                 userlist(argbuf);
1334                                 break;
1335                         case 27:
1336                                 invite();
1337                                 break;
1338                         case 28:
1339                                 kickout();
1340                                 break;
1341                         case 23:
1342                                 editthisroom();
1343                                 break;
1344                         case 14:
1345                                 roomdir();
1346                                 break;
1347                         case 33:
1348                                 download(0);
1349                                 break;
1350                         case 34:
1351                                 download(1);
1352                                 break;
1353                         case 31:
1354                                 download(2);
1355                                 break;
1356                         case 43:
1357                                 download(3);
1358                                 break;
1359                         case 45:
1360                                 download(4);
1361                                 break;
1362                         case 55:
1363                                 download(5);
1364                                 break;
1365                         case 39:
1366                                 upload(0);
1367                                 break;
1368                         case 40:
1369                                 upload(1);
1370                                 break;
1371                         case 42:
1372                                 upload(2);
1373                                 break;
1374                         case 44:
1375                                 upload(3);
1376                                 break;
1377                         case 57:
1378                                 cli_upload();
1379                                 break;
1380                         case 16:
1381                                 ungoto();
1382                                 break;
1383                         case 24:
1384                                 whoknows();
1385                                 break;
1386                         case 26:
1387                                 validate();
1388                                 break;
1389                         case 29:
1390                                 if (!rc_alt_semantics)
1391                                         updatels();
1392                                 termn8 = 1;
1393                                 break;
1394                         case 30:
1395                                 if (!rc_alt_semantics)
1396                                         updatels();
1397                                 termn8 = 1;
1398                                 break;
1399                         case 48:
1400                                 enterinfo();
1401                                 break;
1402                         case 49:
1403                                 readinfo();
1404                                 break;
1405                         case 72:
1406                                 cli_image_upload("_userpic_");
1407                                 break;
1408                         case 73:
1409                                 cli_image_upload("_roompic_");
1410                                 break;
1411
1412                         case 74:
1413                                 snprintf(aaa, sizeof aaa, "_floorpic_|%d", curr_floor);
1414                                 cli_image_upload(aaa);
1415                                 break;
1416
1417                         case 75:
1418                                 enternew("roomname", aaa, 20);
1419                                 r = CtdlIPCChangeRoomname(aaa, bbb);
1420                                 if (r / 100 != 2)
1421                                         scr_printf("\n%s\n", aaa);
1422                                 break;
1423                         case 76:
1424                                 enternew("hostname", aaa, 25);
1425                                 r = CtdlIPCChangeHostname(aaa, bbb);
1426                                 if (r / 100 != 2)
1427                                         scr_printf("\n%s\n", aaa);
1428                                 break;
1429                         case 77:
1430                                 enternew("username", aaa, 32);
1431                                 r = CtdlIPCChangeUsername(aaa, bbb);
1432                                 if (r / 100 != 2)
1433                                         scr_printf("\n%s\n", aaa);
1434                                 break;
1435
1436                         case 35:
1437                                 set_password();
1438                                 break;
1439
1440                         case 21:
1441                                 if (argbuf[0] == 0)
1442                                         strcpy(aaa, "?");
1443                                 display_help(argbuf);
1444                                 break;
1445
1446                         case 41:
1447                                 formout("register");
1448                                 entregis();
1449                                 break;
1450
1451                         case 15:
1452                                 scr_printf("Are you sure (y/n)? ");
1453                                 if (yesno() == 1) {
1454                                         updatels();
1455                                         a = 0;
1456                                         termn8 = 1;
1457                                 }
1458                                 break;
1459
1460                         case 85:
1461                                 scr_printf("All users will be disconnected!  "
1462                                         "Really terminate the server? ");
1463                                 if (yesno() == 1) {
1464                                         r = CtdlIPCTerminateServerNow(aaa);
1465                                         scr_printf("%s\n", aaa);
1466                                         if (r / 100 == 2) {
1467                                                 updatels();
1468                                                 a = 0;
1469                                                 termn8 = 1;
1470                                         }
1471                                 }
1472                                 break;
1473
1474                         case 86:
1475                                 scr_printf("Do you really want to schedule a "
1476                                         "server shutdown? ");
1477                                 if (yesno() == 1) {
1478                                         r = CtdlIPCTerminateServerScheduled(1, aaa);
1479                                         if (r / 100 == 2) {
1480                                                 if (atoi(aaa)) {
1481                                                         scr_printf(
1482 "The Citadel server will terminate when all users are logged off.\n"
1483                                                                 );
1484                                                 } else {
1485                                                         scr_printf(
1486 "The Citadel server will not terminate.\n"
1487                                                                 );
1488                                                 }
1489                                         }
1490                                 }
1491                                 break;
1492
1493                         case 87:
1494                                 network_config_management("listrecp",
1495                                         "Mailing list recipients");
1496                                 break;
1497
1498                         case 89:
1499                                 network_config_management("ignet_push_share",
1500                                         "Nodes with which we share this room");
1501                                 break;
1502
1503                         case 88:
1504                                 do_ignet_configuration();
1505                                 break;
1506
1507                         case 92:
1508                                 do_filterlist_configuration();
1509                                 break;
1510
1511                         case 6:
1512                                 if (rc_alt_semantics)
1513                                         updatelsa();
1514                                 gotonext();
1515                                 break;
1516
1517                         case 3:
1518                                 chatmode();
1519                                 break;
1520
1521                         case 2:
1522                                 if (server_is_local) {
1523                                         screen_reset();
1524                                         sttybbs(SB_RESTORE);
1525                                         snprintf(aaa, sizeof aaa, "USERNAME=\042%s\042; export USERNAME;"
1526                                                  "exec ./subsystem %ld %d %d", fullname,
1527                                           usernum, screenwidth, axlevel);
1528                                         ka_system(aaa);
1529                                         sttybbs(SB_NO_INTR);
1530                                         screen_set();
1531                                 } else {
1532                                         scr_printf("*** Can't run doors when server is not local.\n");
1533                                 }
1534                                 break;
1535
1536                         case 17:
1537                                 who_is_online(0);
1538                                 break;
1539
1540                         case 79:
1541                                 who_is_online(1);
1542                                 break;
1543
1544             case 91:
1545                 who_is_online(2);
1546                 break;
1547                 
1548                         case 80:
1549                                 do_system_configuration();
1550                                 break;
1551
1552                         case 82:
1553                                 do_internet_configuration();
1554                                 break;
1555
1556                         case 83:
1557                                 check_message_base();
1558                                 break;
1559
1560                         case 84:
1561                                 quiet_mode();
1562                                 break;
1563
1564                         case 93:
1565                                 stealth_mode();
1566                                 break;
1567
1568                         case 50:
1569                                 enter_config(2);
1570                                 break;
1571
1572                         case 37:
1573                                 enter_config(0);
1574                                 set_floor_mode();
1575                                 break;
1576
1577                         case 59:
1578                                 enter_config(3);
1579                                 set_floor_mode();
1580                                 break;
1581
1582                         case 60:
1583                                 gotofloor(argbuf, GF_GOTO);
1584                                 break;
1585
1586                         case 61:
1587                                 gotofloor(argbuf, GF_SKIP);
1588                                 break;
1589
1590                         case 62:
1591                                 forget_this_floor();
1592                                 break;
1593
1594                         case 63:
1595                                 create_floor();
1596                                 break;
1597
1598                         case 64:
1599                                 edit_floor();
1600                                 break;
1601
1602                         case 65:
1603                                 kill_floor();
1604                                 break;
1605
1606                         case 66:
1607                                 enter_bio();
1608                                 break;
1609
1610                         case 67:
1611                                 read_bio();
1612                                 break;
1613
1614                         case 25:
1615                                 edituser();
1616                                 break;
1617
1618                         case 8:
1619                                 knrooms(floor_mode);
1620                                 scr_printf("\n");
1621                                 break;
1622
1623                         case 68:
1624                                 knrooms(2);
1625                                 scr_printf("\n");
1626                                 break;
1627
1628                         case 69:
1629                                 misc_server_cmd(argbuf);
1630                                 break;
1631
1632                         case 70:
1633                                 edit_system_message(argbuf);
1634                                 break;
1635
1636                         case 19:
1637                                 listzrooms();
1638                                 scr_printf("\n");
1639                                 break;
1640
1641                         case 51:
1642                                 deletefile();
1643                                 break;
1644
1645                         case 53:
1646                                 netsendfile();
1647                                 break;
1648
1649                         case 54:
1650                                 movefile();
1651                                 break;
1652
1653                         case 56:
1654                                 page_user();
1655                                 break;
1656
1657                         }       /* end switch */
1658         } while (termn8 == 0);
1659
1660 TERMN8: scr_printf("%s logged out.\n", fullname);
1661         while (march != NULL) {
1662                 remove_march(march->march_name, 0);
1663         }
1664         if (mcmd == 30) {
1665                 sln_printf("\n\nType 'off' to disconnect, or next user...\n");
1666         }
1667         CtdlIPCLogout();
1668         screen_delete();
1669         sttybbs(SB_RESTORE);
1670         if ((mcmd == 29) || (mcmd == 15)) {
1671                 formout("goodbye");
1672                 logoff(0);
1673         }
1674         goto GSTA;
1675
1676 }       /* end main() */