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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Dec 24 20:16:43 CET 2009


Author: mattm
Date: 2009-12-24 20:16:41 +0100 (Thu, 24 Dec 2009)
New Revision: 6253

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/help/contents.htm4
   trunk/gsa/src/html/src/omp.xsl
Log:
	Add Escalators.

	* src/gsad.c (init_validator): Add escalator commands.  Add "condition",
	"escalator", "event" and "method" validators.
	(struct req_parms): Add fields for escalator commands.
	(free_resources): Init escalator resources.
	(serve_post): Check and setup escalator keys.
	(exec_omp_post): Handle command "create_escalator".  Pass escalator to
	create_task_omp.
	(exec_omp_get): Handle commands "delete_escalator" and "get_escalators".

	* src/gsad_omp.c (gsad_newtask): Also get escalators.  Correct two error
	message strings.
	(create_task_omp): Add escalator arg.
	(send_escalator_data, create_escalator_omp, delete_escalator_omp)
	(get_escalators_omp): New functions.

	* src/gsad_omp.h: Add and update headers accordingly.

	* src/omp.xsl (html-report-table): Add escalator link.
	(escalator, html-create-escalator-form, html-escalators-table)
	(create_escalator_response, delete_escalator_response)
	(escalator, get_escalator): New templates.
	(gsad_newtask): Add escalator selector.

	* src/html/src/gsad.xsl (html-gsa-navigation): Add Escalators menu item.

	* src/html/src/help/contents.htm4: Add Escalators menu item.

	* src/html/headers.m4: Add Escalators menu item.

Modified: trunk/gsa/ChangeLog
===================================================================
--- trunk/gsa/ChangeLog	2009-12-24 18:56:33 UTC (rev 6252)
+++ trunk/gsa/ChangeLog	2009-12-24 19:16:41 UTC (rev 6253)
@@ -1,3 +1,36 @@
+2009-12-24  Matthew Mundell <matthew.mundell at intevation.de>
+
+	Add Escalators.
+
+	* src/gsad.c (init_validator): Add escalator commands.  Add "condition",
+	"escalator", "event" and "method" validators.
+	(struct req_parms): Add fields for escalator commands.
+	(free_resources): Init escalator resources.
+	(serve_post): Check and setup escalator keys.
+	(exec_omp_post): Handle command "create_escalator".  Pass escalator to
+	create_task_omp.
+	(exec_omp_get): Handle commands "delete_escalator" and "get_escalators".
+
+	* src/gsad_omp.c (gsad_newtask): Also get escalators.  Correct two error
+	message strings.
+	(create_task_omp): Add escalator arg.
+	(send_escalator_data, create_escalator_omp, delete_escalator_omp)
+	(get_escalators_omp): New functions.
+
+	* src/gsad_omp.h: Add and update headers accordingly.
+
+	* src/omp.xsl (html-report-table): Add escalator link.
+	(escalator, html-create-escalator-form, html-escalators-table)
+	(create_escalator_response, delete_escalator_response)
+	(escalator, get_escalator): New templates.
+	(gsad_newtask): Add escalator selector.
+
+	* src/html/src/gsad.xsl (html-gsa-navigation): Add Escalators menu item.
+
+	* src/html/src/help/contents.htm4: Add Escalators menu item.
+
+	* src/html/headers.m4: Add Escalators menu item.
+
 2009-12-23  Jan-Oliver Wagner <jan-oliver.wagner at greenbone.net>
 
 	* src/gsad_omp.h: Updated according to last commit.

Modified: trunk/gsa/src/gsad.c
===================================================================
--- trunk/gsa/src/gsad.c	2009-12-24 18:56:33 UTC (rev 6252)
+++ trunk/gsa/src/gsad.c	2009-12-24 19:16:41 UTC (rev 6253)
@@ -162,12 +162,14 @@
                          "^(abort_task)"
                          "|(create_agent)"
                          "|(create_config)"
+                         "|(create_escalator)"
                          "|(create_lsc_credential)"
                          "|(create_target)"
                          "|(create_task)"
                          "|(create_user)"
                          "|(delete_agent)"
                          "|(delete_config)"
+                         "|(delete_escalator)"
                          "|(delete_lsc_credential)"
                          "|(delete_report)"
                          "|(delete_target)"
@@ -182,6 +184,7 @@
                          "|(get_config_nvt)"
                          "|(get_configs)"
                          "|(get_feed)"
+                         "|(get_escalators)"
                          "|(get_lsc_credentials)"
                          "|(get_nvt_details)"
                          "|(get_report)"
@@ -198,6 +201,7 @@
   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, "condition",  "^[[:alnum:] ]{0,100}$");
   openvas_validator_add (validator, "create_credentials_type", "^(gen|pass)$");
   openvas_validator_add (validator, "credential_login", "^[[:alnum:]]{1,40}$");
   openvas_validator_add (validator, "family",     "^[-_[:alnum:] :]{1,200}$");
@@ -227,6 +231,9 @@
   openvas_validator_alias (validator, "scanconfig",   "name");
   openvas_validator_alias (validator, "scantarget",   "name");
   openvas_validator_alias (validator, "base",         "name");
+  openvas_validator_alias (validator, "escalator",    "name");
+  openvas_validator_alias (validator, "event",        "condition");
+  openvas_validator_alias (validator, "method",       "condition");
   openvas_validator_alias (validator, "level_high",   "boolean");
   openvas_validator_alias (validator, "level_medium", "boolean");
   openvas_validator_alias (validator, "level_low",    "boolean");
@@ -260,8 +267,12 @@
     char *cmd;           ///< Value of "cmd" parameter.
     char *name;          ///< Value of "name" parameter.
     char *comment;       ///< Value of "comment" parameter.
+    char *condition;     ///< Value of "condition" parameter.
     char *credential_login; ///< Value of "credential_login" parameter.
+    char *escalator;     ///< Value of "escalator" parameter.
+    char *event;         ///< Value of "event" parameter.
     char *family;        ///< Value of "family" parameter.
+    char *method;        ///< Value of "event" parameter.
     char *scanconfig;    ///< Value of "scanconfig" parameter.
     char *scantarget;    ///< Value of "scantarget" parameter.
     char *sort_field;    ///< Value of "sort_field" parameter.
@@ -282,6 +293,9 @@
     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 *condition_data; ///< Collection of "condition_data:*" parameters.
+    GArray *event_data;  ///< Collection of "event_data:*" parameters.
+    GArray *method_data; ///< Collection of "method_data:*" parameters.
     GArray *passwords;   ///< Collection of "password:*" parameters.
     GArray *preferences; ///< Collection of "preference:*" parameters.
     GArray *nvts;        ///< Collection of "nvt:*" parameters.
@@ -427,6 +441,7 @@
           MHD_destroy_post_processor (con_info->postprocessor);
         }
     }
+  /** @todo Remove the checks, as it is safe to pass NULL to free. */
   if (con_info->req_parms.base)
     {
       free (con_info->req_parms.base);
@@ -443,14 +458,30 @@
     {
       free (con_info->req_parms.comment);
     }
+  if (con_info->req_parms.condition)
+    {
+      free (con_info->req_parms.condition);
+    }
   if (con_info->req_parms.credential_login)
     {
       free (con_info->req_parms.credential_login);
     }
+  if (con_info->req_parms.escalator)
+    {
+      free (con_info->req_parms.escalator);
+    }
+  if (con_info->req_parms.event)
+    {
+      free (con_info->req_parms.event);
+    }
   if (con_info->req_parms.family)
     {
       free (con_info->req_parms.family);
     }
+  if (con_info->req_parms.method)
+    {
+      free (con_info->req_parms.method);
+    }
   if (con_info->req_parms.scanconfig)
     {
       free (con_info->req_parms.scanconfig);
@@ -515,6 +546,36 @@
     {
       free (con_info->req_parms.howto_use);
     }
+  if (con_info->req_parms.condition_data)
+    {
+      gchar *item;
+      int index = 0;
+
+      while ((item = g_array_index (con_info->req_parms.condition_data, gchar*, index++)))
+        g_free (item);
+
+      g_array_free (con_info->req_parms.condition_data, TRUE);
+    }
+  if (con_info->req_parms.event_data)
+    {
+      gchar *item;
+      int index = 0;
+
+      while ((item = g_array_index (con_info->req_parms.event_data, gchar*, index++)))
+        g_free (item);
+
+      g_array_free (con_info->req_parms.event_data, TRUE);
+    }
+  if (con_info->req_parms.method_data)
+    {
+      gchar *item;
+      int index = 0;
+
+      while ((item = g_array_index (con_info->req_parms.method_data, gchar*, index++)))
+        g_free (item);
+
+      g_array_free (con_info->req_parms.method_data, TRUE);
+    }
   if (con_info->req_parms.preferences)
     {
       preference_t *item;
@@ -695,6 +756,21 @@
           con_info->answercode = MHD_HTTP_OK;
           return MHD_YES;
         }
+      if (!strcmp (key, "condition"))
+        {
+          con_info->req_parms.condition = malloc (size + 1);
+          memcpy ((char *) con_info->req_parms.condition,
+                  (char *) data,
+                  size);
+          con_info->req_parms.condition[size] = 0;
+          if (abort_on_insane
+              && openvas_validate (validator,
+                                   "condition",
+                                   con_info->req_parms.condition))
+            return MHD_NO;
+          con_info->answercode = MHD_HTTP_OK;
+          return MHD_YES;
+        }
       if (!strcmp (key, "credential_login"))
         {
           con_info->req_parms.credential_login = malloc (size + 1);
@@ -710,6 +786,49 @@
           con_info->answercode = MHD_HTTP_OK;
           return MHD_YES;
         }
+      if (!strcmp (key, "escalator"))
+        {
+          con_info->req_parms.escalator = malloc (size + 1);
+          memcpy ((char *) con_info->req_parms.escalator, (char *) data, size);
+          con_info->req_parms.escalator[size] = 0;
+          if (abort_on_insane
+              && openvas_validate (validator,
+                                   "escalator",
+                                   con_info->req_parms.escalator))
+            return MHD_NO;
+          con_info->answercode = MHD_HTTP_OK;
+          return MHD_YES;
+        }
+      if (!strcmp (key, "event"))
+        {
+          con_info->req_parms.event = malloc (size + 1);
+          memcpy ((char *) con_info->req_parms.event,
+                  (char *) data,
+                  size);
+          con_info->req_parms.event[size] = 0;
+          if (abort_on_insane
+              && openvas_validate (validator,
+                                   "event",
+                                   con_info->req_parms.event))
+            return MHD_NO;
+          con_info->answercode = MHD_HTTP_OK;
+          return MHD_YES;
+        }
+      if (!strcmp (key, "method"))
+        {
+          con_info->req_parms.method = malloc (size + 1);
+          memcpy ((char *) con_info->req_parms.method,
+                  (char *) data,
+                  size);
+          con_info->req_parms.method[size] = 0;
+          if (abort_on_insane
+              && openvas_validate (validator,
+                                   "method",
+                                   con_info->req_parms.method))
+            return MHD_NO;
+          con_info->answercode = MHD_HTTP_OK;
+          return MHD_YES;
+        }
       if (!strcmp (key, "name"))
         {
           con_info->req_parms.name = malloc (size + 1);
@@ -928,6 +1047,69 @@
           con_info->answercode = MHD_HTTP_OK;
           return MHD_YES;
         }
+      if (!strncmp (key, "condition_data:", strlen ("condition_data:")))
+        {
+          gchar *condition_data;
+
+          condition_data = g_strdup_printf ("%s0%.*s",
+                                            key + strlen ("condition_data:"),
+                                            size,
+                                            data);
+          condition_data[strlen (key + strlen ("condition_data:"))] = '\0';
+
+          if (con_info->req_parms.condition_data == NULL)
+            con_info->req_parms.condition_data
+             = g_array_new (TRUE,
+                            FALSE,
+                            sizeof (gchar*));
+
+          g_array_append_val (con_info->req_parms.condition_data, condition_data);
+
+          con_info->answercode = MHD_HTTP_OK;
+          return MHD_YES;
+        }
+      if (!strncmp (key, "event_data:", strlen ("event_data:")))
+        {
+          gchar *event_data;
+
+          event_data = g_strdup_printf ("%s0%.*s",
+                                        key + strlen ("event_data:"),
+                                        size,
+                                        data);
+          event_data[strlen (key + strlen ("event_data:"))] = '\0';
+
+          if (con_info->req_parms.event_data == NULL)
+            con_info->req_parms.event_data
+             = g_array_new (TRUE,
+                            FALSE,
+                            sizeof (gchar*));
+
+          g_array_append_val (con_info->req_parms.event_data, event_data);
+
+          con_info->answercode = MHD_HTTP_OK;
+          return MHD_YES;
+        }
+      if (!strncmp (key, "method_data:", strlen ("method_data:")))
+        {
+          gchar *method_data;
+
+          method_data = g_strdup_printf ("%s0%.*s",
+                                         key + strlen ("method_data:"),
+                                         size,
+                                         data);
+          method_data[strlen (key + strlen ("method_data:"))] = '\0';
+
+          if (con_info->req_parms.method_data == NULL)
+            con_info->req_parms.method_data
+             = g_array_new (TRUE,
+                            FALSE,
+                            sizeof (gchar*));
+
+          g_array_append_val (con_info->req_parms.method_data, method_data);
+
+          con_info->answercode = MHD_HTTP_OK;
+          return MHD_YES;
+        }
       if (!strncmp (key, "nvt:", strlen ("nvt:")))
         {
           gchar *nvt = g_strdup (key + strlen ("nvt:"));
@@ -1155,6 +1337,45 @@
                           con_info->req_parms.howto_use,
                           con_info->req_parms.howto_use_size);
     }
+  else if (!strcmp (con_info->req_parms.cmd, "create_escalator"))
+    {
+      if (openvas_validate (validator, "name", con_info->req_parms.name))
+        {
+          free (con_info->req_parms.name);
+          con_info->req_parms.name = NULL;
+        }
+      if (openvas_validate (validator, "comment", con_info->req_parms.comment))
+        {
+          free (con_info->req_parms.comment);
+          con_info->req_parms.comment = NULL;
+        }
+      if (openvas_validate (validator,
+                            "condition",
+                            con_info->req_parms.condition))
+        {
+          free (con_info->req_parms.condition);
+          con_info->req_parms.condition = NULL;
+        }
+      if (openvas_validate (validator, "event", con_info->req_parms.event))
+        {
+          free (con_info->req_parms.event);
+          con_info->req_parms.event = NULL;
+        }
+      if (openvas_validate (validator, "method", con_info->req_parms.method))
+        {
+          free (con_info->req_parms.method);
+          con_info->req_parms.method = NULL;
+        }
+      con_info->response =
+        create_escalator_omp (credentials, con_info->req_parms.name,
+                              con_info->req_parms.comment,
+                              con_info->req_parms.condition,
+                              con_info->req_parms.condition_data,
+                              con_info->req_parms.event,
+                              con_info->req_parms.event_data,
+                              con_info->req_parms.method,
+                              con_info->req_parms.method_data);
+    }
   else if (!strcmp (con_info->req_parms.cmd, "create_lsc_credential"))
     {
       if (openvas_validate (validator, "name", con_info->req_parms.name))
@@ -1204,6 +1425,13 @@
           con_info->req_parms.name = NULL;
         }
       if (openvas_validate (validator,
+                            "escalator",
+                            con_info->req_parms.escalator))
+        {
+          free (con_info->req_parms.escalator);
+          con_info->req_parms.escalator  = NULL;
+        }
+      if (openvas_validate (validator,
                             "scantarget",
                             con_info->req_parms.scantarget))
         {
@@ -1225,7 +1453,8 @@
         con_info->response =
           create_task_omp (credentials, con_info->req_parms.name, "comment",
                            con_info->req_parms.scantarget,
-                           con_info->req_parms.scanconfig);
+                           con_info->req_parms.scanconfig,
+                           con_info->req_parms.escalator);
     }
   else if (!strcmp (con_info->req_parms.cmd, "create_user"))
     {
@@ -1596,6 +1825,9 @@
   else if ((0 == strcmp (cmd, "delete_agent")) && (name != NULL))
     return delete_agent_omp (credentials, name);
 
+  else if ((!strcmp (cmd, "delete_escalator")) && (name != NULL))
+    return delete_escalator_omp (credentials, name);
+
   else if ((!strcmp (cmd, "delete_lsc_credential")) && (name != NULL))
     return delete_lsc_credential_omp (credentials, name);
 
@@ -1653,6 +1885,9 @@
                              NULL);
     }
 
+  else if (!strcmp (cmd, "get_escalators"))
+    return get_escalators_omp (credentials, 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-24 18:56:33 UTC (rev 6252)
+++ trunk/gsa/src/gsad_omp.c	2009-12-24 19:16:41 UTC (rev 6253)
@@ -118,7 +118,6 @@
   return html;
 }
 
-/** @todo Duplicated in openvas-manager. */
 /**
  * @brief Test whether a string equal to a given string exists in an array.
  *
@@ -241,8 +240,8 @@
       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. "
+                           "An internal error occurred while getting config list. "
+                           "The current list of configs is not available. "
                            "Diagnostics: Failure to send command to manager daemon.",
                            "/omp?cmd=get_status");
     }
@@ -253,13 +252,41 @@
       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. "
+                           "An internal error occurred while getting config list. "
+                           "The current list of configs is not available. "
                            "Diagnostics: Failure to receive response from manager daemon.",
                            "/omp?cmd=get_status");
     }
   free_entity (entity);
 
+  if (openvas_server_send (&session,
+                           "<get_escalators"
+                           " sort_field=\"name\""
+                           " 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 escalator list. "
+                           "The current list of escalators 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 escalator list. "
+                           "The current list of escalators is not available. "
+                           "Diagnostics: Failure to receive response from manager daemon.",
+                           "/omp?cmd=get_status");
+    }
+  free_entity (entity);
+
   if (message)
     g_string_append (xml, GSAD_MESSAGE_INVALID_PARAM ("Create Task"));
   g_string_append_printf (xml,
@@ -278,17 +305,18 @@
  * @param[in]  comment      Comment on task.
  * @param[in]  scantarget   Target for task.
  * @param[in]  scanconfig   Config for task.
+ * @param[in]  escalator    Escalator for task.
  *
  * @return Result of XSL transformation.
  */
 char *
 create_task_omp (credentials_t * credentials, char *name, char *comment,
-                 char *scantarget, char *scanconfig)
+                 char *scantarget, char *scanconfig, const char *escalator)
 {
   entity_t entity;
   gnutls_session_t session;
   char *text = NULL;
-  int socket;
+  int socket, ret;
 
   if (manager_connect (credentials, &socket, &session))
     return gsad_message ("Internal error", __FUNCTION__, __LINE__,
@@ -297,20 +325,44 @@
                          "Diagnostics: Failure to connect to manager daemon.",
                          "/omp?cmd=get_status");
 
-  if (openvas_server_sendf (&session,
-                            "<commands>"
-                            "<create_task>"
-                            "<config>%s</config>"
-                            "<target>%s</target>"
-                            "<name>%s</name>"
-                            "<comment>%s</comment>"
-                            "</create_task>"
-                            "<get_status"
-                            " sort_field=\"name\""
-                            " sort_order=\"ascending\"/>"
-                            "</commands>",
-                            scanconfig, scantarget, name, comment)
-      == -1)
+  if (strcmp (escalator, "--") == 0)
+    ret = openvas_server_sendf (&session,
+                                "<commands>"
+                                "<create_task>"
+                                "<config>%s</config>"
+                                "<target>%s</target>"
+                                "<name>%s</name>"
+                                "<comment>%s</comment>"
+                                "</create_task>"
+                                "<get_status"
+                                " sort_field=\"name\""
+                                " sort_order=\"ascending\"/>"
+                                "</commands>",
+                                scanconfig,
+                                scantarget,
+                                name,
+                                comment);
+  else
+    ret = openvas_server_sendf (&session,
+                                "<commands>"
+                                "<create_task>"
+                                "<config>%s</config>"
+                                "<escalator>%s</escalator>"
+                                "<target>%s</target>"
+                                "<name>%s</name>"
+                                "<comment>%s</comment>"
+                                "</create_task>"
+                                "<get_status"
+                                " sort_field=\"name\""
+                                " sort_order=\"ascending\"/>"
+                                "</commands>",
+                                scanconfig,
+                                escalator,
+                                scantarget,
+                                name,
+                                comment);
+
+  if (ret == -1)
     {
       openvas_server_close (socket, session);
       return gsad_message ("Internal error", __FUNCTION__, __LINE__,
@@ -1396,6 +1448,284 @@
 }
 
 /**
+ * @brief Send data for an escalator.
+ *
+ * @param[out]  data  Data.
+ *
+ * @return 0 on success, -1 on error.
+ */
+static int
+send_escalator_data (gnutls_session_t *session, GArray *data)
+{
+  int index = 0;
+  gchar *element;
+
+  if (data)
+    while ((element = g_array_index (data, gchar*, index++)))
+      if (openvas_server_sendf (session,
+                                "<data><name>%s</name>%s</data>",
+                                element,
+                                element + strlen (element) + 1))
+        return -1;
+
+  return 0;
+}
+
+/**
+ * @brief Create an escalator, get all escalators, XSL transform the result.
+ *
+ * @param[in]   credentials     Username and password for authentication.
+ * @param[in]   name            Name of new escalator.
+ * @param[out]  comment         Comment on escalator.
+ * @param[out]  condition       Condition.
+ * @param[out]  condition_data  Condition data.
+ * @param[out]  event           Event.
+ * @param[out]  event_data      Event data.
+ * @param[out]  method          Method.
+ * @param[out]  method_data     Method data.
+ *
+ * @return Result of XSL transformation.
+ */
+char *
+create_escalator_omp (credentials_t * credentials, char *name, char *comment,
+                      const char *condition, GArray *condition_data,
+                      const char *event, GArray *event_data,
+                      const char *method, GArray *method_data)
+{
+  entity_t entity;
+  gnutls_session_t session;
+  GString *xml;
+  int socket;
+
+  if (manager_connect (credentials, &socket, &session))
+    return gsad_message ("Internal error", __FUNCTION__, __LINE__,
+                         "An internal error occurred while creating a new target. "
+                         "No new target was created. "
+                         "Diagnostics: Failure to connect to manager daemon.",
+                         "/omp?cmd=get_targets");
+
+  xml = g_string_new ("<get_escalators>");
+
+  if (name == NULL || comment == NULL || condition == NULL || event == NULL
+      || method == NULL)
+    g_string_append (xml, GSAD_MESSAGE_INVALID_PARAM ("Create Escalator"));
+  else
+    {
+      /* Create the escalator. */
+
+      if (openvas_server_sendf (&session,
+                                "<create_escalator>"
+                                "<name>%s</name>"
+                                "%s%s%s",
+                                name,
+                                comment ? "<comment>" : "",
+                                comment ? comment : "",
+                                comment ? "</comment>" : "")
+          || openvas_server_sendf (&session, "<event>%s", event)
+          || send_escalator_data (&session, event_data)
+          || openvas_server_send (&session, "</event>")
+          || openvas_server_sendf (&session, "<method>%s", method)
+          || send_escalator_data (&session, method_data)
+          || openvas_server_send (&session, "</method>")
+          || openvas_server_sendf (&session, "<condition>%s", condition)
+          || send_escalator_data (&session, condition_data)
+          || openvas_server_send (&session,
+                                  "</condition>"
+                                  "</create_escalator>"))
+        {
+          g_string_free (xml, TRUE);
+          openvas_server_close (socket, session);
+          return gsad_message ("Internal error", __FUNCTION__, __LINE__,
+                               "An internal error occurred while creating a new escalator. "
+                               "No new escalator was created. "
+                               "Diagnostics: Failure to send command to manager daemon.",
+                               "/omp?cmd=get_escalators");
+        }
+
+      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 creating a new escalator. "
+                               "It is unclear whether the escalator has been created or not. "
+                               "Diagnostics: Failure to receive response from manager daemon.",
+                               "/omp?cmd=get_escalators");
+        }
+      free_entity (entity);
+    }
+
+  /* Get all the escalators. */
+
+  if (openvas_server_send (&session,
+                           "<get_escalators"
+                           " sort_field=\"name\""
+                           " 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 creating a new escalator. "
+                           "A new escalator was, however, created. "
+                           "Diagnostics: Failure to send command to manager daemon.",
+                           "/omp?cmd=get_escalators");
+    }
+
+  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 creating a new escalators. "
+                           "A new escalator was, however, created. "
+                           "Diagnostics: Failure to receive response from manager daemon.",
+                           "/omp?cmd=get_escalators");
+    }
+  free_entity (entity);
+
+  /* Cleanup, and return transformed XML. */
+
+  g_string_append (xml, "</get_escalators>");
+  openvas_server_close (socket, session);
+  return xsl_transform_omp (credentials, g_string_free (xml, FALSE));
+}
+
+/**
+ * @brief Delete an escalator, get all escalators, XSL transform the result.
+ *
+ * @param[in]  credentials  Username and password for authentication.
+ * @param[in]  escalator_name  Name of escalator.
+ *
+ * @return Result of XSL transformation.
+ */
+char *
+delete_escalator_omp (credentials_t * credentials, const char *escalator_name)
+{
+  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 deleting a escalator. "
+                         "The escalator is not deleted. "
+                         "Diagnostics: Failure to connect to manager daemon.",
+                         "/omp?cmd=get_escalators");
+
+  xml = g_string_new ("<get_escalators>");
+
+  /* Delete escalator and get all escalators. */
+
+  if (openvas_server_sendf (&session,
+                            "<commands>"
+                            "<delete_escalator><name>%s</name></delete_escalator>"
+                            "<get_escalators"
+                            " sort_field=\"name\""
+                            " sort_order=\"ascending\"/>"
+                            "</commands>",
+                            escalator_name)
+      == -1)
+    {
+      g_string_free (xml, TRUE);
+      openvas_server_close (socket, session);
+      return gsad_message ("Internal error", __FUNCTION__, __LINE__,
+                           "An internal error occurred while deleting an escalator. "
+                           "The escalator was not deleted. "
+                           "Diagnostics: Failure to send command to manager daemon.",
+                           "/omp?cmd=get_escalators");
+    }
+
+  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 deleting an escalator. "
+                           "It is unclear whether the escalator has been deleted or not. "
+                           "Diagnostics: Failure to read response from manager daemon.",
+                           "/omp?cmd=get_escalators");
+    }
+  free_entity (entity);
+
+  /* Cleanup, and return transformed XML. */
+
+  g_string_append (xml, "</get_escalators>");
+  openvas_server_close (socket, session);
+  return xsl_transform_omp (credentials, g_string_free (xml, FALSE));
+}
+
+/**
+ * @brief Get all escalators, XSL transform the result.
+ *
+ * @param[in]  credentials  Username and password for authentication.
+ * @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_escalators_omp (credentials_t * credentials, 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 esalator list. "
+                         "The current list of escalators is not available. "
+                         "Diagnostics: Failure to connect to manager daemon.",
+                         "/omp?cmd=get_status");
+
+  xml = g_string_new ("<get_escalators>");
+
+  /* Get the escalators. */
+
+  if (openvas_server_sendf (&session,
+                            "<get_escalators"
+                            " sort_field=\"%s\""
+                            " sort_order=\"%s\"/>",
+                            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 escalators list. "
+                           "The current list of escalators 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 escalators list. "
+                           "The current list of escalators 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_escalators>");
+  openvas_server_close (socket, session);
+  return xsl_transform_omp (credentials, g_string_free (xml, FALSE));
+}
+
+/**
  * @brief Create a target, get all targets, XSL transform the result.
  *
  * @param[in]   credentials  Username and password for authentication.
@@ -1573,7 +1903,7 @@
 
   xml = g_string_new ("<get_targets>");
 
-  /* Get the targets. */
+  /* Delete the target and get all targets. */
 
   if (openvas_server_sendf (&session,
                             "<commands>"

Modified: trunk/gsa/src/gsad_omp.h
===================================================================
--- trunk/gsa/src/gsad_omp.h	2009-12-24 18:56:33 UTC (rev 6252)
+++ trunk/gsa/src/gsad_omp.h	2009-12-24 19:16:41 UTC (rev 6253)
@@ -41,7 +41,8 @@
 
 char * gsad_newtask (credentials_t *, const char *);
 
-char * create_task_omp (credentials_t *, char *, char *, char *, char *);
+char * create_task_omp (credentials_t *, char *, char *, char *, char *,
+                        const char *);
 char * delete_task_omp (credentials_t *, const char *);
 char * abort_task_omp (credentials_t *, const char *);
 char * start_task_omp (credentials_t *, const char *);
@@ -55,6 +56,12 @@
                        const unsigned int, const char *, const char *,
                        const char *);
 
+char * create_escalator_omp (credentials_t *, char *, char *, const char *,
+                             GArray *, const char *, GArray *, const char *,
+                             GArray *);
+char * delete_escalator_omp (credentials_t *, const char *);
+char * get_escalators_omp (credentials_t *, 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/header.m4
===================================================================
--- trunk/gsa/src/html/header.m4	2009-12-24 18:56:33 UTC (rev 6252)
+++ trunk/gsa/src/html/header.m4	2009-12-24 19:16:41 UTC (rev 6253)
@@ -47,6 +47,7 @@
        <li><a href="/omp?cmd=get_targets">Targets</a></li>
        <li><a href="/omp?cmd=get_lsc_credentials">Credentials</a></li>
        <li><a href="/omp?cmd=get_agents">Agents</a></li>
+       <li><a href="/omp?cmd=get_escalators">Escalators</a></li>
       </ul>
       </li>
       <li>Administration

Modified: trunk/gsa/src/html/src/gsad.xsl
===================================================================
--- trunk/gsa/src/html/src/gsad.xsl	2009-12-24 18:56:33 UTC (rev 6252)
+++ trunk/gsa/src/html/src/gsad.xsl	2009-12-24 19:16:41 UTC (rev 6253)
@@ -100,6 +100,7 @@
               <li><a href="/omp?cmd=get_targets">Targets</a></li>
               <li><a href="/omp?cmd=get_lsc_credentials">Credentials</a></li>
               <li><a href="/omp?cmd=get_agents">Agents</a></li>
+              <li><a href="/omp?cmd=get_escalators">Escalators</a></li>
             </ul>
           </li>
           <li>

Modified: trunk/gsa/src/html/src/help/contents.htm4
===================================================================
--- trunk/gsa/src/html/src/help/contents.htm4	2009-12-24 18:56:33 UTC (rev 6252)
+++ trunk/gsa/src/html/src/help/contents.htm4	2009-12-24 19:16:41 UTC (rev 6253)
@@ -25,6 +25,7 @@
   <li> <a href="configure_scanconfigs.html">Configure Scan Configs</a></li>
   <li> <a href="configure_credentials.html">Configure Credentials</a></li>
   <li> <a href="configure_agents.html">Configure Agents</a></li>
+  <li> <a href="configure_escalators.html">Configure Escalators</a></li>
   </ul>
 <li> Administration</li>
   <ul>

Modified: trunk/gsa/src/html/src/omp.xsl
===================================================================
--- trunk/gsa/src/html/src/omp.xsl	2009-12-24 18:56:33 UTC (rev 6252)
+++ trunk/gsa/src/html/src/omp.xsl	2009-12-24 19:16:41 UTC (rev 6253)
@@ -553,6 +553,16 @@
           </td>
         </tr>
         <tr>
+          <td>Escalator:</td>
+          <td>
+            <xsl:if test="task/escalator">
+              <a href="/omp?cmd=get_escalators">
+                <xsl:value-of select="task/escalator/name"/>
+              </a>
+            </xsl:if>
+          </td>
+        </tr>
+        <tr>
           <td>Target:</td>
           <td>
             <a href="/omp?cmd=get_targets">
@@ -781,6 +791,10 @@
   <option value="{name}"><xsl:value-of select="name"/></option>
 </xsl:template>
 
+<xsl:template match="escalator" mode="newtask">
+  <option value="{name}"><xsl:value-of select="name"/></option>
+</xsl:template>
+
 <xsl:template name="status_bar">
   <xsl:param name="status">(Unknown)</xsl:param>
   <xsl:param name="progress">(Unknown)</xsl:param>
@@ -1640,6 +1654,253 @@
 
 <!-- END AGENTS MANAGEMENT -->
 
+<!-- BEGIN ESCALATORS MANAGEMENT -->
+
+<xsl:template name="html-create-escalator-form">
+  <xsl:param name="lsc-credentials"></xsl:param>
+  <div class="gb_window">
+    <div class="gb_window_part_left"></div>
+    <div class="gb_window_part_right"></div>
+    <div class="gb_window_part_center">New Escalator
+      <a href="/help/configure_escalators.html#newescalator"
+         title="Help: Configure Escalators (New Escalator)">
+        <img src="/img/help.png"/>
+      </a>
+    </div>
+    <div class="gb_window_part_content">
+      <form action="/omp" method="post" enctype="multipart/form-data">
+        <input type="hidden" name="cmd" value="create_escalator"/>
+        <table border="0" cellspacing="0" cellpadding="3" width="100%">
+          <tr>
+            <td valign="top" width="125">Name</td>
+            <td>
+              <input type="text" name="name" value="unnamed" size="30"
+                     maxlength="80"/>
+            </td>
+          </tr>
+          <tr>
+            <td valign="top" width="125">Comment (optional)</td>
+            <td>
+              <input type="text" name="comment" size="30" maxlength="400"/>
+            </td>
+          </tr>
+          <tr>
+            <td valign="top" width="125">Event</td>
+            <td colspan="2">
+              <table border="0" width="100%">
+                <tr>
+                  <td colspan="2" valign="top">
+                    <input type="radio" name="event" value="Task run status changed" checked="1"/>
+                    Task run status changed to
+                    <select name="event_data:status">
+                      <option value="Delete Requested">Delete Requested</option>
+                      <option value="Done" selected="1">Done</option>
+                      <option value="New">New</option>
+                      <option value="Requested">Requested</option>
+                      <option value="Running">Running</option>
+                      <option value="Stop Requested">Stop Requested</option>
+                      <option value="Stopped">Stopped</option>
+                    </select>
+                  </td>
+                </tr>
+              </table>
+            </td>
+          </tr>
+          <tr>
+            <td valign="top" width="125">Condition</td>
+            <td colspan="2">
+              <table border="0" width="100%">
+                <tr>
+                  <td colspan="2" valign="top">
+                    <input type="radio" name="condition" value="Always" checked="1"/>
+                    Always
+                  </td>
+                </tr>
+              </table>
+            </td>
+          </tr>
+          <tr>
+            <td valign="top" width="125">Method</td>
+            <td colspan="2">
+              <table border="0" width="100%">
+                <tr class="odd">
+                  <td colspan="3" valign="top">
+                    <input type="radio" name="method" value="Email" checked="1"/>
+                    Email
+                  </td>
+                </tr>
+                <tr>
+                  <td width="45"></td>
+                  <td width="100">Address</td>
+                  <td>
+                    <input type="text" name="method_data:address" size="30" maxlength="400"/>
+                  </td>
+                </tr>
+                <tr>
+                  <td width="45"></td>
+                  <td width="100">Message</td>
+                  <td>
+                    <table>
+                      <tr>
+                        <td colspan="3" valign="top">
+                          <input type="radio" name="method_data:notice" value="1" checked="1"/>
+                          Simple notice
+                        </td>
+                      </tr>
+                      <tr>
+                        <td colspan="3" valign="top">
+                          <input type="radio" name="method_data:notice" value="0"/>
+                          Summary (can include vulnerability details)
+                        </td>
+                      </tr>
+                    </table>
+                  </td>
+                </tr>
+              </table>
+            </td>
+          </tr>
+          <tr>
+            <td colspan="2" style="text-align:right;">
+              <input type="submit" name="submit" value="Create Escalator"/>
+            </td>
+          </tr>
+        </table>
+      </form>
+    </div>
+  </div>
+</xsl:template>
+
+<xsl:template name="html-escalators-table">
+  <div class="gb_window">
+    <div class="gb_window_part_left"></div>
+    <div class="gb_window_part_right"></div>
+    <div class="gb_window_part_center">Escalators
+      <a href="/help/configure_escalators.html#escalators"
+         title="Help: Configure Escalators (Escalators)">
+        <img src="/img/help.png"/>
+      </a>
+    </div>
+    <div class="gb_window_part_content_no_pad">
+      <div id="tasks">
+        <table class="gbntable" cellspacing="2" cellpadding="4" border="0">
+          <tr class="gbntablehead2">
+            <td>Name</td>
+            <td>Event</td>
+            <td>Condition</td>
+            <td>Method</td>
+            <td width="100">Actions</td>
+          </tr>
+          <xsl:apply-templates select="escalator"/>
+        </table>
+      </div>
+    </div>
+  </div>
+</xsl:template>
+
+<!--     CREATE_ESCALATOR_RESPONSE -->
+
+<xsl:template match="create_escalator_response">
+  <xsl:call-template name="command_result_dialog">
+    <xsl:with-param name="operation">Create Escalator</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>
+
+<!--     DELETE_ESCALATOR_RESPONSE -->
+
+<xsl:template match="delete_escalator_response">
+  <xsl:call-template name="command_result_dialog">
+    <xsl:with-param name="operation">
+      Delete Escalator
+    </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>
+
+<!--     ESCALATOR -->
+
+<xsl:template match="escalator">
+  <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>
+      <b><xsl:value-of select="name"/></b>
+      <xsl:choose>
+        <xsl:when test="comment != ''">
+          <br/>(<xsl:value-of select="comment"/>)
+        </xsl:when>
+        <xsl:otherwise></xsl:otherwise>
+      </xsl:choose>
+    </td>
+    <td>
+      <xsl:value-of select="event/text()"/>
+      <xsl:choose>
+        <xsl:when test="event/text()='Task run status changed' and string-length(event/data[name='status']/text()) &gt; 0">
+          <br/>(to <xsl:value-of select=" event/data[name='status']/text()"/>)
+        </xsl:when>
+      </xsl:choose>
+    </td>
+    <td><xsl:value-of select="condition/text()"/></td>
+    <td>
+      <xsl:value-of select="method/text()"/>
+      <xsl:choose>
+        <xsl:when test="method/text()='Email' and string-length(method/data[name='address']/text()) &gt; 0">
+          <br/>(<xsl:value-of select="method/data[name='address']/text()"/>)
+        </xsl:when>
+      </xsl:choose>
+    </td>
+    <td>
+      <xsl:choose>
+        <xsl:when test="in_use='0'">
+          <a href="/omp?cmd=delete_escalator&amp;name={name}"
+             title="Delete Escalator" style="margin-left:3px;">
+            <img src="/img/delete.png" border="0" alt="Delete"/>
+          </a>
+        </xsl:when>
+        <xsl:otherwise>
+          <img src="/img/delete_inactive.png"
+               border="0"
+               alt="Delete"
+               style="margin-left:3px;"/>
+        </xsl:otherwise>
+      </xsl:choose>
+    </td>
+  </tr>
+</xsl:template>
+
+<!--     GET_ESCALATORS_RESPONSE -->
+
+<xsl:template match="get_escalators">
+  <xsl:apply-templates select="gsad_msg"/>
+  <xsl:apply-templates select="commands_response/delete_escalator_response"/>
+  <xsl:apply-templates select="create_escalator_response"/>
+  <xsl:call-template name="html-create-escalator-form">
+    <xsl:with-param
+      name="lsc-credentials"
+      select="get_lsc_credentials_response | commands_response/get_lsc_credentials_response"/>
+  </xsl:call-template>
+  <!-- The for-each makes the get_escalators_response the current node. -->
+  <xsl:for-each select="get_escalators_response | commands_response/get_escalators_response">
+    <xsl:call-template name="html-escalators-table"/>
+  </xsl:for-each>
+</xsl:template>
+
+<!-- END ESCALATORS MANAGEMENT -->
+
 <!-- BEGIN TARGETS MANAGEMENT -->
 
 <xsl:template name="html-create-target-form">
@@ -3375,6 +3636,16 @@
           </td>
         </tr>
         <tr>
+          <td>Escalator (optional)</td>
+          <td>
+            <select name="escalator">
+              <option value="--">--</option>
+              <xsl:apply-templates select="get_escalators_response/escalator"
+                                   mode="newtask"/>
+            </select>
+          </td>
+        </tr>
+        <tr>
           <td colspan="2" style="text-align:right;">
             <input type="submit" name="submit" value="Create Task"/>
           </td>



More information about the Openvas-commits mailing list