]> code.citadel.org Git - citadel.git/blob - citadel/citadel.c
* Misc. routines converted to new IPC code
[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          * 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         struct ctdlipcroom *roomrec;    /* Ignored */
519         int r;                          /* IPC response code */
520
521         scr_printf("Forgetting all rooms on %s...\r", &floorlist[ffloor][0]);
522         scr_flush();
523         snprintf(buf, sizeof buf, "LKRA %d", ffloor);
524         serv_puts(buf);
525         serv_gets(buf);
526         if (buf[0] != '1') {
527                 scr_printf("%-72s\n", &buf[4]);
528                 return;
529         }
530         flist = NULL;
531         while (serv_gets(buf), strcmp(buf, "000")) {
532                 fptr = (struct march *) malloc(sizeof(struct march));
533                 fptr->next = flist;
534                 flist = fptr;
535                 extract(fptr->march_name, buf, 0);
536         }
537         while (flist != NULL) {
538                 r = CtdlIPCGotoRoom(flist->march_name, "", &roomrec, buf);
539                 if (r / 100 == 2) {
540                         r = CtdlIPCForgetRoom(buf);
541                 }
542                 fptr = flist;
543                 flist = flist->next;
544                 free(fptr);
545         }
546         scr_printf("%-72s\r", "");
547 }
548
549
550 /*
551  * routine called by gotofloor() to move to a new room on a new floor
552  */
553 void gf_toroom(char *towhere, int mode)
554 {
555         int floor_being_left;
556
557         floor_being_left = curr_floor;
558
559         if (mode == GF_GOTO) {  /* <;G>oto mode */
560                 updatels();
561                 dotgoto(towhere, 1, 0);
562         }
563         if (mode == GF_SKIP) {  /* <;S>kip mode */
564                 dotgoto(towhere, 1, 0);
565                 remove_march("_FLOOR_", floor_being_left);
566         }
567         if (mode == GF_ZAP) {   /* <;Z>ap mode */
568                 dotgoto(towhere, 1, 0);
569                 remove_march("_FLOOR_", floor_being_left);
570                 forget_all_rooms_on(floor_being_left);
571         }
572 }
573
574
575 /*
576  * go to a new floor
577  */
578 void gotofloor(char *towhere, int mode)
579 {
580         int a, tofloor;
581         struct march *mptr;
582         char buf[SIZ], targ[SIZ];
583
584         if (floorlist[0][0] == 0)
585                 load_floorlist();
586         tofloor = (-1);
587         for (a = 0; a < 128; ++a)
588                 if (!strcasecmp(&floorlist[a][0], towhere))
589                         tofloor = a;
590
591         if (tofloor < 0) {
592                 for (a = 0; a < 128; ++a) {
593                         if (!strncasecmp(&floorlist[a][0], towhere, strlen(towhere))) {
594                                 tofloor = a;
595                         }
596                 }
597         }
598         if (tofloor < 0) {
599                 for (a = 0; a < 128; ++a)
600                         if (pattern(towhere, &floorlist[a][0]) > 0)
601                                 tofloor = a;
602         }
603         if (tofloor < 0) {
604                 scr_printf("No floor '%s'.\n", towhere);
605                 return;
606         }
607         for (mptr = march; mptr != NULL; mptr = mptr->next) {
608                 if ((mptr->march_floor) == tofloor)
609                         gf_toroom(mptr->march_name, mode);
610                 return;
611         }
612
613         strcpy(targ, "");
614         snprintf(buf, sizeof buf, "LKRA %d", tofloor);
615         serv_puts(buf);
616         serv_gets(buf);
617         if (buf[0] == '1')
618                 while (serv_gets(buf), strcmp(buf, "000")) {
619                         if ((extract_int(buf, 2) == tofloor) && (strlen(targ) == 0))
620                                 extract(targ, buf, 0);
621                 }
622         if (strlen(targ) > 0) {
623                 gf_toroom(targ, mode);
624         } else {
625                 scr_printf("There are no rooms on '%s'.\n", &floorlist[tofloor][0]);
626         }
627 }
628
629
630 /*
631  * forget all rooms on current floor
632  */
633 void forget_this_floor(void)
634 {
635
636         if (curr_floor == 0) {
637                 scr_printf("Can't forget this floor.\n");
638                 return;
639         }
640         if (floorlist[0][0] == 0)
641                 load_floorlist();
642         scr_printf("Are you sure you want to forget all rooms on %s? ",
643                &floorlist[(int) curr_floor][0]);
644         if (yesno() == 0)
645                 return;
646
647         gf_toroom("_BASEROOM_", GF_ZAP);
648 }
649
650
651 /* 
652  * Figure out the physical screen dimensions, if we can
653  * WARNING:  this is now called from a signal handler!
654  */
655 void check_screen_dims(void)
656 {
657 #ifdef TIOCGWINSZ
658         struct {
659                 unsigned short height;  /* rows */
660                 unsigned short width;   /* columns */
661                 unsigned short xpixels;
662                 unsigned short ypixels;         /* pixels */
663         } xwinsz;
664
665         if (have_xterm) {       /* dynamically size screen if on an xterm */
666                 if (ioctl(0, TIOCGWINSZ, &xwinsz) == 0) {
667                         if (xwinsz.height)
668                                 screenheight = is_curses_enabled() ? (int)xwinsz.height - 1 : (int) xwinsz.height;
669                         if (xwinsz.width)
670                                 screenwidth = (int) xwinsz.width;
671                 }
672         }
673 #endif
674 }
675
676
677 /*
678  * set floor mode depending on client, server, and user settings
679  */
680 void set_floor_mode(void)
681 {
682         if (serv_info.serv_ok_floors == 0) {
683                 floor_mode = 0; /* Don't use floors if the server */
684         }
685         /* doesn't support them!          */
686         else {
687                 if (rc_floor_mode == RC_NO) {   /* never use floors */
688                         floor_mode = 0;
689                 }
690                 if (rc_floor_mode == RC_YES) {  /* always use floors */
691                         floor_mode = 1;
692                 }
693                 if (rc_floor_mode == RC_DEFAULT) {      /* user choice */
694                         floor_mode = ((userflags & US_FLOORS) ? 1 : 0);
695                 }
696         }
697 }
698
699 /*
700  * Set or change the user's password
701  */
702 int set_password(void)
703 {
704         char pass1[20];
705         char pass2[20];
706         char buf[SIZ];
707
708         if (strlen(rc_password) > 0) {
709                 strcpy(pass1, rc_password);
710                 strcpy(pass2, rc_password);
711         } else {
712                 IFNEXPERT formout("changepw");
713                 newprompt("Enter a new password: ", pass1, -19);
714                 newprompt("Enter it again to confirm: ", pass2, -19);
715         }
716         strproc(pass1);
717         strproc(pass2);
718         if (!strcasecmp(pass1, pass2)) {
719                 CtdlIPCChangePassword(pass1, buf);
720                 scr_printf("%s\n", buf);
721                 offer_to_remember_password(hostbuf, portbuf, fullname, pass1);
722                 return (0);
723         } else {
724                 scr_printf("*** They don't match... try again.\n");
725                 return (1);
726         }
727 }
728
729
730
731 /*
732  * get info about the server we've connected to
733  */
734 void get_serv_info(char *supplied_hostname)
735 {
736         char buf[SIZ];
737
738         CtdlIPCServerInfo(&serv_info, buf);
739
740         /* be nice and identify ourself to the server */
741         CtdlIPCIdentifySoftware(SERVER_TYPE, 0, REV_LEVEL,
742                  (server_is_local ? "local" : CITADEL),
743                  (supplied_hostname) ? supplied_hostname : "", buf);
744                  /* (locate_host(buf), buf)); */
745 }
746
747
748
749
750
751 /*
752  * Display list of users currently logged on to the server
753  */
754 void who_is_online(int longlist)
755 {
756         char buf[SIZ], username[SIZ], roomname[SIZ], fromhost[SIZ];
757         char flags[SIZ];
758         char actual_user[SIZ], actual_room[SIZ], actual_host[SIZ];
759         char tbuf[SIZ], clientsoft[SIZ];
760         time_t timenow = 0;
761         time_t idletime, idlehours, idlemins, idlesecs;
762         int last_session = (-1);
763         int skipidle = 0;
764         char *listing = NULL;
765         int r;                          /* IPC response code */
766     
767         if (longlist == 2) {
768                 longlist = 0;
769                 skipidle = 1;
770         }
771
772         if (!(timenow = CtdlIPCServerTime(tbuf))) {
773                 time(&timenow);
774         }
775
776         if (!longlist) {
777                 color(BRIGHT_WHITE);
778                 pprintf("FLG ###        User Name                 Room                 From host\n");
779                 color(DIM_WHITE);
780                 pprintf("--- --- ------------------------- -------------------- ------------------------\n");
781         }
782         r = CtdlIPCOnlineUsers(&listing, &timenow, buf);
783         if (r / 100 == 1) {
784                 while (strlen(listing) > 0) {
785                         int isidle = 0;
786                         
787                         /* Get another line */
788                         extract_token(buf, listing, 0, '\n');
789                         remove_token(listing, 0, '\n');
790
791                         extract(username, buf, 1);
792                         extract(roomname, buf, 2);
793                         extract(fromhost, buf, 3);
794                         extract(clientsoft, buf, 4);
795                         extract(flags, buf, 7);
796
797                         idletime = timenow - extract_long(buf, 5);
798                         idlehours = idletime / 3600;
799                         idlemins = (idletime - (idlehours * 3600)) / 60;
800                         idlesecs = (idletime - (idlehours * 3600) - (idlemins * 60));
801
802                         if (idletime > rc_idle_threshold) {
803                                 while (strlen(roomname) < 20) {
804                                         strcat(roomname, " ");
805                                 }
806                                 strcpy(&roomname[14], "[idle]");
807                                 if (skipidle)
808                                         isidle = 1;
809                         }
810
811                         if (longlist) {
812                                 extract(actual_user, buf, 8);
813                                 extract(actual_room, buf, 9);
814                                 extract(actual_host, buf, 10);
815
816                                 pprintf("  Flags: %s\n", flags);
817                                 pprintf("Session: %d\n", extract_int(buf, 0));
818                                 pprintf("   Name: %s\n", username);
819                                 pprintf("In room: %s\n", roomname);
820                                 pprintf("   Host: %s\n", fromhost);
821                                 pprintf(" Client: %s\n", clientsoft);
822                                 pprintf("   Idle: %ld:%02ld:%02ld\n",
823                                         (long) idlehours,
824                                         (long) idlemins,
825                                         (long) idlesecs);
826
827                                 if ( (strlen(actual_user)+strlen(actual_room)+strlen(actual_host)) > 0) {
828                                         pprintf("(really ");
829                                         if (strlen(actual_user)>0) pprintf("<%s> ", actual_user);
830                                         if (strlen(actual_room)>0) pprintf("in <%s> ", actual_room);
831                                         if (strlen(actual_host)>0) pprintf("from <%s> ", actual_host);
832                                         pprintf(")\n");
833                                 }
834                                 pprintf("\n");
835
836                         } else {
837                     if (isidle == 0) {
838                                 if (extract_int(buf, 0) == last_session) {
839                                         pprintf("        ");
840                                 } else {
841                                         color(BRIGHT_MAGENTA);
842                                         pprintf("%-3s ", flags);
843                                         color(DIM_WHITE);
844                                         pprintf("%-3d ", extract_int(buf, 0));
845                                 }
846                                 last_session = extract_int(buf, 0);
847                                 color(BRIGHT_CYAN);
848                                 pprintf("%-25s ", username);
849                                 color(BRIGHT_MAGENTA);
850                                 roomname[20] = 0;
851                                 pprintf("%-20s ", roomname);
852                                 color(BRIGHT_CYAN);
853                                 fromhost[24] = '\0';
854                                 pprintf("%-24s\n", fromhost);
855                                 color(DIM_WHITE);
856                         }
857                         }
858                 }
859         }
860         free(listing);
861 }
862
863 void enternew(char *desc, char *buf, int maxlen)
864 {
865         char bbb[128];
866         snprintf(bbb, sizeof bbb, "Enter in your new %s: ", desc);
867         newprompt(bbb, buf, maxlen);
868 }
869
870
871
872 int shift(int argc, char **argv, int start, int count) {
873         int i;
874
875         for (i=start; i<(argc-count); ++i) {
876                 argv[i] = argv[i+count];
877         }
878         argc = argc - count;
879         return argc;
880 }
881
882 static void statusHook(char *s) {
883         sln_printf(s);
884         sln_flush();
885 }
886
887 /*
888  * main
889  */
890 int main(int argc, char **argv)
891 {
892         int a, b, mcmd;
893         char aaa[100], bbb[100];/* general purpose variables */
894         char argbuf[32];        /* command line buf */
895         char nonce[NONCE_SIZE];
896         char *telnet_client_host = NULL;
897         char *sptr, *sptr2;     /* USed to extract the nonce */
898         char hexstring[MD5_HEXSTRING_SIZE];
899         int stored_password = 0;
900         char password[SIZ];
901         struct ctdlipcmisc chek;
902         struct usersupp *myself = NULL;
903         int r;                          /* IPC result code */
904
905         setIPCDeathHook(screen_delete);
906         setIPCErrorPrintf(err_printf);
907         setCryptoStatusHook(statusHook);
908         
909         /* Permissions sanity check - don't run citadel setuid/setgid */
910         if (getuid() != geteuid()) {
911                 err_printf("Please do not run citadel setuid!\n");
912                 logoff(3);
913         } else if (getgid() != getegid()) {
914                 err_printf("Please do not run citadel setgid!\n");
915                 logoff(3);
916         }
917
918         sttybbs(SB_SAVE);       /* Store the old terminal parameters */
919         load_command_set();     /* parse the citadel.rc file */
920         sttybbs(SB_NO_INTR);    /* Install the new ones */
921         signal(SIGHUP, dropcarr);       /* Cleanup gracefully if carrier is dropped */
922         signal(SIGTERM, dropcarr);      /* Cleanup gracefully if terminated */
923         signal(SIGCONT, catch_sigcont); /* Catch SIGCONT so we can reset terminal */
924 #ifdef SIGWINCH
925         signal(SIGWINCH, scr_winch);    /* Window resize signal */
926 #endif
927
928 #ifdef HAVE_OPENSSL
929         arg_encrypt = RC_DEFAULT;
930 #endif
931 #ifdef HAVE_CURSES_H
932         arg_screen = RC_DEFAULT;
933 #endif
934
935         /* 
936          * Handle command line options as if we were called like /bin/login
937          * (i.e. from in.telnetd)
938          */
939         for (a=0; a<argc; ++a) {
940                 if ((argc > a+1) && (!strcmp(argv[a], "-h")) ) {
941                         telnet_client_host = argv[a+1];
942                         argc = shift(argc, argv, a, 2);
943                 }
944                 if (!strcmp(argv[a], "-x")) {
945 #ifdef HAVE_OPENSSL
946                         arg_encrypt = RC_NO;
947 #endif
948                         argc = shift(argc, argv, a, 1);
949                 }
950                 if (!strcmp(argv[a], "-X")) {
951 #ifdef HAVE_OPENSSL
952                         arg_encrypt = RC_YES;
953                         argc = shift(argc, argv, a, 1);
954 #else
955                         fprintf(stderr, "Not compiled with encryption support");
956                         return 1;
957 #endif
958                 }
959                 if (!strcmp(argv[a], "-s")) {
960 #ifdef HAVE_CURSES_H
961                         arg_screen = RC_NO;
962 #endif
963                         argc = shift(argc, argv, a, 1);
964                 }
965                 if (!strcmp(argv[a], "-S")) {
966 #ifdef HAVE_CURSES_H
967                         arg_screen = RC_YES;
968 #endif
969                         argc = shift(argc, argv, a, 1);
970                 }
971                 if (!strcmp(argv[a], "-p")) {
972                         struct stat st;
973                 
974                         if (chdir(BBSDIR) < 0) {
975                                 perror("can't change to " BBSDIR);
976                                 logoff(3);
977                         }
978
979                         /*
980                          * Drop privileges if necessary. We stat
981                          * citadel.config to get the uid/gid since it's
982                          * guaranteed to have the uid/gid we want.
983                          */
984                         if (!getuid() || !getgid()) {
985                                 if (stat(BBSDIR "/citadel.config", &st) < 0) {
986                                         perror("couldn't stat citadel.config");
987                                         logoff(3);
988                                 }
989                                 if (!getgid() && (setgid(st.st_gid) < 0)) {
990                                         perror("couldn't change gid");
991                                         logoff(3);
992                                 }
993                                 if (!getuid() && (setuid(st.st_uid) < 0)) {
994                                         perror("couldn't change uid");
995                                         logoff(3);
996                                 }
997                                 /*
998                                 scr_printf("Privileges changed to uid %d gid %d\n",
999                                                 getuid(), getgid());
1000                                 */
1001                         }
1002                         argc = shift(argc, argv, a, 1);
1003                 }
1004         }
1005
1006         screen_new();
1007
1008         sln_printf("Attaching to server... \r");
1009         sln_flush();
1010         attach_to_server(argc, argv, hostbuf, portbuf);
1011
1012         serv_gets(aaa);
1013         if (aaa[0] != '2') {
1014                 scr_printf("%s\n", &aaa[4]);
1015                 logoff(atoi(aaa));
1016         }
1017
1018 /* If there is a [nonce] at the end, put the nonce in <nonce>, else nonce
1019  * is zeroized.
1020  */
1021         
1022         if ((sptr = strchr(aaa, '<')) == NULL)
1023         {
1024            nonce[0] = '\0';
1025         }
1026         else
1027         {
1028            if ((sptr2 = strchr(sptr, '>')) == NULL)
1029            {
1030               nonce[0] = '\0';
1031            }
1032            else
1033            {
1034               sptr2++;
1035               *sptr2 = '\0';
1036               strncpy(nonce, sptr, NONCE_SIZE);
1037            }
1038         }
1039
1040         get_serv_info(telnet_client_host);
1041
1042         scr_printf("%-24s\n%s\n%s\n", serv_info.serv_software, serv_info.serv_humannode,
1043                 serv_info.serv_bbs_city);
1044         scr_flush();
1045
1046         secure = starttls();
1047         status_line(serv_info.serv_humannode, serv_info.serv_bbs_city, NULL,
1048                         secure, -1);
1049
1050         screenwidth = 80;       /* default screen dimensions */
1051         screenheight = 24;
1052         
1053         scr_printf(" pause    next    stop\n");
1054         scr_printf(" ctrl-s  ctrl-o  ctrl-c\n\n");
1055         formout("hello");       /* print the opening greeting */
1056         scr_printf("\n");
1057
1058 GSTA:   /* See if we have a username and password on disk */
1059         if (rc_remember_passwords) {
1060                 get_stored_password(hostbuf, portbuf, fullname, password);
1061                 if (strlen(fullname) > 0) {
1062                         snprintf(aaa, sizeof(aaa)-1, "USER %s", fullname);
1063                         serv_puts(aaa);
1064                         serv_gets(aaa);
1065                         if (nonce[0])
1066                         {
1067                                 snprintf(aaa, sizeof aaa, "PAS2 %s", make_apop_string(password, nonce, hexstring, sizeof hexstring));
1068                         }
1069                         else    /* Else no APOP */
1070                         {
1071                                 snprintf(aaa, sizeof(aaa)-1, "PASS %s", password);
1072                         }
1073                         
1074                         serv_puts(aaa);
1075                         serv_gets(aaa);
1076                         if (aaa[0] == '2') {
1077                                 load_user_info(&aaa[4]);
1078                                 stored_password = 1;
1079                                 goto PWOK;
1080                         }
1081                         else {
1082                                 set_stored_password(hostbuf, portbuf, "", "");
1083                         }
1084                 }
1085         }
1086
1087         termn8 = 0;
1088         newnow = 0;
1089         do {
1090                 if (strlen(rc_username) > 0) {
1091                         strcpy(fullname, rc_username);
1092                 } else {
1093                         newprompt("Enter your name: ", fullname, 29);
1094                 }
1095                 strproc(fullname);
1096                 if (!strcasecmp(fullname, "new")) {     /* just in case */
1097                         scr_printf("Please enter the name you wish to log in with.\n");
1098                 }
1099         } while (
1100                         (!strcasecmp(fullname, "bbs"))
1101                         || (!strcasecmp(fullname, "new"))
1102                         || (strlen(fullname) == 0));
1103
1104         if (!strcasecmp(fullname, "off")) {
1105                 mcmd = 29;
1106                 goto TERMN8;
1107         }
1108         /* sign on to the server */
1109         r = CtdlIPCTryLogin(fullname, aaa);
1110         if (r / 100 != 3)
1111                 goto NEWUSR;
1112
1113         /* password authentication */
1114         if (strlen(rc_password) > 0) {
1115                 strcpy(password, rc_password);
1116         } else {
1117                 newprompt("\rPlease enter your password: ", password, -19);
1118         }
1119         strproc(password);
1120
1121         if (nonce[0])
1122         {
1123                 snprintf(aaa, sizeof aaa, "PAS2 %s", make_apop_string(password, nonce, hexstring, sizeof hexstring));
1124         }
1125         else    /* Else no APOP */
1126         {
1127                 snprintf(aaa, sizeof aaa, "PASS %s", password);
1128         }
1129         
1130         serv_puts(aaa);
1131         serv_gets(aaa);
1132         if (aaa[0] == '2') {
1133                 load_user_info(&aaa[4]);
1134                 offer_to_remember_password(hostbuf, portbuf,
1135                                         fullname, password);
1136                 goto PWOK;
1137         }
1138         scr_printf("<< wrong password >>\n");
1139         if (strlen(rc_password) > 0)
1140                 logoff(0);
1141         goto GSTA;
1142
1143 NEWUSR: if (strlen(rc_password) == 0) {
1144                 scr_printf("No record. Enter as new user? ");
1145                 if (yesno() == 0)
1146                         goto GSTA;
1147         }
1148         snprintf(aaa, sizeof aaa, "NEWU %s", fullname);
1149         serv_puts(aaa);
1150         serv_gets(aaa);
1151         if (aaa[0] != '2') {
1152                 scr_printf("%s\n", aaa);
1153                 goto GSTA;
1154         }
1155         load_user_info(&aaa[4]);
1156
1157         while (set_password() != 0);;
1158         newnow = 1;
1159
1160         enter_config(1);
1161
1162 PWOK:
1163         /* Switch color support on or off if we're in user mode */
1164         if (rc_ansi_color == 3) {
1165                 if (userflags & US_COLOR)
1166                         enable_color = 1;
1167                 else
1168                         enable_color = 0;
1169         }
1170
1171         scr_printf("%s\nAccess level: %d (%s)\n"
1172                 "User #%ld / Login #%d",
1173                 fullname, axlevel, axdefs[(int) axlevel],
1174                 usernum, timescalled);
1175         if (lastcall > 0L) {
1176                 scr_printf(" / Last login: %s\n",
1177                         asctime(localtime(&lastcall)) );
1178         }
1179         scr_printf("\n");
1180
1181         r = CtdlIPCMiscCheck(&chek, aaa);
1182         if (r / 100 == 2) {
1183                 b = chek.newmail;
1184                 if (b > 0) {
1185                         color(BRIGHT_RED);
1186                         if (b == 1)
1187                                 scr_printf("*** You have a new private message in Mail>\n");
1188                         if (b > 1)
1189                                 scr_printf("*** You have %d new private messages in Mail>\n", b);
1190                         color(DIM_WHITE);
1191                 }
1192                 if ((axlevel >= 6) && (chek.needvalid > 0)) {
1193                         scr_printf("*** Users need validation\n");
1194                 }
1195                 if (chek.needregis > 0) {
1196                         scr_printf("*** Please register.\n");
1197                         formout("register");
1198                         entregis();
1199                 }
1200         }
1201         /* Make up some temporary filenames for use in various parts of the
1202          * program.  Don't mess with these once they've been set, because we
1203          * will be unlinking them later on in the program and we don't
1204          * want to delete something that we didn't create. */
1205         snprintf(temp, sizeof temp, tmpnam(NULL));
1206         snprintf(temp2, sizeof temp2, tmpnam(NULL));
1207         snprintf(tempdir, sizeof tempdir, tmpnam(NULL));
1208
1209         /* Get screen dimensions.  First we go to a default of 80x24.  Then
1210          * we try to get the user's actual screen dimensions off the server.
1211          * However, if we're running on an xterm, all this stuff is
1212          * irrelevant because we're going to dynamically size the screen
1213          * during the session.
1214          */
1215         screenwidth = 80;
1216         screenheight = 24;
1217         r = CtdlIPCGetConfig(&myself, aaa);
1218         if (r == 2) {
1219                 screenwidth = myself->USscreenwidth;
1220                 screenheight = myself->USscreenheight;
1221         }
1222         if (getenv("TERM") != NULL)
1223                 if (!strcmp(getenv("TERM"), "xterm")) {
1224                         have_xterm = 1;
1225                 }
1226 #ifdef TIOCGWINSZ
1227         check_screen_dims();
1228 #endif
1229
1230         set_floor_mode();
1231
1232
1233         /* Enter the lobby */
1234         dotgoto("_BASEROOM_", 1, 0);
1235
1236 /* Main loop for the system... user is logged in. */
1237     uglistsize = 0;
1238
1239         if (newnow == 1)
1240                 readmsgs(3, 1, 5);
1241         else
1242                 readmsgs(1, 1, 0);
1243
1244         /* MAIN COMMAND LOOP */
1245         do {
1246                 mcmd = getcmd(argbuf);          /* Get keyboard command */
1247
1248 #ifdef TIOCGWINSZ
1249                 check_screen_dims();            /* if xterm, get screen size */
1250 #endif
1251
1252                 if (termn8 == 0)
1253                         switch (mcmd) {
1254                         case 1:
1255                                 formout("help");
1256                                 break;
1257                         case 4:
1258                                 entmsg(0, 0);
1259                                 break;
1260                         case 36:
1261                                 entmsg(0, 1);
1262                                 break;
1263                         case 46:
1264                                 entmsg(0, 2);
1265                                 break;
1266                         case 78:
1267                                 newprompt("What do you want your username to be? ", aaa, 32);
1268                                 snprintf(bbb, sizeof bbb, "ENT0 2|0|0|0|%s", aaa);
1269                                 serv_puts(bbb);
1270                                 serv_gets(aaa);
1271                                 if (strncmp("200", aaa, 3))
1272                                         scr_printf("\n%s\n", aaa);
1273                                 else
1274                                         entmsg(0, 0);
1275                                 break;
1276                         case 5:
1277                                 updatels();
1278                                 gotonext();
1279                                 break;
1280                         case 47:
1281                                 if (!rc_alt_semantics)
1282                                         updatelsa();
1283                                 gotonext();
1284                                 break;
1285                         case 90:
1286                                 if (!rc_alt_semantics)
1287                                         updatelsa();
1288                                 dotgoto(argbuf, 0, 0);
1289                                 break;
1290                         case 58:
1291                                 updatelsa();
1292                                 dotgoto("_MAIL_", 1, 0);
1293                                 break;
1294                         case 20:
1295                                 updatels();
1296                                 dotgoto(argbuf, 0, 0);
1297                                 break;
1298                         case 52:
1299                                 if (rc_alt_semantics)
1300                                         updatelsa();
1301                                 dotgoto(argbuf, 0, 0);
1302                                 break;
1303                         case 10:
1304                                 readmsgs(0, 1, 0);
1305                                 break;
1306                         case 9:
1307                                 readmsgs(3, 1, 5);
1308                                 break;
1309                         case 13:
1310                                 readmsgs(1, 1, 0);
1311                                 break;
1312                         case 11:
1313                                 readmsgs(0, (-1), 0);
1314                                 break;
1315                         case 12:
1316                                 readmsgs(2, (-1), 0);
1317                                 break;
1318                         case 71:
1319                                 readmsgs(3, 1, atoi(argbuf));
1320                                 break;
1321                         case 7:
1322                                 forget();
1323                                 break;
1324                         case 18:
1325                                 subshell();
1326                                 break;
1327                         case 38:
1328                                 updatels();
1329                                 entroom();
1330                                 break;
1331                         case 22:
1332                                 killroom();
1333                                 break;
1334                         case 32:
1335                                 userlist(argbuf);
1336                                 break;
1337                         case 27:
1338                                 invite();
1339                                 break;
1340                         case 28:
1341                                 kickout();
1342                                 break;
1343                         case 23:
1344                                 editthisroom();
1345                                 break;
1346                         case 14:
1347                                 roomdir();
1348                                 break;
1349                         case 33:
1350                                 download(0);
1351                                 break;
1352                         case 34:
1353                                 download(1);
1354                                 break;
1355                         case 31:
1356                                 download(2);
1357                                 break;
1358                         case 43:
1359                                 download(3);
1360                                 break;
1361                         case 45:
1362                                 download(4);
1363                                 break;
1364                         case 55:
1365                                 download(5);
1366                                 break;
1367                         case 39:
1368                                 upload(0);
1369                                 break;
1370                         case 40:
1371                                 upload(1);
1372                                 break;
1373                         case 42:
1374                                 upload(2);
1375                                 break;
1376                         case 44:
1377                                 upload(3);
1378                                 break;
1379                         case 57:
1380                                 cli_upload();
1381                                 break;
1382                         case 16:
1383                                 ungoto();
1384                                 break;
1385                         case 24:
1386                                 whoknows();
1387                                 break;
1388                         case 26:
1389                                 validate();
1390                                 break;
1391                         case 29:
1392                                 if (!rc_alt_semantics)
1393                                         updatels();
1394                                 termn8 = 1;
1395                                 break;
1396                         case 30:
1397                                 if (!rc_alt_semantics)
1398                                         updatels();
1399                                 termn8 = 1;
1400                                 break;
1401                         case 48:
1402                                 enterinfo();
1403                                 break;
1404                         case 49:
1405                                 readinfo();
1406                                 break;
1407                         case 72:
1408                                 cli_image_upload("_userpic_");
1409                                 break;
1410                         case 73:
1411                                 cli_image_upload("_roompic_");
1412                                 break;
1413
1414                         case 74:
1415                                 snprintf(aaa, sizeof aaa, "_floorpic_|%d", curr_floor);
1416                                 cli_image_upload(aaa);
1417                                 break;
1418
1419                         case 75:
1420                                 enternew("roomname", aaa, 20);
1421                                 r = CtdlIPCChangeRoomname(aaa, bbb);
1422                                 if (r / 100 != 2)
1423                                         scr_printf("\n%s\n", aaa);
1424                                 break;
1425                         case 76:
1426                                 enternew("hostname", aaa, 25);
1427                                 r = CtdlIPCChangeHostname(aaa, bbb);
1428                                 if (r / 100 != 2)
1429                                         scr_printf("\n%s\n", aaa);
1430                                 break;
1431                         case 77:
1432                                 enternew("username", aaa, 32);
1433                                 r = CtdlIPCChangeUsername(aaa, bbb);
1434                                 if (r / 100 != 2)
1435                                         scr_printf("\n%s\n", aaa);
1436                                 break;
1437
1438                         case 35:
1439                                 set_password();
1440                                 break;
1441
1442                         case 21:
1443                                 if (argbuf[0] == 0)
1444                                         strcpy(aaa, "?");
1445                                 display_help(argbuf);
1446                                 break;
1447
1448                         case 41:
1449                                 formout("register");
1450                                 entregis();
1451                                 break;
1452
1453                         case 15:
1454                                 scr_printf("Are you sure (y/n)? ");
1455                                 if (yesno() == 1) {
1456                                         updatels();
1457                                         a = 0;
1458                                         termn8 = 1;
1459                                 }
1460                                 break;
1461
1462                         case 85:
1463                                 scr_printf("All users will be disconnected!  "
1464                                         "Really terminate the server? ");
1465                                 if (yesno() == 1) {
1466                                         r = CtdlIPCTerminateServerNow(aaa);
1467                                         scr_printf("%s\n", aaa);
1468                                         if (r / 100 == 2) {
1469                                                 updatels();
1470                                                 a = 0;
1471                                                 termn8 = 1;
1472                                         }
1473                                 }
1474                                 break;
1475
1476                         case 86:
1477                                 scr_printf("Do you really want to schedule a "
1478                                         "server shutdown? ");
1479                                 if (yesno() == 1) {
1480                                         r = CtdlIPCTerminateServerScheduled(1, aaa);
1481                                         if (r / 100 == 2) {
1482                                                 if (atoi(aaa)) {
1483                                                         scr_printf(
1484 "The Citadel server will terminate when all users are logged off.\n"
1485                                                                 );
1486                                                 } else {
1487                                                         scr_printf(
1488 "The Citadel server will not terminate.\n"
1489                                                                 );
1490                                                 }
1491                                         }
1492                                 }
1493                                 break;
1494
1495                         case 87:
1496                                 network_config_management("listrecp",
1497                                         "Mailing list recipients");
1498                                 break;
1499
1500                         case 89:
1501                                 network_config_management("ignet_push_share",
1502                                         "Nodes with which we share this room");
1503                                 break;
1504
1505                         case 88:
1506                                 do_ignet_configuration();
1507                                 break;
1508
1509                         case 92:
1510                                 do_filterlist_configuration();
1511                                 break;
1512
1513                         case 6:
1514                                 if (rc_alt_semantics)
1515                                         updatelsa();
1516                                 gotonext();
1517                                 break;
1518
1519                         case 3:
1520                                 chatmode();
1521                                 break;
1522
1523                         case 2:
1524                                 if (server_is_local) {
1525                                         screen_reset();
1526                                         sttybbs(SB_RESTORE);
1527                                         snprintf(aaa, sizeof aaa, "USERNAME=\042%s\042; export USERNAME;"
1528                                                  "exec ./subsystem %ld %d %d", fullname,
1529                                           usernum, screenwidth, axlevel);
1530                                         ka_system(aaa);
1531                                         sttybbs(SB_NO_INTR);
1532                                         screen_set();
1533                                 } else {
1534                                         scr_printf("*** Can't run doors when server is not local.\n");
1535                                 }
1536                                 break;
1537
1538                         case 17:
1539                                 who_is_online(0);
1540                                 break;
1541
1542                         case 79:
1543                                 who_is_online(1);
1544                                 break;
1545
1546             case 91:
1547                 who_is_online(2);
1548                 break;
1549                 
1550                         case 80:
1551                                 do_system_configuration();
1552                                 break;
1553
1554                         case 82:
1555                                 do_internet_configuration();
1556                                 break;
1557
1558                         case 83:
1559                                 check_message_base();
1560                                 break;
1561
1562                         case 84:
1563                                 quiet_mode();
1564                                 break;
1565
1566                         case 93:
1567                                 stealth_mode();
1568                                 break;
1569
1570                         case 50:
1571                                 enter_config(2);
1572                                 break;
1573
1574                         case 37:
1575                                 enter_config(0);
1576                                 set_floor_mode();
1577                                 break;
1578
1579                         case 59:
1580                                 enter_config(3);
1581                                 set_floor_mode();
1582                                 break;
1583
1584                         case 60:
1585                                 gotofloor(argbuf, GF_GOTO);
1586                                 break;
1587
1588                         case 61:
1589                                 gotofloor(argbuf, GF_SKIP);
1590                                 break;
1591
1592                         case 62:
1593                                 forget_this_floor();
1594                                 break;
1595
1596                         case 63:
1597                                 create_floor();
1598                                 break;
1599
1600                         case 64:
1601                                 edit_floor();
1602                                 break;
1603
1604                         case 65:
1605                                 kill_floor();
1606                                 break;
1607
1608                         case 66:
1609                                 enter_bio();
1610                                 break;
1611
1612                         case 67:
1613                                 read_bio();
1614                                 break;
1615
1616                         case 25:
1617                                 edituser();
1618                                 break;
1619
1620                         case 8:
1621                                 knrooms(floor_mode);
1622                                 scr_printf("\n");
1623                                 break;
1624
1625                         case 68:
1626                                 knrooms(2);
1627                                 scr_printf("\n");
1628                                 break;
1629
1630                         case 69:
1631                                 misc_server_cmd(argbuf);
1632                                 break;
1633
1634                         case 70:
1635                                 edit_system_message(argbuf);
1636                                 break;
1637
1638                         case 19:
1639                                 listzrooms();
1640                                 scr_printf("\n");
1641                                 break;
1642
1643                         case 51:
1644                                 deletefile();
1645                                 break;
1646
1647                         case 53:
1648                                 netsendfile();
1649                                 break;
1650
1651                         case 54:
1652                                 movefile();
1653                                 break;
1654
1655                         case 56:
1656                                 page_user();
1657                                 break;
1658
1659                         }       /* end switch */
1660         } while (termn8 == 0);
1661
1662 TERMN8: scr_printf("%s logged out.\n", fullname);
1663         while (march != NULL) {
1664                 remove_march(march->march_name, 0);
1665         }
1666         if (mcmd == 30) {
1667                 sln_printf("\n\nType 'off' to disconnect, or next user...\n");
1668         }
1669         CtdlIPCLogout();
1670         screen_delete();
1671         sttybbs(SB_RESTORE);
1672         if ((mcmd == 29) || (mcmd == 15)) {
1673                 formout("goodbye");
1674                 logoff(0);
1675         }
1676         goto GSTA;
1677
1678 }       /* end main() */