3 * More client-side support functions.
4 * Unlike routines.c, some of these DO use global variables.
10 #include <sys/types.h>
18 #if TIME_WITH_SYS_TIME
19 # include <sys/time.h>
23 # include <sys/time.h>
35 #include "citadel_ipc.h"
36 #include "citadel_decls.h"
37 #include "routines2.h"
47 /* work around solaris include files */
53 extern char tempdir[];
54 extern char *axdefs[7];
55 extern long highest_msg_read;
56 extern long maxmsgnum;
57 extern unsigned room_flags;
58 extern int screenwidth;
62 int eopen(char *name, int mode)
65 ret = open(name, mode);
67 err_printf("Cannot open file '%s', mode=%d, errno=%d\n",
76 int room_prompt(unsigned int qrflags)
77 { /* return proper room prompt character */
80 if (qrflags & QR_DIRECTORY)
82 if ((a == ']') && (qrflags & QR_NETWORK))
84 if ((a == '>') && (qrflags & QR_NETWORK))
89 void entregis(CtdlIPC *ipc)
90 { /* register with name and address */
106 int r; /* IPC response code */
111 strcpy(tmpstate, "");
113 strcpy(tmpphone, "");
114 strcpy(tmpemail, "");
115 strcpy(tmpcountry, "");
117 r = CtdlIPCGetUserRegistration(ipc, NULL, ®, buf);
121 while (reg && strlen(reg) > 0) {
123 extract_token(buf, reg, 0, '\n', sizeof buf);
124 remove_token(reg, 0, '\n');
127 safestrncpy(tmpname, buf, sizeof tmpname);
129 safestrncpy(tmpaddr, buf, sizeof tmpaddr);
131 safestrncpy(tmpcity, buf, sizeof tmpcity);
133 safestrncpy(tmpstate, buf, sizeof tmpstate);
135 safestrncpy(tmpzip, buf, sizeof tmpzip);
137 safestrncpy(tmpphone, buf, sizeof tmpphone);
139 safestrncpy(tmpemail, buf, sizeof tmpemail);
141 safestrncpy(tmpcountry, buf, sizeof tmpcountry);
145 strprompt("REAL name", tmpname, 29);
146 strprompt("Address", tmpaddr, 24);
147 strprompt("City/town", tmpcity, 14);
148 strprompt("State/province", tmpstate, 2);
149 strprompt("ZIP/Postal Code", tmpzip, 10);
150 strprompt("Country", tmpcountry, 31);
151 strprompt("Telephone number", tmpphone, 14);
155 safestrncpy(holdemail, tmpemail, sizeof holdemail);
156 strprompt("Email address", tmpemail, 31);
157 r = CtdlIPCDirectoryLookup(ipc, tmpemail, buf);
159 extract_token(diruser, buf, 0, '@', sizeof diruser);
160 extract_token(dirnode, buf, 1, '@', sizeof dirnode);
163 if ((strcasecmp(diruser, fullname))
164 || (strcasecmp(dirnode, ipc->ServInfo.nodename))) {
166 "\nYou can't use %s as your address.\n",
169 "It is already in use by %s @ %s.\n",
172 safestrncpy(tmpemail, holdemail, sizeof tmpemail);
177 /* now send the registration info back to the server */
178 reg = (char *)realloc(reg, SIZ);
180 sprintf(reg, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
181 tmpname, tmpaddr, tmpcity, tmpstate,
182 tmpzip, tmpphone, tmpemail, tmpcountry);
183 r = CtdlIPCSetRegistration(ipc, reg, buf);
185 scr_printf("%s\n", buf);
191 void updatels(CtdlIPC *ipc)
192 { /* make all messages old in current room */
194 int r; /* IPC response code */
196 if (rc_alt_semantics) {
197 if (maxmsgnum == 0 && highest_msg_read == 0) {
200 r = CtdlIPCSetLastRead(ipc, (maxmsgnum > highest_msg_read) ?
201 maxmsgnum : highest_msg_read, buf);
203 r = CtdlIPCSetLastRead(ipc, (maxmsgnum > highest_msg_read) ?
204 maxmsgnum : highest_msg_read, buf);
205 /* r = CtdlIPCSetLastRead(ipc, maxmsgnum, buf); */
206 /* This is a quick-and-dirty fix to all msgs becoming new in Mail>.
207 * It will need to be rethought when messages.c is rewritten.
211 scr_printf("%s\n", buf);
215 * only make messages old in this room that have been read
217 void updatelsa(CtdlIPC *ipc)
220 int r; /* IPC response code */
222 r = CtdlIPCSetLastRead(ipc, highest_msg_read, buf);
224 scr_printf("%s\n", &buf[4]);
229 * client-based uploads (for users with their own clientware)
231 void cli_upload(CtdlIPC *ipc)
237 int r; /* IPC response code */
241 if ((room_flags & QR_UPLOAD) == 0) {
242 scr_printf("*** You cannot upload to this room.\n");
245 newprompt("File to be uploaded: ", flnm, 55);
246 fd = open(flnm, O_RDONLY);
248 scr_printf("Cannot open '%s': %s\n", flnm, strerror(errno));
251 scr_printf("Enter a description of this file:\n");
252 newprompt(": ", desc, 75);
254 /* Keep generating filenames in hope of finding a unique one */
257 /* basename of filename */
259 if (haschar(tbuf, '/'))
260 extract_token(tbuf, flnm,
261 num_tokens(tbuf, '/') - 1,
264 /* filename.1, filename.2, etc */
266 sprintf(&tbuf[strlen(tbuf)], ".%d", a);
269 r = CtdlIPCFileUpload(ipc, tbuf, desc, flnm, progress, buf);
270 if (r / 100 == 5 || r < 0)
271 scr_printf("%s\n", buf);
276 if (a > 0) scr_printf("Saved as '%s'\n", tbuf);
281 * Function used for various image upload commands
283 void cli_image_upload(CtdlIPC *ipc, char *keyname)
289 /* Can we upload this image? */
290 r = CtdlIPCImageUpload(ipc, 0, NULL, keyname, NULL, buf);
292 err_printf("%s\n", buf);
295 newprompt("Image file to be uploaded: ", flnm, 55);
296 r = CtdlIPCImageUpload(ipc, 1, flnm, keyname, progress, buf);
298 err_printf("%s\n", buf);
300 err_printf("Cannot upload '%s': %s\n", flnm, strerror(errno));
302 /* else upload succeeded */
307 * protocol-based uploads (Xmodem, Ymodem, Zmodem)
309 void upload(CtdlIPC *ipc, int c)
310 { /* c = upload mode */
320 if ((room_flags & QR_UPLOAD) == 0) {
321 scr_printf("*** You cannot upload to this room.\n");
324 /* we don't need a filename when receiving batch y/z modem */
325 if ((c == 2) || (c == 3))
328 newprompt("Enter filename: ", flnm, 15);
330 for (a = 0; a < strlen(flnm); ++a)
331 if ((flnm[a] == '/') || (flnm[a] == '\\') || (flnm[a] == '>')
332 || (flnm[a] == '?') || (flnm[a] == '*')
333 || (flnm[a] == ';') || (flnm[a] == '&'))
336 /* create a temporary directory... */
337 if (mkdir(tempdir, 0700) != 0) {
338 scr_printf("*** Could not create temporary directory %s: %s\n",
339 tempdir, strerror(errno));
342 /* now do the transfer ... in a separate process */
349 scr_printf("Receiving %s - press Ctrl-D to end.\n", flnm);
350 fp = fopen(flnm, "w");
366 execlp("rx", "rx", flnm, NULL);
371 execlp("rb", "rb", NULL);
376 execlp("rz", "rz", NULL);
382 } while ((b != xfer_pid) && (b != (-1)));
387 scr_printf("\r*** Transfer unsuccessful.\n");
391 scr_printf("\r*** Transfer successful.\n");
392 snprintf(buf, sizeof buf, "cd %s; ls", tempdir);
393 lsfp = popen(buf, "r");
395 while (fgets(flnm, sizeof flnm, lsfp) != NULL) {
396 flnm[strlen(flnm) - 1] = 0; /* chop newline */
397 snprintf(buf, sizeof buf,
398 "Enter a short description of '%s':\n: ",
400 newprompt(buf, desc, 150);
401 snprintf(buf, sizeof buf, "%s/%s", tempdir, flnm);
402 r = CtdlIPCFileUpload(ipc, flnm, desc, buf, progress, tbuf);
403 scr_printf("%s\n", tbuf);
411 * validate a user (returns 0 for successful validation, nonzero if quitting)
413 int val_user(CtdlIPC *ipc, char *user, int do_validate)
421 int r; /* IPC response code */
424 r = CtdlIPCGetUserRegistration(ipc, user, &resp, cmd);
428 extract_token(buf, resp, 0, '\n', sizeof buf);
429 remove_token(resp, 0, '\n');
432 scr_printf("User #%s - %s ", buf, cmd);
434 scr_printf("PW: %s\n", buf);
436 scr_printf("%s\n", buf);
438 scr_printf("%s\n", buf);
440 scr_printf("%s, ", buf);
442 scr_printf("%s ", buf);
444 scr_printf("%s\n", buf);
446 scr_printf("%s\n", buf);
450 scr_printf("%s\n", buf);
452 scr_printf("%s\n", buf);
453 } while (strlen(resp));
454 scr_printf("Current access level: %d (%s)\n", ax, axdefs[ax]);
456 scr_printf("%s\n%s\n", user, &cmd[4]);
458 if (resp) free(resp);
461 /* now set the access level */
463 sprintf(answer, "%d", ax);
464 strprompt("New access level (? for help, q to quit)",
466 if ((answer[0] >= '0') && (answer[0] <= '6')) {
468 r = CtdlIPCValidateUser(ipc, user, ax, cmd);
470 scr_printf("%s\n\n", cmd);
473 if (tolower(answer[0]) == 'q') {
474 scr_printf("*** Aborted.\n\n");
477 if (answer[0] == '?') {
478 scr_printf("Available access levels:\n");
479 for (a=0; a<7; ++a) {
480 scr_printf("%d - %s\n",
490 void validate(CtdlIPC *ipc)
491 { /* validate new users */
495 int r; /* IPC response code */
498 r = CtdlIPCNextUnvalidatedUser(ipc, cmd);
502 scr_printf("%s\n", cmd);
504 extract_token(buf, cmd, 0, '|', sizeof buf);
505 if (val_user(ipc, buf, 1) != 0) finished = 1;
507 } while (finished == 0);
515 stty_ctdl(SB_RESTORE);
518 signal(SIGINT, SIG_DFL);
519 signal(SIGQUIT, SIG_DFL);
520 execlp(getenv("SHELL"), getenv("SHELL"), NULL);
521 err_printf("Could not open a shell: %s\n", strerror(errno));
526 } while ((a != b) && (a != (-1)));
532 * <.A>ide <F>ile <D>elete command
534 void deletefile(CtdlIPC *ipc)
539 newprompt("Filename: ", filename, 31);
540 if (strlen(filename) == 0)
542 CtdlIPCDeleteFile(ipc, filename, buf);
543 err_printf("%s\n", buf);
547 * <.A>ide <F>ile <S>end command
549 void netsendfile(CtdlIPC *ipc)
551 char filename[32], destsys[20], buf[256];
553 newprompt("Filename: ", filename, 31);
554 if (strlen(filename) == 0)
556 newprompt("System to send to: ", destsys, 19);
557 CtdlIPCNetSendFile(ipc, filename, destsys, buf);
558 err_printf("%s\n", buf);
563 * <.A>ide <F>ile <M>ove command
565 void movefile(CtdlIPC *ipc)
568 char newroom[ROOMNAMELEN];
571 newprompt("Filename: ", filename, 63);
572 if (strlen(filename) == 0)
574 newprompt("Enter target room: ", newroom, ROOMNAMELEN - 1);
575 CtdlIPCMoveFile(ipc, filename, newroom, buf);
576 err_printf("%s\n", buf);
581 * list of users who have filled out a bio
583 void list_bio(CtdlIPC *ipc)
588 int r; /* IPC response code */
590 r = CtdlIPCListUsersWithBios(ipc, &resp, buf);
592 pprintf("%s\n", buf);
595 while (resp && strlen(resp)) {
596 extract_token(buf, resp, 0, '\n', sizeof buf);
597 remove_token(resp, 0, '\n');
598 if ((pos + strlen(buf) + 5) > screenwidth) {
602 pprintf("%s, ", buf);
603 pos = pos + strlen(buf) + 2;
605 pprintf("%c%c \n\n", 8, 8);
606 if (resp) free(resp);
613 void read_bio(CtdlIPC *ipc)
618 int r; /* IPC response code */
621 newprompt("Read bio for who ('?' for list) : ", who, 25);
623 if (!strcmp(who, "?"))
625 } while (!strcmp(who, "?"));
627 r = CtdlIPCGetBio(ipc, who, &resp, buf);
629 pprintf("%s\n", buf);
632 while (strlen(resp)) {
633 extract_token(buf, resp, 0, '\n', sizeof buf);
634 remove_token(resp, 0, '\n');
635 pprintf("%s\n", buf);
637 if (resp) free(resp);
642 * General system configuration command
644 void do_system_configuration(CtdlIPC *ipc)
647 #define NUM_CONFIGS 57
650 char sc[NUM_CONFIGS][256];
652 struct ExpirePolicy *site_expirepolicy = NULL;
653 struct ExpirePolicy *mbx_expirepolicy = NULL;
656 int r; /* IPC response code */
657 int server_configs = 0;
659 /* Clear out the config buffers */
660 memset(&sc[0][0], 0, sizeof(sc));
662 /* Fetch the current config */
663 r = CtdlIPCGetSystemConfig(ipc, &resp, buf);
665 server_configs = num_tokens(resp, '\n');
666 for (a=0; a<server_configs; ++a) {
667 if (a < NUM_CONFIGS) {
668 extract_token(&sc[a][0], resp, a, '\n', sizeof sc[a]);
672 if (resp) free(resp);
674 /* Fetch the expire policy (this will silently fail on old servers,
675 * resulting in "default" policy)
677 r = CtdlIPCGetMessageExpirationPolicy(ipc, 2, &site_expirepolicy, buf);
678 r = CtdlIPCGetMessageExpirationPolicy(ipc, 3, &mbx_expirepolicy, buf);
680 /* Identification parameters */
682 strprompt("Node name", &sc[0][0], 15);
683 strprompt("Fully qualified domain name", &sc[1][0], 63);
684 strprompt("Human readable node name", &sc[2][0], 20);
685 strprompt("Telephone number", &sc[3][0], 15);
686 strprompt("Geographic location of this system", &sc[12][0], 31);
687 strprompt("Name of system administrator", &sc[13][0], 25);
688 strprompt("Paginator prompt", &sc[10][0], 79);
690 /* Security parameters */
692 snprintf(sc[7], sizeof sc[7], "%d", (boolprompt(
693 "Require registration for new users",
695 snprintf(sc[29], sizeof sc[29], "%d", (boolprompt(
696 "Disable self-service user account creation",
698 strprompt("Initial access level for new users", &sc[6][0], 1);
699 strprompt("Access level required to create rooms", &sc[19][0], 1);
700 snprintf(sc[4], sizeof sc[4], "%d", (boolprompt(
701 "Automatically give room aide privs to a user who creates a private room",
704 snprintf(sc[8], sizeof sc[8], "%d", (boolprompt(
705 "Automatically move problem user messages to twit room",
708 strprompt("Name of twit room", &sc[9][0], ROOMNAMELEN);
709 snprintf(sc[11], sizeof sc[11], "%d", (boolprompt(
710 "Restrict Internet mail to only those with that privilege",
712 snprintf(sc[26], sizeof sc[26], "%d", (boolprompt(
713 "Allow Aides to Zap (forget) rooms",
716 if (strlen(&sc[18][0]) > 0) logpages = 1;
718 logpages = boolprompt("Log all pages", logpages);
720 strprompt("Name of logging room", &sc[18][0], ROOMNAMELEN);
725 snprintf(sc[52], sizeof sc[52], "%d", (boolprompt(
726 "Use system authentication",
731 strprompt("Server connection idle timeout (in seconds)", &sc[5][0], 4);
732 strprompt("Maximum concurrent sessions", &sc[14][0], 4);
733 strprompt("Maximum message length", &sc[20][0], 20);
734 strprompt("Minimum number of worker threads", &sc[21][0], 3);
735 strprompt("Maximum number of worker threads", &sc[22][0], 3);
736 snprintf(sc[43], sizeof sc[43], "%d", (boolprompt(
737 "Automatically delete committed database logs",
740 strprompt("Server IP address (0.0.0.0 for 'any')", &sc[37][0], 15);
741 strprompt("POP3 server port (-1 to disable)", &sc[23][0], 5);
742 strprompt("POP3S server port (-1 to disable)", &sc[40][0], 5);
743 strprompt("IMAP server port (-1 to disable)", &sc[27][0], 5);
744 strprompt("IMAPS server port (-1 to disable)", &sc[39][0], 5);
745 strprompt("SMTP MTA server port (-1 to disable)", &sc[24][0], 5);
746 strprompt("SMTP MSA server port (-1 to disable)", &sc[38][0], 5);
747 strprompt("SMTPS server port (-1 to disable)", &sc[41][0], 5);
748 strprompt("Postfix TCP Dictionary Port server port (-1 to disable)", &sc[50][0], 5);
749 strprompt("ManageSieve server port (-1 to disable)", &sc[51][0], 5);
750 /* This logic flips the question around, because it's one of those
751 * situations where 0=yes and 1=no
755 a = boolprompt("Correct forged From: lines during authenticated SMTP",
758 snprintf(sc[25], sizeof sc[25], "%d", a);
759 snprintf(sc[45], sizeof sc[45], "%d", (boolprompt(
760 "Allow unauthenticated SMTP clients to spoof my domains",
762 snprintf(sc[44], sizeof sc[44], "%d", (boolprompt(
763 "Instantly expunge deleted IMAP messages",
767 if (ipc->ServInfo.supports_ldap) {
768 a = strlen(&sc[32][0]);
769 a = (a ? 1 : 0); /* Set only to 1 or 0 */
770 a = boolprompt("Connect this Citadel to an LDAP directory", a);
772 strprompt("Host name of LDAP server",
774 strprompt("Port number of LDAP service",
776 strprompt("Base DN", &sc[34][0], 255);
777 strprompt("Bind DN", &sc[35][0], 255);
778 strprompt("Password for bind DN", &sc[36][0], 255);
781 strcpy(&sc[32][0], "");
785 /* Expiry settings */
786 strprompt("Default user purge time (days)", &sc[16][0], 5);
787 strprompt("Default room purge time (days)", &sc[17][0], 5);
789 /* Angels and demons dancing in my head... */
791 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_mode);
792 strprompt("System default message expire policy (? for list)",
796 "1. Never automatically expire messages\n"
797 "2. Expire by message count\n"
798 "3. Expire by message age\n");
800 } while ((buf[0] < '1') || (buf[0] > '3'));
801 site_expirepolicy->expire_mode = buf[0] - '0';
803 /* ...lunatics and monsters underneath my bed */
804 if (site_expirepolicy->expire_mode == 2) {
805 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_value);
806 strprompt("Keep how many messages online?", buf, 10);
807 site_expirepolicy->expire_value = atol(buf);
809 if (site_expirepolicy->expire_mode == 3) {
810 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_value);
811 strprompt("Keep messages for how many days?", buf, 10);
812 site_expirepolicy->expire_value = atol(buf);
815 /* Media messiahs preying on my fears... */
817 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_mode);
818 strprompt("Mailbox default message expire policy (? for list)",
822 "0. Go with the system default\n"
823 "1. Never automatically expire messages\n"
824 "2. Expire by message count\n"
825 "3. Expire by message age\n");
827 } while ((buf[0] < '0') || (buf[0] > '3'));
828 mbx_expirepolicy->expire_mode = buf[0] - '0';
830 /* ...Pop culture prophets playing in my ears */
831 if (mbx_expirepolicy->expire_mode == 2) {
832 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_value);
833 strprompt("Keep how many messages online?", buf, 10);
834 mbx_expirepolicy->expire_value = atol(buf);
836 if (mbx_expirepolicy->expire_mode == 3) {
837 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_value);
838 strprompt("Keep messages for how many days?", buf, 10);
839 mbx_expirepolicy->expire_value = atol(buf);
842 strprompt("How often to run network jobs (in seconds)", &sc[28][0], 5);
843 strprompt("Hour to run purges (0-23)", &sc[31][0], 2);
844 snprintf(sc[42], sizeof sc[42], "%d", (boolprompt(
845 "Enable full text search index (warning: resource intensive)",
848 snprintf(sc[46], sizeof sc[46], "%d", (boolprompt(
849 "Perform journaling of email messages",
851 snprintf(sc[47], sizeof sc[47], "%d", (boolprompt(
852 "Perform journaling of non-email messages",
854 if ( (atoi(&sc[46][0])) || (atoi(&sc[47][0])) ) {
855 strprompt("Email destination of journalized messages",
859 /* Funambol push stuff */
860 strprompt("Funambol server (blank to disable)", &sc[53][0], 63);
861 strprompt("Funambol server port", &sc[54][0], 5);
862 strprompt("Funambol sync source", &sc[55][0], 63);
863 strprompt("Funambol authentication details (user:pass in Base64)", &sc[56][0],63);
866 scr_printf("Save this configuration? ");
869 for (a = 0; a < NUM_CONFIGS; a++)
870 r += 1 + strlen(sc[a]);
871 resp = (char *)calloc(1, r);
873 err_printf("Can't save config - out of memory!\n");
876 for (a = 0; a < NUM_CONFIGS; a++) {
880 r = CtdlIPCSetSystemConfig(ipc, resp, buf);
882 err_printf("%s\n", buf);
886 r = CtdlIPCSetMessageExpirationPolicy(ipc, 2, site_expirepolicy, buf);
888 err_printf("%s\n", buf);
891 r = CtdlIPCSetMessageExpirationPolicy(ipc, 3, mbx_expirepolicy, buf);
893 err_printf("%s\n", buf);
901 * support function for do_internet_configuration()
903 void get_inet_rec_type(CtdlIPC *ipc, char *buf) {
906 keyopt(" <1> localhost (Alias for this computer)\n");
907 keyopt(" <2> gateway domain (Domain for all Citadel systems)\n");
908 keyopt(" <3> smart-host (Forward all outbound mail to this host)\n");
909 keyopt(" <4> directory (Consult the Global Address Book)\n");
910 keyopt(" <5> SpamAssassin (Address of SpamAssassin server)\n");
911 keyopt(" <6> RBL (domain suffix of spam hunting RBL)\n");
912 sel = intprompt("Which one", 1, 1, 6);
914 case 1: strcpy(buf, "localhost");
916 case 2: strcpy(buf, "gatewaydomain");
918 case 3: strcpy(buf, "smarthost");
920 case 4: strcpy(buf, "directory");
922 case 5: strcpy(buf, "spamassassin");
924 case 6: strcpy(buf, "rbl");
931 * Internet mail configuration
933 void do_internet_configuration(CtdlIPC *ipc)
946 r = CtdlIPCGetSystemConfigByType(ipc, INTERNETCFG, &resp, buf);
948 while (strlen(resp)) {
949 extract_token(buf, resp, 0, '\n', sizeof buf);
950 remove_token(resp, 0, '\n');
952 if (num_recs == 1) recs = malloc(sizeof(char *));
953 else recs = realloc(recs, (sizeof(char *)) * num_recs);
954 recs[num_recs-1] = malloc(strlen(buf) + 1);
955 strcpy(recs[num_recs-1], buf);
958 if (resp) free(resp);
963 scr_printf("### Host or domain Record type \n");
965 scr_printf("--- -------------------------------------------------- --------------------\n");
966 for (i=0; i<num_recs; ++i) {
968 scr_printf("%3d ", i+1);
969 extract_token(buf, recs[i], 0, '|', sizeof buf);
971 scr_printf("%-50s ", buf);
972 extract_token(buf, recs[i], 1, '|', sizeof buf);
973 color(BRIGHT_MAGENTA);
974 scr_printf("%-20s\n", buf);
978 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
981 newprompt("Enter host name: ",
984 if (strlen(buf) > 0) {
987 recs = malloc(sizeof(char *));
988 else recs = realloc(recs,
989 (sizeof(char *)) * num_recs);
991 get_inet_rec_type(ipc,
993 recs[num_recs-1] = strdup(buf);
998 i = intprompt("Delete which one",
1002 for (j=i; j<num_recs; ++j)
1003 recs[j] = recs[j+1];
1008 for (i = 0; i < num_recs; i++)
1009 r += 1 + strlen(recs[i]);
1010 resp = (char *)calloc(1, r);
1012 err_printf("Can't save config - out of memory!\n");
1015 if (num_recs) for (i = 0; i < num_recs; i++) {
1016 strcat(resp, recs[i]);
1019 r = CtdlIPCSetSystemConfigByType(ipc, INTERNETCFG, resp, buf);
1021 err_printf("%s\n", buf);
1023 scr_printf("Wrote %d records.\n", num_recs);
1028 quitting = !modified || boolprompt(
1029 "Quit without saving", 0);
1034 } while (!quitting);
1037 for (i=0; i<num_recs; ++i) free(recs[i]);
1045 * Edit network configuration for room sharing, mailing lists, etc.
1047 void network_config_management(CtdlIPC *ipc, char *entrytype, char *comment)
1049 char filename[PATH_MAX];
1050 char changefile[PATH_MAX];
1060 char *listing = NULL;
1063 if (strlen(editor_paths[0]) == 0) {
1064 scr_printf("You must have an external editor configured in"
1065 " order to use this function.\n");
1069 CtdlMakeTempFileName(filename, sizeof filename);
1070 CtdlMakeTempFileName(changefile, sizeof changefile);
1072 tempfp = fopen(filename, "w");
1073 if (tempfp == NULL) {
1074 err_printf("Cannot open %s: %s\n", filename, strerror(errno));
1078 fprintf(tempfp, "# Configuration for room: %s\n", room_name);
1079 fprintf(tempfp, "# %s\n", comment);
1080 fprintf(tempfp, "# Specify one per line.\n"
1083 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
1085 while(listing && strlen(listing)) {
1086 extract_token(buf, listing, 0, '\n', sizeof buf);
1087 remove_token(listing, 0, '\n');
1088 extract_token(instr, buf, 0, '|', sizeof instr);
1089 if (!strcasecmp(instr, entrytype)) {
1090 tokens = num_tokens(buf, '|');
1091 for (i=1; i<tokens; ++i) {
1092 extract_token(addr, buf, i, '|', sizeof addr);
1093 fprintf(tempfp, "%s", addr);
1094 if (i < (tokens-1)) {
1095 fprintf(tempfp, "|");
1098 fprintf(tempfp, "\n");
1108 e_ex_code = 1; /* start with a failed exit code */
1110 stty_ctdl(SB_RESTORE);
1111 editor_pid = fork();
1112 cksum = file_checksum(filename);
1113 if (editor_pid == 0) {
1114 chmod(filename, 0600);
1115 putenv("WINDOW_TITLE=Network configuration");
1116 execlp(editor_paths[0], editor_paths[0], filename, NULL);
1119 if (editor_pid > 0) {
1122 b = ka_wait(&e_ex_code);
1123 } while ((b != editor_pid) && (b >= 0));
1129 if (file_checksum(filename) == cksum) {
1130 err_printf("*** No changes to save.\n");
1134 if (e_ex_code == 0) { /* Save changes */
1135 changefp = fopen(changefile, "w");
1137 /* Load all netconfig entries that are *not* of the type we are editing */
1138 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
1140 while(listing && strlen(listing)) {
1141 extract_token(buf, listing, 0, '\n', sizeof buf);
1142 remove_token(listing, 0, '\n');
1143 extract_token(instr, buf, 0, '|', sizeof instr);
1144 if (strcasecmp(instr, entrytype)) {
1145 fprintf(changefp, "%s\n", buf);
1154 /* ...and merge that with the data we just edited */
1155 tempfp = fopen(filename, "r");
1156 while (fgets(buf, sizeof buf, tempfp) != NULL) {
1157 for (i=0; i<strlen(buf); ++i) {
1158 if (buf[i] == '#') buf[i] = 0;
1161 if (strlen(buf) > 0) {
1162 fprintf(changefp, "%s|%s\n", entrytype, buf);
1168 /* now write it to the server... */
1169 changefp = fopen(changefile, "r");
1170 if (changefp != NULL) {
1171 listing = load_message_from_file(changefp);
1173 r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
1181 unlink(filename); /* Delete the temporary files */
1187 * IGnet node configuration
1189 void do_ignet_configuration(CtdlIPC *ipc) {
1198 char *listing = NULL;
1201 r = CtdlIPCGetSystemConfigByType(ipc, IGNETCFG, &listing, buf);
1202 if (r / 100 == 1) while (*listing && strlen(listing)) {
1203 extract_token(buf, listing, 0, '\n', sizeof buf);
1204 remove_token(listing, 0, '\n');
1207 if (num_recs == 1) recs = malloc(sizeof(char *));
1208 else recs = realloc(recs, (sizeof(char *)) * num_recs);
1209 recs[num_recs-1] = malloc(SIZ);
1210 strcpy(recs[num_recs-1], buf);
1212 if (listing) free(listing);
1216 color(BRIGHT_WHITE);
1225 "------------------ "
1226 "-------------------------------- "
1228 for (i=0; i<num_recs; ++i) {
1230 scr_printf("%3d ", i+1);
1231 extract_token(buf, recs[i], 0, '|', sizeof buf);
1233 scr_printf("%-16s ", buf);
1234 extract_token(buf, recs[i], 1, '|', sizeof buf);
1235 color(BRIGHT_MAGENTA);
1236 scr_printf("%-18s ", buf);
1237 extract_token(buf, recs[i], 2, '|', sizeof buf);
1239 scr_printf("%-32s ", buf);
1240 extract_token(buf, recs[i], 3, '|', sizeof buf);
1241 color(BRIGHT_MAGENTA);
1242 scr_printf("%-3s\n", buf);
1247 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
1252 recs = malloc(sizeof(char *));
1253 else recs = realloc(recs,
1254 (sizeof(char *)) * num_recs);
1255 newprompt("Enter node name : ", buf, 16);
1257 newprompt("Enter shared secret: ",
1258 &buf[strlen(buf)], 18);
1260 newprompt("Enter host or IP : ",
1261 &buf[strlen(buf)], 32);
1262 strcat(buf, "|504");
1263 strprompt("Enter port number : ",
1264 &buf[strlen(buf)-3], 5);
1265 recs[num_recs-1] = strdup(buf);
1269 i = intprompt("Delete which one",
1270 1, 1, num_recs) - 1;
1273 for (j=i; j<num_recs; ++j)
1274 recs[j] = recs[j+1];
1279 for (i = 0; i < num_recs; ++i)
1280 r += 1 + strlen(recs[i]);
1281 listing = (char*) calloc(1, r);
1283 err_printf("Can't save config - out of memory!\n");
1286 if (num_recs) for (i = 0; i < num_recs; ++i) {
1287 strcat(listing, recs[i]);
1288 strcat(listing, "\n");
1290 r = CtdlIPCSetSystemConfigByType(ipc, IGNETCFG, listing, buf);
1292 scr_printf("%s\n", buf);
1294 scr_printf("Wrote %d records.\n", num_recs);
1299 quitting = !modified || boolprompt(
1300 "Quit without saving", 0);
1305 } while (!quitting);
1308 for (i=0; i<num_recs; ++i) free(recs[i]);
1314 * Filter list configuration
1316 void do_filterlist_configuration(CtdlIPC *ipc)
1326 char *listing = NULL;
1329 r = CtdlIPCGetSystemConfigByType(ipc, FILTERLIST, &listing, buf);
1330 if (r / 100 == 1) while (*listing && strlen(listing)) {
1331 extract_token(buf, listing, 0, '\n', sizeof buf);
1332 remove_token(listing, 0, '\n');
1335 if (num_recs == 1) recs = malloc(sizeof(char *));
1336 else recs = realloc(recs, (sizeof(char *)) * num_recs);
1337 recs[num_recs-1] = malloc(SIZ);
1338 strcpy(recs[num_recs-1], buf);
1340 if (listing) free(listing);
1344 color(BRIGHT_WHITE);
1352 "---------------------------- "
1353 "---------------------------- "
1356 for (i=0; i<num_recs; ++i) {
1358 scr_printf("%3d ", i+1);
1359 extract_token(buf, recs[i], 0, '|', sizeof buf);
1361 scr_printf("%-28s ", buf);
1362 extract_token(buf, recs[i], 1, '|', sizeof buf);
1363 color(BRIGHT_MAGENTA);
1364 scr_printf("%-28s ", buf);
1365 extract_token(buf, recs[i], 2, '|', sizeof buf);
1367 scr_printf("%-16s\n", buf);
1368 extract_token(buf, recs[i], 3, '|', sizeof buf);
1372 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
1377 recs = malloc(sizeof(char *));
1378 else recs = realloc(recs,
1379 (sizeof(char *)) * num_recs);
1380 newprompt("Enter user name: ", buf, 28);
1382 newprompt("Enter room name: ",
1383 &buf[strlen(buf)], 28);
1385 newprompt("Enter node name: ",
1386 &buf[strlen(buf)], 16);
1388 recs[num_recs-1] = strdup(buf);
1392 i = intprompt("Delete which one",
1393 1, 1, num_recs) - 1;
1396 for (j=i; j<num_recs; ++j)
1397 recs[j] = recs[j+1];
1402 for (i = 0; i < num_recs; ++i)
1403 r += 1 + strlen(recs[i]);
1404 listing = (char*) calloc(1, r);
1406 err_printf("Can't save config - out of memory!\n");
1409 if (num_recs) for (i = 0; i < num_recs; ++i) {
1410 strcat(listing, recs[i]);
1411 strcat(listing, "\n");
1413 r = CtdlIPCSetSystemConfigByType(ipc, FILTERLIST, listing, buf);
1415 scr_printf("%s\n", buf);
1417 scr_printf("Wrote %d records.\n", num_recs);
1422 quitting = !modified || boolprompt(
1423 "Quit without saving", 0);
1428 } while (!quitting);
1431 for (i=0; i<num_recs; ++i) free(recs[i]);