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