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