* inetconf.c: partial i18n
[citadel.git] / webcit / inetconf.c
1 /* 
2  * $Id$
3  *
4  * Functions which handle Internet domain configuration etc.
5  *
6  */
7
8 #include "webcit.h"
9
10
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
20         enum {
21                 ic_localhost,
22                 ic_directory,
23                 ic_gwdom,
24                 ic_smarthost,
25                 ic_rbl,
26                 ic_spamass,
27                 ic_max
28         };
29         char *ic_spec[ic_max];
30         char *ic_misc;
31         char *ic_keyword[ic_max];
32         char *ic_boxtitle[ic_max];
33         char *ic_desc[ic_max];
34
35         ic_keyword[0] = _("localhost");
36         ic_keyword[1] = _("directory");
37         ic_keyword[2] = _("gatewaydomain");
38         ic_keyword[3] = _("smarthost");
39         ic_keyword[4] = _("rbl");
40         ic_keyword[5] = _("spamassassin");
41
42         ic_boxtitle[0] = _("Local host aliases");
43         ic_boxtitle[1] = _("Directory domains");
44         ic_boxtitle[2] = _("Gateway domains");
45         ic_boxtitle[3] = _("Smart hosts");
46         ic_boxtitle[4] = _("RBL hosts");
47         ic_boxtitle[5] = _("SpamAssassin hosts");
48
49         ic_desc[0] = _("(domains for which this host receives mail)");
50         ic_desc[1] = _("(domains mapped with the Global Address Book)");
51         ic_desc[2] = _("(domains whose subdomains match Citadel hosts)");
52         ic_desc[3] = _("(if present, forward all outbound mail to one of these hosts)");
53         ic_desc[4] = _("(hosts running a Realtime Blackhole List)");
54         ic_desc[5] = _("(hosts running the SpamAssassin service)");
55
56         for (i=0; i<ic_max; ++i) {
57                 ic_spec[i] = strdup("");
58         }
59         ic_misc = strdup("");
60
61         serv_printf("CONF GETSYS|application/x-citadel-internet-config");
62         serv_getln(buf, sizeof buf);
63         if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
64
65                 extract_token(ename, buf, 0, '|', sizeof ename);
66                 extract_token(etype, buf, 1, '|', sizeof etype);
67                 which = (-1);
68                 for (i=0; i<ic_max; ++i) {
69                         if (!strcasecmp(etype, ic_keyword[i])) {
70                                 which = i;
71                         }
72                 }
73
74                 if (which >= 0) {
75                         ic_spec[which] = realloc(ic_spec[which], strlen(ic_spec[which]) + strlen(ename) + 2);
76                         if (strlen(ic_spec[which]) > 0) strcat(ic_spec[which], "\n");
77                         strcat(ic_spec[which], ename);
78                 }
79                 else {
80                         ic_misc = realloc(ic_misc, strlen(ic_misc) + strlen(buf) + 2);
81                         if (strlen(ic_misc) > 0) strcat(ic_misc, "\n");
82                         strcat(ic_misc, buf);
83                 }
84
85         }
86
87         output_headers(1, 1, 2, 0, 0, 0, 0);
88         wprintf("<div id=\"banner\">\n");
89         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
90         wprintf("<SPAN CLASS=\"titlebar\">");
91         wprintf(_("Internet configuration"));
92         wprintf("</SPAN>\n");
93         wprintf("</TD></TR></TABLE>\n");
94         wprintf("</div>\n<div id=\"content\">\n");
95
96         wprintf("<div id=\"fix_scrollbar_bug\">"
97                 "<table border=0 width=100%%><tr><td valign=top>\n");
98         for (which=0; which<ic_max; ++which) {
99                 if (which == (ic_max / 2)) {
100                         wprintf("</TD><TD VALIGN=TOP>");
101                 }
102                 svprintf("BOXTITLE", WCS_STRING, ic_boxtitle[which]);
103                 do_template("beginbox");
104                 wprintf("<span class=\"menudesc\">");
105                 escputs(ic_desc[which]);
106                 wprintf("</span><br />");
107                 wprintf("<TABLE border=0 cellspacing=0 cellpadding=0 width=100%%>\n");
108                 if (strlen(ic_spec[which]) > 0) {
109                         for (i=0; i<num_tokens(ic_spec[which], '\n'); ++i) {
110                                 wprintf("<TR><TD ALIGN=LEFT>");
111                                 extract_token(buf, ic_spec[which], i, '\n', sizeof buf);
112                                 escputs(buf);
113                                 wprintf("</TD><TD ALIGN=RIGHT>"
114                                         "<A HREF=\"/save_inetconf?oper=delete&ename=");
115                                 escputs(buf);
116                                 wprintf("&etype=%s\" ", ic_keyword[which]);
117                                 wprintf("onClick=\"return confirm('Delete ");
118                                 jsescputs(buf);
119                                 wprintf("?');\">");
120                                 wprintf("<font size=-1>(Delete)</font></a></TD></TR>\n");
121                         }
122                 }
123                 wprintf("<FORM METHOD=\"POST\" ACTION=\"/save_inetconf\">\n"
124                         "<TR><TD>"
125                         "<INPUT TYPE=\"text\" NAME=\"ename\" MAXLENGTH=\"64\">"
126                         "<INPUT TYPE=\"hidden\" NAME=\"etype\" VALUE=\"%s\">", ic_keyword[which]);
127                 wprintf("</TD><TD ALIGN=RIGHT>"
128                         "<INPUT TYPE=\"submit\" NAME=\"oper\" VALUE=\"Add\">"
129                         "</TD></TR></TABLE></FORM>\n");
130                 do_template("endbox");
131         }
132         wprintf("</td></tr></table></div>\n");
133         wDumpContent(1);
134
135         for (i=0; i<ic_max; ++i) {
136                 free(ic_spec[i]);
137         }
138         free(ic_misc);
139 }
140
141
142 void save_inetconf(void) {
143         char *buf;
144         char *ename;
145         char *etype;
146         char *newconfig;
147
148         buf = malloc(SIZ);
149         ename = malloc(SIZ);
150         etype = malloc(SIZ);
151         newconfig = malloc(65536);
152
153         strcpy(newconfig, "");
154         serv_printf("CONF GETSYS|application/x-citadel-internet-config");
155         serv_getln(buf, SIZ);
156         if (buf[0] == '1') while (serv_getln(buf, SIZ), strcmp(buf, "000")) {
157                 extract_token(ename, buf, 0, '|', SIZ);
158                 extract_token(etype, buf, 1, '|', SIZ);
159                 if (strlen(buf) == 0) {
160                         /* skip blank lines */
161                 }
162                 else if ((!strcasecmp(ename, bstr("ename")))
163                    &&   (!strcasecmp(etype, bstr("etype")))
164                    &&   (!strcasecmp(bstr("oper"), "delete"))
165                 ) {
166                         sprintf(WC->ImportantMessage, "%s deleted.", ename);
167                 }
168                 else {
169                         if (strlen(newconfig) > 0) strcat(newconfig, "\n");
170                         strcat(newconfig, buf);
171                 }
172         }
173
174         serv_printf("CONF PUTSYS|application/x-citadel-internet-config");
175         serv_getln(buf, SIZ);
176         if (buf[0] == '4') {
177                 serv_puts(newconfig);
178                 if (!strcasecmp(bstr("oper"), "add")) {
179                         serv_printf("%s|%s", bstr("ename"), bstr("etype") );
180                         sprintf(WC->ImportantMessage, "%s added.", bstr("ename"));
181                 }
182                 serv_puts("000");
183         }
184         
185         display_inetconf();
186
187         free(buf);
188         free(ename);
189         free(etype);
190         free(newconfig);
191 }