[Openvas-commits] r6206 - in trunk/gsa: . src src/html/src src/html/src/help

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Dec 18 18:31:50 CET 2009


Author: mattm
Date: 2009-12-18 18:31:49 +0100 (Fri, 18 Dec 2009)
New Revision: 6206

Modified:
   trunk/gsa/ChangeLog
   trunk/gsa/src/CMakeLists.txt
   trunk/gsa/src/gsad.c
   trunk/gsa/src/gsad_omp.c
   trunk/gsa/src/gsad_omp.h
   trunk/gsa/src/html/src/help/configure_agents.htm4
   trunk/gsa/src/html/src/omp.xsl
Log:
	Enable agent download button.

	* src/gsad.c (init_validator): Add "agent_format".
	(struct req_parms): Add fields for agent installer and HOWTO.
	(free_resources): Free installer and HOWTO fields.
	(serve_post): Fill installer and HOWTO fields.
	(exec_omp_post): Pass installer and HOWTO fields to create_agent_omp.
	(exec_omp_get): Expect format in request parameter "agent_format"
	instead of in "package_format".  Switch MIME type to
	application/octet-stream.

	* src/gsad_omp.c (create_agent_omp): Add installer and HOWTO args.  Encode
	installer and HOWTO before sending.

	* src/gsad_omp.h: Update header.

	* src/html/src/omp.xsl (agent): Enable single download button.

	* src/html/src/help/configure_agents.htm4: Correct typo.  Use agent.png.
	Close comment.

	* src/CMakeLists.txt: Neaten heading description.

Modified: trunk/gsa/ChangeLog
===================================================================
--- trunk/gsa/ChangeLog	2009-12-18 17:17:36 UTC (rev 6205)
+++ trunk/gsa/ChangeLog	2009-12-18 17:31:49 UTC (rev 6206)
@@ -1,5 +1,30 @@
 2009-12-18  Matthew Mundell <matthew.mundell at intevation.de>
 
+	Enable agent download button.
+
+	* src/gsad.c (init_validator): Add "agent_format".
+	(struct req_parms): Add fields for agent installer and HOWTO.
+	(free_resources): Free installer and HOWTO fields.
+	(serve_post): Fill installer and HOWTO fields.
+	(exec_omp_post): Pass installer and HOWTO fields to create_agent_omp.
+	(exec_omp_get): Expect format in request parameter "agent_format"
+	instead of in "package_format".  Switch MIME type to
+	application/octet-stream.
+
+	* src/gsad_omp.c (create_agent_omp): Add installer and HOWTO args.  Encode
+	installer and HOWTO before sending.
+
+	* src/gsad_omp.h: Update header.
+
+	* src/html/src/omp.xsl (agent): Enable single download button.
+
+	* src/html/src/help/configure_agents.htm4: Correct typo.  Use agent.png.
+	Close comment.
+
+	* src/CMakeLists.txt: Neaten heading description.
+
+2009-12-18  Matthew Mundell <matthew.mundell at intevation.de>
+
 	* src/CMakeLists.txt: Remove HEADERS_TEMP and LIBS_TEMP as the OpenVAS
 	flags are provided by other variables.  Set OpenVAS compile flags on
 	gsad_omp and gsad_oap.

Modified: trunk/gsa/src/CMakeLists.txt
===================================================================
--- trunk/gsa/src/CMakeLists.txt	2009-12-18 17:17:36 UTC (rev 6205)
+++ trunk/gsa/src/CMakeLists.txt	2009-12-18 17:31:49 UTC (rev 6206)
@@ -1,6 +1,6 @@
 # Greenbone Security Assistant
 # $Id$
-# Description: CMakefile for gsad sources
+# Description: CMakefile for GSAD sources.
 #
 # Authors:
 # Matthew Mundell <matthew.mundell at intevation.de>

Modified: trunk/gsa/src/gsad.c
===================================================================
--- trunk/gsa/src/gsad.c	2009-12-18 17:17:36 UTC (rev 6205)
+++ trunk/gsa/src/gsad.c	2009-12-18 17:31:49 UTC (rev 6206)
@@ -195,6 +195,7 @@
                          "|(start_task)"
                          "|(sync_feed)$");
 
+  openvas_validator_add (validator, "agent_format", "^(installer)$");
   openvas_validator_add (validator, "boolean",    "^0|1$");
   openvas_validator_add (validator, "comment",    "^[-_[:alnum:], \\./]{0,400}$");
   openvas_validator_add (validator, "create_credentials_type", "^(gen|pass)$");
@@ -275,6 +276,12 @@
     char *pw;            ///< Value of "pw" parameter.
     char *password;      ///< Value of "password" parameter.
     char *timeout;       ///< Value of "timeout" parameter.
+    char *installer;     ///< Value of "installer" parameter.
+    int installer_size;  ///< Size of "installer" parameter.
+    char *howto_install; ///< Value of "howto_install" parameter.
+    int howto_install_size; ///< Size of "howto_install" parameter.
+    char *howto_use;     ///< Value of "howto_use" parameter.
+    int howto_use_size;  ///< Size of "howto_use" parameter.
     GArray *passwords;   ///< Collection of "password:*" parameters.
     GArray *preferences; ///< Collection of "preference:*" parameters.
     GArray *nvts;        ///< Collection of "nvt:*" parameters.
@@ -496,6 +503,18 @@
     {
       free (con_info->req_parms.timeout);
     }
+  if (con_info->req_parms.installer)
+    {
+      free (con_info->req_parms.installer);
+    }
+  if (con_info->req_parms.howto_install)
+    {
+      free (con_info->req_parms.howto_install);
+    }
+  if (con_info->req_parms.howto_use)
+    {
+      free (con_info->req_parms.howto_use);
+    }
   if (con_info->req_parms.preferences)
     {
       preference_t *item;
@@ -831,6 +850,34 @@
           con_info->answercode = MHD_HTTP_OK;
           return MHD_YES;
         }
+      if (!strcmp (key, "installer"))
+        {
+          con_info->req_parms.installer = malloc (size + 1);
+          memcpy ((char *) con_info->req_parms.installer, (char *) data, size);
+          con_info->req_parms.installer_size = size;
+          con_info->answercode = MHD_HTTP_OK;
+          return MHD_YES;
+        }
+      if (!strcmp (key, "howto_install"))
+        {
+          con_info->req_parms.howto_install = malloc (size + 1);
+          memcpy ((char *) con_info->req_parms.howto_install,
+                  (char *) data,
+                  size);
+          con_info->req_parms.howto_install_size = size;
+          con_info->answercode = MHD_HTTP_OK;
+          return MHD_YES;
+        }
+      if (!strcmp (key, "howto_use"))
+        {
+          con_info->req_parms.howto_use = malloc (size + 1);
+          memcpy ((char *) con_info->req_parms.howto_use,
+                  (char *) data,
+                  size);
+          con_info->req_parms.howto_use_size = size;
+          con_info->answercode = MHD_HTTP_OK;
+          return MHD_YES;
+        }
       if (!strncmp (key, "nvt:", strlen ("nvt:")))
         {
           gchar *nvt = g_strdup (key + strlen ("nvt:"));
@@ -1050,7 +1097,13 @@
       con_info->response =
         create_agent_omp (credentials,
                           con_info->req_parms.name,
-                          con_info->req_parms.comment);
+                          con_info->req_parms.comment,
+                          con_info->req_parms.installer,
+                          con_info->req_parms.installer_size,
+                          con_info->req_parms.howto_install,
+                          con_info->req_parms.howto_install_size,
+                          con_info->req_parms.howto_use,
+                          con_info->req_parms.howto_use_size);
     }
   else if (!strcmp (con_info->req_parms.cmd, "create_lsc_credential"))
     {
@@ -1309,6 +1362,7 @@
 exec_omp_get (struct MHD_Connection *connection)
 {
   char *cmd = NULL;
+  const char *agent_format = NULL;
   const char *task_id = NULL;
   const char *report_id = NULL;
   const char *format = NULL;
@@ -1361,6 +1415,13 @@
       if (openvas_validate (validator, "oid", oid))
         oid = NULL;
 
+      agent_format = MHD_lookup_connection_value
+                      (connection,
+                       MHD_GET_ARGUMENT_KIND,
+                       "agent_format");
+      if (openvas_validate (validator, "agent_format", agent_format))
+        agent_format = NULL;
+
       format = MHD_lookup_connection_value (connection,
                                             MHD_GET_ARGUMENT_KIND,
                                             "format");
@@ -1513,13 +1574,13 @@
                                sort_order, 1);
 
   else if (0 == strcmp (cmd, "get_agents")
-           && ((name == NULL && package_format == NULL)
-               || (name && package_format)))
+           && ((name == NULL && agent_format == NULL)
+               || (name && agent_format)))
     {
       if (name == NULL)
         return get_agents_omp (credentials,
                                name,
-                               package_format,
+                               agent_format,
                                &response_size,
                                sort_field,
                                sort_order);
@@ -1528,17 +1589,15 @@
        * @todo
        * Get these sizes from constants that are also used by gsad_params.
        */
-      content_type = calloc (16, sizeof (char));
-      snprintf (content_type, 16, "application/%s", package_format);
+      content_type = calloc (25, sizeof (char));
+      snprintf (content_type, 25, "application/octet-stream");
       content_disposition = calloc (250, sizeof (char));
-      snprintf (content_disposition, 250,
-                "attachment; filename=%s",  // FIXME
-                name);
+      snprintf (content_disposition, 250, "attachment; filename=agent.bin");
 
       /** @todo On fail, HTML ends up in file. */
       return get_agents_omp (credentials,
                              name,
-                             package_format,
+                             agent_format,
                              &response_size,
                              NULL,
                              NULL);

Modified: trunk/gsa/src/gsad_omp.c
===================================================================
--- trunk/gsa/src/gsad_omp.c	2009-12-18 17:17:36 UTC (rev 6205)
+++ trunk/gsa/src/gsad_omp.c	2009-12-18 17:31:49 UTC (rev 6206)
@@ -1020,16 +1020,21 @@
 /**
  * @brief Create an agent, get all agents, XSL transform result.
  *
- * @param[in]  credentials  Username and password for authentication.
- * @param[in]  name         Agent name.
- * @param[in]  comment      Comment on agent.
+ * @param[in]  credentials    Username and password for authentication.
+ * @param[in]  name           Agent name.
+ * @param[in]  comment        Comment on agent.
+ * @param[in]  installer      Installer, in base64.
+ * @param[in]  howto_install  Install HOWTO, in base64.
+ * @param[in]  howto_use      Usage HOWTO, in base64.
  *
  * @return Result of XSL transformation.
  */
 char *
-create_agent_omp (credentials_t * credentials,
-                  char *name,
-                  char *comment)
+create_agent_omp (credentials_t * credentials, const char *name,
+                  const char *comment,
+                  const char *installer, int installer_size,
+                  const char *howto_install, int howto_install_size,
+                  const char *howto_use, int howto_use_size)
 {
   entity_t entity;
   gnutls_session_t session;
@@ -1050,18 +1055,44 @@
   else
     {
       int ret;
+      gchar *installer_64, *howto_install_64, *howto_use_64;
 
       /* Create the agent. */
 
+      installer_64 = installer_size
+                     ? g_base64_encode ((guchar *) installer,
+                                        installer_size)
+                     : g_strdup ("");
+
+      howto_install_64 = howto_install_size
+                         ? g_base64_encode ((guchar *) howto_install,
+                                            howto_install_size)
+                         : g_strdup ("");
+
+      howto_use_64 = howto_use_size
+                     ? g_base64_encode ((guchar *) howto_use,
+                                        howto_use_size)
+                     : g_strdup ("");
+
       ret = openvas_server_sendf (&session,
                                   "<create_agent>"
                                   "<name>%s</name>"
                                   "%s%s%s"
+                                  "<installer>%s</installer>"
+                                  "<howto_install>%s</howto_install>"
+                                  "<howto_use>%s</howto_use>"
                                   "</create_agent>",
                                   name, comment ? "<comment>" : "",
                                   comment ? comment : "",
-                                  comment ? "</comment>" : "");
+                                  comment ? "</comment>" : "",
+                                  installer_64,
+                                  howto_install_64,
+                                  howto_use_64);
 
+      g_free (installer_64);
+      g_free (howto_install_64);
+      g_free (howto_use_64);
+
       if (ret == -1)
         {
           g_string_free (xml, TRUE);

Modified: trunk/gsa/src/gsad_omp.h
===================================================================
--- trunk/gsa/src/gsad_omp.h	2009-12-18 17:17:36 UTC (rev 6205)
+++ trunk/gsa/src/gsad_omp.h	2009-12-18 17:31:49 UTC (rev 6206)
@@ -63,7 +63,10 @@
 
 char * get_agents_omp (credentials_t *, const char *, const char *,
                        unsigned int *, const char *, const char *);
-char * create_agent_omp (credentials_t *, char *, char *);
+char * create_agent_omp (credentials_t *, const char *, const char *,
+                         const char *, int,
+                         const char *, int,
+                         const char *, int);
 char * delete_agent_omp (credentials_t *, const char *);
 
 char * get_targets_omp (credentials_t *, const char *, const char *);

Modified: trunk/gsa/src/html/src/help/configure_agents.htm4
===================================================================
--- trunk/gsa/src/html/src/help/configure_agents.htm4	2009-12-18 17:17:36 UTC (rev 6205)
+++ trunk/gsa/src/html/src/help/configure_agents.htm4	2009-12-18 17:31:49 UTC (rev 6206)
@@ -16,7 +16,7 @@
 <h2>New Agent</h2>
 
 <p>
-For creating a agent the dialog offers these entries.
+For creating an agent the dialog offers these entries.
 Hit the button "Create Agent" to submit the new agent.
 The list of agents will be updated.
 </p>
@@ -84,10 +84,10 @@
 
 <p>
 Pressing the download icon
-<img src="/img/rpm.png" alt="Download Installer Package" title="Download Installer Package" />
+<img src="/img/agent.png" alt="Download Installer Package" title="Download Installer Package" />
 will download a installation package for this agent.
 </p>
 
-<!-- TODO: Description for howto's.
+<!-- TODO: Description for howto's. -->
 
-m4_include(`footer.m4')
\ No newline at end of file
+m4_include(`footer.m4')

Modified: trunk/gsa/src/html/src/omp.xsl
===================================================================
--- trunk/gsa/src/html/src/omp.xsl	2009-12-18 17:17:36 UTC (rev 6205)
+++ trunk/gsa/src/html/src/omp.xsl	2009-12-18 17:31:49 UTC (rev 6206)
@@ -1613,20 +1613,10 @@
                style="margin-left:3px;"/>
         </xsl:otherwise>
       </xsl:choose>
-      <xsl:if test="type='gen'">
-        <a href="/omp?cmd=get_agents&amp;name={name}&amp;package_format=installer"
-           title="Download installer package" style="margin-left:3px;">
-          <img src="/img/agent.png" border="0" alt="Download Installer"/>
-        </a>
-        <a href="/omp?cmd=get_agents&amp;name={name}&amp;package_format=howto_install"
-           title="Download Howto on Installtion" style="margin-left:3px;">
-          <img src="/img/rpm.png" border="0" alt="Download Howto Install"/>
-        </a>
-        <a href="/omp?cmd=get_agents&amp;name={name}&amp;package_format=howto_use"
-           title="Download Howto on Using" style="margin-left:3px;">
-          <img src="/img/rpm.png" border="0" alt="Download Howto Use"/>
-        </a>
-      </xsl:if>
+      <a href="/omp?cmd=get_agents&amp;name={name}&amp;agent_format=installer"
+         title="Download installer package" style="margin-left:3px;">
+        <img src="/img/agent.png" border="0" alt="Download Installer"/>
+      </a>
     </td>
   </tr>
 </xsl:template>



More information about the Openvas-commits mailing list