c61ee41665ce01f98c80e3159a90f8b4c7dc6dbd
[citadel.git] / webcit / inetconf.c
1 /* 
2  * $Id$
3  *
4  * Functions which handle Internet domain configuration etc.
5  */
6
7 #include "webcit.h"
8
9 /*
10  * display the inet config dialog 
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         int bg = 0;
20
21         enum {
22                 ic_localhost,
23                 ic_directory,
24                 ic_smarthost,
25                 ic_rbl,
26                 ic_spamass,
27                 ic_masq,
28                 ic_max
29         };
30
31         char *ic_spec[ic_max];
32         char *ic_misc;
33         char *ic_keyword[ic_max];
34         char *ic_boxtitle[ic_max];
35         char *ic_desc[ic_max];
36
37         /* These are server config keywords; do not localize! */
38         ic_keyword[0] = "localhost";
39         ic_keyword[1] = "directory";
40         ic_keyword[2] = "smarthost";
41         ic_keyword[3] = "rbl";
42         ic_keyword[4] = "spamassassin";
43         ic_keyword[5] = "masqdomain";
44
45         ic_boxtitle[0] = _("Local host aliases");
46         ic_boxtitle[1] = _("Directory domains");
47         ic_boxtitle[2] = _("Smart hosts");
48         ic_boxtitle[3] = _("RBL hosts");
49         ic_boxtitle[4] = _("SpamAssassin hosts");
50         ic_boxtitle[5] = _("Masqueradable domains");
51
52         ic_desc[0] = _("(domains for which this host receives mail)");
53         ic_desc[1] = _("(domains mapped with the Global Address Book)");
54         ic_desc[2] = _("(if present, forward all outbound mail to one of these hosts)");
55         ic_desc[3] = _("(hosts running a Realtime Blackhole List)");
56         ic_desc[4] = _("(hosts running the SpamAssassin service)");
57         ic_desc[5] = _("(Domains as which users are allowed to masquerade)");
58
59         for (i=0; i<ic_max; ++i) {
60                 ic_spec[i] = strdup("");
61         }
62
63         ic_misc = strdup("");
64
65         serv_printf("CONF GETSYS|application/x-citadel-internet-config");
66         serv_getln(buf, sizeof buf);
67         if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
68
69                 extract_token(ename, buf, 0, '|', sizeof ename);
70                 extract_token(etype, buf, 1, '|', sizeof etype);
71                 which = (-1);
72                 for (i=0; i<ic_max; ++i) {
73                         if (!strcasecmp(etype, ic_keyword[i])) {
74                                 which = i;
75                         }
76                 }
77
78                 if (which >= 0) {
79                         ic_spec[which] = realloc(ic_spec[which], strlen(ic_spec[which]) + strlen(ename) + 2);
80                         if (!IsEmptyStr(ic_spec[which])) strcat(ic_spec[which], "\n");
81                         strcat(ic_spec[which], ename);
82                 }
83                 else {
84                         ic_misc = realloc(ic_misc, strlen(ic_misc) + strlen(buf) + 2);
85                         if (!IsEmptyStr(ic_misc)) strcat(ic_misc, "\n");
86                         strcat(ic_misc, buf);
87                 }
88
89         }
90
91         output_headers(1, 1, 2, 0, 0, 0);
92         wprintf("<div id=\"banner\">\n");
93         wprintf("<h1>");
94         wprintf(_("Internet configuration"));
95         wprintf("</h1>");
96         wprintf("</div>\n");
97
98         wprintf("<div id=\"content\" class=\"service\">\n");
99
100         wprintf("<div class=\"fix_scrollbar_bug\">"
101                 "<table border=0 width=100%% cellspacing=\"10px\" cellpadding=\"10px\"> "
102                 "<tr><td valign=top width=50%%>\n");
103         for (which=0; which<ic_max; ++which) {
104                 if (which == (ic_max / 2)) {
105                         wprintf("</td><td valign=top>");
106                 }
107                 svput("BOXTITLE", WCS_STRING, ic_boxtitle[which]);
108                 do_template("beginbox");
109                 wprintf("<span class=\"menudesc\">");
110                 escputs(ic_desc[which]);
111                 wprintf("</span><br />");
112                 wprintf("<table border=0 cellspacing=\"2px\" cellpadding=\"2px\" width=94%% "
113                         "class=\"altern\" >\n");
114                 bg = 0;
115                 if (!IsEmptyStr(ic_spec[which])) {
116                         for (i=0; i<num_tokens(ic_spec[which], '\n'); ++i) {
117                                 bg = 1 - bg;
118                                 wprintf("<tr class=\"%s\">",
119                                         (bg ? "even" : "odd")
120                                 );
121                                 wprintf("<td align=left>");
122                                 extract_token(buf, ic_spec[which], i, '\n', sizeof buf);
123                                 escputs(buf);
124                                 wprintf("</td><td align=left>"
125                                         "<span class=\"button_link\">"
126                                         "<a href=\"save_inetconf?oper=delete&ename=");
127                                 escputs(buf);
128                                 wprintf("&etype=%s\" ", ic_keyword[which]);
129                                 wprintf("onClick=\"return confirm('%s');\">",
130                                         _("Delete this entry?"));
131                                 wprintf(_("Delete"));
132                                 wprintf("</a></span></td></tr>\n");
133                         }
134
135                 }
136                 wprintf("<form method=\"post\" action=\"save_inetconf\">\n");
137                 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
138                 wprintf("<tr><td>"
139                         "<input type=\"text\" name=\"ename\" maxlength=\"64\">"
140                         "<input type=\"hidden\" name=\"etype\" VALUE=\"%s\">", ic_keyword[which]);
141                 wprintf("</td><td align=left>"
142                         "<input type=\"submit\" name=\"oper\" value=\"Add\">"
143                         "</td></tr></table></form>\n");
144                 do_template("endbox");
145                 wprintf("<br />");
146         }
147         wprintf("</td></tr></table></div>\n");
148         wDumpContent(1);
149
150         for (i=0; i<ic_max; ++i) {
151                 free(ic_spec[i]);
152         }
153         free(ic_misc);
154 }
155
156
157 /*
158  * save changes to the inet config
159  */
160 void save_inetconf(void) {
161         char *buf;
162         char *ename;
163         char *etype;
164         char *newconfig;
165
166         buf = malloc(SIZ);
167         ename = malloc(SIZ);
168         etype = malloc(SIZ);
169         newconfig = malloc(65536);
170
171         strcpy(newconfig, "");
172         serv_printf("CONF GETSYS|application/x-citadel-internet-config");
173         serv_getln(buf, SIZ);
174         if (buf[0] == '1') while (serv_getln(buf, SIZ), strcmp(buf, "000")) {
175                 extract_token(ename, buf, 0, '|', SIZ);
176                 extract_token(etype, buf, 1, '|', SIZ);
177                 if (IsEmptyStr(buf)) {
178                         /* skip blank lines */
179                 }
180                 else if ((!strcasecmp(ename, bstr("ename")))
181                    &&   (!strcasecmp(etype, bstr("etype")))
182                    &&   (!strcasecmp(bstr("oper"), "delete"))
183                 ) {
184                         sprintf(WC->ImportantMessage, _("%s has been deleted."), ename);
185                 }
186                 else {
187                         if (!IsEmptyStr(newconfig)) strcat(newconfig, "\n");
188                         strcat(newconfig, buf);
189                 }
190         }
191
192         serv_printf("CONF PUTSYS|application/x-citadel-internet-config");
193         serv_getln(buf, SIZ);
194         if (buf[0] == '4') {
195                 serv_puts(newconfig);
196                 if (!strcasecmp(bstr("oper"), "add")) {
197                         serv_printf("%s|%s", bstr("ename"), bstr("etype") );
198                         sprintf(WC->ImportantMessage, "%s added.", bstr("ename"));
199                 }
200                 serv_puts("000");
201         }
202         
203         display_inetconf();
204
205         free(buf);
206         free(ename);
207         free(etype);
208         free(newconfig);
209 }