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>
38 #include "citadel_ipc.h"
41 #include "routines2.h"
45 #include "client_chat.h"
46 #include "client_passwords.h"
47 #include "citadel_decls.h"
57 #define IFEXPERT if (userflags&US_EXPERT)
58 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
59 #define IFAIDE if (axlevel>=6)
60 #define IFNAIDE if (axlevel<6)
62 struct march *march = NULL;
64 /* globals associated with the client program */
65 char temp[PATH_MAX]; /* Name of general temp file */
66 char temp2[PATH_MAX]; /* Name of general temp file */
67 char tempdir[PATH_MAX]; /* Name of general temp dir */
68 char editor_path[SIZ]; /* path to external editor */
69 char printcmd[SIZ]; /* print command */
70 int editor_pid = (-1);
71 char fullname[USERNAME_SIZE];
73 struct CtdlServInfo serv_info; /* Info on the server connected */
77 char room_name[ROOMNAMELEN];
78 char *uglist[UGLISTLEN]; /* size of the ungoto list */
79 long uglistlsn[UGLISTLEN]; /* current read position for all the ungoto's. Not going to make any friends with this one. */
81 char is_mail = 0; /* nonzero when we're in a mail room */
82 char axlevel = 0; /* access level */
83 char is_room_aide = 0; /* boolean flag, 1 if room aide */
87 long usernum = 0L; /* user number */
88 time_t lastcall = 0L; /* Date/time of previous login */
90 long highest_msg_read; /* used for <A>bandon room cmd */
91 long maxmsgnum; /* used for <G>oto */
93 char have_xterm = 0; /* are we running on an xterm? */
94 char rc_username[USERNAME_SIZE];
100 char curr_floor = 0; /* number of current floor */
101 char floorlist[128][SIZ]; /* names of floors */
102 int termn8 = 0; /* Set to nonzero to cause a logoff */
103 int secure; /* Set to nonzero when wire is encrypted */
104 int can_do_msg4 = 0; /* Set to nonzero if the server can handle MSG4 commands */
106 extern char express_msgs; /* express messages waiting! */
107 extern int rc_ansi_color; /* ansi color value from citadel.rc */
108 extern int next_lazy_cmd;
110 CtdlIPC *ipc_for_signal_handlers; /* KLUDGE cover your eyes */
113 * here is our 'clean up gracefully and exit' routine
115 void logoff(CtdlIPC *ipc, int code)
118 if (editor_pid > 0) { /* kill the editor if it's running */
119 kill(editor_pid, SIGHUP);
122 /* Free the ungoto list */
123 for (lp = 0; lp < uglistsize; lp++)
126 /* shut down the server... but not if the logoff code is 3, because
127 * that means we're exiting because we already lost the server
133 * 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);
179 /* 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 *roomrec = 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];
361 uglist[ugpos] = malloc(strlen(room_name)+1);
362 strcpy(uglist[ugpos], room_name);
363 uglistlsn[ugpos] = ls;
366 /* first try an exact match */
367 r = CtdlIPCGotoRoom(ipc, towhere, "", &roomrec, aaa);
369 newprompt("Enter room password: ", bbb, 9);
370 r = CtdlIPCGotoRoom(ipc, towhere, bbb, &roomrec, aaa);
372 scr_printf("Wrong password.\n");
378 * If a match is not found, try a partial match.
379 * Partial matches anywhere in the string carry a weight of 1,
380 * left-aligned matches carry a weight of 2. Pick the room that
381 * has the highest-weighted match.
384 struct march *march = NULL;
389 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, -1, &march, aaa);
391 /* Run the roomlist; free the data as we go */
392 struct march *mp = march; /* Current */
396 if (pattern(mp->march_name, towhere) >= 0) {
399 if (!strncasecmp(mp->march_name, towhere, strlen(towhere))) {
402 if (partial_match > best_match) {
403 strcpy(bbb, mp->march_name);
404 best_match = partial_match;
406 /* Both pointers are NULL at end of list */
413 if (strlen(bbb) == 0) {
414 scr_printf("No room '%s'.\n", towhere);
418 r = CtdlIPCGotoRoom(ipc, bbb, "", &roomrec, aaa);
420 if (r / 100 != 1 && r / 100 != 2) {
421 scr_printf("%s\n", aaa);
424 safestrncpy(room_name, roomrec->RRname, ROOMNAMELEN);
425 room_flags = roomrec->RRflags;
426 from_floor = curr_floor;
427 curr_floor = roomrec->RRfloor;
429 remove_march(room_name, 0);
430 if (!strcasecmp(towhere, "_BASEROOM_"))
431 remove_march(towhere, 0);
432 if (!roomrec->RRunread)
433 next_lazy_cmd = 5; /* Don't read new if no new msgs */
434 if ((from_floor != curr_floor) && (display_name > 0) && (floor_mode == 1)) {
435 if (floorlist[(int) curr_floor][0] == 0)
437 scr_printf("(Entering floor: %s)\n", &floorlist[(int) curr_floor][0]);
439 if (display_name == 1) {
441 scr_printf("%s ", room_name);
445 if (display_name != 2) {
446 color(BRIGHT_YELLOW);
447 scr_printf("%d ", roomrec->RRunread);
449 scr_printf("new of ");
450 color(BRIGHT_YELLOW);
451 scr_printf("%d ", roomrec->RRtotal);
453 scr_printf("messages.\n");
455 highest_msg_read = roomrec->RRlastread;
456 maxmsgnum = roomrec->RRhighest;
457 is_mail = roomrec->RRismailbox;
458 is_room_aide = roomrec->RRaide;
459 ls = roomrec->RRlastread;
461 /* read info file if necessary */
462 if (roomrec->RRinfoupdated > 0)
465 /* check for newly arrived mail if we can */
466 newmailcount = roomrec->RRnewmail;
467 if (newmailcount > 0) {
469 if (newmailcount == 1) {
470 scr_printf("*** A new mail message has arrived.\n");
473 scr_printf("*** %d new mail messages have arrived.\n",
477 if (strlen(rc_gotmail_cmd) > 0) {
478 system(rc_gotmail_cmd);
481 status_line(serv_info.serv_humannode, serv_info.serv_bbs_city,
482 room_name, secure, newmailcount);
485 /* Goto next room having unread messages.
486 * We want to skip over rooms that the user has already been to, and take the
487 * user back to the lobby when done. The room we end up in is placed in
488 * newroom - which is set to 0 (the lobby) initially.
490 void gotonext(CtdlIPC *ipc)
493 struct march *mptr, *mptr2;
494 char next_room[ROOMNAMELEN];
495 int r; /* IPC response code */
497 /* Check to see if the march-mode list is already allocated.
498 * If it is, pop the first room off the list and go there.
501 r = CtdlIPCKnownRooms(ipc, SubscribedRoomsWithNewMessages, -1, &march, buf);
502 /* add _BASEROOM_ to the end of the march list, so the user will end up
503 * in the system base room (usually the Lobby>) at the end of the loop
505 mptr = (struct march *) malloc(sizeof(struct march));
507 strcpy(mptr->march_name, "_BASEROOM_");
512 while (mptr2->next != NULL)
517 * ...and remove the room we're currently in, so a <G>oto doesn't make us
518 * walk around in circles
520 remove_march(room_name, 0);
523 strcpy(next_room, pop_march(curr_floor));
525 strcpy(next_room, "_BASEROOM_");
527 remove_march(next_room, 0);
528 dotgoto(ipc, next_room, 1, 0);
532 * forget all rooms on a given floor
534 void forget_all_rooms_on(CtdlIPC *ipc, int ffloor)
537 struct march *flist, *fptr;
538 struct ctdlipcroom *roomrec; /* Ignored */
539 int r; /* IPC response code */
541 scr_printf("Forgetting all rooms on %s...\r", &floorlist[ffloor][0]);
543 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, ffloor, &flist, buf);
545 scr_printf("%-72s\n", buf);
549 r = CtdlIPCGotoRoom(ipc, flist->march_name, "", &roomrec, buf);
551 r = CtdlIPCForgetRoom(ipc, buf);
557 scr_printf("%-72s\r", "");
562 * routine called by gotofloor() to move to a new room on a new floor
564 void gf_toroom(CtdlIPC *ipc, char *towhere, int mode)
566 int floor_being_left;
568 floor_being_left = curr_floor;
570 if (mode == GF_GOTO) { /* <;G>oto mode */
572 dotgoto(ipc, towhere, 1, 0);
574 if (mode == GF_SKIP) { /* <;S>kip mode */
575 dotgoto(ipc, towhere, 1, 0);
576 remove_march("_FLOOR_", floor_being_left);
578 if (mode == GF_ZAP) { /* <;Z>ap mode */
579 dotgoto(ipc, towhere, 1, 0);
580 remove_march("_FLOOR_", floor_being_left);
581 forget_all_rooms_on(ipc, floor_being_left);
589 void gotofloor(CtdlIPC *ipc, char *towhere, int mode)
592 int r; /* IPC response code */
594 char buf[SIZ], targ[SIZ];
596 if (floorlist[0][0] == 0)
599 for (a = 0; a < 128; ++a)
600 if (!strcasecmp(&floorlist[a][0], towhere))
604 for (a = 0; a < 128; ++a) {
605 if (!strncasecmp(&floorlist[a][0], towhere, strlen(towhere))) {
611 for (a = 0; a < 128; ++a)
612 if (pattern(towhere, &floorlist[a][0]) > 0)
616 scr_printf("No floor '%s'.\n", towhere);
619 for (mptr = march; mptr != NULL; mptr = mptr->next) {
620 if ((mptr->march_floor) == tofloor)
621 gf_toroom(ipc, mptr->march_name, mode);
627 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, tofloor, &mptr, buf);
629 struct march *tmp = mptr;
631 /* TODO: room order is being ignored? */
633 strncpy(targ, mptr->march_name, ROOMNAMELEN);
640 if (strlen(targ) > 0) {
641 gf_toroom(ipc, targ, mode);
643 scr_printf("There are no rooms on '%s'.\n", &floorlist[tofloor][0]);
649 * forget all rooms on current floor
651 void forget_this_floor(CtdlIPC *ipc)
654 if (curr_floor == 0) {
655 scr_printf("Can't forget this floor.\n");
658 if (floorlist[0][0] == 0)
660 scr_printf("Are you sure you want to forget all rooms on %s? ",
661 &floorlist[(int) curr_floor][0]);
665 gf_toroom(ipc, "_BASEROOM_", GF_ZAP);
670 * Figure out the physical screen dimensions, if we can
671 * WARNING: this is now called from a signal handler!
673 void check_screen_dims(void)
677 unsigned short height; /* rows */
678 unsigned short width; /* columns */
679 unsigned short xpixels;
680 unsigned short ypixels; /* pixels */
683 if (have_xterm) { /* dynamically size screen if on an xterm */
684 if (ioctl(0, TIOCGWINSZ, &xwinsz) == 0) {
686 screenheight = is_curses_enabled() ? (int)xwinsz.height - 1 : (int) xwinsz.height;
688 screenwidth = (int) xwinsz.width;
696 * set floor mode depending on client, server, and user settings
698 void set_floor_mode(void)
700 if (serv_info.serv_ok_floors == 0) {
701 floor_mode = 0; /* Don't use floors if the server */
703 /* doesn't support them! */
705 if (rc_floor_mode == RC_NO) { /* never use floors */
708 if (rc_floor_mode == RC_YES) { /* always use floors */
711 if (rc_floor_mode == RC_DEFAULT) { /* user choice */
712 floor_mode = ((userflags & US_FLOORS) ? 1 : 0);
718 * Set or change the user's password
720 int set_password(CtdlIPC *ipc)
726 if (strlen(rc_password) > 0) {
727 strcpy(pass1, rc_password);
728 strcpy(pass2, rc_password);
730 IFNEXPERT formout(ipc, "changepw");
731 newprompt("Enter a new password: ", pass1, -19);
732 newprompt("Enter it again to confirm: ", pass2, -19);
736 if (!strcasecmp(pass1, pass2)) {
737 CtdlIPCChangePassword(ipc, pass1, buf);
738 scr_printf("%s\n", buf);
739 offer_to_remember_password(ipc, hostbuf, portbuf, fullname, pass1);
742 scr_printf("*** They don't match... try again.\n");
750 * get info about the server we've connected to
752 void get_serv_info(CtdlIPC *ipc, char *supplied_hostname)
756 CtdlIPCServerInfo(ipc, &serv_info, buf);
758 /* be nice and identify ourself to the server */
759 CtdlIPCIdentifySoftware(ipc, SERVER_TYPE, 0, REV_LEVEL,
760 (ipc->isLocal ? "local" : CITADEL),
761 (supplied_hostname) ? supplied_hostname : "", buf);
762 /* (locate_host(buf), buf)); */
764 /* Tell the server what our preferred content formats are */
765 if ((CtdlIPCSpecifyPreferredFormats(ipc, buf, "text/html|text/plain") / 100 )== 2) {
775 * Display list of users currently logged on to the server
777 void who_is_online(CtdlIPC *ipc, int longlist)
779 char buf[SIZ], username[SIZ], roomname[SIZ], fromhost[SIZ];
781 char actual_user[SIZ], actual_room[SIZ], actual_host[SIZ];
782 char clientsoft[SIZ];
784 time_t idletime, idlehours, idlemins, idlesecs;
785 int last_session = (-1);
787 char *listing = NULL;
788 int r; /* IPC response code */
797 pprintf("FLG ### User Name Room From host\n");
799 pprintf("--- --- ------------------------- -------------------- ------------------------\n");
801 r = CtdlIPCOnlineUsers(ipc, &listing, &timenow, buf);
803 while (strlen(listing) > 0) {
806 /* Get another line */
807 extract_token(buf, listing, 0, '\n');
808 remove_token(listing, 0, '\n');
810 extract(username, buf, 1);
811 extract(roomname, buf, 2);
812 extract(fromhost, buf, 3);
813 extract(clientsoft, buf, 4);
814 extract(flags, buf, 7);
816 idletime = timenow - extract_long(buf, 5);
817 idlehours = idletime / 3600;
818 idlemins = (idletime - (idlehours * 3600)) / 60;
819 idlesecs = (idletime - (idlehours * 3600) - (idlemins * 60));
821 if (idletime > rc_idle_threshold) {
822 while (strlen(roomname) < 20) {
823 strcat(roomname, " ");
825 strcpy(&roomname[14], "[idle]");
831 extract(actual_user, buf, 8);
832 extract(actual_room, buf, 9);
833 extract(actual_host, buf, 10);
835 pprintf(" Flags: %s\n", flags);
836 pprintf("Session: %d\n", extract_int(buf, 0));
837 pprintf(" Name: %s\n", username);
838 pprintf("In room: %s\n", roomname);
839 pprintf(" Host: %s\n", fromhost);
840 pprintf(" Client: %s\n", clientsoft);
841 pprintf(" Idle: %ld:%02ld:%02ld\n",
846 if ( (strlen(actual_user)+strlen(actual_room)+strlen(actual_host)) > 0) {
848 if (strlen(actual_user)>0) pprintf("<%s> ", actual_user);
849 if (strlen(actual_room)>0) pprintf("in <%s> ", actual_room);
850 if (strlen(actual_host)>0) pprintf("from <%s> ", actual_host);
857 if (extract_int(buf, 0) == last_session) {
860 color(BRIGHT_MAGENTA);
861 pprintf("%-3s ", flags);
863 pprintf("%-3d ", extract_int(buf, 0));
865 last_session = extract_int(buf, 0);
867 pprintf("%-25s ", username);
868 color(BRIGHT_MAGENTA);
870 pprintf("%-20s ", roomname);
873 pprintf("%-24s\n", fromhost);
882 void enternew(CtdlIPC *ipc, char *desc, char *buf, int maxlen)
885 snprintf(bbb, sizeof bbb, "Enter in your new %s: ", desc);
886 newprompt(bbb, buf, maxlen);
891 int shift(int argc, char **argv, int start, int count) {
894 for (i=start; i<(argc-count); ++i) {
895 argv[i] = argv[i+count];
901 static void statusHook(char *s) {
909 int main(int argc, char **argv)
912 char aaa[100], bbb[100];/* general purpose variables */
913 char argbuf[32]; /* command line buf */
914 char nonce[NONCE_SIZE];
915 char *telnet_client_host = NULL;
916 char *sptr, *sptr2; /* USed to extract the nonce */
917 char hexstring[MD5_HEXSTRING_SIZE];
918 int stored_password = 0;
920 struct ctdlipcmisc chek;
921 struct usersupp *myself = NULL;
922 CtdlIPC* ipc; /* Our server connection */
923 int r; /* IPC result code */
925 setIPCDeathHook(screen_delete);
926 setIPCErrorPrintf(err_printf);
927 setCryptoStatusHook(statusHook);
929 /* Permissions sanity check - don't run citadel setuid/setgid */
930 if (getuid() != geteuid()) {
931 err_printf("Please do not run citadel setuid!\n");
933 } else if (getgid() != getegid()) {
934 err_printf("Please do not run citadel setgid!\n");
938 sttybbs(SB_SAVE); /* Store the old terminal parameters */
939 load_command_set(); /* parse the citadel.rc file */
940 sttybbs(SB_NO_INTR); /* Install the new ones */
941 signal(SIGHUP, dropcarr); /* Cleanup gracefully if carrier is dropped */
942 signal(SIGTERM, dropcarr); /* Cleanup gracefully if terminated */
943 signal(SIGCONT, catch_sigcont); /* Catch SIGCONT so we can reset terminal */
945 signal(SIGWINCH, scr_winch); /* Window resize signal */
949 arg_encrypt = RC_DEFAULT;
951 #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
952 arg_screen = RC_DEFAULT;
956 * Handle command line options as if we were called like /bin/login
957 * (i.e. from in.telnetd)
959 for (a=0; a<argc; ++a) {
960 if ((argc > a+1) && (!strcmp(argv[a], "-h")) ) {
961 telnet_client_host = argv[a+1];
962 argc = shift(argc, argv, a, 2);
964 if (!strcmp(argv[a], "-x")) {
968 argc = shift(argc, argv, a, 1);
970 if (!strcmp(argv[a], "-X")) {
972 arg_encrypt = RC_YES;
973 argc = shift(argc, argv, a, 1);
975 fprintf(stderr, "Not compiled with encryption support");
979 if (!strcmp(argv[a], "-s")) {
980 #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
983 argc = shift(argc, argv, a, 1);
985 if (!strcmp(argv[a], "-S")) {
986 #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
989 argc = shift(argc, argv, a, 1);
991 if (!strcmp(argv[a], "-p")) {
994 if (chdir(BBSDIR) < 0) {
995 perror("can't change to " BBSDIR);
1000 * Drop privileges if necessary. We stat
1001 * citadel.config to get the uid/gid since it's
1002 * guaranteed to have the uid/gid we want.
1004 if (!getuid() || !getgid()) {
1005 if (stat(BBSDIR "/citadel.config", &st) < 0) {
1006 perror("couldn't stat citadel.config");
1009 if (!getgid() && (setgid(st.st_gid) < 0)) {
1010 perror("couldn't change gid");
1013 if (!getuid() && (setuid(st.st_uid) < 0)) {
1014 perror("couldn't change uid");
1018 scr_printf("Privileges changed to uid %d gid %d\n",
1019 getuid(), getgid());
1022 argc = shift(argc, argv, a, 1);
1028 sln_printf("Attaching to server... \r");
1030 ipc = CtdlIPC_new(argc, argv, hostbuf, portbuf);
1033 error_printf("Can't connect: %s\n", strerror(errno));
1036 #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
1037 CtdlIPC_SetNetworkStatusCallback(ipc, wait_indicator);
1039 ipc_for_signal_handlers = ipc; /* KLUDGE cover your eyes */
1041 CtdlIPC_getline(ipc, aaa);
1042 if (aaa[0] != '2') {
1043 scr_printf("%s\n", &aaa[4]);
1044 logoff(ipc, atoi(aaa));
1047 /* If there is a [nonce] at the end, put the nonce in <nonce>, else nonce
1051 if ((sptr = strchr(aaa, '<')) == NULL)
1057 if ((sptr2 = strchr(sptr, '>')) == NULL)
1065 strncpy(nonce, sptr, NONCE_SIZE);
1070 /* Evaluate encryption preferences */
1071 if (arg_encrypt != RC_NO && rc_encrypt != RC_NO) {
1072 if (!ipc->isLocal || arg_encrypt == RC_YES || rc_encrypt == RC_YES) {
1073 secure = (CtdlIPCStartEncryption(ipc, aaa) / 100 == 2) ? 1 : 0;
1075 error_printf("Can't encrypt: %s\n", aaa);
1080 get_serv_info(ipc, telnet_client_host);
1081 scr_printf("%-24s\n%s\n%s\n", serv_info.serv_software, serv_info.serv_humannode,
1082 serv_info.serv_bbs_city);
1085 status_line(serv_info.serv_humannode, serv_info.serv_bbs_city, NULL,
1088 screenwidth = 80; /* default screen dimensions */
1091 scr_printf(" pause next stop\n");
1092 scr_printf(" ctrl-s ctrl-o ctrl-c\n\n");
1093 formout(ipc, "hello"); /* print the opening greeting */
1096 GSTA: /* See if we have a username and password on disk */
1097 if (rc_remember_passwords) {
1098 get_stored_password(hostbuf, portbuf, fullname, password);
1099 if (strlen(fullname) > 0) {
1100 r = CtdlIPCTryLogin(ipc, fullname, aaa);
1103 r = CtdlIPCTryApopPassword(ipc, make_apop_string(password, nonce, hexstring, sizeof hexstring), aaa);
1105 r = CtdlIPCTryPassword(ipc, password, aaa);
1110 load_user_info(aaa);
1111 stored_password = 1;
1114 set_stored_password(hostbuf, portbuf, "", "");
1122 if (strlen(rc_username) > 0) {
1123 strcpy(fullname, rc_username);
1125 newprompt("Enter your name: ", fullname, 29);
1128 if (!strcasecmp(fullname, "new")) { /* just in case */
1129 scr_printf("Please enter the name you wish to log in with.\n");
1132 (!strcasecmp(fullname, "bbs"))
1133 || (!strcasecmp(fullname, "new"))
1134 || (strlen(fullname) == 0));
1136 if (!strcasecmp(fullname, "off")) {
1140 /* sign on to the server */
1141 r = CtdlIPCTryLogin(ipc, fullname, aaa);
1145 /* password authentication */
1146 if (strlen(rc_password) > 0) {
1147 strcpy(password, rc_password);
1149 newprompt("\rPlease enter your password: ", password, -19);
1154 r = CtdlIPCTryApopPassword(ipc, make_apop_string(password, nonce, hexstring, sizeof hexstring), aaa);
1156 r = CtdlIPCTryPassword(ipc, password, aaa);
1160 load_user_info(aaa);
1161 offer_to_remember_password(ipc, hostbuf, portbuf,
1162 fullname, password);
1165 scr_printf("<< wrong password >>\n");
1166 if (strlen(rc_password) > 0)
1170 NEWUSR: if (strlen(rc_password) == 0) {
1171 scr_printf("No record. Enter as new user? ");
1176 r = CtdlIPCCreateUser(ipc, fullname, 1, aaa);
1178 scr_printf("%s\n", aaa);
1181 load_user_info(aaa);
1183 while (set_password(ipc) != 0);
1186 enter_config(ipc, 1);
1189 /* Switch color support on or off if we're in user mode */
1190 if (rc_ansi_color == 3) {
1191 if (userflags & US_COLOR)
1197 scr_printf("%s\nAccess level: %d (%s)\n"
1198 "User #%ld / Login #%d",
1199 fullname, axlevel, axdefs[(int) axlevel],
1200 usernum, timescalled);
1201 if (lastcall > 0L) {
1202 scr_printf(" / Last login: %s\n",
1203 asctime(localtime(&lastcall)));
1207 r = CtdlIPCMiscCheck(ipc, &chek, aaa);
1213 scr_printf("*** You have a new private message in Mail>\n");
1215 scr_printf("*** You have %d new private messages in Mail>\n", b);
1217 if (strlen(rc_gotmail_cmd) > 0) {
1218 system(rc_gotmail_cmd);
1221 if ((axlevel >= 6) && (chek.needvalid > 0)) {
1222 scr_printf("*** Users need validation\n");
1224 if (chek.needregis > 0) {
1225 scr_printf("*** Please register.\n");
1226 formout(ipc, "register");
1230 /* Make up some temporary filenames for use in various parts of the
1231 * program. Don't mess with these once they've been set, because we
1232 * will be unlinking them later on in the program and we don't
1233 * want to delete something that we didn't create. */
1234 snprintf(temp, sizeof temp, tmpnam(NULL));
1235 snprintf(temp2, sizeof temp2, tmpnam(NULL));
1236 snprintf(tempdir, sizeof tempdir, tmpnam(NULL));
1238 /* Get screen dimensions. First we go to a default of 80x24. Then
1239 * we try to get the user's actual screen dimensions off the server.
1240 * However, if we're running on an xterm, all this stuff is
1241 * irrelevant because we're going to dynamically size the screen
1242 * during the session.
1246 r = CtdlIPCGetConfig(ipc, &myself, aaa);
1248 screenwidth = myself->USscreenwidth;
1249 screenheight = myself->USscreenheight;
1251 if (getenv("TERM") != NULL)
1252 if (!strcmp(getenv("TERM"), "xterm")) {
1256 check_screen_dims();
1262 /* Enter the lobby */
1263 dotgoto(ipc, "_BASEROOM_", 1, 0);
1265 /* Main loop for the system... user is logged in. */
1269 readmsgs(ipc, 3, 1, 5);
1271 readmsgs(ipc, 1, 1, 0);
1273 /* MAIN COMMAND LOOP */
1275 mcmd = getcmd(ipc, argbuf); /* Get keyboard command */
1278 check_screen_dims(); /* if xterm, get screen size */
1284 formout(ipc, "help");
1296 newprompt("What do you want your username to be? ", aaa, 32);
1297 snprintf(bbb, sizeof bbb, "ENT0 2|0|0|0|%s", aaa);
1298 CtdlIPC_putline(ipc, bbb);
1299 CtdlIPC_getline(ipc, aaa);
1300 if (strncmp("200", aaa, 3))
1301 scr_printf("\n%s\n", aaa);
1310 if (!rc_alt_semantics)
1315 if (!rc_alt_semantics)
1317 dotgoto(ipc, argbuf, 0, 0);
1321 dotgoto(ipc, "_MAIL_", 1, 0);
1325 dotgoto(ipc, argbuf, 0, 0);
1328 if (rc_alt_semantics)
1330 dotgoto(ipc, argbuf, 0, 0);
1333 readmsgs(ipc, 0, 1, 0);
1336 readmsgs(ipc, 3, 1, 5);
1339 readmsgs(ipc, 1, 1, 0);
1342 readmsgs(ipc, 0, (-1), 0);
1345 readmsgs(ipc, 2, (-1), 0);
1348 readmsgs(ipc, 3, 1, atoi(argbuf));
1364 userlist(ipc, argbuf);
1422 if (!rc_alt_semantics)
1433 cli_image_upload(ipc, "_userpic_");
1436 cli_image_upload(ipc, "_roompic_");
1440 snprintf(aaa, sizeof aaa, "_floorpic_|%d", curr_floor);
1441 cli_image_upload(ipc, aaa);
1445 enternew(ipc, "roomname", aaa, 20);
1446 r = CtdlIPCChangeRoomname(ipc, aaa, bbb);
1448 scr_printf("\n%s\n", aaa);
1451 enternew(ipc, "hostname", aaa, 25);
1452 r = CtdlIPCChangeHostname(ipc, aaa, bbb);
1454 scr_printf("\n%s\n", aaa);
1457 enternew(ipc, "username", aaa, 32);
1458 r = CtdlIPCChangeUsername(ipc, aaa, bbb);
1460 scr_printf("\n%s\n", aaa);
1470 display_help(ipc, argbuf);
1474 formout(ipc, "register");
1479 scr_printf("Are you sure (y/n)? ");
1481 if (!rc_alt_semantics)
1489 scr_printf("All users will be disconnected! "
1490 "Really terminate the server? ");
1492 if (!rc_alt_semantics)
1494 r = CtdlIPCTerminateServerNow(ipc, aaa);
1495 scr_printf("%s\n", aaa);
1504 scr_printf("Do you really want to schedule a "
1505 "server shutdown? ");
1507 r = CtdlIPCTerminateServerScheduled(ipc, 1, aaa);
1511 "The Citadel server will terminate when all users are logged off.\n"
1515 "The Citadel server will not terminate.\n"
1523 network_config_management(ipc, "listrecp",
1524 "Message-by-message mailing list recipients");
1528 network_config_management(ipc, "digestrecp",
1529 "Digest mailing list recipients");
1533 network_config_management(ipc, "ignet_push_share",
1534 "Nodes with which we share this room");
1538 do_ignet_configuration(ipc);
1542 do_filterlist_configuration(ipc);
1546 if (rc_alt_semantics)
1558 sttybbs(SB_RESTORE);
1559 snprintf(aaa, sizeof aaa, "USERNAME=\042%s\042; export USERNAME;"
1560 "exec ./subsystem %ld %d %d", fullname,
1561 usernum, screenwidth, axlevel);
1563 sttybbs(SB_NO_INTR);
1566 scr_printf("*** Can't run doors when server is not local.\n");
1571 who_is_online(ipc, 0);
1575 who_is_online(ipc, 1);
1579 who_is_online(ipc, 2);
1583 do_system_configuration(ipc);
1587 do_internet_configuration(ipc);
1591 check_message_base(ipc);
1603 enter_config(ipc, 2);
1607 enter_config(ipc, 0);
1612 enter_config(ipc, 3);
1617 gotofloor(ipc, argbuf, GF_GOTO);
1621 gotofloor(ipc, argbuf, GF_SKIP);
1625 forget_this_floor(ipc);
1653 knrooms(ipc, floor_mode);
1663 misc_server_cmd(ipc, argbuf);
1667 edit_system_message(ipc, argbuf);
1692 } while (termn8 == 0);
1694 TERMN8: scr_printf("%s logged out.\n", fullname);
1695 while (march != NULL) {
1696 remove_march(march->march_name, 0);
1699 sln_printf("\n\nType 'off' to disconnect, or next user...\n");
1702 if ((mcmd == 29) || (mcmd == 15)) {
1704 sttybbs(SB_RESTORE);
1705 formout(ipc, "goodbye");