diff --git a/CHANGELOG.md b/CHANGELOG.md index 147c91f781..88ac05750e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [21.4.3] (unreleased) ### Added +- Add new handler for single performance report [#3149](https://github.com/greenbone/gsa/pull/3149) ### Changed - Changed conditions for enabling CreateTicketIcon on results detailspage [#3154](https://github.com/greenbone/gsa/pull/3154) @@ -17,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed - Don't crash target table when port_list is undefined [#3120](https://github.com/greenbone/gsa/pull/3120) + [Unreleased]: https://github.com/greenbone/gsa/compare/v21.4.2...gsa-21.04 ## [21.4.2] 2021-08-03 diff --git a/gsad/src/gsad.c b/gsad/src/gsad.c index b121190618..3ced846c44 100644 --- a/gsad/src/gsad.c +++ b/gsad/src/gsad.c @@ -394,6 +394,7 @@ init_validator () "|(get_setting)" "|(get_settings)" "|(get_system_reports)" + "|(get_system_report)" "|(get_tag)" "|(get_tags)" "|(get_target)" @@ -2113,6 +2114,7 @@ exec_gmp_get (http_connection_t *con, gsad_connection_info_t *con_info, ELSE (get_setting) ELSE (get_settings) ELSE (get_system_reports) + ELSE (get_system_report) ELSE (get_tag) ELSE (get_tags) ELSE (get_target) diff --git a/gsad/src/gsad_gmp.c b/gsad/src/gsad_gmp.c index d95b42987c..b8352f5f64 100644 --- a/gsad/src/gsad_gmp.c +++ b/gsad/src/gsad_gmp.c @@ -10154,6 +10154,98 @@ get_system_reports_gmp (gvm_connection_t *connection, g_string_free (xml, FALSE), response_data); } +/** + * @brief Get a single system report + * + * @param[in] connection Connection to manager. + * @param[in] credentials Username and password for authentication. + * @param[in] params Request parameters. + * @param[out] response_data Extra data return for the HTTP response. + * + * @return Enveloped XML object. + */ +char * +get_system_report_gmp (gvm_connection_t *connection, credentials_t *credentials, + params_t *params, cmd_response_data_t *response_data) +{ + GString *xml; + + const char *name, *slave_id, *duration, *start_time, *end_time; + char *gmp_command; + + name = params_value (params, "name"); + slave_id = params_value (params, "slave_id"); + + duration = params_value (params, "duration"); + start_time = params_value (params, "start_time"); + end_time = params_value (params, "end_time"); + + CHECK_VARIABLE_INVALID (name, "Get System Report"); + xml = g_string_new (""); + + if (duration && strcmp (duration, "")) + { + gmp_command = + g_markup_printf_escaped ("", + name, duration, slave_id ? slave_id : "0"); + } + else + { + start_time = params_value (params, "start_time"); + end_time = params_value (params, "end_time"); + + CHECK_VARIABLE_INVALID (start_time, "Get System Report") + CHECK_VARIABLE_INVALID (end_time, "Get System Report") + + gmp_command = g_markup_printf_escaped ("", + name, start_time, end_time, + slave_id ? slave_id : "0"); + } + + if (gvm_connection_sendf (connection, "%s", gmp_command) == -1) + { + g_string_free (xml, TRUE); + g_free (gmp_command); + cmd_response_data_set_status_code (response_data, + MHD_HTTP_INTERNAL_SERVER_ERROR); + return gsad_message ( + credentials, "Internal error", __func__, __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.", + response_data); + } + + if (read_string_c (connection, &xml)) + { + g_string_free (xml, TRUE); + g_free (gmp_command); + cmd_response_data_set_status_code (response_data, + MHD_HTTP_INTERNAL_SERVER_ERROR); + return gsad_message ( + credentials, "Internal error", __func__, __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.", + response_data); + } + + g_free (gmp_command); + + /* Cleanup, and return transformed XML. */ + + g_string_append (xml, ""); + return envelope_gmp (connection, credentials, params, + g_string_free (xml, FALSE), response_data); +} + /** * @brief Return system report image. * @@ -10166,9 +10258,10 @@ get_system_reports_gmp (gvm_connection_t *connection, * @return Image, or NULL. */ char * -get_system_report_gmp (gvm_connection_t *connection, credentials_t *credentials, - const char *url, params_t *params, - cmd_response_data_t *response_data) +get_system_report_gmp_from_url (gvm_connection_t *connection, + credentials_t *credentials, const char *url, + params_t *params, + cmd_response_data_t *response_data) { entity_t entity; entity_t report_entity; @@ -10252,10 +10345,19 @@ get_system_report_gmp (gvm_connection_t *connection, credentials_t *credentials, content = (char *) g_base64_decode (content_64, &content_length); #if 1 - cmd_response_data_set_content_type (response_data, - GSAD_CONTENT_TYPE_IMAGE_PNG); - //*content_disposition = g_strdup_printf ("attachment; - // filename=\"xxx.png\""); + if (strcmp (entity_attribute (report_entity, "format"), "png") + == 0) + { + cmd_response_data_set_content_type ( + response_data, GSAD_CONTENT_TYPE_IMAGE_PNG); + } + else + { + cmd_response_data_set_content_type ( + response_data, GSAD_CONTENT_TYPE_TEXT_PLAIN); + } + //*content_disposition = g_strdup_printf ("attachment; + // filename=\"xxx.png\""); #else g_free (content); content = g_strdup ("helo"); diff --git a/gsad/src/gsad_gmp.h b/gsad/src/gsad_gmp.h index 2889eb4832..cfd9fc3ad8 100644 --- a/gsad/src/gsad_gmp.h +++ b/gsad/src/gsad_gmp.h @@ -507,8 +507,12 @@ char * get_system_reports_gmp (gvm_connection_t *, credentials_t *, params_t *, cmd_response_data_t *); char * -get_system_report_gmp (gvm_connection_t *, credentials_t *, const char *, - params_t *, cmd_response_data_t *); +get_system_report_gmp (gvm_connection_t *, credentials_t *, params_t *, + cmd_response_data_t *); +char * +get_system_report_gmp_from_url (gvm_connection_t *, credentials_t *, + const char *, params_t *, + cmd_response_data_t *); char * get_report_format_gmp (gvm_connection_t *, credentials_t *, params_t *, diff --git a/gsad/src/gsad_http_handler.c b/gsad/src/gsad_http_handler.c index f3529ad579..59b19701fb 100644 --- a/gsad/src/gsad_http_handler.c +++ b/gsad/src/gsad_http_handler.c @@ -25,7 +25,7 @@ #include "gsad_base.h" /* for ctime_r_strip_newline */ #include "gsad_credentials.h" /* for credentials_t */ -#include "gsad_gmp.h" /* for get_system_report_gmp */ +#include "gsad_gmp.h" /* for get_system_report_gmp_from_url */ #include "gsad_i18n.h" /* for accept_language_to_env_fmt */ #include "gsad_settings.h" /* for get_guest_usernmae */ #include "gsad_user.h" /* for user_t */ @@ -597,9 +597,9 @@ handle_system_report (http_connection_t *connection, const char *method, switch (manager_connect (credentials, &con, response_data)) { case 0: /* success */ - res = get_system_report_gmp (&con, credentials, - &url[0] + strlen ("/system_report/"), params, - response_data); + res = get_system_report_gmp_from_url ( + &con, credentials, &url[0] + strlen ("/system_report/"), params, + response_data); gvm_connection_close (&con); break; case 1: /* manager closed connection */