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