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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sun Dec 27 19:24:16 CET 2009


Author: mattm
Date: 2009-12-27 19:24:13 +0100 (Sun, 27 Dec 2009)
New Revision: 6261

Modified:
   trunk/gsa/ChangeLog
   trunk/gsa/src/gsad.c
   trunk/gsa/src/gsad_omp.c
   trunk/gsa/src/gsad_omp.h
   trunk/gsa/src/html/src/omp.xsl
Log:
	Add a target details page.

	* src/gsad_omp.c (get_target_omp): New function.

	* src/gsad_omp.h: Add header.

	* src/gsad.c (init_validator): Add get_target command.
	(exec_omp_get): Handle command get_target.

	* src/html/src/omp.xsl (html-report-table): Link target to details.
	(target): Add details button.
	(target mode=details, get_target): New templates.

Modified: trunk/gsa/ChangeLog
===================================================================
--- trunk/gsa/ChangeLog	2009-12-27 18:14:58 UTC (rev 6260)
+++ trunk/gsa/ChangeLog	2009-12-27 18:24:13 UTC (rev 6261)
@@ -1,3 +1,18 @@
+2009-12-27  Matthew Mundell <matthew.mundell at intevation.de>
+
+	Add a target details page.
+
+	* src/gsad_omp.c (get_target_omp): New function.
+
+	* src/gsad_omp.h: Add header.
+
+	* src/gsad.c (init_validator): Add get_target command.
+	(exec_omp_get): Handle command get_target.
+
+	* src/html/src/omp.xsl (html-report-table): Link target to details.
+	(target): Add details button.
+	(target mode=details, get_target): New templates.
+
 2009-12-24  Matthew Mundell <matthew.mundell at intevation.de>
 
 	Add Escalators.

Modified: trunk/gsa/src/gsad.c
===================================================================
--- trunk/gsa/src/gsad.c	2009-12-27 18:14:58 UTC (rev 6260)
+++ trunk/gsa/src/gsad.c	2009-12-27 18:24:13 UTC (rev 6261)
@@ -190,6 +190,7 @@
                          "|(get_report)"
                          "|(get_settings)"
                          "|(get_status)"
+                         "|(get_target)"
                          "|(get_targets)"
                          "|(get_users)"
                          "|(save_config)"
@@ -1976,6 +1977,9 @@
   else if (!strcmp (cmd, "get_status"))
     return get_status_omp (credentials, NULL, sort_field, sort_order);
 
+  else if ((!strcmp (cmd, "get_target")) && (name != NULL))
+    return get_target_omp (credentials, name, sort_field, sort_order);
+
   else if (!strcmp (cmd, "get_targets"))
     return get_targets_omp (credentials, sort_field, sort_order);
 
@@ -2000,9 +2004,7 @@
                                sort_order, 0);
 
   else if ((!strcmp (cmd, "get_nvt_details")) && (oid != NULL))
-    {
-      return get_nvt_details_omp (credentials, oid);
-    }
+    return get_nvt_details_omp (credentials, oid);
 
   else if (!strcmp (cmd, "get_settings"))
     return get_settings_oap (credentials, sort_field, sort_order);

Modified: trunk/gsa/src/gsad_omp.c
===================================================================
--- trunk/gsa/src/gsad_omp.c	2009-12-27 18:14:58 UTC (rev 6260)
+++ trunk/gsa/src/gsad_omp.c	2009-12-27 18:24:13 UTC (rev 6261)
@@ -1948,6 +1948,75 @@
 }
 
 /**
+ * @brief Get one target, XSL transform the result.
+ *
+ * @param[in]  credentials  Username and password for authentication.
+ * @param[in]  name         Name of target.
+ * @param[in]  sort_field   Field to sort on, or NULL.
+ * @param[in]  sort_order   "ascending", "descending", or NULL.
+ *
+ * @return Result of XSL transformation.
+ */
+char *
+get_target_omp (credentials_t * credentials, const char * name,
+                const char * sort_field, const char * sort_order)
+{
+  entity_t entity;
+  GString *xml;
+  gnutls_session_t session;
+  int socket;
+
+  if (manager_connect (credentials, &socket, &session))
+    return gsad_message ("Internal error", __FUNCTION__, __LINE__,
+                         "An internal error occurred while getting targets list. "
+                         "The current list of targets is not available. "
+                         "Diagnostics: Failure to connect to manager daemon.",
+                         "/omp?cmd=get_targets");
+
+  xml = g_string_new ("<get_target>");
+
+  /* Get the target. */
+
+  if (openvas_server_sendf (&session,
+                            "<get_targets"
+                            " name=\"%s\""
+                            " sort_field=\"%s\""
+                            " sort_order=\"%s\"/>",
+                            name,
+                            sort_field ? sort_field : "name",
+                            sort_order ? sort_order : "ascending")
+      == -1)
+    {
+      g_string_free (xml, TRUE);
+      openvas_server_close (socket, session);
+      return gsad_message ("Internal error", __FUNCTION__, __LINE__,
+                           "An internal error occurred while getting targets list. "
+                           "The current list of targets is not available. "
+                           "Diagnostics: Failure to send command to manager daemon.",
+                           "/omp?cmd=get_targets");
+    }
+
+  entity = NULL;
+  if (read_entity_and_string (&session, &entity, &xml))
+    {
+      g_string_free (xml, TRUE);
+      openvas_server_close (socket, session);
+      return gsad_message ("Internal error", __FUNCTION__, __LINE__,
+                           "An internal error occurred while getting targets list. "
+                           "The current list of targets is not available. "
+                           "Diagnostics: Failure to receive response from manager daemon.",
+                           "/omp?cmd=get_targets");
+    }
+  free_entity (entity);
+
+  /* Cleanup, and return transformed XML. */
+
+  g_string_append (xml, "</get_target>");
+  openvas_server_close (socket, session);
+  return xsl_transform_omp (credentials, g_string_free (xml, FALSE));
+}
+
+/**
  * @brief Get all targets, XSL transform the result.
  *
  * @param[in]  credentials  Username and password for authentication.

Modified: trunk/gsa/src/gsad_omp.h
===================================================================
--- trunk/gsa/src/gsad_omp.h	2009-12-27 18:14:58 UTC (rev 6260)
+++ trunk/gsa/src/gsad_omp.h	2009-12-27 18:24:13 UTC (rev 6261)
@@ -76,6 +76,8 @@
                          const char *, int);
 char * delete_agent_omp (credentials_t *, const char *);
 
+char * get_target_omp (credentials_t *, const char *, const char *,
+                       const char *);
 char * get_targets_omp (credentials_t *, const char *, const char *);
 char * create_target_omp (credentials_t *, char *, char *, char *,
                           const char *);

Modified: trunk/gsa/src/html/src/omp.xsl
===================================================================
--- trunk/gsa/src/html/src/omp.xsl	2009-12-27 18:14:58 UTC (rev 6260)
+++ trunk/gsa/src/html/src/omp.xsl	2009-12-27 18:24:13 UTC (rev 6261)
@@ -565,7 +565,7 @@
         <tr>
           <td>Target:</td>
           <td>
-            <a href="/omp?cmd=get_targets">
+            <a href="/omp?cmd=get_target&amp;name={task/target/name}">
               <xsl:value-of select="task/target/name"/>
             </a>
           </td>
@@ -2056,12 +2056,97 @@
                style="margin-left:3px;"/>
         </xsl:otherwise>
       </xsl:choose>
+      <a href="/omp?cmd=get_target&amp;name={name}"
+         title="Target Details" style="margin-left:3px;">
+        <img src="/img/details.png" border="0" alt="Details"/>
+      </a>
     </td>
   </tr>
 </xsl:template>
 
-<!--     GET_TARGETS_RESPONSE -->
+<xsl:template match="target" mode="details">
+  <div class="gb_window">
+    <div class="gb_window_part_left"></div>
+    <div class="gb_window_part_right"></div>
+    <div class="gb_window_part_center">Target Details</div>
+    <div class="gb_window_part_content">
+      <div style="float:right;">
+        <a href="?cmd=get_targets">Back to Targets</a>
+      </div>
+      <table>
+        <tr>
+          <td><b>Name:</b></td>
+          <td><b><xsl:value-of select="name"/></b></td>
+        </tr>
+        <tr>
+          <td>Comment:</td>
+          <td><xsl:value-of select="summary"/></td>
+        </tr>
+        <tr>
+          <td>Hosts:</td>
+          <td><xsl:value-of select="hosts"/></td>
+        </tr>
+        <tr>
+          <td>Maximum number of hosts:</td>
+          <td><xsl:value-of select="max_hosts"/></td>
+        </tr>
+        <tr>
+          <td>Credential:</td>
+          <td>
+            <a href="/omp?cmd=get_lsc_credentials">
+              <xsl:value-of select="lsc_credential/name"/>
+            </a>
+          </td>
+        </tr>
+      </table>
 
+      <xsl:choose>
+        <xsl:when test="count(tasks/task) = 0">
+          <h1>Tasks using this Target: None</h1>
+        </xsl:when>
+        <xsl:otherwise>
+          <h1>Tasks using this Target</h1>
+          <table class="gbntable" cellspacing="2" cellpadding="4">
+            <tr class="gbntablehead2">
+              <td>Name</td>
+              <td>Actions</td>
+            </tr>
+            <xsl:for-each select="tasks/task">
+              <xsl:variable name="class">
+                <xsl:choose>
+                  <xsl:when test="position() mod 2 = 0">even</xsl:when>
+                  <xsl:otherwise>odd</xsl:otherwise>
+                </xsl:choose>
+              </xsl:variable>
+              <tr class="{$class}">
+                <td><xsl:value-of select="name"/></td>
+                <td width="100">
+                  <a href="/omp?cmd=get_status&amp;task_id={@id}" title="Reports">
+                    <img src="/img/list.png"
+                         border="0"
+                         alt="Reports"
+                         style="margin-left:3px;"/>
+                  </a>
+                </td>
+              </tr>
+            </xsl:for-each>
+          </table>
+        </xsl:otherwise>
+      </xsl:choose>
+    </div>
+  </div>
+</xsl:template>
+
+<!--     GET_TARGET -->
+
+<xsl:template match="get_target">
+  <xsl:apply-templates select="gsad_msg"/>
+  <xsl:apply-templates select="commands_response/delete_target_response"/>
+  <xsl:apply-templates select="get_targets_response/target" mode="details"/>
+</xsl:template>
+
+<!--     GET_TARGETS -->
+
 <xsl:template match="get_targets">
   <xsl:apply-templates select="gsad_msg"/>
   <xsl:apply-templates select="commands_response/delete_target_response"/>



More information about the Openvas-commits mailing list