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)
31 /* NUM_CONFIGS is now defined in citadel.h */
34 char sc[NUM_CONFIGS][256];
36 struct ExpirePolicy *site_expirepolicy = NULL;
37 struct ExpirePolicy *mbx_expirepolicy = NULL;
40 int r; /* IPC response code */
41 int server_configs = 0;
43 /* Clear out the config buffers */
44 memset(&sc[0][0], 0, sizeof(sc));
46 /* Fetch the current config */
47 r = CtdlIPCGetSystemConfig(ipc, &resp, buf);
49 server_configs = num_tokens(resp, '\n');
50 for (a = 0; a < server_configs; ++a) {
51 if (a < NUM_CONFIGS) {
52 extract_token(&sc[a][0], resp, a, '\n', sizeof sc[a]);
59 /* Fetch the expire policy (this will silently fail on old servers,
60 * resulting in "default" policy)
62 r = CtdlIPCGetMessageExpirationPolicy(ipc, 2, &site_expirepolicy, buf);
63 r = CtdlIPCGetMessageExpirationPolicy(ipc, 3, &mbx_expirepolicy, buf);
65 /* Identification parameters */
67 strprompt("Node name", &sc[0][0], 15);
68 strprompt("Fully qualified domain name", &sc[1][0], 63);
69 strprompt("Human readable node name", &sc[2][0], 20);
70 strprompt("Telephone number", &sc[3][0], 15);
71 strprompt("Geographic location of this system", &sc[12][0], 31);
72 strprompt("Name of system administrator", &sc[13][0], 25);
73 strprompt("Paginator prompt", &sc[10][0], 79);
75 /* Security parameters */
77 snprintf(sc[7], sizeof sc[7], "%d", (boolprompt("Require registration for new users", atoi(&sc[7][0]))));
78 snprintf(sc[29], sizeof sc[29], "%d", (boolprompt("Disable self-service user account creation", atoi(&sc[29][0]))));
79 strprompt("Initial access level for new users", &sc[6][0], 1);
80 strprompt("Access level required to create rooms", &sc[19][0], 1);
81 snprintf(sc[67], sizeof sc[67], "%d", (boolprompt("Allow anonymous guest logins", atoi(&sc[67][0]))));
82 snprintf(sc[4], sizeof sc[4], "%d", (boolprompt("Automatically give room admin privs to a user who creates a private room",
85 snprintf(sc[8], sizeof sc[8], "%d", (boolprompt("Automatically move problem user messages to twit room", atoi(&sc[8][0]))));
87 strprompt("Name of twit room", &sc[9][0], ROOMNAMELEN);
88 snprintf(sc[11], sizeof sc[11], "%d", (boolprompt("Restrict Internet mail to only those with that privilege",
90 snprintf(sc[26], sizeof sc[26], "%d", (boolprompt("Allow admins to Zap (forget) rooms", atoi(&sc[26][0]))));
92 if (!IsEmptyStr(&sc[18][0])) {
97 logpages = boolprompt("Log all instant messages", logpages);
99 strprompt("Name of logging room", &sc[18][0], ROOMNAMELEN);
104 /* Commented out because this setting isn't really appropriate to
105 * change while the server is running.
107 * snprintf(sc[52], sizeof sc[52], "%d", (boolprompt(
108 * "Use system authentication",
109 * atoi(&sc[52][0]))));
114 strprompt("Server connection idle timeout (in seconds)", &sc[5][0], 4);
115 strprompt("Maximum concurrent sessions", &sc[14][0], 4);
116 strprompt("Maximum message length", &sc[20][0], 20);
117 strprompt("Minimum number of worker threads", &sc[21][0], 3);
118 strprompt("Maximum number of worker threads", &sc[22][0], 3);
119 snprintf(sc[43], sizeof sc[43], "%d", (boolprompt("Automatically delete committed database logs", atoi(&sc[43][0]))));
121 strprompt("Server IP address (* for 'any')", &sc[37][0], 15);
122 strprompt("POP3 server port (-1 to disable)", &sc[23][0], 5);
123 strprompt("POP3S server port (-1 to disable)", &sc[40][0], 5);
124 strprompt("IMAP server port (-1 to disable)", &sc[27][0], 5);
125 strprompt("IMAPS server port (-1 to disable)", &sc[39][0], 5);
126 strprompt("SMTP MTA server port (-1 to disable)", &sc[24][0], 5);
127 strprompt("SMTP MSA server port (-1 to disable)", &sc[38][0], 5);
128 strprompt("SMTPS server port (-1 to disable)", &sc[41][0], 5);
129 strprompt("NNTP server port (-1 to disable)", &sc[70][0], 5);
130 strprompt("NNTPS server port (-1 to disable)", &sc[71][0], 5);
131 strprompt("Postfix TCP Dictionary Port server port (-1 to disable)", &sc[50][0], 5);
132 strprompt("ManageSieve server port (-1 to disable)", &sc[51][0], 5);
134 strprompt("XMPP (Jabber) client to server port (-1 to disable)", &sc[62][0], 5);
135 /* No prompt because we don't implement this service yet, it's just a placeholder */
136 /* strprompt("XMPP (Jabber) server to server port (-1 to disable)", &sc[63][0], 5); */
138 /* This logic flips the question around, because it's one of those
139 * situations where 0=yes and 1=no
143 a = boolprompt("Correct forged From: lines during authenticated SMTP", a);
145 snprintf(sc[25], sizeof sc[25], "%d", a);
147 snprintf(sc[66], sizeof sc[66], "%d", (boolprompt("Flag messages as spam instead of rejecting", atoi(&sc[66][0]))));
149 /* This logic flips the question around, because it's one of those
150 * situations where 0=yes and 1=no
154 a = boolprompt("Force IMAP posts in public rooms to be from the user who submitted them", a);
156 snprintf(sc[61], sizeof sc[61], "%d", a);
158 snprintf(sc[45], sizeof sc[45], "%d", (boolprompt("Allow unauthenticated SMTP clients to spoof my domains",
160 snprintf(sc[57], sizeof sc[57], "%d", (boolprompt("Perform RBL checks at greeting instead of after RCPT",
164 if (ipc->ServInfo.supports_ldap) {
165 a = strlen(&sc[32][0]);
166 a = (a ? 1 : 0); /* Set only to 1 or 0 */
167 a = boolprompt("Do you want to configure LDAP authentication?", a);
169 strprompt("Host name of LDAP server", &sc[32][0], 127);
170 strprompt("Port number of LDAP service", &sc[33][0], 5);
171 strprompt("Base DN", &sc[34][0], 255);
172 strprompt("Bind DN (or blank for anonymous bind)", &sc[35][0], 255);
173 strprompt("Password for bind DN (or blank for anonymous bind)", &sc[36][0], 255);
175 strcpy(&sc[32][0], "");
179 /* Expiry settings */
180 strprompt("Default user purge time (days)", &sc[16][0], 5);
181 strprompt("Default room purge time (days)", &sc[17][0], 5);
183 /* Angels and demons dancing in my head... */
185 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_mode);
186 strprompt("System default message expire policy (? for list)", buf, 1);
189 "1. Never automatically expire messages\n"
190 "2. Expire by message count\n" "3. Expire by message age\n");
192 } while ((buf[0] < '1') || (buf[0] > '3'));
193 site_expirepolicy->expire_mode = buf[0] - '0';
195 /* ...lunatics and monsters underneath my bed */
196 if (site_expirepolicy->expire_mode == 2) {
197 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_value);
198 strprompt("Keep how many messages online?", buf, 10);
199 site_expirepolicy->expire_value = atol(buf);
201 if (site_expirepolicy->expire_mode == 3) {
202 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_value);
203 strprompt("Keep messages for how many days?", buf, 10);
204 site_expirepolicy->expire_value = atol(buf);
207 /* Media messiahs preying on my fears... */
209 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_mode);
210 strprompt("Mailbox default message expire policy (? for list)", buf, 1);
213 "0. Go with the system default\n"
214 "1. Never automatically expire messages\n"
215 "2. Expire by message count\n" "3. Expire by message age\n");
217 } while ((buf[0] < '0') || (buf[0] > '3'));
218 mbx_expirepolicy->expire_mode = buf[0] - '0';
220 /* ...Pop culture prophets playing in my ears */
221 if (mbx_expirepolicy->expire_mode == 2) {
222 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_value);
223 strprompt("Keep how many messages online?", buf, 10);
224 mbx_expirepolicy->expire_value = atol(buf);
226 if (mbx_expirepolicy->expire_mode == 3) {
227 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_value);
228 strprompt("Keep messages for how many days?", buf, 10);
229 mbx_expirepolicy->expire_value = atol(buf);
232 strprompt("How often to run network jobs (in seconds)", &sc[28][0], 5);
233 strprompt("Default frequency to run POP3 collection (in seconds)", &sc[64][0], 5);
234 strprompt("Fastest frequency to run POP3 collection (in seconds)", &sc[65][0], 5);
235 strprompt("Hour to run purges (0-23)", &sc[31][0], 2);
236 snprintf(sc[42], sizeof sc[42], "%d", (boolprompt("Enable full text search index (warning: resource intensive)",
239 snprintf(sc[46], sizeof sc[46], "%d", (boolprompt("Perform journaling of email messages", atoi(&sc[46][0]))));
240 snprintf(sc[47], sizeof sc[47], "%d", (boolprompt("Perform journaling of non-email messages", atoi(&sc[47][0]))));
241 if ((atoi(&sc[46][0])) || (atoi(&sc[47][0]))) {
242 strprompt("Email destination of journalized messages", &sc[48][0], 127);
245 /* No more Funambol */
251 /* External pager stuff */
253 if (strlen(sc[60]) > 0)
255 yes_pager = boolprompt("Configure an external pager tool", yes_pager);
257 strprompt("External pager tool", &sc[60][0], 255);
263 scr_printf("Save this configuration? ");
266 for (a = 0; a < NUM_CONFIGS; a++) {
267 r += 1 + strlen(sc[a]);
269 resp = (char *) calloc(1, r);
271 scr_printf("Can't save config - out of memory!\n");
274 for (a = 0; a < NUM_CONFIGS; a++) {
278 r = CtdlIPCSetSystemConfig(ipc, resp, buf);
280 scr_printf("%s\n", buf);
284 r = CtdlIPCSetMessageExpirationPolicy(ipc, 2, site_expirepolicy, buf);
286 scr_printf("%s\n", buf);
289 r = CtdlIPCSetMessageExpirationPolicy(ipc, 3, mbx_expirepolicy, buf);
291 scr_printf("%s\n", buf);
295 if (site_expirepolicy)
296 free(site_expirepolicy);
297 if (mbx_expirepolicy)
298 free(mbx_expirepolicy);
303 * support function for do_internet_configuration()
305 void get_inet_rec_type(CtdlIPC * ipc, char *buf)
309 keyopt(" <1> localhost (Alias for this computer)\n");
310 keyopt(" <2> smart host (Forward all outbound mail to this host)\n");
311 keyopt(" <3> fallback host (Send mail to this host only if direct delivery fails)\n");
312 keyopt(" <4> SpamAssassin (Address of SpamAssassin server)\n");
313 keyopt(" <5> RBL (domain suffix of spam hunting RBL)\n");
314 keyopt(" <6> masq domains (Domains as which users are allowed to masquerade)\n");
315 keyopt(" <7> ClamAV (Address of ClamAV clamd server)\n");
316 sel = intprompt("Which one", 1, 1, 8);
319 strcpy(buf, "localhost");
322 strcpy(buf, "smarthost");
325 strcpy(buf, "fallbackhost");
328 strcpy(buf, "spamassassin");
334 strcpy(buf, "masqdomain");
337 strcpy(buf, "clamav");
344 * Internet mail configuration
346 void do_internet_configuration(CtdlIPC * ipc)
358 r = CtdlIPCGetSystemConfigByType(ipc, INTERNETCFG, &resp, buf);
360 while (!IsEmptyStr(resp)) {
361 extract_token(buf, resp, 0, '\n', sizeof buf);
362 remove_token(resp, 0, '\n');
364 // VILE SLEAZY HACK: replace obsolete "directory" domains with "localhost"
365 char *d = strstr(buf, "|directory");
367 strcpy(d, "|localhost");
372 recs = malloc(sizeof(char *));
374 recs = realloc(recs, (sizeof(char *)) * num_recs);
375 recs[num_recs - 1] = malloc(strlen(buf) + 1);
376 strcpy(recs[num_recs - 1], buf);
385 scr_printf("### Host or domain Record type \n");
387 scr_printf("--- -------------------------------------------------- --------------------\n");
388 for (i = 0; i < num_recs; ++i) {
390 scr_printf("%3d ", i + 1);
391 extract_token(buf, recs[i], 0, '|', sizeof buf);
393 scr_printf("%-50s ", buf);
394 extract_token(buf, recs[i], 1, '|', sizeof buf);
395 color(BRIGHT_MAGENTA);
396 scr_printf("%-20s\n", buf);
400 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
403 newprompt("Enter host name: ", buf, 50);
405 if (!IsEmptyStr(buf)) {
408 recs = malloc(sizeof(char *));
410 recs = realloc(recs, (sizeof(char *)) * num_recs);
413 get_inet_rec_type(ipc, &buf[strlen(buf)]);
414 recs[num_recs - 1] = strdup(buf);
419 i = intprompt("Delete which one", 1, 1, num_recs) - 1;
422 for (j = i; j < num_recs; ++j) {
423 recs[j] = recs[j + 1];
429 for (i = 0; i < num_recs; i++)
430 r += 1 + strlen(recs[i]);
431 resp = (char *) calloc(1, r);
433 scr_printf("Can't save config - out of memory!\n");
437 for (i = 0; i < num_recs; i++) {
438 strcat(resp, recs[i]);
441 r = CtdlIPCSetSystemConfigByType(ipc, INTERNETCFG, resp, buf);
443 scr_printf("%s\n", buf);
445 scr_printf("Wrote %d records.\n", num_recs);
451 quitting = !modified || boolprompt("Quit without saving", 0);
459 for (i = 0; i < num_recs; ++i)
468 * Edit network configuration for room sharing, mailing lists, etc.
470 void network_config_management(CtdlIPC * ipc, char *entrytype, char *comment)
472 char filename[PATH_MAX];
473 char changefile[PATH_MAX];
483 char *listing = NULL;
486 if (IsEmptyStr(editor_path)) {
487 scr_printf("You must have an external editor configured in order to use this function.\n");
491 CtdlMakeTempFileName(filename, sizeof filename);
492 CtdlMakeTempFileName(changefile, sizeof changefile);
494 tempfp = fopen(filename, "w");
495 if (tempfp == NULL) {
496 scr_printf("Cannot open %s: %s\n", filename, strerror(errno));
500 fprintf(tempfp, "# Configuration for room: %s\n", room_name);
501 fprintf(tempfp, "# %s\n", comment);
502 fprintf(tempfp, "# Specify one per line.\n" "\n\n");
504 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
506 while (listing && !IsEmptyStr(listing)) {
507 extract_token(buf, listing, 0, '\n', sizeof buf);
508 remove_token(listing, 0, '\n');
509 extract_token(instr, buf, 0, '|', sizeof instr);
510 if (!strcasecmp(instr, entrytype)) {
511 tokens = num_tokens(buf, '|');
512 for (i = 1; i < tokens; ++i) {
513 extract_token(addr, buf, i, '|', sizeof addr);
514 fprintf(tempfp, "%s", addr);
515 if (i < (tokens - 1)) {
516 fprintf(tempfp, "|");
519 fprintf(tempfp, "\n");
529 e_ex_code = 1; /* start with a failed exit code */
530 stty_ctdl(SB_RESTORE);
532 cksum = file_checksum(filename);
533 if (editor_pid == 0) {
534 chmod(filename, 0600);
535 putenv("WINDOW_TITLE=Network configuration");
536 execlp(editor_path, editor_path, filename, NULL);
539 if (editor_pid > 0) {
542 b = ka_wait(&e_ex_code);
543 } while ((b != editor_pid) && (b >= 0));
548 if (file_checksum(filename) == cksum) {
549 scr_printf("*** No changes to save.\n");
553 if (e_ex_code == 0) { /* Save changes */
554 changefp = fopen(changefile, "w");
556 /* Load all netconfig entries that are *not* of the type we are editing */
557 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
559 while (listing && !IsEmptyStr(listing)) {
560 extract_token(buf, listing, 0, '\n', sizeof buf);
561 remove_token(listing, 0, '\n');
562 extract_token(instr, buf, 0, '|', sizeof instr);
563 if (strcasecmp(instr, entrytype)) {
564 fprintf(changefp, "%s\n", buf);
573 /* ...and merge that with the data we just edited */
574 tempfp = fopen(filename, "r");
575 while (fgets(buf, sizeof buf, tempfp) != NULL) {
576 for (i = 0; i < strlen(buf); ++i) {
581 if (!IsEmptyStr(buf)) {
582 fprintf(changefp, "%s|%s\n", entrytype, buf);
588 /* now write it to the server... */
589 changefp = fopen(changefile, "r");
590 if (changefp != NULL) {
591 listing = load_message_from_file(changefp);
593 r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
601 unlink(filename); /* Delete the temporary files */
607 * POP3 aggregation client configuration
609 void do_pop3client_configuration(CtdlIPC * ipc)
618 char *listing = NULL;
619 char *other_listing = NULL;
623 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
625 while (listing && !IsEmptyStr(listing)) {
626 extract_token(buf, listing, 0, '\n', sizeof buf);
627 remove_token(listing, 0, '\n');
628 extract_token(instr, buf, 0, '|', sizeof instr);
629 if (!strcasecmp(instr, "pop3client")) {
633 recs = malloc(sizeof(char *));
635 recs = realloc(recs, (sizeof(char *)) * num_recs);
636 recs[num_recs - 1] = malloc(SIZ);
637 strcpy(recs[num_recs - 1], buf);
650 scr_printf("### " " Remote POP3 host " " User name " "Keep on server? " "\n");
652 scr_printf("--- " "---------------------------- " "---------------------------- " "--------------- " "\n");
653 for (i = 0; i < num_recs; ++i) {
655 scr_printf("%3d ", i + 1);
657 extract_token(buf, recs[i], 1, '|', sizeof buf);
659 scr_printf("%-28s ", buf);
661 extract_token(buf, recs[i], 2, '|', sizeof buf);
662 color(BRIGHT_MAGENTA);
663 scr_printf("%-28s ", buf);
666 scr_printf("%-15s\n", (extract_int(recs[i], 4) ? "Yes" : "No"));
670 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
675 recs = malloc(sizeof(char *));
677 recs = realloc(recs, (sizeof(char *)) * num_recs);
679 strcpy(buf, "pop3client|");
680 newprompt("Enter host name: ", &buf[strlen(buf)], 28);
682 newprompt("Enter user name: ", &buf[strlen(buf)], 28);
684 newprompt("Enter password : ", &buf[strlen(buf)], 16);
686 scr_printf("Keep messages on server instead of deleting them? ");
687 sprintf(&buf[strlen(buf)], "%d", yesno());
689 recs[num_recs - 1] = strdup(buf);
693 i = intprompt("Delete which one", 1, 1, num_recs) - 1;
696 for (j = i; j < num_recs; ++j)
697 recs[j] = recs[j + 1];
702 for (i = 0; i < num_recs; ++i) {
703 r += 1 + strlen(recs[i]);
705 listing = (char *) calloc(1, r);
707 scr_printf("Can't save config - out of memory!\n");
711 for (i = 0; i < num_recs; ++i) {
712 strcat(listing, recs[i]);
713 strcat(listing, "\n");
716 /* Retrieve all the *other* records for merging */
717 r = CtdlIPCGetRoomNetworkConfig(ipc, &other_listing, buf);
719 for (i = 0; i < num_tokens(other_listing, '\n'); ++i) {
720 extract_token(buf, other_listing, i, '\n', sizeof buf);
721 if (strncasecmp(buf, "pop3client|", 11)) {
722 listing = realloc(listing, strlen(listing) + strlen(buf) + 10);
723 strcat(listing, buf);
724 strcat(listing, "\n");
729 r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
734 scr_printf("%s\n", buf);
736 scr_printf("Wrote %d records.\n", num_recs);
742 quitting = !modified || boolprompt("Quit without saving", 0);
750 for (i = 0; i < num_recs; ++i)
762 * RSS feed retrieval client configuration
764 void do_rssclient_configuration(CtdlIPC * ipc)
773 char *listing = NULL;
774 char *other_listing = NULL;
778 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
780 while (listing && !IsEmptyStr(listing)) {
781 extract_token(buf, listing, 0, '\n', sizeof buf);
782 remove_token(listing, 0, '\n');
783 extract_token(instr, buf, 0, '|', sizeof instr);
784 if (!strcasecmp(instr, "rssclient")) {
788 recs = malloc(sizeof(char *));
790 recs = realloc(recs, (sizeof(char *)) * num_recs);
791 recs[num_recs - 1] = malloc(SIZ);
792 strcpy(recs[num_recs - 1], buf);
805 scr_printf("### Feed URL\n");
807 scr_printf("--- " "---------------------------------------------------------------------------" "\n");
809 for (i = 0; i < num_recs; ++i) {
811 scr_printf("%3d ", i + 1);
813 extract_token(buf, recs[i], 1, '|', sizeof buf);
815 scr_printf("%-75s\n", buf);
820 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
825 recs = malloc(sizeof(char *));
827 recs = realloc(recs, (sizeof(char *)) * num_recs);
829 strcpy(buf, "rssclient|");
830 newprompt("Enter feed URL: ", &buf[strlen(buf)], 75);
832 recs[num_recs - 1] = strdup(buf);
836 i = intprompt("Delete which one", 1, 1, num_recs) - 1;
839 for (j = i; j < num_recs; ++j)
840 recs[j] = recs[j + 1];
845 for (i = 0; i < num_recs; ++i) {
846 r += 1 + strlen(recs[i]);
848 listing = (char *) calloc(1, r);
850 scr_printf("Can't save config - out of memory!\n");
854 for (i = 0; i < num_recs; ++i) {
855 strcat(listing, recs[i]);
856 strcat(listing, "\n");
859 /* Retrieve all the *other* records for merging */
860 r = CtdlIPCGetRoomNetworkConfig(ipc, &other_listing, buf);
862 for (i = 0; i < num_tokens(other_listing, '\n'); ++i) {
863 extract_token(buf, other_listing, i, '\n', sizeof buf);
864 if (strncasecmp(buf, "rssclient|", 10)) {
865 listing = realloc(listing, strlen(listing) + strlen(buf) + 10);
866 strcat(listing, buf);
867 strcat(listing, "\n");
872 r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
877 scr_printf("%s\n", buf);
879 scr_printf("Wrote %d records.\n", num_recs);
885 quitting = !modified || boolprompt("Quit without saving", 0);
893 for (i = 0; i < num_recs; ++i)