\n");
- wDumpContent(1);
-}
+/*----------------------------------------------------------------------*/
+/* WEB Handlers */
+/*----------------------------------------------------------------------*/
-/**
- * \brief modify an existing node
- */
-void display_edit_node(void)
-{
- char buf[512];
- char node[256];
- char cnode[256];
- char csecret[256];
- char chost[256];
- char cport[256];
-
- strcpy(node, bstr("node"));
-
- output_headers(1, 1, 2, 0, 0, 0);
- wprintf("
\n");
- serv_puts("CONF getsys|application/x-citadel-ignet-config");
- serv_getln(buf, sizeof buf);
- if (buf[0] == '1') {
- while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
- extract_token(cnode, buf, 0, '|', sizeof cnode);
- extract_token(csecret, buf, 1, '|', sizeof csecret);
- extract_token(chost, buf, 2, '|', sizeof chost);
- extract_token(cport, buf, 3, '|', sizeof cport);
-
- if (!strcasecmp(node, cnode)) {
- wprintf("
\n");
- }
+/*
+ * edit a network node
+ */
+void edit_node(void) {
+ HashList *NodeConfig;
+ const StrBuf *Index;
+ NodeConf *NewNode;
+
+ if (havebstr("ok_button")) {
+ Index = sbstr("index");
+ NewNode = HttpGetNewNode();
+ if ((NewNode == NULL) || (Index == NULL)) {
+ AppendImportantMessage(_("Invalid Parameter"), -1);
+ url_do_template();
+ return;
}
+
+ NodeConfig = load_netconf(NULL, &NoCtx);
+ Put(NodeConfig, ChrPtr(Index), StrLength(Index), NewNode, DeleteNodeConf);
+ save_net_conf(NodeConfig);
+ DeleteHash(&NodeConfig);
}
+ url_do_template();
+}
+
- else { /** command error getting configuration */
- wprintf("%s
\n", &buf[4]);
+/*
+ * modify an existing node
+ */
+void display_edit_node(void) {
+ WCTemplputParams SubTP;
+ HashList *NodeConfig;
+ const StrBuf *Index;
+ void *vNode;
+ const StrBuf *Tmpl;
+
+ Index = sbstr("index");
+ if (Index == NULL) {
+ AppendImportantMessage(_("Invalid Parameter"), -1);
+ url_do_template();
+ return;
}
- wDumpContent(1);
+ NodeConfig = load_netconf(NULL, &NoCtx);
+ if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) ||
+ (vNode == NULL)) {
+ AppendImportantMessage(_("Invalid Parameter"), -1);
+ url_do_template();
+ DeleteHash(&NodeConfig);
+ return;
+ }
+ StackContext(NULL, &SubTP, vNode, CTX_NODECONF, 0, NULL);
+ {
+ begin_burst();
+ Tmpl = sbstr("template");
+ output_headers(1, 0, 0, 0, 1, 0);
+ DoTemplate(SKEY(Tmpl), NULL, &SubTP);
+ end_burst();
+ }
+ UnStackContext(&SubTP);
+ DeleteHash(&NodeConfig);
+
}
-/**
- * \brief display all configured nodes
+/*
+ * display all configured nodes
*/
-void display_netconf(void)
-{
- char buf[SIZ];
- char node[SIZ];
-
- output_headers(1, 1, 2, 0, 0, 0);
- wprintf("
\n");
- wprintf("
");
- wprintf("");
- wprintf(_("Network configuration"));
- wprintf("\n");
- wprintf(" |
\n");
- wprintf("
\n
\n");
-
- wprintf("
");
- wprintf("");
- wprintf(_("Add a new node"));
- wprintf("
\n");
- wprintf("");
-
- wprintf("
");
- wprintf("");
- wprintf(_("Currently configured nodes"));
- wprintf("\n");
- wprintf(" |
\n");
- serv_puts("CONF getsys|application/x-citadel-ignet-config");
- serv_getln(buf, sizeof buf);
- if (buf[0] == '1') {
- wprintf("
\n");
- }
+void display_netconf(void) {
wDumpContent(1);
}
-/**
- * \brief display the dialog to verify the deletion
+/*
+ * display the dialog to verify the deletion
*/
-void display_confirm_delete_node(void)
-{
- char node[SIZ];
-
- output_headers(1, 1, 2, 0, 0, 0);
- wprintf("
\n");
- wprintf("
");
- wprintf("");
- wprintf(_("Confirm delete"));
- wprintf("\n");
- wprintf(" |
\n");
- wprintf("
\n
\n");
-
- strcpy(node, bstr("node"));
- wprintf("
");
- wprintf(_("Are you sure you want to delete "));
- wprintf("");
- escputs(node);
- wprintf("?
\n");
- wprintf("");
- wprintf(_("Yes"));
- wprintf(" ");
- wprintf("");
- wprintf(_("No"));
- wprintf("
\n");
+void display_confirm_delete_node(void) {
wDumpContent(1);
}
-/**
- * \brief actually delete the node
+
+/*
+ * actually delete the node
*/
-void delete_node(void)
-{
- char buf[SIZ];
- char node[SIZ];
- char cnode[SIZ];
- FILE *fp;
-
- strcpy(node, bstr("node") );
- fp = tmpfile();
- if (fp != NULL) {
- serv_puts("CONF getsys|application/x-citadel-ignet-config");
- serv_getln(buf, sizeof buf);
- if (buf[0] == '1') {
- while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
- extract_token(cnode, buf, 0, '|', sizeof cnode);
- if (strcasecmp(node, cnode)) {
- fprintf(fp, "%s\n", buf);
- }
- }
- }
- rewind(fp);
-
- serv_puts("CONF putsys|application/x-citadel-ignet-config");
- serv_getln(buf, sizeof buf);
- if (buf[0] == '4') {
- while (fgets(buf, sizeof buf, fp) != NULL) {
- buf[strlen(buf)-1] = 0;
- serv_puts(buf);
- }
- serv_puts("000");
- }
- fclose(fp);
+void delete_node(void) {
+ HashList *NodeConfig;
+ const StrBuf *Index;
+ NodeConf *Node;
+ void *vNode;
+
+ Index = sbstr("index");
+ if (Index == NULL) {
+ AppendImportantMessage(_("Invalid Parameter"), -1);
+ url_do_template();
+ return;
+ }
+
+ NodeConfig = load_netconf(NULL, &NoCtx);
+ if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) ||
+ (vNode == NULL)) {
+ AppendImportantMessage(_("Invalid Parameter"), -1);
+ url_do_template();
+ DeleteHash(&NodeConfig);
+ return;
}
+ Node = (NodeConf *) vNode;
+ Node->DeleteMe = 1;
+ save_net_conf(NodeConfig);
+ DeleteHash(&NodeConfig);
+
+ url_do_template();
- display_netconf();
}
-/**
- * \brief add a new node
- */
-void add_node(void)
-{
- char node[SIZ];
- char buf[SIZ];
- strcpy(node, bstr("node"));
-
- if (strlen(bstr("add_button")) > 0) {
- sprintf(buf, "NSET addnode|%s", node);
- serv_puts(buf);
- serv_getln(buf, sizeof buf);
- if (buf[0] == '1') {
- output_headers(1, 1, 0, 0, 0, 0);
- server_to_text();
- wprintf("");
- wprintf(_("Back to menu"));
- wprintf("\n");
- wDumpContent(1);
- } else {
- strcpy(WC->ImportantMessage, &buf[4]);
- display_netconf();
- }
- }
+void tmplput_NodeName(StrBuf *Target, WCTemplputParams *TP) {
+ NodeConf *Node = (NodeConf*) CTX(CTX_NODECONF);
+ StrBufAppendTemplate(Target, TP, Node->NodeName, 0);
}
+void tmplput_Secret(StrBuf *Target, WCTemplputParams *TP) {
+ NodeConf *Node = (NodeConf*) CTX(CTX_NODECONF);
+ StrBufAppendTemplate(Target, TP, Node->Secret, 0);
+}
+
+void tmplput_Host(StrBuf *Target, WCTemplputParams *TP) {
+ NodeConf *Node= (NodeConf*) CTX(CTX_NODECONF);
+ StrBufAppendTemplate(Target, TP, Node->Host, 0);
+}
+
+void tmplput_Port(StrBuf *Target, WCTemplputParams *TP) {
+ NodeConf *Node= (NodeConf*) CTX(CTX_NODECONF);
+ StrBufAppendTemplate(Target, TP, Node->Port, 0);
+}
-/*@}*/
+void
+InitModule_NETCONF
+(void)
+{
+ RegisterCTX(CTX_NODECONF);
+ WebcitAddUrlHandler(HKEY("display_edit_node"), "", 0, display_edit_node, 0);
+
+ WebcitAddUrlHandler(HKEY("aide_ignetconf_edit_node"), "", 0, edit_node, 0);
+ WebcitAddUrlHandler(HKEY("display_netconf"), "", 0, display_netconf, 0);
+ WebcitAddUrlHandler(HKEY("display_confirm_delete_node"), "", 0, display_confirm_delete_node, 0);
+ WebcitAddUrlHandler(HKEY("delete_node"), "", 0, delete_node, 0);
+
+
+ RegisterNamespace("CFG:IGNET:NODE", 0, 1, tmplput_NodeName, NULL, CTX_NODECONF);
+ RegisterNamespace("CFG:IGNET:SECRET", 0, 1, tmplput_Secret, NULL, CTX_NODECONF);
+ RegisterNamespace("CFG:IGNET:HOST", 0, 1, tmplput_Host, NULL, CTX_NODECONF);
+ RegisterNamespace("CFG:IGNET:PORT", 0, 1, tmplput_Port, NULL, CTX_NODECONF);
+
+ RegisterIterator("NODECONFIG", 0, NULL, load_netconf, NULL, DeleteHash, CTX_NODECONF, CTX_NONE, IT_NOFLAG);
+}