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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Sep 28 20:33:23 CEST 2011


Author: mattm
Date: 2011-09-28 20:33:21 +0200 (Wed, 28 Sep 2011)
New Revision: 11710

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/omp.xsl
Log:
	Add editing of My Settings.

	* src/gsad.c (init_validator, exec_omp_post, exec_omp_get): Add
	edit_my_settings and save_my_settings.

	* src/gsad_omp.c (get_my_settings, edit_my_settings)
	(edit_my_settings_omp, save_my_settings_omp): New function.
	(get_my_settings_omp): Call through to get_my_settings.

	* src/gsad_omp.h: Add headers accordingly.

	* src/html/omp.xsl (modify_settings_response, edit_my_settings): New
	templates.
	(my_settings): Remove.  Renamed to get_my_settings.
	(get_my_settings): New template.  Was my_settings.  Add edit icon.

Modified: trunk/gsa/ChangeLog
===================================================================
--- trunk/gsa/ChangeLog	2011-09-28 18:26:33 UTC (rev 11709)
+++ trunk/gsa/ChangeLog	2011-09-28 18:33:21 UTC (rev 11710)
@@ -1,5 +1,23 @@
 2011-09-28  Matthew Mundell <matthew.mundell at greenbone.net>
 
+	Add editing of My Settings.
+
+	* src/gsad.c (init_validator, exec_omp_post, exec_omp_get): Add
+	edit_my_settings and save_my_settings.
+
+	* src/gsad_omp.c (get_my_settings, edit_my_settings)
+	(edit_my_settings_omp, save_my_settings_omp): New function.
+	(get_my_settings_omp): Call through to get_my_settings.
+
+	* src/gsad_omp.h: Add headers accordingly.
+
+	* src/html/omp.xsl (modify_settings_response, edit_my_settings): New
+	templates.
+	(my_settings): Remove.  Renamed to get_my_settings.
+	(get_my_settings): New template.  Was my_settings.  Add edit icon.
+
+2011-09-28  Matthew Mundell <matthew.mundell at greenbone.net>
+
 	* src/gsad.c (exec_omp_post): Initialise role and timezone in credentials.
 
 2011-09-27  Matthew Mundell <matthew.mundell at greenbone.net>

Modified: trunk/gsa/src/gsad.c
===================================================================
--- trunk/gsa/src/gsad.c	2011-09-28 18:26:33 UTC (rev 11709)
+++ trunk/gsa/src/gsad.c	2011-09-28 18:33:21 UTC (rev 11710)
@@ -477,6 +477,7 @@
                          "|(edit_config_family)"
                          "|(edit_config_nvt)"
                          "|(edit_lsc_credential)"
+                         "|(edit_my_settings)"
                          "|(edit_note)"
                          "|(edit_override)"
                          "|(edit_report_format)"
@@ -539,6 +540,7 @@
                          "|(save_config_family)"
                          "|(save_config_nvt)"
                          "|(save_lsc_credential)"
+                         "|(save_my_settings)"
                          "|(save_note)"
                          "|(save_override)"
                          "|(save_report_format)"
@@ -1332,6 +1334,7 @@
   ELSE (save_config_family)
   ELSE (save_config_nvt)
   ELSE (save_lsc_credential)
+  ELSE (save_my_settings)
   ELSE (save_note)
   ELSE (save_override)
   ELSE (save_report_format)
@@ -1456,6 +1459,7 @@
   ELSE (edit_config_family)
   ELSE (edit_config_nvt)
   ELSE (edit_lsc_credential)
+  ELSE (edit_my_settings)
   ELSE (edit_note)
   ELSE (edit_override)
   ELSE (edit_report_format)

Modified: trunk/gsa/src/gsad_omp.c
===================================================================
--- trunk/gsa/src/gsad_omp.c	2011-09-28 18:26:33 UTC (rev 11709)
+++ trunk/gsa/src/gsad_omp.c	2011-09-28 18:33:21 UTC (rev 11710)
@@ -13795,15 +13795,150 @@
  *
  * @param[in]  credentials  Credentials of user issuing the action.
  * @param[in]  params       Request parameters.
+ * @param[in]  extra_xml    Extra XML to insert inside page element.
  *
  * @return Result of XSL transformation.
  */
+static char *
+get_my_settings (credentials_t * credentials, params_t *params,
+                 const char *extra_xml)
+{
+  GString *xml;
+  xml = g_string_new ("<get_my_settings>");
+  if (extra_xml)
+    g_string_append (xml, extra_xml);
+  g_string_append (xml, "</get_my_settings>");
+  return xsl_transform_omp (credentials, g_string_free (xml, FALSE));
+}
+
+/**
+ * @brief Returns page with user's settings.
+ *
+ * @param[in]  credentials  Credentials of user issuing the action.
+ * @param[in]  params       Request parameters.
+ *
+ * @return Result of XSL transformation.
+ */
 char *
 get_my_settings_omp (credentials_t * credentials, params_t *params)
 {
-  return xsl_transform_omp (credentials, g_strdup ("<my_settings/>"));
+  return get_my_settings (credentials, params, NULL);
 }
 
+/**
+ * @brief Returns page with user's settings, for editing.
+ *
+ * @param[in]  credentials  Credentials of user issuing the action.
+ * @param[in]  params       Request parameters.
+ * @param[in]  extra_xml    Extra XML to insert inside page element.
+ *
+ * @return Result of XSL transformation.
+ */
+static char *
+edit_my_settings (credentials_t * credentials, params_t *params,
+                  const char *extra_xml)
+{
+  GString *xml;
+  xml = g_string_new ("<edit_my_settings>");
+  if (extra_xml)
+    g_string_append (xml, extra_xml);
+  g_string_append (xml, "</edit_my_settings>");
+  return xsl_transform_omp (credentials, g_string_free (xml, FALSE));
+}
+
+/**
+ * @brief Returns page with user's settings, for editing.
+ *
+ * @param[in]  credentials  Credentials of user issuing the action.
+ * @param[in]  params       Request parameters.
+ *
+ * @return Result of XSL transformation.
+ */
+char *
+edit_my_settings_omp (credentials_t * credentials, params_t *params)
+{
+  return edit_my_settings (credentials, params, NULL);
+}
+
+/**
+ * @brief Returns page with user's settings, for editing.
+ *
+ * @param[in]  credentials  Credentials of user issuing the action.
+ * @param[in]  params       Request parameters.
+ *
+ * @return Result of XSL transformation.
+ */
+char *
+save_my_settings_omp (credentials_t * credentials, params_t *params)
+{
+  int socket;
+  gnutls_session_t session;
+  gchar *html;
+  const char *text;
+  gchar *text_64;
+  GString *xml;
+
+  if (params_value (params, "text") == NULL)
+    return edit_my_settings (credentials, params,
+                             GSAD_MESSAGE_INVALID_PARAM
+                               ("Save My Settings"));
+
+  switch (manager_connect (credentials, &socket, &session, &html))
+    {
+      case 0:
+        break;
+      case -1:
+        if (html)
+          return html;
+        /* Fall through. */
+      default:
+        return gsad_message (credentials,
+                             "Internal error", __FUNCTION__, __LINE__,
+                             "An internal error occurred while saving settings. "
+                             "The settings remains the same. "
+                             "Diagnostics: Failure to connect to manager daemon.",
+                             "/omp?cmd=get_my_settings");
+    }
+
+  text = params_value (params, "text");
+  text_64 = text ? g_base64_encode ((guchar*) text, strlen (text)) : g_strdup ("");
+
+  if (openvas_server_sendf (&session,
+                            "<modify_setting>"
+                            "<name>Timezone</name>"
+                            "<value>%s</value>"
+                            "</modify_setting>",
+                            text_64)
+      == -1)
+    {
+      g_free (text_64);
+      openvas_server_close (socket, session);
+      return gsad_message (credentials,
+                           "Internal error", __FUNCTION__, __LINE__,
+                           "An internal error occurred while saving settings. "
+                           "It is unclear whether all the settings were saved. "
+                           "Diagnostics: Failure to send command to manager daemon.",
+                           "/omp?cmd=get_my_settings");
+    }
+  g_free (text_64);
+
+  xml = g_string_new ("");
+
+  if (read_string (&session, &xml))
+    {
+      g_string_free (xml, TRUE);
+      openvas_server_close (socket, session);
+      return gsad_message (credentials,
+                           "Internal error", __FUNCTION__, __LINE__,
+                           "An internal error occurred while saving settings. "
+                           "Diagnostics: Failure to receive response from manager daemon.",
+                           "/omp?cmd=get_my_settings");
+    }
+
+  openvas_server_close (socket, session);
+  return get_my_settings (credentials, params, g_string_free (xml, FALSE));
+}
+
 
 /* Manager communication. */
 

Modified: trunk/gsa/src/gsad_omp.h
===================================================================
--- trunk/gsa/src/gsad_omp.h	2011-09-28 18:26:33 UTC (rev 11709)
+++ trunk/gsa/src/gsad_omp.h	2011-09-28 18:33:21 UTC (rev 11710)
@@ -159,7 +159,9 @@
 char * restore_omp (credentials_t *, params_t *);
 char * empty_trashcan_omp (credentials_t *, params_t *);
 
+char * edit_my_settings_omp (credentials_t *, params_t *);
 char * get_my_settings_omp (credentials_t *, params_t *);
+char * save_my_settings_omp (credentials_t *, params_t *);
 
 int authenticate_omp (const gchar *, const gchar *, gchar **, gchar **);
 

Modified: trunk/gsa/src/html/omp.xsl
===================================================================
--- trunk/gsa/src/html/omp.xsl	2011-09-28 18:26:33 UTC (rev 11709)
+++ trunk/gsa/src/html/omp.xsl	2011-09-28 18:33:21 UTC (rev 11710)
@@ -12806,8 +12806,21 @@
 
 <!-- MY SETTINGS -->
 
-<xsl:template match="my_settings">
+<xsl:template match="modify_settings_response">
+  <xsl:call-template name="command_result_dialog">
+    <xsl:with-param name="operation">Save Settings</xsl:with-param>
+    <xsl:with-param name="status">
+      <xsl:value-of select="@status"/>
+    </xsl:with-param>
+    <xsl:with-param name="msg">
+      <xsl:value-of select="@status_text"/>
+    </xsl:with-param>
+  </xsl:call-template>
+</xsl:template>
+
+<xsl:template match="get_my_settings">
   <xsl:apply-templates select="gsad_msg"/>
+  <xsl:apply-templates select="modify_settings_response"/>
 
   <div class="gb_window">
     <div class="gb_window_part_left"></div>
@@ -12817,6 +12830,11 @@
          title="Help: My Settings">
         <img src="/img/help.png"/>
       </a>
+      <a href="/omp?cmd=edit_my_settings&amp;token={/envelope/token}"
+         title="Edit My Settings"
+         style="margin-left:3px;">
+        <img src="/img/edit.png"/>
+      </a>
     </div>
     <div class="gb_window_part_content_no_pad">
       <div id="tasks">
@@ -12837,6 +12855,48 @@
   </div>
 </xsl:template>
 
+<xsl:template match="edit_my_settings">
+  <xsl:apply-templates select="gsad_msg"/>
+
+  <div class="gb_window">
+    <div class="gb_window_part_left"></div>
+    <div class="gb_window_part_right"></div>
+    <div class="gb_window_part_center">Edit My Settings
+      <a href="/help/my_settings.html?token={/envelope/token}#edit"
+         title="Help: My Settings (Edit)">
+        <img src="/img/help.png"/>
+      </a>
+    </div>
+    <div class="gb_window_part_content_no_pad">
+      <div id="tasks">
+        <form action="" method="post" enctype="multipart/form-data">
+          <input type="hidden" name="token" value="{/envelope/token}"/>
+          <input type="hidden" name="cmd" value="save_my_settings"/>
+          <input type="hidden" name="caller" value="{/envelope/caller}"/>
+          <table class="gbntable" cellspacing="2" cellpadding="4" border="0">
+            <tr class="gbntablehead2">
+              <td>Name</td>
+              <td>Value</td>
+            </tr>
+            <tr>
+              <td>Timezone</td>
+              <td>
+                <input type="text" name="text" size="40" maxlength="800"
+                       value="{/envelope/timezone}"/>
+              </td>
+            </tr>
+            <tr>
+              <td colspan="2" style="text-align:right;">
+                <input type="submit" name="submit" value="Save My Settings"/>
+              </td>
+            </tr>
+          </table>
+        </form>
+      </div>
+    </div>
+  </div>
+</xsl:template>
+
 <!-- COMMANDS_RESPONSE -->
 
 <xsl:template match="commands_response">



More information about the Openvas-commits mailing list