* Templatize IGNet Node Config
authorWilfried Göesgens <willi@citadel.org>
Thu, 11 Sep 2008 14:05:50 +0000 (14:05 +0000)
committerWilfried Göesgens <willi@citadel.org>
Thu, 11 Sep 2008 14:05:50 +0000 (14:05 +0000)
webcit/netconf.c
webcit/static/t/add_node.html [new file with mode: 0644]
webcit/static/t/aide_global_config.html
webcit/static/t/display_ignet_confirmdelete.html [new file with mode: 0644]
webcit/static/t/display_netconf.html [new file with mode: 0644]
webcit/static/t/edit_node.html [new file with mode: 0644]
webcit/static/t/section_ignetconf.html [new file with mode: 0644]
webcit/subst.c
webcit/webcit.h
webcit/who.c

index 8b76a86b9b53fcfdf3ebfc1acdf3b699644af731..e152800f5bd7091315d465f3700e999126c0fa30 100644 (file)
 
 void display_netconf(void);
 
+/*----------------------------------------------------------------------*/
+/*              Business Logic                                          */
+/*----------------------------------------------------------------------*/
+
+typedef struct _nodeconf {
+       int DeleteMe;
+       StrBuf *NodeName;
+       StrBuf *Secret;
+       StrBuf *Host;
+       StrBuf *Port;
+}NodeConf;
+
+void DeleteNodeConf(void *vNode)
+{
+       NodeConf *Node = (NodeConf*) vNode;
+       FreeStrBuf(&Node->NodeName);
+       FreeStrBuf(&Node->Secret);
+       FreeStrBuf(&Node->Host);
+       FreeStrBuf(&Node->Port);
+       free(Node);
+}
+
+NodeConf *NewNode(StrBuf *SerializedNode)
+{
+       NodeConf *Node;
+
+       if (StrLength(SerializedNode) < 8) 
+               return NULL; /** we need at least 4 pipes and some other text so its invalid. */
+       Node = (NodeConf *) malloc(sizeof(NodeConf));
+       Node->DeleteMe = 0;
+       Node->NodeName=NewStrBuf();
+       StrBufExtract_token(Node->NodeName, SerializedNode, 0, '|');
+       Node->Secret=NewStrBuf();
+       StrBufExtract_token(Node->Secret, SerializedNode, 1, '|');
+       Node->Host=NewStrBuf();
+       StrBufExtract_token(Node->Host, SerializedNode, 2, '|');
+       Node->Port=NewStrBuf();
+       StrBufExtract_token(Node->Port, SerializedNode, 3, '|');
+       return Node;
+}
+
+NodeConf *HttpGetNewNode(void)
+{
+       NodeConf *Node;
+
+       if (!havebstr("node") || 
+           !havebstr("secret")||
+           !havebstr("host")||
+           !havebstr("port"))
+               return NULL;
+
+       Node = (NodeConf *) malloc(sizeof(NodeConf));
+       Node->DeleteMe = 0;
+       Node->NodeName = NewStrBufDup(sbstr("node"));
+       Node->Secret = NewStrBufDup(sbstr("secret"));
+       Node->Host = NewStrBufDup(sbstr("host"));
+       Node->Port = NewStrBufDup(sbstr("port"));
+       return Node;
+}
+
+void SerializeNode(NodeConf *Node, StrBuf *Buf)
+{
+       StrBufPrintf(Buf, "%s|%s|%s|%s", 
+                    ChrPtr(Node->NodeName),
+                    ChrPtr(Node->Secret),
+                    ChrPtr(Node->Host),
+                    ChrPtr(Node->Port));
+}
+
+
+HashList *load_netconf(WCTemplateToken *Token)
+{
+       StrBuf *Buf;
+       HashList *Hash;
+       char nnn[64];
+       char buf[SIZ];
+       long len;
+       int nUsed;
+       NodeConf *Node;
+
+       serv_puts("CONF getsys|application/x-citadel-ignet-config");
+       serv_getln(buf, sizeof buf);
+       if (buf[0] == '1') {
+               Hash = NewHash(1, NULL);
+
+               Buf = NewStrBuf();
+               while ((len = StrBuf_ServGetln(Buf),
+                       strcmp(ChrPtr(Buf), "000"))) {
+                       Node = NewNode(Buf);
+                       if (Node == NULL)
+                               continue;
+                       nUsed = GetCount(Hash);
+                       nUsed = snprintf(nnn, sizeof(nnn), "%d", nUsed+1);
+                       Put(Hash, nnn, nUsed, Node, DeleteNodeConf); 
+               }
+               FreeStrBuf(&Buf);
+               return Hash;
+       }
+       return NULL;
+}
+
+
+void NodeCfgSubst(StrBuf *TemplBuffer, void *vContext, WCTemplateToken *Token)
+{
+       NodeConf *Node= (NodeConf*)vContext;
+
+       SVPutBuf("CFG:IGNET:NODE", Node->NodeName, 1);
+       SVPutBuf("CFG:IGNET:SECRET", Node->Secret, 1);
+       SVPutBuf("CFG:IGNET:HOST", Node->Host, 1);
+       SVPutBuf("CFG:IGNET:PORT", Node->Port, 1);
+}
+
+
+void save_net_conf(HashList *Nodelist)
+{
+       char buf[SIZ];
+       StrBuf *Buf;
+       HashPos *where;
+       void *vNode;
+       NodeConf *Node;
+       const char *Key;
+       long KeyLen;
+
+       serv_puts("CONF putsys|application/x-citadel-ignet-config");
+       serv_getln(buf, sizeof buf);
+       if (buf[0] == '4') {
+               if ((Nodelist != NULL) && (GetCount(Nodelist) > 0)) {
+                       where = GetNewHashPos();
+                       Buf = NewStrBuf();
+                       while (GetNextHashPos(Nodelist, where, &KeyLen, &Key, &vNode)) {
+                               Node = (NodeConf*) vNode;
+                               if (Node->DeleteMe==0) { 
+                                       SerializeNode(Node, Buf);
+                                       serv_putbuf(Buf);
+                               }
+                       }
+                       FreeStrBuf(&Buf);
+               }
+               serv_puts("000");
+       }
+}
+
+
+
+/*----------------------------------------------------------------------*/
+/*              WEB Handlers                                            */
+/*----------------------------------------------------------------------*/
+
+
+
 /**
  * \brief edit a network node
  */
 void edit_node(void) {
+       HashList *NodeConfig;
+       const StrBuf *Index;
+       NodeConf *NewNode;
+/*
        char buf[SIZ];
        char node[SIZ];
        char cnode[SIZ];
        FILE *fp;
-
+*/
        if (havebstr("ok_button")) {
+               Index = sbstr("index");
+               NewNode = HttpGetNewNode();
+               if ((NewNode == NULL) || (Index == NULL)) {
+                       sprintf(WC->ImportantMessage, _("Invalid Parameter"));
+                       url_do_template();
+                       return;
+               }
+                       
+               NodeConfig = load_netconf(NULL);
+               Put(NodeConfig, ChrPtr(Index), StrLength(Index), NewNode, DeleteNodeConf);
+               save_net_conf(NodeConfig);
+               DeleteHash(&NodeConfig);
+/*
                strcpy(node, bstr("node") );
                fp = tmpfile();
                if (fp != NULL) {
@@ -56,9 +223,11 @@ void edit_node(void) {
                        }
                        serv_puts("000");
                }
+*/
        }
 
-       display_netconf();
+       //display_netconf();
+       url_do_template();
 }
 
 
@@ -66,7 +235,7 @@ void edit_node(void) {
  * \brief add a node
  */
 void display_add_node(void)
-{
+{/*
        output_headers(1, 1, 2, 0, 0, 0);
        wprintf("<div id=\"banner\">\n");
        wprintf("<h1>");
@@ -94,6 +263,7 @@ void display_add_node(void)
        wprintf("</CENTER></FORM>\n");
 
        wDumpContent(1);
+ */
 }
 
 /**
@@ -101,6 +271,33 @@ void display_add_node(void)
  */
 void display_edit_node(void)
 {
+       HashList *NodeConfig;
+       const StrBuf *Index;
+       void *vNode;
+
+       Index = sbstr("index");
+       if (Index == NULL) {
+               sprintf(WC->ImportantMessage, _("Invalid Parameter"));
+               url_do_template();
+               return;
+       }
+
+       NodeConfig = load_netconf(NULL);
+       if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) || 
+           (vNode == NULL)) {
+               sprintf(WC->ImportantMessage, _("Invalid Parameter"));
+               url_do_template();
+               DeleteHash(&NodeConfig);
+               return;
+       }
+       
+       NodeCfgSubst(NULL, vNode, NULL);
+       SVPutBuf("ITERATE:KEY", Index, 1);
+       url_do_template();
+
+       DeleteHash(&NodeConfig);
+       
+/*
        char buf[512];
        char node[256];
        char cnode[256];
@@ -161,22 +358,26 @@ void display_edit_node(void)
                }
        }
 
-       else {          /** command error getting configuration */
+       else {          / ** command error getting configuration * /
                wprintf("%s<br />\n", &buf[4]);
        }
 
        wDumpContent(1);
+*/
 }
 
 
+
+
+//CFG:IGNET:NODE
 /**
  * \brief display all configured nodes
  */
 void display_netconf(void)
 {
+/*
        char buf[SIZ];
        char node[SIZ];
-
        output_headers(1, 1, 2, 0, 0, 0);
        wprintf("<div id=\"banner\">\n");
        wprintf("<h1>");
@@ -220,6 +421,7 @@ void display_netconf(void)
                }
                wprintf("</TABLE></CENTER>\n");
        }
+*/
        wDumpContent(1);
 }
 
@@ -228,8 +430,8 @@ void display_netconf(void)
  */
 void display_confirm_delete_node(void)
 {
+/*
        char node[SIZ];
-
        output_headers(1, 1, 2, 0, 0, 0);
        wprintf("<div id=\"banner\">\n");
        wprintf("<h1>");
@@ -253,14 +455,44 @@ void display_confirm_delete_node(void)
        wprintf("<a href=\"display_netconf\">");
        wprintf(_("No"));
        wprintf("</A><br />\n");
+*/
        wDumpContent(1);
 }
 
+
 /**
  * \brief actually delete the node
  */
 void delete_node(void)
 {
+       HashList *NodeConfig;
+       const StrBuf *Index;
+       NodeConf *Node;
+       void *vNode;
+
+       Index = sbstr("index");
+       if (Index == NULL) {
+               sprintf(WC->ImportantMessage, _("Invalid Parameter"));
+               url_do_template();
+               return;
+       }
+
+       NodeConfig = load_netconf(NULL);
+       if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) || 
+           (vNode == NULL)) {
+               sprintf(WC->ImportantMessage, _("Invalid Parameter"));
+               url_do_template();
+               DeleteHash(&NodeConfig);
+               return;
+       }
+       Node = (NodeConf *) vNode;
+       Node->DeleteMe = 1;
+               save_net_conf(NodeConfig);
+       DeleteHash(&NodeConfig);
+       
+       url_do_template();
+
+/*
        char buf[SIZ];
        char node[SIZ];
        char cnode[SIZ];
@@ -294,6 +526,7 @@ void delete_node(void)
        }
 
        display_netconf();
+*/
 }
 
 void 
@@ -307,5 +540,6 @@ InitModule_NETCONF
        WebcitAddUrlHandler(HKEY("display_confirm_delete_node"), display_confirm_delete_node, 0);
        WebcitAddUrlHandler(HKEY("delete_node"), delete_node, 0);
        WebcitAddUrlHandler(HKEY("display_add_node"), display_add_node, 0);
+       RegisterIterator("NODECONFIG", 0, NULL, load_netconf, NodeCfgSubst, DeleteHash);
 }
 /*@}*/
diff --git a/webcit/static/t/add_node.html b/webcit/static/t/add_node.html
new file mode 100644 (file)
index 0000000..afa1f93
--- /dev/null
@@ -0,0 +1,29 @@
+<?=("head")>
+<?=("important_msg")>
+<?ICONBAR>
+<div id="banner">
+<h1>
+<?_("Add a new node")>
+</h1>
+</div>
+
+<div id="content" class="service">
+<form method="POST" action="edit_node">
+<input type="hidden" name="nonce" value="<?NONCE>">
+<input type="hidden" name="template" value="display_netconf">
+<input type="hidden" name="index" value="-1">
+<center><table border=0>
+<tr><td><?_("Node name")></td>
+<td><input type="text" name="node" maxlength="16"></td></tr>
+<tr><td><?_("Shared secret")></td>
+<td><input type="password" name="secret" maxlength="16"></td></tr>
+<tr><td><?_("Host or IP address")></td>
+<td><input type="text" name="host" maxlength="64"></td></tr>
+<tr><td><?_("Port number")></td>
+<td><input type="text" name="port" value="504" maxlength="8"></td></tr>
+</table><br />
+<input type="submit" name="ok_button" value="<?_("Add node?")>">
+&nbsp;
+<input type="submit" name="cancel_button" value="<?_("Cancel")>">
+</center></form>
+<?=("trailing")>
index 3149e66c31e06f07a7fde683849785135207a221..aa8e79b70cf7f04a534bdf8b98045e4616b22b9b 100644 (file)
@@ -1,6 +1,6 @@
 <ul class="adminitems">
 <li><a href="do_template?template=display_sitewide_config"><?_("Edit site-wide configuration")></a></li>
 <li><a href="do_template?template=aide_inetconf"><?_("Domain names and Internet mail configuration")></a></li>
-<li><a href="display_netconf"><?_("Configure replication with other Citadel servers")></a></li>
+<li><a href="do_template?template=display_netconf"><?_("Configure replication with other Citadel servers")></a></li>
 <li><a href="display_smtpqueue"><?_("View the outbound SMTP queue")></a></li>
 </ul>
diff --git a/webcit/static/t/display_ignet_confirmdelete.html b/webcit/static/t/display_ignet_confirmdelete.html
new file mode 100644 (file)
index 0000000..c431339
--- /dev/null
@@ -0,0 +1,18 @@
+<?=("head")>
+<?=("important_msg")>
+<?ICONBAR>
+<div id="banner">
+<h1>
+<?_("Confirm delete")> <?BSTR("node")>
+</h1>
+</div>
+
+<div id="content" class="service">
+<center>
+<?_("Are you sure you want to delete ")>
+<font SIZE=+1><?BSTR("node")></font>
+</center>
+<a href="delete_node?template=display_netconf&node=<?BSTR("node", "X")>&index=<?BSTR("index")>"><?_("Yes")></a>
+&nbsp;&nbsp;&nbsp;
+<a href="do_template?template=display_netconf"><?_("No")></a><br />
+<?=("trailing")>
diff --git a/webcit/static/t/display_netconf.html b/webcit/static/t/display_netconf.html
new file mode 100644 (file)
index 0000000..23e769a
--- /dev/null
@@ -0,0 +1,22 @@
+<?=("head")>
+<?=("important_msg")>
+<?ICONBAR>
+<div id="banner">
+  <h1><?_("Network configuration")></h1>
+</div>
+
+<div id="content" class="service">
+
+<center>
+<a href="do_template?template=add_node"><?_("Add a new node")></a><br />
+</center>
+
+<table class="netconf_banner"><tr><td>
+<span class="titlebar"><?_("Currently configured nodes")></span>
+</td></tr></table>
+
+<center><table border=0>
+<?ITERATE("NODECONFIG", "section_ignetconf")>
+</table></center>
+
+<?=("trailing")>
diff --git a/webcit/static/t/edit_node.html b/webcit/static/t/edit_node.html
new file mode 100644 (file)
index 0000000..198730d
--- /dev/null
@@ -0,0 +1,29 @@
+<?=("head")>
+<?=("important_msg")>
+<?ICONBAR>
+<div id="banner">
+<h1>
+<?_("Add a new node")>
+</h1>
+</div>
+
+<div id="content" class="service">
+<form method="POST" action="edit_node">
+<input type="hidden" name="nonce" value="<?NONCE>">
+<input type="hidden" name="template" value="display_netconf">
+<input type="hidden" name="index" value='<?ITERATE:KEY>'>
+<center><table border=0>
+<tr><td><?_("Node name")></td>
+<td><input type="text" name="node" maxlength="16" value='<?CFG:IGNET:NODE>'></td></tr>
+<tr><td><?_("Shared secret")></td>
+<td><input type="password" name="secret" maxlength="16" value='<?CFG:IGNET:SECRET>'></td></tr>
+<tr><td><?_("Host or IP address")></td>
+<td><input type="text" name="host" maxlength="64" value='<?CFG:IGNET:HOST>'></td></tr>
+<tr><td><?_("Port number")></td>
+<td><input type="text" name="port" value='<?CFG:IGNET:PORT>' maxlength="8"></td></tr>
+</table><br />
+<input type="submit" name="ok_button" value="<?_("Save changes?")>">
+&nbsp;
+<input type="submit" name="cancel_button" value="<?_("Cancel")>">
+</center></form>
+<?=("trailing")>
diff --git a/webcit/static/t/section_ignetconf.html b/webcit/static/t/section_ignetconf.html
new file mode 100644 (file)
index 0000000..bf9c9ca
--- /dev/null
@@ -0,0 +1,6 @@
+<tr><td><font SIZE=+1>
+<?CFG:IGNET:NODE("X")>
+</font></td>
+<td><a href="display_edit_node?template=edit_node&node=<?CFG:IGNET:NODE>&index=<?ITERATE:KEY>"><?_("(Edit)")></a></td>
+<td><a href="do_template?template=display_ignet_confirmdelete&node=<?CFG:IGNET:NODE("X")>&index=<?ITERATE:KEY>"><?_("(Delete)")></a></td>
+</tr>
index 0aa6bb0709a997daf989e633d70e1e67af57f4e5..32000bb3fc4f7c59b8fe89a55191c37589dcde07 100644 (file)
@@ -376,7 +376,7 @@ inline void SVCALLBACK(char *keyname, var_callback_fptr fcn_ptr)
 
 
 
-void SVPUTBuf(const char *keyname, int keylen, StrBuf *Buf, int ref)
+void SVPUTBuf(const char *keyname, int keylen, const StrBuf *Buf, int ref)
 {
        wcsubst *ptr;
        void *vPtr;
@@ -396,7 +396,7 @@ void SVPUTBuf(const char *keyname, int keylen, StrBuf *Buf, int ref)
        {
                ptr = NewSubstVar(keyname, keylen, (ref)?WCS_STRBUF_REF:WCS_STRBUF);
        }
-       ptr->wcs_value = Buf;
+       ptr->wcs_value = (StrBuf*)Buf;
 }
 
 /**
@@ -1299,7 +1299,7 @@ void tmpl_iterate_subtmpl(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo
        FreeStrBuf(&SubBuf);
        DeleteHashPos(&it);
        if (It->Destructor != NULL)
-               It->Destructor(List);
+               It->Destructor(&List);
 }
 
 int ConditionalVar(WCTemplateToken *Tokens, void *Context)
index 717645ea9031e5d58e4c7eca3c994ea41560879e..5d678c3f6b098835c2932ccbeae8563b5502e579 100644 (file)
@@ -322,7 +322,7 @@ void RegisterConditional(const char *Name, long len,
 
 typedef void (*SubTemplFunc)(StrBuf *TemplBuffer, void *Context, WCTemplateToken *Token);
 typedef HashList *(*RetrieveHashlistFunc)(WCTemplateToken *Token);
-typedef void (*HashDestructorFunc) (HashList *KillMe);
+typedef void (*HashDestructorFunc) (HashList **KillMe);
 void RegisterITERATOR(const char *Name, long len,
                      int AdditionalParams, 
                      HashList *StaticList, 
@@ -677,7 +677,7 @@ void SVCALLBACK(char *keyname, var_callback_fptr fcn_ptr);
 void SVCallback(char *keyname, size_t keylen,  var_callback_fptr fcn_ptr);
 #define svcallback(a, b) SVCallback(a, sizeof(a) - 1, b)
 
-void SVPUTBuf(const char *keyname, int keylen, StrBuf *Buf, int ref);
+void SVPUTBuf(const char *keyname, int keylen, const StrBuf *Buf, int ref);
 #define SVPutBuf(a, b, c); SVPUTBuf(a, sizeof(a) - 1, b, c)
 
 void DoTemplate(const char *templatename, long len, void *Context, StrBuf *Target);
index 0d78dee59eef68f95747068f6c467d80b0d5af95..0cc06bc8adeead255652e3b6481d37f5e6a7ebac 100644 (file)
@@ -481,9 +481,9 @@ void WholistSubst(StrBuf *TemplBuffer, void *vContext, WCTemplateToken *Token)
        svputlong("WHO:ISME", (User->Session == WC->ctdl_pid));
 }
 
-void DeleteWholistHash(HashList *KillMe)
+void DeleteWholistHash(HashList **KillMe)
 {
-       DeleteHash(&KillMe);
+       DeleteHash(KillMe);
 }
 
 void