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 is 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 snprintf(sc[72], sizeof sc[72], "%d", (boolprompt("Advertise STARTTLS on the SMTP port", atoi(&sc[72][0]))));
112 strprompt("NNTP server port (-1 to disable)", &sc[70][0], 5);
113 strprompt("NNTPS server port (-1 to disable)", &sc[71][0], 5);
114 strprompt("Postfix TCP Dictionary Port server port (-1 to disable)", &sc[50][0], 5);
115 strprompt("ManageSieve server port (-1 to disable)", &sc[51][0], 5);
116 strprompt("XMPP (Jabber) client to server port (-1 to disable)", &sc[62][0], 5);
117 // strprompt("XMPP (Jabber) server to server port (-1 to disable)", &sc[63][0], 5); This is just a placeholder.
119 // This logic flips the question around, because it's one of those situations where 0=yes and 1=no
122 a = boolprompt("Correct forged From: lines during authenticated SMTP", a);
124 snprintf(sc[25], sizeof sc[25], "%d", a);
126 snprintf(sc[66], sizeof sc[66], "%d", (boolprompt("Flag messages as spam instead of rejecting", atoi(&sc[66][0]))));
128 // This logic flips the question around, because it's one of those situations where 0=yes and 1=no
131 a = boolprompt("Force IMAP posts in public rooms to be from the user who submitted them", a);
133 snprintf(sc[61], sizeof sc[61], "%d", a);
135 snprintf(sc[45], sizeof sc[45], "%d",
136 (boolprompt("Allow unauthenticated SMTP clients to spoof my domains", atoi(&sc[45][0]))));
137 snprintf(sc[57], sizeof sc[57], "%d",
138 (boolprompt("Perform RBL checks at greeting instead of after RCPT", atoi(&sc[57][0]))));
141 if (ipc->ServInfo.supports_ldap) {
142 a = strlen(&sc[32][0]);
143 a = (a ? 1 : 0); // Set only to 1 or 0
144 a = boolprompt("Do you want to configure LDAP authentication?", a);
146 strprompt("Host name of LDAP server", &sc[32][0], 127);
147 strprompt("Port number of LDAP service", &sc[33][0], 5);
148 strprompt("Base DN", &sc[34][0], 255);
149 strprompt("Bind DN (or blank for anonymous bind)", &sc[35][0], 255);
150 strprompt("Password for bind DN (or blank for anonymous bind)", &sc[36][0], 255);
153 strcpy(&sc[32][0], "");
158 strprompt("Default user purge time (days)", &sc[16][0], 5);
159 strprompt("Default room purge time (days)", &sc[17][0], 5);
161 // Angels and demons dancing in my head...
163 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_mode);
164 strprompt("System default message expire policy (? for list)", buf, 1);
167 "1. Never automatically expire messages\n"
168 "2. Expire by message count\n" "3. Expire by message age\n");
170 } while ((buf[0] < '1') || (buf[0] > '3'));
171 site_expirepolicy->expire_mode = buf[0] - '0';
173 // ...lunatics and monsters underneath my bed
174 if (site_expirepolicy->expire_mode == 2) {
175 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_value);
176 strprompt("Keep how many messages online?", buf, 10);
177 site_expirepolicy->expire_value = atol(buf);
179 if (site_expirepolicy->expire_mode == 3) {
180 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_value);
181 strprompt("Keep messages for how many days?", buf, 10);
182 site_expirepolicy->expire_value = atol(buf);
185 // Media messiahs preying on my fears...
187 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_mode);
188 strprompt("Mailbox default message expire policy (? for list)", buf, 1);
191 "0. Go with the system default\n"
192 "1. Never automatically expire messages\n"
193 "2. Expire by message count\n" "3. Expire by message age\n");
195 } while ((buf[0] < '0') || (buf[0] > '3'));
196 mbx_expirepolicy->expire_mode = buf[0] - '0';
198 // ...Pop culture prophets playing in my ears
199 if (mbx_expirepolicy->expire_mode == 2) {
200 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_value);
201 strprompt("Keep how many messages online?", buf, 10);
202 mbx_expirepolicy->expire_value = atol(buf);
204 if (mbx_expirepolicy->expire_mode == 3) {
205 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_value);
206 strprompt("Keep messages for how many days?", buf, 10);
207 mbx_expirepolicy->expire_value = atol(buf);
210 strprompt("How often to run network jobs (in seconds)", &sc[28][0], 5);
211 strprompt("Default frequency to run POP3 collection (in seconds)", &sc[64][0], 5);
212 strprompt("Fastest frequency to run POP3 collection (in seconds)", &sc[65][0], 5);
213 strprompt("Hour to run purges (0-23)", &sc[31][0], 2);
214 snprintf(sc[42], sizeof sc[42], "%d",
215 (boolprompt("Enable full text search index (warning: resource intensive)", atoi(&sc[42][0]))));
216 snprintf(sc[46], sizeof sc[46], "%d", (boolprompt("Perform journaling of email messages", atoi(&sc[46][0]))));
217 snprintf(sc[47], sizeof sc[47], "%d", (boolprompt("Perform journaling of non-email messages", atoi(&sc[47][0]))));
218 if ((atoi(&sc[46][0])) || (atoi(&sc[47][0]))) {
219 strprompt("Email destination of journalized messages", &sc[48][0], 127);
228 // External pager stuff
230 if (strlen(sc[60]) > 0) {
233 yes_pager = boolprompt("Configure an external pager tool", yes_pager);
235 strprompt("External pager tool", &sc[60][0], 255);
242 scr_printf("Save this configuration? ");
245 for (a = 0; a < NUM_CONFIGS; a++) {
246 r += 1 + strlen(sc[a]);
248 resp = (char *) calloc(1, r);
250 scr_printf("Can't save config - out of memory!\n");
253 for (a = 0; a < NUM_CONFIGS; a++) {
257 r = CtdlIPCSetSystemConfig(ipc, resp, buf);
259 scr_printf("%s\n", buf);
263 r = CtdlIPCSetMessageExpirationPolicy(ipc, 2, site_expirepolicy, buf);
265 scr_printf("%s\n", buf);
268 r = CtdlIPCSetMessageExpirationPolicy(ipc, 3, mbx_expirepolicy, buf);
270 scr_printf("%s\n", buf);
274 if (site_expirepolicy)
275 free(site_expirepolicy);
276 if (mbx_expirepolicy)
277 free(mbx_expirepolicy);
281 // support function for do_internet_configuration()
282 void get_inet_rec_type(CtdlIPC * ipc, char *buf) {
285 keyopt(" <1> localhost (Alias for this computer)\n");
286 keyopt(" <2> smart host (Forward all outbound mail to this host)\n");
287 keyopt(" <3> fallback host (Send mail to this host only if direct delivery fails)\n");
288 keyopt(" <4> SpamAssassin (Address of SpamAssassin server)\n");
289 keyopt(" <5> RBL (domain suffix of spam hunting RBL)\n");
290 keyopt(" <6> masq domains (Domains as which users are allowed to masquerade)\n");
291 keyopt(" <7> ClamAV (Address of ClamAV clamd server)\n");
292 sel = intprompt("Which one", 1, 1, 8);
295 strcpy(buf, "localhost");
298 strcpy(buf, "smarthost");
301 strcpy(buf, "fallbackhost");
304 strcpy(buf, "spamassassin");
310 strcpy(buf, "masqdomain");
313 strcpy(buf, "clamav");
319 // Internet mail configuration
320 void do_internet_configuration(CtdlIPC * ipc) {
331 r = CtdlIPCGetSystemConfigByType(ipc, INTERNETCFG, &resp, buf);
333 while (!IsEmptyStr(resp)) {
334 extract_token(buf, resp, 0, '\n', sizeof buf);
335 remove_token(resp, 0, '\n');
337 // "directory" is no longer used. replace it with "localhost"
338 char *d = strstr(buf, "|directory");
340 strcpy(d, "|localhost");
345 recs = malloc(sizeof(char *));
347 recs = realloc(recs, (sizeof(char *)) * num_recs);
348 recs[num_recs - 1] = malloc(strlen(buf) + 1);
349 strcpy(recs[num_recs - 1], buf);
359 scr_printf("### Host or domain Record type \n");
361 scr_printf("--- -------------------------------------------------- --------------------\n");
362 for (i = 0; i < num_recs; ++i) {
364 scr_printf("%3d ", i + 1);
365 extract_token(buf, recs[i], 0, '|', sizeof buf);
367 scr_printf("%-50s ", buf);
368 extract_token(buf, recs[i], 1, '|', sizeof buf);
369 color(BRIGHT_MAGENTA);
370 scr_printf("%-20s\n", buf);
374 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
377 newprompt("Enter host name: ", buf, 50);
379 if (!IsEmptyStr(buf)) {
382 recs = malloc(sizeof(char *));
385 recs = realloc(recs, (sizeof(char *)) * num_recs);
388 get_inet_rec_type(ipc, &buf[strlen(buf)]);
389 recs[num_recs - 1] = strdup(buf);
394 i = intprompt("Delete which one", 1, 1, num_recs) - 1;
397 for (j = i; j < num_recs; ++j) {
398 recs[j] = recs[j + 1];
404 for (i = 0; i < num_recs; i++) {
405 r += 1 + strlen(recs[i]);
407 resp = (char *) calloc(1, r);
409 scr_printf("Can't save config - out of memory!\n");
413 for (i = 0; i < num_recs; i++) {
414 strcat(resp, recs[i]);
417 r = CtdlIPCSetSystemConfigByType(ipc, INTERNETCFG, resp, buf);
419 scr_printf("%s\n", buf);
422 scr_printf("Wrote %d records.\n", num_recs);
428 quitting = !modified || boolprompt("Quit without saving", 0);
436 for (i = 0; i < num_recs; ++i)
443 // Edit network configuration for room sharing, mailing lists, etc.
444 void network_config_management(CtdlIPC * ipc, char *entrytype, char *comment) {
445 char filename[PATH_MAX];
446 char changefile[PATH_MAX];
456 char *listing = NULL;
459 if (IsEmptyStr(editor_path)) {
460 scr_printf("You must have an external editor configured in order to use this function.\n");
464 CtdlMakeTempFileName(filename, sizeof filename);
465 CtdlMakeTempFileName(changefile, sizeof changefile);
467 tempfp = fopen(filename, "w");
468 if (tempfp == NULL) {
469 scr_printf("Cannot open %s: %s\n", filename, strerror(errno));
473 fprintf(tempfp, "# Configuration for room: %s\n", room_name);
474 fprintf(tempfp, "# %s\n", comment);
475 fprintf(tempfp, "# Specify one per line.\n" "\n\n");
477 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
479 while (listing && !IsEmptyStr(listing)) {
480 extract_token(buf, listing, 0, '\n', sizeof buf);
481 remove_token(listing, 0, '\n');
482 extract_token(instr, buf, 0, '|', sizeof instr);
483 if (!strcasecmp(instr, entrytype)) {
484 tokens = num_tokens(buf, '|');
485 for (i = 1; i < tokens; ++i) {
486 extract_token(addr, buf, i, '|', sizeof addr);
487 fprintf(tempfp, "%s", addr);
488 if (i < (tokens - 1)) {
489 fprintf(tempfp, "|");
492 fprintf(tempfp, "\n");
502 e_ex_code = 1; // start with a failed exit code
503 stty_ctdl(SB_RESTORE);
505 cksum = file_checksum(filename);
506 if (editor_pid == 0) {
507 chmod(filename, 0600);
508 putenv("WINDOW_TITLE=Network configuration");
509 execlp(editor_path, editor_path, filename, NULL);
512 if (editor_pid > 0) {
515 b = ka_wait(&e_ex_code);
516 } while ((b != editor_pid) && (b >= 0));
521 if (file_checksum(filename) == cksum) {
522 scr_printf("*** No changes to save.\n");
526 if (e_ex_code == 0) { // Save changes
527 changefp = fopen(changefile, "w");
529 // Load all netconfig entries that are *not* of the type we are editing
530 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
532 while (listing && !IsEmptyStr(listing)) {
533 extract_token(buf, listing, 0, '\n', sizeof buf);
534 remove_token(listing, 0, '\n');
535 extract_token(instr, buf, 0, '|', sizeof instr);
536 if (strcasecmp(instr, entrytype)) {
537 fprintf(changefp, "%s\n", buf);
546 // ...and merge that with the data we just edited
547 tempfp = fopen(filename, "r");
548 while (fgets(buf, sizeof buf, tempfp) != NULL) {
549 for (i = 0; i < strlen(buf); ++i) {
554 if (!IsEmptyStr(buf)) {
555 fprintf(changefp, "%s|%s\n", entrytype, buf);
561 // now write it to the server...
562 changefp = fopen(changefile, "r");
563 if (changefp != NULL) {
564 listing = load_message_from_file(changefp);
566 r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
574 unlink(filename); // Delete the temporary files
579 // POP3 aggregation client configuration
580 void do_pop3client_configuration(CtdlIPC * ipc) {
588 char *listing = NULL;
589 char *other_listing = NULL;
593 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
595 while (listing && !IsEmptyStr(listing)) {
596 extract_token(buf, listing, 0, '\n', sizeof buf);
597 remove_token(listing, 0, '\n');
598 extract_token(instr, buf, 0, '|', sizeof instr);
599 if (!strcasecmp(instr, "pop3client")) {
603 recs = malloc(sizeof(char *));
605 recs = realloc(recs, (sizeof(char *)) * num_recs);
606 recs[num_recs - 1] = malloc(SIZ);
607 strcpy(recs[num_recs - 1], buf);
620 scr_printf("### " " Remote POP3 host " " User name " "Keep on server? " "\n");
622 scr_printf("--- " "---------------------------- " "---------------------------- " "--------------- " "\n");
623 for (i = 0; i < num_recs; ++i) {
625 scr_printf("%3d ", i + 1);
627 extract_token(buf, recs[i], 1, '|', sizeof buf);
629 scr_printf("%-28s ", buf);
631 extract_token(buf, recs[i], 2, '|', sizeof buf);
632 color(BRIGHT_MAGENTA);
633 scr_printf("%-28s ", buf);
636 scr_printf("%-15s\n", (extract_int(recs[i], 4) ? "Yes" : "No"));
640 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
645 recs = malloc(sizeof(char *));
648 recs = realloc(recs, (sizeof(char *)) * num_recs);
650 strcpy(buf, "pop3client|");
651 newprompt("Enter host name: ", &buf[strlen(buf)], 28);
653 newprompt("Enter user name: ", &buf[strlen(buf)], 28);
655 newprompt("Enter password : ", &buf[strlen(buf)], 16);
657 scr_printf("Keep messages on server instead of deleting them? ");
658 sprintf(&buf[strlen(buf)], "%d", yesno());
660 recs[num_recs - 1] = strdup(buf);
664 i = intprompt("Delete which one", 1, 1, num_recs) - 1;
667 for (j = i; j < num_recs; ++j)
668 recs[j] = recs[j + 1];
673 for (i = 0; i < num_recs; ++i) {
674 r += 1 + strlen(recs[i]);
676 listing = (char *) calloc(1, r);
678 scr_printf("Can't save config - out of memory!\n");
682 for (i = 0; i < num_recs; ++i) {
683 strcat(listing, recs[i]);
684 strcat(listing, "\n");
687 // Retrieve all the *other* records for merging
688 r = CtdlIPCGetRoomNetworkConfig(ipc, &other_listing, buf);
690 for (i = 0; i < num_tokens(other_listing, '\n'); ++i) {
691 extract_token(buf, other_listing, i, '\n', sizeof buf);
692 if (strncasecmp(buf, "pop3client|", 11)) {
693 listing = realloc(listing, strlen(listing) + strlen(buf) + 10);
694 strcat(listing, buf);
695 strcat(listing, "\n");
700 r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
705 scr_printf("%s\n", buf);
708 scr_printf("Wrote %d records.\n", num_recs);
714 quitting = !modified || boolprompt("Quit without saving", 0);
722 for (i = 0; i < num_recs; ++i) {
730 // RSS feed retrieval client configuration
731 void do_rssclient_configuration(CtdlIPC * ipc) {
739 char *listing = NULL;
740 char *other_listing = NULL;
744 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
746 while (listing && !IsEmptyStr(listing)) {
747 extract_token(buf, listing, 0, '\n', sizeof buf);
748 remove_token(listing, 0, '\n');
749 extract_token(instr, buf, 0, '|', sizeof instr);
750 if (!strcasecmp(instr, "rssclient")) {
754 recs = malloc(sizeof(char *));
756 recs = realloc(recs, (sizeof(char *)) * num_recs);
757 recs[num_recs - 1] = malloc(SIZ);
758 strcpy(recs[num_recs - 1], buf);
771 scr_printf("### Feed URL\n");
773 scr_printf("--- " "---------------------------------------------------------------------------" "\n");
775 for (i = 0; i < num_recs; ++i) {
777 scr_printf("%3d ", i + 1);
779 extract_token(buf, recs[i], 1, '|', sizeof buf);
781 scr_printf("%-75s\n", buf);
786 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
791 recs = malloc(sizeof(char *));
794 recs = realloc(recs, (sizeof(char *)) * num_recs);
796 strcpy(buf, "rssclient|");
797 newprompt("Enter feed URL: ", &buf[strlen(buf)], 75);
799 recs[num_recs - 1] = strdup(buf);
803 i = intprompt("Delete which one", 1, 1, num_recs) - 1;
806 for (j = i; j < num_recs; ++j)
807 recs[j] = recs[j + 1];
812 for (i = 0; i < num_recs; ++i) {
813 r += 1 + strlen(recs[i]);
815 listing = (char *) calloc(1, r);
817 scr_printf("Can't save config - out of memory!\n");
821 for (i = 0; i < num_recs; ++i) {
822 strcat(listing, recs[i]);
823 strcat(listing, "\n");
826 // Retrieve all the *other* records for merging
827 r = CtdlIPCGetRoomNetworkConfig(ipc, &other_listing, buf);
829 for (i = 0; i < num_tokens(other_listing, '\n'); ++i) {
830 extract_token(buf, other_listing, i, '\n', sizeof buf);
831 if (strncasecmp(buf, "rssclient|", 10)) {
832 listing = realloc(listing, strlen(listing) + strlen(buf) + 10);
833 strcat(listing, buf);
834 strcat(listing, "\n");
839 r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
844 scr_printf("%s\n", buf);
847 scr_printf("Wrote %d records.\n", num_recs);
853 quitting = !modified || boolprompt("Quit without saving", 0);
861 for (i = 0; i < num_recs; ++i)