* Set all version numbers to 7.41 for upcoming beta.
[citadel.git] / citadel / tuiconfig.c
blob5197abeae8e662f819a03fd42cf5df7b54cc541a
1 /* $Id: $
3 * Configuration screens that are part of the text mode client.
5 */
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <fcntl.h>
12 #include <stdio.h>
13 #include <ctype.h>
14 #include <string.h>
15 #include <limits.h>
17 #if TIME_WITH_SYS_TIME
18 # include <sys/time.h>
19 # include <time.h>
20 #else
21 # if HAVE_SYS_TIME_H
22 # include <sys/time.h>
23 # else
24 # include <time.h>
25 # endif
26 #endif
28 #include <signal.h>
29 #include <pwd.h>
30 #include <errno.h>
31 #include <stdarg.h>
32 #include <libcitadel.h>
33 #include "sysdep.h"
34 #include "citadel.h"
35 #include "citadel_ipc.h"
36 #include "citadel_decls.h"
37 #include "tuiconfig.h"
38 #include "messages.h"
39 #include "routines.h"
40 #include "commands.h"
41 #ifndef HAVE_SNPRINTF
42 #include "snprintf.h"
43 #endif
44 #include "screen.h"
46 /* work around solaris include files */
47 #ifdef reg
48 #undef reg
49 #endif
51 extern char temp[];
52 extern char tempdir[];
53 extern char *axdefs[8];
54 extern long highest_msg_read;
55 extern long maxmsgnum;
56 extern unsigned room_flags;
57 extern int screenwidth;
60 /*
61 * General system configuration command
63 void do_system_configuration(CtdlIPC *ipc)
66 #define NUM_CONFIGS 67
68 char buf[256];
69 char sc[NUM_CONFIGS][256];
70 char *resp = NULL;
71 struct ExpirePolicy *site_expirepolicy = NULL;
72 struct ExpirePolicy *mbx_expirepolicy = NULL;
73 int a;
74 int logpages = 0;
75 int r; /* IPC response code */
76 int server_configs = 0;
78 /* Clear out the config buffers */
79 memset(&sc[0][0], 0, sizeof(sc));
81 /* Fetch the current config */
82 r = CtdlIPCGetSystemConfig(ipc, &resp, buf);
83 if (r / 100 == 1) {
84 server_configs = num_tokens(resp, '\n');
85 for (a=0; a<server_configs; ++a) {
86 if (a < NUM_CONFIGS) {
87 extract_token(&sc[a][0], resp, a, '\n', sizeof sc[a]);
91 if (resp) free(resp);
92 resp = NULL;
93 /* Fetch the expire policy (this will silently fail on old servers,
94 * resulting in "default" policy)
96 r = CtdlIPCGetMessageExpirationPolicy(ipc, 2, &site_expirepolicy, buf);
97 r = CtdlIPCGetMessageExpirationPolicy(ipc, 3, &mbx_expirepolicy, buf);
99 /* Identification parameters */
101 strprompt("Node name", &sc[0][0], 15);
102 strprompt("Fully qualified domain name", &sc[1][0], 63);
103 strprompt("Human readable node name", &sc[2][0], 20);
104 strprompt("Telephone number", &sc[3][0], 15);
105 strprompt("Geographic location of this system", &sc[12][0], 31);
106 strprompt("Name of system administrator", &sc[13][0], 25);
107 strprompt("Paginator prompt", &sc[10][0], 79);
109 /* Security parameters */
111 snprintf(sc[7], sizeof sc[7], "%d", (boolprompt(
112 "Require registration for new users",
113 atoi(&sc[7][0]))));
114 snprintf(sc[29], sizeof sc[29], "%d", (boolprompt(
115 "Disable self-service user account creation",
116 atoi(&sc[29][0]))));
117 strprompt("Initial access level for new users", &sc[6][0], 1);
118 strprompt("Access level required to create rooms", &sc[19][0], 1);
119 snprintf(sc[4], sizeof sc[4], "%d", (boolprompt(
120 "Automatically give room aide privs to a user who creates a private room",
121 atoi(&sc[4][0]))));
123 snprintf(sc[8], sizeof sc[8], "%d", (boolprompt(
124 "Automatically move problem user messages to twit room",
125 atoi(&sc[8][0]))));
127 strprompt("Name of twit room", &sc[9][0], ROOMNAMELEN);
128 snprintf(sc[11], sizeof sc[11], "%d", (boolprompt(
129 "Restrict Internet mail to only those with that privilege",
130 atoi(&sc[11][0]))));
131 snprintf(sc[26], sizeof sc[26], "%d", (boolprompt(
132 "Allow Aides to Zap (forget) rooms",
133 atoi(&sc[26][0]))));
135 if (!IsEmptyStr(&sc[18][0])) logpages = 1;
136 else logpages = 0;
137 logpages = boolprompt("Log all pages", logpages);
138 if (logpages) {
139 strprompt("Name of logging room", &sc[18][0], ROOMNAMELEN);
141 else {
142 sc[18][0] = 0;
145 /* Commented out because this setting isn't really appropriate to
146 * change while the server is running.
148 * snprintf(sc[52], sizeof sc[52], "%d", (boolprompt(
149 * "Use system authentication",
150 * atoi(&sc[52][0]))));
153 /* Server tuning */
155 strprompt("Server connection idle timeout (in seconds)", &sc[5][0], 4);
156 strprompt("Maximum concurrent sessions", &sc[14][0], 4);
157 strprompt("Maximum message length", &sc[20][0], 20);
158 strprompt("Minimum number of worker threads", &sc[21][0], 3);
159 strprompt("Maximum number of worker threads", &sc[22][0], 3);
160 snprintf(sc[43], sizeof sc[43], "%d", (boolprompt(
161 "Automatically delete committed database logs",
162 atoi(&sc[43][0]))));
164 strprompt("Server IP address (0.0.0.0 for 'any')", &sc[37][0], 15);
165 strprompt("POP3 server port (-1 to disable)", &sc[23][0], 5);
166 strprompt("POP3S server port (-1 to disable)", &sc[40][0], 5);
167 strprompt("IMAP server port (-1 to disable)", &sc[27][0], 5);
168 strprompt("IMAPS server port (-1 to disable)", &sc[39][0], 5);
169 strprompt("SMTP MTA server port (-1 to disable)", &sc[24][0], 5);
170 strprompt("SMTP MSA server port (-1 to disable)", &sc[38][0], 5);
171 strprompt("SMTPS server port (-1 to disable)", &sc[41][0], 5);
172 strprompt("Postfix TCP Dictionary Port server port (-1 to disable)", &sc[50][0], 5);
173 strprompt("ManageSieve server port (-1 to disable)", &sc[51][0], 5);
175 strprompt("XMPP (Jabber) client to server port (-1 to disable)", &sc[62][0], 5);
176 /* No prompt because we don't implement this service yet, it's just a placeholder */
177 /* strprompt("XMPP (Jabber) server to server port (-1 to disable)", &sc[63][0], 5); */
179 /* This logic flips the question around, because it's one of those
180 * situations where 0=yes and 1=no
182 a = atoi(sc[25]);
183 a = (a ? 0 : 1);
184 a = boolprompt("Correct forged From: lines during authenticated SMTP",
186 a = (a ? 0 : 1);
187 snprintf(sc[25], sizeof sc[25], "%d", a);
189 snprintf(sc[66], sizeof sc[66], "%d", (boolprompt(
190 "Flag messages as spam instead of rejecting",
191 atoi(&sc[66][0]))));
193 /* This logic flips the question around, because it's one of those
194 * situations where 0=yes and 1=no
196 a = atoi(sc[61]);
197 a = (a ? 0 : 1);
198 a = boolprompt("Force IMAP posts in public rooms to be from the user who submitted them", a);
199 a = (a ? 0 : 1);
200 snprintf(sc[61], sizeof sc[61], "%d", a);
202 snprintf(sc[45], sizeof sc[45], "%d", (boolprompt(
203 "Allow unauthenticated SMTP clients to spoof my domains",
204 atoi(&sc[45][0]))));
205 snprintf(sc[57], sizeof sc[57], "%d", (boolprompt(
206 "Perform RBL checks at greeting instead of after RCPT",
207 atoi(&sc[57][0]))));
208 snprintf(sc[44], sizeof sc[44], "%d", (boolprompt(
209 "Instantly expunge deleted IMAP messages",
210 atoi(&sc[44][0]))));
212 /* LDAP settings */
213 if (ipc->ServInfo.supports_ldap) {
214 a = strlen(&sc[32][0]);
215 a = (a ? 1 : 0); /* Set only to 1 or 0 */
216 a = boolprompt("Connect this Citadel to an external LDAP directory", a);
217 if (a) {
218 strprompt("Host name of LDAP server",
219 &sc[32][0], 127);
220 strprompt("Port number of LDAP service",
221 &sc[33][0], 5);
222 strprompt("Base DN", &sc[34][0], 255);
223 strprompt("Bind DN", &sc[35][0], 255);
224 strprompt("Password for bind DN", &sc[36][0], 255);
226 else {
227 strcpy(&sc[32][0], "");
231 /* Expiry settings */
232 strprompt("Default user purge time (days)", &sc[16][0], 5);
233 strprompt("Default room purge time (days)", &sc[17][0], 5);
235 /* Angels and demons dancing in my head... */
236 do {
237 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_mode);
238 strprompt("System default message expire policy (? for list)",
239 buf, 1);
240 if (buf[0] == '?') {
241 scr_printf("\n"
242 "1. Never automatically expire messages\n"
243 "2. Expire by message count\n"
244 "3. Expire by message age\n");
246 } while ((buf[0] < '1') || (buf[0] > '3'));
247 site_expirepolicy->expire_mode = buf[0] - '0';
249 /* ...lunatics and monsters underneath my bed */
250 if (site_expirepolicy->expire_mode == 2) {
251 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_value);
252 strprompt("Keep how many messages online?", buf, 10);
253 site_expirepolicy->expire_value = atol(buf);
255 if (site_expirepolicy->expire_mode == 3) {
256 snprintf(buf, sizeof buf, "%d", site_expirepolicy->expire_value);
257 strprompt("Keep messages for how many days?", buf, 10);
258 site_expirepolicy->expire_value = atol(buf);
261 /* Media messiahs preying on my fears... */
262 do {
263 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_mode);
264 strprompt("Mailbox default message expire policy (? for list)",
265 buf, 1);
266 if (buf[0] == '?') {
267 scr_printf("\n"
268 "0. Go with the system default\n"
269 "1. Never automatically expire messages\n"
270 "2. Expire by message count\n"
271 "3. Expire by message age\n");
273 } while ((buf[0] < '0') || (buf[0] > '3'));
274 mbx_expirepolicy->expire_mode = buf[0] - '0';
276 /* ...Pop culture prophets playing in my ears */
277 if (mbx_expirepolicy->expire_mode == 2) {
278 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_value);
279 strprompt("Keep how many messages online?", buf, 10);
280 mbx_expirepolicy->expire_value = atol(buf);
282 if (mbx_expirepolicy->expire_mode == 3) {
283 snprintf(buf, sizeof buf, "%d", mbx_expirepolicy->expire_value);
284 strprompt("Keep messages for how many days?", buf, 10);
285 mbx_expirepolicy->expire_value = atol(buf);
288 strprompt("How often to run network jobs (in seconds)", &sc[28][0], 5);
289 strprompt("Default frequency to run POP3 collection (in seconds)", &sc[64][0], 5);
290 strprompt("Fastest frequency to run POP3 collection (in seconds)", &sc[65][0], 5);
291 strprompt("Hour to run purges (0-23)", &sc[31][0], 2);
292 snprintf(sc[42], sizeof sc[42], "%d", (boolprompt(
293 "Enable full text search index (warning: resource intensive)",
294 atoi(&sc[42][0]))));
296 snprintf(sc[46], sizeof sc[46], "%d", (boolprompt(
297 "Perform journaling of email messages",
298 atoi(&sc[46][0]))));
299 snprintf(sc[47], sizeof sc[47], "%d", (boolprompt(
300 "Perform journaling of non-email messages",
301 atoi(&sc[47][0]))));
302 if ( (atoi(&sc[46][0])) || (atoi(&sc[47][0])) ) {
303 strprompt("Email destination of journalized messages",
304 &sc[48][0], 127);
307 /* Funambol push stuff */
308 int yes_funambol = 0;
309 if (strlen(sc[53]) > 0) yes_funambol = 1;
310 yes_funambol = boolprompt("Connect to an external Funambol sync server", yes_funambol);
311 if (yes_funambol) {
312 strprompt("Funambol server (blank to disable)", &sc[53][0], 63);
313 strprompt("Funambol server port", &sc[54][0], 5);
314 strprompt("Funambol sync source", &sc[55][0], 63);
315 strprompt("Funambol authentication details (user:pass in Base64)", &sc[56][0],63);
317 else {
318 sc[53][0] = 0;
319 sc[54][0] = 0;
320 sc[55][0] = 0;
321 sc[56][0] = 0;
324 /* External pager stuff */
325 int yes_pager = 0;
326 if (strlen(sc[60]) > 0) yes_pager = 1;
327 yes_pager = boolprompt("Configure an external pager tool", yes_pager);
328 if (yes_pager) {
329 strprompt("External pager tool", &sc[60][0], 255);
331 else {
332 sc[60][0] = 0;
335 /* Master user account */
336 int yes_muacct = 0;
337 if (strlen(sc[58]) > 0) yes_muacct = 1;
338 yes_muacct = boolprompt("Enable a 'master user' account", yes_muacct);
339 if (yes_muacct) {
340 strprompt("Master user name", &sc[58][0], 31);
341 strprompt("Master user password", &sc[59][0], -31);
343 else {
344 strcpy(&sc[58][0], "");
345 strcpy(&sc[59][0], "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
348 /* Save it */
349 scr_printf("Save this configuration? ");
350 if (yesno()) {
351 r = 1;
352 for (a = 0; a < NUM_CONFIGS; a++)
353 r += 1 + strlen(sc[a]);
354 resp = (char *)calloc(1, r);
355 if (!resp) {
356 err_printf("Can't save config - out of memory!\n");
357 logoff(ipc, 1);
359 for (a = 0; a < NUM_CONFIGS; a++) {
360 strcat(resp, sc[a]);
361 strcat(resp, "\n");
363 r = CtdlIPCSetSystemConfig(ipc, resp, buf);
364 if (r / 100 != 4) {
365 err_printf("%s\n", buf);
367 free(resp);
369 r = CtdlIPCSetMessageExpirationPolicy(ipc, 2, site_expirepolicy, buf);
370 if (r / 100 != 2) {
371 err_printf("%s\n", buf);
374 r = CtdlIPCSetMessageExpirationPolicy(ipc, 3, mbx_expirepolicy, buf);
375 if (r / 100 != 2) {
376 err_printf("%s\n", buf);
380 if (site_expirepolicy) free(site_expirepolicy);
381 if (mbx_expirepolicy) free(mbx_expirepolicy);
386 * support function for do_internet_configuration()
388 void get_inet_rec_type(CtdlIPC *ipc, char *buf) {
389 int sel;
391 keyopt(" <1> localhost (Alias for this computer)\n");
392 keyopt(" <2> smart-host (Forward all outbound mail to this host)\n");
393 keyopt(" <3> directory (Consult the Global Address Book)\n");
394 keyopt(" <4> SpamAssassin (Address of SpamAssassin server)\n");
395 keyopt(" <5> RBL (domain suffix of spam hunting RBL)\n");
396 keyopt(" <6> masq domains (Domains as which users are allowed to masquerade)\n");
397 keyopt(" <7> ClamAV (Address of ClamAV clamd server)\n");
398 sel = intprompt("Which one", 1, 1, 7);
399 switch(sel) {
400 case 1: strcpy(buf, "localhost");
401 return;
402 case 2: strcpy(buf, "smarthost");
403 return;
404 case 3: strcpy(buf, "directory");
405 return;
406 case 4: strcpy(buf, "spamassassin");
407 return;
408 case 5: strcpy(buf, "rbl");
409 return;
410 case 6: strcpy(buf, "masqdomain");
411 return;
412 case 7: strcpy(buf, "clamav");
413 return;
419 * Internet mail configuration
421 void do_internet_configuration(CtdlIPC *ipc)
423 char buf[256];
424 char *resp = NULL;
425 int num_recs = 0;
426 char **recs = NULL;
427 char ch;
428 int badkey;
429 int i, j;
430 int quitting = 0;
431 int modified = 0;
432 int r;
434 r = CtdlIPCGetSystemConfigByType(ipc, INTERNETCFG, &resp, buf);
435 if (r / 100 == 1) {
436 while (!IsEmptyStr(resp)) {
437 extract_token(buf, resp, 0, '\n', sizeof buf);
438 remove_token(resp, 0, '\n');
439 ++num_recs;
440 if (num_recs == 1) recs = malloc(sizeof(char *));
441 else recs = realloc(recs, (sizeof(char *)) * num_recs);
442 recs[num_recs-1] = malloc(strlen(buf) + 1);
443 strcpy(recs[num_recs-1], buf);
446 if (resp) free(resp);
448 do {
449 scr_printf("\n");
450 color(BRIGHT_WHITE);
451 scr_printf("### Host or domain Record type \n");
452 color(DIM_WHITE);
453 scr_printf("--- -------------------------------------------------- --------------------\n");
454 for (i=0; i<num_recs; ++i) {
455 color(DIM_WHITE);
456 scr_printf("%3d ", i+1);
457 extract_token(buf, recs[i], 0, '|', sizeof buf);
458 color(BRIGHT_CYAN);
459 scr_printf("%-50s ", buf);
460 extract_token(buf, recs[i], 1, '|', sizeof buf);
461 color(BRIGHT_MAGENTA);
462 scr_printf("%-20s\n", buf);
463 color(DIM_WHITE);
466 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
467 switch(ch) {
468 case 'a':
469 newprompt("Enter host name: ",
470 buf, 50);
471 striplt(buf);
472 if (!IsEmptyStr(buf)) {
473 ++num_recs;
474 if (num_recs == 1)
475 recs = malloc(sizeof(char *));
476 else recs = realloc(recs,
477 (sizeof(char *)) * num_recs);
478 strcat(buf, "|");
479 get_inet_rec_type(ipc,
480 &buf[strlen(buf)]);
481 recs[num_recs-1] = strdup(buf);
483 modified = 1;
484 break;
485 case 'd':
486 i = intprompt("Delete which one",
487 1, 1, num_recs) - 1;
488 free(recs[i]);
489 --num_recs;
490 for (j=i; j<num_recs; ++j)
491 recs[j] = recs[j+1];
492 modified = 1;
493 break;
494 case 's':
495 r = 1;
496 for (i = 0; i < num_recs; i++)
497 r += 1 + strlen(recs[i]);
498 resp = (char *)calloc(1, r);
499 if (!resp) {
500 err_printf("Can't save config - out of memory!\n");
501 logoff(ipc, 1);
503 if (num_recs) for (i = 0; i < num_recs; i++) {
504 strcat(resp, recs[i]);
505 strcat(resp, "\n");
507 r = CtdlIPCSetSystemConfigByType(ipc, INTERNETCFG, resp, buf);
508 if (r / 100 != 4) {
509 err_printf("%s\n", buf);
510 } else {
511 scr_printf("Wrote %d records.\n", num_recs);
512 modified = 0;
514 free(resp);
515 break;
516 case 'q':
517 quitting = !modified || boolprompt(
518 "Quit without saving", 0);
519 break;
520 default:
521 badkey = 1;
523 } while (!quitting);
525 if (recs != NULL) {
526 for (i=0; i<num_recs; ++i) free(recs[i]);
527 free(recs);
534 * Edit network configuration for room sharing, mailing lists, etc.
536 void network_config_management(CtdlIPC *ipc, char *entrytype, char *comment)
538 char filename[PATH_MAX];
539 char changefile[PATH_MAX];
540 int e_ex_code;
541 pid_t editor_pid;
542 int cksum;
543 int b, i, tokens;
544 char buf[1024];
545 char instr[1024];
546 char addr[1024];
547 FILE *tempfp;
548 FILE *changefp;
549 char *listing = NULL;
550 int r;
552 if (IsEmptyStr(editor_paths[0])) {
553 scr_printf("You must have an external editor configured in"
554 " order to use this function.\n");
555 return;
558 CtdlMakeTempFileName(filename, sizeof filename);
559 CtdlMakeTempFileName(changefile, sizeof changefile);
561 tempfp = fopen(filename, "w");
562 if (tempfp == NULL) {
563 err_printf("Cannot open %s: %s\n", filename, strerror(errno));
564 return;
567 fprintf(tempfp, "# Configuration for room: %s\n", room_name);
568 fprintf(tempfp, "# %s\n", comment);
569 fprintf(tempfp, "# Specify one per line.\n"
570 "\n\n");
572 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
573 if (r / 100 == 1) {
574 while(listing && !IsEmptyStr(listing)) {
575 extract_token(buf, listing, 0, '\n', sizeof buf);
576 remove_token(listing, 0, '\n');
577 extract_token(instr, buf, 0, '|', sizeof instr);
578 if (!strcasecmp(instr, entrytype)) {
579 tokens = num_tokens(buf, '|');
580 for (i=1; i<tokens; ++i) {
581 extract_token(addr, buf, i, '|', sizeof addr);
582 fprintf(tempfp, "%s", addr);
583 if (i < (tokens-1)) {
584 fprintf(tempfp, "|");
587 fprintf(tempfp, "\n");
591 if (listing) {
592 free(listing);
593 listing = NULL;
595 fclose(tempfp);
597 e_ex_code = 1; /* start with a failed exit code */
598 screen_reset();
599 stty_ctdl(SB_RESTORE);
600 editor_pid = fork();
601 cksum = file_checksum(filename);
602 if (editor_pid == 0) {
603 chmod(filename, 0600);
604 putenv("WINDOW_TITLE=Network configuration");
605 execlp(editor_paths[0], editor_paths[0], filename, NULL);
606 exit(1);
608 if (editor_pid > 0) {
609 do {
610 e_ex_code = 0;
611 b = ka_wait(&e_ex_code);
612 } while ((b != editor_pid) && (b >= 0));
613 editor_pid = (-1);
614 stty_ctdl(0);
615 screen_set();
618 if (file_checksum(filename) == cksum) {
619 err_printf("*** No changes to save.\n");
620 e_ex_code = 1;
623 if (e_ex_code == 0) { /* Save changes */
624 changefp = fopen(changefile, "w");
626 /* Load all netconfig entries that are *not* of the type we are editing */
627 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
628 if (r / 100 == 1) {
629 while(listing && !IsEmptyStr(listing)) {
630 extract_token(buf, listing, 0, '\n', sizeof buf);
631 remove_token(listing, 0, '\n');
632 extract_token(instr, buf, 0, '|', sizeof instr);
633 if (strcasecmp(instr, entrytype)) {
634 fprintf(changefp, "%s\n", buf);
638 if (listing) {
639 free(listing);
640 listing = NULL;
643 /* ...and merge that with the data we just edited */
644 tempfp = fopen(filename, "r");
645 while (fgets(buf, sizeof buf, tempfp) != NULL) {
646 for (i=0; i<strlen(buf); ++i) {
647 if (buf[i] == '#') buf[i] = 0;
649 striplt(buf);
650 if (!IsEmptyStr(buf)) {
651 fprintf(changefp, "%s|%s\n", entrytype, buf);
654 fclose(tempfp);
655 fclose(changefp);
657 /* now write it to the server... */
658 changefp = fopen(changefile, "r");
659 if (changefp != NULL) {
660 listing = load_message_from_file(changefp);
661 if (listing) {
662 r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
663 free(listing);
664 listing = NULL;
666 fclose(changefp);
670 unlink(filename); /* Delete the temporary files */
671 unlink(changefile);
676 * IGnet node configuration
678 void do_ignet_configuration(CtdlIPC *ipc) {
679 char buf[SIZ];
680 int num_recs = 0;
681 char **recs = NULL;
682 char ch;
683 int badkey;
684 int i, j;
685 int quitting = 0;
686 int modified = 0;
687 char *listing = NULL;
688 int r;
690 r = CtdlIPCGetSystemConfigByType(ipc, IGNETCFG, &listing, buf);
691 if (r / 100 == 1) while (*listing && !IsEmptyStr(listing)) {
692 extract_token(buf, listing, 0, '\n', sizeof buf);
693 remove_token(listing, 0, '\n');
695 ++num_recs;
696 if (num_recs == 1) recs = malloc(sizeof(char *));
697 else recs = realloc(recs, (sizeof(char *)) * num_recs);
698 recs[num_recs-1] = malloc(SIZ);
699 strcpy(recs[num_recs-1], buf);
701 if (listing) free(listing);
703 do {
704 scr_printf("\n");
705 color(BRIGHT_WHITE);
706 scr_printf( "### "
707 " Node "
708 " Secret "
709 " Host or IP "
710 "Port#\n");
711 color(DIM_WHITE);
712 scr_printf( "--- "
713 "---------------- "
714 "------------------ "
715 "-------------------------------- "
716 "-----\n");
717 for (i=0; i<num_recs; ++i) {
718 color(DIM_WHITE);
719 scr_printf("%3d ", i+1);
720 extract_token(buf, recs[i], 0, '|', sizeof buf);
721 color(BRIGHT_CYAN);
722 scr_printf("%-16s ", buf);
723 extract_token(buf, recs[i], 1, '|', sizeof buf);
724 color(BRIGHT_MAGENTA);
725 scr_printf("%-18s ", buf);
726 extract_token(buf, recs[i], 2, '|', sizeof buf);
727 color(BRIGHT_CYAN);
728 scr_printf("%-32s ", buf);
729 extract_token(buf, recs[i], 3, '|', sizeof buf);
730 color(BRIGHT_MAGENTA);
731 scr_printf("%-3s\n", buf);
732 color(DIM_WHITE);
734 scr_printf("\n");
736 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
737 switch(ch) {
738 case 'a':
739 ++num_recs;
740 if (num_recs == 1)
741 recs = malloc(sizeof(char *));
742 else recs = realloc(recs,
743 (sizeof(char *)) * num_recs);
744 newprompt("Enter node name : ", buf, 16);
745 strcat(buf, "|");
746 newprompt("Enter shared secret: ",
747 &buf[strlen(buf)], 18);
748 strcat(buf, "|");
749 newprompt("Enter host or IP : ",
750 &buf[strlen(buf)], 32);
751 strcat(buf, "|504");
752 strprompt("Enter port number : ",
753 &buf[strlen(buf)-3], 5);
754 recs[num_recs-1] = strdup(buf);
755 modified = 1;
756 break;
757 case 'd':
758 i = intprompt("Delete which one",
759 1, 1, num_recs) - 1;
760 free(recs[i]);
761 --num_recs;
762 for (j=i; j<num_recs; ++j)
763 recs[j] = recs[j+1];
764 modified = 1;
765 break;
766 case 's':
767 r = 1;
768 for (i = 0; i < num_recs; ++i)
769 r += 1 + strlen(recs[i]);
770 listing = (char*) calloc(1, r);
771 if (!listing) {
772 err_printf("Can't save config - out of memory!\n");
773 logoff(ipc, 1);
775 if (num_recs) for (i = 0; i < num_recs; ++i) {
776 strcat(listing, recs[i]);
777 strcat(listing, "\n");
779 r = CtdlIPCSetSystemConfigByType(ipc, IGNETCFG, listing, buf);
780 if (r / 100 != 4) {
781 scr_printf("%s\n", buf);
782 } else {
783 scr_printf("Wrote %d records.\n", num_recs);
784 modified = 0;
786 free(listing);
787 break;
788 case 'q':
789 quitting = !modified || boolprompt(
790 "Quit without saving", 0);
791 break;
792 default:
793 badkey = 1;
795 } while (!quitting);
797 if (recs != NULL) {
798 for (i=0; i<num_recs; ++i) free(recs[i]);
799 free(recs);
805 * Filter list configuration
807 void do_filterlist_configuration(CtdlIPC *ipc)
809 char buf[SIZ];
810 int num_recs = 0;
811 char **recs = NULL;
812 char ch;
813 int badkey;
814 int i, j;
815 int quitting = 0;
816 int modified = 0;
817 char *listing = NULL;
818 int r;
820 r = CtdlIPCGetSystemConfigByType(ipc, FILTERLIST, &listing, buf);
821 if (r / 100 == 1) while (*listing && !IsEmptyStr(listing)) {
822 extract_token(buf, listing, 0, '\n', sizeof buf);
823 remove_token(listing, 0, '\n');
825 ++num_recs;
826 if (num_recs == 1) recs = malloc(sizeof(char *));
827 else recs = realloc(recs, (sizeof(char *)) * num_recs);
828 recs[num_recs-1] = malloc(SIZ);
829 strcpy(recs[num_recs-1], buf);
831 if (listing) free(listing);
833 do {
834 scr_printf("\n");
835 color(BRIGHT_WHITE);
836 scr_printf( "### "
837 " User name "
838 " Room name "
839 " Node name "
840 "\n");
841 color(DIM_WHITE);
842 scr_printf( "--- "
843 "---------------------------- "
844 "---------------------------- "
845 "---------------- "
846 "\n");
847 for (i=0; i<num_recs; ++i) {
848 color(DIM_WHITE);
849 scr_printf("%3d ", i+1);
850 extract_token(buf, recs[i], 0, '|', sizeof buf);
851 color(BRIGHT_CYAN);
852 scr_printf("%-28s ", buf);
853 extract_token(buf, recs[i], 1, '|', sizeof buf);
854 color(BRIGHT_MAGENTA);
855 scr_printf("%-28s ", buf);
856 extract_token(buf, recs[i], 2, '|', sizeof buf);
857 color(BRIGHT_CYAN);
858 scr_printf("%-16s\n", buf);
859 extract_token(buf, recs[i], 3, '|', sizeof buf);
860 color(DIM_WHITE);
863 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
864 switch(ch) {
865 case 'a':
866 ++num_recs;
867 if (num_recs == 1)
868 recs = malloc(sizeof(char *));
869 else recs = realloc(recs,
870 (sizeof(char *)) * num_recs);
871 newprompt("Enter user name: ", buf, 28);
872 strcat(buf, "|");
873 newprompt("Enter room name: ",
874 &buf[strlen(buf)], 28);
875 strcat(buf, "|");
876 newprompt("Enter node name: ",
877 &buf[strlen(buf)], 16);
878 strcat(buf, "|");
879 recs[num_recs-1] = strdup(buf);
880 modified = 1;
881 break;
882 case 'd':
883 i = intprompt("Delete which one",
884 1, 1, num_recs) - 1;
885 free(recs[i]);
886 --num_recs;
887 for (j=i; j<num_recs; ++j)
888 recs[j] = recs[j+1];
889 modified = 1;
890 break;
891 case 's':
892 r = 1;
893 for (i = 0; i < num_recs; ++i)
894 r += 1 + strlen(recs[i]);
895 listing = (char*) calloc(1, r);
896 if (!listing) {
897 err_printf("Can't save config - out of memory!\n");
898 logoff(ipc, 1);
900 if (num_recs) for (i = 0; i < num_recs; ++i) {
901 strcat(listing, recs[i]);
902 strcat(listing, "\n");
904 r = CtdlIPCSetSystemConfigByType(ipc, FILTERLIST, listing, buf);
905 if (r / 100 != 4) {
906 scr_printf("%s\n", buf);
907 } else {
908 scr_printf("Wrote %d records.\n", num_recs);
909 modified = 0;
911 free(listing);
912 break;
913 case 'q':
914 quitting = !modified || boolprompt(
915 "Quit without saving", 0);
916 break;
917 default:
918 badkey = 1;
920 } while (!quitting);
922 if (recs != NULL) {
923 for (i=0; i<num_recs; ++i) free(recs[i]);
924 free(recs);
932 * POP3 aggregation client configuration
934 void do_pop3client_configuration(CtdlIPC *ipc)
936 char buf[SIZ];
937 int num_recs = 0;
938 char **recs = NULL;
939 char ch;
940 int badkey;
941 int i, j;
942 int quitting = 0;
943 int modified = 0;
944 char *listing = NULL;
945 char *other_listing = NULL;
946 int r;
947 char instr[SIZ];
949 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
950 if (r / 100 == 1) {
951 while(listing && !IsEmptyStr(listing)) {
952 extract_token(buf, listing, 0, '\n', sizeof buf);
953 remove_token(listing, 0, '\n');
954 extract_token(instr, buf, 0, '|', sizeof instr);
955 if (!strcasecmp(instr, "pop3client")) {
957 ++num_recs;
958 if (num_recs == 1) recs = malloc(sizeof(char *));
959 else recs = realloc(recs, (sizeof(char *)) * num_recs);
960 recs[num_recs-1] = malloc(SIZ);
961 strcpy(recs[num_recs-1], buf);
966 if (listing) {
967 free(listing);
968 listing = NULL;
971 do {
972 scr_printf("\n");
973 color(BRIGHT_WHITE);
974 scr_printf( "### "
975 " Remote POP3 host "
976 " User name "
977 "Keep on server? "
978 "Fetching inteval"
979 "\n");
980 color(DIM_WHITE);
981 scr_printf( "--- "
982 "---------------------------- "
983 "---------------------------- "
984 "--------------- "
985 "---------------- "
986 "\n");
987 for (i=0; i<num_recs; ++i) {
988 color(DIM_WHITE);
989 scr_printf("%3d ", i+1);
991 extract_token(buf, recs[i], 1, '|', sizeof buf);
992 color(BRIGHT_CYAN);
993 scr_printf("%-28s ", buf);
995 extract_token(buf, recs[i], 2, '|', sizeof buf);
996 color(BRIGHT_MAGENTA);
997 scr_printf("%-28s ", buf);
999 color(BRIGHT_CYAN);
1000 scr_printf("%-15s ", (extract_int(recs[i], 4) ? "Yes" : "No") );
1001 color(BRIGHT_MAGENTA);
1002 scr_printf("%ld\n", extract_long(recs[i], 5) );
1003 color(DIM_WHITE);
1006 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
1007 switch(ch) {
1008 case 'a':
1009 ++num_recs;
1010 if (num_recs == 1) {
1011 recs = malloc(sizeof(char *));
1013 else {
1014 recs = realloc(recs, (sizeof(char *)) * num_recs);
1016 strcpy(buf, "pop3client|");
1017 newprompt("Enter host name: ", &buf[strlen(buf)], 28);
1018 strcat(buf, "|");
1019 newprompt("Enter user name: ", &buf[strlen(buf)], 28);
1020 strcat(buf, "|");
1021 newprompt("Enter password : ", &buf[strlen(buf)], 16);
1022 strcat(buf, "|");
1023 scr_printf("Keep messages on server instead of deleting them? ");
1024 sprintf(&buf[strlen(buf)], "%d", yesno());
1025 strcat(buf, "|");
1026 newprompt("Enter interval : ", &buf[strlen(buf)], 5);
1027 strcat(buf, "|");
1028 recs[num_recs-1] = strdup(buf);
1029 modified = 1;
1030 break;
1031 case 'd':
1032 i = intprompt("Delete which one",
1033 1, 1, num_recs) - 1;
1034 free(recs[i]);
1035 --num_recs;
1036 for (j=i; j<num_recs; ++j)
1037 recs[j] = recs[j+1];
1038 modified = 1;
1039 break;
1040 case 's':
1041 r = 1;
1042 for (i = 0; i < num_recs; ++i) {
1043 r += 1 + strlen(recs[i]);
1045 listing = (char*) calloc(1, r);
1046 if (!listing) {
1047 err_printf("Can't save config - out of memory!\n");
1048 logoff(ipc, 1);
1050 if (num_recs) for (i = 0; i < num_recs; ++i) {
1051 strcat(listing, recs[i]);
1052 strcat(listing, "\n");
1055 /* Retrieve all the *other* records for merging */
1056 r = CtdlIPCGetRoomNetworkConfig(ipc, &other_listing, buf);
1057 if (r / 100 == 1) {
1058 for (i=0; i<num_tokens(other_listing, '\n'); ++i) {
1059 extract_token(buf, other_listing, i, '\n', sizeof buf);
1060 if (strncasecmp(buf, "pop3client|", 11)) {
1061 listing = realloc(listing, strlen(listing) +
1062 strlen(buf) + 10);
1063 strcat(listing, buf);
1064 strcat(listing, "\n");
1068 free(other_listing);
1069 r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
1070 free(listing);
1071 listing = NULL;
1073 if (r / 100 != 4) {
1074 scr_printf("%s\n", buf);
1075 } else {
1076 scr_printf("Wrote %d records.\n", num_recs);
1077 modified = 0;
1079 quitting = 1;
1080 break;
1081 case 'q':
1082 quitting = !modified || boolprompt(
1083 "Quit without saving", 0);
1084 break;
1085 default:
1086 badkey = 1;
1088 } while (!quitting);
1090 if (recs != NULL) {
1091 for (i=0; i<num_recs; ++i) free(recs[i]);
1092 free(recs);
1102 * RSS feed retrieval client configuration
1104 void do_rssclient_configuration(CtdlIPC *ipc)
1106 char buf[SIZ];
1107 int num_recs = 0;
1108 char **recs = NULL;
1109 char ch;
1110 int badkey;
1111 int i, j;
1112 int quitting = 0;
1113 int modified = 0;
1114 char *listing = NULL;
1115 char *other_listing = NULL;
1116 int r;
1117 char instr[SIZ];
1119 r = CtdlIPCGetRoomNetworkConfig(ipc, &listing, buf);
1120 if (r / 100 == 1) {
1121 while(listing && !IsEmptyStr(listing)) {
1122 extract_token(buf, listing, 0, '\n', sizeof buf);
1123 remove_token(listing, 0, '\n');
1124 extract_token(instr, buf, 0, '|', sizeof instr);
1125 if (!strcasecmp(instr, "rssclient")) {
1127 ++num_recs;
1128 if (num_recs == 1) recs = malloc(sizeof(char *));
1129 else recs = realloc(recs, (sizeof(char *)) * num_recs);
1130 recs[num_recs-1] = malloc(SIZ);
1131 strcpy(recs[num_recs-1], buf);
1136 if (listing) {
1137 free(listing);
1138 listing = NULL;
1141 do {
1142 scr_printf("\n");
1143 color(BRIGHT_WHITE);
1144 scr_printf("### Feed URL\n");
1145 color(DIM_WHITE);
1146 scr_printf("--- "
1147 "---------------------------------------------------------------------------"
1148 "\n");
1150 for (i=0; i<num_recs; ++i) {
1151 color(DIM_WHITE);
1152 scr_printf("%3d ", i+1);
1154 extract_token(buf, recs[i], 1, '|', sizeof buf);
1155 color(BRIGHT_CYAN);
1156 scr_printf("%-75s\n", buf);
1158 color(DIM_WHITE);
1161 ch = keymenu("", "<A>dd|<D>elete|<S>ave|<Q>uit");
1162 switch(ch) {
1163 case 'a':
1164 ++num_recs;
1165 if (num_recs == 1) {
1166 recs = malloc(sizeof(char *));
1168 else {
1169 recs = realloc(recs, (sizeof(char *)) * num_recs);
1171 strcpy(buf, "rssclient|");
1172 newprompt("Enter feed URL: ", &buf[strlen(buf)], 75);
1173 strcat(buf, "|");
1174 recs[num_recs-1] = strdup(buf);
1175 modified = 1;
1176 break;
1177 case 'd':
1178 i = intprompt("Delete which one", 1, 1, num_recs) - 1;
1179 free(recs[i]);
1180 --num_recs;
1181 for (j=i; j<num_recs; ++j)
1182 recs[j] = recs[j+1];
1183 modified = 1;
1184 break;
1185 case 's':
1186 r = 1;
1187 for (i = 0; i < num_recs; ++i) {
1188 r += 1 + strlen(recs[i]);
1190 listing = (char*) calloc(1, r);
1191 if (!listing) {
1192 err_printf("Can't save config - out of memory!\n");
1193 logoff(ipc, 1);
1195 if (num_recs) for (i = 0; i < num_recs; ++i) {
1196 strcat(listing, recs[i]);
1197 strcat(listing, "\n");
1200 /* Retrieve all the *other* records for merging */
1201 r = CtdlIPCGetRoomNetworkConfig(ipc, &other_listing, buf);
1202 if (r / 100 == 1) {
1203 for (i=0; i<num_tokens(other_listing, '\n'); ++i) {
1204 extract_token(buf, other_listing, i, '\n', sizeof buf);
1205 if (strncasecmp(buf, "rssclient|", 10)) {
1206 listing = realloc(listing, strlen(listing) +
1207 strlen(buf) + 10);
1208 strcat(listing, buf);
1209 strcat(listing, "\n");
1213 free(other_listing);
1214 r = CtdlIPCSetRoomNetworkConfig(ipc, listing, buf);
1215 free(listing);
1216 listing = NULL;
1218 if (r / 100 != 4) {
1219 scr_printf("%s\n", buf);
1220 } else {
1221 scr_printf("Wrote %d records.\n", num_recs);
1222 modified = 0;
1224 quitting = 1;
1225 break;
1226 case 'q':
1227 quitting = !modified || boolprompt(
1228 "Quit without saving", 0);
1229 break;
1230 default:
1231 badkey = 1;
1233 } while (!quitting);
1235 if (recs != NULL) {
1236 for (i=0; i<num_recs; ++i) free(recs[i]);
1237 free(recs);