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