5 * \defgroup NetShareConf Functions which handle network and sharing configuration.
7 * \ingroup CitadelConfig
12 void display_netconf(void);
14 /*----------------------------------------------------------------------*/
16 /*----------------------------------------------------------------------*/
18 typedef struct _nodeconf {
26 void DeleteNodeConf(void *vNode)
28 NodeConf *Node = (NodeConf*) vNode;
29 FreeStrBuf(&Node->NodeName);
30 FreeStrBuf(&Node->Secret);
31 FreeStrBuf(&Node->Host);
32 FreeStrBuf(&Node->Port);
36 NodeConf *NewNode(StrBuf *SerializedNode)
40 if (StrLength(SerializedNode) < 8)
41 return NULL; /** we need at least 4 pipes and some other text so its invalid. */
42 Node = (NodeConf *) malloc(sizeof(NodeConf));
44 Node->NodeName=NewStrBuf();
45 StrBufExtract_token(Node->NodeName, SerializedNode, 0, '|');
46 Node->Secret=NewStrBuf();
47 StrBufExtract_token(Node->Secret, SerializedNode, 1, '|');
48 Node->Host=NewStrBuf();
49 StrBufExtract_token(Node->Host, SerializedNode, 2, '|');
50 Node->Port=NewStrBuf();
51 StrBufExtract_token(Node->Port, SerializedNode, 3, '|');
55 NodeConf *HttpGetNewNode(void)
59 if (!havebstr("node") ||
65 Node = (NodeConf *) malloc(sizeof(NodeConf));
67 Node->NodeName = NewStrBufDup(sbstr("node"));
68 Node->Secret = NewStrBufDup(sbstr("secret"));
69 Node->Host = NewStrBufDup(sbstr("host"));
70 Node->Port = NewStrBufDup(sbstr("port"));
74 void SerializeNode(NodeConf *Node, StrBuf *Buf)
76 StrBufPrintf(Buf, "%s|%s|%s|%s",
77 ChrPtr(Node->NodeName),
84 HashList *load_netconf(WCTemplateToken *Token)
94 serv_puts("CONF getsys|application/x-citadel-ignet-config");
95 serv_getln(buf, sizeof buf);
97 Hash = NewHash(1, NULL);
100 while ((len = StrBuf_ServGetln(Buf),
101 strcmp(ChrPtr(Buf), "000"))) {
105 nUsed = GetCount(Hash);
106 nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
107 Put(Hash, nnn, nUsed, Node, DeleteNodeConf);
116 void NodeCfgSubst(StrBuf *TemplBuffer, void *vContext, WCTemplateToken *Token)
118 NodeConf *Node= (NodeConf*)vContext;
120 SVPutBuf("CFG:IGNET:NODE", Node->NodeName, 1);
121 SVPutBuf("CFG:IGNET:SECRET", Node->Secret, 1);
122 SVPutBuf("CFG:IGNET:HOST", Node->Host, 1);
123 SVPutBuf("CFG:IGNET:PORT", Node->Port, 1);
127 void save_net_conf(HashList *Nodelist)
137 serv_puts("CONF putsys|application/x-citadel-ignet-config");
138 serv_getln(buf, sizeof buf);
140 if ((Nodelist != NULL) && (GetCount(Nodelist) > 0)) {
141 where = GetNewHashPos();
143 while (GetNextHashPos(Nodelist, where, &KeyLen, &Key, &vNode)) {
144 Node = (NodeConf*) vNode;
145 if (Node->DeleteMe==0) {
146 SerializeNode(Node, Buf);
158 /*----------------------------------------------------------------------*/
160 /*----------------------------------------------------------------------*/
165 * \brief edit a network node
167 void edit_node(void) {
168 HashList *NodeConfig;
177 if (havebstr("ok_button")) {
178 Index = sbstr("index");
179 NewNode = HttpGetNewNode();
180 if ((NewNode == NULL) || (Index == NULL)) {
181 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
186 NodeConfig = load_netconf(NULL);
187 Put(NodeConfig, ChrPtr(Index), StrLength(Index), NewNode, DeleteNodeConf);
188 save_net_conf(NodeConfig);
189 DeleteHash(&NodeConfig);
191 strcpy(node, bstr("node") );
194 serv_puts("CONF getsys|application/x-citadel-ignet-config");
195 serv_getln(buf, sizeof buf);
197 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
198 extract_token(cnode, buf, 0, '|', sizeof cnode);
199 if (strcasecmp(node, cnode)) {
200 fprintf(fp, "%s\n", buf);
206 serv_puts("CONF putsys|application/x-citadel-ignet-config");
207 serv_getln(buf, sizeof buf);
210 while (fgets(buf, sizeof buf, fp) != NULL) {
211 buf[strlen(buf)-1] = 0;
218 serv_printf("%s|%s|%s|%s",
237 void display_add_node(void)
239 output_headers(1, 1, 2, 0, 0, 0);
240 wprintf("<div id=\"banner\">\n");
242 wprintf(_("Add a new node"));
246 wprintf("<div id=\"content\" class=\"service\">\n");
248 wprintf("<FORM METHOD=\"POST\" action=\"edit_node\">\n");
249 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
250 wprintf("<CENTER><TABLE border=0>\n");
251 wprintf("<TR><TD>%s</TD>", _("Node name"));
252 wprintf("<TD><INPUT TYPE=\"text\" NAME=\"node\" MAXLENGTH=\"16\"></TD></TR>\n");
253 wprintf("<TR><TD>%s</TD>", _("Shared secret"));
254 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"secret\" MAXLENGTH=\"16\"></TD></TR>\n");
255 wprintf("<TR><TD>%s</TD>", _("Host or IP address"));
256 wprintf("<TD><INPUT TYPE=\"text\" NAME=\"host\" MAXLENGTH=\"64\"></TD></TR>\n");
257 wprintf("<TR><TD>%s</TD>", _("Port number"));
258 wprintf("<TD><INPUT TYPE=\"text\" NAME=\"port\" VALUE=\"504\" MAXLENGTH=\"8\"></TD></TR>\n");
259 wprintf("</TABLE><br />");
260 wprintf("<INPUT TYPE=\"submit\" NAME=\"ok_button\" VALUE=\"%s\">", _("Add node"));
262 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
263 wprintf("</CENTER></FORM>\n");
270 * \brief modify an existing node
272 void display_edit_node(void)
274 HashList *NodeConfig;
278 Index = sbstr("index");
280 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
285 NodeConfig = load_netconf(NULL);
286 if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) ||
288 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
290 DeleteHash(&NodeConfig);
294 NodeCfgSubst(NULL, vNode, NULL);
295 SVPutBuf("ITERATE:KEY", Index, 1);
298 DeleteHash(&NodeConfig);
308 strcpy(node, bstr("node"));
310 output_headers(1, 1, 2, 0, 0, 0);
311 wprintf("<div id=\"banner\">\n");
313 wprintf(_("Edit node configuration for "));
318 wprintf("<div id=\"content\" class=\"service\">\n");
320 serv_puts("CONF getsys|application/x-citadel-ignet-config");
321 serv_getln(buf, sizeof buf);
323 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
324 extract_token(cnode, buf, 0, '|', sizeof cnode);
325 extract_token(csecret, buf, 1, '|', sizeof csecret);
326 extract_token(chost, buf, 2, '|', sizeof chost);
327 extract_token(cport, buf, 3, '|', sizeof cport);
329 if (!strcasecmp(node, cnode)) {
330 wprintf("<FORM METHOD=\"POST\" action=\"edit_node\">\n");
331 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
332 wprintf("<CENTER><TABLE border=0>\n");
334 wprintf(_("Node name"));
336 wprintf("<TD><INPUT TYPE=\"text\" NAME=\"node\" MAXLENGTH=\"16\" VALUE=\"%s\"></TD></TR>\n", cnode);
338 wprintf(_("Shared secret"));
340 wprintf("<TD><INPUT TYPE=\"password\" NAME=\"secret\" MAXLENGTH=\"16\" VALUE=\"%s\"></TD></TR>\n", csecret);
342 wprintf(_("Host or IP address"));
344 wprintf("<TD><INPUT TYPE=\"text\" NAME=\"host\" MAXLENGTH=\"64\" VALUE=\"%s\"></TD></TR>\n", chost);
346 wprintf(_("Port number"));
348 wprintf("<TD><INPUT TYPE=\"text\" NAME=\"port\" MAXLENGTH=\"8\" VALUE=\"%s\"></TD></TR>\n", cport);
349 wprintf("</TABLE><br />");
350 wprintf("<INPUT TYPE=\"submit\" NAME=\"ok_button\" VALUE=\"%s\">",
353 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">",
355 wprintf("</CENTER></FORM>\n");
361 else { / ** command error getting configuration * /
362 wprintf("%s<br />\n", &buf[4]);
374 * \brief display all configured nodes
376 void display_netconf(void)
381 output_headers(1, 1, 2, 0, 0, 0);
382 wprintf("<div id=\"banner\">\n");
384 wprintf(_("Network configuration"));
388 wprintf("<div id=\"content\" class=\"service\">\n");
391 wprintf("<a href=\"display_add_node\">");
392 wprintf(_("Add a new node"));
393 wprintf("</A><br />\n");
394 wprintf("</CENTER>");
396 wprintf("<TABLE class=\"netconf_banner\"><TR><TD>");
397 wprintf("<SPAN CLASS=\"titlebar\">");
398 wprintf(_("Currently configured nodes"));
399 wprintf("</SPAN>\n");
400 wprintf("</TD></TR></TABLE>\n");
401 serv_puts("CONF getsys|application/x-citadel-ignet-config");
402 serv_getln(buf, sizeof buf);
404 wprintf("<CENTER><TABLE border=0>\n");
405 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
406 extract_token(node, buf, 0, '|', sizeof node);
407 wprintf("<TR><TD><FONT SIZE=+1>");
409 wprintf("</FONT></TD>");
410 wprintf("<TD><a href=\"display_edit_node&node=");
413 wprintf(_("(Edit)"));
414 wprintf("</A></TD>");
415 wprintf("<TD><a href=\"display_confirm_delete_node&node=");
418 wprintf(_("(Delete)"));
419 wprintf("</A></TD>");
422 wprintf("</TABLE></CENTER>\n");
429 * \brief display the dialog to verify the deletion
431 void display_confirm_delete_node(void)
435 output_headers(1, 1, 2, 0, 0, 0);
436 wprintf("<div id=\"banner\">\n");
438 wprintf(_("Confirm delete"));
442 wprintf("<div id=\"content\" class=\"service\" >\n");
444 strcpy(node, bstr("node"));
446 wprintf(_("Are you sure you want to delete "));
447 wprintf("<FONT SIZE=+1>");
449 wprintf("</FONT>?<br />\n");
450 wprintf("<a href=\"delete_node&node=");
454 wprintf("</A> ");
455 wprintf("<a href=\"display_netconf\">");
457 wprintf("</A><br />\n");
464 * \brief actually delete the node
466 void delete_node(void)
468 HashList *NodeConfig;
473 Index = sbstr("index");
475 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
480 NodeConfig = load_netconf(NULL);
481 if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) ||
483 sprintf(WC->ImportantMessage, _("Invalid Parameter"));
485 DeleteHash(&NodeConfig);
488 Node = (NodeConf *) vNode;
490 save_net_conf(NodeConfig);
491 DeleteHash(&NodeConfig);
501 strcpy(node, bstr("node") );
504 serv_puts("CONF getsys|application/x-citadel-ignet-config");
505 serv_getln(buf, sizeof buf);
507 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
508 extract_token(cnode, buf, 0, '|', sizeof cnode);
509 if (strcasecmp(node, cnode)) {
510 fprintf(fp, "%s\n", buf);
516 serv_puts("CONF putsys|application/x-citadel-ignet-config");
517 serv_getln(buf, sizeof buf);
519 while (fgets(buf, sizeof buf, fp) != NULL) {
520 buf[strlen(buf)-1] = 0;
536 WebcitAddUrlHandler(HKEY("display_edit_node"), display_edit_node, 0);
538 WebcitAddUrlHandler(HKEY("edit_node"), edit_node, 0);
539 WebcitAddUrlHandler(HKEY("display_netconf"), display_netconf, 0);
540 WebcitAddUrlHandler(HKEY("display_confirm_delete_node"), display_confirm_delete_node, 0);
541 WebcitAddUrlHandler(HKEY("delete_node"), delete_node, 0);
542 WebcitAddUrlHandler(HKEY("display_add_node"), display_add_node, 0);
543 RegisterIterator("NODECONFIG", 0, NULL, load_netconf, NodeCfgSubst, DeleteHash, CTX_NODECONF);