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