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