* *** HUGE CHANGES *** *** WARNING: NOT FULLY FUNCTIONAL ***
[citadel.git] / webcit / inetconf.c
1 /* 
2  * inetconf.c
3  *
4  * Functions which handle Internet domain configuration etc.
5  *
6  * $Id$
7  */
8
9 #include <ctype.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <stdio.h>
13 #include <fcntl.h>
14 #include <signal.h>
15 #include <sys/types.h>
16 #include <sys/wait.h>
17 #include <sys/socket.h>
18 #include <sys/time.h>
19 #include <limits.h>
20 #include <netinet/in.h>
21 #include <netdb.h>
22 #include <string.h>
23 #include <pwd.h>
24 #include <errno.h>
25 #include <stdarg.h>
26 #include <pthread.h>
27 #include <signal.h>
28 #include "webcit.h"
29
30
31
32 void display_inetconf(void)
33 {
34         char buf[SIZ];
35         char ename[SIZ];
36         char etype[SIZ];
37         int i;
38         int which;
39
40         enum {
41                 ic_localhost,
42                 ic_directory,
43                 ic_gwdom,
44                 ic_smarthost,
45                 ic_rbl,
46                 ic_spamass,
47                 ic_max
48         };
49         char *ic_spec[ic_max];
50         char *ic_misc;
51
52         char *ic_keyword[] = {
53                 "localhost",
54                 "directory",
55                 "gatewaydomain",
56                 "smarthost",
57                 "rbl",
58                 "spamassassin",
59         };
60
61         char *ic_boxtitle[] = {
62                 "Local host aliases",
63                 "Directory domains",
64                 "Gateway domains",
65                 "Smart hosts",
66                 "RBL hosts",
67                 "SpamAssassin hosts",
68         };
69
70         char *ic_desc[] = {
71                 "(domains for which this host receives mail)",
72                 "(domains mapped with the Global Address Book)",
73                 "(domains whose subdomains match Citadel hosts)",
74                 "(if present, forward all outbound mail to one of these hosts)",
75                 "(hosts running a Realtime Blackhole List)",
76                 "(hosts running the SpamAssassin service)",
77         };
78
79         for (i=0; i<ic_max; ++i) {
80                 ic_spec[i] = strdup("");
81         }
82         ic_misc = strdup("");
83
84         output_headers(1, 1, 2, 0, 0, 0, 0);
85         wprintf("<div id=\"banner\">\n");
86         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
87         wprintf("<SPAN CLASS=\"titlebar\">Internet configuration</SPAN>\n");
88         wprintf("</TD></TR></TABLE>\n");
89         wprintf("</div><div id=\"text\">\n");
90
91         serv_printf("CONF GETSYS|application/x-citadel-internet-config");
92         serv_gets(buf);
93         if (buf[0] == '1') while (serv_gets(buf), strcmp(buf, "000")) {
94
95                 extract(ename, buf, 0);
96                 extract(etype, buf, 1);
97                 which = (-1);
98                 for (i=0; i<ic_max; ++i) {
99                         if (!strcasecmp(etype, ic_keyword[i])) {
100                                 which = i;
101                         }
102                 }
103
104                 if (which >= 0) {
105                         ic_spec[which] = realloc(ic_spec[which], strlen(ic_spec[which]) + strlen(ename) + 2);
106                         if (strlen(ic_spec[which]) > 0) strcat(ic_spec[which], "\n");
107                         strcat(ic_spec[which], ename);
108                 }
109                 else {
110                         ic_misc = realloc(ic_misc, strlen(ic_misc) + strlen(buf) + 2);
111                         if (strlen(ic_misc) > 0) strcat(ic_misc, "\n");
112                         strcat(ic_misc, buf);
113                 }
114
115         }
116
117         wprintf("<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>\n");
153
154         wDumpContent(1);
155
156         for (i=0; i<ic_max; ++i) {
157                 free(ic_spec[i]);
158         }
159         free(ic_misc);
160 }
161
162
163 void save_inetconf(void) {
164         char buf[SIZ];
165         char ename[SIZ];
166         char etype[SIZ];
167         char newconfig[65536];
168
169         strcpy(newconfig, "");
170         serv_printf("CONF GETSYS|application/x-citadel-internet-config");
171         serv_gets(buf);
172         if (buf[0] == '1') while (serv_gets(buf), strcmp(buf, "000")) {
173                 extract(ename, buf, 0);
174                 extract(etype, buf, 1);
175                 if (strlen(buf) == 0) {
176                         /* skip blank lines */
177                 }
178                 else if ((!strcasecmp(ename, bstr("ename")))
179                    &&   (!strcasecmp(etype, bstr("etype")))
180                    &&   (!strcasecmp(bstr("oper"), "delete"))
181                 ) {
182                         sprintf(WC->ImportantMessage, "%s deleted.", ename);
183                 }
184                 else {
185                         if (strlen(newconfig) > 0) strcat(newconfig, "\n");
186                         strcat(newconfig, buf);
187                 }
188         }
189
190         serv_printf("CONF PUTSYS|application/x-citadel-internet-config");
191         serv_gets(buf);
192         if (buf[0] == '4') {
193                 serv_puts(newconfig);
194                 if (!strcasecmp(bstr("oper"), "add")) {
195                         serv_printf("%s|%s", bstr("ename"), bstr("etype") );
196                         sprintf(WC->ImportantMessage, "%s added.", bstr("ename"));
197                 }
198                 serv_puts("000");
199         }
200         
201         display_inetconf();
202 }