* Removed all of the absolute URL's.
[citadel.git] / webcit / netconf.c
1 /* 
2  * $Id$
3  *
4  * Functions which handle network and sharing configuration.
5  *
6  */
7
8 #include "webcit.h"
9
10 void edit_node(void) {
11         char buf[SIZ];
12         char node[SIZ];
13         char cnode[SIZ];
14         FILE *fp;
15
16         if (strlen(bstr("ok_button")) > 0) {
17                 strcpy(node, bstr("node") );
18                 fp = tmpfile();
19                 if (fp != NULL) {
20                         serv_puts("CONF getsys|application/x-citadel-ignet-config");
21                         serv_getln(buf, sizeof buf);
22                         if (buf[0] == '1') {
23                                 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
24                                         extract_token(cnode, buf, 0, '|', sizeof cnode);
25                                         if (strcasecmp(node, cnode)) {
26                                                 fprintf(fp, "%s\n", buf);
27                                         }
28                                 }
29                         fprintf(fp, "%s|%s|%s|%s\n", 
30                                 bstr("node"),
31                                 bstr("secret"),
32                                 bstr("host"),
33                                 bstr("port") );
34                         }
35                         rewind(fp);
36
37                         serv_puts("CONF putsys|application/x-citadel-ignet-config");
38                         serv_getln(buf, sizeof buf);
39                         if (buf[0] == '4') {
40                                 while (fgets(buf, sizeof buf, fp) != NULL) {
41                                         buf[strlen(buf)-1] = 0;
42                                         serv_puts(buf);
43                                 }
44                                 serv_puts("000");
45                         }
46                         fclose(fp);
47                 }
48         }
49
50         display_netconf();
51 }
52
53
54
55 void display_add_node(void)
56 {
57         output_headers(1, 1, 2, 0, 0, 0);
58         wprintf("<div id=\"banner\">\n");
59         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
60         wprintf("<SPAN CLASS=\"titlebar\">");
61         wprintf(_("Add a new node"));
62         wprintf("</SPAN>");
63         wprintf("</TD></TR></TABLE>\n");
64         wprintf("</div>\n<div id=\"content\">\n");
65
66         wprintf("<FORM METHOD=\"POST\" action=\"edit_node\">\n");
67         wprintf("<CENTER><TABLE border=0>\n");
68         wprintf("<TR><TD>%s</TD>", _("Node name"));
69         wprintf("<TD><INPUT TYPE=\"text\" NAME=\"node\" MAXLENGTH=\"16\"></TD></TR>\n");
70         wprintf("<TR><TD>%s</TD>", _("Shared secret"));
71         wprintf("<TD><INPUT TYPE=\"password\" NAME=\"secret\" MAXLENGTH=\"16\"></TD></TR>\n");
72         wprintf("<TR><TD>%s</TD>", _("Host or IP address"));
73         wprintf("<TD><INPUT TYPE=\"text\" NAME=\"host\" MAXLENGTH=\"64\"></TD></TR>\n");
74         wprintf("<TR><TD>%s</TD>", _("Port number"));
75         wprintf("<TD><INPUT TYPE=\"text\" NAME=\"port\" MAXLENGTH=\"8\"></TD></TR>\n");
76         wprintf("</TABLE><br />");
77         wprintf("<INPUT TYPE=\"submit\" NAME=\"ok_button\" VALUE=\"%s\">", _("Add node"));
78         wprintf("&nbsp;");
79         wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
80         wprintf("</CENTER></FORM>\n");
81
82         wDumpContent(1);
83 }
84
85 void display_edit_node(void)
86 {
87         char buf[512];
88         char node[256];
89         char cnode[256];
90         char csecret[256];
91         char chost[256];
92         char cport[256];
93
94         strcpy(node, bstr("node"));
95
96         output_headers(1, 1, 2, 0, 0, 0);
97         wprintf("<div id=\"banner\">\n");
98         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
99         wprintf("<SPAN CLASS=\"titlebar\">");
100         wprintf(_("Edit node configuration for "));
101         escputs(node);
102         wprintf("</SPAN>\n");
103         wprintf("</TD></TR></TABLE>\n");
104         wprintf("</div>\n<div id=\"content\">\n");
105
106         serv_puts("CONF getsys|application/x-citadel-ignet-config");
107         serv_getln(buf, sizeof buf);
108         if (buf[0] == '1') {
109                 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
110                         extract_token(cnode, buf, 0, '|', sizeof cnode);
111                         extract_token(csecret, buf, 1, '|', sizeof csecret);
112                         extract_token(chost, buf, 2, '|', sizeof chost);
113                         extract_token(cport, buf, 3, '|', sizeof cport);
114
115                         if (!strcasecmp(node, cnode)) {
116                                 wprintf("<FORM METHOD=\"POST\" action=\"edit_node\">\n");
117                                 wprintf("<CENTER><TABLE border=0>\n");
118                                 wprintf("<TR><TD>");
119                                 wprintf(_("Node name"));
120                                 wprintf("</TD>");
121                                 wprintf("<TD><INPUT TYPE=\"text\" NAME=\"node\" MAXLENGTH=\"16\" VALUE=\"%s\"></TD></TR>\n", cnode);
122                                 wprintf("<TR><TD>");
123                                 wprintf(_("Shared secret"));
124                                 wprintf("</TD>");
125                                 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"secret\" MAXLENGTH=\"16\" VALUE=\"%s\"></TD></TR>\n", csecret);
126                                 wprintf("<TR><TD>");
127                                 wprintf(_("Host or IP address"));
128                                 wprintf("</TD>");
129                                 wprintf("<TD><INPUT TYPE=\"text\" NAME=\"host\" MAXLENGTH=\"64\" VALUE=\"%s\"></TD></TR>\n", chost);
130                                 wprintf("<TR><TD>");
131                                 wprintf(_("Port number"));
132                                 wprintf("</TD>");
133                                 wprintf("<TD><INPUT TYPE=\"text\" NAME=\"port\" MAXLENGTH=\"8\" VALUE=\"%s\"></TD></TR>\n", cport);
134                                 wprintf("</TABLE><br />");
135                                 wprintf("<INPUT TYPE=\"submit\" NAME=\"ok_button\" VALUE=\"%s\">",
136                                         _("Save changes"));
137                                 wprintf("&nbsp;");
138                                 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">",
139                                         _("Cancel"));
140                                 wprintf("</CENTER></FORM>\n");
141                         }
142
143                 }
144         }
145
146         else {          /* command error getting configuration */
147                 wprintf("%s<br />\n", &buf[4]);
148         }
149
150         wDumpContent(1);
151 }
152
153
154
155 void display_netconf(void)
156 {
157         char buf[SIZ];
158         char node[SIZ];
159
160         output_headers(1, 1, 2, 0, 0, 0);
161         wprintf("<div id=\"banner\">\n");
162         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
163         wprintf("<SPAN CLASS=\"titlebar\">");
164         wprintf(_("Network configuration"));
165         wprintf("</SPAN>\n");
166         wprintf("</TD></TR></TABLE>\n");
167         wprintf("</div>\n<div id=\"content\">\n");
168
169         wprintf("<CENTER>");
170         wprintf("<a href=\"display_add_node\">");
171         wprintf(_("Add a new node"));
172         wprintf("</A><br />\n");
173         wprintf("</CENTER>");
174
175         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
176         wprintf("<SPAN CLASS=\"titlebar\">");
177         wprintf(_("Currently configured nodes"));
178         wprintf("</SPAN>\n");
179         wprintf("</TD></TR></TABLE>\n");
180         serv_puts("CONF getsys|application/x-citadel-ignet-config");
181         serv_getln(buf, sizeof buf);
182         if (buf[0] == '1') {
183                 wprintf("<CENTER><TABLE border=0>\n");
184                 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
185                         extract_token(node, buf, 0, '|', sizeof node);
186                         wprintf("<TR><TD><FONT SIZE=+1>");
187                         escputs(node);
188                         wprintf("</FONT></TD>");
189                         wprintf("<TD><a href=\"display_edit_node&node=");
190                         urlescputs(node);
191                         wprintf("\">");
192                         wprintf(_("(Edit)"));
193                         wprintf("</A></TD>");
194                         wprintf("<TD><a href=\"display_confirm_delete_node&node=");
195                         urlescputs(node);
196                         wprintf("\">");
197                         wprintf(_("(Delete)"));
198                         wprintf("</A></TD>");
199                         wprintf("</TR>\n");
200                 }
201                 wprintf("</TABLE></CENTER>\n");
202         }
203         wDumpContent(1);
204 }
205
206
207 void display_confirm_delete_node(void)
208 {
209         char node[SIZ];
210
211         output_headers(1, 1, 2, 0, 0, 0);
212         wprintf("<div id=\"banner\">\n");
213         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
214         wprintf("<SPAN CLASS=\"titlebar\">");
215         wprintf(_("Confirm delete"));
216         wprintf("</SPAN>\n");
217         wprintf("</TD></TR></TABLE>\n");
218         wprintf("</div>\n<div id=\"content\">\n");
219
220         strcpy(node, bstr("node"));
221         wprintf("<CENTER>");
222         wprintf(_("Are you sure you want to delete "));
223         wprintf("<FONT SIZE=+1>");
224         escputs(node);
225         wprintf("</FONT>?<br />\n");
226         wprintf("<a href=\"delete_node&node=");
227         urlescputs(node);
228         wprintf("\">");
229         wprintf(_("Yes"));
230         wprintf("</A>&nbsp;&nbsp;&nbsp;");
231         wprintf("<a href=\"display_netconf\">");
232         wprintf(_("No"));
233         wprintf("</A><br />\n");
234         wDumpContent(1);
235 }
236
237
238 void delete_node(void)
239 {
240         char buf[SIZ];
241         char node[SIZ];
242         char cnode[SIZ];
243         FILE *fp;
244
245         strcpy(node, bstr("node") );
246         fp = tmpfile();
247         if (fp != NULL) {
248                 serv_puts("CONF getsys|application/x-citadel-ignet-config");
249                 serv_getln(buf, sizeof buf);
250                 if (buf[0] == '1') {
251                         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
252                                 extract_token(cnode, buf, 0, '|', sizeof cnode);
253                                 if (strcasecmp(node, cnode)) {
254                                         fprintf(fp, "%s\n", buf);
255                                 }
256                         }
257                 }
258                 rewind(fp);
259
260                 serv_puts("CONF putsys|application/x-citadel-ignet-config");
261                 serv_getln(buf, sizeof buf);
262                 if (buf[0] == '4') {
263                         while (fgets(buf, sizeof buf, fp) != NULL) {
264                                 buf[strlen(buf)-1] = 0;
265                                 serv_puts(buf);
266                         }
267                         serv_puts("000");
268                 }
269                 fclose(fp);
270         }
271
272         display_netconf();
273 }
274
275
276 void add_node(void)
277 {
278         char node[SIZ];
279         char buf[SIZ];
280
281         strcpy(node, bstr("node"));
282
283         if (strlen(bstr("add_button")) > 0)  {
284                 sprintf(buf, "NSET addnode|%s", node);
285                 serv_puts(buf);
286                 serv_getln(buf, sizeof buf);
287                 if (buf[0] == '1') {
288                         output_headers(1, 1, 0, 0, 0, 0);
289                         server_to_text();
290                         wprintf("<a href=\"display_netconf\">");
291                         wprintf(_("Back to menu"));
292                         wprintf("</A>\n");
293                         wDumpContent(1);
294                 } else {
295                         strcpy(WC->ImportantMessage, &buf[4]);
296                         display_netconf();
297                 }
298         }
299 }
300
301