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