* we have now several bstrs:
[citadel.git] / webcit / netconf.c
index 8b73b8d7a9e24387a12cd26b1d56865b350d0164..ee7c5a91fd7f4bf4e30dbe568453873f71c99fa8 100644 (file)
@@ -1,19 +1,24 @@
 /* 
  * $Id$
+ */
+/**
+ * \defgroup NetShareConf Functions which handle network and sharing configuration.
  *
- * Functions which handle network and sharing configuration.
- *
+ * \ingroup CitadelConfig
  */
-
+/*@{*/
 #include "webcit.h"
 
+/**
+ * \brief edit a network node
+ */
 void edit_node(void) {
        char buf[SIZ];
        char node[SIZ];
        char cnode[SIZ];
        FILE *fp;
 
-       if (strlen(bstr("ok_button")) > 0) {
+       if (havebstr("ok_button")) {
                strcpy(node, bstr("node") );
                fp = tmpfile();
                if (fp != NULL) {
@@ -26,24 +31,28 @@ void edit_node(void) {
                                                fprintf(fp, "%s\n", buf);
                                        }
                                }
-                       fprintf(fp, "%s|%s|%s|%s\n", 
-                               bstr("node"),
-                               bstr("secret"),
-                               bstr("host"),
-                               bstr("port") );
-                       }
                        rewind(fp);
+               }
 
-                       serv_puts("CONF putsys|application/x-citadel-ignet-config");
-                       serv_getln(buf, sizeof buf);
-                       if (buf[0] == '4') {
+               serv_puts("CONF putsys|application/x-citadel-ignet-config");
+               serv_getln(buf, sizeof buf);
+               if (buf[0] == '4') {
+                       if (fp != NULL) {
                                while (fgets(buf, sizeof buf, fp) != NULL) {
                                        buf[strlen(buf)-1] = 0;
-                                       serv_puts(buf);
+                                       if (buf[0] != 0) {
+                                               serv_puts(buf);
+                                       }
                                }
-                               serv_puts("000");
+                               fclose(fp);
                        }
-                       fclose(fp);
+                       serv_printf("%s|%s|%s|%s", 
+                               bstr("node"),
+                               bstr("secret"),
+                               bstr("host"),
+                               bstr("port") );
+                       }
+                       serv_puts("000");
                }
        }
 
@@ -51,19 +60,22 @@ 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("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
-       wprintf("<SPAN CLASS=\"titlebar\">");
+       wprintf("<h1>");
        wprintf(_("Add a new node"));
-       wprintf("</SPAN>");
-       wprintf("</TD></TR></TABLE>\n");
-       wprintf("</div>\n<div id=\"content\">\n");
+       wprintf("</h1>");
+       wprintf("</div>\n");
+
+       wprintf("<div id=\"content\" class=\"service\">\n");
 
-       wprintf("<FORM METHOD=\"POST\" action=\"/edit_node\">\n");
+       wprintf("<FORM METHOD=\"POST\" action=\"edit_node\">\n");
+       wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
        wprintf("<CENTER><TABLE border=0>\n");
        wprintf("<TR><TD>%s</TD>", _("Node name"));
        wprintf("<TD><INPUT TYPE=\"text\" NAME=\"node\" MAXLENGTH=\"16\"></TD></TR>\n");
@@ -72,7 +84,7 @@ void display_add_node(void)
        wprintf("<TR><TD>%s</TD>", _("Host or IP address"));
        wprintf("<TD><INPUT TYPE=\"text\" NAME=\"host\" MAXLENGTH=\"64\"></TD></TR>\n");
        wprintf("<TR><TD>%s</TD>", _("Port number"));
-       wprintf("<TD><INPUT TYPE=\"text\" NAME=\"port\" MAXLENGTH=\"8\"></TD></TR>\n");
+       wprintf("<TD><INPUT TYPE=\"text\" NAME=\"port\" VALUE=\"504\" MAXLENGTH=\"8\"></TD></TR>\n");
        wprintf("</TABLE><br />");
                wprintf("<INPUT TYPE=\"submit\" NAME=\"ok_button\" VALUE=\"%s\">", _("Add node"));
        wprintf("&nbsp;");
@@ -82,6 +94,9 @@ void display_add_node(void)
        wDumpContent(1);
 }
 
+/**
+ * \brief modify an existing node
+ */
 void display_edit_node(void)
 {
        char buf[512];
@@ -95,13 +110,13 @@ void display_edit_node(void)
 
        output_headers(1, 1, 2, 0, 0, 0);
        wprintf("<div id=\"banner\">\n");
-       wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
-       wprintf("<SPAN CLASS=\"titlebar\">");
+       wprintf("<h1>");
        wprintf(_("Edit node configuration for "));
        escputs(node);
-       wprintf("</SPAN>\n");
-       wprintf("</TD></TR></TABLE>\n");
-       wprintf("</div>\n<div id=\"content\">\n");
+       wprintf("</h1>");
+       wprintf("</div>\n");
+
+       wprintf("<div id=\"content\" class=\"service\">\n");
 
        serv_puts("CONF getsys|application/x-citadel-ignet-config");
        serv_getln(buf, sizeof buf);
@@ -113,7 +128,8 @@ void display_edit_node(void)
                        extract_token(cport, buf, 3, '|', sizeof cport);
 
                        if (!strcasecmp(node, cnode)) {
-                               wprintf("<FORM METHOD=\"POST\" action=\"/edit_node\">\n");
+                               wprintf("<FORM METHOD=\"POST\" action=\"edit_node\">\n");
+                               wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
                                wprintf("<CENTER><TABLE border=0>\n");
                                wprintf("<TR><TD>");
                                wprintf(_("Node name"));
@@ -143,7 +159,7 @@ void display_edit_node(void)
                }
        }
 
-       else {          /* command error getting configuration */
+       else {          /** command error getting configuration */
                wprintf("%s<br />\n", &buf[4]);
        }
 
@@ -151,7 +167,9 @@ void display_edit_node(void)
 }
 
 
-
+/**
+ * \brief display all configured nodes
+ */
 void display_netconf(void)
 {
        char buf[SIZ];
@@ -159,20 +177,20 @@ void display_netconf(void)
 
        output_headers(1, 1, 2, 0, 0, 0);
        wprintf("<div id=\"banner\">\n");
-       wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
-       wprintf("<SPAN CLASS=\"titlebar\">");
+       wprintf("<h1>");
        wprintf(_("Network configuration"));
-       wprintf("</SPAN>\n");
-       wprintf("</TD></TR></TABLE>\n");
-       wprintf("</div>\n<div id=\"content\">\n");
+       wprintf("</h1>");
+       wprintf("</div>\n");
+
+       wprintf("<div id=\"content\" class=\"service\">\n");
 
        wprintf("<CENTER>");
-       wprintf("<a href=\"/display_add_node\">");
+       wprintf("<a href=\"display_add_node\">");
        wprintf(_("Add a new node"));
        wprintf("</A><br />\n");
        wprintf("</CENTER>");
 
-       wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
+       wprintf("<TABLE class=\"netconf_banner\"><TR><TD>");
        wprintf("<SPAN CLASS=\"titlebar\">");
        wprintf(_("Currently configured nodes"));
        wprintf("</SPAN>\n");
@@ -186,12 +204,12 @@ void display_netconf(void)
                        wprintf("<TR><TD><FONT SIZE=+1>");
                        escputs(node);
                        wprintf("</FONT></TD>");
-                       wprintf("<TD><a href=\"/display_edit_node&node=");
+                       wprintf("<TD><a href=\"display_edit_node&node=");
                        urlescputs(node);
                        wprintf("\">");
                        wprintf(_("(Edit)"));
                        wprintf("</A></TD>");
-                       wprintf("<TD><a href=\"/display_confirm_delete_node&node=");
+                       wprintf("<TD><a href=\"display_confirm_delete_node&node=");
                        urlescputs(node);
                        wprintf("\">");
                        wprintf(_("(Delete)"));
@@ -203,19 +221,21 @@ void display_netconf(void)
        wDumpContent(1);
 }
 
-
+/**
+ * \brief 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("<div id=\"banner\">\n");
-       wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#444455\"><TR><TD>");
-       wprintf("<SPAN CLASS=\"titlebar\">");
+       wprintf("<h1>");
        wprintf(_("Confirm delete"));
-       wprintf("</SPAN>\n");
-       wprintf("</TD></TR></TABLE>\n");
-       wprintf("</div>\n<div id=\"content\">\n");
+       wprintf("</h1>");
+       wprintf("</div>\n");
+
+       wprintf("<div id=\"content\" class=\"service\" >\n");
 
        strcpy(node, bstr("node"));
        wprintf("<CENTER>");
@@ -223,18 +243,20 @@ void display_confirm_delete_node(void)
        wprintf("<FONT SIZE=+1>");
        escputs(node);
        wprintf("</FONT>?<br />\n");
-       wprintf("<a href=\"/delete_node&node=");
+       wprintf("<a href=\"delete_node&node=");
        urlescputs(node);
        wprintf("\">");
        wprintf(_("Yes"));
        wprintf("</A>&nbsp;&nbsp;&nbsp;");
-       wprintf("<a href=\"/display_netconf\">");
+       wprintf("<a href=\"display_netconf\">");
        wprintf(_("No"));
        wprintf("</A><br />\n");
        wDumpContent(1);
 }
 
-
+/**
+ * \brief actually delete the node
+ */
 void delete_node(void)
 {
        char buf[SIZ];
@@ -273,29 +295,4 @@ void delete_node(void)
 }
 
 
-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("<a href=\"/display_netconf\">");
-                       wprintf(_("Back to menu"));
-                       wprintf("</A>\n");
-                       wDumpContent(1);
-               } else {
-                       strcpy(WC->ImportantMessage, &buf[4]);
-                       display_netconf();
-               }
-       }
-}
-
-
+/*@}*/