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