Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new handler for single performance report (backport #3149) #3156

Merged
merged 8 commits into from
Sep 23, 2021
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ 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)
### Deprecated
### Fixed
- Don't crash target table when port_list is undefined [#3120](https://github.com/greenbone/gsa/pull/3120)
### Removed
Expand Down
2 changes: 2 additions & 0 deletions gsad/src/gsad.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ init_validator ()
"|(get_setting)"
"|(get_settings)"
"|(get_system_reports)"
"|(get_system_report)"
"|(get_tag)"
"|(get_tags)"
"|(get_target)"
Expand Down Expand Up @@ -2112,6 +2113,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)
Expand Down
116 changes: 109 additions & 7 deletions gsad/src/gsad_gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -10137,6 +10137,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 ("<get_system_report>");

if (duration && strcmp (duration, ""))
{
gmp_command =
g_markup_printf_escaped ("<get_system_reports"
" name=\"%s\""
" duration=\"%s\""
" slave_id=\"%s\"/>",
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 ("<get_system_reports"
" name=\"%s\""
" start_time=\"%s\""
" end_time=\"%s\""
" slave_id=\"%s\"/>",
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, "</get_system_report>");
return envelope_gmp (connection, credentials, params,
g_string_free (xml, FALSE), response_data);
}

/**
* @brief Return system report image.
*
Expand All @@ -10149,9 +10241,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;
Expand Down Expand Up @@ -10235,10 +10328,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");
Expand Down
8 changes: 6 additions & 2 deletions gsad/src/gsad_gmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *,
Expand Down
8 changes: 4 additions & 4 deletions gsad/src/gsad_http_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down