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, or disclosure is subject to the GNU General Public License version 3.
7 #include "textclient.h"
10 extern char tempdir[];
11 extern char *axdefs[8];
12 extern long highest_msg_read;
13 extern long maxmsgnum;
14 extern unsigned room_flags;
15 extern int screenwidth;
16 char editor_path[PATH_MAX];
19 // General system configuration command
20 void do_system_configuration(CtdlIPC * ipc) {
22 char sc[NUM_CONFIGS][256];
24 struct ExpirePolicy *site_expirepolicy = NULL;
25 struct ExpirePolicy *mbx_expirepolicy = NULL;
28 int r; // IPC response code
29 int server_configs = 0;
31 // Clear out the config buffers
32 memset(&sc[0][0], 0, sizeof(sc));
34 // Fetch the current config
35 r = CtdlIPCGetSystemConfig(ipc, &resp, buf);
37 server_configs = num_tokens(resp, '\n');
38 for (a = 0; a < server_configs; ++a) {
39 if (a < NUM_CONFIGS) {
40 extract_token(&sc[a][0], resp, a, '\n', sizeof sc[a]);
49 // Fetch the expire policy (this will silently fail on old servers, resulting in "default" policy)
50 r = CtdlIPCGetMessageExpirationPolicy(ipc, 2, &site_expirepolicy, buf);
51 r = CtdlIPCGetMessageExpirationPolicy(ipc, 3, &mbx_expirepolicy, buf);
53 // Identification parameters
54 strprompt("Node name", &sc[0][0], 15);
55 strprompt("Fully qualified domain name", &sc[1][0], 63);
56 strprompt("Human readable node name", &sc[2][0], 20);
57 strprompt("Telephone number", &sc[3][0], 15);
58 strprompt("Geographic location of this system", &sc[12][0], 31);
59 strprompt("Name of system administrator", &sc[13][0], 25);
60 strprompt("Paginator prompt", &sc[10][0], 79);
62 // Security parameters
63 snprintf(sc[7], sizeof sc[7], "%d", (boolprompt("Require registration for new users", atoi(&sc[7][0]))));
64 snprintf(sc[29], sizeof sc[29], "%d", (boolprompt("Disable self-service user account creation", atoi(&sc[29][0]))));
65 strprompt("Initial access level for new users", &sc[6][0], 1);
66 strprompt("Access level required to create rooms", &sc[19][0], 1);
67 snprintf(sc[67], sizeof sc[67], "%d", (boolprompt("Allow anonymous guest logins", atoi(&sc[67][0]))));
68 snprintf(sc[4], sizeof sc[4], "%d",
69 (boolprompt("Automatically give room admin privs to a user who creates a private room", atoi(&sc[4][0]))));
70 snprintf(sc[8], sizeof sc[8], "%d", (boolprompt("Automatically move problem user messages to twit room", atoi(&sc[8][0]))));
71 strprompt("Name of twit room", &sc[9][0], ROOMNAMELEN);
72 snprintf(sc[11], sizeof sc[11], "%d",
73 (boolprompt("Restrict Internet mail to only those with that privilege", atoi(&sc[11][0]))));
74 snprintf(sc[26], sizeof sc[26], "%d", (boolprompt("Allow admins to Zap (forget) rooms", atoi(&sc[26][0]))));
76 if (!IsEmptyStr(&sc[18][0])) {
82 logpages = boolprompt("Log all instant messages", logpages);
84 strprompt("Name of logging room", &sc[18][0], ROOMNAMELEN);
91 strprompt("Server connection idle timeout (in seconds)", &sc[5][0], 4);
92 strprompt("Maximum concurrent sessions", &sc[14][0], 4);
93 strprompt("Maximum message length", &sc[20][0], 20);
94 strprompt("Minimum number of worker threads", &sc[21][0], 3);
95 strprompt("Maximum number of worker threads", &sc[22][0], 3);
96 snprintf(sc[43], sizeof sc[43], "%d", (boolprompt("Automatically delete committed database logs", atoi(&sc[43][0]))));
97 strprompt("Server IP address (* for 'any')", &sc[37][0], 15);
98 strprompt("POP3 server port (-1 to disable)", &sc[23][0], 5);
99 strprompt("POP3S server port (-1 to disable)", &sc[40][0], 5);
100 strprompt("IMAP server port (-1 to disable)", &sc[27][0], 5);
101 strprompt("IMAPS server port (-1 to disable)", &sc[39][0], 5);
102 strprompt("SMTP MTA server port (-1 to disable)", &sc[24][0], 5);
103 strprompt("SMTP MSA server port (-1 to disable)", &sc[38][0], 5);
104 strprompt("SMTPS server port (-1 to disable)", &sc[41][0], 5);
105 snprintf(sc[72], sizeof sc[72], "%d", (boolprompt("Advertise STARTTLS on the SMTP port", atoi(&sc[72][0]))));
106 strprompt("NNTP server port (-1 to disable)", &sc[70][0], 5);
107 strprompt("NNTPS server port (-1 to disable)", &sc[71][0], 5);
108 strprompt("Postfix TCP Dictionary Port server port (-1 to disable)", &sc[50][0], 5);
109 strprompt("ManageSieve server port (-1 to disable)", &sc[51][0], 5);
110 strprompt("XMPP (Jabber) client to server port (-1 to disable)", &sc[62][0], 5);
111 // strprompt("XMPP (Jabber) server to server port (-1 to disable)", &sc[63][0], 5); This is just a placeholder.
113 // This logic flips the question around, because it's one of those situations where 0=yes and 1=no
116 a = boolprompt("Correct forged From: lines during authenticated SMTP", a);
118 snprintf(sc[25], sizeof sc[25], "%d", a);
120 snprintf(sc[66], sizeof sc[66], "%d", (boolprompt("Flag messages as spam instead of rejecting", atoi(&sc[66][0]))));
122 // This logic flips the question around, because it's one of those situations where 0=yes and 1=no
125 a = boolprompt("Force IMAP posts in public rooms to be from the user who submitted them", a);
127 snprintf(sc[61], sizeof sc[61], "%d", a);
129 snprintf(sc[45], sizeof sc[45], "%d",
130 (boolprompt("Allow unauthenticated SMTP clients to spoof my domains", atoi(&sc[45][0]))));
131 snprintf(sc[57], sizeof sc[57], "%d",
132 (boolprompt("Perform RBL checks at greeting instead of after RCPT", atoi(&sc[57][0]))));
135 if (ipc->ServInfo.supports_ldap) {
136 a = strlen(&sc[32][0]);
137 a = (a ? 1 : 0); // Set only to 1 or 0
138 a = boolprompt("Do you want to configure LDAP authentication?", a);
140 strprompt("Host name of LDAP server", &sc[32][0], 127);
141 strprompt("Port number of LDAP service", &sc[33][0], 5);
142 strprompt("Base DN", &sc[34][0], 255);
143 strprompt("Bind DN (or blank for anonymous bind)", &sc[35][0], 255);
144 strprompt("Password for bind DN (or blank for anonymous bind)", &sc[36][0], 255);
147 strcpy(&sc[32][0], "");
152 strprompt("Default user purge time (days)", &sc[16][0], 5);
153 strprompt("Default room purge time (days)", &sc[17][0], 5);
155 // Angels and demons dancing in my head...
157 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_mode);
158 strprompt("System default message expire policy (? for list)", buf, 1);
161 "1. Never automatically expire messages\n"
162 "2. Expire by message count\n" "3. Expire by message age\n");
164 } while ((buf[0] < '1') || (buf[0] > '3'));
165 site_expirepolicy->expire_mode = buf[0] - '0';
167 // ...lunatics and monsters underneath my bed
168 if (site_expirepolicy->expire_mode == 2) {
169 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_value);
170 strprompt("Keep how many messages online?", buf, 10);
171 site_expirepolicy->expire_value = atol(buf);
173 if (site_expirepolicy->expire_mode == 3) {
174 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_value);
175 strprompt("Keep messages for how many days?", buf, 10);
176 site_expirepolicy->expire_value = atol(buf);
179 // Media messiahs preying on my fears...
181 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_mode);
182 strprompt("Mailbox default message expire policy (? for list)", buf, 1);
185 "0. Go with the system default\n"
186 "1. Never automatically expire messages\n"
187 "2. Expire by message count\n" "3. Expire by message age\n");
189 } while ((buf[0] < '0') || (buf[0] > '3'));
190 mbx_expirepolicy->expire_mode = buf[0] - '0';
192 // ...Pop culture prophets playing in my ears
193 if (mbx_expirepolicy->expire_mode == 2) {
194 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_value);
195 strprompt("Keep how many messages online?", buf, 10);
196 mbx_expirepolicy->expire_value = atol(buf);
198 if (mbx_expirepolicy->expire_mode == 3) {
199 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_value);
200 strprompt("Keep messages for how many days?", buf, 10);
201 mbx_expirepolicy->expire_value = atol(buf);
204 strprompt("How often to run network jobs (in seconds)", &sc[28][0], 5);
205 strprompt("Default frequency to run POP3 collection (in seconds)", &sc[64][0], 5);
206 strprompt("Fastest frequency to run POP3 collection (in seconds)", &sc[65][0], 5);
207 strprompt("Hour to run purges (0-23)", &sc[31][0], 2);
208 snprintf(sc[42], sizeof sc[42], "%d",
209 (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 *));
642 recs = realloc(recs, (sizeof(char *)) * num_recs);
644 strcpy(buf, "pop3client|");
645 newprompt("Enter host name: ", &buf[strlen(buf)], 28);
647 newprompt("Enter user name: ", &buf[strlen(buf)], 28);
649 newprompt("Enter password : ", &buf[strlen(buf)], 16);
651 scr_printf("Keep messages on server instead of deleting them? ");
652 sprintf(&buf[strlen(buf)], "%d", yesno());
654 recs[num_recs - 1] = strdup(buf);
658 i = intprompt("Delete which one", 1, 1, num_recs) - 1;
661 for (j = i; j < num_recs; ++j)
662 recs[j] = recs[j + 1];
667 for (i = 0; i < num_recs; ++i) {
668 r += 1 + strlen(recs[i]);
670 listing = (char *) calloc(1, r);
672 scr_printf("Can't save config - out of memory!\n");
676 for (i = 0; i < num_recs; ++i) {
677 strcat(listing, recs[i]);
678 strcat(listing, "\n");
681 // Retrieve all the *other* records for merging
682 r = CtdlIPCGetRoomNetworkConfig(ipc, &other_listing, buf);
684 for (i = 0; i < num_tokens(other_listing, '\n'); ++i) {
685 extract_token(buf, other_listing, i, '\n', sizeof buf);
686 if (strncasecmp(buf, "pop3client|", 11)) {
687 listing = realloc(listing, strlen(listing) + strlen(buf) + 10);
688 strcat(listing, buf);
689 strcat(listing, "\n");
694 r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
699 scr_printf("%s\n", buf);
702 scr_printf("Wrote %d records.\n", num_recs);
708 quitting = !modified || boolprompt("Quit without saving", 0);
716 for (i = 0; i < num_recs; ++i) {
724 // RSS feed retrieval client configuration
725 void do_rssclient_configuration(CtdlIPC * ipc) {
733 char *listing = NULL;
734 char *other_listing = NULL;
738 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
740 while (listing && !IsEmptyStr(listing)) {
741 extract_token(buf, listing, 0, '\n', sizeof buf);
742 remove_token(listing, 0, '\n');
743 extract_token(instr, buf, 0, '|', sizeof instr);
744 if (!strcasecmp(instr, "rssclient")) {
748 recs = malloc(sizeof(char *));
750 recs = realloc(recs, (sizeof(char *)) * num_recs);
751 recs[num_recs - 1] = malloc(SIZ);
752 strcpy(recs[num_recs - 1], buf);
765 scr_printf("### Feed URL\n");
767 scr_printf("--- " "---------------------------------------------------------------------------" "\n");
769 for (i = 0; i < num_recs; ++i) {
771 scr_printf("%3d ", i + 1);
773 extract_token(buf, recs[i], 1, '|', sizeof buf);
775 scr_printf("%-75s\n", buf);
780 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
785 recs = malloc(sizeof(char *));
788 recs = realloc(recs, (sizeof(char *)) * num_recs);
790 strcpy(buf, "rssclient|");
791 newprompt("Enter feed URL: ", &buf[strlen(buf)], 75);
793 recs[num_recs - 1] = strdup(buf);
797 i = intprompt("Delete which one", 1, 1, num_recs) - 1;
800 for (j = i; j < num_recs; ++j)
801 recs[j] = recs[j + 1];
806 for (i = 0; i < num_recs; ++i) {
807 r += 1 + strlen(recs[i]);
809 listing = (char *) calloc(1, r);
811 scr_printf("Can't save config - out of memory!\n");
815 for (i = 0; i < num_recs; ++i) {
816 strcat(listing, recs[i]);
817 strcat(listing, "\n");
820 // Retrieve all the *other* records for merging
821 r = CtdlIPCGetRoomNetworkConfig(ipc, &other_listing, buf);
823 for (i = 0; i < num_tokens(other_listing, '\n'); ++i) {
824 extract_token(buf, other_listing, i, '\n', sizeof buf);
825 if (strncasecmp(buf, "rssclient|", 10)) {
826 listing = realloc(listing, strlen(listing) + strlen(buf) + 10);
827 strcat(listing, buf);
828 strcat(listing, "\n");
833 r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
838 scr_printf("%s\n", buf);
841 scr_printf("Wrote %d records.\n", num_recs);
847 quitting = !modified || boolprompt("Quit without saving", 0);
855 for (i = 0; i < num_recs; ++i)