2 * Configuration screens that are part of the text mode client.
4 * Copyright (c) 1987-2018 by the citadel.org team
6 * This program is open source software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include "textclient.h"
18 extern char tempdir[];
19 extern char *axdefs[8];
20 extern long highest_msg_read;
21 extern long maxmsgnum;
22 extern unsigned room_flags;
23 extern int screenwidth;
24 char editor_path[PATH_MAX];
28 * General system configuration command
30 void do_system_configuration(CtdlIPC * ipc)
33 /* NUM_CONFIGS is now defined in citadel.h */
36 char sc[NUM_CONFIGS][256];
38 struct ExpirePolicy *site_expirepolicy = NULL;
39 struct ExpirePolicy *mbx_expirepolicy = NULL;
42 int r; /* IPC response code */
43 int server_configs = 0;
45 /* Clear out the config buffers */
46 memset(&sc[0][0], 0, sizeof(sc));
48 /* Fetch the current config */
49 r = CtdlIPCGetSystemConfig(ipc, &resp, buf);
51 server_configs = num_tokens(resp, '\n');
52 for (a = 0; a < server_configs; ++a) {
53 if (a < NUM_CONFIGS) {
54 extract_token(&sc[a][0], resp, a, '\n', sizeof sc[a]);
61 /* Fetch the expire policy (this will silently fail on old servers,
62 * resulting in "default" policy)
64 r = CtdlIPCGetMessageExpirationPolicy(ipc, 2, &site_expirepolicy, buf);
65 r = CtdlIPCGetMessageExpirationPolicy(ipc, 3, &mbx_expirepolicy, buf);
67 /* Identification parameters */
69 strprompt("Node name", &sc[0][0], 15);
70 strprompt("Fully qualified domain name", &sc[1][0], 63);
71 strprompt("Human readable node name", &sc[2][0], 20);
72 strprompt("Telephone number", &sc[3][0], 15);
73 strprompt("Geographic location of this system", &sc[12][0], 31);
74 strprompt("Name of system administrator", &sc[13][0], 25);
75 strprompt("Paginator prompt", &sc[10][0], 79);
77 /* Security parameters */
79 snprintf(sc[7], sizeof sc[7], "%d", (boolprompt("Require registration for new users", atoi(&sc[7][0]))));
80 snprintf(sc[29], sizeof sc[29], "%d", (boolprompt("Disable self-service user account creation", atoi(&sc[29][0]))));
81 strprompt("Initial access level for new users", &sc[6][0], 1);
82 strprompt("Access level required to create rooms", &sc[19][0], 1);
83 snprintf(sc[67], sizeof sc[67], "%d", (boolprompt("Allow anonymous guest logins", atoi(&sc[67][0]))));
84 snprintf(sc[4], sizeof sc[4], "%d", (boolprompt("Automatically give room admin privs to a user who creates a private room",
87 snprintf(sc[8], sizeof sc[8], "%d", (boolprompt("Automatically move problem user messages to twit room", atoi(&sc[8][0]))));
89 strprompt("Name of twit room", &sc[9][0], ROOMNAMELEN);
90 snprintf(sc[11], sizeof sc[11], "%d", (boolprompt("Restrict Internet mail to only those with that privilege",
92 snprintf(sc[26], sizeof sc[26], "%d", (boolprompt("Allow admins to Zap (forget) rooms", atoi(&sc[26][0]))));
94 if (!IsEmptyStr(&sc[18][0])) {
99 logpages = boolprompt("Log all instant messages", logpages);
101 strprompt("Name of logging room", &sc[18][0], ROOMNAMELEN);
106 /* Commented out because this setting isn't really appropriate to
107 * change while the server is running.
109 * snprintf(sc[52], sizeof sc[52], "%d", (boolprompt(
110 * "Use system authentication",
111 * atoi(&sc[52][0]))));
116 strprompt("Server connection idle timeout (in seconds)", &sc[5][0], 4);
117 strprompt("Maximum concurrent sessions", &sc[14][0], 4);
118 strprompt("Maximum message length", &sc[20][0], 20);
119 strprompt("Minimum number of worker threads", &sc[21][0], 3);
120 strprompt("Maximum number of worker threads", &sc[22][0], 3);
121 snprintf(sc[43], sizeof sc[43], "%d", (boolprompt("Automatically delete committed database logs", atoi(&sc[43][0]))));
123 strprompt("Server IP address (* for 'any')", &sc[37][0], 15);
124 strprompt("POP3 server port (-1 to disable)", &sc[23][0], 5);
125 strprompt("POP3S server port (-1 to disable)", &sc[40][0], 5);
126 strprompt("IMAP server port (-1 to disable)", &sc[27][0], 5);
127 strprompt("IMAPS server port (-1 to disable)", &sc[39][0], 5);
128 strprompt("SMTP MTA server port (-1 to disable)", &sc[24][0], 5);
129 strprompt("SMTP MSA server port (-1 to disable)", &sc[38][0], 5);
130 strprompt("SMTPS server port (-1 to disable)", &sc[41][0], 5);
131 strprompt("NNTP server port (-1 to disable)", &sc[70][0], 5);
132 strprompt("NNTPS server port (-1 to disable)", &sc[71][0], 5);
133 strprompt("Postfix TCP Dictionary Port server port (-1 to disable)", &sc[50][0], 5);
134 strprompt("ManageSieve server port (-1 to disable)", &sc[51][0], 5);
136 strprompt("XMPP (Jabber) client to server port (-1 to disable)", &sc[62][0], 5);
137 /* No prompt because we don't implement this service yet, it's just a placeholder */
138 /* strprompt("XMPP (Jabber) server to server port (-1 to disable)", &sc[63][0], 5); */
140 /* This logic flips the question around, because it's one of those
141 * situations where 0=yes and 1=no
145 a = boolprompt("Correct forged From: lines during authenticated SMTP", a);
147 snprintf(sc[25], sizeof sc[25], "%d", a);
149 snprintf(sc[66], sizeof sc[66], "%d", (boolprompt("Flag messages as spam instead of rejecting", atoi(&sc[66][0]))));
151 /* This logic flips the question around, because it's one of those
152 * situations where 0=yes and 1=no
156 a = boolprompt("Force IMAP posts in public rooms to be from the user who submitted them", a);
158 snprintf(sc[61], sizeof sc[61], "%d", a);
160 snprintf(sc[45], sizeof sc[45], "%d", (boolprompt("Allow unauthenticated SMTP clients to spoof my domains",
162 snprintf(sc[57], sizeof sc[57], "%d", (boolprompt("Perform RBL checks at greeting instead of after RCPT",
166 if (ipc->ServInfo.supports_ldap) {
167 a = strlen(&sc[32][0]);
168 a = (a ? 1 : 0); /* Set only to 1 or 0 */
169 a = boolprompt("Do you want to configure LDAP authentication?", a);
171 strprompt("Host name of LDAP server", &sc[32][0], 127);
172 strprompt("Port number of LDAP service", &sc[33][0], 5);
173 strprompt("Base DN", &sc[34][0], 255);
174 strprompt("Bind DN (or blank for anonymous bind)", &sc[35][0], 255);
175 strprompt("Password for bind DN (or blank for anonymous bind)", &sc[36][0], 255);
177 strcpy(&sc[32][0], "");
181 /* Expiry settings */
182 strprompt("Default user purge time (days)", &sc[16][0], 5);
183 strprompt("Default room purge time (days)", &sc[17][0], 5);
185 /* Angels and demons dancing in my head... */
187 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_mode);
188 strprompt("System default message expire policy (? for list)", buf, 1);
191 "1. Never automatically expire messages\n"
192 "2. Expire by message count\n" "3. Expire by message age\n");
194 } while ((buf[0] < '1') || (buf[0] > '3'));
195 site_expirepolicy->expire_mode = buf[0] - '0';
197 /* ...lunatics and monsters underneath my bed */
198 if (site_expirepolicy->expire_mode == 2) {
199 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_value);
200 strprompt("Keep how many messages online?", buf, 10);
201 site_expirepolicy->expire_value = atol(buf);
203 if (site_expirepolicy->expire_mode == 3) {
204 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_value);
205 strprompt("Keep messages for how many days?", buf, 10);
206 site_expirepolicy->expire_value = atol(buf);
209 /* Media messiahs preying on my fears... */
211 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_mode);
212 strprompt("Mailbox default message expire policy (? for list)", buf, 1);
215 "0. Go with the system default\n"
216 "1. Never automatically expire messages\n"
217 "2. Expire by message count\n" "3. Expire by message age\n");
219 } while ((buf[0] < '0') || (buf[0] > '3'));
220 mbx_expirepolicy->expire_mode = buf[0] - '0';
222 /* ...Pop culture prophets playing in my ears */
223 if (mbx_expirepolicy->expire_mode == 2) {
224 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_value);
225 strprompt("Keep how many messages online?", buf, 10);
226 mbx_expirepolicy->expire_value = atol(buf);
228 if (mbx_expirepolicy->expire_mode == 3) {
229 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_value);
230 strprompt("Keep messages for how many days?", buf, 10);
231 mbx_expirepolicy->expire_value = atol(buf);
234 strprompt("How often to run network jobs (in seconds)", &sc[28][0], 5);
235 strprompt("Default frequency to run POP3 collection (in seconds)", &sc[64][0], 5);
236 strprompt("Fastest frequency to run POP3 collection (in seconds)", &sc[65][0], 5);
237 strprompt("Hour to run purges (0-23)", &sc[31][0], 2);
238 snprintf(sc[42], sizeof sc[42], "%d", (boolprompt("Enable full text search index (warning: resource intensive)",
241 snprintf(sc[46], sizeof sc[46], "%d", (boolprompt("Perform journaling of email messages", atoi(&sc[46][0]))));
242 snprintf(sc[47], sizeof sc[47], "%d", (boolprompt("Perform journaling of non-email messages", atoi(&sc[47][0]))));
243 if ((atoi(&sc[46][0])) || (atoi(&sc[47][0]))) {
244 strprompt("Email destination of journalized messages", &sc[48][0], 127);
247 /* No more Funambol */
253 /* External pager stuff */
255 if (strlen(sc[60]) > 0)
257 yes_pager = boolprompt("Configure an external pager tool", yes_pager);
259 strprompt("External pager tool", &sc[60][0], 255);
265 scr_printf("Save this configuration? ");
268 for (a = 0; a < NUM_CONFIGS; a++) {
269 r += 1 + strlen(sc[a]);
271 resp = (char *) calloc(1, r);
273 scr_printf("Can't save config - out of memory!\n");
276 for (a = 0; a < NUM_CONFIGS; a++) {
280 r = CtdlIPCSetSystemConfig(ipc, resp, buf);
282 scr_printf("%s\n", buf);
286 r = CtdlIPCSetMessageExpirationPolicy(ipc, 2, site_expirepolicy, buf);
288 scr_printf("%s\n", buf);
291 r = CtdlIPCSetMessageExpirationPolicy(ipc, 3, mbx_expirepolicy, buf);
293 scr_printf("%s\n", buf);
297 if (site_expirepolicy)
298 free(site_expirepolicy);
299 if (mbx_expirepolicy)
300 free(mbx_expirepolicy);
305 * support function for do_internet_configuration()
307 void get_inet_rec_type(CtdlIPC * ipc, char *buf)
311 keyopt(" <1> localhost (Alias for this computer)\n");
312 keyopt(" <2> smart host (Forward all outbound mail to this host)\n");
313 keyopt(" <3> fallback host (Send mail to this host only if direct delivery fails)\n");
314 keyopt(" <4> SpamAssassin (Address of SpamAssassin server)\n");
315 keyopt(" <5> RBL (domain suffix of spam hunting RBL)\n");
316 keyopt(" <6> masq domains (Domains as which users are allowed to masquerade)\n");
317 keyopt(" <7> ClamAV (Address of ClamAV clamd server)\n");
318 sel = intprompt("Which one", 1, 1, 8);
321 strcpy(buf, "localhost");
324 strcpy(buf, "smarthost");
327 strcpy(buf, "fallbackhost");
330 strcpy(buf, "spamassassin");
336 strcpy(buf, "masqdomain");
339 strcpy(buf, "clamav");
346 * Internet mail configuration
348 void do_internet_configuration(CtdlIPC * ipc)
360 r = CtdlIPCGetSystemConfigByType(ipc, INTERNETCFG, &resp, buf);
362 while (!IsEmptyStr(resp)) {
363 extract_token(buf, resp, 0, '\n', sizeof buf);
364 remove_token(resp, 0, '\n');
366 // VILE SLEAZY HACK: replace obsolete "directory" domains with "localhost"
367 char *d = strstr(buf, "|directory");
369 strcpy(d, "|localhost");
374 recs = malloc(sizeof(char *));
376 recs = realloc(recs, (sizeof(char *)) * num_recs);
377 recs[num_recs - 1] = malloc(strlen(buf) + 1);
378 strcpy(recs[num_recs - 1], buf);
387 scr_printf("### Host or domain Record type \n");
389 scr_printf("--- -------------------------------------------------- --------------------\n");
390 for (i = 0; i < num_recs; ++i) {
392 scr_printf("%3d ", i + 1);
393 extract_token(buf, recs[i], 0, '|', sizeof buf);
395 scr_printf("%-50s ", buf);
396 extract_token(buf, recs[i], 1, '|', sizeof buf);
397 color(BRIGHT_MAGENTA);
398 scr_printf("%-20s\n", buf);
402 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
405 newprompt("Enter host name: ", buf, 50);
407 if (!IsEmptyStr(buf)) {
410 recs = malloc(sizeof(char *));
412 recs = realloc(recs, (sizeof(char *)) * num_recs);
415 get_inet_rec_type(ipc, &buf[strlen(buf)]);
416 recs[num_recs - 1] = strdup(buf);
421 i = intprompt("Delete which one", 1, 1, num_recs) - 1;
424 for (j = i; j < num_recs; ++j) {
425 recs[j] = recs[j + 1];
431 for (i = 0; i < num_recs; i++)
432 r += 1 + strlen(recs[i]);
433 resp = (char *) calloc(1, r);
435 scr_printf("Can't save config - out of memory!\n");
439 for (i = 0; i < num_recs; i++) {
440 strcat(resp, recs[i]);
443 r = CtdlIPCSetSystemConfigByType(ipc, INTERNETCFG, resp, buf);
445 scr_printf("%s\n", buf);
447 scr_printf("Wrote %d records.\n", num_recs);
453 quitting = !modified || boolprompt("Quit without saving", 0);
461 for (i = 0; i < num_recs; ++i)
470 * Edit network configuration for room sharing, mailing lists, etc.
472 void network_config_management(CtdlIPC * ipc, char *entrytype, char *comment)
474 char filename[PATH_MAX];
475 char changefile[PATH_MAX];
485 char *listing = NULL;
488 if (IsEmptyStr(editor_path)) {
489 scr_printf("You must have an external editor configured in order to use this function.\n");
493 CtdlMakeTempFileName(filename, sizeof filename);
494 CtdlMakeTempFileName(changefile, sizeof changefile);
496 tempfp = fopen(filename, "w");
497 if (tempfp == NULL) {
498 scr_printf("Cannot open %s: %s\n", filename, strerror(errno));
502 fprintf(tempfp, "# Configuration for room: %s\n", room_name);
503 fprintf(tempfp, "# %s\n", comment);
504 fprintf(tempfp, "# Specify one per line.\n" "\n\n");
506 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
508 while (listing && !IsEmptyStr(listing)) {
509 extract_token(buf, listing, 0, '\n', sizeof buf);
510 remove_token(listing, 0, '\n');
511 extract_token(instr, buf, 0, '|', sizeof instr);
512 if (!strcasecmp(instr, entrytype)) {
513 tokens = num_tokens(buf, '|');
514 for (i = 1; i < tokens; ++i) {
515 extract_token(addr, buf, i, '|', sizeof addr);
516 fprintf(tempfp, "%s", addr);
517 if (i < (tokens - 1)) {
518 fprintf(tempfp, "|");
521 fprintf(tempfp, "\n");
531 e_ex_code = 1; /* start with a failed exit code */
532 stty_ctdl(SB_RESTORE);
534 cksum = file_checksum(filename);
535 if (editor_pid == 0) {
536 chmod(filename, 0600);
537 putenv("WINDOW_TITLE=Network configuration");
538 execlp(editor_path, editor_path, filename, NULL);
541 if (editor_pid > 0) {
544 b = ka_wait(&e_ex_code);
545 } while ((b != editor_pid) && (b >= 0));
550 if (file_checksum(filename) == cksum) {
551 scr_printf("*** No changes to save.\n");
555 if (e_ex_code == 0) { /* Save changes */
556 changefp = fopen(changefile, "w");
558 /* Load all netconfig entries that are *not* of the type we are editing */
559 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
561 while (listing && !IsEmptyStr(listing)) {
562 extract_token(buf, listing, 0, '\n', sizeof buf);
563 remove_token(listing, 0, '\n');
564 extract_token(instr, buf, 0, '|', sizeof instr);
565 if (strcasecmp(instr, entrytype)) {
566 fprintf(changefp, "%s\n", buf);
575 /* ...and merge that with the data we just edited */
576 tempfp = fopen(filename, "r");
577 while (fgets(buf, sizeof buf, tempfp) != NULL) {
578 for (i = 0; i < strlen(buf); ++i) {
583 if (!IsEmptyStr(buf)) {
584 fprintf(changefp, "%s|%s\n", entrytype, buf);
590 /* now write it to the server... */
591 changefp = fopen(changefile, "r");
592 if (changefp != NULL) {
593 listing = load_message_from_file(changefp);
595 r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
603 unlink(filename); /* Delete the temporary files */
609 * POP3 aggregation client configuration
611 void do_pop3client_configuration(CtdlIPC * ipc)
620 char *listing = NULL;
621 char *other_listing = NULL;
625 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
627 while (listing && !IsEmptyStr(listing)) {
628 extract_token(buf, listing, 0, '\n', sizeof buf);
629 remove_token(listing, 0, '\n');
630 extract_token(instr, buf, 0, '|', sizeof instr);
631 if (!strcasecmp(instr, "pop3client")) {
635 recs = malloc(sizeof(char *));
637 recs = realloc(recs, (sizeof(char *)) * num_recs);
638 recs[num_recs - 1] = malloc(SIZ);
639 strcpy(recs[num_recs - 1], buf);
652 scr_printf("### " " Remote POP3 host " " User name " "Keep on server? " "\n");
654 scr_printf("--- " "---------------------------- " "---------------------------- " "--------------- " "\n");
655 for (i = 0; i < num_recs; ++i) {
657 scr_printf("%3d ", i + 1);
659 extract_token(buf, recs[i], 1, '|', sizeof buf);
661 scr_printf("%-28s ", buf);
663 extract_token(buf, recs[i], 2, '|', sizeof buf);
664 color(BRIGHT_MAGENTA);
665 scr_printf("%-28s ", buf);
668 scr_printf("%-15s\n", (extract_int(recs[i], 4) ? "Yes" : "No"));
672 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
677 recs = malloc(sizeof(char *));
679 recs = realloc(recs, (sizeof(char *)) * num_recs);
681 strcpy(buf, "pop3client|");
682 newprompt("Enter host name: ", &buf[strlen(buf)], 28);
684 newprompt("Enter user name: ", &buf[strlen(buf)], 28);
686 newprompt("Enter password : ", &buf[strlen(buf)], 16);
688 scr_printf("Keep messages on server instead of deleting them? ");
689 sprintf(&buf[strlen(buf)], "%d", yesno());
691 recs[num_recs - 1] = strdup(buf);
695 i = intprompt("Delete which one", 1, 1, num_recs) - 1;
698 for (j = i; j < num_recs; ++j)
699 recs[j] = recs[j + 1];
704 for (i = 0; i < num_recs; ++i) {
705 r += 1 + strlen(recs[i]);
707 listing = (char *) calloc(1, r);
709 scr_printf("Can't save config - out of memory!\n");
713 for (i = 0; i < num_recs; ++i) {
714 strcat(listing, recs[i]);
715 strcat(listing, "\n");
718 /* Retrieve all the *other* records for merging */
719 r = CtdlIPCGetRoomNetworkConfig(ipc, &other_listing, buf);
721 for (i = 0; i < num_tokens(other_listing, '\n'); ++i) {
722 extract_token(buf, other_listing, i, '\n', sizeof buf);
723 if (strncasecmp(buf, "pop3client|", 11)) {
724 listing = realloc(listing, strlen(listing) + strlen(buf) + 10);
725 strcat(listing, buf);
726 strcat(listing, "\n");
731 r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
736 scr_printf("%s\n", buf);
738 scr_printf("Wrote %d records.\n", num_recs);
744 quitting = !modified || boolprompt("Quit without saving", 0);
752 for (i = 0; i < num_recs; ++i)
764 * RSS feed retrieval client configuration
766 void do_rssclient_configuration(CtdlIPC * ipc)
775 char *listing = NULL;
776 char *other_listing = NULL;
780 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
782 while (listing && !IsEmptyStr(listing)) {
783 extract_token(buf, listing, 0, '\n', sizeof buf);
784 remove_token(listing, 0, '\n');
785 extract_token(instr, buf, 0, '|', sizeof instr);
786 if (!strcasecmp(instr, "rssclient")) {
790 recs = malloc(sizeof(char *));
792 recs = realloc(recs, (sizeof(char *)) * num_recs);
793 recs[num_recs - 1] = malloc(SIZ);
794 strcpy(recs[num_recs - 1], buf);
807 scr_printf("### Feed URL\n");
809 scr_printf("--- " "---------------------------------------------------------------------------" "\n");
811 for (i = 0; i < num_recs; ++i) {
813 scr_printf("%3d ", i + 1);
815 extract_token(buf, recs[i], 1, '|', sizeof buf);
817 scr_printf("%-75s\n", buf);
822 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
827 recs = malloc(sizeof(char *));
829 recs = realloc(recs, (sizeof(char *)) * num_recs);
831 strcpy(buf, "rssclient|");
832 newprompt("Enter feed URL: ", &buf[strlen(buf)], 75);
834 recs[num_recs - 1] = strdup(buf);
838 i = intprompt("Delete which one", 1, 1, num_recs) - 1;
841 for (j = i; j < num_recs; ++j)
842 recs[j] = recs[j + 1];
847 for (i = 0; i < num_recs; ++i) {
848 r += 1 + strlen(recs[i]);
850 listing = (char *) calloc(1, r);
852 scr_printf("Can't save config - out of memory!\n");
856 for (i = 0; i < num_recs; ++i) {
857 strcat(listing, recs[i]);
858 strcat(listing, "\n");
861 /* Retrieve all the *other* records for merging */
862 r = CtdlIPCGetRoomNetworkConfig(ipc, &other_listing, buf);
864 for (i = 0; i < num_tokens(other_listing, '\n'); ++i) {
865 extract_token(buf, other_listing, i, '\n', sizeof buf);
866 if (strncasecmp(buf, "rssclient|", 10)) {
867 listing = realloc(listing, strlen(listing) + strlen(buf) + 10);
868 strcat(listing, buf);
869 strcat(listing, "\n");
874 r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
879 scr_printf("%s\n", buf);
881 scr_printf("Wrote %d records.\n", num_recs);
887 quitting = !modified || boolprompt("Quit without saving", 0);
895 for (i = 0; i < num_recs; ++i)