4 * Main source module for the client program.
15 #if TIME_WITH_SYS_TIME
16 # include <sys/time.h>
20 # include <sys/time.h>
27 #include <sys/types.h>
30 #include <sys/ioctl.h>
37 #include "citadel_ipc.h"
40 #include "routines2.h"
44 #include "client_chat.h"
45 #include "client_passwords.h"
46 #include "citadel_decls.h"
56 #define IFEXPERT if (userflags&US_EXPERT)
57 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
58 #define IFAIDE if (axlevel>=6)
59 #define IFNAIDE if (axlevel<6)
61 struct march *march = NULL;
63 /* globals associated with the client program */
64 char temp[PATH_MAX]; /* Name of general-purpose temp file */
65 char temp2[PATH_MAX]; /* Name of general-purpose temp file */
66 char tempdir[PATH_MAX]; /* Name of general-purpose temp directory */
67 char editor_paths[MAX_EDITORS][SIZ]; /* paths to external editors */
68 char printcmd[SIZ]; /* print command */
69 int editor_pid = (-1);
70 char fullname[USERNAME_SIZE];
71 struct CtdlServInfo serv_info; /* Info on the server connected */
75 char room_name[ROOMNAMELEN];
76 char *uglist[UGLISTLEN]; /* size of the ungoto list */
77 long uglistlsn[UGLISTLEN]; /* current read position for all the ungoto's. Not going to make any friends with this one. */
79 char is_mail = 0; /* nonzero when we're in a mail room */
80 char axlevel = 0; /* access level */
81 char is_room_aide = 0; /* boolean flag, 1 if room aide */
85 long usernum = 0L; /* user number */
86 time_t lastcall = 0L; /* Date/time of previous login */
88 long highest_msg_read; /* used for <A>bandon room cmd */
89 long maxmsgnum; /* used for <G>oto */
91 char have_xterm = 0; /* are we running on an xterm? */
92 char rc_username[USERNAME_SIZE];
98 char curr_floor = 0; /* number of current floor */
99 char floorlist[128][SIZ]; /* names of floors */
100 int termn8 = 0; /* Set to nonzero to cause a logoff */
101 int secure; /* Set to nonzero when wire is encrypted */
102 int can_do_msg4 = 0; /* Set to nonzero if the server can handle MSG4 commands */
104 extern char express_msgs; /* express messages waiting! */
105 extern int rc_ansi_color; /* ansi color value from citadel.rc */
106 extern int next_lazy_cmd;
108 CtdlIPC *ipc_for_signal_handlers; /* KLUDGE cover your eyes */
111 * here is our 'clean up gracefully and exit' routine
113 void logoff(CtdlIPC *ipc, int code)
117 if (editor_pid > 0) { /* kill the editor if it's running */
118 kill(editor_pid, SIGHUP);
121 /* Free the ungoto list */
122 for (lp = 0; lp < uglistsize; lp++) {
126 /* Shut down the server connection ... but not if the logoff code is 3,
127 * because that means we're exiting because we already lost the server.
134 * now clean up various things
142 /* Violently kill off any child processes if Citadel is
145 if (getppid() == 1) {
146 kill(0 - getpgrp(), SIGTERM);
148 kill(0 - getpgrp(), SIGKILL);
150 color(ORIGINAL_PAIR); /* Restore the old color settings */
151 sttybbs(SB_RESTORE); /* return the old terminal settings */
152 exit(code); /* exit with the proper exit code */
158 * signal catching function for hangups...
160 void dropcarr(int signum)
162 logoff(NULL, 3); /* No IPC when server's already gone! */
168 * catch SIGCONT to reset terminal modes when were are put back into the
171 void catch_sigcont(int signum)
174 signal(SIGCONT, catch_sigcont);
178 /* general purpose routines */
181 void formout(CtdlIPC *ipc, char *name)
183 int r; /* IPC return code */
187 r = CtdlIPCSystemMessage(ipc, name, &text, buf);
189 scr_printf("%s\n", buf);
193 fmout(screenwidth, NULL, text, NULL,
194 ((userflags & US_PAGINATOR) ? 1 : 0),
201 void userlist(CtdlIPC *ipc, char *patn)
207 int r; /* IPC response code */
208 char *listing = NULL;
210 r = CtdlIPCUserListing(ipc, &listing, buf);
212 pprintf("%s\n", buf);
216 pprintf(" User Name Num L LastCall Calls Posts\n");
217 pprintf("------------------------- ----- - ---------- ----- -----\n");
218 while (strlen(listing) > 0) {
219 extract_token(buf, listing, 0, '\n');
220 remove_token(listing, 0, '\n');
222 if (sigcaught == 0) {
224 if (pattern(fl, patn) >= 0) {
225 pprintf("%-25s ", fl);
226 pprintf("%5ld %d ", extract_long(buf, 2),
227 extract_int(buf, 1));
228 lc = extract_long(buf, 3);
229 tmbuf = (struct tm *) localtime(&lc);
230 pprintf("%02d/%02d/%04d ",
233 (tmbuf->tm_year + 1900));
234 pprintf("%5ld %5ld\n", extract_long(buf, 4), extract_long(buf, 5));
245 * grab assorted info about the user...
247 void load_user_info(char *params)
249 extract(fullname, params, 0);
250 axlevel = extract_int(params, 1);
251 timescalled = extract_int(params, 2);
252 posted = extract_int(params, 3);
253 userflags = extract_int(params, 4);
254 usernum = extract_long(params, 5);
255 lastcall = extract_long(params, 6);
260 * Remove a room from the march list. 'floornum' is ignored unless
261 * 'roomname' is set to _FLOOR_, in which case all rooms on the requested
262 * floor will be removed from the march list.
264 void remove_march(char *roomname, int floornum)
266 struct march *mptr, *mptr2;
271 if ((!strcasecmp(march->march_name, roomname))
272 || ((!strcasecmp(roomname, "_FLOOR_")) && (march->march_floor == floornum))) {
279 for (mptr = march; mptr != NULL; mptr = mptr->next) {
281 if ((!strcasecmp(mptr->march_name, roomname))
282 || ((!strcasecmp(roomname, "_FLOOR_"))
283 && (mptr->march_floor == floornum))) {
285 mptr2->next = mptr->next;
296 * Locate the room on the march list which we most want to go to. Each room
297 * is measured given a "weight" of preference based on various factors.
299 char *pop_march(int desired_floor)
301 static char TheRoom[ROOMNAMELEN];
303 int TheOrder = 32767;
306 struct march *mptr = NULL;
308 strcpy(TheRoom, "_BASEROOM_");
312 for (mptr = march; mptr != NULL; mptr = mptr->next) {
314 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
315 weight = weight + 10000;
316 if (mptr->march_floor == desired_floor)
317 weight = weight + 5000;
319 weight = weight + ((128 - (mptr->march_floor)) * 128);
320 weight = weight + (128 - (mptr->march_order));
322 if (weight > TheWeight) {
324 strcpy(TheRoom, mptr->march_name);
325 TheFloor = mptr->march_floor;
326 TheOrder = mptr->march_order;
334 * jump directly to a room
336 void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto)
338 char aaa[SIZ], bbb[SIZ];
340 int newmailcount = 0;
341 int partial_match, best_match;
343 int ugpos = uglistsize;
344 int r; /* IPC result code */
345 struct ctdlipcroom *room = NULL;
347 /* store ungoto information */
348 if (fromungoto == 0) {
349 /* sloppy slide them all down, hey it's the client, who cares. :-) */
350 if (uglistsize >= (UGLISTLEN-1)) {
353 for (lp = 0; lp < (UGLISTLEN-1); lp++) {
354 uglist[lp] = uglist[lp+1];
355 uglistlsn[lp] = uglistlsn[lp+1];
362 uglist[ugpos] = malloc(strlen(room_name)+1);
363 strcpy(uglist[ugpos], room_name);
364 uglistlsn[ugpos] = ls;
367 /* first try an exact match */
368 r = CtdlIPCGotoRoom(ipc, towhere, "", &room, aaa);
370 newprompt("Enter room password: ", bbb, 9);
371 r = CtdlIPCGotoRoom(ipc, towhere, bbb, &room, aaa);
373 scr_printf("Wrong password.\n");
379 * If a match is not found, try a partial match.
380 * Partial matches anywhere in the string carry a weight of 1,
381 * left-aligned matches carry a weight of 2. Pick the room that
382 * has the highest-weighted match.
385 struct march *march = NULL;
390 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, AllFloors, &march, aaa);
392 /* Run the roomlist; free the data as we go */
393 struct march *mp = march; /* Current */
397 if (pattern(mp->march_name, towhere) >= 0) {
400 if (!strncasecmp(mp->march_name, towhere, strlen(towhere))) {
403 if (partial_match > best_match) {
404 strcpy(bbb, mp->march_name);
405 best_match = partial_match;
407 /* Both pointers are NULL at end of list */
414 if (strlen(bbb) == 0) {
415 scr_printf("No room '%s'.\n", towhere);
419 r = CtdlIPCGotoRoom(ipc, bbb, "", &room, aaa);
421 if (r / 100 != 1 && r / 100 != 2) {
422 scr_printf("%s\n", aaa);
425 safestrncpy(room_name, room->RRname, ROOMNAMELEN);
426 room_flags = room->RRflags;
427 from_floor = curr_floor;
428 curr_floor = room->RRfloor;
430 remove_march(room_name, 0);
431 if (!strcasecmp(towhere, "_BASEROOM_"))
432 remove_march(towhere, 0);
434 next_lazy_cmd = 5; /* Don't read new if no new msgs */
435 if ((from_floor != curr_floor) && (display_name > 0) && (floor_mode == 1)) {
436 if (floorlist[(int) curr_floor][0] == 0)
438 scr_printf("(Entering floor: %s)\n", &floorlist[(int) curr_floor][0]);
440 if (display_name == 1) {
442 scr_printf("%s ", room_name);
446 if (display_name != 2) {
447 color(BRIGHT_YELLOW);
448 scr_printf("%d ", room->RRunread);
450 scr_printf("new of ");
451 color(BRIGHT_YELLOW);
452 scr_printf("%d ", room->RRtotal);
454 scr_printf("messages.\n");
456 highest_msg_read = room->RRlastread;
457 maxmsgnum = room->RRhighest;
458 is_mail = room->RRismailbox;
459 is_room_aide = room->RRaide;
460 ls = room->RRlastread;
462 /* read info file if necessary */
463 if (room->RRinfoupdated > 0)
466 /* check for newly arrived mail if we can */
467 newmailcount = room->RRnewmail;
468 if (newmailcount > 0) {
470 if (newmailcount == 1) {
471 scr_printf("*** A new mail message has arrived.\n");
474 scr_printf("*** %d new mail messages have arrived.\n",
478 if (strlen(rc_gotmail_cmd) > 0) {
479 system(rc_gotmail_cmd);
482 status_line(serv_info.serv_humannode, serv_info.serv_bbs_city,
483 room_name, secure, newmailcount);
486 /* Goto next room having unread messages.
487 * We want to skip over rooms that the user has already been to, and take the
488 * user back to the lobby when done. The room we end up in is placed in
489 * newroom - which is set to 0 (the lobby) initially.
491 void gotonext(CtdlIPC *ipc)
494 struct march *mptr, *mptr2;
495 char next_room[ROOMNAMELEN];
496 int r; /* IPC response code */
498 /* Check to see if the march-mode list is already allocated.
499 * If it is, pop the first room off the list and go there.
502 r = CtdlIPCKnownRooms(ipc, SubscribedRoomsWithNewMessages,
503 AllFloors, &march, buf);
505 /* add _BASEROOM_ to the end of the march list, so the user will end up
506 * in the system base room (usually the Lobby>) at the end of the loop
508 mptr = (struct march *) malloc(sizeof(struct march));
510 strcpy(mptr->march_name, "_BASEROOM_");
515 while (mptr2->next != NULL)
520 * ...and remove the room we're currently in, so a <G>oto doesn't make us
521 * walk around in circles
523 remove_march(room_name, 0);
526 strcpy(next_room, pop_march(curr_floor));
528 strcpy(next_room, "_BASEROOM_");
530 remove_march(next_room, 0);
531 dotgoto(ipc, next_room, 1, 0);
535 * forget all rooms on a given floor
537 void forget_all_rooms_on(CtdlIPC *ipc, int ffloor)
540 struct march *flist, *fptr;
541 struct ctdlipcroom *room; /* Ignored */
542 int r; /* IPC response code */
544 scr_printf("Forgetting all rooms on %s...\r", &floorlist[ffloor][0]);
546 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, ffloor, &flist, buf);
548 scr_printf("%-72s\n", buf);
552 r = CtdlIPCGotoRoom(ipc, flist->march_name, "", &room, buf);
554 r = CtdlIPCForgetRoom(ipc, buf);
560 scr_printf("%-72s\r", "");
565 * routine called by gotofloor() to move to a new room on a new floor
567 void gf_toroom(CtdlIPC *ipc, char *towhere, int mode)
569 int floor_being_left;
571 floor_being_left = curr_floor;
573 if (mode == GF_GOTO) { /* <;G>oto mode */
575 dotgoto(ipc, towhere, 1, 0);
577 if (mode == GF_SKIP) { /* <;S>kip mode */
578 dotgoto(ipc, towhere, 1, 0);
579 remove_march("_FLOOR_", floor_being_left);
581 if (mode == GF_ZAP) { /* <;Z>ap mode */
582 dotgoto(ipc, towhere, 1, 0);
583 remove_march("_FLOOR_", floor_being_left);
584 forget_all_rooms_on(ipc, floor_being_left);
592 void gotofloor(CtdlIPC *ipc, char *towhere, int mode)
595 int r; /* IPC response code */
597 char buf[SIZ], targ[SIZ];
599 if (floorlist[0][0] == 0)
602 for (a = 0; a < 128; ++a)
603 if (!strcasecmp(&floorlist[a][0], towhere))
607 for (a = 0; a < 128; ++a) {
608 if (!strncasecmp(&floorlist[a][0], towhere, strlen(towhere))) {
614 for (a = 0; a < 128; ++a)
615 if (pattern(towhere, &floorlist[a][0]) > 0)
619 scr_printf("No floor '%s'.\n", towhere);
622 for (mptr = march; mptr != NULL; mptr = mptr->next) {
623 if ((mptr->march_floor) == tofloor)
624 gf_toroom(ipc, mptr->march_name, mode);
630 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, tofloor, &mptr, buf);
632 struct march *tmp = mptr;
634 /* TODO: room order is being ignored? */
636 strncpy(targ, mptr->march_name, ROOMNAMELEN);
643 if (strlen(targ) > 0) {
644 gf_toroom(ipc, targ, mode);
646 scr_printf("There are no rooms on '%s'.\n", &floorlist[tofloor][0]);
652 * forget all rooms on current floor
654 void forget_this_floor(CtdlIPC *ipc)
657 if (curr_floor == 0) {
658 scr_printf("Can't forget this floor.\n");
661 if (floorlist[0][0] == 0)
663 scr_printf("Are you sure you want to forget all rooms on %s? ",
664 &floorlist[(int) curr_floor][0]);
668 gf_toroom(ipc, "_BASEROOM_", GF_ZAP);
673 * Figure out the physical screen dimensions, if we can
674 * WARNING: this is now called from a signal handler!
676 void check_screen_dims(void)
680 unsigned short height; /* rows */
681 unsigned short width; /* columns */
682 unsigned short xpixels;
683 unsigned short ypixels; /* pixels */
686 if (have_xterm) { /* dynamically size screen if on an xterm */
687 if (ioctl(0, TIOCGWINSZ, &xwinsz) == 0) {
689 screenheight = is_curses_enabled() ? (int)xwinsz.height - 1 : (int) xwinsz.height;
691 screenwidth = (int) xwinsz.width;
699 * set floor mode depending on client, server, and user settings
701 void set_floor_mode(void)
703 if (serv_info.serv_ok_floors == 0) {
704 floor_mode = 0; /* Don't use floors if the server */
706 /* doesn't support them! */
708 if (rc_floor_mode == RC_NO) { /* never use floors */
711 if (rc_floor_mode == RC_YES) { /* always use floors */
714 if (rc_floor_mode == RC_DEFAULT) { /* user choice */
715 floor_mode = ((userflags & US_FLOORS) ? 1 : 0);
721 * Set or change the user's password
723 int set_password(CtdlIPC *ipc)
729 if (strlen(rc_password) > 0) {
730 strcpy(pass1, rc_password);
731 strcpy(pass2, rc_password);
733 IFNEXPERT formout(ipc, "changepw");
734 newprompt("Enter a new password: ", pass1, -19);
735 newprompt("Enter it again to confirm: ", pass2, -19);
739 if (!strcasecmp(pass1, pass2)) {
740 CtdlIPCChangePassword(ipc, pass1, buf);
741 scr_printf("%s\n", buf);
742 offer_to_remember_password(ipc, hostbuf, portbuf, fullname, pass1);
745 scr_printf("*** They don't match... try again.\n");
753 * get info about the server we've connected to
755 void get_serv_info(CtdlIPC *ipc, char *supplied_hostname)
759 CtdlIPCServerInfo(ipc, &serv_info, buf);
761 /* be nice and identify ourself to the server */
762 CtdlIPCIdentifySoftware(ipc, SERVER_TYPE, 0, REV_LEVEL,
763 (ipc->isLocal ? "local" : CITADEL),
764 (supplied_hostname) ? supplied_hostname :
765 /* Look up the , in the bible if you're confused */
766 (locate_host(buf), buf), buf);
768 /* Tell the server what our preferred content formats are */
769 if ((CtdlIPCSpecifyPreferredFormats(ipc, buf, "text/html|text/plain") / 100 )== 2) {
777 * Record compare function for SortOnlineUsers()
779 int idlecmp(const void *rec1, const void *rec2) {
782 i1 = extract_long(rec1, 5);
783 i2 = extract_long(rec2, 5);
785 if (i1 < i2) return(1);
786 if (i1 > i2) return(-1);
792 * Sort the list of online users by idle time.
793 * This function frees the supplied buffer, and returns a new one
794 * to the caller. The caller is responsible for freeing the returned buffer.
796 char *SortOnlineUsers(char *listing) {
803 rows = num_tokens(listing, '\n');
804 sortbuf = malloc(rows * SIZ);
805 if (sortbuf == NULL) return(listing);
806 retbuf = malloc(rows * SIZ);
807 if (retbuf == NULL) {
812 /* Copy the list into a fixed-record-size array for sorting */
813 for (i=0; i<rows; ++i) {
815 extract_token(buf, listing, i, '\n');
816 memcpy(&sortbuf[i*SIZ], buf, SIZ);
820 qsort(sortbuf, rows, SIZ, idlecmp);
822 /* Copy back to a \n delimited list */
824 for (i=0; i<rows; ++i) {
825 strcat(retbuf, &sortbuf[i*SIZ]);
826 if (i<(rows-1)) strcat(retbuf, "\n");
834 * Display list of users currently logged on to the server
836 void who_is_online(CtdlIPC *ipc, int longlist)
838 char buf[SIZ], username[SIZ], roomname[SIZ], fromhost[SIZ];
840 char actual_user[SIZ], actual_room[SIZ], actual_host[SIZ];
841 char clientsoft[SIZ];
843 time_t idletime, idlehours, idlemins, idlesecs;
844 int last_session = (-1);
846 char *listing = NULL;
847 int r; /* IPC response code */
856 pprintf(" User Name Room Idle From host\n");
858 pprintf(" ------------------------- -------------------- ---- ------------------------\n");
860 r = CtdlIPCOnlineUsers(ipc, &listing, &timenow, buf);
861 listing = SortOnlineUsers(listing);
863 while (strlen(listing) > 0) {
866 /* Get another line */
867 extract_token(buf, listing, 0, '\n');
868 remove_token(listing, 0, '\n');
870 extract(username, buf, 1);
871 extract(roomname, buf, 2);
872 extract(fromhost, buf, 3);
873 extract(clientsoft, buf, 4);
874 extract(flags, buf, 7);
876 idletime = timenow - extract_long(buf, 5);
877 idlehours = idletime / 3600;
878 idlemins = (idletime - (idlehours * 3600)) / 60;
879 idlesecs = (idletime - (idlehours * 3600) - (idlemins * 60));
881 if (idletime > rc_idle_threshold) {
883 while (strlen(roomname) < 20) {
884 strcat(roomname, " ");
886 strcpy(&roomname[14], "[idle]");
893 extract(actual_user, buf, 8);
894 extract(actual_room, buf, 9);
895 extract(actual_host, buf, 10);
897 pprintf(" Flags: %s\n", flags);
898 pprintf("Session: %d\n", extract_int(buf, 0));
899 pprintf(" Name: %s\n", username);
900 pprintf("In room: %s\n", roomname);
901 pprintf(" Host: %s\n", fromhost);
902 pprintf(" Client: %s\n", clientsoft);
903 pprintf(" Idle: %ld:%02ld:%02ld\n",
908 if ( (strlen(actual_user)+strlen(actual_room)+strlen(actual_host)) > 0) {
910 if (strlen(actual_user)>0) pprintf("<%s> ", actual_user);
911 if (strlen(actual_room)>0) pprintf("in <%s> ", actual_room);
912 if (strlen(actual_host)>0) pprintf("from <%s> ", actual_host);
919 if (extract_int(buf, 0) == last_session) {
922 color(BRIGHT_MAGENTA);
923 pprintf("%-3s", flags);
925 last_session = extract_int(buf, 0);
927 pprintf("%-25s ", username);
928 color(BRIGHT_MAGENTA);
930 pprintf("%-20s ", roomname);
931 if (idletime > rc_idle_threshold) {
932 /* over 1000d, must be gone fishing */
933 if (idlehours > 23999) {
936 } else if (idlehours > 239) {
940 } else if (idlehours > 9) {
941 pprintf("%1ldd%02ld",
944 /* less than 10 hours */
946 pprintf("%1ld:%02ld",
947 idlehours, idlemins);
956 pprintf("%-24s\n", fromhost);
965 void enternew(CtdlIPC *ipc, char *desc, char *buf, int maxlen)
968 snprintf(bbb, sizeof bbb, "Enter in your new %s: ", desc);
969 newprompt(bbb, buf, maxlen);
974 int shift(int argc, char **argv, int start, int count) {
977 for (i=start; i<(argc-count); ++i) {
978 argv[i] = argv[i+count];
984 static void statusHook(char *s) {
992 int main(int argc, char **argv)
995 char aaa[100], bbb[100];/* general purpose variables */
996 char argbuf[32]; /* command line buf */
997 char nonce[NONCE_SIZE];
998 char *telnet_client_host = NULL;
999 char *sptr, *sptr2; /* USed to extract the nonce */
1000 char hexstring[MD5_HEXSTRING_SIZE];
1001 int stored_password = 0;
1003 struct ctdlipcmisc chek;
1004 struct user *myself = NULL;
1005 CtdlIPC* ipc; /* Our server connection */
1006 int r; /* IPC result code */
1008 setIPCDeathHook(screen_delete);
1009 setIPCErrorPrintf(err_printf);
1010 setCryptoStatusHook(statusHook);
1012 /* Permissions sanity check - don't run citadel setuid/setgid */
1013 if (getuid() != geteuid()) {
1014 err_printf("Please do not run citadel setuid!\n");
1016 } else if (getgid() != getegid()) {
1017 err_printf("Please do not run citadel setgid!\n");
1021 sttybbs(SB_SAVE); /* Store the old terminal parameters */
1022 load_command_set(); /* parse the citadel.rc file */
1023 sttybbs(SB_NO_INTR); /* Install the new ones */
1024 signal(SIGHUP, dropcarr); /* Cleanup gracefully if carrier is dropped */
1025 signal(SIGTERM, dropcarr); /* Cleanup gracefully if terminated */
1026 signal(SIGCONT, catch_sigcont); /* Catch SIGCONT so we can reset terminal */
1028 signal(SIGWINCH, scr_winch); /* Window resize signal */
1032 arg_encrypt = RC_DEFAULT;
1034 #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
1035 arg_screen = RC_DEFAULT;
1039 * Handle command line options as if we were called like /bin/login
1040 * (i.e. from in.telnetd)
1042 for (a=0; a<argc; ++a) {
1043 if ((argc > a+1) && (!strcmp(argv[a], "-h")) ) {
1044 telnet_client_host = argv[a+1];
1045 argc = shift(argc, argv, a, 2);
1047 if (!strcmp(argv[a], "-x")) {
1049 arg_encrypt = RC_NO;
1051 argc = shift(argc, argv, a, 1);
1053 if (!strcmp(argv[a], "-X")) {
1055 arg_encrypt = RC_YES;
1056 argc = shift(argc, argv, a, 1);
1058 fprintf(stderr, "Not compiled with encryption support");
1062 if (!strcmp(argv[a], "-s")) {
1063 #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
1066 argc = shift(argc, argv, a, 1);
1068 if (!strcmp(argv[a], "-S")) {
1069 #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
1070 arg_screen = RC_YES;
1072 argc = shift(argc, argv, a, 1);
1074 if (!strcmp(argv[a], "-p")) {
1077 if (chdir(BBSDIR) < 0) {
1078 perror("can't change to " BBSDIR);
1083 * Drop privileges if necessary. We stat
1084 * citadel.config to get the uid/gid since it's
1085 * guaranteed to have the uid/gid we want.
1087 if (!getuid() || !getgid()) {
1088 if (stat(BBSDIR "/citadel.config", &st) < 0) {
1089 perror("couldn't stat citadel.config");
1092 if (!getgid() && (setgid(st.st_gid) < 0)) {
1093 perror("couldn't change gid");
1096 if (!getuid() && (setuid(st.st_uid) < 0)) {
1097 perror("couldn't change uid");
1101 scr_printf("Privileges changed to uid %d gid %d\n",
1102 getuid(), getgid());
1105 argc = shift(argc, argv, a, 1);
1112 newprompt("Connect to (return for local server): ", hostbuf, 64);
1115 sln_printf("Attaching to server... \r");
1117 ipc = CtdlIPC_new(argc, argv, hostbuf, portbuf);
1120 error_printf("Can't connect: %s\n", strerror(errno));
1123 #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
1124 CtdlIPC_SetNetworkStatusCallback(ipc, wait_indicator);
1126 ipc_for_signal_handlers = ipc; /* KLUDGE cover your eyes */
1128 CtdlIPC_getline(ipc, aaa);
1129 if (aaa[0] != '2') {
1130 scr_printf("%s\n", &aaa[4]);
1131 logoff(ipc, atoi(aaa));
1134 /* If there is a [nonce] at the end, put the nonce in <nonce>, else nonce
1138 if ((sptr = strchr(aaa, '<')) == NULL)
1144 if ((sptr2 = strchr(sptr, '>')) == NULL)
1152 strncpy(nonce, sptr, NONCE_SIZE);
1157 /* Evaluate encryption preferences */
1158 if (arg_encrypt != RC_NO && rc_encrypt != RC_NO) {
1159 if (!ipc->isLocal || arg_encrypt == RC_YES || rc_encrypt == RC_YES) {
1160 secure = (CtdlIPCStartEncryption(ipc, aaa) / 100 == 2) ? 1 : 0;
1162 error_printf("Can't encrypt: %s\n", aaa);
1167 get_serv_info(ipc, telnet_client_host);
1168 scr_printf("%-24s\n%s\n%s\n", serv_info.serv_software, serv_info.serv_humannode,
1169 serv_info.serv_bbs_city);
1172 status_line(serv_info.serv_humannode, serv_info.serv_bbs_city, NULL,
1175 screenwidth = 80; /* default screen dimensions */
1178 scr_printf(" pause next stop\n");
1179 scr_printf(" ctrl-s ctrl-o ctrl-c\n\n");
1180 formout(ipc, "hello"); /* print the opening greeting */
1183 GSTA: /* See if we have a username and password on disk */
1184 if (rc_remember_passwords) {
1185 get_stored_password(hostbuf, portbuf, fullname, password);
1186 if (strlen(fullname) > 0) {
1187 r = CtdlIPCTryLogin(ipc, fullname, aaa);
1190 r = CtdlIPCTryApopPassword(ipc, make_apop_string(password, nonce, hexstring, sizeof hexstring), aaa);
1192 r = CtdlIPCTryPassword(ipc, password, aaa);
1197 load_user_info(aaa);
1198 stored_password = 1;
1201 set_stored_password(hostbuf, portbuf, "", "");
1209 if (strlen(rc_username) > 0) {
1210 strcpy(fullname, rc_username);
1212 newprompt("Enter your name: ", fullname, 29);
1215 if (!strcasecmp(fullname, "new")) { /* just in case */
1216 scr_printf("Please enter the name you wish to log in with.\n");
1219 (!strcasecmp(fullname, "bbs"))
1220 || (!strcasecmp(fullname, "new"))
1221 || (strlen(fullname) == 0));
1223 if (!strcasecmp(fullname, "off")) {
1227 /* sign on to the server */
1228 r = CtdlIPCTryLogin(ipc, fullname, aaa);
1232 /* password authentication */
1233 if (strlen(rc_password) > 0) {
1234 strcpy(password, rc_password);
1236 newprompt("\rPlease enter your password: ", password, -19);
1241 r = CtdlIPCTryApopPassword(ipc, make_apop_string(password, nonce, hexstring, sizeof hexstring), aaa);
1243 r = CtdlIPCTryPassword(ipc, password, aaa);
1247 load_user_info(aaa);
1248 offer_to_remember_password(ipc, hostbuf, portbuf,
1249 fullname, password);
1252 scr_printf("<< wrong password >>\n");
1253 if (strlen(rc_password) > 0)
1257 NEWUSR: if (strlen(rc_password) == 0) {
1258 scr_printf("No record. Enter as new user? ");
1263 r = CtdlIPCCreateUser(ipc, fullname, 1, aaa);
1265 scr_printf("%s\n", aaa);
1268 load_user_info(aaa);
1270 while (set_password(ipc) != 0);
1273 enter_config(ipc, 1);
1276 /* Switch color support on or off if we're in user mode */
1277 if (rc_ansi_color == 3) {
1278 if (userflags & US_COLOR)
1284 color(BRIGHT_WHITE);
1285 scr_printf("\n%s\nAccess level: %d (%s)\n"
1286 "User #%ld / Login #%d",
1287 fullname, axlevel, axdefs[(int) axlevel],
1288 usernum, timescalled);
1289 if (lastcall > 0L) {
1290 scr_printf(" / Last login: %s",
1291 asctime(localtime(&lastcall)));
1295 r = CtdlIPCMiscCheck(ipc, &chek, aaa);
1301 scr_printf("*** You have a new private message in Mail>\n");
1303 scr_printf("*** You have %d new private messages in Mail>\n", b);
1305 if (strlen(rc_gotmail_cmd) > 0) {
1306 system(rc_gotmail_cmd);
1309 if ((axlevel >= 6) && (chek.needvalid > 0)) {
1310 scr_printf("*** Users need validation\n");
1312 if (chek.needregis > 0) {
1313 scr_printf("*** Please register.\n");
1314 formout(ipc, "register");
1318 /* Make up some temporary filenames for use in various parts of the
1319 * program. Don't mess with these once they've been set, because we
1320 * will be unlinking them later on in the program and we don't
1321 * want to delete something that we didn't create. */
1322 snprintf(temp, sizeof temp, tmpnam(NULL));
1323 snprintf(temp2, sizeof temp2, tmpnam(NULL));
1324 snprintf(tempdir, sizeof tempdir, tmpnam(NULL));
1326 /* Get screen dimensions. First we go to a default of 80x24. Then
1327 * we try to get the user's actual screen dimensions off the server.
1328 * However, if we're running on an xterm, all this stuff is
1329 * irrelevant because we're going to dynamically size the screen
1330 * during the session.
1334 r = CtdlIPCGetConfig(ipc, &myself, aaa);
1336 screenwidth = myself->USscreenwidth;
1337 screenheight = myself->USscreenheight;
1339 if (getenv("TERM") != NULL)
1340 if (!strcmp(getenv("TERM"), "xterm")) {
1344 check_screen_dims();
1349 /* Enter the lobby */
1350 dotgoto(ipc, "_BASEROOM_", 1, 0);
1352 /* Main loop for the system... user is logged in. */
1356 readmsgs(ipc, LastMessages, ReadForward, 5);
1358 readmsgs(ipc, NewMessages, ReadForward, 0);
1360 /* MAIN COMMAND LOOP */
1362 mcmd = getcmd(ipc, argbuf); /* Get keyboard command */
1365 check_screen_dims(); /* if xterm, get screen size */
1371 formout(ipc, "help");
1383 newprompt("What do you want your username to be? ", aaa, 32);
1384 snprintf(bbb, sizeof bbb, "ENT0 2|0|0|0|%s", aaa);
1385 CtdlIPC_putline(ipc, bbb);
1386 CtdlIPC_getline(ipc, aaa);
1387 if (strncmp("200", aaa, 3))
1388 scr_printf("\n%s\n", aaa);
1392 case 5: /* <G>oto */
1396 case 47: /* <A>bandon */
1397 if (!rc_alt_semantics) {
1402 case 90: /* <.A>bandon */
1403 if (!rc_alt_semantics)
1405 dotgoto(ipc, argbuf, 0, 0);
1407 case 58: /* <M>ail */
1409 dotgoto(ipc, "_MAIL_", 1, 0);
1412 if (strlen(argbuf) > 0) {
1414 dotgoto(ipc, argbuf, 0, 0);
1418 if (strlen(argbuf) > 0) {
1419 if (rc_alt_semantics) {
1422 dotgoto(ipc, argbuf, 0, 0);
1425 case 95: /* what exactly is the numbering scheme supposed to be anyway? */
1426 dotungoto(ipc, argbuf);
1429 readmsgs(ipc, AllMessages, ReadForward, 0);
1432 readmsgs(ipc, LastMessages, ReadForward, 5);
1435 readmsgs(ipc, NewMessages, ReadForward, 0);
1438 readmsgs(ipc, AllMessages, ReadReverse, 0);
1441 readmsgs(ipc, OldMessages, ReadReverse, 0);
1444 readmsgs(ipc, LastMessages, ReadForward,
1461 userlist(ipc, argbuf);
1519 if (!rc_alt_semantics) {
1531 cli_image_upload(ipc, "_userpic_");
1534 cli_image_upload(ipc, "_roompic_");
1538 snprintf(aaa, sizeof aaa, "_floorpic_|%d", curr_floor);
1539 cli_image_upload(ipc, aaa);
1543 enternew(ipc, "roomname", aaa, 20);
1544 r = CtdlIPCChangeRoomname(ipc, aaa, bbb);
1546 scr_printf("\n%s\n", aaa);
1549 enternew(ipc, "hostname", aaa, 25);
1550 r = CtdlIPCChangeHostname(ipc, aaa, bbb);
1552 scr_printf("\n%s\n", aaa);
1555 enternew(ipc, "username", aaa, 32);
1556 r = CtdlIPCChangeUsername(ipc, aaa, bbb);
1558 scr_printf("\n%s\n", aaa);
1568 display_help(ipc, argbuf);
1572 formout(ipc, "register");
1577 scr_printf("Are you sure (y/n)? ");
1579 if (!rc_alt_semantics)
1587 scr_printf("All users will be disconnected! "
1588 "Really terminate the server? ");
1590 if (!rc_alt_semantics)
1592 r = CtdlIPCTerminateServerNow(ipc, aaa);
1593 scr_printf("%s\n", aaa);
1602 scr_printf("Do you really want to schedule a "
1603 "server shutdown? ");
1605 r = CtdlIPCTerminateServerScheduled(ipc, 1, aaa);
1609 "The Citadel server will terminate when all users are logged off.\n"
1613 "The Citadel server will not terminate.\n"
1621 network_config_management(ipc, "listrecp",
1622 "Message-by-message mailing list recipients");
1626 network_config_management(ipc, "digestrecp",
1627 "Digest mailing list recipients");
1631 network_config_management(ipc, "ignet_push_share",
1632 "Nodes with which we share this room");
1636 do_ignet_configuration(ipc);
1640 do_filterlist_configuration(ipc);
1644 if (rc_alt_semantics) {
1657 sttybbs(SB_RESTORE);
1658 snprintf(aaa, sizeof aaa, "USERNAME=\042%s\042; export USERNAME;"
1659 "exec ./subsystem %ld %d %d", fullname,
1660 usernum, screenwidth, axlevel);
1662 sttybbs(SB_NO_INTR);
1665 scr_printf("*** Can't run doors when server is not local.\n");
1670 who_is_online(ipc, 0);
1674 who_is_online(ipc, 1);
1678 who_is_online(ipc, 2);
1682 do_system_configuration(ipc);
1686 do_internet_configuration(ipc);
1690 check_message_base(ipc);
1702 enter_config(ipc, 2);
1706 enter_config(ipc, 0);
1711 enter_config(ipc, 3);
1716 gotofloor(ipc, argbuf, GF_GOTO);
1720 gotofloor(ipc, argbuf, GF_SKIP);
1724 forget_this_floor(ipc);
1752 knrooms(ipc, floor_mode);
1762 misc_server_cmd(ipc, argbuf);
1766 edit_system_message(ipc, argbuf);
1790 default: /* allow some math on the command */
1791 /* commands 100... to 100+MAX_EDITORS-1 will
1792 call the appropriate editor... in other
1793 words, command numbers 100+ will match
1794 the citadel.rc keys editor0, editor1, etc.*/
1795 if (mcmd >= 100 && mcmd < (100+MAX_EDITORS))
1797 /* entmsg mode >=2 select editor */
1798 entmsg(ipc, 0, mcmd - 100 + 2);
1802 } while (termn8 == 0);
1804 TERMN8: scr_printf("%s logged out.", fullname);
1806 color(ORIGINAL_PAIR);
1808 while (march != NULL) {
1809 remove_march(march->march_name, 0);
1812 sln_printf("\n\nType 'off' to disconnect, or next user...\n");
1815 if ((mcmd == 29) || (mcmd == 15)) {
1817 sttybbs(SB_RESTORE);
1818 formout(ipc, "goodbye");