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