6bb3272ac002395edc7ea9dc3cec391c9a3d9900
[citadel.git] / webcit / inetconf.c
1 /* 
2  * $Id$
3  *
4  * Functions which handle Internet domain configuration etc.
5  *
6  */
7
8 #include "webcit.h"
9
10
11
12 void display_inetconf(void)
13 {
14         char buf[SIZ];
15         char ename[SIZ];
16         char etype[SIZ];
17         int i;
18         int which;
19
20         enum {
21                 ic_localhost,
22                 ic_directory,
23                 ic_gwdom,
24                 ic_smarthost,
25                 ic_rbl,
26                 ic_spamass,
27                 ic_max
28         };
29         char *ic_spec[ic_max];
30         char *ic_misc;
31
32         char *ic_keyword[] = {
33                 "localhost",
34                 "directory",
35                 "gatewaydomain",
36                 "smarthost",
37                 "rbl",
38                 "spamassassin",
39         };
40
41         char *ic_boxtitle[] = {
42                 "Local host aliases",
43                 "Directory domains",
44                 "Gateway domains",
45                 "Smart hosts",
46                 "RBL hosts",
47                 "SpamAssassin hosts",
48         };
49
50         char *ic_desc[] = {
51                 "(domains for which this host receives mail)",
52                 "(domains mapped with the Global Address Book)",
53                 "(domains whose subdomains match Citadel hosts)",
54                 "(if present, forward all outbound mail to one of these hosts)",
55                 "(hosts running a Realtime Blackhole List)",
56                 "(hosts running the SpamAssassin service)",
57         };
58
59         for (i=0; i<ic_max; ++i) {
60                 ic_spec[i] = strdup("");
61         }
62         ic_misc = strdup("");
63
64         serv_printf("CONF GETSYS|application/x-citadel-internet-config");
65         serv_getln(buf, sizeof buf);
66         if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
67
68                 extract_token(ename, buf, 0, '|', sizeof ename);
69                 extract_token(etype, buf, 1, '|', sizeof etype);
70                 which = (-1);
71                 for (i=0; i<ic_max; ++i) {
72                         if (!strcasecmp(etype, ic_keyword[i])) {
73                                 which = i;
74                         }
75                 }
76
77                 if (which >= 0) {
78                         ic_spec[which] = realloc(ic_spec[which], strlen(ic_spec[which]) + strlen(ename) + 2);
79                         if (strlen(ic_spec[which]) > 0) strcat(ic_spec[which], "\n");
80                         strcat(ic_spec[which], ename);
81                 }
82                 else {
83                         ic_misc = realloc(ic_misc, strlen(ic_misc) + strlen(buf) + 2);
84                         if (strlen(ic_misc) > 0) strcat(ic_misc, "\n");
85                         strcat(ic_misc, buf);
86                 }
87
88         }
89
90         output_headers(1, 1, 2, 0, 0, 0, 0);
91         wprintf("<div id=\"banner\">\n");
92         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
93         wprintf("<SPAN CLASS=\"titlebar\">Internet configuration</SPAN>\n");
94         wprintf("</TD></TR></TABLE>\n");
95         wprintf("</div>\n<div id=\"content\">\n");
96
97         wprintf("<div id=\"fix_scrollbar_bug\">"
98                 "<table border=0 width=100%%><tr><td valign=top>\n");
99         for (which=0; which<ic_max; ++which) {
100                 if (which == (ic_max / 2)) {
101                         wprintf("</TD><TD VALIGN=TOP>");
102                 }
103                 svprintf("BOXTITLE", WCS_STRING, ic_boxtitle[which]);
104                 do_template("beginbox");
105                 wprintf("<span class=\"menudesc\">");
106                 escputs(ic_desc[which]);
107                 wprintf("</span><br />");
108                 wprintf("<TABLE border=0 cellspacing=0 cellpadding=0 width=100%%>\n");
109                 if (strlen(ic_spec[which]) > 0) {
110                         for (i=0; i<num_tokens(ic_spec[which], '\n'); ++i) {
111                                 wprintf("<TR><TD ALIGN=LEFT>");
112                                 extract_token(buf, ic_spec[which], i, '\n', sizeof buf);
113                                 escputs(buf);
114                                 wprintf("</TD><TD ALIGN=RIGHT>"
115                                         "<A HREF=\"/save_inetconf?oper=delete&ename=");
116                                 escputs(buf);
117                                 wprintf("&etype=%s\" ", ic_keyword[which]);
118                                 wprintf("onClick=\"return confirm('Delete ");
119                                 jsescputs(buf);
120                                 wprintf("?');\">");
121                                 wprintf("<font size=-1>(Delete)</font></a></TD></TR>\n");
122                         }
123                 }
124                 wprintf("<FORM METHOD=\"POST\" ACTION=\"/save_inetconf\">\n"
125                         "<TR><TD>"
126                         "<INPUT TYPE=\"text\" NAME=\"ename\" MAXLENGTH=\"64\">"
127                         "<INPUT TYPE=\"hidden\" NAME=\"etype\" VALUE=\"%s\">", ic_keyword[which]);
128                 wprintf("</TD><TD ALIGN=RIGHT>"
129                         "<INPUT TYPE=\"submit\" NAME=\"oper\" VALUE=\"Add\">"
130                         "</TD></TR></TABLE></FORM>\n");
131                 do_template("endbox");
132         }
133         wprintf("</td></tr></table></div>\n");
134         wDumpContent(1);
135
136         for (i=0; i<ic_max; ++i) {
137                 free(ic_spec[i]);
138         }
139         free(ic_misc);
140 }
141
142
143 void save_inetconf(void) {
144         char *buf;
145         char *ename;
146         char *etype;
147         char *newconfig;
148
149         buf = malloc(SIZ);
150         ename = malloc(SIZ);
151         etype = malloc(SIZ);
152         newconfig = malloc(65536);
153
154         strcpy(newconfig, "");
155         serv_printf("CONF GETSYS|application/x-citadel-internet-config");
156         serv_getln(buf, SIZ);
157         if (buf[0] == '1') while (serv_getln(buf, SIZ), strcmp(buf, "000")) {
158                 extract_token(ename, buf, 0, '|', SIZ);
159                 extract_token(etype, buf, 1, '|', SIZ);
160                 if (strlen(buf) == 0) {
161                         /* skip blank lines */
162                 }
163                 else if ((!strcasecmp(ename, bstr("ename")))
164                    &&   (!strcasecmp(etype, bstr("etype")))
165                    &&   (!strcasecmp(bstr("oper"), "delete"))
166                 ) {
167                         sprintf(WC->ImportantMessage, "%s deleted.", ename);
168                 }
169                 else {
170                         if (strlen(newconfig) > 0) strcat(newconfig, "\n");
171                         strcat(newconfig, buf);
172                 }
173         }
174
175         serv_printf("CONF PUTSYS|application/x-citadel-internet-config");
176         serv_getln(buf, SIZ);
177         if (buf[0] == '4') {
178                 serv_puts(newconfig);
179                 if (!strcasecmp(bstr("oper"), "add")) {
180                         serv_printf("%s|%s", bstr("ename"), bstr("etype") );
181                         sprintf(WC->ImportantMessage, "%s added.", bstr("ename"));
182                 }
183                 serv_puts("000");
184         }
185         
186         display_inetconf();
187
188         free(buf);
189         free(ename);
190         free(etype);
191         free(newconfig);
192 }