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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Dec 28 15:40:09 CET 2009


Author: mattm
Date: 2009-12-28 15:40:07 +0100 (Mon, 28 Dec 2009)
New Revision: 6268

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 credential details page.

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

	* src/gsad_omp.h: Add header.

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

	* src/html/src/omp.xsl (target): Link credential to details.
	(target mode=details): Correct element name.  Link credential to details.
	(lsc_credential): Add details button.
	(lsc_credential mode=details, get_lsc_credential): New templates.

Modified: trunk/gsa/ChangeLog
===================================================================
--- trunk/gsa/ChangeLog	2009-12-28 14:33:17 UTC (rev 6267)
+++ trunk/gsa/ChangeLog	2009-12-28 14:40:07 UTC (rev 6268)
@@ -1,5 +1,21 @@
 2009-12-27  Matthew Mundell <matthew.mundell at intevation.de>
 
+	Add a credential details page.
+
+	* src/gsad_omp.c (get_lsc_credential_omp): New function.
+
+	* src/gsad_omp.h: Add header.
+
+	* src/gsad.c (init_validator): Add get_lsc_credential command.
+	(exec_omp_get): Handle command get_lsc_credential.
+
+	* src/html/src/omp.xsl (target): Link credential to details.
+	(target mode=details): Correct element name.  Link credential to details.
+	(lsc_credential): Add details button.
+	(lsc_credential mode=details, get_lsc_credential): New templates.
+
+2009-12-27  Matthew Mundell <matthew.mundell at intevation.de>
+
 	* ChangeLog: Repair after last commit.
 
 2009-12-27  Matthew Mundell <matthew.mundell at intevation.de>

Modified: trunk/gsa/src/gsad.c
===================================================================
--- trunk/gsa/src/gsad.c	2009-12-28 14:33:17 UTC (rev 6267)
+++ trunk/gsa/src/gsad.c	2009-12-28 14:40:07 UTC (rev 6268)
@@ -185,6 +185,7 @@
                          "|(get_configs)"
                          "|(get_feed)"
                          "|(get_escalators)"
+                         "|(get_lsc_credential)"
                          "|(get_lsc_credentials)"
                          "|(get_nvt_details)"
                          "|(get_report)"
@@ -1889,6 +1890,9 @@
   else if (!strcmp (cmd, "get_escalators"))
     return get_escalators_omp (credentials, sort_field, sort_order);
 
+  else if ((!strcmp (cmd, "get_lsc_credential")) && (name != NULL))
+    return get_lsc_credential_omp (credentials, name, sort_field, sort_order);
+
   else if (!strcmp (cmd, "get_lsc_credentials")
            && ((name == NULL && package_format == NULL)
                || (name && package_format)))

Modified: trunk/gsa/src/gsad_omp.c
===================================================================
--- trunk/gsa/src/gsad_omp.c	2009-12-28 14:33:17 UTC (rev 6267)
+++ trunk/gsa/src/gsad_omp.c	2009-12-28 14:40:07 UTC (rev 6268)
@@ -878,8 +878,81 @@
   return xsl_transform_omp (credentials, text);
 }
 
-/** @todo Split into get_lsc_credentials_omp and get_lsc_credential_omp. */
 /**
+ * @brief Get one LSC credential, XSL transform the result.
+ *
+ * @param[in]   credentials  Username and password for authentication.
+ * @param[in]   name         Name of LSC credential.
+ * @param[in]   format       Format of result
+ * @param[out]  result_len   Length of result.
+ * @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_lsc_credential_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 a credential. "
+                         "The credential is not available. "
+                         "Diagnostics: Failure to connect to manager daemon.",
+                         "/omp?cmd=get_lsc_credentials");
+
+  xml = g_string_new ("<get_lsc_credential>");
+
+  /* Get the target. */
+
+  if (openvas_server_sendf (&session,
+                            "<get_lsc_credentials"
+                            " 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 a credential. "
+                           "The credential is not available. "
+                           "Diagnostics: Failure to send command to manager daemon.",
+                           "/omp?cmd=get_lsc_credentials");
+    }
+
+  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 a credential. "
+                           "The credential is not available. "
+                           "Diagnostics: Failure to receive response from manager daemon.",
+                           "/omp?cmd=get_lsc_credentials");
+    }
+  free_entity (entity);
+
+  /* Cleanup, and return transformed XML. */
+
+  g_string_append (xml, "</get_lsc_credential>");
+  openvas_server_close (socket, session);
+  return xsl_transform_omp (credentials, g_string_free (xml, FALSE));
+}
+
+/** @todo Do package download somewhere else. */
+/**
  * @brief Get one or all LSC credentials, 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-28 14:33:17 UTC (rev 6267)
+++ trunk/gsa/src/gsad_omp.h	2009-12-28 14:40:07 UTC (rev 6268)
@@ -62,6 +62,8 @@
 char * delete_escalator_omp (credentials_t *, const char *);
 char * get_escalators_omp (credentials_t *, const char *, const char *);
 
+char * get_lsc_credential_omp (credentials_t *, const char *, const char *,
+                               const char *);
 char * get_lsc_credentials_omp (credentials_t *, const char *, const char *,
                                 gsize *, const char *, const char *);
 char * create_lsc_credential_omp (credentials_t *, char *, char *,

Modified: trunk/gsa/src/html/src/omp.xsl
===================================================================
--- trunk/gsa/src/html/src/omp.xsl	2009-12-28 14:33:17 UTC (rev 6267)
+++ trunk/gsa/src/html/src/omp.xsl	2009-12-28 14:40:07 UTC (rev 6268)
@@ -1450,6 +1450,10 @@
                style="margin-left:3px;"/>
         </xsl:otherwise>
       </xsl:choose>
+      <a href="/omp?cmd=get_lsc_credential&amp;name={name}"
+         title="Credential Details" style="margin-left:3px;">
+        <img src="/img/details.png" border="0" alt="Details"/>
+      </a>
       <xsl:if test="type='gen'">
         <a href="/omp?cmd=get_lsc_credentials&amp;name={name}&amp;package_format=rpm"
            title="Download RPM package" style="margin-left:3px;">
@@ -1472,6 +1476,75 @@
   </tr>
 </xsl:template>
 
+<xsl:template match="lsc_credential" 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">Credential Details</div>
+    <div class="gb_window_part_content">
+      <div style="float:right;">
+        <a href="?cmd=get_lsc_credentials">Back to Credentials</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="comment"/></td>
+        </tr>
+        <tr>
+          <td>Login:</td>
+          <td><xsl:value-of select="login"/></td>
+        </tr>
+      </table>
+
+      <xsl:choose>
+        <xsl:when test="count(targets/target) = 0">
+          <h1>Targets using this Credential: None</h1>
+        </xsl:when>
+        <xsl:otherwise>
+          <h1>Targets using this Credential:</h1>
+          <table class="gbntable" cellspacing="2" cellpadding="4">
+            <tr class="gbntablehead2">
+              <td>Name</td>
+              <td>Actions</td>
+            </tr>
+            <xsl:for-each select="targets/target">
+              <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_target&amp;name={name}" title="Target Details">
+                    <img src="/img/details.png"
+                         border="0"
+                         alt="Target"
+                         style="margin-left:3px;"/>
+                  </a>
+                </td>
+              </tr>
+            </xsl:for-each>
+          </table>
+        </xsl:otherwise>
+      </xsl:choose>
+    </div>
+  </div>
+</xsl:template>
+
+<!--     GET_LSC_CREDENTIAL -->
+
+<xsl:template match="get_lsc_credential">
+  <xsl:apply-templates select="gsad_msg"/>
+  <xsl:apply-templates select="commands_response/delete_lsc_credential_response"/>
+  <xsl:apply-templates select="get_lsc_credentials_response/lsc_credential" mode="details"/>
+</xsl:template>
+
 <!--     GET_LSC_CREDENTIALS_RESPONSE -->
 
 <xsl:template match="get_lsc_credentials_response">
@@ -2056,7 +2129,7 @@
     <td><xsl:value-of select="hosts"/></td>
     <td><xsl:value-of select="max_hosts"/></td>
     <td>
-      <a href="/omp?cmd=get_lsc_credentials">
+      <a href="/omp?cmd=get_lsc_credential&amp;name={lsc_credential/name}">
         <xsl:value-of select="lsc_credential/name"/>
       </a>
     </td>
@@ -2099,7 +2172,7 @@
         </tr>
         <tr>
           <td>Comment:</td>
-          <td><xsl:value-of select="summary"/></td>
+          <td><xsl:value-of select="comment"/></td>
         </tr>
         <tr>
           <td>Hosts:</td>
@@ -2112,7 +2185,7 @@
         <tr>
           <td>Credential:</td>
           <td>
-            <a href="/omp?cmd=get_lsc_credentials">
+            <a href="/omp?cmd=get_lsc_credential&amp;name={lsc_credential/name}">
               <xsl:value-of select="lsc_credential/name"/>
             </a>
           </td>



More information about the Openvas-commits mailing list