1 // Configuration screens that are part of the text mode client.
3 // Copyright (c) 1987-2022 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];
25 // General system configuration command
26 void do_system_configuration(CtdlIPC * ipc) {
28 char sc[NUM_CONFIGS][256];
30 struct ExpirePolicy *site_expirepolicy = NULL;
31 struct ExpirePolicy *mbx_expirepolicy = NULL;
34 int r; // IPC response code
35 int server_configs = 0;
37 // Clear out the config buffers
38 memset(&sc[0][0], 0, sizeof(sc));
40 // Fetch the current config
41 r = CtdlIPCGetSystemConfig(ipc, &resp, buf);
43 server_configs = num_tokens(resp, '\n');
44 for (a = 0; a < server_configs; ++a) {
45 if (a < NUM_CONFIGS) {
46 extract_token(&sc[a][0], resp, a, '\n', sizeof sc[a]);
55 // Fetch the expire policy (this will silently fail on old servers, resulting in "default" policy)
56 r = CtdlIPCGetMessageExpirationPolicy(ipc, 2, &site_expirepolicy, buf);
57 r = CtdlIPCGetMessageExpirationPolicy(ipc, 3, &mbx_expirepolicy, buf);
59 // Identification parameters
60 strprompt("Node name", &sc[0][0], 15);
61 strprompt("Fully qualified domain name", &sc[1][0], 63);
62 strprompt("Human readable node name", &sc[2][0], 20);
63 strprompt("Telephone number", &sc[3][0], 15);
64 strprompt("Geographic location of this system", &sc[12][0], 31);
65 strprompt("Name of system administrator", &sc[13][0], 25);
66 strprompt("Paginator prompt", &sc[10][0], 79);
68 // Security parameters
69 snprintf(sc[7], sizeof sc[7], "%d", (boolprompt("Require registration for new users", atoi(&sc[7][0]))));
70 snprintf(sc[29], sizeof sc[29], "%d", (boolprompt("Disable self-service user account creation", atoi(&sc[29][0]))));
71 strprompt("Initial access level for new users", &sc[6][0], 1);
72 strprompt("Access level required to create rooms", &sc[19][0], 1);
73 snprintf(sc[67], sizeof sc[67], "%d", (boolprompt("Allow anonymous guest logins", atoi(&sc[67][0]))));
74 snprintf(sc[4], sizeof sc[4], "%d",
75 (boolprompt("Automatically give room admin privs to a user who creates a private room", atoi(&sc[4][0]))));
76 snprintf(sc[8], sizeof sc[8], "%d", (boolprompt("Automatically move problem user messages to twit room", atoi(&sc[8][0]))));
77 strprompt("Name of twit room", &sc[9][0], ROOMNAMELEN);
78 snprintf(sc[11], sizeof sc[11], "%d",
79 (boolprompt("Restrict Internet mail to only those with that privilege", atoi(&sc[11][0]))));
80 snprintf(sc[26], sizeof sc[26], "%d", (boolprompt("Allow admins to Zap (forget) rooms", atoi(&sc[26][0]))));
82 if (!IsEmptyStr(&sc[18][0])) {
88 logpages = boolprompt("Log all instant messages", logpages);
90 strprompt("Name of logging room", &sc[18][0], ROOMNAMELEN);
97 strprompt("Server connection idle timeout (in seconds)", &sc[5][0], 4);
98 strprompt("Maximum concurrent sessions", &sc[14][0], 4);
99 strprompt("Maximum message length", &sc[20][0], 20);
100 strprompt("Minimum number of worker threads", &sc[21][0], 3);
101 strprompt("Maximum number of worker threads", &sc[22][0], 3);
102 snprintf(sc[43], sizeof sc[43], "%d", (boolprompt("Automatically delete committed database logs", atoi(&sc[43][0]))));
103 strprompt("Server IP address (* for 'any')", &sc[37][0], 15);
104 strprompt("POP3 server port (-1 to disable)", &sc[23][0], 5);
105 strprompt("POP3S server port (-1 to disable)", &sc[40][0], 5);
106 strprompt("IMAP server port (-1 to disable)", &sc[27][0], 5);
107 strprompt("IMAPS server port (-1 to disable)", &sc[39][0], 5);
108 strprompt("SMTP MTA server port (-1 to disable)", &sc[24][0], 5);
109 strprompt("SMTP MSA server port (-1 to disable)", &sc[38][0], 5);
110 strprompt("SMTPS server port (-1 to disable)", &sc[41][0], 5);
111 strprompt("NNTP server port (-1 to disable)", &sc[70][0], 5);
112 strprompt("NNTPS server port (-1 to disable)", &sc[71][0], 5);
113 strprompt("Postfix TCP Dictionary Port server port (-1 to disable)", &sc[50][0], 5);
114 strprompt("ManageSieve server port (-1 to disable)", &sc[51][0], 5);
115 strprompt("XMPP (Jabber) client to server port (-1 to disable)", &sc[62][0], 5);
116 // strprompt("XMPP (Jabber) server to server port (-1 to disable)", &sc[63][0], 5); This is just a placeholder.
118 // This logic flips the question around, because it's one of those situations where 0=yes and 1=no
121 a = boolprompt("Correct forged From: lines during authenticated SMTP", a);
123 snprintf(sc[25], sizeof sc[25], "%d", a);
125 snprintf(sc[66], sizeof sc[66], "%d", (boolprompt("Flag messages as spam instead of rejecting", atoi(&sc[66][0]))));
127 // This logic flips the question around, because it's one of those situations where 0=yes and 1=no
130 a = boolprompt("Force IMAP posts in public rooms to be from the user who submitted them", a);
132 snprintf(sc[61], sizeof sc[61], "%d", a);
134 snprintf(sc[45], sizeof sc[45], "%d",
135 (boolprompt("Allow unauthenticated SMTP clients to spoof my domains", atoi(&sc[45][0]))));
136 snprintf(sc[57], sizeof sc[57], "%d",
137 (boolprompt("Perform RBL checks at greeting instead of after RCPT", atoi(&sc[57][0]))));
140 if (ipc->ServInfo.supports_ldap) {
141 a = strlen(&sc[32][0]);
142 a = (a ? 1 : 0); // Set only to 1 or 0
143 a = boolprompt("Do you want to configure LDAP authentication?", a);
145 strprompt("Host name of LDAP server", &sc[32][0], 127);
146 strprompt("Port number of LDAP service", &sc[33][0], 5);
147 strprompt("Base DN", &sc[34][0], 255);
148 strprompt("Bind DN (or blank for anonymous bind)", &sc[35][0], 255);
149 strprompt("Password for bind DN (or blank for anonymous bind)", &sc[36][0], 255);
152 strcpy(&sc[32][0], "");
157 strprompt("Default user purge time (days)", &sc[16][0], 5);
158 strprompt("Default room purge time (days)", &sc[17][0], 5);
160 // Angels and demons dancing in my head...
162 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_mode);
163 strprompt("System default message expire policy (? for list)", buf, 1);
166 "1. Never automatically expire messages\n"
167 "2. Expire by message count\n" "3. Expire by message age\n");
169 } while ((buf[0] < '1') || (buf[0] > '3'));
170 site_expirepolicy->expire_mode = buf[0] - '0';
172 // ...lunatics and monsters underneath my bed
173 if (site_expirepolicy->expire_mode == 2) {
174 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_value);
175 strprompt("Keep how many messages online?", buf, 10);
176 site_expirepolicy->expire_value = atol(buf);
178 if (site_expirepolicy->expire_mode == 3) {
179 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_value);
180 strprompt("Keep messages for how many days?", buf, 10);
181 site_expirepolicy->expire_value = atol(buf);
184 // Media messiahs preying on my fears...
186 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_mode);
187 strprompt("Mailbox default message expire policy (? for list)", buf, 1);
190 "0. Go with the system default\n"
191 "1. Never automatically expire messages\n"
192 "2. Expire by message count\n" "3. Expire by message age\n");
194 } while ((buf[0] < '0') || (buf[0] > '3'));
195 mbx_expirepolicy->expire_mode = buf[0] - '0';
197 // ...Pop culture prophets playing in my ears
198 if (mbx_expirepolicy->expire_mode == 2) {
199 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_value);
200 strprompt("Keep how many messages online?", buf, 10);
201 mbx_expirepolicy->expire_value = atol(buf);
203 if (mbx_expirepolicy->expire_mode == 3) {
204 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_value);
205 strprompt("Keep messages for how many days?", buf, 10);
206 mbx_expirepolicy->expire_value = atol(buf);
209 strprompt("How often to run network jobs (in seconds)", &sc[28][0], 5);
210 strprompt("Default frequency to run POP3 collection (in seconds)", &sc[64][0], 5);
211 strprompt("Fastest frequency to run POP3 collection (in seconds)", &sc[65][0], 5);
212 strprompt("Hour to run purges (0-23)", &sc[31][0], 2);
213 snprintf(sc[42], sizeof sc[42], "%d",
214 (boolprompt("Enable full text search index (warning: resource intensive)", atoi(&sc[42][0]))));
215 snprintf(sc[46], sizeof sc[46], "%d", (boolprompt("Perform journaling of email messages", atoi(&sc[46][0]))));
216 snprintf(sc[47], sizeof sc[47], "%d", (boolprompt("Perform journaling of non-email messages", atoi(&sc[47][0]))));
217 if ((atoi(&sc[46][0])) || (atoi(&sc[47][0]))) {
218 strprompt("Email destination of journalized messages", &sc[48][0], 127);
227 // External pager stuff
229 if (strlen(sc[60]) > 0) {
232 yes_pager = boolprompt("Configure an external pager tool", yes_pager);
234 strprompt("External pager tool", &sc[60][0], 255);
241 scr_printf("Save this configuration? ");
244 for (a = 0; a < NUM_CONFIGS; a++) {
245 r += 1 + strlen(sc[a]);
247 resp = (char *) calloc(1, r);
249 scr_printf("Can't save config - out of memory!\n");
252 for (a = 0; a < NUM_CONFIGS; a++) {
256 r = CtdlIPCSetSystemConfig(ipc, resp, buf);
258 scr_printf("%s\n", buf);
262 r = CtdlIPCSetMessageExpirationPolicy(ipc, 2, site_expirepolicy, buf);
264 scr_printf("%s\n", buf);
267 r = CtdlIPCSetMessageExpirationPolicy(ipc, 3, mbx_expirepolicy, buf);
269 scr_printf("%s\n", buf);
273 if (site_expirepolicy)
274 free(site_expirepolicy);
275 if (mbx_expirepolicy)
276 free(mbx_expirepolicy);
280 // support function for do_internet_configuration()
281 void get_inet_rec_type(CtdlIPC * ipc, char *buf) {
284 keyopt(" <1> localhost (Alias for this computer)\n");
285 keyopt(" <2> smart host (Forward all outbound mail to this host)\n");
286 keyopt(" <3> fallback host (Send mail to this host only if direct delivery fails)\n");
287 keyopt(" <4> SpamAssassin (Address of SpamAssassin server)\n");
288 keyopt(" <5> RBL (domain suffix of spam hunting RBL)\n");
289 keyopt(" <6> masq domains (Domains as which users are allowed to masquerade)\n");
290 keyopt(" <7> ClamAV (Address of ClamAV clamd server)\n");
291 sel = intprompt("Which one", 1, 1, 8);
294 strcpy(buf, "localhost");
297 strcpy(buf, "smarthost");
300 strcpy(buf, "fallbackhost");
303 strcpy(buf, "spamassassin");
309 strcpy(buf, "masqdomain");
312 strcpy(buf, "clamav");
318 // Internet mail configuration
319 void do_internet_configuration(CtdlIPC * ipc) {
330 r = CtdlIPCGetSystemConfigByType(ipc, INTERNETCFG, &resp, buf);
332 while (!IsEmptyStr(resp)) {
333 extract_token(buf, resp, 0, '\n', sizeof buf);
334 remove_token(resp, 0, '\n');
336 // "directory" is no longer used. replace it with "localhost"
337 char *d = strstr(buf, "|directory");
339 strcpy(d, "|localhost");
344 recs = malloc(sizeof(char *));
346 recs = realloc(recs, (sizeof(char *)) * num_recs);
347 recs[num_recs - 1] = malloc(strlen(buf) + 1);
348 strcpy(recs[num_recs - 1], buf);
358 scr_printf("### Host or domain Record type \n");
360 scr_printf("--- -------------------------------------------------- --------------------\n");
361 for (i = 0; i < num_recs; ++i) {
363 scr_printf("%3d ", i + 1);
364 extract_token(buf, recs[i], 0, '|', sizeof buf);
366 scr_printf("%-50s ", buf);
367 extract_token(buf, recs[i], 1, '|', sizeof buf);
368 color(BRIGHT_MAGENTA);
369 scr_printf("%-20s\n", buf);
373 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
376 newprompt("Enter host name: ", buf, 50);
378 if (!IsEmptyStr(buf)) {
381 recs = malloc(sizeof(char *));
384 recs = realloc(recs, (sizeof(char *)) * num_recs);
387 get_inet_rec_type(ipc, &buf[strlen(buf)]);
388 recs[num_recs - 1] = strdup(buf);
393 i = intprompt("Delete which one", 1, 1, num_recs) - 1;
396 for (j = i; j < num_recs; ++j) {
397 recs[j] = recs[j + 1];
403 for (i = 0; i < num_recs; i++) {
404 r += 1 + strlen(recs[i]);
406 resp = (char *) calloc(1, r);
408 scr_printf("Can't save config - out of memory!\n");
412 for (i = 0; i < num_recs; i++) {
413 strcat(resp, recs[i]);
416 r = CtdlIPCSetSystemConfigByType(ipc, INTERNETCFG, resp, buf);
418 scr_printf("%s\n", buf);
421 scr_printf("Wrote %d records.\n", num_recs);
427 quitting = !modified || boolprompt("Quit without saving", 0);
435 for (i = 0; i < num_recs; ++i)
442 // Edit network configuration for room sharing, mailing lists, etc.
443 void network_config_management(CtdlIPC * ipc, char *entrytype, char *comment) {
444 char filename[PATH_MAX];
445 char changefile[PATH_MAX];
455 char *listing = NULL;
458 if (IsEmptyStr(editor_path)) {
459 scr_printf("You must have an external editor configured in order to use this function.\n");
463 CtdlMakeTempFileName(filename, sizeof filename);
464 CtdlMakeTempFileName(changefile, sizeof changefile);
466 tempfp = fopen(filename, "w");
467 if (tempfp == NULL) {
468 scr_printf("Cannot open %s: %s\n", filename, strerror(errno));
472 fprintf(tempfp, "# Configuration for room: %s\n", room_name);
473 fprintf(tempfp, "# %s\n", comment);
474 fprintf(tempfp, "# Specify one per line.\n" "\n\n");
476 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
478 while (listing && !IsEmptyStr(listing)) {
479 extract_token(buf, listing, 0, '\n', sizeof buf);
480 remove_token(listing, 0, '\n');
481 extract_token(instr, buf, 0, '|', sizeof instr);
482 if (!strcasecmp(instr, entrytype)) {
483 tokens = num_tokens(buf, '|');
484 for (i = 1; i < tokens; ++i) {
485 extract_token(addr, buf, i, '|', sizeof addr);
486 fprintf(tempfp, "%s", addr);
487 if (i < (tokens - 1)) {
488 fprintf(tempfp, "|");
491 fprintf(tempfp, "\n");
501 e_ex_code = 1; // start with a failed exit code
502 stty_ctdl(SB_RESTORE);
504 cksum = file_checksum(filename);
505 if (editor_pid == 0) {
506 chmod(filename, 0600);
507 putenv("WINDOW_TITLE=Network configuration");
508 execlp(editor_path, editor_path, filename, NULL);
511 if (editor_pid > 0) {
514 b = ka_wait(&e_ex_code);
515 } while ((b != editor_pid) && (b >= 0));
520 if (file_checksum(filename) == cksum) {
521 scr_printf("*** No changes to save.\n");
525 if (e_ex_code == 0) { // Save changes
526 changefp = fopen(changefile, "w");
528 // Load all netconfig entries that are *not* of the type we are editing
529 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
531 while (listing && !IsEmptyStr(listing)) {
532 extract_token(buf, listing, 0, '\n', sizeof buf);
533 remove_token(listing, 0, '\n');
534 extract_token(instr, buf, 0, '|', sizeof instr);
535 if (strcasecmp(instr, entrytype)) {
536 fprintf(changefp, "%s\n", buf);
545 // ...and merge that with the data we just edited
546 tempfp = fopen(filename, "r");
547 while (fgets(buf, sizeof buf, tempfp) != NULL) {
548 for (i = 0; i < strlen(buf); ++i) {
553 if (!IsEmptyStr(buf)) {
554 fprintf(changefp, "%s|%s\n", entrytype, buf);
560 // now write it to the server...
561 changefp = fopen(changefile, "r");
562 if (changefp != NULL) {
563 listing = load_message_from_file(changefp);
565 r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
573 unlink(filename); // Delete the temporary files
578 // POP3 aggregation client configuration
579 void do_pop3client_configuration(CtdlIPC * ipc) {
587 char *listing = NULL;
588 char *other_listing = NULL;
592 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
594 while (listing && !IsEmptyStr(listing)) {
595 extract_token(buf, listing, 0, '\n', sizeof buf);
596 remove_token(listing, 0, '\n');
597 extract_token(instr, buf, 0, '|', sizeof instr);
598 if (!strcasecmp(instr, "pop3client")) {
602 recs = malloc(sizeof(char *));
604 recs = realloc(recs, (sizeof(char *)) * num_recs);
605 recs[num_recs - 1] = malloc(SIZ);
606 strcpy(recs[num_recs - 1], buf);
619 scr_printf("### " " Remote POP3 host " " User name " "Keep on server? " "\n");
621 scr_printf("--- " "---------------------------- " "---------------------------- " "--------------- " "\n");
622 for (i = 0; i < num_recs; ++i) {
624 scr_printf("%3d ", i + 1);
626 extract_token(buf, recs[i], 1, '|', sizeof buf);
628 scr_printf("%-28s ", buf);
630 extract_token(buf, recs[i], 2, '|', sizeof buf);
631 color(BRIGHT_MAGENTA);
632 scr_printf("%-28s ", buf);
635 scr_printf("%-15s\n", (extract_int(recs[i], 4) ? "Yes" : "No"));
639 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
644 recs = malloc(sizeof(char *));
647 recs = realloc(recs, (sizeof(char *)) * num_recs);
649 strcpy(buf, "pop3client|");
650 newprompt("Enter host name: ", &buf[strlen(buf)], 28);
652 newprompt("Enter user name: ", &buf[strlen(buf)], 28);
654 newprompt("Enter password : ", &buf[strlen(buf)], 16);
656 scr_printf("Keep messages on server instead of deleting them? ");
657 sprintf(&buf[strlen(buf)], "%d", yesno());
659 recs[num_recs - 1] = strdup(buf);
663 i = intprompt("Delete which one", 1, 1, num_recs) - 1;
666 for (j = i; j < num_recs; ++j)
667 recs[j] = recs[j + 1];
672 for (i = 0; i < num_recs; ++i) {
673 r += 1 + strlen(recs[i]);
675 listing = (char *) calloc(1, r);
677 scr_printf("Can't save config - out of memory!\n");
681 for (i = 0; i < num_recs; ++i) {
682 strcat(listing, recs[i]);
683 strcat(listing, "\n");
686 // Retrieve all the *other* records for merging
687 r = CtdlIPCGetRoomNetworkConfig(ipc, &other_listing, buf);
689 for (i = 0; i < num_tokens(other_listing, '\n'); ++i) {
690 extract_token(buf, other_listing, i, '\n', sizeof buf);
691 if (strncasecmp(buf, "pop3client|", 11)) {
692 listing = realloc(listing, strlen(listing) + strlen(buf) + 10);
693 strcat(listing, buf);
694 strcat(listing, "\n");
699 r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
704 scr_printf("%s\n", buf);
707 scr_printf("Wrote %d records.\n", num_recs);
713 quitting = !modified || boolprompt("Quit without saving", 0);
721 for (i = 0; i < num_recs; ++i) {
729 // RSS feed retrieval client configuration
730 void do_rssclient_configuration(CtdlIPC * ipc) {
738 char *listing = NULL;
739 char *other_listing = NULL;
743 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
745 while (listing && !IsEmptyStr(listing)) {
746 extract_token(buf, listing, 0, '\n', sizeof buf);
747 remove_token(listing, 0, '\n');
748 extract_token(instr, buf, 0, '|', sizeof instr);
749 if (!strcasecmp(instr, "rssclient")) {
753 recs = malloc(sizeof(char *));
755 recs = realloc(recs, (sizeof(char *)) * num_recs);
756 recs[num_recs - 1] = malloc(SIZ);
757 strcpy(recs[num_recs - 1], buf);
770 scr_printf("### Feed URL\n");
772 scr_printf("--- " "---------------------------------------------------------------------------" "\n");
774 for (i = 0; i < num_recs; ++i) {
776 scr_printf("%3d ", i + 1);
778 extract_token(buf, recs[i], 1, '|', sizeof buf);
780 scr_printf("%-75s\n", buf);
785 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
790 recs = malloc(sizeof(char *));
793 recs = realloc(recs, (sizeof(char *)) * num_recs);
795 strcpy(buf, "rssclient|");
796 newprompt("Enter feed URL: ", &buf[strlen(buf)], 75);
798 recs[num_recs - 1] = strdup(buf);
802 i = intprompt("Delete which one", 1, 1, num_recs) - 1;
805 for (j = i; j < num_recs; ++j)
806 recs[j] = recs[j + 1];
811 for (i = 0; i < num_recs; ++i) {
812 r += 1 + strlen(recs[i]);
814 listing = (char *) calloc(1, r);
816 scr_printf("Can't save config - out of memory!\n");
820 for (i = 0; i < num_recs; ++i) {
821 strcat(listing, recs[i]);
822 strcat(listing, "\n");
825 // Retrieve all the *other* records for merging
826 r = CtdlIPCGetRoomNetworkConfig(ipc, &other_listing, buf);
828 for (i = 0; i < num_tokens(other_listing, '\n'); ++i) {
829 extract_token(buf, other_listing, i, '\n', sizeof buf);
830 if (strncasecmp(buf, "rssclient|", 10)) {
831 listing = realloc(listing, strlen(listing) + strlen(buf) + 10);
832 strcat(listing, buf);
833 strcat(listing, "\n");
838 r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
843 scr_printf("%s\n", buf);
846 scr_printf("Wrote %d records.\n", num_recs);
852 quitting = !modified || boolprompt("Quit without saving", 0);
860 for (i = 0; i < num_recs; ++i)