56989f73f3182404f2f5a3235df5ad095a043161
[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("<TABLE class=\"inetconf_banner\"><TR><TD>");
99         wprintf("<SPAN CLASS=\"titlebar\">");
100         wprintf(_("Internet configuration"));
101         wprintf("</SPAN>\n");
102         wprintf("</TD></TR></TABLE>\n");
103         wprintf("</div>\n<div id=\"content\">\n");
104
105         wprintf("<div class=\"fix_scrollbar_bug\">"
106                 "<table border=0 width=100%%><tr><td valign=top>\n");
107         for (which=0; which<ic_max; ++which) {
108                 if (which == (ic_max / 2)) {
109                         wprintf("</TD><TD VALIGN=TOP>");
110                 }
111                 svprintf("BOXTITLE", WCS_STRING, ic_boxtitle[which]);
112                 do_template("beginbox");
113                 wprintf("<span class=\"menudesc\">");
114                 escputs(ic_desc[which]);
115                 wprintf("</span><br />");
116                 wprintf("<TABLE border=0 cellspacing=0 cellpadding=0 width=100%%>\n");
117                 if (!IsEmptyStr(ic_spec[which])) {
118                         for (i=0; i<num_tokens(ic_spec[which], '\n'); ++i) {
119                                 wprintf("<TR><TD ALIGN=LEFT>");
120                                 extract_token(buf, ic_spec[which], i, '\n', sizeof buf);
121                                 escputs(buf);
122                                 wprintf("</TD><TD ALIGN=RIGHT>"
123                                         "<a href=\"save_inetconf?oper=delete&ename=");
124                                 escputs(buf);
125                                 wprintf("&etype=%s\" ", ic_keyword[which]);
126                                 wprintf("onClick=\"return confirm('%s');\">",
127                                         _("Delete this entry?"));
128                                 wprintf("<font size=-1>");
129                                 wprintf(_("(Delete)"));
130                                 wprintf("</font></a></TD></TR>\n");
131                         }
132                 }
133                 wprintf("<FORM METHOD=\"POST\" action=\"save_inetconf\">\n");
134                 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
135                 wprintf("<TR><TD>"
136                         "<INPUT TYPE=\"text\" NAME=\"ename\" MAXLENGTH=\"64\">"
137                         "<INPUT TYPE=\"hidden\" NAME=\"etype\" VALUE=\"%s\">", ic_keyword[which]);
138                 wprintf("</TD><TD ALIGN=RIGHT>"
139                         "<INPUT TYPE=\"submit\" NAME=\"oper\" VALUE=\"Add\">"
140                         "</TD></TR></TABLE></FORM>\n");
141                 do_template("endbox");
142         }
143         wprintf("</td></tr></table></div>\n");
144         wDumpContent(1);
145
146         for (i=0; i<ic_max; ++i) {
147                 free(ic_spec[i]);
148         }
149         free(ic_misc);
150 }
151
152
153 /**
154  * \brief save changes to the inet config
155  */
156 void save_inetconf(void) {
157         char *buf;
158         char *ename;
159         char *etype;
160         char *newconfig;
161
162         buf = malloc(SIZ);
163         ename = malloc(SIZ);
164         etype = malloc(SIZ);
165         newconfig = malloc(65536);
166
167         strcpy(newconfig, "");
168         serv_printf("CONF GETSYS|application/x-citadel-internet-config");
169         serv_getln(buf, SIZ);
170         if (buf[0] == '1') while (serv_getln(buf, SIZ), strcmp(buf, "000")) {
171                 extract_token(ename, buf, 0, '|', SIZ);
172                 extract_token(etype, buf, 1, '|', SIZ);
173                 if (IsEmptyStr(buf)) {
174                         /** skip blank lines */
175                 }
176                 else if ((!strcasecmp(ename, bstr("ename")))
177                    &&   (!strcasecmp(etype, bstr("etype")))
178                    &&   (!strcasecmp(bstr("oper"), "delete"))
179                 ) {
180                         sprintf(WC->ImportantMessage, _("%s has been deleted."), ename);
181                 }
182                 else {
183                         if (!IsEmptyStr(newconfig)) strcat(newconfig, "\n");
184                         strcat(newconfig, buf);
185                 }
186         }
187
188         serv_printf("CONF PUTSYS|application/x-citadel-internet-config");
189         serv_getln(buf, SIZ);
190         if (buf[0] == '4') {
191                 serv_puts(newconfig);
192                 if (!strcasecmp(bstr("oper"), "add")) {
193                         serv_printf("%s|%s", bstr("ename"), bstr("etype") );
194                         sprintf(WC->ImportantMessage, "%s added.", bstr("ename"));
195                 }
196                 serv_puts("000");
197         }
198         
199         display_inetconf();
200
201         free(buf);
202         free(ename);
203         free(etype);
204         free(newconfig);
205 }
206
207
208
209 /*@}*/