1 // Configuration screens that are part of the text mode client.
3 // Copyright (c) 1987-2018 by the citadel.org team
5 // This program is open source software. Use, duplication, and/or
6 // disclosure are subject to the GNU General Purpose License version 3.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 #include "textclient.h"
16 extern char tempdir[];
17 extern char *axdefs[8];
18 extern long highest_msg_read;
19 extern long maxmsgnum;
20 extern unsigned room_flags;
21 extern int screenwidth;
22 char editor_path[PATH_MAX];
26 * General system configuration command
28 void do_system_configuration(CtdlIPC * ipc) {
30 char sc[NUM_CONFIGS][256];
32 struct ExpirePolicy *site_expirepolicy = NULL;
33 struct ExpirePolicy *mbx_expirepolicy = NULL;
36 int r; /* IPC response code */
37 int server_configs = 0;
39 /* Clear out the config buffers */
40 memset(&sc[0][0], 0, sizeof(sc));
42 /* Fetch the current config */
43 r = CtdlIPCGetSystemConfig(ipc, &resp, buf);
45 server_configs = num_tokens(resp, '\n');
46 for (a = 0; a < server_configs; ++a) {
47 if (a < NUM_CONFIGS) {
48 extract_token(&sc[a][0], resp, a, '\n', sizeof sc[a]);
56 /* Fetch the expire policy (this will silently fail on old servers,
57 * resulting in "default" policy)
59 r = CtdlIPCGetMessageExpirationPolicy(ipc, 2, &site_expirepolicy, buf);
60 r = CtdlIPCGetMessageExpirationPolicy(ipc, 3, &mbx_expirepolicy, buf);
62 /* Identification parameters */
64 strprompt("Node name", &sc[0][0], 15);
65 strprompt("Fully qualified domain name", &sc[1][0], 63);
66 strprompt("Human readable node name", &sc[2][0], 20);
67 strprompt("Telephone number", &sc[3][0], 15);
68 strprompt("Geographic location of this system", &sc[12][0], 31);
69 strprompt("Name of system administrator", &sc[13][0], 25);
70 strprompt("Paginator prompt", &sc[10][0], 79);
72 /* Security parameters */
74 snprintf(sc[7], sizeof sc[7], "%d", (boolprompt("Require registration for new users", atoi(&sc[7][0]))));
75 snprintf(sc[29], sizeof sc[29], "%d", (boolprompt("Disable self-service user account creation", atoi(&sc[29][0]))));
76 strprompt("Initial access level for new users", &sc[6][0], 1);
77 strprompt("Access level required to create rooms", &sc[19][0], 1);
78 snprintf(sc[67], sizeof sc[67], "%d", (boolprompt("Allow anonymous guest logins", atoi(&sc[67][0]))));
79 snprintf(sc[4], sizeof sc[4], "%d", (boolprompt("Automatically give room admin privs to a user who creates a private room",
82 snprintf(sc[8], sizeof sc[8], "%d", (boolprompt("Automatically move problem user messages to twit room", atoi(&sc[8][0]))));
84 strprompt("Name of twit room", &sc[9][0], ROOMNAMELEN);
85 snprintf(sc[11], sizeof sc[11], "%d", (boolprompt("Restrict Internet mail to only those with that privilege",
87 snprintf(sc[26], sizeof sc[26], "%d", (boolprompt("Allow admins to Zap (forget) rooms", atoi(&sc[26][0]))));
89 if (!IsEmptyStr(&sc[18][0])) {
95 logpages = boolprompt("Log all instant messages", logpages);
97 strprompt("Name of logging room", &sc[18][0], ROOMNAMELEN);
103 /* Commented out because this setting isn't really appropriate to
104 * change while the server is running.
106 * snprintf(sc[52], sizeof sc[52], "%d", (boolprompt(
107 * "Use system authentication",
108 * atoi(&sc[52][0]))));
113 strprompt("Server connection idle timeout (in seconds)", &sc[5][0], 4);
114 strprompt("Maximum concurrent sessions", &sc[14][0], 4);
115 strprompt("Maximum message length", &sc[20][0], 20);
116 strprompt("Minimum number of worker threads", &sc[21][0], 3);
117 strprompt("Maximum number of worker threads", &sc[22][0], 3);
118 snprintf(sc[43], sizeof sc[43], "%d", (boolprompt("Automatically delete committed database logs", atoi(&sc[43][0]))));
119 strprompt("Server IP address (* for 'any')", &sc[37][0], 15);
120 strprompt("POP3 server port (-1 to disable)", &sc[23][0], 5);
121 strprompt("POP3S server port (-1 to disable)", &sc[40][0], 5);
122 strprompt("IMAP server port (-1 to disable)", &sc[27][0], 5);
123 strprompt("IMAPS server port (-1 to disable)", &sc[39][0], 5);
124 strprompt("SMTP MTA server port (-1 to disable)", &sc[24][0], 5);
125 strprompt("SMTP MSA server port (-1 to disable)", &sc[38][0], 5);
126 strprompt("SMTPS server port (-1 to disable)", &sc[41][0], 5);
127 strprompt("NNTP server port (-1 to disable)", &sc[70][0], 5);
128 strprompt("NNTPS server port (-1 to disable)", &sc[71][0], 5);
129 strprompt("Postfix TCP Dictionary Port server port (-1 to disable)", &sc[50][0], 5);
130 strprompt("ManageSieve server port (-1 to disable)", &sc[51][0], 5);
131 strprompt("XMPP (Jabber) client to server port (-1 to disable)", &sc[62][0], 5);
132 // strprompt("XMPP (Jabber) server to server port (-1 to disable)", &sc[63][0], 5); This is just a placeholder.
134 /* This logic flips the question around, because it's one of those
135 * situations where 0=yes and 1=no
139 a = boolprompt("Correct forged From: lines during authenticated SMTP", a);
141 snprintf(sc[25], sizeof sc[25], "%d", a);
143 snprintf(sc[66], sizeof sc[66], "%d", (boolprompt("Flag messages as spam instead of rejecting", atoi(&sc[66][0]))));
145 /* This logic flips the question around, because it's one of those
146 * situations where 0=yes and 1=no
150 a = boolprompt("Force IMAP posts in public rooms to be from the user who submitted them", a);
152 snprintf(sc[61], sizeof sc[61], "%d", a);
154 snprintf(sc[45], sizeof sc[45], "%d", (boolprompt("Allow unauthenticated SMTP clients to spoof my domains",
156 snprintf(sc[57], sizeof sc[57], "%d", (boolprompt("Perform RBL checks at greeting instead of after RCPT",
160 if (ipc->ServInfo.supports_ldap) {
161 a = strlen(&sc[32][0]);
162 a = (a ? 1 : 0); /* Set only to 1 or 0 */
163 a = boolprompt("Do you want to configure LDAP authentication?", a);
165 strprompt("Host name of LDAP server", &sc[32][0], 127);
166 strprompt("Port number of LDAP service", &sc[33][0], 5);
167 strprompt("Base DN", &sc[34][0], 255);
168 strprompt("Bind DN (or blank for anonymous bind)", &sc[35][0], 255);
169 strprompt("Password for bind DN (or blank for anonymous bind)", &sc[36][0], 255);
171 strcpy(&sc[32][0], "");
175 /* Expiry settings */
176 strprompt("Default user purge time (days)", &sc[16][0], 5);
177 strprompt("Default room purge time (days)", &sc[17][0], 5);
179 /* Angels and demons dancing in my head... */
181 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_mode);
182 strprompt("System default message expire policy (? for list)", buf, 1);
185 "1. Never automatically expire messages\n"
186 "2. Expire by message count\n" "3. Expire by message age\n");
188 } while ((buf[0] < '1') || (buf[0] > '3'));
189 site_expirepolicy->expire_mode = buf[0] - '0';
191 /* ...lunatics and monsters underneath my bed */
192 if (site_expirepolicy->expire_mode == 2) {
193 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_value);
194 strprompt("Keep how many messages online?", buf, 10);
195 site_expirepolicy->expire_value = atol(buf);
197 if (site_expirepolicy->expire_mode == 3) {
198 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_value);
199 strprompt("Keep messages for how many days?", buf, 10);
200 site_expirepolicy->expire_value = atol(buf);
203 /* Media messiahs preying on my fears... */
205 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_mode);
206 strprompt("Mailbox default message expire policy (? for list)", buf, 1);
209 "0. Go with the system default\n"
210 "1. Never automatically expire messages\n"
211 "2. Expire by message count\n" "3. Expire by message age\n");
213 } while ((buf[0] < '0') || (buf[0] > '3'));
214 mbx_expirepolicy->expire_mode = buf[0] - '0';
216 /* ...Pop culture prophets playing in my ears */
217 if (mbx_expirepolicy->expire_mode == 2) {
218 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_value);
219 strprompt("Keep how many messages online?", buf, 10);
220 mbx_expirepolicy->expire_value = atol(buf);
222 if (mbx_expirepolicy->expire_mode == 3) {
223 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_value);
224 strprompt("Keep messages for how many days?", buf, 10);
225 mbx_expirepolicy->expire_value = atol(buf);
228 strprompt("How often to run network jobs (in seconds)", &sc[28][0], 5);
229 strprompt("Default frequency to run POP3 collection (in seconds)", &sc[64][0], 5);
230 strprompt("Fastest frequency to run POP3 collection (in seconds)", &sc[65][0], 5);
231 strprompt("Hour to run purges (0-23)", &sc[31][0], 2);
232 snprintf(sc[42], sizeof sc[42], "%d", (boolprompt("Enable full text search index (warning: resource intensive)", atoi(&sc[42][0]))));
233 snprintf(sc[46], sizeof sc[46], "%d", (boolprompt("Perform journaling of email messages", atoi(&sc[46][0]))));
234 snprintf(sc[47], sizeof sc[47], "%d", (boolprompt("Perform journaling of non-email messages", atoi(&sc[47][0]))));
235 if ((atoi(&sc[46][0])) || (atoi(&sc[47][0]))) {
236 strprompt("Email destination of journalized messages", &sc[48][0], 127);
239 /* No more Funambol */
245 /* External pager stuff */
247 if (strlen(sc[60]) > 0) {
250 yes_pager = boolprompt("Configure an external pager tool", yes_pager);
252 strprompt("External pager tool", &sc[60][0], 255);
258 scr_printf("Save this configuration? ");
261 for (a = 0; a < NUM_CONFIGS; a++) {
262 r += 1 + strlen(sc[a]);
264 resp = (char *) calloc(1, r);
266 scr_printf("Can't save config - out of memory!\n");
269 for (a = 0; a < NUM_CONFIGS; a++) {
273 r = CtdlIPCSetSystemConfig(ipc, resp, buf);
275 scr_printf("%s\n", buf);
279 r = CtdlIPCSetMessageExpirationPolicy(ipc, 2, site_expirepolicy, buf);
281 scr_printf("%s\n", buf);
284 r = CtdlIPCSetMessageExpirationPolicy(ipc, 3, mbx_expirepolicy, buf);
286 scr_printf("%s\n", buf);
290 if (site_expirepolicy)
291 free(site_expirepolicy);
292 if (mbx_expirepolicy)
293 free(mbx_expirepolicy);
298 * support function for do_internet_configuration()
300 void get_inet_rec_type(CtdlIPC * ipc, char *buf)
304 keyopt(" <1> localhost (Alias for this computer)\n");
305 keyopt(" <2> smart host (Forward all outbound mail to this host)\n");
306 keyopt(" <3> fallback host (Send mail to this host only if direct delivery fails)\n");
307 keyopt(" <4> SpamAssassin (Address of SpamAssassin server)\n");
308 keyopt(" <5> RBL (domain suffix of spam hunting RBL)\n");
309 keyopt(" <6> masq domains (Domains as which users are allowed to masquerade)\n");
310 keyopt(" <7> ClamAV (Address of ClamAV clamd server)\n");
311 sel = intprompt("Which one", 1, 1, 8);
314 strcpy(buf, "localhost");
317 strcpy(buf, "smarthost");
320 strcpy(buf, "fallbackhost");
323 strcpy(buf, "spamassassin");
329 strcpy(buf, "masqdomain");
332 strcpy(buf, "clamav");
339 * Internet mail configuration
341 void do_internet_configuration(CtdlIPC * ipc)
353 r = CtdlIPCGetSystemConfigByType(ipc, INTERNETCFG, &resp, buf);
355 while (!IsEmptyStr(resp)) {
356 extract_token(buf, resp, 0, '\n', sizeof buf);
357 remove_token(resp, 0, '\n');
359 // VILE SLEAZY HACK: replace obsolete "directory" domains with "localhost"
360 char *d = strstr(buf, "|directory");
362 strcpy(d, "|localhost");
367 recs = malloc(sizeof(char *));
369 recs = realloc(recs, (sizeof(char *)) * num_recs);
370 recs[num_recs - 1] = malloc(strlen(buf) + 1);
371 strcpy(recs[num_recs - 1], buf);
380 scr_printf("### Host or domain Record type \n");
382 scr_printf("--- -------------------------------------------------- --------------------\n");
383 for (i = 0; i < num_recs; ++i) {
385 scr_printf("%3d ", i + 1);
386 extract_token(buf, recs[i], 0, '|', sizeof buf);
388 scr_printf("%-50s ", buf);
389 extract_token(buf, recs[i], 1, '|', sizeof buf);
390 color(BRIGHT_MAGENTA);
391 scr_printf("%-20s\n", buf);
395 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
398 newprompt("Enter host name: ", buf, 50);
400 if (!IsEmptyStr(buf)) {
403 recs = malloc(sizeof(char *));
405 recs = realloc(recs, (sizeof(char *)) * num_recs);
408 get_inet_rec_type(ipc, &buf[strlen(buf)]);
409 recs[num_recs - 1] = strdup(buf);
414 i = intprompt("Delete which one", 1, 1, num_recs) - 1;
417 for (j = i; j < num_recs; ++j) {
418 recs[j] = recs[j + 1];
424 for (i = 0; i < num_recs; i++)
425 r += 1 + strlen(recs[i]);
426 resp = (char *) calloc(1, r);
428 scr_printf("Can't save config - out of memory!\n");
432 for (i = 0; i < num_recs; i++) {
433 strcat(resp, recs[i]);
436 r = CtdlIPCSetSystemConfigByType(ipc, INTERNETCFG, resp, buf);
438 scr_printf("%s\n", buf);
440 scr_printf("Wrote %d records.\n", num_recs);
446 quitting = !modified || boolprompt("Quit without saving", 0);
454 for (i = 0; i < num_recs; ++i)
463 * Edit network configuration for room sharing, mailing lists, etc.
465 void network_config_management(CtdlIPC * ipc, char *entrytype, char *comment)
467 char filename[PATH_MAX];
468 char changefile[PATH_MAX];
478 char *listing = NULL;
481 if (IsEmptyStr(editor_path)) {
482 scr_printf("You must have an external editor configured in order to use this function.\n");
486 CtdlMakeTempFileName(filename, sizeof filename);
487 CtdlMakeTempFileName(changefile, sizeof changefile);
489 tempfp = fopen(filename, "w");
490 if (tempfp == NULL) {
491 scr_printf("Cannot open %s: %s\n", filename, strerror(errno));
495 fprintf(tempfp, "# Configuration for room: %s\n", room_name);
496 fprintf(tempfp, "# %s\n", comment);
497 fprintf(tempfp, "# Specify one per line.\n" "\n\n");
499 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
501 while (listing && !IsEmptyStr(listing)) {
502 extract_token(buf, listing, 0, '\n', sizeof buf);
503 remove_token(listing, 0, '\n');
504 extract_token(instr, buf, 0, '|', sizeof instr);
505 if (!strcasecmp(instr, entrytype)) {
506 tokens = num_tokens(buf, '|');
507 for (i = 1; i < tokens; ++i) {
508 extract_token(addr, buf, i, '|', sizeof addr);
509 fprintf(tempfp, "%s", addr);
510 if (i < (tokens - 1)) {
511 fprintf(tempfp, "|");
514 fprintf(tempfp, "\n");
524 e_ex_code = 1; /* start with a failed exit code */
525 stty_ctdl(SB_RESTORE);
527 cksum = file_checksum(filename);
528 if (editor_pid == 0) {
529 chmod(filename, 0600);
530 putenv("WINDOW_TITLE=Network configuration");
531 execlp(editor_path, editor_path, filename, NULL);
534 if (editor_pid > 0) {
537 b = ka_wait(&e_ex_code);
538 } while ((b != editor_pid) && (b >= 0));
543 if (file_checksum(filename) == cksum) {
544 scr_printf("*** No changes to save.\n");
548 if (e_ex_code == 0) { /* Save changes */
549 changefp = fopen(changefile, "w");
551 /* Load all netconfig entries that are *not* of the type we are editing */
552 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
554 while (listing && !IsEmptyStr(listing)) {
555 extract_token(buf, listing, 0, '\n', sizeof buf);
556 remove_token(listing, 0, '\n');
557 extract_token(instr, buf, 0, '|', sizeof instr);
558 if (strcasecmp(instr, entrytype)) {
559 fprintf(changefp, "%s\n", buf);
568 /* ...and merge that with the data we just edited */
569 tempfp = fopen(filename, "r");
570 while (fgets(buf, sizeof buf, tempfp) != NULL) {
571 for (i = 0; i < strlen(buf); ++i) {
576 if (!IsEmptyStr(buf)) {
577 fprintf(changefp, "%s|%s\n", entrytype, buf);
583 /* now write it to the server... */
584 changefp = fopen(changefile, "r");
585 if (changefp != NULL) {
586 listing = load_message_from_file(changefp);
588 r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
596 unlink(filename); /* Delete the temporary files */
602 * POP3 aggregation client configuration
604 void do_pop3client_configuration(CtdlIPC * ipc)
613 char *listing = NULL;
614 char *other_listing = NULL;
618 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
620 while (listing && !IsEmptyStr(listing)) {
621 extract_token(buf, listing, 0, '\n', sizeof buf);
622 remove_token(listing, 0, '\n');
623 extract_token(instr, buf, 0, '|', sizeof instr);
624 if (!strcasecmp(instr, "pop3client")) {
628 recs = malloc(sizeof(char *));
630 recs = realloc(recs, (sizeof(char *)) * num_recs);
631 recs[num_recs - 1] = malloc(SIZ);
632 strcpy(recs[num_recs - 1], buf);
645 scr_printf("### " " Remote POP3 host " " User name " "Keep on server? " "\n");
647 scr_printf("--- " "---------------------------- " "---------------------------- " "--------------- " "\n");
648 for (i = 0; i < num_recs; ++i) {
650 scr_printf("%3d ", i + 1);
652 extract_token(buf, recs[i], 1, '|', sizeof buf);
654 scr_printf("%-28s ", buf);
656 extract_token(buf, recs[i], 2, '|', sizeof buf);
657 color(BRIGHT_MAGENTA);
658 scr_printf("%-28s ", buf);
661 scr_printf("%-15s\n", (extract_int(recs[i], 4) ? "Yes" : "No"));
665 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
670 recs = malloc(sizeof(char *));
672 recs = realloc(recs, (sizeof(char *)) * num_recs);
674 strcpy(buf, "pop3client|");
675 newprompt("Enter host name: ", &buf[strlen(buf)], 28);
677 newprompt("Enter user name: ", &buf[strlen(buf)], 28);
679 newprompt("Enter password : ", &buf[strlen(buf)], 16);
681 scr_printf("Keep messages on server instead of deleting them? ");
682 sprintf(&buf[strlen(buf)], "%d", yesno());
684 recs[num_recs - 1] = strdup(buf);
688 i = intprompt("Delete which one", 1, 1, num_recs) - 1;
691 for (j = i; j < num_recs; ++j)
692 recs[j] = recs[j + 1];
697 for (i = 0; i < num_recs; ++i) {
698 r += 1 + strlen(recs[i]);
700 listing = (char *) calloc(1, r);
702 scr_printf("Can't save config - out of memory!\n");
706 for (i = 0; i < num_recs; ++i) {
707 strcat(listing, recs[i]);
708 strcat(listing, "\n");
711 /* Retrieve all the *other* records for merging */
712 r = CtdlIPCGetRoomNetworkConfig(ipc, &other_listing, buf);
714 for (i = 0; i < num_tokens(other_listing, '\n'); ++i) {
715 extract_token(buf, other_listing, i, '\n', sizeof buf);
716 if (strncasecmp(buf, "pop3client|", 11)) {
717 listing = realloc(listing, strlen(listing) + strlen(buf) + 10);
718 strcat(listing, buf);
719 strcat(listing, "\n");
724 r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
729 scr_printf("%s\n", buf);
731 scr_printf("Wrote %d records.\n", num_recs);
737 quitting = !modified || boolprompt("Quit without saving", 0);
745 for (i = 0; i < num_recs; ++i)
753 * RSS feed retrieval client configuration
755 void do_rssclient_configuration(CtdlIPC * ipc)
764 char *listing = NULL;
765 char *other_listing = NULL;
769 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
771 while (listing && !IsEmptyStr(listing)) {
772 extract_token(buf, listing, 0, '\n', sizeof buf);
773 remove_token(listing, 0, '\n');
774 extract_token(instr, buf, 0, '|', sizeof instr);
775 if (!strcasecmp(instr, "rssclient")) {
779 recs = malloc(sizeof(char *));
781 recs = realloc(recs, (sizeof(char *)) * num_recs);
782 recs[num_recs - 1] = malloc(SIZ);
783 strcpy(recs[num_recs - 1], buf);
796 scr_printf("### Feed URL\n");
798 scr_printf("--- " "---------------------------------------------------------------------------" "\n");
800 for (i = 0; i < num_recs; ++i) {
802 scr_printf("%3d ", i + 1);
804 extract_token(buf, recs[i], 1, '|', sizeof buf);
806 scr_printf("%-75s\n", buf);
811 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
816 recs = malloc(sizeof(char *));
818 recs = realloc(recs, (sizeof(char *)) * num_recs);
820 strcpy(buf, "rssclient|");
821 newprompt("Enter feed URL: ", &buf[strlen(buf)], 75);
823 recs[num_recs - 1] = strdup(buf);
827 i = intprompt("Delete which one", 1, 1, num_recs) - 1;
830 for (j = i; j < num_recs; ++j)
831 recs[j] = recs[j + 1];
836 for (i = 0; i < num_recs; ++i) {
837 r += 1 + strlen(recs[i]);
839 listing = (char *) calloc(1, r);
841 scr_printf("Can't save config - out of memory!\n");
845 for (i = 0; i < num_recs; ++i) {
846 strcat(listing, recs[i]);
847 strcat(listing, "\n");
850 /* Retrieve all the *other* records for merging */
851 r = CtdlIPCGetRoomNetworkConfig(ipc, &other_listing, buf);
853 for (i = 0; i < num_tokens(other_listing, '\n'); ++i) {
854 extract_token(buf, other_listing, i, '\n', sizeof buf);
855 if (strncasecmp(buf, "rssclient|", 10)) {
856 listing = realloc(listing, strlen(listing) + strlen(buf) + 10);
857 strcat(listing, buf);
858 strcat(listing, "\n");
863 r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
868 scr_printf("%s\n", buf);
870 scr_printf("Wrote %d records.\n", num_recs);
876 quitting = !modified || boolprompt("Quit without saving", 0);
884 for (i = 0; i < num_recs; ++i)