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", (boolprompt("Automatically give room admin privs to a user who creates a private room", atoi(&sc[4][0]))));
75 snprintf(sc[8], sizeof sc[8], "%d", (boolprompt("Automatically move problem user messages to twit room", atoi(&sc[8][0]))));
76 strprompt("Name of twit room", &sc[9][0], ROOMNAMELEN);
77 snprintf(sc[11], sizeof sc[11], "%d", (boolprompt("Restrict Internet mail to only those with that privilege", atoi(&sc[11][0]))));
78 snprintf(sc[26], sizeof sc[26], "%d", (boolprompt("Allow admins to Zap (forget) rooms", atoi(&sc[26][0]))));
80 if (!IsEmptyStr(&sc[18][0])) {
86 logpages = boolprompt("Log all instant messages", logpages);
88 strprompt("Name of logging room", &sc[18][0], ROOMNAMELEN);
95 strprompt("Server connection idle timeout (in seconds)", &sc[5][0], 4);
96 strprompt("Maximum concurrent sessions", &sc[14][0], 4);
97 strprompt("Maximum message length", &sc[20][0], 20);
98 strprompt("Minimum number of worker threads", &sc[21][0], 3);
99 strprompt("Maximum number of worker threads", &sc[22][0], 3);
100 snprintf(sc[43], sizeof sc[43], "%d", (boolprompt("Automatically delete committed database logs", atoi(&sc[43][0]))));
101 strprompt("Server IP address (* for 'any')", &sc[37][0], 15);
102 strprompt("POP3 server port (-1 to disable)", &sc[23][0], 5);
103 strprompt("POP3S server port (-1 to disable)", &sc[40][0], 5);
104 strprompt("IMAP server port (-1 to disable)", &sc[27][0], 5);
105 strprompt("IMAPS server port (-1 to disable)", &sc[39][0], 5);
106 strprompt("SMTP MTA server port (-1 to disable)", &sc[24][0], 5);
107 strprompt("SMTP MSA server port (-1 to disable)", &sc[38][0], 5);
108 strprompt("SMTPS server port (-1 to disable)", &sc[41][0], 5);
109 strprompt("NNTP server port (-1 to disable)", &sc[70][0], 5);
110 strprompt("NNTPS server port (-1 to disable)", &sc[71][0], 5);
111 strprompt("Postfix TCP Dictionary Port server port (-1 to disable)", &sc[50][0], 5);
112 strprompt("ManageSieve server port (-1 to disable)", &sc[51][0], 5);
113 strprompt("XMPP (Jabber) client to server port (-1 to disable)", &sc[62][0], 5);
114 // strprompt("XMPP (Jabber) server to server port (-1 to disable)", &sc[63][0], 5); This is just a placeholder.
116 // This logic flips the question around, because it's one of those situations where 0=yes and 1=no
119 a = boolprompt("Correct forged From: lines during authenticated SMTP", a);
121 snprintf(sc[25], sizeof sc[25], "%d", a);
123 snprintf(sc[66], sizeof sc[66], "%d", (boolprompt("Flag messages as spam instead of rejecting", atoi(&sc[66][0]))));
125 // This logic flips the question around, because it's one of those situations where 0=yes and 1=no
128 a = boolprompt("Force IMAP posts in public rooms to be from the user who submitted them", a);
130 snprintf(sc[61], sizeof sc[61], "%d", a);
132 snprintf(sc[45], sizeof sc[45], "%d", (boolprompt("Allow unauthenticated SMTP clients to spoof my domains", atoi(&sc[45][0]))));
133 snprintf(sc[57], sizeof sc[57], "%d", (boolprompt("Perform RBL checks at greeting instead of after RCPT", atoi(&sc[57][0]))));
136 if (ipc->ServInfo.supports_ldap) {
137 a = strlen(&sc[32][0]);
138 a = (a ? 1 : 0); // Set only to 1 or 0
139 a = boolprompt("Do you want to configure LDAP authentication?", a);
141 strprompt("Host name of LDAP server", &sc[32][0], 127);
142 strprompt("Port number of LDAP service", &sc[33][0], 5);
143 strprompt("Base DN", &sc[34][0], 255);
144 strprompt("Bind DN (or blank for anonymous bind)", &sc[35][0], 255);
145 strprompt("Password for bind DN (or blank for anonymous bind)", &sc[36][0], 255);
148 strcpy(&sc[32][0], "");
153 strprompt("Default user purge time (days)", &sc[16][0], 5);
154 strprompt("Default room purge time (days)", &sc[17][0], 5);
156 // Angels and demons dancing in my head...
158 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_mode);
159 strprompt("System default message expire policy (? for list)", buf, 1);
162 "1. Never automatically expire messages\n"
163 "2. Expire by message count\n" "3. Expire by message age\n");
165 } while ((buf[0] < '1') || (buf[0] > '3'));
166 site_expirepolicy->expire_mode = buf[0] - '0';
168 // ...lunatics and monsters underneath my bed
169 if (site_expirepolicy->expire_mode == 2) {
170 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_value);
171 strprompt("Keep how many messages online?", buf, 10);
172 site_expirepolicy->expire_value = atol(buf);
174 if (site_expirepolicy->expire_mode == 3) {
175 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_value);
176 strprompt("Keep messages for how many days?", buf, 10);
177 site_expirepolicy->expire_value = atol(buf);
180 // Media messiahs preying on my fears...
182 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_mode);
183 strprompt("Mailbox default message expire policy (? for list)", buf, 1);
186 "0. Go with the system default\n"
187 "1. Never automatically expire messages\n"
188 "2. Expire by message count\n" "3. Expire by message age\n");
190 } while ((buf[0] < '0') || (buf[0] > '3'));
191 mbx_expirepolicy->expire_mode = buf[0] - '0';
193 // ...Pop culture prophets playing in my ears
194 if (mbx_expirepolicy->expire_mode == 2) {
195 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_value);
196 strprompt("Keep how many messages online?", buf, 10);
197 mbx_expirepolicy->expire_value = atol(buf);
199 if (mbx_expirepolicy->expire_mode == 3) {
200 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_value);
201 strprompt("Keep messages for how many days?", buf, 10);
202 mbx_expirepolicy->expire_value = atol(buf);
205 strprompt("How often to run network jobs (in seconds)", &sc[28][0], 5);
206 strprompt("Default frequency to run POP3 collection (in seconds)", &sc[64][0], 5);
207 strprompt("Fastest frequency to run POP3 collection (in seconds)", &sc[65][0], 5);
208 strprompt("Hour to run purges (0-23)", &sc[31][0], 2);
209 snprintf(sc[42], sizeof sc[42], "%d", (boolprompt("Enable full text search index (warning: resource intensive)", atoi(&sc[42][0]))));
210 snprintf(sc[46], sizeof sc[46], "%d", (boolprompt("Perform journaling of email messages", atoi(&sc[46][0]))));
211 snprintf(sc[47], sizeof sc[47], "%d", (boolprompt("Perform journaling of non-email messages", atoi(&sc[47][0]))));
212 if ((atoi(&sc[46][0])) || (atoi(&sc[47][0]))) {
213 strprompt("Email destination of journalized messages", &sc[48][0], 127);
222 // External pager stuff
224 if (strlen(sc[60]) > 0) {
227 yes_pager = boolprompt("Configure an external pager tool", yes_pager);
229 strprompt("External pager tool", &sc[60][0], 255);
236 scr_printf("Save this configuration? ");
239 for (a = 0; a < NUM_CONFIGS; a++) {
240 r += 1 + strlen(sc[a]);
242 resp = (char *) calloc(1, r);
244 scr_printf("Can't save config - out of memory!\n");
247 for (a = 0; a < NUM_CONFIGS; a++) {
251 r = CtdlIPCSetSystemConfig(ipc, resp, buf);
253 scr_printf("%s\n", buf);
257 r = CtdlIPCSetMessageExpirationPolicy(ipc, 2, site_expirepolicy, buf);
259 scr_printf("%s\n", buf);
262 r = CtdlIPCSetMessageExpirationPolicy(ipc, 3, mbx_expirepolicy, buf);
264 scr_printf("%s\n", buf);
268 if (site_expirepolicy)
269 free(site_expirepolicy);
270 if (mbx_expirepolicy)
271 free(mbx_expirepolicy);
275 // support function for do_internet_configuration()
276 void get_inet_rec_type(CtdlIPC * ipc, char *buf) {
279 keyopt(" <1> localhost (Alias for this computer)\n");
280 keyopt(" <2> smart host (Forward all outbound mail to this host)\n");
281 keyopt(" <3> fallback host (Send mail to this host only if direct delivery fails)\n");
282 keyopt(" <4> SpamAssassin (Address of SpamAssassin server)\n");
283 keyopt(" <5> RBL (domain suffix of spam hunting RBL)\n");
284 keyopt(" <6> masq domains (Domains as which users are allowed to masquerade)\n");
285 keyopt(" <7> ClamAV (Address of ClamAV clamd server)\n");
286 sel = intprompt("Which one", 1, 1, 8);
289 strcpy(buf, "localhost");
292 strcpy(buf, "smarthost");
295 strcpy(buf, "fallbackhost");
298 strcpy(buf, "spamassassin");
304 strcpy(buf, "masqdomain");
307 strcpy(buf, "clamav");
313 // Internet mail configuration
314 void do_internet_configuration(CtdlIPC * ipc) {
325 r = CtdlIPCGetSystemConfigByType(ipc, INTERNETCFG, &resp, buf);
327 while (!IsEmptyStr(resp)) {
328 extract_token(buf, resp, 0, '\n', sizeof buf);
329 remove_token(resp, 0, '\n');
331 // "directory" is no longer used. replace it with "localhost"
332 char *d = strstr(buf, "|directory");
334 strcpy(d, "|localhost");
339 recs = malloc(sizeof(char *));
341 recs = realloc(recs, (sizeof(char *)) * num_recs);
342 recs[num_recs - 1] = malloc(strlen(buf) + 1);
343 strcpy(recs[num_recs - 1], buf);
353 scr_printf("### Host or domain Record type \n");
355 scr_printf("--- -------------------------------------------------- --------------------\n");
356 for (i = 0; i < num_recs; ++i) {
358 scr_printf("%3d ", i + 1);
359 extract_token(buf, recs[i], 0, '|', sizeof buf);
361 scr_printf("%-50s ", buf);
362 extract_token(buf, recs[i], 1, '|', sizeof buf);
363 color(BRIGHT_MAGENTA);
364 scr_printf("%-20s\n", buf);
368 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
371 newprompt("Enter host name: ", buf, 50);
373 if (!IsEmptyStr(buf)) {
376 recs = malloc(sizeof(char *));
379 recs = realloc(recs, (sizeof(char *)) * num_recs);
382 get_inet_rec_type(ipc, &buf[strlen(buf)]);
383 recs[num_recs - 1] = strdup(buf);
388 i = intprompt("Delete which one", 1, 1, num_recs) - 1;
391 for (j = i; j < num_recs; ++j) {
392 recs[j] = recs[j + 1];
398 for (i = 0; i < num_recs; i++) {
399 r += 1 + strlen(recs[i]);
401 resp = (char *) calloc(1, r);
403 scr_printf("Can't save config - out of memory!\n");
407 for (i = 0; i < num_recs; i++) {
408 strcat(resp, recs[i]);
411 r = CtdlIPCSetSystemConfigByType(ipc, INTERNETCFG, resp, buf);
413 scr_printf("%s\n", buf);
416 scr_printf("Wrote %d records.\n", num_recs);
422 quitting = !modified || boolprompt("Quit without saving", 0);
430 for (i = 0; i < num_recs; ++i)
437 // Edit network configuration for room sharing, mailing lists, etc.
438 void network_config_management(CtdlIPC * ipc, char *entrytype, char *comment) {
439 char filename[PATH_MAX];
440 char changefile[PATH_MAX];
450 char *listing = NULL;
453 if (IsEmptyStr(editor_path)) {
454 scr_printf("You must have an external editor configured in order to use this function.\n");
458 CtdlMakeTempFileName(filename, sizeof filename);
459 CtdlMakeTempFileName(changefile, sizeof changefile);
461 tempfp = fopen(filename, "w");
462 if (tempfp == NULL) {
463 scr_printf("Cannot open %s: %s\n", filename, strerror(errno));
467 fprintf(tempfp, "# Configuration for room: %s\n", room_name);
468 fprintf(tempfp, "# %s\n", comment);
469 fprintf(tempfp, "# Specify one per line.\n" "\n\n");
471 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
473 while (listing && !IsEmptyStr(listing)) {
474 extract_token(buf, listing, 0, '\n', sizeof buf);
475 remove_token(listing, 0, '\n');
476 extract_token(instr, buf, 0, '|', sizeof instr);
477 if (!strcasecmp(instr, entrytype)) {
478 tokens = num_tokens(buf, '|');
479 for (i = 1; i < tokens; ++i) {
480 extract_token(addr, buf, i, '|', sizeof addr);
481 fprintf(tempfp, "%s", addr);
482 if (i < (tokens - 1)) {
483 fprintf(tempfp, "|");
486 fprintf(tempfp, "\n");
496 e_ex_code = 1; // start with a failed exit code
497 stty_ctdl(SB_RESTORE);
499 cksum = file_checksum(filename);
500 if (editor_pid == 0) {
501 chmod(filename, 0600);
502 putenv("WINDOW_TITLE=Network configuration");
503 execlp(editor_path, editor_path, filename, NULL);
506 if (editor_pid > 0) {
509 b = ka_wait(&e_ex_code);
510 } while ((b != editor_pid) && (b >= 0));
515 if (file_checksum(filename) == cksum) {
516 scr_printf("*** No changes to save.\n");
520 if (e_ex_code == 0) { // Save changes
521 changefp = fopen(changefile, "w");
523 // Load all netconfig entries that are *not* of the type we are editing
524 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
526 while (listing && !IsEmptyStr(listing)) {
527 extract_token(buf, listing, 0, '\n', sizeof buf);
528 remove_token(listing, 0, '\n');
529 extract_token(instr, buf, 0, '|', sizeof instr);
530 if (strcasecmp(instr, entrytype)) {
531 fprintf(changefp, "%s\n", buf);
540 // ...and merge that with the data we just edited
541 tempfp = fopen(filename, "r");
542 while (fgets(buf, sizeof buf, tempfp) != NULL) {
543 for (i = 0; i < strlen(buf); ++i) {
548 if (!IsEmptyStr(buf)) {
549 fprintf(changefp, "%s|%s\n", entrytype, buf);
555 // now write it to the server...
556 changefp = fopen(changefile, "r");
557 if (changefp != NULL) {
558 listing = load_message_from_file(changefp);
560 r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
568 unlink(filename); // Delete the temporary files
573 // POP3 aggregation client configuration
574 void do_pop3client_configuration(CtdlIPC * ipc) {
582 char *listing = NULL;
583 char *other_listing = NULL;
587 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
589 while (listing && !IsEmptyStr(listing)) {
590 extract_token(buf, listing, 0, '\n', sizeof buf);
591 remove_token(listing, 0, '\n');
592 extract_token(instr, buf, 0, '|', sizeof instr);
593 if (!strcasecmp(instr, "pop3client")) {
597 recs = malloc(sizeof(char *));
599 recs = realloc(recs, (sizeof(char *)) * num_recs);
600 recs[num_recs - 1] = malloc(SIZ);
601 strcpy(recs[num_recs - 1], buf);
614 scr_printf("### " " Remote POP3 host " " User name " "Keep on server? " "\n");
616 scr_printf("--- " "---------------------------- " "---------------------------- " "--------------- " "\n");
617 for (i = 0; i < num_recs; ++i) {
619 scr_printf("%3d ", i + 1);
621 extract_token(buf, recs[i], 1, '|', sizeof buf);
623 scr_printf("%-28s ", buf);
625 extract_token(buf, recs[i], 2, '|', sizeof buf);
626 color(BRIGHT_MAGENTA);
627 scr_printf("%-28s ", buf);
630 scr_printf("%-15s\n", (extract_int(recs[i], 4) ? "Yes" : "No"));
634 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
639 recs = malloc(sizeof(char *));
641 recs = realloc(recs, (sizeof(char *)) * num_recs);
643 strcpy(buf, "pop3client|");
644 newprompt("Enter host name: ", &buf[strlen(buf)], 28);
646 newprompt("Enter user name: ", &buf[strlen(buf)], 28);
648 newprompt("Enter password : ", &buf[strlen(buf)], 16);
650 scr_printf("Keep messages on server instead of deleting them? ");
651 sprintf(&buf[strlen(buf)], "%d", yesno());
653 recs[num_recs - 1] = strdup(buf);
657 i = intprompt("Delete which one", 1, 1, num_recs) - 1;
660 for (j = i; j < num_recs; ++j)
661 recs[j] = recs[j + 1];
666 for (i = 0; i < num_recs; ++i) {
667 r += 1 + strlen(recs[i]);
669 listing = (char *) calloc(1, r);
671 scr_printf("Can't save config - out of memory!\n");
675 for (i = 0; i < num_recs; ++i) {
676 strcat(listing, recs[i]);
677 strcat(listing, "\n");
680 // Retrieve all the *other* records for merging
681 r = CtdlIPCGetRoomNetworkConfig(ipc, &other_listing, buf);
683 for (i = 0; i < num_tokens(other_listing, '\n'); ++i) {
684 extract_token(buf, other_listing, i, '\n', sizeof buf);
685 if (strncasecmp(buf, "pop3client|", 11)) {
686 listing = realloc(listing, strlen(listing) + strlen(buf) + 10);
687 strcat(listing, buf);
688 strcat(listing, "\n");
693 r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
698 scr_printf("%s\n", buf);
701 scr_printf("Wrote %d records.\n", num_recs);
707 quitting = !modified || boolprompt("Quit without saving", 0);
715 for (i = 0; i < num_recs; ++i) {
723 // RSS feed retrieval client configuration
724 void do_rssclient_configuration(CtdlIPC * ipc) {
732 char *listing = NULL;
733 char *other_listing = NULL;
737 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
739 while (listing && !IsEmptyStr(listing)) {
740 extract_token(buf, listing, 0, '\n', sizeof buf);
741 remove_token(listing, 0, '\n');
742 extract_token(instr, buf, 0, '|', sizeof instr);
743 if (!strcasecmp(instr, "rssclient")) {
747 recs = malloc(sizeof(char *));
749 recs = realloc(recs, (sizeof(char *)) * num_recs);
750 recs[num_recs - 1] = malloc(SIZ);
751 strcpy(recs[num_recs - 1], buf);
764 scr_printf("### Feed URL\n");
766 scr_printf("--- " "---------------------------------------------------------------------------" "\n");
768 for (i = 0; i < num_recs; ++i) {
770 scr_printf("%3d ", i + 1);
772 extract_token(buf, recs[i], 1, '|', sizeof buf);
774 scr_printf("%-75s\n", buf);
779 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
784 recs = malloc(sizeof(char *));
787 recs = realloc(recs, (sizeof(char *)) * num_recs);
789 strcpy(buf, "rssclient|");
790 newprompt("Enter feed URL: ", &buf[strlen(buf)], 75);
792 recs[num_recs - 1] = strdup(buf);
796 i = intprompt("Delete which one", 1, 1, num_recs) - 1;
799 for (j = i; j < num_recs; ++j)
800 recs[j] = recs[j + 1];
805 for (i = 0; i < num_recs; ++i) {
806 r += 1 + strlen(recs[i]);
808 listing = (char *) calloc(1, r);
810 scr_printf("Can't save config - out of memory!\n");
814 for (i = 0; i < num_recs; ++i) {
815 strcat(listing, recs[i]);
816 strcat(listing, "\n");
819 // Retrieve all the *other* records for merging
820 r = CtdlIPCGetRoomNetworkConfig(ipc, &other_listing, buf);
822 for (i = 0; i < num_tokens(other_listing, '\n'); ++i) {
823 extract_token(buf, other_listing, i, '\n', sizeof buf);
824 if (strncasecmp(buf, "rssclient|", 10)) {
825 listing = realloc(listing, strlen(listing) + strlen(buf) + 10);
826 strcat(listing, buf);
827 strcat(listing, "\n");
832 r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
837 scr_printf("%s\n", buf);
840 scr_printf("Wrote %d records.\n", num_recs);
846 quitting = !modified || boolprompt("Quit without saving", 0);
854 for (i = 0; i < num_recs; ++i)