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