* inetconf.c, listsub.c, part of mainmenu.c: 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('%s');\">",
118                                         _("Delete this entry?"));
119                                 wprintf("<font size=-1>");
120                                 wprintf(_("(Delete)"));
121                                 wprintf("</font></a></TD></TR>\n");
122                         }
123                 }
124                 wprintf("<FORM METHOD=\"POST\" ACTION=\"/save_inetconf\">\n"
125                         "<TR><TD>"
126                         "<INPUT TYPE=\"text\" NAME=\"ename\" MAXLENGTH=\"64\">"
127                         "<INPUT TYPE=\"hidden\" NAME=\"etype\" VALUE=\"%s\">", ic_keyword[which]);
128                 wprintf("</TD><TD ALIGN=RIGHT>"
129                         "<INPUT TYPE=\"submit\" NAME=\"oper\" VALUE=\"Add\">"
130                         "</TD></TR></TABLE></FORM>\n");
131                 do_template("endbox");
132         }
133         wprintf("</td></tr></table></div>\n");
134         wDumpContent(1);
135
136         for (i=0; i<ic_max; ++i) {
137                 free(ic_spec[i]);
138         }
139         free(ic_misc);
140 }
141
142
143 void save_inetconf(void) {
144         char *buf;
145         char *ename;
146         char *etype;
147         char *newconfig;
148
149         buf = malloc(SIZ);
150         ename = malloc(SIZ);
151         etype = malloc(SIZ);
152         newconfig = malloc(65536);
153
154         strcpy(newconfig, "");
155         serv_printf("CONF GETSYS|application/x-citadel-internet-config");
156         serv_getln(buf, SIZ);
157         if (buf[0] == '1') while (serv_getln(buf, SIZ), strcmp(buf, "000")) {
158                 extract_token(ename, buf, 0, '|', SIZ);
159                 extract_token(etype, buf, 1, '|', SIZ);
160                 if (strlen(buf) == 0) {
161                         /* skip blank lines */
162                 }
163                 else if ((!strcasecmp(ename, bstr("ename")))
164                    &&   (!strcasecmp(etype, bstr("etype")))
165                    &&   (!strcasecmp(bstr("oper"), "delete"))
166                 ) {
167                         sprintf(WC->ImportantMessage, _("%s has been deleted."), ename);
168                 }
169                 else {
170                         if (strlen(newconfig) > 0) strcat(newconfig, "\n");
171                         strcat(newconfig, buf);
172                 }
173         }
174
175         serv_printf("CONF PUTSYS|application/x-citadel-internet-config");
176         serv_getln(buf, SIZ);
177         if (buf[0] == '4') {
178                 serv_puts(newconfig);
179                 if (!strcasecmp(bstr("oper"), "add")) {
180                         serv_printf("%s|%s", bstr("ename"), bstr("etype") );
181                         sprintf(WC->ImportantMessage, "%s added.", bstr("ename"));
182                 }
183                 serv_puts("000");
184         }
185         
186         display_inetconf();
187
188         free(buf);
189         free(ename);
190         free(etype);
191         free(newconfig);
192 }