* Merged Thierry's CSS changes
[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_max
31         };
32         char *ic_spec[ic_max];
33         char *ic_misc;
34         char *ic_keyword[ic_max];
35         char *ic_boxtitle[ic_max];
36         char *ic_desc[ic_max];
37
38         /* DON'T NEVER EVER AGAIN TRANSLATE CITADEL COMMANDS! */
39         ic_keyword[0] = "localhost";
40         ic_keyword[1] = "directory";
41         ic_keyword[2] = "gatewaydomain";
42         ic_keyword[3] = "smarthost";
43         ic_keyword[4] = "rbl";
44         ic_keyword[5] = "spamassassin";
45
46         ic_boxtitle[0] = _("Local host aliases");
47         ic_boxtitle[1] = _("Directory domains");
48         ic_boxtitle[2] = _("Gateway domains");
49         ic_boxtitle[3] = _("Smart hosts");
50         ic_boxtitle[4] = _("RBL hosts");
51         ic_boxtitle[5] = _("SpamAssassin hosts");
52
53         ic_desc[0] = _("(domains for which this host receives mail)");
54         ic_desc[1] = _("(domains mapped with the Global Address Book)");
55         ic_desc[2] = _("(domains whose subdomains match Citadel hosts)");
56         ic_desc[3] = _("(if present, forward all outbound mail to one of these hosts)");
57         ic_desc[4] = _("(hosts running a Realtime Blackhole List)");
58         ic_desc[5] = _("(hosts running the SpamAssassin service)");
59
60         for (i=0; i<ic_max; ++i) {
61                 ic_spec[i] = strdup("");
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 (strlen(ic_spec[which]) > 0) 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 (strlen(ic_misc) > 0) 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("<TABLE class=\"inetconf_banner\"><TR><TD>");
94         wprintf("<SPAN CLASS=\"titlebar\">");
95         wprintf(_("Internet configuration"));
96         wprintf("</SPAN>\n");
97         wprintf("</TD></TR></TABLE>\n");
98         wprintf("</div>\n<div id=\"content\">\n");
99
100         wprintf("<div class=\"fix_scrollbar_bug\">"
101                 "<table border=0 width=100%%><tr><td valign=top>\n");
102         for (which=0; which<ic_max; ++which) {
103                 if (which == (ic_max / 2)) {
104                         wprintf("</TD><TD VALIGN=TOP>");
105                 }
106                 svprintf("BOXTITLE", WCS_STRING, ic_boxtitle[which]);
107                 do_template("beginbox");
108                 wprintf("<span class=\"menudesc\">");
109                 escputs(ic_desc[which]);
110                 wprintf("</span><br />");
111                 wprintf("<TABLE border=0 cellspacing=0 cellpadding=0 width=100%%>\n");
112                 if (strlen(ic_spec[which]) > 0) {
113                         for (i=0; i<num_tokens(ic_spec[which], '\n'); ++i) {
114                                 wprintf("<TR><TD ALIGN=LEFT>");
115                                 extract_token(buf, ic_spec[which], i, '\n', sizeof buf);
116                                 escputs(buf);
117                                 wprintf("</TD><TD ALIGN=RIGHT>"
118                                         "<a href=\"save_inetconf?oper=delete&ename=");
119                                 escputs(buf);
120                                 wprintf("&etype=%s\" ", ic_keyword[which]);
121                                 wprintf("onClick=\"return confirm('%s');\">",
122                                         _("Delete this entry?"));
123                                 wprintf("<font size=-1>");
124                                 wprintf(_("(Delete)"));
125                                 wprintf("</font></a></TD></TR>\n");
126                         }
127                 }
128                 wprintf("<FORM METHOD=\"POST\" action=\"save_inetconf\">\n"
129                         "<TR><TD>"
130                         "<INPUT TYPE=\"text\" NAME=\"ename\" MAXLENGTH=\"64\">"
131                         "<INPUT TYPE=\"hidden\" NAME=\"etype\" VALUE=\"%s\">", ic_keyword[which]);
132                 wprintf("</TD><TD ALIGN=RIGHT>"
133                         "<INPUT TYPE=\"submit\" NAME=\"oper\" VALUE=\"Add\">"
134                         "</TD></TR></TABLE></FORM>\n");
135                 do_template("endbox");
136         }
137         wprintf("</td></tr></table></div>\n");
138         wDumpContent(1);
139
140         for (i=0; i<ic_max; ++i) {
141                 free(ic_spec[i]);
142         }
143         free(ic_misc);
144 }
145
146
147 /**
148  * \brief save changes to the inet config
149  */
150 void save_inetconf(void) {
151         char *buf;
152         char *ename;
153         char *etype;
154         char *newconfig;
155
156         buf = malloc(SIZ);
157         ename = malloc(SIZ);
158         etype = malloc(SIZ);
159         newconfig = malloc(65536);
160
161         strcpy(newconfig, "");
162         serv_printf("CONF GETSYS|application/x-citadel-internet-config");
163         serv_getln(buf, SIZ);
164         if (buf[0] == '1') while (serv_getln(buf, SIZ), strcmp(buf, "000")) {
165                 extract_token(ename, buf, 0, '|', SIZ);
166                 extract_token(etype, buf, 1, '|', SIZ);
167                 if (strlen(buf) == 0) {
168                         /** skip blank lines */
169                 }
170                 else if ((!strcasecmp(ename, bstr("ename")))
171                    &&   (!strcasecmp(etype, bstr("etype")))
172                    &&   (!strcasecmp(bstr("oper"), "delete"))
173                 ) {
174                         sprintf(WC->ImportantMessage, _("%s has been deleted."), ename);
175                 }
176                 else {
177                         if (strlen(newconfig) > 0) strcat(newconfig, "\n");
178                         strcat(newconfig, buf);
179                 }
180         }
181
182         serv_printf("CONF PUTSYS|application/x-citadel-internet-config");
183         serv_getln(buf, SIZ);
184         if (buf[0] == '4') {
185                 serv_puts(newconfig);
186                 if (!strcasecmp(bstr("oper"), "add")) {
187                         serv_printf("%s|%s", bstr("ename"), bstr("etype") );
188                         sprintf(WC->ImportantMessage, "%s added.", bstr("ename"));
189                 }
190                 serv_puts("000");
191         }
192         
193         display_inetconf();
194
195         free(buf);
196         free(ename);
197         free(etype);
198         free(newconfig);
199 }
200
201
202
203 /*@}*/