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: Allow the update of setting variables for time and date formats #179

Merged
merged 4 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions src/gsad_gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -11984,7 +11984,9 @@
{
const char *lang, *text, *old_passwd, *passwd, *max;
const char *details_fname, *list_fname, *report_fname;
const char *time_format, *date_format;
gchar *lang_64, *text_64, *max_64, *fname_64;
gchar *time_format_64, *date_format_64;
mattmundell marked this conversation as resolved.
Show resolved Hide resolved
GString *xml;
entity_t entity;
params_t *changed, *defaults, *filters;
Expand All @@ -12004,6 +12006,8 @@
details_fname = params_value (params, "details_fname");
list_fname = params_value (params, "list_fname");
report_fname = params_value (params, "report_fname");
time_format = params_value (params, "time_format");
date_format = params_value (params, "date_format");

Check warning on line 12010 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L12009-L12010

Added lines #L12009 - L12010 were not covered by tests

CHECK_VARIABLE_INVALID (text, "Save Settings")
CHECK_VARIABLE_INVALID (text, "Save Settings")
Expand All @@ -12013,6 +12017,8 @@
CHECK_VARIABLE_INVALID (details_fname, "Save Settings")
CHECK_VARIABLE_INVALID (list_fname, "Save Settings")
CHECK_VARIABLE_INVALID (report_fname, "Save Settings")
CHECK_VARIABLE_INVALID (time_format, "Save Settings")
CHECK_VARIABLE_INVALID (date_format, "Save Settings")

Check warning on line 12021 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L12020-L12021

Added lines #L12020 - L12021 were not covered by tests

xml = g_string_new ("");

Expand Down Expand Up @@ -12638,6 +12644,110 @@
}
}

/* Send User Interface Time Format. */
changed_value = params_value (changed, "time_format");

Check warning on line 12648 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L12648

Added line #L12648 was not covered by tests
if (changed_value == NULL
|| (strcmp (changed_value, "") && strcmp (changed_value, "0")))

Check warning on line 12650 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L12650

Added line #L12650 was not covered by tests
{
time_format_64 =
g_base64_encode ((guchar *) time_format, strlen (time_format));

Check warning on line 12653 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L12653

Added line #L12653 was not covered by tests

if (gvm_connection_sendf (connection,
"<modify_setting"
" setting_id"
"=\"11deb7ff-550b-4950-aacf-06faeb7c61b9\">"
"<value>%s</value>"
"</modify_setting>",
time_format_64 ? time_format_64 : "")
== -1)
{
g_free (time_format_64);
cmd_response_data_set_status_code (response_data,

Check warning on line 12665 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L12664-L12665

Added lines #L12664 - L12665 were not covered by tests
MHD_HTTP_INTERNAL_SERVER_ERROR);
return gsad_message (

Check warning on line 12667 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L12667

Added line #L12667 was not covered by tests
credentials, "Internal error", __func__, __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.",
response_data);
}
g_free (time_format_64);

Check warning on line 12674 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L12674

Added line #L12674 was not covered by tests

entity = NULL;
xml_string_append (xml, "<save_setting id=\"%s\">",

Check warning on line 12677 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L12676-L12677

Added lines #L12676 - L12677 were not covered by tests
"11deb7ff-550b-4950-aacf-06faeb7c61b9");
if (read_entity_and_string_c (connection, &entity, &xml))
{
g_string_free (xml, TRUE);
cmd_response_data_set_status_code (response_data,

Check warning on line 12682 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L12681-L12682

Added lines #L12681 - L12682 were not covered by tests
MHD_HTTP_INTERNAL_SERVER_ERROR);
return gsad_message (

Check warning on line 12684 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L12684

Added line #L12684 was not covered by tests
credentials, "Internal error", __func__, __LINE__,
"An internal error occurred while saving settings. "
"It is unclear whether all the settings were saved. "
"Diagnostics: Failure to receive response from manager daemon.",
response_data);
}
xml_string_append (xml, "</save_setting>");

Check warning on line 12691 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L12691

Added line #L12691 was not covered by tests
if (gmp_success (entity) != 1)
{
set_http_status_from_entity (entity, response_data);
modify_failed = 1;

Check warning on line 12695 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L12694-L12695

Added lines #L12694 - L12695 were not covered by tests
}
}

/* Send User Interface Date Format. */
changed_value = params_value (changed, "date_format");

Check warning on line 12700 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L12700

Added line #L12700 was not covered by tests
if (changed_value == NULL
|| (strcmp (changed_value, "") && strcmp (changed_value, "0")))

Check warning on line 12702 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L12702

Added line #L12702 was not covered by tests
{
date_format_64 =
g_base64_encode ((guchar *) date_format, strlen (date_format));

Check warning on line 12705 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L12705

Added line #L12705 was not covered by tests

if (gvm_connection_sendf (connection,
"<modify_setting"
" setting_id"
"=\"d9857b7c-1159-4193-9bc0-18fae5473a69\">"
"<value>%s</value>"
"</modify_setting>",
date_format_64 ? date_format_64 : "")
== -1)
{
g_free (date_format_64);
cmd_response_data_set_status_code (response_data,

Check warning on line 12717 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L12716-L12717

Added lines #L12716 - L12717 were not covered by tests
MHD_HTTP_INTERNAL_SERVER_ERROR);
return gsad_message (

Check warning on line 12719 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L12719

Added line #L12719 was not covered by tests
credentials, "Internal error", __func__, __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.",
response_data);
}
g_free (date_format_64);

Check warning on line 12726 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L12726

Added line #L12726 was not covered by tests

entity = NULL;
xml_string_append (xml, "<save_setting id=\"%s\">",

Check warning on line 12729 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L12728-L12729

Added lines #L12728 - L12729 were not covered by tests
"d9857b7c-1159-4193-9bc0-18fae5473a69");
if (read_entity_and_string_c (connection, &entity, &xml))
{
g_string_free (xml, TRUE);
cmd_response_data_set_status_code (response_data,

Check warning on line 12734 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L12733-L12734

Added lines #L12733 - L12734 were not covered by tests
MHD_HTTP_INTERNAL_SERVER_ERROR);
return gsad_message (

Check warning on line 12736 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L12736

Added line #L12736 was not covered by tests
credentials, "Internal error", __func__, __LINE__,
"An internal error occurred while saving settings. "
"It is unclear whether all the settings were saved. "
"Diagnostics: Failure to receive response from manager daemon.",
response_data);
}
xml_string_append (xml, "</save_setting>");

Check warning on line 12743 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L12743

Added line #L12743 was not covered by tests
if (gmp_success (entity) != 1)
{
set_http_status_from_entity (entity, response_data);
modify_failed = 1;

Check warning on line 12747 in src/gsad_gmp.c

View check run for this annotation

Codecov / codecov/patch

src/gsad_gmp.c#L12746-L12747

Added lines #L12746 - L12747 were not covered by tests
}
}

if (user_changed)
{
session_add_user (user_get_token (user), user);
Expand Down
2 changes: 2 additions & 0 deletions src/gsad_validator.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,8 @@ init_validator ()
"^(second|minute|hour|day|week|month|year|decade)$");
gvm_validator_add (validator, "chart_title", "(?s)^.*$");
gvm_validator_add (validator, "icalendar", "(?s)^BEGIN:VCALENDAR.+$");
gvm_validator_add (validator, "time_format", "^(12|24|system_default)$");
gvm_validator_add (validator, "date_format", "^(wmdy|wdmy|system_default)$");

/* Binary data params that should not use no UTF-8 validation */
gvm_validator_add_binary (validator, "certificate_bin");
Expand Down
Loading