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