[Openvas-commits] r6342 - in trunk/gsa: . src src/html src/html/src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Jan 7 22:11:52 CET 2010
Author: mattm
Date: 2010-01-07 22:11:51 +0100 (Thu, 07 Jan 2010)
New Revision: 6342
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/header.m4
trunk/gsa/src/html/src/gsad.xsl
trunk/gsa/src/html/src/omp.xsl
Log:
Add performance reports page.
* src/gsad_omp.c (get_system_reports_omp, get_system_report_omp): New
function.
* src/gsad_omp.h: Add headers accordingly.
* src/gsad.c (init_validator): Add get_system_reports command. Add rule
"duration".
(exec_omp_get): Add get_system_reports command handling.
(request_handler): Add system report image response.
* src/html/src/omp.xsl (system_report, get_system_reports): New templates.
* src/html/header.m4, src/html/src/gsad.xsl: Add "Performance" menu item.
Modified: trunk/gsa/ChangeLog
===================================================================
--- trunk/gsa/ChangeLog 2010-01-07 20:57:23 UTC (rev 6341)
+++ trunk/gsa/ChangeLog 2010-01-07 21:11:51 UTC (rev 6342)
@@ -1,3 +1,21 @@
+2010-01-07 Matthew Mundell <matthew.mundell at intevation.de>
+
+ Add performance reports page.
+
+ * src/gsad_omp.c (get_system_reports_omp, get_system_report_omp): New
+ function.
+
+ * src/gsad_omp.h: Add headers accordingly.
+
+ * src/gsad.c (init_validator): Add get_system_reports command. Add rule
+ "duration".
+ (exec_omp_get): Add get_system_reports command handling.
+ (request_handler): Add system report image response.
+
+ * src/html/src/omp.xsl (system_report, get_system_reports): New templates.
+
+ * src/html/header.m4, src/html/src/gsad.xsl: Add "Performance" menu item.
+
2010-01-06 Felix Wolfsteller <felix.wolfsteller at intevation.de>
* src/html/src/help/configure_scanconfigs.htm4: Added help text about
Modified: trunk/gsa/src/gsad.c
===================================================================
--- trunk/gsa/src/gsad.c 2010-01-07 20:57:23 UTC (rev 6341)
+++ trunk/gsa/src/gsad.c 2010-01-07 21:11:51 UTC (rev 6342)
@@ -194,6 +194,7 @@
"|(get_settings)"
"|(get_status)"
"|(get_target)"
+ "|(get_system_reports)"
"|(get_targets)"
"|(get_users)"
"|(import_config)"
@@ -238,6 +239,7 @@
openvas_validator_alias (validator, "base", "name");
+ openvas_validator_alias (validator, "duration", "number");
openvas_validator_alias (validator, "escalator", "name");
openvas_validator_alias (validator, "scanconfig", "name");
openvas_validator_alias (validator, "scantarget", "name");
@@ -1651,6 +1653,7 @@
const char *sort_order = NULL;
const char *levels = NULL;
const char *refresh_interval = NULL;
+ const char *duration = NULL;
int high = 0, medium = 0, low = 0, log = 0;
credentials_t *credentials = NULL;
@@ -1744,11 +1747,17 @@
sort_field = NULL;
refresh_interval = MHD_lookup_connection_value (connection,
- MHD_GET_ARGUMENT_KIND,
- "refresh_interval");
+ MHD_GET_ARGUMENT_KIND,
+ "refresh_interval");
if (openvas_validate (validator, "refresh_interval", refresh_interval))
refresh_interval = NULL;
+ duration = MHD_lookup_connection_value (connection,
+ MHD_GET_ARGUMENT_KIND,
+ "duration");
+ if (openvas_validate (validator, "duration", duration))
+ duration = NULL;
+
sort_order = MHD_lookup_connection_value (connection,
MHD_GET_ARGUMENT_KIND,
"sort_order");
@@ -1987,6 +1996,9 @@
else if (!strcmp (cmd, "get_status"))
return get_status_omp (credentials, NULL, sort_field, sort_order, refresh_interval);
+ else if ((!strcmp (cmd, "get_system_reports")))
+ return get_system_reports_omp (credentials, duration);
+
else if ((!strcmp (cmd, "get_target")) && (name != NULL))
return get_target_omp (credentials, name, sort_field, sort_order);
@@ -2365,6 +2377,45 @@
return MHD_YES;
}
+ if (!strncmp (&url[0], "/system_report/",
+ strlen ("/system_report/"))) /* flawfinder: ignore,
+ it is a const str */
+ {
+ unsigned int res_len;
+ const char *duration;
+
+ duration = MHD_lookup_connection_value (connection,
+ MHD_GET_ARGUMENT_KIND,
+ "duration");
+ if (openvas_validate (validator, "duration", duration))
+ duration = NULL;
+
+ res = get_system_report_omp (credentials,
+ &url[0] + strlen ("/system_report/"),
+ duration,
+ &content_type,
+ &content_disposition,
+ &res_len);
+ if (res == NULL) return MHD_NO;
+ response = MHD_create_response_from_data (res_len, res,
+ MHD_NO, MHD_YES);
+ if (content_type != NULL)
+ {
+ MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE,
+ content_type);
+ content_type = NULL;
+ }
+ if (content_disposition != NULL)
+ {
+ MHD_add_response_header (response, "Content-Disposition",
+ content_disposition);
+ content_disposition = NULL;
+ }
+ ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
+ MHD_destroy_response (response);
+ return MHD_YES;
+ }
+
/* URL requests neither an OMP command nor a special GSAD command,
* so it is a simple file. */
Modified: trunk/gsa/src/gsad_omp.c
===================================================================
--- trunk/gsa/src/gsad_omp.c 2010-01-07 20:57:23 UTC (rev 6341)
+++ trunk/gsa/src/gsad_omp.c 2010-01-07 21:11:51 UTC (rev 6342)
@@ -3819,6 +3819,163 @@
}
}
+/**
+ * @brief Get all system reports, XSL transform the result.
+ *
+ * @param[in] credentials Username and password for authentication.
+ * @param[in] duration Duration of reports, in seconds.
+ *
+ * @return Result of XSL transformation.
+ */
+char *
+get_system_reports_omp (credentials_t * credentials, const char * duration)
+{
+ 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 the system reports. "
+ "The current list of system reports is not available. "
+ "Diagnostics: Failure to connect to manager daemon.",
+ "/omp?cmd=get_status");
+
+ xml = g_string_new ("<get_system_reports>");
+ g_string_append_printf (xml, "<duration>%s</duration>",
+ duration ? duration : "86400");
+
+ /* Get the system reports. */
+
+ if (openvas_server_sendf (&session,
+ "<get_system_reports name=\"types\"/>")
+ == -1)
+ {
+ g_string_free (xml, TRUE);
+ openvas_server_close (socket, session);
+ return gsad_message ("Internal error", __FUNCTION__, __LINE__,
+ "An internal error occurred while getting the system reports. "
+ "The current list of system reports is not available. "
+ "Diagnostics: Failure to send command to manager daemon.",
+ "/omp?cmd=get_status");
+ }
+
+ 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 the system reports. "
+ "The current list of system reports is not available. "
+ "Diagnostics: Failure to receive response from manager daemon.",
+ "/omp?cmd=get_status");
+ }
+ free_entity (entity);
+
+ /* Cleanup, and return transformed XML. */
+
+ g_string_append (xml, "</get_system_reports>");
+ openvas_server_close (socket, session);
+ return xsl_transform_omp (credentials, g_string_free (xml, FALSE));
+}
+
+/**
+ * @brief Return system report image.
+ *
+ * @param[in] credentials Credentials of user issuing the action.
+ * @param[in] url URL of report image.
+ * @param[in] duration Duration of report, in seconds.
+ * @param[out] content_type Content type return.
+ * @param[out] content_disposition Content dispositions return.
+ * @param[out] content_length Content length return.
+ *
+ * @return Image, or NULL.
+ */
+char *
+get_system_report_omp (credentials_t *credentials, const char *url,
+ const char *duration, char **content_type,
+ char **content_disposition, gsize *content_length)
+{
+ entity_t entity;
+ entity_t report_entity;
+ gnutls_session_t session;
+ int socket;
+ char name[501];
+
+ *content_length = 0;
+
+ if (url == NULL)
+ return NULL;
+
+ /* fan/report.png */
+ if (sscanf (url, "%500[^ /]./report.png", name) == 1)
+ {
+ if (manager_connect (credentials, &socket, &session))
+ return NULL;
+
+ if (openvas_server_sendf (&session,
+ "<get_system_reports"
+ " name=\"%s\" duration=\"%s\"/>",
+ name,
+ duration ? duration : "86400")
+ == -1)
+ {
+ openvas_server_close (socket, session);
+ return NULL;
+ }
+
+ entity = NULL;
+ if (read_entity (&session, &entity))
+ {
+ openvas_server_close (socket, session);
+ return NULL;
+ }
+
+ report_entity = entity_child (entity, "system_report");
+ if (report_entity == NULL)
+ {
+ free_entity (entity);
+ openvas_server_close (socket, session);
+ return NULL;
+ }
+
+ report_entity = entity_child (report_entity, "report");
+ if (report_entity == NULL)
+ {
+ free_entity (entity);
+ openvas_server_close (socket, session);
+ return NULL;
+ }
+ else
+ {
+ char *content_64 = entity_text (report_entity);
+ char *content = NULL;
+
+ if (content_64 && strlen (content_64))
+ {
+ content = (char *) g_base64_decode (content_64,
+ content_length);
+
+#if 1
+ *content_type = g_strdup ("image/png");
+ //*content_disposition = g_strdup_printf ("attachment; filename=\"xxx.png\"");
+#else
+ g_free (content);
+ content = g_strdup ("helo");
+#endif
+ }
+
+ free_entity (entity);
+ openvas_server_close (socket, session);
+ return content;
+ }
+ }
+
+ return NULL;
+}
+
/* Manager communication. */
Modified: trunk/gsa/src/gsad_omp.h
===================================================================
--- trunk/gsa/src/gsad_omp.h 2010-01-07 20:57:23 UTC (rev 6341)
+++ trunk/gsa/src/gsad_omp.h 2010-01-07 21:11:51 UTC (rev 6342)
@@ -108,6 +108,10 @@
char * delete_config_omp (credentials_t *, const char *);
char * export_config_omp (credentials_t *, const char *, char **, char **, gsize *);
+char * get_system_reports_omp (credentials_t *, const char *);
+char * get_system_report_omp (credentials_t *, const char *, const char *, char **,
+ char **, gsize *);
+
gboolean is_omp_authenticated (gchar *, gchar *);
char * get_nvt_details_omp (credentials_t *, const char *);
Modified: trunk/gsa/src/html/header.m4
===================================================================
--- trunk/gsa/src/html/header.m4 2010-01-07 20:57:23 UTC (rev 6341)
+++ trunk/gsa/src/html/header.m4 2010-01-07 21:11:51 UTC (rev 6342)
@@ -39,6 +39,7 @@
<ul>
<li><a href="/omp?cmd=get_status">Tasks</a></li>
<li><a href="/new_task.html">New Task</a></li>
+ <li><a href="/omp?cmd=get_system_reports">Performance</a></li>
</ul>
</li>
<li>Configuration
Modified: trunk/gsa/src/html/src/gsad.xsl
===================================================================
--- trunk/gsa/src/html/src/gsad.xsl 2010-01-07 20:57:23 UTC (rev 6341)
+++ trunk/gsa/src/html/src/gsad.xsl 2010-01-07 21:11:51 UTC (rev 6342)
@@ -97,6 +97,7 @@
<ul>
<li><a href="/omp?cmd=get_status">Tasks</a></li>
<li><a href="/new_task.html">New Task</a></li>
+ <li><a href="/omp?cmd=get_system_reports">Performance</a></li>
</ul>
</li>
<li>
Modified: trunk/gsa/src/html/src/omp.xsl
===================================================================
--- trunk/gsa/src/html/src/omp.xsl 2010-01-07 20:57:23 UTC (rev 6341)
+++ trunk/gsa/src/html/src/omp.xsl 2010-01-07 21:11:51 UTC (rev 6342)
@@ -4006,6 +4006,102 @@
<!-- END REPORT DETAILS -->
+<!-- BEGIN SYSTEM REPORTS MANAGEMENT -->
+
+<xsl:template match="system_report" mode="image">
+ <tr>
+ <td>
+ <h1><xsl:value-of select="title"/></h1>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <img src="/system_report/{name}/report.png?duration={../../../../duration}"/>
+ </td>
+ </tr>
+</xsl:template>
+
+<xsl:template match="system_report">
+ <xsl:variable name="duration" select="../../duration"/>
+ <div class="gb_window">
+ <div class="gb_window_part_left"></div>
+ <div class="gb_window_part_right"></div>
+ <div class="gb_window_part_center">Performance
+ <a href="/help/performance.html"
+ title="Help: Performance">
+ <img src="/img/help.png"/>
+ </a>
+ </div>
+ <div class="gb_window_part_content_no_pad">
+ <table>
+ <tr>
+ <td>
+ Reports span the last:
+ </td>
+ <td>
+ <xsl:choose>
+ <xsl:when test="$duration='3600'">
+ hour
+ </xsl:when>
+ <xsl:otherwise>
+ <a href="/omp?cmd=get_system_reports&duration={3600}">hour</a>
+ </xsl:otherwise>
+ </xsl:choose>
+ |
+ <xsl:choose>
+ <xsl:when test="$duration='86400'">
+ day
+ </xsl:when>
+ <xsl:otherwise>
+ <a href="/omp?cmd=get_system_reports&duration={86400}">day</a>
+ </xsl:otherwise>
+ </xsl:choose>
+ |
+ <xsl:choose>
+ <xsl:when test="$duration='604800'">
+ week
+ </xsl:when>
+ <xsl:otherwise>
+ <a href="/omp?cmd=get_system_reports&duration={604800}">week</a>
+ </xsl:otherwise>
+ </xsl:choose>
+ |
+ <xsl:choose>
+ <xsl:when test="$duration='2592000'">
+ month
+ </xsl:when>
+ <xsl:otherwise>
+ <a href="/omp?cmd=get_system_reports&duration={2592000}">month</a>
+ </xsl:otherwise>
+ </xsl:choose>
+ |
+ <xsl:choose>
+ <xsl:when test="$duration='31536000'">
+ year
+ </xsl:when>
+ <xsl:otherwise>
+ <a href="/omp?cmd=get_system_reports&duration={31536000}">year</a>
+ </xsl:otherwise>
+ </xsl:choose>
+ </td>
+ </tr>
+ </table>
+ <table>
+ <xsl:apply-templates select="report/system_report" mode="image"/>
+ </table>
+ </div>
+ </div>
+</xsl:template>
+
+<!-- GET_SYSTEM_REPORTS -->
+
+<xsl:template match="get_system_reports">
+ <xsl:apply-templates select="gsad_msg"/>
+ <xsl:apply-templates select="get_system_reports_response/system_report"/>
+</xsl:template>
+
+<!-- END SYSTEM REPORTS MANAGEMENT -->
+
<!-- GSAD_RESPONSE -->
<xsl:template match="gsad_response">
More information about the Openvas-commits
mailing list