2 * Main source module for the client program.
4 * Copyright (c) 1987-2011 by the citadel.org team
6 * This program is open source software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #if TIME_WITH_SYS_TIME
30 # include <sys/time.h>
34 # include <sys/time.h>
41 #include <sys/types.h>
44 #include <sys/ioctl.h>
49 #include <libcitadel.h>
51 #include "citadel_ipc.h"
54 #include "routines2.h"
55 #include "tuiconfig.h"
59 #include "client_chat.h"
60 #include "client_passwords.h"
61 #include "citadel_decls.h"
67 #include "citadel_dirs.h"
72 #define IFEXPERT if (userflags&US_EXPERT)
73 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
74 #define IFAIDE if (axlevel>=AxAideU)
75 #define IFNAIDE if (axlevel<AxAideU)
77 int rordercmp(struct ctdlroomlisting *r1, struct ctdlroomlisting *r2);
78 march *marchptr = NULL;
79 extern char *moreprompt;
81 /* globals associated with the client program */
82 char temp[PATH_MAX]; /* Name of general-purpose temp file */
83 char temp2[PATH_MAX]; /* Name of general-purpose temp file */
84 char tempdir[PATH_MAX]; /* Name of general-purpose temp directory */
85 char editor_paths[MAX_EDITORS][SIZ]; /* paths to external editors */
86 char printcmd[SIZ]; /* print command */
87 int editor_pid = (-1);
88 char fullname[USERNAME_SIZE];
92 char room_name[ROOMNAMELEN];
93 char *uglist[UGLISTLEN]; /* size of the ungoto list */
94 long uglistlsn[UGLISTLEN]; /* current read position for all the ungoto's. Not going to make any friends with this one. */
96 char is_mail = 0; /* nonzero when we're in a mail room */
97 char axlevel = AxDeleted; /* access level */
98 char is_room_aide = 0; /* boolean flag, 1 if room aide */
102 long usernum = 0L; /* user number */
103 time_t lastcall = 0L; /* Date/time of previous login */
105 long highest_msg_read; /* used for <A>bandon room cmd */
106 long maxmsgnum; /* used for <G>oto */
108 char rc_username[USERNAME_SIZE];
109 char rc_password[32];
114 char curr_floor = 0; /* number of current floor */
115 char floorlist[128][SIZ]; /* names of floors */
116 int termn8 = 0; /* Set to nonzero to cause a logoff */
117 int secure; /* Set to nonzero when wire is encrypted */
119 extern char instant_msgs; /* instant messages waiting! */
120 extern int rc_ansi_color; /* ansi color value from citadel.rc */
121 extern int next_lazy_cmd;
123 CtdlIPC *ipc_for_signal_handlers; /* KLUDGE cover your eyes */
124 int enable_syslog = 0;
128 * here is our 'clean up gracefully and exit' routine
130 void ctdl_logoff(char *file, int line, CtdlIPC *ipc, int code)
134 if (editor_pid > 0) { /* kill the editor if it's running */
135 kill(editor_pid, SIGHUP);
138 /* Free the ungoto list */
139 for (lp = 0; lp < uglistsize; lp++) {
143 /* Shut down the server connection ... but not if the logoff code is 3,
144 * because that means we're exiting because we already lost the server.
151 * now clean up various things
157 /* Violently kill off any child processes if Citadel is
160 if (getppid() == 1) {
161 kill(0 - getpgrp(), SIGTERM);
163 kill(0 - getpgrp(), SIGKILL);
165 color(ORIGINAL_PAIR); /* Restore the old color settings */
166 stty_ctdl(SB_RESTORE); /* return the old terminal settings */
168 * uncomment the following if you need to know why Citadel exited
169 printf("*** Exit code %d at %s:%d\n", code, file, line);
172 exit(code); /* exit with the proper exit code */
178 * signal catching function for hangups...
180 void dropcarr(int signum)
182 logoff(NULL, 3); /* No IPC when server's already gone! */
188 * catch SIGCONT to reset terminal modes when were are put back into the
191 void catch_sigcont(int signum)
194 signal(SIGCONT, catch_sigcont);
198 /* general purpose routines */
201 void formout(CtdlIPC *ipc, char *name)
203 int r; /* IPC return code */
207 r = CtdlIPCSystemMessage(ipc, name, &text, buf);
209 scr_printf("%s\n", buf);
213 fmout(screenwidth, NULL, text, NULL, 1);
219 void userlist(CtdlIPC *ipc, char *patn)
225 int r; /* IPC response code */
226 char *listing = NULL;
228 r = CtdlIPCUserListing(ipc, patn, &listing, buf);
230 scr_printf("%s\n", buf);
234 scr_printf(" User Name Num L Last Visit Logins Messages\n");
235 scr_printf("------------------------- ----- - ---------- ------ --------\n");
236 if (listing != NULL) while (!IsEmptyStr(listing)) {
237 extract_token(buf, listing, 0, '\n', sizeof buf);
238 remove_token(listing, 0, '\n');
240 if (sigcaught == 0) {
241 extract_token(fl, buf, 0, '|', sizeof fl);
242 if (pattern(fl, patn) >= 0) {
243 scr_printf("%-25s ", fl);
244 scr_printf("%5ld %d ", extract_long(buf, 2),
245 extract_int(buf, 1));
246 lc = extract_long(buf, 3);
247 localtime_r(&lc, &tmbuf);
248 scr_printf("%02d/%02d/%04d ",
251 (tmbuf.tm_year + 1900));
252 scr_printf("%6ld %8ld\n", extract_long(buf, 4), extract_long(buf, 5));
263 * grab assorted info about the user...
265 void load_user_info(char *params)
267 extract_token(fullname, params, 0, '|', sizeof fullname);
268 axlevel = extract_int(params, 1);
269 timescalled = extract_int(params, 2);
270 posted = extract_int(params, 3);
271 userflags = extract_int(params, 4);
272 usernum = extract_long(params, 5);
273 lastcall = extract_long(params, 6);
278 * Remove a room from the march list. 'floornum' is ignored unless
279 * 'roomname' is set to _FLOOR_, in which case all rooms on the requested
280 * floor will be removed from the march list.
282 void remove_march(char *roomname, int floornum)
284 struct march *mptr, *mptr2;
286 if (marchptr == NULL)
289 if ((!strcasecmp(marchptr->march_name, roomname))
290 || ((!strcasecmp(roomname, "_FLOOR_")) && (marchptr->march_floor == floornum))) {
291 mptr = marchptr->next;
297 for (mptr = marchptr; mptr != NULL; mptr = mptr->next) {
299 if ((!strcasecmp(mptr->march_name, roomname))
300 || ((!strcasecmp(roomname, "_FLOOR_"))
301 && (mptr->march_floor == floornum))) {
303 mptr2->next = mptr->next;
314 * Locate the room on the march list which we most want to go to. Each room
315 * is measured given a "weight" of preference based on various factors.
317 char *pop_march(int desired_floor, struct march *_march)
319 static char TheRoom[ROOMNAMELEN];
322 struct march *mptr = NULL;
324 strcpy(TheRoom, "_BASEROOM_");
328 for (mptr = _march; mptr != NULL; mptr = mptr->next) {
330 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
331 weight = weight + 10000;
332 if (mptr->march_floor == desired_floor)
333 weight = weight + 5000;
335 weight = weight + ((128 - (mptr->march_floor)) * 128);
336 weight = weight + (128 - (mptr->march_order));
338 if (weight > TheWeight) {
340 strcpy(TheRoom, mptr->march_name);
348 * jump directly to a room
350 void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto)
352 char aaa[SIZ], bbb[SIZ];
354 int newmailcount = 0;
355 int partial_match, best_match;
357 int ugpos = uglistsize;
358 int r; /* IPC result code */
359 struct ctdlipcroom *room = NULL;
362 /* store ungoto information */
363 if (fromungoto == 0) {
364 /* sloppy slide them all down, hey it's the client, who cares. :-) */
365 if (uglistsize >= (UGLISTLEN-1)) {
368 for (lp = 0; lp < (UGLISTLEN-1); lp++) {
369 uglist[lp] = uglist[lp+1];
370 uglistlsn[lp] = uglistlsn[lp+1];
377 uglist[ugpos] = malloc(strlen(room_name)+1);
378 strcpy(uglist[ugpos], room_name);
379 uglistlsn[ugpos] = ls;
382 /* first try an exact match */
383 r = CtdlIPCGotoRoom(ipc, towhere, "", &room, aaa);
385 newprompt("Enter room password: ", bbb, 9);
386 r = CtdlIPCGotoRoom(ipc, towhere, bbb, &room, aaa);
388 scr_printf("Wrong password.\n");
394 * If a match is not found, try a partial match.
395 * Partial matches anywhere in the string carry a weight of 1,
396 * left-aligned matches carry a weight of 2. Pick the room that
397 * has the highest-weighted match. Do not match on forgotten
401 struct march *march = NULL;
406 r = CtdlIPCKnownRooms(ipc, SubscribedRooms, AllFloors, &march, aaa);
408 /* Run the roomlist; free the data as we go */
409 struct march *mp = march; /* Current */
413 if (pattern(mp->march_name, towhere) >= 0) {
416 if (!strncasecmp(mp->march_name, towhere, strlen(towhere))) {
419 if (partial_match > best_match) {
420 strcpy(bbb, mp->march_name);
421 best_match = partial_match;
423 /* Both pointers are NULL at end of list */
430 if (IsEmptyStr(bbb)) {
431 scr_printf("No room '%s'.\n", towhere);
434 r = CtdlIPCGotoRoom(ipc, bbb, "", &room, aaa);
436 if (r / 100 != 1 && r / 100 != 2) {
437 scr_printf("%s\n", aaa);
440 safestrncpy(room_name, room->RRname, ROOMNAMELEN);
441 room_flags = room->RRflags;
442 room_flags2 = room->RRflags2;
443 from_floor = curr_floor;
444 curr_floor = room->RRfloor;
446 /* Determine, based on the room's default view, whether an <E>nter message
447 * command will be valid here.
449 switch(room->RRdefaultview) {
460 remove_march(room_name, 0);
461 if (!strcasecmp(towhere, "_BASEROOM_"))
462 remove_march(towhere, 0);
464 next_lazy_cmd = 5; /* Don't read new if no new msgs */
465 if ((from_floor != curr_floor) && (display_name > 0) && (floor_mode == 1)) {
466 if (floorlist[(int) curr_floor][0] == 0)
468 scr_printf("(Entering floor: %s)\n", &floorlist[(int) curr_floor][0]);
470 if (display_name == 1) {
472 scr_printf("%s ", room_name);
476 if (display_name != 2) {
477 color(BRIGHT_YELLOW);
478 scr_printf("%d ", room->RRunread);
480 scr_printf("new of ");
481 color(BRIGHT_YELLOW);
482 scr_printf("%d ", room->RRtotal);
484 scr_printf("messages.\n");
486 highest_msg_read = room->RRlastread;
487 maxmsgnum = room->RRhighest;
488 is_mail = room->RRismailbox;
489 is_room_aide = room->RRaide;
490 ls = room->RRlastread;
492 /* read info file if necessary */
493 if (room->RRinfoupdated > 0)
496 /* check for newly arrived mail if we can */
497 newmailcount = room->RRnewmail;
498 if (newmailcount > 0) {
500 if (newmailcount == 1) {
501 scr_printf("*** A new mail message has arrived.\n");
504 scr_printf("*** %d new mail messages have arrived.\n",
508 if (!IsEmptyStr(rc_gotmail_cmd)) {
509 rv = system(rc_gotmail_cmd);
511 scr_printf("*** failed to check for mail calling %s Reason %d.\n",
517 if (screenwidth>5) snprintf(&status_line[1], screenwidth-1, "%s | %s | %s | %s | %d new mail |",
518 (secure ? "Encrypted" : "Unencrypted"),
519 ipc->ServInfo.humannode,
520 ipc->ServInfo.site_location,
526 /* Goto next room having unread messages.
527 * We want to skip over rooms that the user has already been to, and take the
528 * user back to the lobby when done. The room we end up in is placed in
529 * newroom - which is set to 0 (the lobby) initially.
531 void gotonext(CtdlIPC *ipc)
534 struct march *mptr, *mptr2;
535 char next_room[ROOMNAMELEN];
537 /* Check to see if the march-mode list is already allocated.
538 * If it is, pop the first room off the list and go there.
540 if (marchptr == NULL) {
541 CtdlIPCKnownRooms(ipc, SubscribedRoomsWithNewMessages,
542 AllFloors, &marchptr, buf);
544 /* add _BASEROOM_ to the end of the march list, so the user will end up
545 * in the system base room (usually the Lobby>) at the end of the loop
547 mptr = (struct march *) malloc(sizeof(struct march));
549 mptr->march_order = 0;
550 mptr->march_floor = 0;
551 strcpy(mptr->march_name, "_BASEROOM_");
552 if (marchptr == NULL) {
556 while (mptr2->next != NULL)
561 * ...and remove the room we're currently in, so a <G>oto doesn't make us
562 * walk around in circles
564 remove_march(room_name, 0);
566 if (marchptr != NULL) {
567 strcpy(next_room, pop_march(curr_floor, marchptr));
569 strcpy(next_room, "_BASEROOM_");
571 remove_march(next_room, 0);
572 dotgoto(ipc, next_room, 1, 0);
576 * forget all rooms on a given floor
578 void forget_all_rooms_on(CtdlIPC *ipc, int ffloor)
581 struct march *flist = NULL;
582 struct march *fptr = NULL;
583 struct ctdlipcroom *room = NULL;
584 int r; /* IPC response code */
586 scr_printf("Forgetting all rooms on %s...\n", &floorlist[ffloor][0]);
587 remove_march("_FLOOR_", ffloor);
588 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, ffloor, &flist, buf);
590 scr_printf("Error %d: %s\n", r, buf);
594 r = CtdlIPCGotoRoom(ipc, flist->march_name, "", &room, buf);
596 r = CtdlIPCForgetRoom(ipc, buf);
598 scr_printf("Error %d: %s\n", r, buf);
606 if (room) free(room);
611 * routine called by gotofloor() to move to a new room on a new floor
613 void gf_toroom(CtdlIPC *ipc, char *towhere, int mode)
615 int floor_being_left;
617 floor_being_left = curr_floor;
619 if (mode == GF_GOTO) { /* <;G>oto mode */
621 dotgoto(ipc, towhere, 1, 0);
623 else if (mode == GF_SKIP) { /* <;S>kip mode */
624 dotgoto(ipc, towhere, 1, 0);
625 remove_march("_FLOOR_", floor_being_left);
627 else if (mode == GF_ZAP) { /* <;Z>ap mode */
628 dotgoto(ipc, towhere, 1, 0);
629 remove_march("_FLOOR_", floor_being_left);
630 forget_all_rooms_on(ipc, floor_being_left);
638 void gotofloor(CtdlIPC *ipc, char *towhere, int mode)
641 int r; /* IPC response code */
643 char buf[SIZ], targ[SIZ];
645 if (floorlist[0][0] == 0)
648 for (a = 0; a < 128; ++a)
649 if (!strcasecmp(&floorlist[a][0], towhere))
653 for (a = 0; a < 128; ++a) {
654 if (!strncasecmp(&floorlist[a][0], towhere, strlen(towhere))) {
660 for (a = 0; a < 128; ++a)
661 if (pattern(towhere, &floorlist[a][0]) > 0)
665 scr_printf("No floor '%s'.\n", towhere);
668 for (mptr = marchptr; mptr != NULL; mptr = mptr->next) {
669 if ((mptr->march_floor) == tofloor) {
670 gf_toroom(ipc, mptr->march_name, mode);
675 /* Find first known room on the floor */
679 r = CtdlIPCKnownRooms(ipc, SubscribedRooms, tofloor, &mptr, buf);
681 struct march *tmp = mptr;
683 /*. . . according to room order */
685 strcpy(targ, pop_march(tofloor, mptr));
692 if (!IsEmptyStr(targ)) {
693 gf_toroom(ipc, targ, mode);
697 /* No known rooms on the floor; unzap the first one then */
701 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, tofloor, &mptr, buf);
703 struct march *tmp = mptr;
705 /*. . . according to room order */
707 strcpy(targ, pop_march(tofloor, mptr));
714 if (!IsEmptyStr(targ)) {
715 gf_toroom(ipc, targ, mode);
717 scr_printf("There are no rooms on '%s'.\n", &floorlist[tofloor][0]);
722 * Indexing mechanism for a room list, called by gotoroomstep()
724 void room_tree_list_query(struct ctdlroomlisting *rp, char *findrmname, int findrmslot, char *rmname, int *rmslot, int *rmtotal)
726 char roomname[ROOMNAMELEN];
727 static int cur_rmslot = 0;
734 if (rp->lnext != NULL) {
735 room_tree_list_query(rp->lnext, findrmname, findrmslot, rmname, rmslot, rmtotal);
738 if (sigcaught == 0) {
739 strcpy(roomname, rp->rlname);
741 if (rmname != NULL) {
742 if (cur_rmslot == findrmslot) {
743 strcpy(rmname, roomname);
746 if (rmslot != NULL) {
747 if (!strcmp(roomname, findrmname)) {
748 *rmslot = cur_rmslot;
754 if (rp->rnext != NULL) {
755 room_tree_list_query(rp->rnext, findrmname, findrmslot, rmname, rmslot, rmtotal);
758 if ((rmname == NULL) && (rmslot == NULL))
761 if (rmtotal != NULL) {
762 *rmtotal = cur_rmslot;
767 * step through rooms on current floor
769 void gotoroomstep(CtdlIPC *ipc, int direction, int mode)
771 struct march *listing = NULL;
773 int r; /* IPC response code */
775 struct ctdlroomlisting *rl = NULL;
776 struct ctdlroomlisting *rp;
777 struct ctdlroomlisting *rs;
779 char rmname[ROOMNAMELEN];
783 /* Ask the server for a room list */
784 r = CtdlIPCKnownRooms(ipc, SubscribedRooms, (-1), &listing, buf);
791 for (mptr = listing; mptr != NULL; mptr = mptr->next) {
795 && (mptr->march_floor != curr_floor))
799 rp = malloc(sizeof(struct ctdlroomlisting));
800 strncpy(rp->rlname, mptr->march_name, ROOMNAMELEN);
801 rp->rlflags = mptr->march_flags;
802 rp->rlfloor = mptr->march_floor;
803 rp->rlorder = mptr->march_order;
812 if (rordercmp(rp, rs) < 0) {
813 if (rs->lnext == NULL) {
820 if (rs->rnext == NULL) {
832 /* Find position of current room */
833 room_tree_list_query(NULL, NULL, 0, NULL, NULL, NULL);
834 room_tree_list_query(rl, room_name, 0, NULL, &rmslot, &rmtotal);
836 if (direction == 0) { /* Previous room */
837 /* If we're at the first room, wrap to the last room */
839 rmslot = rmtotal - 1;
843 } else { /* Next room */
844 /* If we're at the last room, wrap to the first room */
845 if (rmslot == rmtotal - 1) {
852 /* Get name of next/previous room */
853 room_tree_list_query(NULL, NULL, 0, NULL, NULL, NULL);
854 room_tree_list_query(rl, NULL, rmslot, rmname, NULL, NULL);
857 room_tree_list_query(rl, NULL, 0, NULL, NULL, NULL);
859 if (mode == 0) { /* not skipping */
862 if (rc_alt_semantics) {
867 /* Free the room list */
869 mptr = listing->next;
874 dotgoto(ipc, rmname, 1, 0);
879 * step through floors on system
881 void gotofloorstep(CtdlIPC *ipc, int direction, int mode)
885 if (floorlist[0][0] == 0)
890 if (direction == 0) { /* Previous floor */
891 if (curr_floor) tofloor = curr_floor - 1;
894 while (!floorlist[tofloor][0]) tofloor--;
895 } else { /* Next floor */
896 if (curr_floor < 127) tofloor = curr_floor + 1;
899 while (!floorlist[tofloor][0] && tofloor < 127) tofloor++;
900 if (!floorlist[tofloor][0]) tofloor = 0;
902 /* ;g works when not in floor mode so . . . */
904 scr_printf("(%s)\n", floorlist[tofloor] );
907 gotofloor(ipc, floorlist[tofloor], mode);
908 if (curr_floor != tofloor) { /* gotofloor failed */
909 curr_floor = tofloor;
910 goto empty_keep_going;
915 * Display user 'preferences'.
917 extern int rc_prompt_control;
918 void read_config(CtdlIPC *ipc)
922 int r; /* IPC response code */
923 char _fullname[USERNAME_SIZE];
925 int _axlevel, _timescalled, _posted;
927 struct ctdluser *user = NULL;
929 /* get misc user info */
930 r = CtdlIPCGetBio(ipc, fullname, &resp, buf);
932 scr_printf("%s\n", buf);
935 extract_token(_fullname, buf, 1, '|', sizeof fullname);
936 _usernum = extract_long(buf, 2);
937 _axlevel = extract_int(buf, 3);
938 _lastcall = extract_long(buf, 4);
939 _timescalled = extract_int(buf, 5);
940 _posted = extract_int(buf, 6);
944 /* get preferences */
945 r = CtdlIPCGetConfig(ipc, &user, buf);
947 scr_printf("%s\n", buf);
952 /* show misc user info */
953 scr_printf("%s\nAccess level: %d (%s)\n"
954 "User #%ld / %d Calls / %d Posts",
955 _fullname, _axlevel, axdefs[(int) _axlevel],
956 _usernum, _timescalled, _posted);
957 if (_lastcall > 0L) {
958 scr_printf(" / Curr login: %s",
959 asctime(localtime(&_lastcall)));
963 /* show preferences */
964 scr_printf("Are you an experienced Citadel user: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_EXPERT) ? "Yes" : "No"); color(DIM_WHITE);
965 scr_printf("Print last old message on New message request: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_LASTOLD)? "Yes" : "No"); color(DIM_WHITE);
966 scr_printf("Prompt after each message: "); color(BRIGHT_CYAN); scr_printf("%s\n", (!(user->flags & US_NOPROMPT))? "Yes" : "No"); color(DIM_WHITE);
967 if ((user->flags & US_NOPROMPT) == 0) {
968 scr_printf("Use 'disappearing' prompts: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_DISAPPEAR)? "Yes" : "No"); color(DIM_WHITE);
970 scr_printf("Pause after each screenful of text: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_PAGINATOR)? "Yes" : "No"); color(DIM_WHITE);
971 if (rc_prompt_control == 3 && (user->flags & US_PAGINATOR)) {
972 scr_printf("<N>ext and <S>top work at paginator prompt: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_PROMPTCTL)? "Yes" : "No"); color(DIM_WHITE);
974 if (rc_floor_mode == RC_DEFAULT) {
975 scr_printf("View rooms by floor: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_FLOORS)? "Yes" : "No"); color(DIM_WHITE);
977 if (rc_ansi_color == 3) {
978 scr_printf("Enable color support: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_COLOR)? "Yes" : "No"); color(DIM_WHITE);
980 scr_printf("Be unlisted in userlog: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_UNLISTED)? "Yes" : "No"); color(DIM_WHITE);
981 if (!IsEmptyStr(editor_paths[0])) {
982 scr_printf("Always enter messages with the full-screen editor: "); color(BRIGHT_CYAN); scr_printf("%s\n", (user->flags & US_EXTEDIT)? "Yes" : "No"); color(DIM_WHITE);
988 * Display system statistics.
990 void system_info(CtdlIPC *ipc)
995 int mrtg_users, mrtg_active_users;
996 char mrtg_server_uptime[40];
999 /* get #users, #active & server uptime */
1000 CtdlIPCGenericCommand(ipc, "MRTG|users", NULL, 0, &resp, &bytes, buf);
1001 mrtg_users = extract_int(resp, 0);
1002 remove_token(resp, 0, '\n');
1003 mrtg_active_users = extract_int(resp, 0);
1004 remove_token(resp, 0, '\n');
1005 extract_token(mrtg_server_uptime, resp, 0, '\n', sizeof mrtg_server_uptime);
1009 /* get high message# */
1010 CtdlIPCGenericCommand(ipc, "MRTG|messages", NULL, 0, &resp, &bytes, buf);
1011 mrtg_himessage = extract_long(resp, 0);
1015 /* refresh server info just in case */
1016 CtdlIPCServerInfo(ipc, buf);
1018 scr_printf("You are connected to %s (%s) @%s\n", ipc->ServInfo.nodename, ipc->ServInfo.humannode, ipc->ServInfo.fqdn);
1019 scr_printf("running %s with text client v%.2f,\n", ipc->ServInfo.software, (float)REV_LEVEL/100);
1020 scr_printf("server build %s,\n", ipc->ServInfo.svn_revision, (float)REV_LEVEL/100);
1021 scr_printf("and located in %s.\n", ipc->ServInfo.site_location);
1022 scr_printf("Connected users %d / Active users %d / Highest message #%ld\n", mrtg_users, mrtg_active_users, mrtg_himessage);
1023 scr_printf("Server uptime: %s\n", mrtg_server_uptime);
1024 scr_printf("Your system administrator is %s.\n", ipc->ServInfo.sysadm);
1025 scr_printf("Copyright (C)1987-2011 by the Citadel development team\n");
1029 * forget all rooms on current floor
1031 void forget_this_floor(CtdlIPC *ipc)
1033 if (curr_floor == 0) {
1034 scr_printf("Can't forget this floor.\n");
1037 if (floorlist[0][0] == 0) {
1038 load_floorlist(ipc);
1040 scr_printf("Are you sure you want to forget all rooms on %s? ",
1041 &floorlist[(int) curr_floor][0]);
1046 gf_toroom(ipc, "_BASEROOM_", GF_ZAP);
1051 * set floor mode depending on client, server, and user settings
1053 void set_floor_mode(CtdlIPC* ipc)
1055 if (ipc->ServInfo.ok_floors == 0) {
1056 floor_mode = 0; /* Don't use floors if the server */
1058 /* doesn't support them! */
1060 if (rc_floor_mode == RC_NO) { /* never use floors */
1063 if (rc_floor_mode == RC_YES) { /* always use floors */
1066 if (rc_floor_mode == RC_DEFAULT) { /* user choice */
1067 floor_mode = ((userflags & US_FLOORS) ? 1 : 0);
1073 * Set or change the user's password
1075 int set_password(CtdlIPC *ipc)
1081 if (!IsEmptyStr(rc_password)) {
1082 strcpy(pass1, rc_password);
1083 strcpy(pass2, rc_password);
1085 IFNEXPERT formout(ipc, "changepw");
1086 newprompt("Enter a new password: ", pass1, -19);
1087 newprompt("Enter it again to confirm: ", pass2, -19);
1091 if (!strcasecmp(pass1, pass2)) {
1092 CtdlIPCChangePassword(ipc, pass1, buf);
1093 scr_printf("%s\n", buf);
1094 offer_to_remember_password(ipc, hostbuf, portbuf, fullname, pass1);
1097 scr_printf("*** They don't match... try again.\n");
1105 * get info about the server we've connected to
1107 void get_serv_info(CtdlIPC *ipc, char *supplied_hostname)
1111 CtdlIPCServerInfo(ipc, buf);
1112 moreprompt = ipc->ServInfo.moreprompt;
1114 /* be nice and identify ourself to the server */
1115 CtdlIPCIdentifySoftware(ipc, SERVER_TYPE, 0, REV_LEVEL,
1116 (ipc->isLocal ? "local" : CITADEL),
1117 (supplied_hostname) ? supplied_hostname :
1118 /* Look up the , in the bible if you're confused */
1119 (locate_host(ipc, buf), buf), buf);
1121 /* Indicate to the server that we prefer to decode Base64 and
1122 * quoted-printable on the client side.
1124 if ((CtdlIPCSpecifyPreferredFormats(ipc, buf, "dont_decode") / 100 ) != 2) {
1125 scr_printf("ERROR: Extremely old server; MSG4 framework not supported.\n");
1130 * Tell the server what our preferred content formats are.
1132 * Originally we preferred HTML over plain text because we can format
1133 * it to the reader's screen width, but since our HTML-to-text parser
1134 * isn't really all that great, it's probably better to just go with
1135 * the plain text when we have it available.
1137 if ((CtdlIPCSpecifyPreferredFormats(ipc, buf, "text/plain|text/html") / 100 ) != 2) {
1138 scr_printf("ERROR: Extremely old server; MSG4 framework not supported.\n");
1146 * Session username compare function for SortOnlineUsers()
1148 int rwho_username_cmp(const void *rec1, const void *rec2) {
1151 u1 = strchr(rec1, '|');
1152 u2 = strchr(rec2, '|');
1154 return strcasecmp( (u1?++u1:"") , (u2?++u2:"") );
1159 * Idle time compare function for SortOnlineUsers()
1161 int idlecmp(const void *rec1, const void *rec2) {
1164 i1 = extract_long(rec1, 5);
1165 i2 = extract_long(rec2, 5);
1167 if (i1 < i2) return(1);
1168 if (i1 > i2) return(-1);
1174 * Sort the list of online users by idle time.
1175 * This function frees the supplied buffer, and returns a new one
1176 * to the caller. The caller is responsible for freeing the returned buffer.
1178 * If 'condense' is nonzero, multiple sessions for the same user will be
1179 * combined into one for brevity.
1181 char *SortOnlineUsers(char *listing, int condense) {
1188 rows = num_tokens(listing, '\n');
1189 sortbuf = malloc(rows * SIZ);
1190 if (sortbuf == NULL) return(listing);
1191 retbuf = malloc(rows * SIZ);
1192 if (retbuf == NULL) {
1197 /* Copy the list into a fixed-record-size array for sorting */
1198 for (i=0; i<rows; ++i) {
1199 memset(buf, 0, SIZ);
1200 extract_token(buf, listing, i, '\n', sizeof buf);
1201 memcpy(&sortbuf[i*SIZ], buf, (size_t)SIZ);
1204 /* Sort by idle time */
1205 qsort(sortbuf, rows, SIZ, idlecmp);
1207 /* Combine multiple sessions for the same user */
1209 qsort(sortbuf, rows, SIZ, rwho_username_cmp);
1210 if (rows > 1) for (i=1; i<rows; ++i) if (i>0) {
1211 char u1[USERNAME_SIZE];
1212 char u2[USERNAME_SIZE];
1213 extract_token(u1, &sortbuf[(i-1)*SIZ], 1, '|', sizeof u1);
1214 extract_token(u2, &sortbuf[i*SIZ], 1, '|', sizeof u2);
1215 if (!strcasecmp(u1, u2)) {
1216 memcpy(&sortbuf[i*SIZ], &sortbuf[(i+1)*SIZ], (rows-i-1)*SIZ);
1222 qsort(sortbuf, rows, SIZ, idlecmp); /* idle sort again */
1225 /* Copy back to a \n delimited list */
1227 for (i=0; i<rows; ++i) {
1228 if (!IsEmptyStr(&sortbuf[i*SIZ])) {
1229 strcat(retbuf, &sortbuf[i*SIZ]);
1230 if (i<(rows-1)) strcat(retbuf, "\n");
1241 * Display list of users currently logged on to the server
1243 void who_is_online(CtdlIPC *ipc, int longlist)
1245 char buf[SIZ], username[SIZ], roomname[SIZ], fromhost[SIZ];
1247 char actual_user[SIZ], actual_room[SIZ], actual_host[SIZ];
1248 char clientsoft[SIZ];
1250 time_t idletime, idlehours, idlemins, idlesecs;
1251 int last_session = (-1);
1253 char *listing = NULL;
1254 int r; /* IPC response code */
1256 if (longlist == 2) {
1262 color(BRIGHT_WHITE);
1263 scr_printf(" User Name Room ");
1264 if (screenwidth >= 80) scr_printf(" Idle From host");
1267 scr_printf(" ------------------------- --------------------");
1268 if (screenwidth >= 80) scr_printf(" ---- ------------------------");
1271 r = CtdlIPCOnlineUsers(ipc, &listing, &timenow, buf);
1272 listing = SortOnlineUsers(listing, (!longlist));
1274 while (!IsEmptyStr(listing)) {
1277 /* Get another line */
1278 extract_token(buf, listing, 0, '\n', sizeof buf);
1279 remove_token(listing, 0, '\n');
1281 extract_token(username, buf, 1, '|', sizeof username);
1282 extract_token(roomname, buf, 2, '|', sizeof roomname);
1283 extract_token(fromhost, buf, 3, '|', sizeof fromhost);
1284 extract_token(clientsoft, buf, 4, '|', sizeof clientsoft);
1285 extract_token(flags, buf, 7, '|', sizeof flags);
1287 idletime = timenow - extract_long(buf, 5);
1288 idlehours = idletime / 3600;
1289 idlemins = (idletime - (idlehours * 3600)) / 60;
1290 idlesecs = (idletime - (idlehours * 3600) - (idlemins * 60));
1292 if (idletime > rc_idle_threshold) {
1299 extract_token(actual_user, buf, 8, '|', sizeof actual_user);
1300 extract_token(actual_room, buf, 9, '|', sizeof actual_room);
1301 extract_token(actual_host, buf, 10, '|', sizeof actual_host);
1303 scr_printf(" Flags: %s\n", flags);
1304 scr_printf("Session: %d\n", extract_int(buf, 0));
1305 scr_printf(" Name: %s\n", username);
1306 scr_printf("In room: %s\n", roomname);
1307 scr_printf(" Host: %s\n", fromhost);
1308 scr_printf(" Client: %s\n", clientsoft);
1309 scr_printf(" Idle: %ld:%02ld:%02ld\n",
1314 if ( (!IsEmptyStr(actual_user)&&
1315 !IsEmptyStr(actual_room)&&
1316 !IsEmptyStr(actual_host))) {
1317 scr_printf("(really ");
1318 if (!IsEmptyStr(actual_user)) scr_printf("<%s> ", actual_user);
1319 if (!IsEmptyStr(actual_room)) scr_printf("in <%s> ", actual_room);
1320 if (!IsEmptyStr(actual_host)) scr_printf("from <%s> ", actual_host);
1327 if (extract_int(buf, 0) == last_session) {
1331 color(BRIGHT_MAGENTA);
1332 scr_printf("%-3s", flags);
1334 last_session = extract_int(buf, 0);
1336 scr_printf("%-25s ", username);
1337 color(BRIGHT_MAGENTA);
1339 scr_printf("%-20s", roomname);
1341 if (screenwidth >= 80) {
1343 if (idletime > rc_idle_threshold) {
1344 /* over 1000d, must be gone fishing */
1345 if (idlehours > 23999) {
1348 } else if (idlehours > 239) {
1349 scr_printf("%3ldd", idlehours / 24);
1351 } else if (idlehours > 9) {
1352 scr_printf("%1ldd%02ld",
1355 /* less than 10 hours */
1358 scr_printf("%1ld:%02ld", idlehours, idlemins);
1366 fromhost[24] = '\0';
1367 scr_printf("%-24s", fromhost);
1378 void enternew(CtdlIPC *ipc, char *desc, char *buf, int maxlen)
1381 snprintf(bbb, sizeof bbb, "Enter in your new %s: ", desc);
1382 newprompt(bbb, buf, maxlen);
1387 int shift(int argc, char **argv, int start, int count) {
1390 for (i=start; i<(argc-count); ++i) {
1391 argv[i] = argv[i+count];
1393 argc = argc - count;
1397 static void statusHook(char *s) {
1404 int main(int argc, char **argv)
1407 char aaa[100], bbb[100];/* general purpose variables */
1408 char argbuf[64]; /* command line buf */
1409 char nonce[NONCE_SIZE];
1410 char *telnet_client_host = NULL;
1411 char *sptr, *sptr2; /* USed to extract the nonce */
1412 char hexstring[MD5_HEXSTRING_SIZE];
1414 struct ctdlipcmisc chek;
1415 struct ctdluser *myself = NULL;
1416 CtdlIPC* ipc; /* Our server connection */
1417 int r; /* IPC result code */
1418 int rv = 0; /* fetch but ignore syscall return value to suppress warnings */
1422 char relhome[PATH_MAX]="";
1423 char ctdldir[PATH_MAX]=CTDLDIR;
1425 #ifdef HAVE_BACKTRACE
1426 eCrashParameters params;
1427 // eCrashSymbolTable symbol_table;
1429 calc_dirs_n_files(relh, home, relhome, ctdldir, 0);
1431 #ifdef HAVE_BACKTRACE
1432 bzero(¶ms, sizeof(params));
1433 params.filename = file_pid_paniclog;
1434 // panic_fd=open(file_pid_paniclog, O_APPEND|O_CREAT|O_DIRECT);
1435 params.filep = fopen(file_pid_paniclog, "a+");
1436 params.debugLevel = ECRASH_DEBUG_VERBOSE;
1437 params.dumpAllThreads = TRUE;
1438 params.useBacktraceSymbols = 1;
1439 /// BuildSymbolTable(&symbol_table);
1440 // params.symbolTable = &symbol_table;
1441 params.signals[0]=SIGSEGV;
1442 params.signals[1]=SIGILL;
1443 params.signals[2]=SIGBUS;
1444 params.signals[3]=SIGABRT;
1446 eCrash_Init(¶ms);
1448 setIPCErrorPrintf(scr_printf);
1449 setCryptoStatusHook(statusHook);
1451 /* Permissions sanity check - don't run citadel setuid/setgid */
1452 if (getuid() != geteuid()) {
1453 scr_printf("Please do not run citadel setuid!\n");
1455 } else if (getgid() != getegid()) {
1456 scr_printf("Please do not run citadel setgid!\n");
1460 stty_ctdl(SB_SAVE); /* Store the old terminal parameters */
1461 load_command_set(); /* parse the citadel.rc file */
1462 stty_ctdl(SB_NO_INTR); /* Install the new ones */
1463 /* signal(SIGHUP, dropcarr);FIXME */ /* Cleanup gracefully if carrier is dropped */
1464 signal(SIGPIPE, dropcarr); /* Cleanup gracefully if local conn. dropped */
1465 signal(SIGTERM, dropcarr); /* Cleanup gracefully if terminated */
1466 signal(SIGCONT, catch_sigcont); /* Catch SIGCONT so we can reset terminal */
1468 signal(SIGWINCH, scr_winch); /* Window resize signal */
1472 arg_encrypt = RC_DEFAULT;
1476 * Handle command line options as if we were called like /bin/login
1477 * (i.e. from in.telnetd)
1479 for (a=0; a<argc; ++a) {
1480 if ((argc > a+1) && (!strcmp(argv[a], "-h")) ) {
1481 telnet_client_host = argv[a+1];
1482 argc = shift(argc, argv, a, 2);
1484 if (!strcmp(argv[a], "-x")) {
1486 arg_encrypt = RC_NO;
1488 argc = shift(argc, argv, a, 1);
1490 if (!strcmp(argv[a], "-X")) {
1492 arg_encrypt = RC_YES;
1493 argc = shift(argc, argv, a, 1);
1495 fprintf(stderr, "Not compiled with encryption support");
1499 if (!strcmp(argv[a], "-p")) {
1502 if (chdir(CTDLDIR) < 0) {
1503 perror("can't change to " CTDLDIR);
1508 * Drop privileges if necessary. We stat
1509 * citadel.config to get the uid/gid since it's
1510 * guaranteed to have the uid/gid we want.
1512 if (!getuid() || !getgid()) {
1513 if (stat(file_citadel_config, &st) < 0) {
1514 perror("couldn't stat citadel.config");
1517 if (!getgid() && (setgid(st.st_gid) < 0)) {
1518 perror("couldn't change gid");
1521 if (!getuid() && (setuid(st.st_uid) < 0)) {
1522 perror("couldn't change uid");
1526 scr_printf("Privileges changed to uid %d gid %d\n",
1527 getuid(), getgid());
1530 argc = shift(argc, argv, a, 1);
1536 /* Get screen dimensions. First we go to a default of 80x24.
1537 * Then attempt to read the actual screen size from the terminal.
1539 check_screen_dims();
1543 newprompt("Connect to (return for local server): ", hostbuf, 64);
1546 scr_printf("Attaching to server...\n");
1547 ipc = CtdlIPC_new(argc, argv, hostbuf, portbuf);
1549 error_printf("Can't connect: %s\n", strerror(errno));
1553 CtdlIPC_SetNetworkStatusCallback(ipc, scr_wait_indicator);
1555 if (!(ipc->isLocal)) {
1556 scr_printf("Connected to %s [%s].\n", ipc->ip_hostname, ipc->ip_address);
1559 ipc_for_signal_handlers = ipc; /* KLUDGE cover your eyes */
1561 CtdlIPC_chat_recv(ipc, aaa);
1562 if (aaa[0] != '2') {
1563 scr_printf("%s\n", &aaa[4]);
1564 logoff(ipc, atoi(aaa));
1567 /* If there is a [nonce] at the end, put the nonce in <nonce>, else nonce
1571 if ((sptr = strchr(aaa, '<')) == NULL)
1577 if ((sptr2 = strchr(sptr, '>')) == NULL)
1585 strncpy(nonce, sptr, (size_t)NONCE_SIZE);
1590 /* Evaluate encryption preferences */
1591 if (arg_encrypt != RC_NO && rc_encrypt != RC_NO) {
1592 if (!ipc->isLocal || arg_encrypt == RC_YES || rc_encrypt == RC_YES) {
1593 secure = (CtdlIPCStartEncryption(ipc, aaa) / 100 == 2) ? 1 : 0;
1595 error_printf("Can't encrypt: %s\n", aaa);
1600 get_serv_info(ipc, telnet_client_host);
1601 scr_printf("%-24s\n%s\n%s\n", ipc->ServInfo.software, ipc->ServInfo.humannode,
1602 ipc->ServInfo.site_location);
1604 scr_printf(" pause next stop\n");
1605 scr_printf(" ctrl-s ctrl-o ctrl-c\n\n");
1606 formout(ipc, "hello"); /* print the opening greeting */
1609 GSTA: /* See if we have a username and password on disk */
1610 if (rc_remember_passwords) {
1611 get_stored_password(hostbuf, portbuf, fullname, password);
1612 if (!IsEmptyStr(fullname)) {
1613 r = CtdlIPCTryLogin(ipc, fullname, aaa);
1616 r = CtdlIPCTryApopPassword(ipc, make_apop_string(password, nonce, hexstring, sizeof hexstring), aaa);
1618 r = CtdlIPCTryPassword(ipc, password, aaa);
1623 load_user_info(aaa);
1626 set_stored_password(hostbuf, portbuf, "", "");
1634 if (!IsEmptyStr(rc_username)) {
1635 strcpy(fullname, rc_username);
1637 newprompt("Enter your name: ", fullname, 29);
1640 if (!strcasecmp(fullname, "new")) { /* just in case */
1641 scr_printf("Please enter the name you wish to log in with.\n");
1644 (!strcasecmp(fullname, "bbs"))
1645 || (!strcasecmp(fullname, "new"))
1646 || (IsEmptyStr(fullname)));
1648 if (!strcasecmp(fullname, "off")) {
1653 /* FIXME this is a stupid way to do guest mode but it's a reasonable test harness FIXME */
1654 if ( (ipc->ServInfo.guest_logins) && (!strcasecmp(fullname, "guest")) ) {
1658 /* sign on to the server */
1659 r = CtdlIPCTryLogin(ipc, fullname, aaa);
1663 /* password authentication */
1664 if (!IsEmptyStr(rc_password)) {
1665 strcpy(password, rc_password);
1667 newprompt("\rPlease enter your password: ", password, -(SIZ-1));
1671 r = CtdlIPCTryApopPassword(ipc, make_apop_string(password, nonce, hexstring, sizeof hexstring), aaa);
1674 r = CtdlIPCTryApopPassword(ipc, make_apop_string(password, nonce, hexstring, sizeof hexstring), aaa);
1677 r = CtdlIPCTryPassword(ipc, password, aaa);
1680 r = CtdlIPCTryPassword(ipc, password, aaa);
1685 load_user_info(aaa);
1686 offer_to_remember_password(ipc, hostbuf, portbuf,
1687 fullname, password);
1690 scr_printf("<< wrong password >>\n");
1691 if (!IsEmptyStr(rc_password))
1695 NEWUSR: if (IsEmptyStr(rc_password)) {
1696 scr_printf("'%s' not found.\n", fullname);
1697 scr_printf("Type 'off' if you would like to exit.\n");
1698 if (ipc->ServInfo.newuser_disabled == 1) {
1701 scr_printf("Do you want to create a new user account called '%s'? ",
1708 r = CtdlIPCCreateUser(ipc, fullname, 1, aaa);
1710 scr_printf("%s\n", aaa);
1713 load_user_info(aaa);
1715 while (set_password(ipc) != 0);
1718 enter_config(ipc, 1);
1721 /* Switch color support on or off if we're in user mode */
1722 if (rc_ansi_color == 3) {
1723 if (userflags & US_COLOR)
1729 color(BRIGHT_WHITE);
1730 scr_printf("\n%s\nAccess level: %d (%s)\n"
1731 "User #%ld / Login #%d",
1732 fullname, axlevel, axdefs[(int) axlevel],
1733 usernum, timescalled);
1734 if (lastcall > 0L) {
1735 scr_printf(" / Last login: %s",
1736 asctime(localtime(&lastcall)));
1740 r = CtdlIPCMiscCheck(ipc, &chek, aaa);
1746 scr_printf("*** You have a new private message in Mail>\n");
1748 scr_printf("*** You have %d new private messages in Mail>\n", b);
1750 if (!IsEmptyStr(rc_gotmail_cmd)) {
1751 rv = system(rc_gotmail_cmd);
1753 scr_printf("*** failed to check for mail calling %s Reason %d.\n",
1754 rc_gotmail_cmd, rv);
1758 if ((axlevel >= AxAideU) && (chek.needvalid > 0)) {
1759 scr_printf("*** Users need validation\n");
1761 if (chek.needregis > 0) {
1762 scr_printf("*** Please register.\n");
1763 formout(ipc, "register");
1767 /* Make up some temporary filenames for use in various parts of the
1768 * program. Don't mess with these once they've been set, because we
1769 * will be unlinking them later on in the program and we don't
1770 * want to delete something that we didn't create. */
1771 CtdlMakeTempFileName(temp, sizeof temp);
1772 CtdlMakeTempFileName(temp2, sizeof temp2);
1773 CtdlMakeTempFileName(tempdir, sizeof tempdir);
1775 r = CtdlIPCGetConfig(ipc, &myself, aaa);
1776 set_floor_mode(ipc);
1778 /* Enter the lobby */
1779 dotgoto(ipc, "_BASEROOM_", 1, 0);
1781 /* Main loop for the system... user is logged in. */
1786 readmsgs(ipc, LastMessages, ReadForward, 5);
1788 readmsgs(ipc, NewMessages, ReadForward, 0);
1790 /* MAIN COMMAND LOOP */
1792 mcmd = getcmd(ipc, argbuf); /* Get keyboard command */
1795 check_screen_dims(); /* get screen size */
1801 formout(ipc, "help");
1804 entmsg(ipc, 0, ((userflags & US_EXTEDIT) ? 2 : 0), 0);
1807 entmsg(ipc, 0, 1, 0);
1810 entmsg(ipc, 0, 2, 0);
1813 entmsg(ipc, 0, ((userflags & US_EXTEDIT) ? 2 : 0), 1);
1815 case 5: /* <G>oto */
1819 case 47: /* <A>bandon */
1820 if (!rc_alt_semantics) {
1825 case 90: /* <.A>bandon */
1826 if (!rc_alt_semantics)
1828 dotgoto(ipc, argbuf, 0, 0);
1830 case 58: /* <M>ail */
1832 dotgoto(ipc, "_MAIL_", 1, 0);
1835 if (!IsEmptyStr(argbuf)) {
1837 dotgoto(ipc, argbuf, 0, 0);
1841 if (!IsEmptyStr(argbuf)) {
1842 if (rc_alt_semantics) {
1845 dotgoto(ipc, argbuf, 0, 0);
1848 case 95: /* what exactly is the numbering scheme supposed to be anyway? --Ford, there isn't one. -IO */
1849 dotungoto(ipc, argbuf);
1852 readmsgs(ipc, AllMessages, ReadForward, 0);
1855 readmsgs(ipc, LastMessages, ReadForward, 5);
1858 readmsgs(ipc, NewMessages, ReadForward, 0);
1861 readmsgs(ipc, AllMessages, ReadReverse, 0);
1864 readmsgs(ipc, OldMessages, ReadReverse, 0);
1867 readmsgs(ipc, LastMessages, ReadForward,
1884 userlist(ipc, argbuf);
1942 if (!rc_alt_semantics) {
1954 cli_image_upload(ipc, "_userpic_");
1957 cli_image_upload(ipc, "_roompic_");
1961 snprintf(aaa, sizeof aaa, "_floorpic_|%d", curr_floor);
1962 cli_image_upload(ipc, aaa);
1966 enternew(ipc, "roomname", aaa, 20);
1967 r = CtdlIPCChangeRoomname(ipc, aaa, bbb);
1969 scr_printf("\n%s\n", bbb);
1972 enternew(ipc, "hostname", aaa, 25);
1973 r = CtdlIPCChangeHostname(ipc, aaa, bbb);
1975 scr_printf("\n%s\n", bbb);
1978 enternew(ipc, "username", aaa, 32);
1979 r = CtdlIPCChangeUsername(ipc, aaa, bbb);
1981 scr_printf("\n%s\n", bbb);
1991 display_help(ipc, argbuf);
1995 formout(ipc, "register");
2000 scr_printf("Are you sure (y/n)? ");
2002 if (!rc_alt_semantics)
2010 scr_printf("All users will be disconnected! "
2011 "Really terminate the server? ");
2013 if (!rc_alt_semantics)
2015 r = CtdlIPCTerminateServerNow(ipc, aaa);
2016 scr_printf("%s\n", aaa);
2025 scr_printf("Do you really want to schedule a "
2026 "server shutdown? ");
2028 r = CtdlIPCTerminateServerScheduled(ipc, 1, aaa);
2032 "The Citadel server will terminate when all users are logged off.\n"
2036 "The Citadel server will not terminate.\n"
2044 network_config_management(ipc, "listrecp",
2045 "Message-by-message mailing list recipients");
2049 network_config_management(ipc, "digestrecp",
2050 "Digest mailing list recipients");
2054 network_config_management(ipc, "ignet_push_share",
2055 "Nodes with which we share this room");
2059 do_ignet_configuration(ipc);
2063 do_filterlist_configuration(ipc);
2067 if (rc_alt_semantics) {
2078 who_is_online(ipc, 0);
2082 who_is_online(ipc, 1);
2086 who_is_online(ipc, 2);
2090 do_system_configuration(ipc);
2094 do_internet_configuration(ipc);
2098 check_message_base(ipc);
2110 enter_config(ipc, 2);
2114 enter_config(ipc, 0);
2115 set_floor_mode(ipc);
2119 enter_config(ipc, 3);
2120 set_floor_mode(ipc);
2124 gotofloor(ipc, argbuf, GF_GOTO);
2128 gotofloor(ipc, argbuf, GF_SKIP);
2132 forget_this_floor(ipc);
2164 knrooms(ipc, floor_mode);
2174 misc_server_cmd(ipc, argbuf);
2178 edit_system_message(ipc, argbuf);
2198 case 110: /* <+> Next room */
2199 gotoroomstep(ipc, 1, 0);
2202 case 111: /* <-> Previous room */
2203 gotoroomstep(ipc, 0, 0);
2206 case 112: /* <>> Next floor */
2207 gotofloorstep(ipc, 1, GF_GOTO);
2210 case 113: /* <<> Previous floor */
2211 gotofloorstep(ipc, 0, GF_GOTO);
2214 case 116: /* <.> skip to <+> Next room */
2215 gotoroomstep(ipc, 1, 1);
2218 case 117: /* <.> skip to <-> Previous room */
2219 gotoroomstep(ipc, 0, 1);
2222 case 118: /* <.> skip to <>> Next floor */
2223 gotofloorstep(ipc, 1, GF_SKIP);
2226 case 119: /* <.> skip to <<> Previous floor */
2227 gotofloorstep(ipc, 0, GF_SKIP);
2238 case 120: /* .KAnonymous */
2239 dotknown(ipc, 0, NULL);
2242 case 121: /* .KDirectory */
2243 dotknown(ipc, 1, NULL);
2246 case 122: /* .KMatch */
2247 dotknown(ipc, 2, argbuf);
2250 case 123: /* .KpreferredOnly */
2251 dotknown(ipc, 3, NULL);
2254 case 124: /* .KPrivate */
2255 dotknown(ipc, 4, NULL);
2258 case 125: /* .KRead only */
2259 dotknown(ipc, 5, NULL);
2262 case 126: /* .KShared */
2263 dotknown(ipc, 6, NULL);
2266 case 127: /* Configure POP3 aggregation */
2267 do_pop3client_configuration(ipc);
2270 case 128: /* Configure XML/RSS feed retrieval */
2271 do_rssclient_configuration(ipc);
2274 default: /* allow some math on the command */
2275 /* commands 100... to 100+MAX_EDITORS-1 will
2276 call the appropriate editor... in other
2277 words, command numbers 100+ will match
2278 the citadel.rc keys editor0, editor1, etc.*/
2279 if (mcmd >= 100 && mcmd < (100+MAX_EDITORS))
2281 /* entmsg mode >=2 select editor */
2282 entmsg(ipc, 0, mcmd - 100 + 2, 0);
2286 } while (termn8 == 0);
2288 TERMN8: scr_printf("%s logged out.", fullname);
2290 color(ORIGINAL_PAIR);
2292 while (marchptr != NULL) {
2293 remove_march(marchptr->march_name, 0);
2296 scr_printf("\n\nType 'off' to disconnect, or next user...\n");
2299 if ((mcmd == 29) || (mcmd == 15)) {
2300 stty_ctdl(SB_RESTORE);
2301 formout(ipc, "goodbye");
2304 /* Free the ungoto list */
2305 for (lp = 0; lp < uglistsize; lp++) {