41 #include <arpa/inet.h>
46 #include <gvm/base/cvss.h>
47 #include <gvm/gmp/gmp.h>
48 #include <gvm/util/fileutils.h>
49 #include <gvm/util/serverutils.h>
50 #include <gvm/util/xmlutils.h>
51 #include <microhttpd.h>
53 #include <netinet/in.h>
57 #include <sys/socket.h>
67 #define G_LOG_DOMAIN "gsad gmp"
72 #define OPENVASMD_ADDRESS "127.0.0.1"
75 #define GSAD_MESSAGE_INVALID \
76 "<gsad_msg status_text=\"%s\" operation=\"%s\">" \
77 "At least one entered value contains invalid characters or exceeds" \
78 " a size limit. You may use the Back button of your browser to adjust" \
79 " the entered values. If in doubt, the online help of the respective " \
81 " will lead you to the appropriate help page." \
85 #define GSAD_MESSAGE_INVALID_PARAM(op) \
86 "<gsad_msg status_text=\"Invalid parameter\" operation=\"" op "\">" \
87 "At least one entered value contains invalid characters or exceeds" \
88 " a size limit. You may use the Back button of your browser to adjust" \
89 " the entered values. If in doubt, the online help of the respective " \
91 " will lead you to the appropriate help page." \
98 #define GSAD_STATUS_INVALID_REQUEST MHD_HTTP_UNPROCESSABLE_ENTITY
103 #define RESULTS_PER_PAGE 100
108 #define FILT_ID_NONE "0"
113 #define FILT_ID_USER_SETTING "-2"
121 #define CHECK_VARIABLE_INVALID(name, op_name) \
124 return message_invalid (connection, credentials, params, response_data, \
125 "Given " G_STRINGIFY (name) " was invalid", \
144 #define XML_REPORT_FORMAT_ID "a994b278-1f62-11e1-96ac-406186ea4fc5"
145 #define ANONXML_REPORT_FORMAT_ID "5057e5cc-b825-11e4-9d0e-28d24461215b"
251 const char *details,
const char *
id);
277 gmp_init (
const gchar *manager_address_unix,
const gchar *manager_address_tls,
280 if (manager_address_unix)
285 else if (manager_address_tls)
337 string = g_string_new (
"");
339 gettimeofday (&tv, NULL);
340 res = g_markup_printf_escaped (
342 "<version>%s</version>"
343 "<vendor_version>%s</vendor_version>"
346 "<timezone>%s</timezone>"
348 "<session>%ld</session>"
350 "<severity>%s</severity>"
352 "<client_address>%s</client_address>"
353 "<backend_operation>%.2f</backend_operation>",
360 g_string_append (
string, res);
366 warning_elem = g_markup_printf_escaped (
"<password_warning>"
368 "</password_warning>",
370 g_string_append (
string, warning_elem);
371 g_free (warning_elem);
374 g_string_append_printf (
string,
"%s</envelope>", xml);
378 return g_string_free (
string, FALSE);
398 if (strcmp (name,
string) == 0)
421 && strcmp (name,
string) == 0)
441 params_t *params,
const char *next,
const char *fail_next,
446 const char *status_text;
455 if (read_entity_c (connection, &entity))
458 MHD_HTTP_INTERNAL_SERVER_ERROR);
460 credentials,
"Internal error", __FUNCTION__, __LINE__,
461 "An internal error occurred while saving a config. "
462 "It is unclear whether the entire config has been saved. "
463 "Diagnostics: Failure to read command to manager daemon.",
469 status_text = entity_attribute (entity,
"status_text");
470 if (status_text == NULL)
472 free_entity (entity);
474 MHD_HTTP_INTERNAL_SERVER_ERROR);
476 credentials,
"Internal error", __FUNCTION__, __LINE__,
477 "An internal error occurred while saving a config. "
478 "It is unclear whether the entire config has been saved. "
479 "Diagnostics: Failure to parse status_text from response.",
483 if (
str_equal (status_text,
"Config is in use"))
485 const char *message =
"The config is now in use by a task,"
486 " so only name and comment can be modified.";
490 "Save Config", message, NULL, NULL);
492 free_entity (entity);
495 else if (
str_equal (status_text,
"MODIFY_CONFIG name must be unique"))
497 const char *message =
"A config with the given name exists already.";
501 "Save Config", message, NULL, NULL);
503 free_entity (entity);
512 "Save Config", response_data);
513 free_entity (entity);
533 status = entity_attribute (entity,
"status");
534 if ((status == NULL) || (strlen (status) == 0))
537 return status[0] ==
'2';
552 MHD_HTTP_INTERNAL_SERVER_ERROR);
553 else if (
str_equal (entity_attribute (entity,
"status_text"),
554 "Permission denied"))
556 else if (
str_equal (entity_attribute (entity,
"status"),
"404"))
584 *entity_return = NULL;
586 ret = gvm_connection_sendf (connection,
"%s", command);
593 if (read_entity_and_text_c (connection, &entity, response))
598 *entity_return = entity;
600 free_entity (entity);
620 gchar **response, entity_t *entity_return,
627 va_start (args, format);
628 command = g_markup_vprintf_escaped (format, args);
631 ret =
gmp (connection,
credentials, response, entity_return, response_data,
658 ret = gvm_connection_sendf (connection,
"<get_settings setting_id=\"%s\"/>",
664 if (read_entity_and_text_c (connection, &entity, &response))
667 status = entity_attribute (entity,
"status");
668 if (status == NULL || strlen (status) == 0)
671 free_entity (entity);
675 if (status[0] ==
'2')
678 setting = entity_child (entity,
"setting");
681 free_entity (entity);
685 setting = entity_child (setting,
"value");
688 free_entity (entity);
692 *value = g_strdup (entity_text (setting));
694 free_entity (entity);
700 free_entity (entity);
727 const char *action,
const char *message,
const char *details,
732 xml = g_string_new (
"");
733 xml_string_append (xml,
735 "<action>%s</action>"
736 "<message>%s</message>",
737 action ? action :
"", message ? message :
"");
740 xml_string_append (xml,
"<details>%s</details>", details);
743 xml_string_append (xml,
"<id>%s</id>",
id);
745 g_string_append (xml,
"</action_result>");
748 g_string_free (xml, FALSE), response_data);
766 const char *message,
const char *op_name)
769 op_name, message, NULL, NULL);
784 params_t *params, entity_t entity,
const char *action,
788 entity_t status_details_entity;
797 status_details_entity = entity_child (entity,
"status_details");
800 entity_attribute (entity,
"status_text"),
801 entity_text (status_details_entity),
802 entity_attribute (entity,
"id"));
828 xml = g_string_new (
"");
832 cmd = g_strdup_printf (
"get_%s", type);
836 cmd = g_strdup_printf (
"get_%ss", type);
839 g_string_append_printf (xml,
"<get_%s>", type);
848 MHD_HTTP_INTERNAL_SERVER_ERROR);
850 credentials,
"Internal error", __FUNCTION__, __LINE__,
851 "An internal error occurred while getting a resource list. "
852 "The current list of resources is not available. "
853 "Diagnostics: Failure to send command to manager daemon.",
859 if (read_entity_and_string_c (connection, &entity, &xml))
861 g_string_free (xml, TRUE);
865 MHD_HTTP_INTERNAL_SERVER_ERROR);
867 credentials,
"Internal error", __FUNCTION__, __LINE__,
868 "An internal error occurred while getting resources list. "
869 "The current list of resources is not available. "
870 "Diagnostics: Failure to receive response from manager daemon.",
882 entity_attribute (entity,
"status_text"), response_data);
884 g_string_free (xml, TRUE);
886 free_entity (entity);
890 g_string_append_printf (xml,
"</get_%s>", type);
893 free_entity (entity);
896 g_string_free (xml, FALSE), response_data);
913 get_one (gvm_connection_t *connection,
const char *type,
919 const gchar *details;
921 id_name = g_strdup_printf (
"%s_id", type);
932 if (arguments == NULL)
972 cmd = g_strdup_printf (
"get_%s", type);
981 MHD_HTTP_INTERNAL_SERVER_ERROR);
983 credentials,
"Internal error", __FUNCTION__, __LINE__,
984 "An internal error occurred while getting a resource list. "
985 "The current list of resources is not available. "
986 "Diagnostics: Failure to send command to manager daemon.",
992 xml = g_string_new (
"");
993 g_string_append_printf (xml,
"<%s>", cmd);
995 if (read_entity_and_string_c (connection, &entity, &xml))
998 g_string_free (xml, TRUE);
1001 MHD_HTTP_INTERNAL_SERVER_ERROR);
1003 credentials,
"Internal error", __FUNCTION__, __LINE__,
1004 "An internal error occurred while getting resources list. "
1005 "The current list of resources is not available. "
1006 "Diagnostics: Failure to receive response from manager daemon.",
1018 entity_attribute (entity,
"status_text"), response_data);
1021 g_string_free (xml, TRUE);
1022 free_entity (entity);
1026 g_string_append_printf (xml,
"</%s>", cmd);
1029 free_entity (entity);
1032 g_string_free (xml, FALSE), response_data);
1048 get_many (gvm_connection_t *connection,
const char *type,
1052 const gchar *filter_id, *filter;
1053 const gchar *details;
1059 if (arguments == NULL)
1064 if (details && !
str_equal (details,
""))
1069 if (!filter_id && !filter)
1104 const char *extra_get_attribs,
const char *extra_xml,
1109 const char *resource_id;
1111 id_name = g_strdup_printf (
"%s_id", type);
1115 if (resource_id == NULL)
1119 credentials,
"Internal error", __FUNCTION__, __LINE__,
1120 "An internal error occurred while editing a resource. "
1121 "The resource remains as it was. "
1122 "Diagnostics: Required ID parameter was NULL.",
1126 if (gvm_connection_sendf (connection,
1131 type, extra_get_attribs ? extra_get_attribs :
"",
1136 MHD_HTTP_INTERNAL_SERVER_ERROR);
1138 credentials,
"Internal error", __FUNCTION__, __LINE__,
1139 "An internal error occurred while getting a resource. "
1140 "Diagnostics: Failure to send command to manager daemon.",
1144 xml = g_string_new (
"");
1146 g_string_append_printf (xml,
"<edit_%s>", type);
1149 g_string_append (xml, extra_xml);
1151 if (read_string_c (connection, &xml))
1153 g_string_free (xml, TRUE);
1155 MHD_HTTP_INTERNAL_SERVER_ERROR);
1157 credentials,
"Internal error", __FUNCTION__, __LINE__,
1158 "An internal error occurred while getting a resource. "
1159 "Diagnostics: Failure to receive response from manager daemon.",
1165 g_string_append_printf (xml,
"</edit_%s>", type);
1167 g_string_free (xml, FALSE), response_data);
1183 const char *type,
const char *uuid, entity_t resource_entity)
1185 gchar *creation_time, *modification_time, *name, *format_name;
1188 if (resource_entity)
1190 entity_t creation_time_entity, modification_time_entity;
1191 entity_t task_entity, format_entity, format_name_entity, name_entity;
1193 creation_time_entity = entity_child (resource_entity,
"creation_time");
1195 if (creation_time_entity)
1196 creation_time = entity_text (creation_time_entity);
1198 creation_time = NULL;
1200 modification_time_entity =
1201 entity_child (resource_entity,
"modification_time");
1203 if (modification_time_entity)
1204 modification_time = entity_text (modification_time_entity);
1206 modification_time = NULL;
1208 if (strcasecmp (type,
"report") == 0)
1210 task_entity = entity_child (resource_entity,
"task");
1212 name_entity = entity_child (task_entity,
"name");
1216 format_entity = entity_child (resource_entity,
"report_format");
1219 format_name_entity = entity_child (format_entity,
"name");
1222 format_name_entity = NULL;
1224 if (format_name_entity && strlen (entity_text (format_name_entity)))
1225 format_name = entity_text (format_name_entity);
1231 name_entity = entity_child (resource_entity,
"name");
1236 name = entity_text (name_entity);
1242 creation_time = NULL;
1243 modification_time = NULL;
1251 creation_time, modification_time, name, format_name);
1273 entity_t resource_entity;
1274 char *content = NULL;
1276 gchar *fname_format, *file_name;
1278 const char *resource_id, *subtype;
1280 xml = g_string_new (
"");
1282 id_name = g_strdup_printf (
"%s_id", type);
1286 if (resource_id == NULL)
1290 g_string_free (xml, FALSE), response_data);
1295 if (gvm_connection_sendf (connection,
1301 type, type, resource_id, subtype ?
" type=\"" :
"",
1302 subtype ? subtype :
"", subtype ?
"\"" :
"")
1305 g_string_free (xml, TRUE);
1307 MHD_HTTP_INTERNAL_SERVER_ERROR);
1309 credentials,
"Internal error", __FUNCTION__, __LINE__,
1310 "An internal error occurred while getting a resource. "
1311 "The resource could not be delivered. "
1312 "Diagnostics: Failure to send command to manager daemon.",
1317 if (read_entity_and_text_c (connection, &entity, &content))
1319 g_string_free (xml, TRUE);
1321 MHD_HTTP_INTERNAL_SERVER_ERROR);
1323 credentials,
"Internal error", __FUNCTION__, __LINE__,
1324 "An internal error occurred while getting a resource. "
1325 "The resource could not be delivered. "
1326 "Diagnostics: Failure to receive response from manager daemon.",
1333 resource_entity = entity_child (entity, type);
1335 if (resource_entity == NULL)
1338 free_entity (entity);
1339 g_string_free (xml, TRUE);
1341 MHD_HTTP_INTERNAL_SERVER_ERROR);
1343 credentials,
"Internal error", __FUNCTION__, __LINE__,
1344 "An internal error occurred while getting a resource. "
1345 "The resource could not be delivered. "
1346 "Diagnostics: Failure to receive resource from manager daemon.",
1351 &fname_format, response_data);
1355 free_entity (entity);
1356 g_string_free (xml, TRUE);
1358 MHD_HTTP_INTERNAL_SERVER_ERROR);
1363 credentials,
"Internal error", __FUNCTION__, __LINE__,
1364 "An internal error occurred while getting a setting. "
1365 "The setting could not be delivered. "
1366 "Diagnostics: Failure to send command to manager daemon.",
1370 credentials,
"Internal error", __FUNCTION__, __LINE__,
1371 "An internal error occurred while getting a setting. "
1372 "The setting could not be delivered. "
1373 "Diagnostics: Failure to receive response from manager daemon.",
1377 credentials,
"Internal error", __FUNCTION__, __LINE__,
1378 "An internal error occurred while getting a setting. "
1379 "The setting could not be delivered. "
1380 "Diagnostics: Internal error.",
1385 if (fname_format == NULL)
1387 g_warning (
"%s : File name format setting not found.", __FUNCTION__);
1388 fname_format =
"%T-%U";
1393 if (file_name == NULL)
1394 file_name = g_strdup_printf (
"%s-%s", type, resource_id);
1399 g_strdup_printf (
"attachment; filename=\"%s.xml\"", file_name));
1402 free_entity (entity);
1404 g_string_free (xml, TRUE);
1424 char *content = NULL;
1426 gchar *filter_escaped;
1428 gchar *fname_format, *file_name;
1433 filter_escaped = g_markup_escape_text (filter, -1);
1435 if (strcmp (type,
"info") == 0)
1437 if (gvm_connection_sendf (connection,
1444 filter_escaped ? filter_escaped :
"")
1447 g_free (filter_escaped);
1449 MHD_HTTP_INTERNAL_SERVER_ERROR);
1451 credentials,
"Internal error", __FUNCTION__, __LINE__,
1452 "An internal error occurred while getting a list. "
1453 "The list could not be delivered. "
1454 "Diagnostics: Failure to send command to manager daemon.",
1458 else if (strcmp (type,
"asset") == 0)
1460 if (gvm_connection_sendf (connection,
1467 filter_escaped ? filter_escaped :
"")
1470 g_free (filter_escaped);
1472 MHD_HTTP_INTERNAL_SERVER_ERROR);
1474 credentials,
"Internal error", __FUNCTION__, __LINE__,
1475 "An internal error occurred while getting a list. "
1476 "The list could not be delivered. "
1477 "Diagnostics: Failure to send command to manager daemon.",
1483 if (gvm_connection_sendf (connection,
1488 type, filter_escaped ? filter_escaped :
"")
1491 g_free (filter_escaped);
1493 MHD_HTTP_INTERNAL_SERVER_ERROR);
1495 credentials,
"Internal error", __FUNCTION__, __LINE__,
1496 "An internal error occurred while getting a list. "
1497 "The list could not be delivered. "
1498 "Diagnostics: Failure to send command to manager daemon.",
1502 g_free (filter_escaped);
1505 if (read_entity_and_text_c (connection, &entity, &content))
1508 MHD_HTTP_INTERNAL_SERVER_ERROR);
1510 credentials,
"Internal error", __FUNCTION__, __LINE__,
1511 "An internal error occurred while getting a list. "
1512 "The list could not be delivered. "
1513 "Diagnostics: Failure to receive response from manager daemon.",
1521 &fname_format, response_data);
1525 free_entity (entity);
1527 MHD_HTTP_INTERNAL_SERVER_ERROR);
1532 credentials,
"Internal error", __FUNCTION__, __LINE__,
1533 "An internal error occurred while getting a setting. "
1534 "The setting could not be delivered. "
1535 "Diagnostics: Failure to send command to manager daemon.",
1539 credentials,
"Internal error", __FUNCTION__, __LINE__,
1540 "An internal error occurred while getting a setting. "
1541 "The setting could not be delivered. "
1542 "Diagnostics: Failure to receive response from manager daemon.",
1546 credentials,
"Internal error", __FUNCTION__, __LINE__,
1547 "An internal error occurred while getting a setting. "
1548 "The setting could not be delivered. "
1549 "Diagnostics: Internal error.",
1554 if (fname_format == NULL)
1556 g_warning (
"%s : File name format setting not found.", __FUNCTION__);
1557 fname_format =
"%T-%D";
1560 if (strcmp (type,
"info") == 0)
1561 type_many = g_strdup (type);
1563 type_many = g_strdup_printf (
"%ss", type);
1567 if (file_name == NULL)
1568 file_name = g_strdup_printf (
"%s-%s", type_many,
"list");
1575 g_strdup_printf (
"attachment; filename=\"%s.xml\"", file_name));
1578 free_entity (entity);
1600 gchar *html, *response, *id_name, *resource_id, *extra_attribs;
1602 gchar *cap_type, *prev_action;
1604 id_name = g_strdup_printf (
"%s_id", type);
1606 resource_id = g_strdup (
params_value (params, id_name));
1612 credentials,
"Internal error", __FUNCTION__, __LINE__,
1613 "An internal error occurred while deleting a resource. "
1614 "The resource was not deleted. "
1615 "Diagnostics: Required parameter resource_id was NULL.",
1624 extra_attribs = NULL;
1627 if (strcmp (type,
"user") == 0)
1629 const char *inheritor_id;
1632 extra_attribs = g_strdup_printf (
"inheritor_id=\"%s\"", inheritor_id);
1635 "Invalid inheritor_id",
"Delete User");
1640 if (gvm_connection_sendf (
1641 connection,
"<delete_%s %s_id=\"%s\" ultimate=\"%i\"%s%s/>", type, type,
1642 resource_id, !!ultimate, extra_attribs ?
" " :
"",
1643 extra_attribs ? extra_attribs :
"")
1646 g_free (resource_id);
1647 g_free (extra_attribs);
1649 MHD_HTTP_INTERNAL_SERVER_ERROR);
1651 credentials,
"Internal error", __FUNCTION__, __LINE__,
1652 "An internal error occurred while deleting a resource. "
1653 "The resource is not deleted. "
1654 "Diagnostics: Failure to send command to manager daemon.",
1658 g_free (resource_id);
1659 g_free (extra_attribs);
1662 if (read_entity_and_text_c (connection, &entity, &response))
1665 MHD_HTTP_INTERNAL_SERVER_ERROR);
1667 credentials,
"Internal error", __FUNCTION__, __LINE__,
1668 "An internal error occurred while deleting a resource. "
1669 "It is unclear whether the resource has been deleted or not. "
1670 "Diagnostics: Failure to read response from manager daemon.",
1678 prev_action = g_strdup_printf (
"Delete %s", cap_type);
1681 prev_action, response_data);
1684 free_entity (entity);
1686 g_free (prev_action);
1726 const gchar *resource_type;
1728 resource_type =
params_value (params,
"resource_type");
1750 params_t *params,
const char *type,
const char *action,
1753 gchar *html, *response, *param_name;
1754 const char *resource_id;
1755 gchar *cap_action, *cap_type, *get_cmd, *prev_action;
1762 param_name = g_strdup_printf (
"%s_id", type);
1765 if (resource_id == NULL)
1768 message = g_strdup_printf (
1769 "An internal error occurred while performing an action. "
1770 "The resource remains the same. "
1771 "Diagnostics: Required parameter %s was NULL.",
1773 g_free (param_name);
1776 __LINE__, message, response_data);
1780 g_free (param_name);
1784 ret =
gmpf (connection,
credentials, &response, &entity, response_data,
1785 "<%s_%s %s_id=\"%s\"/>", action, type, type, resource_id);
1793 MHD_HTTP_INTERNAL_SERVER_ERROR);
1795 credentials,
"Internal error", __FUNCTION__, __LINE__,
1796 "An internal error occurred while performing an action. "
1797 "The resource remains the same. "
1798 "Diagnostics: Failure to send command to manager daemon.",
1802 MHD_HTTP_INTERNAL_SERVER_ERROR);
1804 credentials,
"Internal error", __FUNCTION__, __LINE__,
1805 "An internal error occurred while performing an action. "
1806 "It is unclear whether the resource has been affected. "
1807 "Diagnostics: Failure to receive response from manager daemon.",
1811 MHD_HTTP_INTERNAL_SERVER_ERROR);
1813 credentials,
"Internal error", __FUNCTION__, __LINE__,
1814 "An internal error occurred while performing an action. "
1815 "It is unclear whether the resource has been affected. "
1816 "Diagnostics: Internal Error.",
1825 get_cmd = g_strdup_printf (
"get_%ss", type);
1826 prev_action = g_strdup_printf (
"%s %s", cap_action, cap_type);
1828 prev_action, response_data);
1831 free_entity (entity);
1832 g_free (cap_action);
1835 g_free (prev_action);
1887 #define PARAM_OR_SETTING(value, param, setting_id, cleanup) \
1888 if (params_valid (params, param)) \
1889 value = g_strdup (params_value (params, param)); \
1893 message = setting_get_value_error (connection, credentials, setting_id, \
1894 &value, response_data); \
1931 gchar **xml_file_array, *xml_file_escaped;
1932 gchar *command, *html, *response;
1933 const char *task_id =
params_value (params,
"task_id"),
1940 if (strlen (xml_file) == 0)
1943 "Report required",
"Create Report");
1946 xml_file_array = g_strsplit (xml_file,
"%", -1);
1947 if (xml_file_array != NULL && xml_file_array[0] != NULL)
1948 xml_file_escaped = g_strjoinv (
"%%", xml_file_array);
1950 xml_file_escaped = g_strdup (xml_file);
1951 g_strfreev (xml_file_array);
1953 command = g_strdup_printf (
"<create_report>"
1954 "<in_assets>%s</in_assets>"
1958 in_assets ? in_assets :
"0", task_id,
1959 xml_file_escaped ? xml_file_escaped :
"");
1960 g_free (xml_file_escaped);
1963 gmp (connection,
credentials, &response, &entity, response_data, command);
1975 MHD_HTTP_INTERNAL_SERVER_ERROR);
1977 credentials,
"Internal error", __FUNCTION__, __LINE__,
1978 "An internal error occurred while creating a new report. "
1979 "No new report was created. "
1980 "Diagnostics: Failure to send command to manager daemon.",
1984 MHD_HTTP_INTERNAL_SERVER_ERROR);
1986 credentials,
"Internal error", __FUNCTION__, __LINE__,
1987 "An internal error occurred while creating a new report. "
1988 "It is unclear whether the report has been created or not. "
1989 "Diagnostics: Failure to receive response from manager daemon.",
1993 MHD_HTTP_INTERNAL_SERVER_ERROR);
1995 credentials,
"Internal error", __FUNCTION__, __LINE__,
1996 "An internal error occurred while creating a new report. "
1997 "It is unclear whether the report has been created or not. "
1998 "Diagnostics: Internal Error.",
2003 "Import Report", response_data);
2004 free_entity (entity);
2043 gchar *command, *html, *response;
2044 const char *name, *comment, *usage_type;
2054 command = g_markup_printf_escaped (
"<create_task>"
2055 "<target id=\"0\"/>"
2057 "<comment>%s</comment>"
2058 "<usage_type>%s</usage_type>"
2060 name, comment, usage_type);
2062 gmp (connection,
credentials, &response, &entity, response_data, command);
2074 MHD_HTTP_INTERNAL_SERVER_ERROR);
2076 credentials,
"Internal error", __FUNCTION__, __LINE__,
2077 "An internal error occurred while creating a container task. "
2078 "No task was created. "
2079 "Diagnostics: Failure to send command to manager daemon.",
2083 MHD_HTTP_INTERNAL_SERVER_ERROR);
2085 credentials,
"Internal error", __FUNCTION__, __LINE__,
2086 "An internal error occurred while creating a container task. "
2087 "It is unclear whether the task has been created or not. "
2088 "Diagnostics: Failure to receive response from manager daemon.",
2092 MHD_HTTP_INTERNAL_SERVER_ERROR);
2094 credentials,
"Internal error", __FUNCTION__, __LINE__,
2095 "An internal error occurred while creating a container task. "
2096 "It is unclear whether the task has been created or not. "
2097 "Diagnostics: Internal Error.",
2101 if (entity_attribute (entity,
"id"))
2102 params_add (params,
"task_id", entity_attribute (entity,
"id"));
2104 "Create Container Task", response_data);
2105 free_entity (entity);
2126 gchar *schedule_element, *command;
2127 gchar *response, *html;
2128 const char *name, *comment, *config_id, *target_id, *scanner_type;
2129 const char *scanner_id, *schedule_id, *schedule_periods;
2130 const char *max_checks, *max_hosts;
2131 const char *in_assets, *hosts_ordering, *alterable, *source_iface;
2132 const char *add_tag, *tag_id, *auto_delete, *auto_delete_data;
2133 const char *apply_overrides, *min_qod, *usage_type;
2134 gchar *name_escaped, *comment_escaped;
2136 GString *alert_element;
2140 apply_overrides =
params_value (params,
"apply_overrides");
2142 auto_delete_data =
params_value (params,
"auto_delete_data");
2145 hosts_ordering =
params_value (params,
"hosts_ordering");
2154 schedule_periods =
params_value (params,
"schedule_periods");
2161 if (!strcmp (scanner_type,
"1"))
2163 hosts_ordering =
"";
2168 else if (!strcmp (scanner_type,
"3"))
2171 hosts_ordering =
"";
2190 "Given target_id was invalid",
"Create Task");
2198 schedule_periods =
"0";
2202 if (!strcmp (in_assets,
"1"))
2211 apply_overrides =
"";
2225 if (add_tag && strcmp (add_tag,
"1") == 0)
2230 if (schedule_id == NULL || strcmp (schedule_id,
"0") == 0)
2231 schedule_element = g_strdup (
"");
2233 schedule_element = g_strdup_printf (
"<schedule id=\"%s\"/>", schedule_id);
2235 alert_element = g_string_new (
"");
2250 g_string_append_printf (alert_element,
"<alert id=\"%s\"/>",
2254 name_escaped = name ? g_markup_escape_text (name, -1) : NULL;
2255 comment_escaped = comment ? g_markup_escape_text (comment, -1) : NULL;
2257 command = g_strdup_printf (
2259 "<config id=\"%s\"/>"
2260 "<schedule_periods>%s</schedule_periods>"
2262 "<target id=\"%s\"/>"
2263 "<scanner id=\"%s\"/>"
2264 "<hosts_ordering>%s</hosts_ordering>"
2266 "<comment>%s</comment>"
2269 "<scanner_name>max_checks</scanner_name>"
2273 "<scanner_name>max_hosts</scanner_name>"
2277 "<scanner_name>in_assets</scanner_name>"
2282 "assets_apply_overrides"
2287 "<scanner_name>assets_min_qod</scanner_name>"
2291 "<scanner_name>source_iface</scanner_name>"
2295 "<scanner_name>auto_delete</scanner_name>"
2299 "<scanner_name>auto_delete_data</scanner_name>"
2303 "<alterable>%i</alterable>"
2304 "<usage_type>%s</usage_type>"
2306 config_id, schedule_periods, schedule_element, alert_element->str,
2307 target_id, scanner_id, hosts_ordering, name_escaped, comment_escaped,
2308 max_checks, max_hosts, strcmp (in_assets,
"0") ?
"yes" :
"no",
2309 strcmp (apply_overrides,
"0") ?
"yes" :
"no", min_qod, source_iface,
2310 auto_delete, auto_delete_data, alterable ? strcmp (alterable,
"0") : 0,
2313 g_free (name_escaped);
2314 g_free (comment_escaped);
2317 gmp (connection,
credentials, &response, &entity, response_data, command);
2320 g_free (schedule_element);
2321 g_string_free (alert_element, TRUE);
2332 MHD_HTTP_INTERNAL_SERVER_ERROR);
2334 credentials,
"Internal error", __FUNCTION__, __LINE__,
2335 "An internal error occurred while creating a new task. "
2336 "No new task was created. "
2337 "Diagnostics: Failure to send command to manager daemon.",
2341 MHD_HTTP_INTERNAL_SERVER_ERROR);
2343 credentials,
"Internal error", __FUNCTION__, __LINE__,
2344 "An internal error occurred while creating a new task. "
2345 "It is unclear whether the task has been created or not. "
2346 "Diagnostics: Failure to receive response from manager daemon.",
2350 MHD_HTTP_INTERNAL_SERVER_ERROR);
2352 credentials,
"Internal error", __FUNCTION__, __LINE__,
2353 "An internal error occurred while creating a new task. "
2354 "It is unclear whether the task has been created or not. "
2355 "Diagnostics: Internal Error.",
2361 if (add_tag && strcmp (add_tag,
"1") == 0)
2363 const char *new_task_id = entity_attribute (entity,
"id");
2364 gchar *tag_command, *tag_response;
2365 entity_t tag_entity;
2367 tag_command = g_markup_printf_escaped (
"<modify_tag tag_id=\"%s\">"
2368 "<resources action=\"add\">"
2369 "<resource id=\"%s\"/>"
2372 tag_id, new_task_id);
2375 response_data, tag_command);
2383 free_entity (entity);
2386 response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
2388 credentials,
"Internal error", __FUNCTION__, __LINE__,
2389 "An internal error occurred while creating a new tag. "
2390 "No new tag was created. "
2391 "Diagnostics: Failure to send command to manager daemon.",
2394 free_entity (entity);
2397 response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
2399 credentials,
"Internal error", __FUNCTION__, __LINE__,
2400 "An internal error occurred while creating a new tag. "
2401 "It is unclear whether the tag has been created or not. "
2402 "Diagnostics: Failure to receive response from manager daemon.",
2405 free_entity (entity);
2408 response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
2410 credentials,
"Internal error", __FUNCTION__, __LINE__,
2411 "An internal error occurred while creating a new task. "
2412 "It is unclear whether the tag has been created or not. "
2413 "Diagnostics: Internal Error.",
2417 if (entity_attribute (entity,
"id"))
2418 params_add (params,
"task_id", entity_attribute (entity,
"id"));
2421 "Create Task and Tag", response_data);
2422 free_entity (tag_entity);
2423 g_free (tag_response);
2427 if (entity_attribute (entity,
"id"))
2428 params_add (params,
"task_id", entity_attribute (entity,
"id"));
2430 "Create Task", response_data);
2436 "Create Task", response_data);
2438 free_entity (entity);
2475 gchar *html, *response, *format;
2476 const char *comment, *name, *schedule_id, *in_assets;
2477 const char *scanner_id, *task_id, *max_checks, *max_hosts;
2478 const char *config_id, *target_id, *hosts_ordering, *alterable, *source_iface;
2479 const char *scanner_type, *schedule_periods, *auto_delete, *auto_delete_data;
2480 const char *apply_overrides, *min_qod;
2483 GString *alert_element;
2487 apply_overrides =
params_value (params,
"apply_overrides");
2489 auto_delete_data =
params_value (params,
"auto_delete_data");
2492 hosts_ordering =
params_value (params,
"hosts_ordering");
2501 schedule_periods =
params_value (params,
"schedule_periods");
2506 if (scanner_type != NULL)
2509 if (!strcmp (scanner_type,
"1"))
2511 hosts_ordering =
"";
2516 else if (!strcmp (scanner_type,
"3"))
2519 hosts_ordering =
"";
2537 schedule_periods =
"0";
2547 if (!strcmp (in_assets,
"1"))
2556 apply_overrides =
"";
2563 alert_element = g_string_new (
"");
2579 g_string_append_printf (alert_element,
"<alert id=\"%s\"/>",
2585 if (strcmp (alert_element->str,
"") == 0)
2586 g_string_append_printf (alert_element,
"<alert id=\"0\"/>");
2588 format = g_strdup_printf (
2589 "<modify_task task_id=\"%%s\">"
2591 "<comment>%%s</comment>"
2592 "<hosts_ordering>%s</hosts_ordering>"
2594 "<target id=\"%%s\"/>"
2595 "<config id=\"%%s\"/>"
2596 "<schedule id=\"%%s\"/>"
2597 "<schedule_periods>%%s</schedule_periods>"
2598 "<scanner id=\"%%s\"/>"
2601 "<scanner_name>max_checks</scanner_name>"
2602 "<value>%%s</value>"
2605 "<scanner_name>max_hosts</scanner_name>"
2606 "<value>%%s</value>"
2609 "<scanner_name>in_assets</scanner_name>"
2610 "<value>%%s</value>"
2613 "<scanner_name>assets_apply_overrides</scanner_name>"
2614 "<value>%%s</value>"
2617 "<scanner_name>assets_min_qod</scanner_name>"
2618 "<value>%%s</value>"
2621 "<scanner_name>source_iface</scanner_name>"
2622 "<value>%%s</value>"
2625 "<scanner_name>auto_delete</scanner_name>"
2626 "<value>%%s</value>"
2629 "<scanner_name>auto_delete_data</scanner_name>"
2630 "<value>%%s</value>"
2635 hosts_ordering, alert_element->str, alterable ?
"<alterable>" :
"",
2636 alterable ? strcmp (alterable,
"0") : 0, alterable ?
"</alterable>" :
"");
2639 ret =
gmpf (connection,
credentials, &response, &entity, response_data,
2640 format, task_id, name, comment, target_id, config_id, schedule_id,
2641 schedule_periods, scanner_id, max_checks, max_hosts,
2642 strcmp (in_assets,
"0") ?
"yes" :
"no",
2643 strcmp (apply_overrides,
"0") ?
"yes" :
"no", min_qod,
2644 source_iface, auto_delete, auto_delete_data);
2647 g_string_free (alert_element, TRUE);
2656 MHD_HTTP_INTERNAL_SERVER_ERROR);
2658 credentials,
"Internal error", __FUNCTION__, __LINE__,
2659 "An internal error occurred while saving a task. "
2660 "The task was not saved. "
2661 "Diagnostics: Failure to send command to manager daemon.",
2665 MHD_HTTP_INTERNAL_SERVER_ERROR);
2667 credentials,
"Internal error", __FUNCTION__, __LINE__,
2668 "An internal error occurred while saving a task. "
2669 "It is unclear whether the task has been saved or not. "
2670 "Diagnostics: Failure to receive response from manager daemon.",
2674 MHD_HTTP_INTERNAL_SERVER_ERROR);
2676 credentials,
"Internal error", __FUNCTION__, __LINE__,
2677 "An internal error occurred while saving a task. "
2678 "It is unclear whether the task has been saved or not. "
2679 "Diagnostics: Internal Error.",
2684 "Save Task", response_data);
2685 free_entity (entity);
2707 gchar *format, *response, *html;
2708 const char *comment, *name, *task_id;
2709 const char *in_assets, *auto_delete, *auto_delete_data;
2718 auto_delete_data =
params_value (params,
"auto_delete_data");
2726 format = g_strdup_printf (
"<modify_task task_id=\"%%s\">"
2728 "<comment>%%s</comment>"
2731 "<scanner_name>in_assets</scanner_name>"
2732 "<value>%%s</value>"
2735 "<scanner_name>auto_delete</scanner_name>"
2736 "<value>%%s</value>"
2739 "<scanner_name>auto_delete_data</scanner_name>"
2740 "<value>%%s</value>"
2748 gmpf (connection,
credentials, &response, &entity, response_data, format,
2749 task_id, name, comment, strcmp (in_assets,
"0") ?
"yes" :
"no",
2750 auto_delete, auto_delete_data);
2759 MHD_HTTP_INTERNAL_SERVER_ERROR);
2761 credentials,
"Internal error", __FUNCTION__, __LINE__,
2762 "An internal error occurred while saving a task. "
2763 "No new task was created. "
2764 "Diagnostics: Failure to send command to manager daemon.",
2768 MHD_HTTP_INTERNAL_SERVER_ERROR);
2770 credentials,
"Internal error", __FUNCTION__, __LINE__,
2771 "An internal error occurred while saving a task. "
2772 "It is unclear whether the task has been created or not. "
2773 "Diagnostics: Failure to receive response from manager daemon.",
2777 MHD_HTTP_INTERNAL_SERVER_ERROR);
2779 credentials,
"Internal error", __FUNCTION__, __LINE__,
2780 "An internal error occurred while saving a task. "
2781 "It is unclear whether the task has been created or not. "
2782 "Diagnostics: Internal Error.",
2787 "Save Container Task", response_data);
2788 free_entity (entity);
2897 gchar *command, *response, *html;
2898 const char *task_id, *slave_id;
2905 command = g_strdup_printf (
"<move_task task_id=\"%s\" slave_id=\"%s\"/>",
2906 task_id ? task_id :
"", slave_id ? slave_id :
"");
2911 gmp (connection,
credentials, &response, &entity, response_data, command);
2922 MHD_HTTP_INTERNAL_SERVER_ERROR);
2924 credentials,
"Internal error", __FUNCTION__, __LINE__,
2925 "An internal error occurred while moving a task. "
2926 "The task was not moved. "
2927 "Diagnostics: Failure to send command to manager daemon.",
2931 MHD_HTTP_INTERNAL_SERVER_ERROR);
2933 credentials,
"Internal error", __FUNCTION__, __LINE__,
2934 "An internal error occurred while moving a task. "
2935 "It is unclear whether the task has been moved or not. "
2936 "Diagnostics: Failure to receive response from manager daemon.",
2940 MHD_HTTP_INTERNAL_SERVER_ERROR);
2942 credentials,
"Internal error", __FUNCTION__, __LINE__,
2943 "An internal error occurred while moving a task. "
2944 "It is unclear whether the task has been moved or not. "
2945 "Diagnostics: Internal Error.",
2950 "Move Task", response_data);
2952 free_entity (entity);
2971 const gchar *info_type;
2972 const gchar *info_name;
2973 const gchar *info_id;
2974 const gchar *details;
3023 const char *schedules_only, *ignore_pagination, *usage_type;
3026 schedules_only =
params_value (params,
"schedules_only");
3027 ignore_pagination =
params_value (params,
"ignore_pagination");
3039 if (ignore_pagination)
3086 gchar *html, *response;
3087 const char *name, *comment, *
login, *type, *password, *passphrase;
3088 const char *private_key, *public_key, *certificate, *community;
3089 const char *privacy_password, *auth_algorithm, *privacy_algorithm;
3090 const char *autogenerate, *allow_insecure;
3103 privacy_password =
params_value (params,
"privacy_password");
3104 auth_algorithm =
params_value (params,
"auth_algorithm");
3105 privacy_algorithm =
params_value (params,
"privacy_algorithm");
3106 allow_insecure =
params_value (params,
"allow_insecure");
3122 "<create_credential>"
3124 "<comment>%s</comment>"
3126 "<allow_insecure>%s</allow_insecure>"
3127 "</create_credential>",
3128 name, comment ? comment :
"", type, allow_insecure);
3137 "<create_credential>"
3139 "<comment>%s</comment>"
3142 "<allow_insecure>%s</allow_insecure>"
3143 "</create_credential>",
3144 name, comment ? comment :
"", type,
login, allow_insecure);
3156 "<create_credential>"
3158 "<comment>%s</comment>"
3161 "<password>%s</password>"
3162 "<allow_insecure>%s</allow_insecure>"
3163 "</create_credential>",
3164 name, comment ? comment :
"", type,
login ?
login :
"",
3165 password ? password :
"", allow_insecure);
3175 "<create_credential>"
3177 "<comment>%s</comment>"
3181 "<private>%s</private>"
3182 "<phrase>%s</phrase>"
3184 "<allow_insecure>%s</allow_insecure>"
3185 "</create_credential>",
3186 name, comment ? comment :
"", type,
login ?
login :
"",
3187 private_key ? private_key :
"", passphrase ? passphrase :
"",
3197 connection,
credentials, &response, &entity, response_data,
3198 "<create_credential>"
3200 "<comment>%s</comment>"
3202 "<certificate>%s</certificate>"
3204 "<private>%s</private>"
3205 "<phrase>%s</phrase>"
3207 "<allow_insecure>%s</allow_insecure>"
3208 "</create_credential>",
3209 name, comment ? comment :
"", type, certificate ? certificate :
"",
3210 private_key ? private_key :
"", passphrase ? passphrase :
"",
3222 if (privacy_password && strcmp (privacy_password,
""))
3224 connection,
credentials, &response, &entity, response_data,
3225 "<create_credential>"
3227 "<comment>%s</comment>"
3229 "<community>%s</community>"
3231 "<password>%s</password>"
3233 "<password>%s</password>"
3234 "<algorithm>%s</algorithm>"
3236 "<auth_algorithm>%s</auth_algorithm>"
3237 "<allow_insecure>%s</allow_insecure>"
3238 "</create_credential>",
3239 name, comment ? comment :
"", type, community ? community :
"",
3240 login ?
login :
"", password ? password :
"",
3241 privacy_password ? privacy_password :
"",
3242 privacy_algorithm ? privacy_algorithm :
"",
3243 auth_algorithm ? auth_algorithm :
"", allow_insecure);
3246 connection,
credentials, &response, &entity, response_data,
3247 "<create_credential>"
3249 "<comment>%s</comment>"
3251 "<community>%s</community>"
3253 "<password>%s</password>"
3254 "<auth_algorithm>%s</auth_algorithm>"
3255 "<allow_insecure>%s</allow_insecure>"
3256 "</create_credential>",
3257 name, comment ? comment :
"", type, community ? community :
"",
3258 login ?
login :
"", password ? password :
"",
3259 auth_algorithm ? auth_algorithm :
"", allow_insecure);
3266 connection,
credentials, &response, &entity, response_data,
3267 "<create_credential>"
3269 "<comment>%s</comment>"
3272 "<public>%s</public>"
3274 "<allow_insecure>%s</allow_insecure>"
3275 "</create_credential>",
3276 name, comment ? comment :
"", type, public_key, allow_insecure);
3283 connection,
credentials, &response, &entity, response_data,
3284 "<create_credential>"
3286 "<comment>%s</comment>"
3288 "<certificate>%s</certificate>"
3289 "<allow_insecure>%s</allow_insecure>"
3290 "</create_credential>",
3291 name, comment ? comment :
"", type, certificate, allow_insecure);
3293 else if (type && (strcmp (type,
"pw") == 0))
3299 "<create_credential>"
3301 "<comment>%s</comment>"
3303 "<password>%s</password>"
3304 "<allow_insecure>%s</allow_insecure>"
3305 "</create_credential>",
3306 name, comment ? comment :
"", type, password ? password :
"",
3312 MHD_HTTP_INTERNAL_SERVER_ERROR);
3314 credentials,
"Internal error", __FUNCTION__, __LINE__,
3315 "An internal error occurred while creating a new credential. "
3316 "The credential could not be created. "
3317 "Diagnostics: Unrecognized credential type.",
3330 MHD_HTTP_INTERNAL_SERVER_ERROR);
3332 credentials,
"Internal error", __FUNCTION__, __LINE__,
3333 "An internal error occurred while creating a new credential. "
3334 "It is unclear whether the credential has been created or not. "
3335 "Diagnostics: Failure to send command to manager daemon.",
3339 MHD_HTTP_INTERNAL_SERVER_ERROR);
3341 credentials,
"Internal error", __FUNCTION__, __LINE__,
3342 "An internal error occurred while creating a new credential. "
3343 "It is unclear whether the credential has been created or not. "
3344 "Diagnostics: Failure to receive response from manager daemon.",
3348 MHD_HTTP_INTERNAL_SERVER_ERROR);
3350 credentials,
"Internal error", __FUNCTION__, __LINE__,
3351 "An internal error occurred while creating a new credential. "
3352 "It is unclear whether the credential has been created or not. "
3353 "Diagnostics: Internal Error.",
3357 if (entity_attribute (entity,
"id"))
3358 params_add (params,
"credential_id", entity_attribute (entity,
"id"));
3360 "Create Credential", response_data);
3361 free_entity (entity);
3379 params_t *params,
const char *extra_xml,
3386 arguments, response_data);
3422 char **html,
char **
login,
3426 const char *credential_id, *format;
3432 credential_id =
params_value (params,
"credential_id");
3435 if ((credential_id == NULL) || (format == NULL))
3440 "An internal error occurred while getting a credential. "
3441 "Diagnostics: Required parameter was NULL.",
3446 if (gvm_connection_sendf (connection,
3448 " credential_id=\"%s\""
3450 credential_id, format)
3454 MHD_HTTP_INTERNAL_SERVER_ERROR);
3457 "An internal error occurred while getting a credential. "
3458 "Diagnostics: Failure to send command to manager daemon.",
3465 if (strcmp (format,
"rpm") == 0 || strcmp (format,
"deb") == 0
3466 || strcmp (format,
"exe") == 0)
3468 gchar *package_decoded = NULL;
3469 entity_t package_entity = NULL, credential_entity;
3474 if (read_entity_c (connection, &entity))
3477 MHD_HTTP_INTERNAL_SERVER_ERROR);
3479 credentials,
"Internal error", __FUNCTION__, __LINE__,
3480 "An internal error occurred while getting a credential. "
3481 "The credential is not available. "
3482 "Diagnostics: Failure to receive response from manager daemon.",
3487 credential_entity = entity_child (entity,
"credential");
3488 if (credential_entity)
3489 package_entity = entity_child (credential_entity,
"package");
3490 if (package_entity != NULL)
3493 char *package_encoded = entity_text (package_entity);
3494 if (strlen (package_encoded))
3497 (gchar *) g_base64_decode (package_encoded, &len);
3498 if (package_decoded == NULL)
3500 package_decoded = (gchar *) g_strdup (
"");
3506 package_decoded = (gchar *) g_strdup (
"");
3512 *html = package_decoded;
3515 entity_t login_entity;
3516 login_entity = entity_child (credential_entity,
"login");
3518 *
login = g_strdup (entity_text (login_entity));
3522 free_entity (entity);
3527 free_entity (entity);
3529 MHD_HTTP_INTERNAL_SERVER_ERROR);
3531 credentials,
"Internal error", __FUNCTION__, __LINE__,
3532 "An internal error occurred while getting a credential. "
3533 "The credential could not be delivered. "
3534 "Diagnostics: Failure to receive credential from manager daemon.",
3541 entity_t credential_entity, key_entity = NULL;
3546 if (read_entity_c (connection, &entity))
3549 MHD_HTTP_INTERNAL_SERVER_ERROR);
3551 credentials,
"Internal error", __FUNCTION__, __LINE__,
3552 "An internal error occurred while getting a credential. "
3553 "The credential could not be delivered. "
3554 "Diagnostics: Failure to receive credential from manager daemon.",
3559 credential_entity = entity_child (entity,
"credential");
3560 if (credential_entity)
3562 if (strcmp (format,
"pem") == 0)
3563 key_entity = entity_child (credential_entity,
"certificate");
3565 key_entity = entity_child (credential_entity,
"public_key");
3567 if (key_entity != NULL)
3569 *html = g_strdup (entity_text (key_entity));
3572 entity_t login_entity = entity_child (credential_entity,
"login");
3574 *
login = g_strdup (entity_text (login_entity));
3578 free_entity (entity);
3582 MHD_HTTP_INTERNAL_SERVER_ERROR);
3584 credentials,
"Internal error", __FUNCTION__, __LINE__,
3585 "An internal error occurred while getting a credential. "
3586 "The credential could not be delivered. "
3587 "Diagnostics: Failure to parse credential from manager daemon.",
3589 free_entity (entity);
3683 int ret, change_password, change_ssh_passphrase, change_passphrase;
3684 int change_community, change_privacy_password;
3685 gchar *html, *response;
3686 const char *credential_id, *public_key;
3687 const char *name, *comment, *
login, *password, *passphrase, *type;
3688 const char *private_key, *certificate, *community, *privacy_password;
3689 const char *auth_algorithm, *privacy_algorithm, *allow_insecure;
3693 credential_id =
params_value (params,
"credential_id");
3703 privacy_password =
params_value (params,
"privacy_password");
3704 auth_algorithm =
params_value (params,
"auth_algorithm");
3705 privacy_algorithm =
params_value (params,
"privacy_algorithm");
3706 allow_insecure =
params_value (params,
"allow_insecure");
3762 command = g_string_new (
"");
3764 xml_string_append (command,
3765 "<modify_credential credential_id=\"%s\">"
3767 "<comment>%s</comment>"
3768 "<allow_insecure>%s</allow_insecure>",
3769 credential_id, name, comment, allow_insecure);
3774 change_privacy_password =
3778 xml_string_append (command,
"<auth_algorithm>%s</auth_algorithm>",
3781 if (change_community)
3782 xml_string_append (command,
"<community>%s</community>", community);
3784 if (privacy_algorithm || change_privacy_password)
3786 xml_string_append (command,
"<privacy>");
3787 if (privacy_algorithm)
3789 xml_string_append (command,
"<algorithm>%s</algorithm>",
3792 if (change_privacy_password && privacy_password)
3794 xml_string_append (command,
"<password>%s</password>",
3798 xml_string_append (command,
"</privacy>");
3805 if ((certificate && strcmp (certificate,
"")))
3807 xml_string_append (command,
"<certificate>%s</certificate>",
3811 if ((private_key && strcmp (private_key,
"")) || change_passphrase)
3813 xml_string_append (command,
"<key>");
3814 if (change_passphrase)
3815 xml_string_append (command,
"<phrase>%s</phrase>", passphrase);
3817 xml_string_append (command,
"<private>%s</private>", private_key);
3818 xml_string_append (command,
"</key>");
3827 if ((private_key && strcmp (private_key,
"")) || change_ssh_passphrase)
3829 xml_string_append (command,
"<key>");
3830 if (change_ssh_passphrase)
3831 xml_string_append (command,
"<phrase>%s</phrase>", passphrase);
3833 xml_string_append (command,
"<private>%s</private>", private_key);
3834 xml_string_append (command,
"</key>");
3839 if (change_password)
3840 xml_string_append (command,
"<password>%s</password>", password);
3844 if ((certificate && strcmp (certificate,
"")))
3846 xml_string_append (command,
"<certificate>%s</certificate>",
3852 if ((public_key && strcmp (public_key,
"")))
3854 xml_string_append (command,
"<key>");
3855 xml_string_append (command,
"<public>%s</public>", public_key);
3856 xml_string_append (command,
"</key>");
3861 xml_string_append (command,
"<login>%s</login>",
login);
3863 xml_string_append (command,
"</modify_credential>");
3868 ret =
gmp (connection,
credentials, &response, &entity, response_data,
3870 g_string_free (command, TRUE);
3881 MHD_HTTP_INTERNAL_SERVER_ERROR);
3883 credentials,
"Internal error", __FUNCTION__, __LINE__,
3884 "An internal error occurred while saving a Credential. "
3885 "The Credential was not saved. "
3886 "Diagnostics: Failure to send command to manager daemon.",
3890 MHD_HTTP_INTERNAL_SERVER_ERROR);
3892 credentials,
"Internal error", __FUNCTION__, __LINE__,
3893 "An internal error occurred while saving a Credential. "
3894 "It is unclear whether the Credential has been saved or not. "
3895 "Diagnostics: Failure to receive response from manager daemon.",
3899 MHD_HTTP_INTERNAL_SERVER_ERROR);
3901 credentials,
"Internal error", __FUNCTION__, __LINE__,
3902 "An internal error occurred while saving a Credential. "
3903 "It is unclear whether the Credential has been saved or not. "
3904 "Diagnostics: Internal Error.",
3909 "Save Credential", response_data);
3910 free_entity (entity);
3930 gchar *response, *html;
3931 const char *name, *comment, *installer, *installer_filename, *installer_sig;
3932 const char *howto_install, *howto_use;
3933 int installer_size, installer_sig_size, howto_install_size, howto_use_size;
3935 gchar *name_escaped, *comment_escaped;
3936 gchar *installer_64, *installer_sig_64, *howto_install_64, *howto_use_64;
3944 installer_sig =
params_value (params,
"installer_sig");
3946 howto_install =
params_value (params,
"howto_install");
3956 installer_64 = (installer_size > 0)
3957 ? g_base64_encode ((guchar *) installer, installer_size)
3961 (installer_sig_size > 0)
3962 ? g_base64_encode ((guchar *) installer_sig, installer_sig_size)
3966 (howto_install_size > 0)
3967 ? g_base64_encode ((guchar *) howto_install, howto_install_size)
3970 howto_use_64 = (howto_use_size > 0)
3971 ? g_base64_encode ((guchar *) howto_use, howto_use_size)
3974 name_escaped = name ? g_markup_escape_text (name, -1) : NULL;
3975 comment_escaped = comment ? g_markup_escape_text (comment, -1) : NULL;
3977 command = g_strdup_printf (
"<create_agent>"
3982 "<signature>%s</signature>"
3983 "<filename>%s</filename>"
3985 "<howto_install>%s</howto_install>"
3986 "<howto_use>%s</howto_use>"
3988 name_escaped, comment_escaped ?
"<comment>" :
"",
3989 comment_escaped ? comment_escaped :
"",
3990 comment_escaped ?
"</comment>" :
"", installer_64,
3992 installer_filename ? installer_filename :
"",
3993 howto_install_64, howto_use_64);
3996 gmp (connection,
credentials, &response, &entity, response_data, command);
3999 g_free (installer_64);
4000 g_free (howto_install_64);
4001 g_free (howto_use_64);
4002 g_free (name_escaped);
4003 g_free (comment_escaped);
4014 MHD_HTTP_INTERNAL_SERVER_ERROR);
4016 credentials,
"Internal error", __FUNCTION__, __LINE__,
4017 "An internal error occurred while creating a new agent. "
4018 "No new agent was created. "
4019 "Diagnostics: Failure to send command to manager daemon.",
4023 MHD_HTTP_INTERNAL_SERVER_ERROR);
4025 credentials,
"Internal error", __FUNCTION__, __LINE__,
4026 "An internal error occurred while creating a new agent. "
4027 "It is unclear whether the agent has been created or not. "
4028 "Diagnostics: Failure to receive response from manager daemon.",
4032 MHD_HTTP_INTERNAL_SERVER_ERROR);
4034 credentials,
"Internal error", __FUNCTION__, __LINE__,
4035 "An internal error occurred while creating a new agent. "
4036 "It is unclear whether the agent has been created or not. "
4037 "Diagnostics: Internal Error.",
4041 if (entity_attribute (entity,
"id"))
4042 params_add (params,
"agent_id", entity_attribute (entity,
"id"));
4044 "Create Agent", response_data);
4045 free_entity (entity);
4083 params_t *params,
char **html,
char **filename,
4087 const char *agent_id, *format;
4088 gsize result_len = 0;
4093 if ((agent_id == NULL) || (format == NULL))
4098 "An internal error occurred while downloading "
4100 "Diagnostics: Required parameter was NULL.",
4107 if (gvm_connection_sendf (connection,
4108 "<get_agents agent_id=\"%s\" format=\"%s\"/>",
4113 MHD_HTTP_INTERNAL_SERVER_ERROR);
4116 "An internal error occurred while getting agent list. "
4117 "The current list of agents is not available. "
4118 "Diagnostics: Failure to send command to manager daemon.",
4125 if (strcmp (format,
"installer") == 0 || strcmp (format,
"howto_install") == 0
4126 || strcmp (format,
"howto_use") == 0)
4128 gchar *package_decoded = NULL;
4129 entity_t package_entity = NULL, agent_entity;
4134 if (read_entity_c (connection, &entity))
4137 MHD_HTTP_INTERNAL_SERVER_ERROR);
4139 credentials,
"Internal error", __FUNCTION__, __LINE__,
4140 "An internal error occurred while getting a agent. "
4141 "The agent is not available. "
4142 "Diagnostics: Failure to receive response from manager daemon.",
4147 agent_entity = entity_child (entity,
"agent");
4149 package_entity = entity_child (agent_entity,
"package");
4150 if (package_entity != NULL)
4152 char *package_encoded = entity_text (package_entity);
4153 if (strlen (package_encoded))
4156 (gchar *) g_base64_decode (package_encoded, &result_len);
4157 if (package_decoded == NULL)
4159 package_decoded = (gchar *) g_strdup (
"");
4165 package_decoded = (gchar *) g_strdup (
"");
4168 *html = package_decoded;
4171 entity_t filename_entity;
4172 filename_entity = entity_child (package_entity,
"filename");
4173 if (filename_entity)
4174 *filename = g_strdup (entity_text (filename_entity));
4177 if (!(*filename && strlen (*filename)))
4180 *filename = g_strdup_printf (
"agent-%s-%s", agent_id, format);
4184 free_entity (entity);
4189 free_entity (entity);
4191 MHD_HTTP_INTERNAL_SERVER_ERROR);
4193 credentials,
"Internal error", __FUNCTION__, __LINE__,
4194 "An internal error occurred while getting a agent. "
4195 "The agent could not be delivered. "
4196 "Diagnostics: Failure to receive agent from manager daemon.",
4206 if (read_entity_c (connection, &entity))
4209 MHD_HTTP_INTERNAL_SERVER_ERROR);
4211 credentials,
"Internal error", __FUNCTION__, __LINE__,
4212 "An internal error occurred while getting a agent. "
4213 "The agent could not be delivered. "
4214 "Diagnostics: Failure to receive agent from manager daemon.",
4219 free_entity (entity);
4221 MHD_HTTP_INTERNAL_SERVER_ERROR);
4223 credentials,
"Internal error", __FUNCTION__, __LINE__,
4224 "An internal error occurred while getting a agent. "
4225 "The agent could not be delivered. "
4226 "Diagnostics: Failure to parse agent from manager daemon.",
4247 gchar *html, *response;
4248 const char *agent_id, *name, *comment;
4263 ret =
gmpf (connection,
credentials, &response, &entity, response_data,
4264 "<modify_agent agent_id=\"%s\">"
4266 "<comment>%s</comment>"
4268 agent_id, name, comment);
4277 MHD_HTTP_INTERNAL_SERVER_ERROR);
4279 credentials,
"Internal error", __FUNCTION__, __LINE__,
4280 "An internal error occurred while saving a agent. "
4281 "The agent was not saved. "
4282 "Diagnostics: Failure to send command to manager daemon.",
4286 MHD_HTTP_INTERNAL_SERVER_ERROR);
4288 credentials,
"Internal error", __FUNCTION__, __LINE__,
4289 "An internal error occurred while saving a agent. "
4290 "It is unclear whether the agent has been saved or not. "
4291 "Diagnostics: Failure to receive response from manager daemon.",
4295 MHD_HTTP_INTERNAL_SERVER_ERROR);
4297 credentials,
"Internal error", __FUNCTION__, __LINE__,
4298 "An internal error occurred while saving a agent. "
4299 "It is unclear whether the agent has been saved or not. "
4300 "Diagnostics: Internal Error.",
4305 "Save Agent", response_data);
4306 free_entity (entity);
4324 params_t *params,
const char *extra_xml,
4380 gchar *html, *response;
4381 const char *agent_id;
4386 if (agent_id == NULL)
4390 credentials,
"Internal error", __FUNCTION__, __LINE__,
4391 "An internal error occurred while verifying an agent. "
4392 "Diagnostics: Required parameter was NULL.",
4397 ret =
gmpf (connection,
credentials, &response, &entity, response_data,
4398 "<verify_agent agent_id=\"%s\" />", agent_id);
4407 MHD_HTTP_INTERNAL_SERVER_ERROR);
4409 credentials,
"Internal error", __FUNCTION__, __LINE__,
4410 "An internal error occurred while verifying a agent. "
4411 "The agent was not verified. "
4412 "Diagnostics: Failure to send command to manager daemon.",
4416 MHD_HTTP_INTERNAL_SERVER_ERROR);
4418 credentials,
"Internal error", __FUNCTION__, __LINE__,
4419 "An internal error occurred while verifying a agent. "
4420 "It is unclear whether the agent was verified or not. "
4421 "Diagnostics: Failure to send command to manager daemon.",
4425 MHD_HTTP_INTERNAL_SERVER_ERROR);
4427 credentials,
"Internal error", __FUNCTION__, __LINE__,
4428 "An internal error occurred while verifying a agent. "
4429 "It is unclear whether the agent was verified or not. "
4430 "Diagnostics: Failure to send command to manager daemon.",
4435 "Verify Agent", response_data);
4436 free_entity (entity);
4491 params_t *data_columns, *text_columns;
4492 params_t *sort_fields, *sort_stats, *sort_orders;
4499 const char *data_column, *group_column, *subgroup_column, *type;
4500 const char *filter, *filter_id;
4501 const char *first_group, *max_groups;
4503 const char *usage_type;
4504 gchar *filter_escaped, *command_escaped, *response;
4506 GString *xml, *command;
4513 subgroup_column =
params_value (params,
"subgroup_column");
4526 filter_escaped = g_markup_escape_text (filter, -1);
4529 if (filter_id == NULL ||
str_equal (filter_id,
"")
4531 filter_escaped = g_strdup (
"rows=-2");
4533 filter_escaped = NULL;
4536 xml = g_string_new (
"<get_aggregate>");
4538 command = g_string_new (
"<get_aggregates");
4539 g_string_append_printf (command,
" type=\"%s\"", type);
4541 g_string_append_printf (command,
" data_column=\"%s\"", data_column);
4544 g_string_append_printf (command,
" group_column=\"%s\"", group_column);
4546 if (subgroup_column)
4547 g_string_append_printf (command,
" subgroup_column=\"%s\"",
4549 if (filter_escaped && strcmp (filter_escaped,
""))
4550 g_string_append_printf (command,
" filter=\"%s\"", filter_escaped);
4552 if (filter_id && !
str_equal (filter_id,
""))
4553 g_string_append_printf (command,
" filt_id=\"%s\"", filter_id);
4555 if (first_group && strcmp (first_group,
""))
4556 g_string_append_printf (command,
" first_group=\"%s\"", first_group);
4558 if (max_groups && strcmp (max_groups,
""))
4559 g_string_append_printf (command,
" max_groups=\"%s\"", max_groups);
4561 if (mode && strcmp (mode,
""))
4562 g_string_append_printf (command,
" mode=\"%s\"", mode);
4564 if (usage_type && strcmp (usage_type,
""))
4565 g_string_append_printf (command,
" usage_type=\"%s\"", usage_type);
4567 g_string_append (command,
">");
4569 if (sort_fields && sort_stats && sort_orders)
4571 param_t *field_param, *stat_param, *order_param;
4572 gchar *field_i, *stat_i, *order_i;
4585 xml_string_append (command,
4586 "<sort field=\"%s\""
4589 field_param->
value ? field_param->
value :
"",
4591 order_param->
value ? order_param->
value :
"");
4603 xml_string_append (command,
"<data_column>%s</data_column>",
4616 xml_string_append (command,
"<text_column>%s</text_column>",
4622 g_string_append (command,
"</get_aggregates>");
4624 g_free (filter_escaped);
4626 command_escaped = g_markup_escape_text (command->str, -1);
4627 g_string_append (xml, command_escaped);
4628 g_free (command_escaped);
4631 ret =
gmp (connection,
credentials, &response, &entity, response_data,
4633 g_string_free (command, TRUE);
4637 free_entity (entity);
4638 g_string_free (xml, TRUE);
4647 MHD_HTTP_INTERNAL_SERVER_ERROR);
4649 credentials,
"Internal error", __FUNCTION__, __LINE__,
4650 "An internal error occurred while getting aggregates. "
4651 "Diagnostics: Failure to send command to manager daemon.",
4655 MHD_HTTP_INTERNAL_SERVER_ERROR);
4657 credentials,
"Internal error", __FUNCTION__, __LINE__,
4658 "An internal error occurred while getting aggregates. "
4659 "Diagnostics: Failure to receive response from manager daemon.",
4663 MHD_HTTP_INTERNAL_SERVER_ERROR);
4665 credentials,
"Internal error", __FUNCTION__, __LINE__,
4666 "An internal error occurred while getting aggregates. "
4667 "Diagnostics: Internal Error.",
4674 g_string_append (xml, response);
4676 g_string_append (xml,
"</get_aggregate>");
4678 free_entity (entity);
4681 g_string_free (xml, FALSE), response_data);
4697 params_t *params,
const char *extra_xml,
4705 xml = g_string_new (
"<new_alert>");
4707 g_string_append (xml, extra_xml);
4713 ret =
gmp (connection,
credentials, &response, &entity, response_data,
4714 "<get_report_formats filter=\"rows=-1\"/>");
4722 MHD_HTTP_INTERNAL_SERVER_ERROR);
4724 credentials,
"Internal error", __FUNCTION__, __LINE__,
4725 "An internal error occurred while getting Report "
4726 "Formats for new alert. "
4727 "Diagnostics: Failure to send command to manager daemon.",
4731 MHD_HTTP_INTERNAL_SERVER_ERROR);
4733 credentials,
"Internal error", __FUNCTION__, __LINE__,
4734 "An internal error occurred while getting Report "
4735 "Formats for new alert. "
4736 "Diagnostics: Failure to receive response from manager daemon.",
4740 MHD_HTTP_INTERNAL_SERVER_ERROR);
4743 "An internal error occurred while getting Report "
4744 "Formats for new alert. It is unclear whether"
4745 " the alert has been saved or not. "
4746 "Diagnostics: Internal Error.",
4749 g_string_append (xml, response);
4751 free_entity (entity);
4755 ret =
gmp (connection,
credentials, &response, &entity, response_data,
4756 "<get_filters filter=\"rows=-1\"/>");
4765 MHD_HTTP_INTERNAL_SERVER_ERROR);
4767 credentials,
"Internal error", __FUNCTION__, __LINE__,
4768 "An internal error occurred while getting Report "
4769 "Filters for new alert. "
4770 "The task was not saved. "
4771 "Diagnostics: Failure to send command to manager daemon.",
4775 MHD_HTTP_INTERNAL_SERVER_ERROR);
4777 credentials,
"Internal error", __FUNCTION__, __LINE__,
4778 "An internal error occurred while getting Report "
4779 "Filters for new alert. "
4780 "Diagnostics: Failure to receive response from manager daemon.",
4784 MHD_HTTP_INTERNAL_SERVER_ERROR);
4787 "An internal error occurred while getting Report "
4788 "Filters for new alert. "
4789 "Diagnostics: Internal Error.",
4792 g_string_append (xml, response);
4794 free_entity (entity);
4798 ret =
gmp (connection,
credentials, &response, &entity, response_data,
4800 " schedules_only=\"1\""
4801 " filter=\"owner=any permission=start_task rows=-1\"/>");
4810 MHD_HTTP_INTERNAL_SERVER_ERROR);
4812 credentials,
"Internal error", __FUNCTION__, __LINE__,
4813 "An internal error occurred while getting Tasks"
4815 "The task was not saved. "
4816 "Diagnostics: Failure to send command to manager daemon.",
4820 MHD_HTTP_INTERNAL_SERVER_ERROR);
4822 credentials,
"Internal error", __FUNCTION__, __LINE__,
4823 "An internal error occurred while getting Tasks"
4825 "Diagnostics: Failure to receive response from manager daemon.",
4829 MHD_HTTP_INTERNAL_SERVER_ERROR);
4832 "An internal error occurred while getting Tasks"
4834 "Diagnostics: Internal Error.",
4837 g_string_append (xml, response);
4839 free_entity (entity);
4843 ret =
gmp (connection,
credentials, &response, &entity, response_data,
4845 " filter=\"type=up or type=pw"
4846 " owner=any permission=any rows=-1\"/>");
4855 MHD_HTTP_INTERNAL_SERVER_ERROR);
4857 credentials,
"Internal error", __FUNCTION__, __LINE__,
4858 "An internal error occurred while getting"
4859 " Credentials for new alert. "
4860 "The task was not saved. "
4861 "Diagnostics: Failure to send command to manager daemon.",
4865 MHD_HTTP_INTERNAL_SERVER_ERROR);
4867 credentials,
"Internal error", __FUNCTION__, __LINE__,
4868 "An internal error occurred while getting"
4869 " Credentials for new alert. "
4870 "Diagnostics: Failure to receive response from manager daemon.",
4874 MHD_HTTP_INTERNAL_SERVER_ERROR);
4877 "An internal error occurred while getting"
4878 " Credentials for new alert. "
4879 "Diagnostics: Internal Error.",
4883 g_string_append (xml, response);
4885 free_entity (entity);
4887 g_string_append (xml,
"</new_alert>");
4889 g_string_free (xml, FALSE), response_data);
4913 #define EVENT_TYPE_NEW_SECINFO "New SecInfo arrived"
4914 #define EVENT_TYPE_UPDATED_SECINFO "Updated SecInfo arrived"
4915 #define EVENT_TYPE_TASK_RUN_STATUS_CHANGED "Task run status changed"
4916 #define EVENT_TYPE_TICKET_RECEIVED "Ticket received"
4917 #define EVENT_TYPE_ASSIGNED_TICKET_CHANGED "Assigned ticket changed"
4918 #define EVENT_TYPE_OWNED_TICKET_CHANGED "Owned ticket changed"
4944 xml_string_append (xml,
"<data><name>%s</name>%s</data>", name,
4958 const char *condition)
4969 if (strcmp (condition,
"Filter count at least") == 0)
4971 if (strcmp (name,
"at_least_count") == 0)
4972 xml_string_append (xml,
"<data><name>count</name>%s</data>",
4974 if (strcmp (name,
"at_least_filter_id") == 0)
4975 xml_string_append (xml,
"<data><name>filter_id</name>%s</data>",
4978 else if (strcmp (condition,
"Filter count changed") == 0)
4980 if (strcmp (name,
"count") == 0
4981 || strcmp (name,
"filter_id") == 0)
4982 xml_string_append (xml,
"<data><name>%s</name>%s</data>", name,
4984 else if (strcmp (name,
"filter_direction") == 0)
4985 xml_string_append (xml,
"<data><name>direction</name>%s</data>",
4988 else if ((strcmp (condition,
"Severity at least") == 0
4989 && strcmp (name,
"severity") == 0)
4990 || (strcmp (condition,
"Severity changed") == 0
4991 && strcmp (name,
"direction") == 0))
4992 xml_string_append (xml,
"<data><name>%s</name>%s</data>", name,
5019 if (strcmp (method,
"Alemba vFire") == 0)
5021 g_string_append (xml,
"<data><name>report_formats</name>");
5023 if (report_formats && g_hash_table_size (report_formats))
5025 int report_formats_count = g_hash_table_size (report_formats);
5029 for (index = 1; index <= report_formats_count; index++)
5031 gchar *index_str = g_strdup_printf (
"%d", index);
5036 xml_string_append (xml,
", %s", value);
5038 xml_string_append (xml,
"%s", value);
5043 g_string_append (xml,
"</data>");
5051 if (strcmp (name,
"notice") == 0)
5057 if (strcmp (method,
"Sourcefire Connector"))
5062 if ((strcmp (method,
"HTTP Get") == 0 && strcmp (name,
"URL") == 0)
5063 || (strcmp (method,
"Send") == 0
5064 && (strcmp (name,
"send_host") == 0
5065 || strcmp (name,
"send_port") == 0
5066 || strcmp (name,
"send_report_format") == 0))
5067 || (strcmp (method,
"SCP") == 0
5068 && (strcmp (name,
"scp_credential") == 0
5069 || strcmp (name,
"scp_host") == 0
5070 || strcmp (name,
"scp_known_hosts") == 0
5071 || strcmp (name,
"scp_path") == 0
5072 || strcmp (name,
"scp_report_format") == 0))
5073 || (strcmp (method,
"SMB") == 0
5074 && (strcmp (name,
"smb_credential") == 0
5075 || strcmp (name,
"smb_file_path") == 0
5076 || strcmp (name,
"smb_report_format") == 0
5077 || strcmp (name,
"smb_share_path") == 0))
5078 || (strcmp (method,
"SNMP") == 0
5079 && (strcmp (name,
"snmp_community") == 0
5080 || strcmp (name,
"snmp_agent") == 0
5081 || strcmp (name,
"snmp_message") == 0))
5082 || (strcmp (method,
"TippingPoint SMS") == 0
5083 && (strcmp (name,
"tp_sms_credential") == 0
5084 || strcmp (name,
"tp_sms_hostname") == 0
5085 || strcmp (name,
"tp_sms_tls_certificate") == 0
5086 || strcmp (name,
"tp_sms_tls_workaround") == 0))
5087 || (strcmp (method,
"verinice Connector") == 0
5088 && (strcmp (name,
"verinice_server_credential") == 0
5089 || strcmp (name,
"verinice_server_url") == 0
5090 || strcmp (name,
"verinice_server_report_format") == 0))
5091 || (strcmp (method,
"Alemba vFire") == 0
5092 && (strcmp (name,
"vfire_base_url") == 0
5093 || strcmp (name,
"vfire_call_description") == 0
5094 || strcmp (name,
"vfire_call_impact_name") == 0
5095 || strcmp (name,
"vfire_call_partition_name") == 0
5096 || strcmp (name,
"vfire_call_template_name") == 0
5097 || strcmp (name,
"vfire_call_type_name") == 0
5098 || strcmp (name,
"vfire_call_urgency_name") == 0
5099 || strcmp (name,
"vfire_client_id") == 0
5100 || strcmp (name,
"vfire_credential") == 0
5101 || strcmp (name,
"vfire_session_type") == 0))
5102 || (strcmp (method,
"Email") == 0
5103 && (strcmp (name,
"to_address") == 0
5104 || strcmp (name,
"from_address") == 0
5105 || strcmp (name,
"subject") == 0
5106 || strcmp (name,
"notice") == 0
5107 || (strcmp (name,
"notice_report_format") == 0
5109 || (strcmp (name,
"notice_attach_format") == 0
5111 || (
str_equal (name,
"recipient_credential")
5113 || (strcmp (method,
"Syslog") == 0
5114 && strcmp (name,
"submethod") == 0)
5115 || (strcmp (method,
"Start Task") == 0
5116 && strcmp (name,
"start_task_task") == 0)
5117 || strcmp (name,
"details_url") == 0
5118 || strcmp (name,
"delta_type") == 0
5119 || strcmp (name,
"delta_report_id") == 0
5120 || strcmp (name,
"composer_include_notes") == 0
5121 || strcmp (name,
"composer_include_overrides") == 0)
5122 xml_string_append (xml,
"<data><name>%s</name>%s</data>", name,
5124 else if (strcmp (method,
"Email") == 0 && notice == 0
5125 && strcmp (name,
"message") == 0)
5126 xml_string_append (xml,
"<data><name>message</name>%s</data>",
5128 else if (strcmp (method,
"Email") == 0 && notice == 2
5129 && strcmp (name,
"message_attach") == 0)
5130 xml_string_append (xml,
"<data><name>message</name>%s</data>",
5138 if (strcmp (name,
"pkcs12"))
5140 if (strcmp (name,
"defense_center_ip") == 0
5141 || strcmp (name,
"defense_center_port") == 0
5142 || (strcmp (name,
"pkcs12_credential") == 0
5144 xml_string_append (xml,
"<data><name>%s</name>%s</data>", name,
5157 xml_string_append (xml,
"<data><name>%s</name>%s</data>", name, base64);
5177 gchar *html, *response;
5178 const char *name, *comment, *active, *condition, *event, *method, *filter_id;
5179 params_t *method_data, *event_data, *condition_data, *report_formats;
5203 report_formats =
params_values (params,
"report_format_ids:");
5205 xml = g_string_new (
"");
5223 xml_string_append (xml,
5226 "<filter id=\"%s\"/>"
5227 "<active>%s</active>"
5228 "<comment>%s</comment>"
5231 comment ? comment :
"", event);
5235 xml_string_append (xml,
5242 xml_string_append (xml,
5249 xml_string_append (xml,
"</condition>"
5253 gmp (connection,
credentials, &response, &entity, response_data, xml->str);
5254 g_string_free (xml, TRUE);
5262 MHD_HTTP_INTERNAL_SERVER_ERROR);
5264 credentials,
"Internal error", __FUNCTION__, __LINE__,
5265 "An internal error occurred while creating a new alert. "
5266 "No new alert was created. "
5267 "Diagnostics: Failure to send command to manager daemon.",
5271 MHD_HTTP_INTERNAL_SERVER_ERROR);
5273 credentials,
"Internal error", __FUNCTION__, __LINE__,
5274 "An internal error occurred while creating a new alert. "
5275 "It is unclear whether the alert has been created or not. "
5276 "Diagnostics: Failure to receive response from manager daemon.",
5280 MHD_HTTP_INTERNAL_SERVER_ERROR);
5282 credentials,
"Internal error", __FUNCTION__, __LINE__,
5283 "An internal error occurred while creating a new alert. "
5284 "It is unclear whether the alert has been created or not. "
5285 "Diagnostics: Internal Error.",
5289 if (entity_attribute (entity,
"id"))
5290 params_add (params,
"alert_id", entity_attribute (entity,
"id"));
5292 "Create Alert", response_data);
5293 free_entity (entity);
5329 params_t *params,
const char *extra_xml,
5389 params_t *params,
const char *extra_xml,
5394 const char *alert_id, *next, *filter;
5400 if (alert_id == NULL)
5405 "An internal error occurred while editing an alert. "
5406 "The alert remains as it was. "
5407 "Diagnostics: Required parameter alert_id was NULL.",
5412 next =
"get_alerts";
5414 if (gvm_connection_sendf (connection,
5422 MHD_HTTP_INTERNAL_SERVER_ERROR);
5424 credentials,
"Internal error", __FUNCTION__, __LINE__,
5425 "An internal error occurred while getting alert info. "
5426 "Diagnostics: Failure to send command to manager daemon.",
5430 xml = g_string_new (
"<edit_alert>");
5433 g_string_append (xml, extra_xml);
5435 edit = g_markup_printf_escaped (
"<alert id=\"%s\"/>"
5439 "<filters><term>%s</term></filters>",
5440 alert_id, next, filter);
5441 g_string_append (xml, edit);
5444 if (read_string_c (connection, &xml))
5446 g_string_free (xml, TRUE);
5448 MHD_HTTP_INTERNAL_SERVER_ERROR);
5450 credentials,
"Internal error", __FUNCTION__, __LINE__,
5451 "An internal error occurred while getting alert info. "
5452 "Diagnostics: Failure to receive response from manager daemon.",
5460 if (gvm_connection_sendf (connection,
"<get_report_formats"
5461 " filter=\"rows=-1\"/>")
5464 g_string_free (xml, TRUE);
5466 MHD_HTTP_INTERNAL_SERVER_ERROR);
5468 credentials,
"Internal error", __FUNCTION__, __LINE__,
5469 "An internal error occurred while getting report formats. "
5470 "The current list of report formats is not available. "
5471 "Diagnostics: Failure to send command to manager daemon.",
5475 if (read_string_c (connection, &xml))
5477 g_string_free (xml, TRUE);
5479 MHD_HTTP_INTERNAL_SERVER_ERROR);
5481 credentials,
"Internal error", __FUNCTION__, __LINE__,
5482 "An internal error occurred while getting report formats. "
5483 "The current list of report formats is not available. "
5484 "Diagnostics: Failure to receive response from manager daemon.",
5493 if (gvm_connection_sendf (connection,
"<get_filters filter=\"rows=-1\"/>")
5496 g_string_free (xml, TRUE);
5498 MHD_HTTP_INTERNAL_SERVER_ERROR);
5500 credentials,
"Internal error", __FUNCTION__, __LINE__,
5501 "An internal error occurred while getting the list "
5503 "The current list of filters is not available. "
5504 "Diagnostics: Failure to send command to manager daemon.",
5508 if (read_string_c (connection, &xml))
5510 g_string_free (xml, TRUE);
5512 MHD_HTTP_INTERNAL_SERVER_ERROR);
5514 credentials,
"Internal error", __FUNCTION__, __LINE__,
5515 "An internal error occurred while getting the list "
5517 "The current list of filters is not available. "
5518 "Diagnostics: Failure to receive response from manager daemon.",
5527 if (gvm_connection_sendf (connection,
5529 " schedules_only=\"1\""
5530 " filter=\"owner=any permission=start_task"
5534 g_string_free (xml, TRUE);
5536 MHD_HTTP_INTERNAL_SERVER_ERROR);
5538 credentials,
"Internal error", __FUNCTION__, __LINE__,
5539 "An internal error occurred while getting the list "
5541 "The current list of tasks is not available. "
5542 "Diagnostics: Failure to send command to manager daemon.",
5546 if (read_string_c (connection, &xml))
5548 g_string_free (xml, TRUE);
5550 MHD_HTTP_INTERNAL_SERVER_ERROR);
5552 credentials,
"Internal error", __FUNCTION__, __LINE__,
5553 "An internal error occurred while getting the list "
5555 "The current list of tasks is not available. "
5556 "Diagnostics: Failure to receive response from manager daemon.",
5565 if (gvm_connection_sendf (connection,
"<get_credentials"
5566 " filter=\"type=up or type=pw"
5567 " owner=any permission=any"
5571 g_string_free (xml, TRUE);
5573 MHD_HTTP_INTERNAL_SERVER_ERROR);
5575 credentials,
"Internal error", __FUNCTION__, __LINE__,
5576 "An internal error occurred while getting the list "
5578 "The current list of tasks is not available. "
5579 "Diagnostics: Failure to send command to manager daemon.",
5583 if (read_string_c (connection, &xml))
5585 g_string_free (xml, TRUE);
5587 MHD_HTTP_INTERNAL_SERVER_ERROR);
5589 credentials,
"Internal error", __FUNCTION__, __LINE__,
5590 "An internal error occurred while getting the list "
5592 "The current list of tasks is not available. "
5593 "Diagnostics: Failure to receive response from manager daemon.",
5600 g_string_append (xml,
"</edit_alert>");
5602 g_string_free (xml, FALSE), response_data);
5638 gchar *html, *response;
5639 const char *name, *comment, *alert_id;
5640 const char *event, *condition, *method;
5641 const char *filter_id, *active;
5642 params_t *event_data, *condition_data, *method_data, *report_formats;
5654 if (filter_id == NULL ||
str_equal (filter_id,
""))
5667 xml = g_string_new (
"");
5674 report_formats =
params_values (params,
"report_format_ids:");
5692 xml_string_append (xml,
5693 "<modify_alert alert_id=\"%s\">"
5695 "<filter id=\"%s\"/>"
5696 "<active>%s</active>"
5697 "<comment>%s</comment>"
5699 alert_id, name, filter_id, active, comment ? comment :
"",
5704 xml_string_append (xml,
5711 xml_string_append (xml,
5718 xml_string_append (xml,
"</condition>"
5722 gmp (connection,
credentials, &response, &entity, response_data, xml->str);
5723 g_string_free (xml, TRUE);
5731 MHD_HTTP_INTERNAL_SERVER_ERROR);
5733 credentials,
"Internal error", __FUNCTION__, __LINE__,
5734 "An internal error occurred while saving a new alert. "
5735 "No new alert was created. "
5736 "Diagnostics: Failure to send command to manager daemon.",
5740 MHD_HTTP_INTERNAL_SERVER_ERROR);
5742 credentials,
"Internal error", __FUNCTION__, __LINE__,
5743 "An internal error occurred while saving a new alert. "
5744 "It is unclear whether the alert has been created or not. "
5745 "Diagnostics: Failure to receive response from manager daemon.",
5749 MHD_HTTP_INTERNAL_SERVER_ERROR);
5751 credentials,
"Internal error", __FUNCTION__, __LINE__,
5752 "An internal error occurred while saving a new alert. "
5753 "It is unclear whether the alert has been created or not. "
5754 "Diagnostics: Internal Error.",
5759 "Save Alert", response_data);
5760 free_entity (entity);
5779 gchar *html, *response;
5780 const char *alert_id;
5785 if (alert_id == NULL)
5791 "Missing parameter alert_id."
5792 "Diagnostics: Required parameter was NULL.",
5798 if (gvm_connection_sendf (connection,
"<test_alert alert_id=\"%s\"/>",
5803 MHD_HTTP_INTERNAL_SERVER_ERROR);
5805 credentials,
"Internal error", __FUNCTION__, __LINE__,
5806 "An internal error occurred while testing an alert. "
5807 "Diagnostics: Failure to send command to manager daemon.",
5812 if (read_entity_and_text_c (connection, &entity, &response))
5815 MHD_HTTP_INTERNAL_SERVER_ERROR);
5817 credentials,
"Internal error", __FUNCTION__, __LINE__,
5818 "An internal error occurred while testing an alert. "
5819 "Diagnostics: Failure to receive response from manager daemon.",
5824 "Test Alert", response_data);
5826 free_entity (entity);
5882 gchar *html, *response, *command;
5883 const char *name, *hosts, *exclude_hosts, *comment;
5884 const char *target_ssh_credential, *port, *target_smb_credential;
5885 const char *target_esxi_credential, *target_snmp_credential, *target_source;
5886 const char *target_exclude_source;
5887 const char *port_list_id, *reverse_lookup_only, *reverse_lookup_unify;
5888 const char *alive_tests, *hosts_filter, *file, *exclude_file;
5889 gchar *ssh_credentials_element, *smb_credentials_element;
5890 gchar *esxi_credentials_element, *snmp_credentials_element;
5891 gchar *asset_hosts_element;
5892 gchar *comment_element = NULL;
5898 exclude_hosts =
params_value (params,
"exclude_hosts");
5899 reverse_lookup_only =
params_value (params,
"reverse_lookup_only");
5900 reverse_lookup_unify =
params_value (params,
"reverse_lookup_unify");
5901 target_source =
params_value (params,
"target_source");
5902 target_exclude_source =
params_value (params,
"target_exclude_source");
5905 target_ssh_credential =
params_value (params,
"ssh_credential_id");
5907 target_smb_credential =
params_value (params,
"smb_credential_id");
5908 target_esxi_credential =
params_value (params,
"esxi_credential_id");
5909 target_snmp_credential =
params_value (params,
"snmp_credential_id");
5917 if (strcmp (target_source,
"manual") == 0)
5919 if (strcmp (target_source,
"file") == 0)
5922 if (strcmp (target_source,
"asset_hosts") == 0)
5928 if (strcmp (target_exclude_source,
"manual") == 0
5932 if (strcmp (target_exclude_source,
"file") == 0)
5939 if (strcmp (target_ssh_credential,
"--"))
5946 if (comment != NULL)
5947 comment_element = g_strdup_printf (
"<comment>%s</comment>", comment);
5949 comment_element = g_strdup (
"");
5951 if (strcmp (target_ssh_credential,
"0") == 0)
5952 ssh_credentials_element = g_strdup (
"");
5954 ssh_credentials_element = g_strdup_printf (
"<ssh_credential id=\"%s\">"
5956 "</ssh_credential>",
5957 target_ssh_credential, port);
5959 if (strcmp (target_smb_credential,
"0") == 0)
5960 smb_credentials_element = g_strdup (
"");
5962 smb_credentials_element =
5963 g_strdup_printf (
"<smb_credential id=\"%s\"/>", target_smb_credential);
5965 if (strcmp (target_esxi_credential,
"0") == 0)
5966 esxi_credentials_element = g_strdup (
"");
5968 esxi_credentials_element =
5969 g_strdup_printf (
"<esxi_credential id=\"%s\"/>", target_esxi_credential);
5971 if (strcmp (target_snmp_credential,
"0") == 0)
5972 snmp_credentials_element = g_strdup (
"");
5974 snmp_credentials_element =
5975 g_strdup_printf (
"<snmp_credential id=\"%s\"/>", target_snmp_credential);
5977 if (strcmp (target_source,
"asset_hosts") == 0)
5978 asset_hosts_element = g_markup_printf_escaped (
"<asset_hosts"
5982 asset_hosts_element = g_strdup (
"");
5986 xml = g_string_new (
"");
5988 xml_string_append (xml,
5991 "<exclude_hosts>%s</exclude_hosts>"
5992 "<reverse_lookup_only>%s</reverse_lookup_only>"
5993 "<reverse_lookup_unify>%s</reverse_lookup_unify>"
5994 "<port_list id=\"%s\"/>"
5995 "<alive_tests>%s</alive_tests>",
5996 name, strcmp (target_source,
"file") == 0 ? file : hosts,
5997 target_exclude_source
5998 ? (strcmp (target_exclude_source,
"file") == 0
6000 : (exclude_hosts ? exclude_hosts :
""))
6002 reverse_lookup_only ? reverse_lookup_only :
"0",
6003 reverse_lookup_unify ? reverse_lookup_unify :
"0",
6004 port_list_id, alive_tests);
6006 command = g_strdup_printf (
"<create_target>"
6009 xml->str, comment_element, ssh_credentials_element,
6010 smb_credentials_element, esxi_credentials_element,
6011 snmp_credentials_element, asset_hosts_element);
6013 g_string_free (xml, TRUE);
6014 g_free (comment_element);
6015 g_free (ssh_credentials_element);
6016 g_free (smb_credentials_element);
6017 g_free (esxi_credentials_element);
6020 gmp (connection,
credentials, &response, &entity, response_data, command);
6031 MHD_HTTP_INTERNAL_SERVER_ERROR);
6033 credentials,
"Internal error", __FUNCTION__, __LINE__,
6034 "An internal error occurred while creating a new target. "
6035 "No new target was created. "
6036 "Diagnostics: Failure to send command to manager daemon.",
6040 MHD_HTTP_INTERNAL_SERVER_ERROR);
6042 credentials,
"Internal error", __FUNCTION__, __LINE__,
6043 "An internal error occurred while creating a new target. "
6044 "It is unclear whether the target has been created or not. "
6045 "Diagnostics: Failure to receive response from manager daemon.",
6049 MHD_HTTP_INTERNAL_SERVER_ERROR);
6051 credentials,
"Internal error", __FUNCTION__, __LINE__,
6052 "An internal error occurred while creating a new target. "
6053 "It is unclear whether the target has been created or not. "
6054 "Diagnostics: Internal Error.",
6058 if (entity_attribute (entity,
"id"))
6059 params_add (params,
"target_id", entity_attribute (entity,
"id"));
6061 "Create Target", response_data);
6062 free_entity (entity);
6081 gchar *html, *response;
6082 const char *id, *type, *alterable;
6094 if (alterable && strcmp (alterable,
"0"))
6096 if (gvm_connection_sendf (connection,
6099 "<alterable>1</alterable>"
6105 MHD_HTTP_INTERNAL_SERVER_ERROR);
6107 credentials,
"Internal error", __FUNCTION__, __LINE__,
6108 "An internal error occurred while cloning a resource. "
6109 "The resource was not cloned. "
6110 "Diagnostics: Failure to send command to manager daemon.",
6114 else if (gvm_connection_sendf (connection,
6122 MHD_HTTP_INTERNAL_SERVER_ERROR);
6124 credentials,
"Internal error", __FUNCTION__, __LINE__,
6125 "An internal error occurred while cloning a resource. "
6126 "The resource was not cloned. "
6127 "Diagnostics: Failure to send command to manager daemon.",
6132 if (read_entity_and_text_c (connection, &entity, &response))
6135 MHD_HTTP_INTERNAL_SERVER_ERROR);
6137 credentials,
"Internal error", __FUNCTION__, __LINE__,
6138 "An internal error occurred while cloning a resource. "
6139 "It is unclear whether the resource has been cloned or not. "
6140 "Diagnostics: Failure to read response from manager daemon.",
6148 free_entity (entity);
6190 const char *target_id;
6196 xml = g_string_new (
"");
6200 if (gvm_connection_sendf (connection,
6206 g_string_free (xml, TRUE);
6208 MHD_HTTP_INTERNAL_SERVER_ERROR);
6210 credentials,
"Internal error", __FUNCTION__, __LINE__,
6211 "An internal error occurred while restoring a resource. "
6212 "The resource was not deleted. "
6213 "Diagnostics: Failure to send command to manager daemon.",
6217 if (read_entity_and_string_c (connection, &entity, &xml))
6219 g_string_free (xml, TRUE);
6221 MHD_HTTP_INTERNAL_SERVER_ERROR);
6223 credentials,
"Internal error", __FUNCTION__, __LINE__,
6224 "An internal error occurred while restoring a resource. "
6225 "It is unclear whether the resource has been restored or not. "
6226 "Diagnostics: Failure to read response from manager daemon.",
6233 "Restore", response_data);
6234 free_entity (entity);
6235 g_string_free (xml, FALSE);
6257 xml = g_string_new (
"");
6261 if (gvm_connection_sendf (connection,
"<empty_trashcan/>") == -1)
6263 g_string_free (xml, TRUE);
6265 MHD_HTTP_INTERNAL_SERVER_ERROR);
6267 credentials,
"Internal error", __FUNCTION__, __LINE__,
6268 "An internal error occurred while emptying the trashcan. "
6269 "Diagnostics: Failure to send command to manager daemon.",
6273 if (read_entity_and_string_c (connection, &entity, &xml))
6275 g_string_free (xml, TRUE);
6277 MHD_HTTP_INTERNAL_SERVER_ERROR);
6279 credentials,
"Internal error", __FUNCTION__, __LINE__,
6280 "An internal error occurred while emptying the trashcan. "
6281 "Diagnostics: Failure to read response from manager daemon.",
6288 "Empty Trashcan", response_data);
6289 free_entity (entity);
6290 g_string_free (xml, FALSE);
6310 const char *name, *comment, *filter, *value, *resource_type, *active;
6319 resource_type =
params_value (params,
"resource_type");
6331 command = g_string_new (
"");
6333 xml_string_append (command,
6336 "<comment>%s</comment>"
6338 "<active>%s</active>"
6339 "<resources filter=\"%s\">"
6341 name, comment, value, active, filter ? filter :
"",
6353 g_string_append_printf (command,
"<resource id=\"%s\"/>",
6357 xml_string_append (command,
"</resources>"
6362 switch (
gmp (connection,
credentials, &response, &entity, response_data,
6370 MHD_HTTP_INTERNAL_SERVER_ERROR);
6371 g_string_free (command, TRUE);
6373 credentials,
"Internal error", __FUNCTION__, __LINE__,
6374 "An internal error occurred while creating a new tag. "
6375 "No new tag was created. "
6376 "Diagnostics: Failure to send command to manager daemon.",
6380 MHD_HTTP_INTERNAL_SERVER_ERROR);
6381 g_string_free (command, TRUE);
6383 credentials,
"Internal error", __FUNCTION__, __LINE__,
6384 "An internal error occurred while creating a new tag. "
6385 "It is unclear whether the tag has been created or not. "
6386 "Diagnostics: Failure to receive response from manager daemon.",
6390 MHD_HTTP_INTERNAL_SERVER_ERROR);
6391 g_string_free (command, TRUE);
6393 credentials,
"Internal error", __FUNCTION__, __LINE__,
6394 "An internal error occurred while creating a new tag. "
6395 "It is unclear whether the tag has been created or not. "
6396 "Diagnostics: Internal Error.",
6400 g_string_free (command, TRUE);
6402 "Create Tag", response_data);
6404 free_entity (entity);
6442 const char *name, *comment, *filter, *value, *resource_type, *active;
6443 const char *resources_action;
6455 resource_type =
params_value (params,
"resource_type");
6457 resources_action =
params_value (params,
"resources_action");
6471 command = g_string_new (
"");
6473 xml_string_append (command,
6474 "<modify_tag tag_id=\"%s\">"
6476 "<comment>%s</comment>"
6478 "<active>%s</active>"
6479 "<resources action=\"%s\" filter=\"%s\">"
6481 tag_id, name, comment, value, active,
6482 resources_action ? resources_action :
"",
6483 filter ? filter :
"", resource_type);
6494 g_string_append_printf (command,
"<resource id=\"%s\"/>",
6498 xml_string_append (command,
"</resources>"
6503 switch (
gmp (connection,
credentials, &response, &entity, response_data,
6511 MHD_HTTP_INTERNAL_SERVER_ERROR);
6512 g_string_free (command, TRUE);
6515 "An internal error occurred while saving a tag. "
6516 "The tag remains the same. "
6517 "Diagnostics: Failure to send command to "
6522 MHD_HTTP_INTERNAL_SERVER_ERROR);
6523 g_string_free (command, TRUE);
6526 "An internal error occurred while saving a tag. "
6527 "It is unclear whether the tag has been saved "
6529 "Diagnostics: Failure to receive response from "
6534 MHD_HTTP_INTERNAL_SERVER_ERROR);
6535 g_string_free (command, TRUE);
6538 "An internal error occurred while saving a tag. "
6539 "It is unclear whether the tag has been saved "
6541 "Diagnostics: Internal Error.",
6545 g_string_free (command, TRUE);
6547 "Save Tag", response_data);
6549 free_entity (entity);
6604 params_t *params,
const char *extra_xml,
6660 gchar *html, *response;
6661 const char *tag_id, *enable;
6672 if (gvm_connection_sendf (connection,
6673 "<modify_tag tag_id=\"%s\">"
6674 "<active>%s</active>"
6680 MHD_HTTP_INTERNAL_SERVER_ERROR);
6683 "An internal error occurred while modifying a tag. "
6684 "The tag is not modified. "
6685 "Diagnostics: Failure to send command to"
6691 if (read_entity_and_text_c (connection, &entity, &response))
6694 MHD_HTTP_INTERNAL_SERVER_ERROR);
6697 "An internal error occurred while modifying a tag. "
6698 "It is unclear whether the tag has been modified"
6700 "Diagnostics: Failure to read response from"
6706 "Toggle Tag", response_data);
6708 free_entity (entity);
6727 params_t *params,
const char *extra_xml,
6736 arguments, response_data);
6788 gchar *html, *response;
6789 const char *name, *hosts, *exclude_hosts, *comment;
6790 const char *target_ssh_credential, *port, *target_smb_credential;
6791 const char *target_esxi_credential, *target_snmp_credential;
6792 const char *target_source, *target_exclude_source;
6793 const char *target_id, *port_list_id, *reverse_lookup_only;
6794 const char *reverse_lookup_unify, *alive_tests, *in_use;
6816 command = g_string_new (
"");
6817 xml_string_append (command,
6818 "<modify_target target_id=\"%s\">"
6820 "<comment>%s</comment>"
6821 "<alive_tests>%s</alive_tests>"
6823 target_id, name ? name :
"", comment ? comment :
"",
6828 ret =
gmp (connection,
credentials, &response, &entity, response_data,
6830 g_string_free (command, TRUE);
6838 MHD_HTTP_INTERNAL_SERVER_ERROR);
6840 credentials,
"Internal error", __FUNCTION__, __LINE__,
6841 "An internal error occurred while saving a target. "
6842 "The target remains the same. "
6843 "Diagnostics: Failure to send command to manager daemon.",
6847 MHD_HTTP_INTERNAL_SERVER_ERROR);
6849 credentials,
"Internal error", __FUNCTION__, __LINE__,
6850 "An internal error occurred while saving a target. "
6851 "It is unclear whether the target has been saved or not. "
6852 "Diagnostics: Failure to receive response from manager daemon.",
6856 MHD_HTTP_INTERNAL_SERVER_ERROR);
6858 credentials,
"Internal error", __FUNCTION__, __LINE__,
6859 "An internal error occurred while saving a target. "
6860 "It is unclear whether the target has been saved or not. "
6861 "Diagnostics: Internal Error.",
6866 "Save Target", response_data);
6868 free_entity (entity);
6874 exclude_hosts =
params_value (params,
"exclude_hosts");
6875 reverse_lookup_only =
params_value (params,
"reverse_lookup_only");
6876 reverse_lookup_unify =
params_value (params,
"reverse_lookup_unify");
6877 target_source =
params_value (params,
"target_source");
6878 target_exclude_source =
params_value (params,
"target_exclude_source");
6880 target_ssh_credential =
params_value (params,
"ssh_credential_id");
6882 target_smb_credential =
params_value (params,
"smb_credential_id");
6883 target_esxi_credential =
params_value (params,
"esxi_credential_id");
6884 target_snmp_credential =
params_value (params,
"snmp_credential_id");
6894 if (strcmp (target_ssh_credential,
"--")
6895 && strcmp (target_ssh_credential,
"0"))
6898 if (
str_equal (target_source,
"manual"))
6905 gchar *ssh_credentials_element, *smb_credentials_element;
6906 gchar *esxi_credentials_element, *snmp_credentials_element;
6907 gchar *comment_element;
6911 comment_element = g_strdup_printf (
"<comment>%s</comment>", comment);
6913 comment_element = g_strdup (
"");
6915 if (
str_equal (target_ssh_credential,
"--"))
6916 ssh_credentials_element = g_strdup (
"");
6918 ssh_credentials_element = g_strdup_printf (
"<ssh_credential id=\"%s\">"
6920 "</ssh_credential>",
6921 target_ssh_credential, port);
6923 if (
str_equal (target_smb_credential,
"--"))
6924 smb_credentials_element = g_strdup (
"");
6926 smb_credentials_element =
6927 g_strdup_printf (
"<smb_credential id=\"%s\"/>", target_smb_credential);
6929 if (
str_equal (target_esxi_credential,
"--"))
6930 esxi_credentials_element = g_strdup (
"");
6932 esxi_credentials_element = g_strdup_printf (
6933 "<esxi_credential id=\"%s\"/>", target_esxi_credential);
6935 if (
str_equal (target_snmp_credential,
"--"))
6936 snmp_credentials_element = g_strdup (
"");
6938 snmp_credentials_element = g_strdup_printf (
6939 "<snmp_credential id=\"%s\"/>", target_snmp_credential);
6941 command = g_string_new (
"");
6944 "<modify_target target_id=\"%s\">"
6947 "<exclude_hosts>%s</exclude_hosts>"
6948 "<reverse_lookup_only>%s</reverse_lookup_only>"
6949 "<reverse_lookup_unify>%s</reverse_lookup_unify>"
6950 "<port_list id=\"%s\"/>"
6951 "<alive_tests>%s</alive_tests>",
6954 str_equal (target_exclude_source,
"file")
6957 reverse_lookup_only ? reverse_lookup_only :
"0",
6958 reverse_lookup_unify ? reverse_lookup_unify :
"0", port_list_id,
6961 g_string_append_printf (command,
6964 comment_element, ssh_credentials_element,
6965 smb_credentials_element, esxi_credentials_element,
6966 snmp_credentials_element);
6968 g_free (comment_element);
6969 g_free (ssh_credentials_element);
6970 g_free (smb_credentials_element);
6971 g_free (esxi_credentials_element);
6972 g_free (snmp_credentials_element);
6976 ret = gvm_connection_sendf (connection,
"%s", command->str);
6977 g_string_free (command, TRUE);
6982 MHD_HTTP_INTERNAL_SERVER_ERROR);
6984 credentials,
"Internal error", __FUNCTION__, __LINE__,
6985 "An internal error occurred while modifying target. "
6986 "No target was modified. "
6987 "Diagnostics: Failure to send command to manager daemon.",
6992 if (read_entity_and_text_c (connection, &entity, &response))
6995 MHD_HTTP_INTERNAL_SERVER_ERROR);
6997 credentials,
"Internal error", __FUNCTION__, __LINE__,
6998 "An internal error occurred while modifying a target. "
6999 "It is unclear whether the target has been modified or not. "
7000 "Diagnostics: Failure to receive response from manager daemon.",
7005 "Save Target", response_data);
7064 gchar *html, *response;
7065 const char *name, *comment, *base, *usage_type, *scanner = NULL;
7084 switch (
gmpf (connection,
credentials, &response, &entity, response_data,
7088 "<comment>%s</comment>"
7089 "<scanner>%s</scanner>"
7090 "<usage_type>%s</usage_type>"
7092 name, base, comment, scanner ?:
"", usage_type))
7099 MHD_HTTP_INTERNAL_SERVER_ERROR);
7101 credentials,
"Internal error", __FUNCTION__, __LINE__,
7102 "An internal error occurred while creating a new config. "
7103 "No new config was created. "
7104 "Diagnostics: Failure to send command to manager daemon.",
7108 MHD_HTTP_INTERNAL_SERVER_ERROR);
7110 credentials,
"Internal error", __FUNCTION__, __LINE__,
7111 "An internal error occurred while creating a new config. "
7112 "It is unclear whether the config has been created or not. "
7113 "Diagnostics: Failure to receive response from manager daemon.",
7117 MHD_HTTP_INTERNAL_SERVER_ERROR);
7119 credentials,
"Internal error", __FUNCTION__, __LINE__,
7120 "An internal error occurred while creating a new config. "
7121 "It is unclear whether the config has been created or not. "
7122 "Diagnostics: Internal Error.",
7126 if (entity_attribute (entity,
"id"))
7127 params_add (params,
"config_id", entity_attribute (entity,
"id"));
7129 "Create Config", response_data);
7131 free_entity (entity);
7150 gchar *command, *html, *response;
7158 command = g_strdup_printf (
"<create_config>"
7163 gmp (connection,
credentials, &response, &entity, response_data, command);
7172 MHD_HTTP_INTERNAL_SERVER_ERROR);
7174 credentials,
"Internal error", __FUNCTION__, __LINE__,
7175 "An internal error occurred while importing a config. "
7176 "The schedule remains the same. "
7177 "Diagnostics: Failure to send command to manager daemon.",
7181 MHD_HTTP_INTERNAL_SERVER_ERROR);
7183 credentials,
"Internal error", __FUNCTION__, __LINE__,
7184 "An internal error occurred while importing a config. "
7185 "It is unclear whether the schedule has been saved or not. "
7186 "Diagnostics: Failure to receive response from manager daemon.",
7190 MHD_HTTP_INTERNAL_SERVER_ERROR);
7192 credentials,
"Internal error", __FUNCTION__, __LINE__,
7193 "An internal error occurred while importing a config. "
7194 "It is unclear whether the schedule has been saved or not. "
7195 "Diagnostics: Internal Error.",
7202 "Import Config", response_data);
7203 free_entity (entity);
7222 const char *usage_type;
7280 params_t *params,
const char *next,
const char *fail_next,
7283 GHashTableIter iter;
7284 gpointer param_name, val;
7286 const char *config_id;
7289 g_hash_table_iter_init (&iter, params);
7291 while (g_hash_table_iter_next (&iter, ¶m_name, &val))
7299 if (!g_str_has_prefix (param_name,
"osp_pref_"))
7306 param_name = ((
char *) param_name) + 9;
7307 if (gvm_connection_sendf (connection,
7308 "<modify_config config_id=\"%s\">"
7309 "<preference><name>%s</name>"
7310 "<value>%s</value></preference>"
7312 config_id, (
char *) param_name, value)
7317 MHD_HTTP_INTERNAL_SERVER_ERROR);
7319 credentials,
"Internal error", __FUNCTION__, __LINE__,
7320 "An internal error occurred while saving a config. It is"
7321 " unclear whether the entire config has been saved. "
7322 "Diagnostics: Failure to send command to manager daemon.",
7328 fail_next, success, response_data);
7350 char *ret, *osp_ret;
7351 params_t *preferences, *selects, *trends;
7352 const char *config_id, *name, *comment, *scanner_id;
7367 gmp_ret = gvm_connection_sendf_xml (connection,
7368 "<modify_config config_id=\"%s\">"
7370 "<comment>%s</comment>"
7371 "<scanner>%s</scanner>"
7374 name, comment, scanner_id);
7376 gmp_ret = gvm_connection_sendf_xml (connection,
7377 "<modify_config config_id=\"%s\">"
7379 "<comment>%s</comment>"
7387 MHD_HTTP_INTERNAL_SERVER_ERROR);
7389 credentials,
"Internal error", __FUNCTION__, __LINE__,
7390 "An internal error occurred while saving a config. "
7391 "It is unclear whether the entire config has been saved. "
7392 "Diagnostics: Failure to send command to manager daemon.",
7397 "edit_config", &success, response_data);
7421 if (gvm_connection_sendf (connection,
7422 "<modify_config config_id=\"%s\">"
7434 response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
7436 credentials,
"Internal error", __FUNCTION__, __LINE__,
7437 "An internal error occurred while saving a config. "
7438 "It is unclear whether the entire config has been saved. "
7439 "Diagnostics: Failure to send command to manager daemon.",
7447 "edit_config", &success, response_data);
7457 "edit_config", &success, response_data);
7466 if (osp_ret == NULL)
7469 MHD_HTTP_INTERNAL_SERVER_ERROR);
7471 credentials,
"Internal error", __FUNCTION__, __LINE__,
7472 "An internal error occurred while saving a config. "
7473 "It is unclear whether the entire config has been saved. "
7474 "Diagnostics: save_osp_prefs returned NULL unexpectedly.",
7485 if (trends || selects ||
params_value (params,
"trend"))
7487 if (gvm_connection_sendf (
7489 "<modify_config config_id=\"%s\">"
7490 "<family_selection>"
7491 "<growing>%i</growing>",
7498 MHD_HTTP_INTERNAL_SERVER_ERROR);
7500 credentials,
"Internal error", __FUNCTION__, __LINE__,
7501 "An internal error occurred while saving a config. "
7502 "It is unclear whether the entire config has been saved. "
7503 "Diagnostics: Failure to send command to manager daemon.",
7515 if (gvm_connection_sendf (connection,
7519 "<growing>%i</growing>"
7522 trends &&
member1 (trends, family))
7526 response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
7528 credentials,
"Internal error", __FUNCTION__, __LINE__,
7529 "An internal error occurred while saving a config. "
7530 "It is unclear whether the entire config has been saved. "
7531 "Diagnostics: Failure to send command to manager daemon.",
7549 if (selects &&
member (selects, family))
7551 if (gvm_connection_sendf (connection,
7555 "<growing>1</growing>"
7561 response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
7563 credentials,
"Internal error", __FUNCTION__, __LINE__,
7564 "An internal error occurred while saving a config. "
7565 "It is unclear whether the entire config has been saved. "
7566 "Diagnostics: Failure to send command to manager daemon.",
7572 if (gvm_connection_sendf (connection,
"</family_selection>"
7577 MHD_HTTP_INTERNAL_SERVER_ERROR);
7579 credentials,
"Internal error", __FUNCTION__, __LINE__,
7580 "An internal error occurred while saving a config. "
7581 "It is unclear whether the entire config has been saved. "
7582 "Diagnostics: Failure to send command to manager daemon.",
7588 "edit_config", NULL, response_data);
7610 const char *config_id, *family, *sort_field, *sort_order;
7618 xml = g_string_new (
"<get_config_family_response>");
7625 if (gvm_connection_sendf (
7628 " config_id=\"%s\" details=\"1\""
7629 " family=\"%s\" timeout=\"1\" preference_count=\"1\""
7630 " sort_field=\"%s\" sort_order=\"%s\"/>",
7631 config_id, family, sort_field ? sort_field :
"nvts.name",
7632 sort_order ? sort_order :
"ascending")
7635 g_string_free (xml, TRUE);
7637 MHD_HTTP_INTERNAL_SERVER_ERROR);
7639 credentials,
"Internal error", __FUNCTION__, __LINE__,
7640 "An internal error occurred while getting list of configs. "
7641 "The current list of configs is not available. "
7642 "Diagnostics: Failure to send command to manager daemon.",
7646 if (read_string_c (connection, &xml))
7648 g_string_free (xml, TRUE);
7650 MHD_HTTP_INTERNAL_SERVER_ERROR);
7652 credentials,
"Internal error", __FUNCTION__, __LINE__,
7653 "An internal error occurred while getting list of configs. "
7654 "The current list of configs is not available. "
7655 "Diagnostics: Failure to receive response from manager daemon.",
7663 g_string_append (xml,
"<all>");
7665 if (gvm_connection_sendf (connection,
7670 " preferences_config_id=\"%s\""
7671 " preference_count=\"1\""
7672 " sort_field=\"%s\""
7673 " sort_order=\"%s\"/>",
7675 sort_field ? sort_field :
"nvts.name",
7676 sort_order ? sort_order :
"ascending")
7679 g_string_free (xml, TRUE);
7681 MHD_HTTP_INTERNAL_SERVER_ERROR);
7683 credentials,
"Internal error", __FUNCTION__, __LINE__,
7684 "An internal error occurred while getting list of configs. "
7685 "The current list of configs is not available. "
7686 "Diagnostics: Failure to send command to manager daemon.",
7690 if (read_string_c (connection, &xml))
7692 g_string_free (xml, TRUE);
7694 MHD_HTTP_INTERNAL_SERVER_ERROR);
7696 credentials,
"Internal error", __FUNCTION__, __LINE__,
7697 "An internal error occurred while getting list of configs. "
7698 "The current list of configs is not available. "
7699 "Diagnostics: Failure to receive response from manager daemon.",
7703 g_string_append (xml,
"</all>");
7706 g_string_append (xml,
"</get_config_family_response>");
7708 g_string_free (xml, FALSE), response_data);
7762 const char *config_id, *family;
7773 if (gvm_connection_sendf (connection,
7774 "<modify_config config_id=\"%s\">"
7776 "<family>%s</family>",
7781 MHD_HTTP_INTERNAL_SERVER_ERROR);
7783 credentials,
"Internal error", __FUNCTION__, __LINE__,
7784 "An internal error occurred while saving a config. "
7785 "It is unclear whether the entire config has been saved. "
7786 "Diagnostics: Failure to send command to manager daemon.",
7799 if (gvm_connection_sendf (connection,
"<nvt oid=\"%s\"/>", name) == -1)
7802 MHD_HTTP_INTERNAL_SERVER_ERROR);
7804 credentials,
"Internal error", __FUNCTION__, __LINE__,
7805 "An internal error occurred while saving a config. "
7806 "It is unclear whether the entire config has been saved. "
7807 "Diagnostics: Failure to send command to manager daemon.",
7812 if (gvm_connection_sendf (connection,
"</nvt_selection>"
7817 MHD_HTTP_INTERNAL_SERVER_ERROR);
7819 credentials,
"Internal error", __FUNCTION__, __LINE__,
7820 "An internal error occurred while saving a config. "
7821 "It is unclear whether the entire config has been saved. "
7822 "Diagnostics: Failure to send command to manager daemon.",
7828 "edit_config_family", NULL, response_data);
7848 const char *config_id, *sort_field, *sort_order, *nvt;
7855 xml = g_string_new (
"<get_config_nvt_response>");
7860 if (gvm_connection_sendf (connection,
7862 " config_id=\"%s\" nvt_oid=\"%s\""
7863 " details=\"1\" preferences=\"1\""
7864 " sort_field=\"%s\" sort_order=\"%s\"/>",
7866 sort_field ? sort_field :
"nvts.name",
7867 sort_order ? sort_order :
"ascending")
7870 g_string_free (xml, TRUE);
7872 MHD_HTTP_INTERNAL_SERVER_ERROR);
7874 credentials,
"Internal error", __FUNCTION__, __LINE__,
7875 "An internal error occurred while getting list of configs. "
7876 "The current list of configs is not available. "
7877 "Diagnostics: Failure to send command to manager daemon.",
7881 if (read_string_c (connection, &xml))
7883 g_string_free (xml, TRUE);
7885 MHD_HTTP_INTERNAL_SERVER_ERROR);
7887 credentials,
"Internal error", __FUNCTION__, __LINE__,
7888 "An internal error occurred while getting list of configs. "
7889 "The current list of configs is not available. "
7890 "Diagnostics: Failure to receive response from manager daemon.",
7894 g_string_append (xml,
"</get_config_nvt_response>");
7897 g_string_free (xml, FALSE), response_data);
7933 const char *config_id;
7935 char *modify_config_ret;
7937 modify_config_ret = NULL;
7944 gchar *preference_name;
7952 int ret, is_timeout = 0;
7953 gchar *value, **splits;
7955 g_free (modify_config_ret);
7956 modify_config_ret = NULL;
7963 splits = g_strsplit (preference_name,
":", 4);
7964 if (splits && splits[0] && splits[1] && splits[2] && splits[3])
7966 if (!strcmp (splits[2],
"password"))
7975 gchar *password_name;
7980 &password_name, &password))
7981 if (strcmp (password_name, preference_name) == 0)
7990 g_strfreev (splits);
7994 else if (!strcmp (splits[2],
"file"))
8009 if (strcmp (file_name, preference_name) == 0)
8018 g_strfreev (splits);
8022 else if (!strcmp (splits[2],
"scanner"))
8028 g_strfreev (splits);
8031 ? g_base64_encode ((guchar *) preference->
value,
8037 const char *timeout;
8038 gchar *preference_name_escaped;
8042 if (timeout == NULL)
8046 MHD_HTTP_BAD_REQUEST);
8048 credentials,
"Internal error", __FUNCTION__, __LINE__,
8049 "An internal error occurred while saving a config. "
8050 "It is unclear whether the entire config has been saved. "
8051 "Diagnostics: Required parameter was NULL.",
8055 preference_name_escaped =
8056 g_markup_escape_text (preference_name, -1);
8058 if (strcmp (timeout,
"0") == 0)
8060 ret = gvm_connection_sendf (connection,
8062 " config_id=\"%s\">"
8067 config_id, preference_name_escaped);
8069 ret = gvm_connection_sendf (connection,
8071 " config_id=\"%s\">"
8077 config_id, preference_name_escaped,
8080 g_free (preference_name_escaped);
8084 gchar *preference_name_escaped;
8085 preference_name_escaped =
8086 g_markup_escape_text (preference_name, -1);
8088 gvm_connection_sendf (connection,
8090 " config_id=\"%s\">"
8098 preference_name_escaped, value);
8099 g_free (preference_name_escaped);
8106 response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
8108 credentials,
"Internal error", __FUNCTION__, __LINE__,
8109 "An internal error occurred while saving a config. "
8110 "It is unclear whether the entire config has been saved. "
8111 "Diagnostics: Failure to send command to manager daemon.",
8117 connection,
credentials, params,
"get_config_nvt",
8118 "save_config_nvt", &success, response_data);
8121 return modify_config_ret;
8130 connection,
credentials, params, response_data,
"Modify Config",
8131 "All NVT preferences modified successfully", NULL, NULL);
8133 return modify_config_ret;
8317 entity_t entity, preference_entity, value_entity;
8318 const char *config_id, *oid, *preference_name;
8322 preference_name =
params_value (params,
"preference_name");
8324 xml = g_string_new (
"<get_preferences_response>");
8330 if (gvm_connection_sendf (connection,
8334 " preference=\"%s\"/>",
8335 config_id, oid, preference_name)
8338 g_string_free (xml, TRUE);
8340 MHD_HTTP_INTERNAL_SERVER_ERROR);
8342 credentials,
"Internal error", __FUNCTION__, __LINE__,
8343 "An internal error occurred while getting a preference file. "
8344 "The file could not be delivered. "
8345 "Diagnostics: Failure to send command to manager daemon.",
8350 if (read_entity_c (connection, &entity))
8352 g_string_free (xml, TRUE);
8354 MHD_HTTP_INTERNAL_SERVER_ERROR);
8356 credentials,
"Internal error", __FUNCTION__, __LINE__,
8357 "An internal error occurred while getting a preference file. "
8358 "The file could not be delivered. "
8359 "Diagnostics: Failure to receive response from manager daemon.",
8363 preference_entity = entity_child (entity,
"preference");
8364 if (preference_entity != NULL
8365 && (value_entity = entity_child (preference_entity,
"value")))
8367 char *content = strdup (entity_text (value_entity));
8372 g_strdup_printf (
"attachment; filename=\"pref_file.bin\""));
8374 free_entity (entity);
8375 g_string_free (xml, TRUE);
8380 free_entity (entity);
8381 g_string_free (xml, TRUE);
8383 MHD_HTTP_INTERNAL_SERVER_ERROR);
8385 credentials,
"Internal error", __FUNCTION__, __LINE__,
8386 "An internal error occurred while getting a preference file. "
8387 "The file could not be delivered. "
8388 "Diagnostics: Failure to receive file from manager daemon.",
8392 g_string_append (xml,
"</get_preferences_response>");
8394 g_string_free (xml, FALSE), response_data);
8470 params_t *params,
const char *extra_xml,
8475 entity_t report_entity;
8476 const char *report_id, *delta_report_id;
8477 const char *format_id;
8479 const char *filter_id;
8480 gboolean lean, ignore_pagination, details;
8482 gchar *fname_format;
8483 const gchar *extension, *requested_content_type;
8493 delta_report_id =
params_value (params,
"delta_report_id");
8501 if (filter == NULL || filter_id)
8504 ret = gvm_connection_sendf_xml (
8508 " ignore_pagination=\"%d\""
8513 " delta_report_id=\"%s\""
8514 " format_id=\"%s\"/>",
8515 details, ignore_pagination, lean, filter,
8517 delta_report_id ? delta_report_id :
"0", format_id ? format_id :
"");
8522 MHD_HTTP_INTERNAL_SERVER_ERROR);
8524 credentials,
"Internal error", __FUNCTION__, __LINE__,
8525 "An internal error occurred while getting a report. "
8526 "The report could not be delivered. "
8527 "Diagnostics: Failure to send command to manager daemon.",
8538 if (read_entity_c (connection, &entity))
8541 response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
8543 credentials,
"Internal error", __FUNCTION__, __LINE__,
8544 "An internal error occurred while getting a report. "
8545 "The report could not be delivered. "
8546 "Diagnostics: Failure to receive response from manager daemon.",
8549 entity_t report = entity_child (entity,
"report");
8552 free_entity (entity);
8554 response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
8556 credentials,
"Internal error", __FUNCTION__, __LINE__,
8557 "An internal error occurred while getting a report. "
8558 "The report could not be delivered. "
8559 "Diagnostics: Response from manager daemon did not contain a "
8563 extension = entity_attribute (report,
"extension");
8564 requested_content_type = entity_attribute (report,
"content_type");
8565 if (extension && requested_content_type)
8569 "e1a2ae0b-736e-4484-b029-330c9e15b900",
8570 &fname_format, response_data);
8577 response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
8579 credentials,
"Internal error", __FUNCTION__, __LINE__,
8580 "An internal error occurred while getting a setting. "
8581 "The setting could not be delivered. "
8582 "Diagnostics: Failure to send command to manager "
8587 response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
8589 credentials,
"Internal error", __FUNCTION__, __LINE__,
8590 "An internal error occurred while getting a setting. "
8591 "The setting could not be delivered. "
8592 "Diagnostics: Failure to receive response from manager "
8597 response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
8599 credentials,
"Internal error", __FUNCTION__, __LINE__,
8600 "An internal error occurred while getting a setting. "
8601 "The setting could not be delivered. "
8602 "Diagnostics: Internal error.",
8607 if (fname_format == NULL)
8609 g_warning (
"%s : File name format setting not found.",
8611 fname_format =
"%T-%U";
8616 if (file_name == NULL)
8617 file_name = g_strdup_printf (
"%s-%s",
"report", report_id);
8620 response_data, g_strdup (requested_content_type));
8623 g_strdup_printf (
"attachment; filename=\"%s.%s\"", file_name,
8628 xml = g_string_new (
"");
8629 print_entity_to_string (report, xml);
8630 free_entity (entity);
8631 return g_string_free (xml, FALSE);
8638 if (read_entity_c (connection, &entity))
8641 response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
8643 credentials,
"Internal error", __FUNCTION__, __LINE__,
8644 "An internal error occurred while getting a report. "
8645 "The report could not be delivered. "
8646 "Diagnostics: Failure to receive response from manager daemon.",
8650 report_entity = entity_child (entity,
"report");
8651 if (report_entity != NULL)
8653 char *report_encoded;
8655 gchar *report_decoded;
8656 extension = entity_attribute (report_entity,
"extension");
8657 requested_content_type =
8658 entity_attribute (report_entity,
"content_type");
8659 report_encoded = entity_text (report_entity);
8661 (gchar *) g_base64_decode (report_encoded, &report_len);
8664 if (report_decoded == NULL)
8666 report_decoded = g_strdup (
"");
8669 if (extension && requested_content_type)
8679 connection,
"e1a2ae0b-736e-4484-b029-330c9e15b900",
8680 &fname_format, response_data);
8687 response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
8691 "An internal error occurred while getting a "
8693 "The setting could not be delivered. "
8694 "Diagnostics: Failure to send command to manager "
8699 response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
8703 "An internal error occurred while getting a "
8705 "The setting could not be delivered. "
8706 "Diagnostics: Failure to receive response from "
8711 response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
8715 "An internal error occurred while getting a "
8717 "The setting could not be delivered. "
8718 "Diagnostics: Internal error.",
8723 if (fname_format == NULL)
8725 g_warning (
"%s : File name format setting not found.",
8727 fname_format =
"%T-%U";
8731 "report",
id, report_entity);
8732 if (file_name == NULL)
8733 file_name = g_strdup_printf (
"%s-%s",
"report",
id);
8736 response_data, g_strdup (requested_content_type));
8739 g_strdup_printf (
"attachment; filename=\"%s.%s\"",
8740 file_name, extension));
8745 free_entity (entity);
8748 return report_decoded;
8752 free_entity (entity);
8754 response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
8756 credentials,
"Internal error", __FUNCTION__, __LINE__,
8757 "An internal error occurred while getting a report. "
8758 "The report could not be delivered. "
8759 "Diagnostics: Failure to receive report from manager daemon.",
8768 xml = g_string_new (
"<get_report>");
8771 g_string_append (xml, extra_xml);
8773 if (delta_report_id)
8775 g_string_append_printf (xml,
"<delta>%s</delta>", delta_report_id);
8778 if (read_entity_and_string_c (connection, &entity, &xml))
8781 MHD_HTTP_INTERNAL_SERVER_ERROR);
8783 credentials,
"Internal error", __FUNCTION__, __LINE__,
8784 "An internal error occurred while getting a report. "
8785 "The report could not be delivered. "
8786 "Diagnostics: Failure to receive response from manager daemon.",
8797 entity_attribute (entity,
"status_text"),
8800 g_string_free (xml, TRUE);
8801 free_entity (entity);
8805 report_entity = entity_child (entity,
"report");
8807 report_entity = entity_child (report_entity,
"report");
8811 entity_t task_entity, name;
8814 task_entity = entity_child (report_entity,
"task");
8817 id = entity_attribute (task_entity,
"id");
8818 name = entity_child (task_entity,
"name");
8823 if (delta_report_id &&
id && name)
8824 g_string_append_printf (xml,
8825 "<task id=\"%s\"><name>%s</name></task>",
8826 id, entity_text (name));
8828 free_entity (entity);
8831 g_string_append (xml,
"</get_report>");
8834 g_string_free (xml, FALSE), response_data);
8837 if (read_string_c (connection, &xml))
8840 MHD_HTTP_INTERNAL_SERVER_ERROR);
8842 credentials,
"Internal error", __FUNCTION__, __LINE__,
8843 "An internal error occurred while getting a report. "
8844 "The report could not be delivered. "
8845 "Diagnostics: Failure to receive response from manager daemon.",
8849 g_string_append (xml,
"</get_report>");
8852 g_string_free (xml, FALSE), response_data);
8888 const char *alert_id, *report_id;
8889 const char *status, *filter;
8890 gchar *response, *html;
8896 if ((alert_id == NULL) || (report_id == NULL))
8900 "Missing parameter alert_id or report_id. "
8901 "Diagnostics: Required parameter was NULL.",
8907 if (filter == NULL && !
params_given (params,
"filter"))
8908 filter =
"first=1 rows=-1"
8909 " result_hosts_only=0"
8910 " apply_overrides=1"
8911 " notes=1 overrides=1"
8912 " sort-reverse=severity";
8914 ret = gvm_connection_sendf_xml (connection,
8917 " ignore_pagination=\"1\""
8919 " alert_id=\"%s\"/>",
8920 report_id, filter ? filter :
"", alert_id);
8924 MHD_HTTP_INTERNAL_SERVER_ERROR);
8926 credentials,
"Internal error", __FUNCTION__, __LINE__,
8927 "An internal error occurred while getting a report. "
8928 "The report could not be delivered. "
8929 "Diagnostics: Failure to send command to manager daemon.",
8933 if (read_entity_and_text_c (connection, &entity, &response))
8936 MHD_HTTP_INTERNAL_SERVER_ERROR);
8939 "An internal error occurred while getting a report. "
8940 "The report could not be delivered. "
8941 "Diagnostics: Failure to receive response from "
8946 status = entity_attribute (entity,
"status");
8947 if ((status == NULL) || (strlen (status) == 0))
8949 free_entity (entity);
8952 MHD_HTTP_INTERNAL_SERVER_ERROR);
8954 credentials,
"Internal error", __FUNCTION__, __LINE__,
8955 "An internal error occurred while getting a report. "
8956 "The report could not be delivered. "
8957 "Diagnostics: Failure to parse response from manager daemon.",
8960 if (strcmp (status,
"200"))
8962 free_entity (entity);
8966 "Running the report alert failed."
8967 "The report could not be delivered.",
8972 "Report Alert", response_data);
8974 free_entity (entity);
8993 const gchar *filter, *filter_id, *details;
9002 if (!filter && !filter_id)
9012 if (!filter_id && !filter)
9022 if (details && !
str_equal (details,
""))
9048 const char *ssl_cert;
9053 if (ssl_cert == NULL)
9058 "An internal error occurred."
9059 " Diagnostics: ssl_cert was NULL.",
9063 unescaped = g_uri_unescape_string (ssl_cert, NULL);
9065 cert = g_strdup_printf (
"-----BEGIN CERTIFICATE-----\n"
9066 "%s\n-----END CERTIFICATE-----\n",
9098 "An internal error occurred."
9099 " Diagnostics: ca_pub was NULL.",
9103 unescaped = g_uri_unescape_string (ca_pub, NULL);
9122 const char *key_pub;
9126 if (key_pub == NULL)
9131 "An internal error occurred."
9132 " Diagnostics: key_pub was NULL.",
9137 unescaped = g_uri_unescape_string (key_pub, NULL);
9193 const gchar *_and_report_id;
9196 _and_report_id =
params_value (params,
"_and_report_id");
9260 params_t *params,
const char *extra_xml,
9306 if (strcmp (port,
"--") == 0)
9330 if (strcmp (hosts,
"--") == 0)
9360 const char *task_id;
9364 if (task_id && (strcmp (task_id,
"0") == 0))
9380 const char *severity;
9403 const char *result_id;
9407 if (result_id && (strcmp (result_id,
"0") == 0))
9431 const char *oid, *severity, *port, *hosts;
9432 const char *text, *task_id, *result_id;
9434 const char *active, *days;
9457 switch (
gmpf (connection,
credentials, &response, &entity, response_data,
9459 "<active>%s</active>"
9463 "<severity>%s</severity>"
9466 "<result id=\"%s\"/>"
9468 strcmp (active,
"1") ? active : (days ? days :
"-1"), oid,
9469 hosts ? hosts :
"", port ? port :
"", severity ? severity :
"",
9470 text ? text :
"", task_id ? task_id :
"",
9471 result_id ? result_id :
""))
9478 MHD_HTTP_INTERNAL_SERVER_ERROR);
9480 credentials,
"Internal error", __FUNCTION__, __LINE__,
9481 "An internal error occurred while creating a new note. "
9482 "No new note was created. "
9483 "Diagnostics: Failure to send command to manager daemon.",
9487 MHD_HTTP_INTERNAL_SERVER_ERROR);
9489 credentials,
"Internal error", __FUNCTION__, __LINE__,
9490 "An internal error occurred while creating a new note. "
9491 "It is unclear whether the note has been created or not. "
9492 "Diagnostics: Failure to receive response from manager daemon.",
9496 MHD_HTTP_INTERNAL_SERVER_ERROR);
9498 credentials,
"Internal error", __FUNCTION__, __LINE__,
9499 "An internal error occurred while creating a new note. "
9500 "It is unclear whether the note has been created or not. "
9501 "Diagnostics: Internal Error.",
9505 if (entity_attribute (entity,
"id"))
9506 params_add (params,
"note_id", entity_attribute (entity,
"id"));
9508 "Create Note", response_data);
9509 free_entity (entity);
9548 const char *note_id, *text, *hosts, *port, *severity, *task_id;
9549 const char *result_id, *active, *days, *oid;
9576 switch (
gmpf (connection,
credentials, &response, &entity, response_data,
9577 "<modify_note note_id=\"%s\">"
9578 "<active>%s</active>"
9581 "<severity>%s</severity>"
9584 "<result id=\"%s\"/>"
9587 note_id, strcmp (active,
"1") ? active : (days ? days :
"-1"),
9588 hosts ? hosts :
"", port ? port :
"", severity ? severity :
"",
9589 text ? text :
"", task_id ? task_id :
"",
9590 result_id ? result_id :
"", oid))
9597 MHD_HTTP_INTERNAL_SERVER_ERROR);
9599 credentials,
"Internal error", __FUNCTION__, __LINE__,
9600 "An internal error occurred while saving a note. "
9601 "The note remains the same. "
9602 "Diagnostics: Failure to send command to manager daemon.",
9606 MHD_HTTP_INTERNAL_SERVER_ERROR);
9608 credentials,
"Internal error", __FUNCTION__, __LINE__,
9609 "An internal error occurred while saving a note. "
9610 "It is unclear whether the note has been saved or not. "
9611 "Diagnostics: Failure to receive response from manager daemon.",
9615 MHD_HTTP_INTERNAL_SERVER_ERROR);
9617 credentials,
"Internal error", __FUNCTION__, __LINE__,
9618 "An internal error occurred while saving a note. "
9619 "It is unclear whether the note has been saved or not. "
9620 "Diagnostics: Internal Error.",
9625 "Save Note", response_data);
9627 free_entity (entity);
9663 params_t *params,
const char *extra_xml,
9672 arguments, response_data);
9708 const char *oid, *severity, *custom_severity, *new_severity, *port, *hosts;
9709 const char *text, *task_id, *result_id;
9711 const char *active, *days;
9723 custom_severity =
params_value (params,
"custom_severity");
9726 if (custom_severity != NULL && strcmp (custom_severity,
"0"))
9732 new_severity = NULL;
9740 new_severity =
params_value (params,
"new_severity_from_list");
9745 new_severity = NULL;
9759 switch (
gmpf (connection,
credentials, &response, &entity, response_data,
9761 "<active>%s</active>"
9765 "<severity>%s</severity>"
9766 "<new_severity>%s</new_severity>"
9769 "<result id=\"%s\"/>"
9770 "</create_override>",
9771 strcmp (active,
"1") ? active : (days ? days :
"-1"), oid,
9772 hosts ? hosts :
"", port ? port :
"", severity ? severity :
"",
9773 new_severity, text ? text :
"", task_id ? task_id :
"",
9774 result_id ? result_id :
""))
9781 MHD_HTTP_INTERNAL_SERVER_ERROR);
9783 credentials,
"Internal error", __FUNCTION__, __LINE__,
9784 "An internal error occurred while creating a new override. "
9785 "No new override was created. "
9786 "Diagnostics: Failure to send command to manager daemon.",
9790 MHD_HTTP_INTERNAL_SERVER_ERROR);
9792 credentials,
"Internal error", __FUNCTION__, __LINE__,
9793 "An internal error occurred while creating a new override. "
9794 "It is unclear whether the override has been created or not. "
9795 "Diagnostics: Failure to receive response from manager daemon.",
9799 MHD_HTTP_INTERNAL_SERVER_ERROR);
9801 credentials,
"Internal error", __FUNCTION__, __LINE__,
9802 "An internal error occurred while creating a new override. "
9803 "It is unclear whether the override has been created or not. "
9804 "Diagnostics: Internal Error.",
9808 if (entity_attribute (entity,
"id"))
9809 params_add (params,
"override_id", entity_attribute (entity,
"id"));
9811 "Create Override", response_data);
9812 free_entity (entity);
9851 const char *override_id, *text, *hosts, *port;
9852 const char *severity, *custom_severity, *new_severity;
9853 const char *task_id, *result_id, *active, *days, *oid;
9868 custom_severity =
params_value (params,
"custom_severity");
9869 if (custom_severity && strcmp (custom_severity,
"0") != 0)
9872 new_severity =
params_value (params,
"new_severity_from_list");
9886 switch (
gmpf (connection,
credentials, &response, &entity, response_data,
9887 "<modify_override override_id=\"%s\">"
9888 "<active>%s</active>"
9892 "<severity>%s</severity>"
9893 "<new_severity>%s</new_severity>"
9896 "<result id=\"%s\"/>"
9897 "</modify_override>",
9899 strcmp (active,
"1") ? active : (days ? days :
"-1"), oid,
9900 hosts ? hosts :
"", port ? port :
"", severity ? severity :
"",
9901 new_severity, text ? text :
"", task_id ? task_id :
"",
9902 result_id ? result_id :
""))
9909 MHD_HTTP_INTERNAL_SERVER_ERROR);
9911 credentials,
"Internal error", __FUNCTION__, __LINE__,
9912 "An internal error occurred while saving a override. "
9913 "The override remains the same. "
9914 "Diagnostics: Failure to send command to manager daemon.",
9918 MHD_HTTP_INTERNAL_SERVER_ERROR);
9920 credentials,
"Internal error", __FUNCTION__, __LINE__,
9921 "An internal error occurred while saving a override. "
9922 "It is unclear whether the override has been saved or not. "
9923 "Diagnostics: Failure to receive response from manager daemon.",
9927 MHD_HTTP_INTERNAL_SERVER_ERROR);
9929 credentials,
"Internal error", __FUNCTION__, __LINE__,
9930 "An internal error occurred while saving a override. "
9931 "It is unclear whether the override has been saved or not. "
9932 "Diagnostics: Internal Error.",
9937 "Save Override", response_data);
9939 free_entity (entity);
9977 params_t *params,
const char *extra_xml,
10051 gchar *html, *response;
10052 const char *scanner_id;
10059 ret =
gmpf (connection,
credentials, &response, &entity, response_data,
10060 "<verify_scanner scanner_id=\"%s\"/>", scanner_id);
10069 MHD_HTTP_INTERNAL_SERVER_ERROR);
10071 credentials,
"Internal error", __FUNCTION__, __LINE__,
10072 "An internal error occurred while verifying a scanner. "
10073 "The scanner was not verified. "
10074 "Diagnostics: Failure to send command to manager daemon.",
10078 MHD_HTTP_INTERNAL_SERVER_ERROR);
10080 credentials,
"Internal error", __FUNCTION__, __LINE__,
10081 "An internal error occurred while verifying a scanner. "
10082 "It is unclear whether the scanner was verified or not. "
10083 "Diagnostics: Failure to send command to manager daemon.",
10087 MHD_HTTP_INTERNAL_SERVER_ERROR);
10089 credentials,
"Internal error", __FUNCTION__, __LINE__,
10090 "An internal error occurred while verifying a scanner. "
10091 "It is unclear whether the scanner was verified or not. "
10092 "Diagnostics: Failure to send command to manager daemon.",
10097 "Verify Scanner", response_data);
10098 free_entity (entity);
10119 gchar *response = NULL;
10120 const char *name, *comment, *host, *port, *type, *ca_pub, *credential_id;
10121 entity_t entity = NULL;
10129 credential_id =
params_value (params,
"credential_id");
10139 ret =
gmpf (connection,
credentials, &response, &entity, response_data,
10141 "<name>%s</name><comment>%s</comment>"
10142 "<host>%s</host><port>%s</port><type>%s</type>"
10143 "<ca_pub>%s</ca_pub>"
10144 "<credential id=\"%s\"/>"
10145 "</create_scanner>",
10146 name, comment, host, port, type, ca_pub,
10147 credential_id ? credential_id :
"");
10149 ret =
gmpf (connection,
credentials, &response, &entity, response_data,
10151 "<name>%s</name><comment>%s</comment>"
10152 "<host>%s</host><port>%s</port><type>%s</type>"
10153 "<credential id=\"%s\"/>"
10154 "</create_scanner>",
10155 name, comment, host, port, type,
10156 credential_id ? credential_id :
"");
10164 MHD_HTTP_INTERNAL_SERVER_ERROR);
10166 credentials,
"Internal error", __FUNCTION__, __LINE__,
10167 "An internal error occurred while creating a new scanner. "
10168 "No new scanner was created. "
10169 "Diagnostics: Failure to send command to manager daemon.",
10173 MHD_HTTP_INTERNAL_SERVER_ERROR);
10175 credentials,
"Internal error", __FUNCTION__, __LINE__,
10176 "An internal error occurred while creating a new scanner. "
10177 "It is unclear whether the scanner has been created or not. "
10178 "Diagnostics: Failure to receive response from manager daemon.",
10182 MHD_HTTP_INTERNAL_SERVER_ERROR);
10184 credentials,
"Internal error", __FUNCTION__, __LINE__,
10185 "An internal error occurred while creating a new scanner. "
10186 "It is unclear whether the scanner has been created or not. "
10187 "Diagnostics: Internal Error.",
10191 if (entity_attribute (entity,
"id"))
10192 params_add (params,
"scanner_id", entity_attribute (entity,
"id"));
10194 "Create Scanner", response_data);
10195 free_entity (entity);
10232 gchar *response = NULL;
10233 entity_t entity = NULL;
10234 const char *scanner_id, *name, *comment, *port, *host, *type, *ca_pub;
10235 const char *credential_id, *which_cert;
10248 credential_id =
params_value (params,
"credential_id");
10268 ret =
gmpf (connection,
credentials, &response, &entity, response_data,
10269 "<modify_scanner scanner_id=\"%s\">"
10271 "<comment>%s</comment>"
10272 "</modify_scanner>",
10273 scanner_id, name, comment ?:
"");
10275 else if (strcmp (which_cert,
"new") == 0
10276 || strcmp (which_cert,
"default") == 0)
10278 if (ca_pub == NULL)
10281 ret =
gmpf (connection,
credentials, &response, &entity, response_data,
10282 "<modify_scanner scanner_id=\"%s\">"
10284 "<comment>%s</comment>"
10285 "<ca_pub>%s</ca_pub>"
10286 "<credential id=\"%s\"/>"
10287 "</modify_scanner>",
10288 scanner_id, name, comment ?:
"",
10289 strcmp (which_cert,
"new") == 0 ? ca_pub :
"",
10290 credential_id ? credential_id :
"");
10292 ret =
gmpf (connection,
credentials, &response, &entity, response_data,
10293 "<modify_scanner scanner_id=\"%s\">"
10295 "<comment>%s</comment>"
10299 "<ca_pub>%s</ca_pub>"
10300 "<credential id=\"%s\"/>"
10301 "</modify_scanner>",
10302 scanner_id, name, comment ?:
"", host, port, type,
10303 strcmp (which_cert,
"new") == 0 ? ca_pub :
"",
10304 credential_id ? credential_id :
"");
10310 ret =
gmpf (connection,
credentials, &response, &entity, response_data,
10311 "<modify_scanner scanner_id=\"%s\">"
10313 "<comment>%s</comment>"
10314 "<credential id=\"%s\"/>"
10315 "</modify_scanner>",
10316 scanner_id, name, comment ?:
"", credential_id);
10318 ret =
gmpf (connection,
credentials, &response, &entity, response_data,
10319 "<modify_scanner scanner_id=\"%s\">"
10321 "<comment>%s</comment>"
10325 "<credential id=\"%s\"/>"
10326 "</modify_scanner>",
10327 scanner_id, name, comment ?:
"", host, port, type,
10338 MHD_HTTP_INTERNAL_SERVER_ERROR);
10340 credentials,
"Internal error", __FUNCTION__, __LINE__,
10341 "An internal error occurred while saving a scanner. "
10342 "The scanner remains the same. "
10343 "Diagnostics: Failure to send command to manager daemon.",
10347 MHD_HTTP_INTERNAL_SERVER_ERROR);
10349 credentials,
"Internal error", __FUNCTION__, __LINE__,
10350 "An internal error occurred while saving a scanner. "
10351 "It is unclear whether the scanner has been saved or not. "
10352 "Diagnostics: Failure to receive response from manager daemon.",
10356 MHD_HTTP_INTERNAL_SERVER_ERROR);
10358 credentials,
"Internal error", __FUNCTION__, __LINE__,
10359 "An internal error occurred while saving a scanner. "
10360 "It is unclear whether the scanner has been saved or not. "
10361 "Diagnostics: Internal Error.",
10366 "Save Scanner", response_data);
10368 free_entity (entity);
10388 params_t *params,
const char *extra_xml,
10397 arguments, response_data);
10451 const char *name, *comment, *timezone, *icalendar;
10466 switch (
gmpf (connection,
credentials, &response, &entity, response_data,
10467 "<create_schedule>"
10469 "<comment>%s</comment>"
10470 "<timezone>%s</timezone>"
10471 "<icalendar>%s</icalendar>"
10472 "</create_schedule>",
10473 name, comment, timezone, icalendar))
10480 MHD_HTTP_INTERNAL_SERVER_ERROR);
10482 credentials,
"Internal error", __FUNCTION__, __LINE__,
10483 "An internal error occurred while creating a new schedule. "
10484 "No new schedule was created. "
10485 "Diagnostics: Failure to send command to manager daemon.",
10489 MHD_HTTP_INTERNAL_SERVER_ERROR);
10491 credentials,
"Internal error", __FUNCTION__, __LINE__,
10492 "An internal error occurred while creating a new schedule. "
10493 "It is unclear whether the schedule has been created or not. "
10494 "Diagnostics: Failure to receive response from manager daemon.",
10498 MHD_HTTP_INTERNAL_SERVER_ERROR);
10500 credentials,
"Internal error", __FUNCTION__, __LINE__,
10501 "An internal error occurred while creating a new schedule. "
10502 "It is unclear whether the schedule has been created or not. "
10503 "Diagnostics: Internal Error.",
10507 if (entity_attribute (entity,
"id"))
10508 params_add (params,
"schedule_id", entity_attribute (entity,
"id"));
10510 "Create Schedule", response_data);
10511 free_entity (entity);
10550 time_t now, duration, duration_start;
10551 struct tm start_time, end_time;
10553 const char *slave_id, *given_duration, *range_type;
10554 const char *start_year, *start_month, *start_day, *start_hour, *start_minute;
10555 const char *end_year, *end_month, *end_day, *end_hour, *end_minute;
10564 range_type =
"duration";
10566 duration = given_duration ? atoi (given_duration) : 86400;
10567 duration_start = now - duration;
10569 xml = g_string_new (
"<get_system_reports>");
10571 g_string_append_printf (xml,
"<slave id=\"%s\"/>", slave_id ? slave_id :
"0");
10573 if (strcmp (range_type,
"duration") == 0)
10575 struct tm *time_broken;
10576 time_broken = localtime (&now);
10577 end_time.tm_year = time_broken->tm_year;
10578 end_time.tm_mon = time_broken->tm_mon;
10579 end_time.tm_mday = time_broken->tm_mday;
10580 end_time.tm_hour = time_broken->tm_hour;
10581 end_time.tm_min = time_broken->tm_min;
10583 time_broken = localtime (&duration_start);
10584 start_time.tm_year = time_broken->tm_year;
10585 start_time.tm_mon = time_broken->tm_mon;
10586 start_time.tm_mday = time_broken->tm_mday;
10587 start_time.tm_hour = time_broken->tm_hour;
10588 start_time.tm_min = time_broken->tm_min;
10590 g_string_append_printf (xml,
"<duration>%ld</duration>", duration);
10594 struct tm *time_broken;
10595 time_broken = localtime (&now);
10609 start_time.tm_year =
10610 start_year ? atoi (start_year) - 1900 : time_broken->tm_year;
10611 start_time.tm_mon =
10612 start_month ? atoi (start_month) - 1 : time_broken->tm_mon;
10613 start_time.tm_mday = start_day ? atoi (start_day) : time_broken->tm_mday;
10614 start_time.tm_hour =
10615 start_hour ? atoi (start_hour) : time_broken->tm_hour;
10616 start_time.tm_min =
10617 start_minute ? atoi (start_minute) : time_broken->tm_min;
10620 end_year ? atoi (end_year) - 1900 : time_broken->tm_year;
10621 end_time.tm_mon = end_month ? atoi (end_month) - 1 : time_broken->tm_mon;
10622 end_time.tm_mday = end_day ? atoi (end_day) : time_broken->tm_mday;
10623 end_time.tm_hour = end_hour ? atoi (end_hour) : time_broken->tm_hour;
10624 end_time.tm_min = end_minute ? atoi (end_minute) : time_broken->tm_min;
10627 g_string_append_printf (xml,
10629 "<minute>%i</minute>"
10631 "<day_of_month>%i</day_of_month>"
10632 "<month>%i</month>"
10635 start_time.tm_min, start_time.tm_hour,
10636 start_time.tm_mday, start_time.tm_mon + 1,
10637 start_time.tm_year + 1900);
10639 g_string_append_printf (xml,
10641 "<minute>%i</minute>"
10643 "<day_of_month>%i</day_of_month>"
10644 "<month>%i</month>"
10647 "<range_type>%s</range_type>",
10648 end_time.tm_min, end_time.tm_hour, end_time.tm_mday,
10649 end_time.tm_mon + 1, end_time.tm_year + 1900,
10654 if (gvm_connection_sendf (connection,
10655 "<get_system_reports brief=\"1\" slave_id=\"%s\"/>",
10656 slave_id ? slave_id :
"0")
10659 g_string_free (xml, TRUE);
10661 MHD_HTTP_INTERNAL_SERVER_ERROR);
10663 credentials,
"Internal error", __FUNCTION__, __LINE__,
10664 "An internal error occurred while getting the system reports. "
10665 "The current list of system reports is not available. "
10666 "Diagnostics: Failure to send command to manager daemon.",
10670 if (read_string_c (connection, &xml))
10672 g_string_free (xml, TRUE);
10674 MHD_HTTP_INTERNAL_SERVER_ERROR);
10676 credentials,
"Internal error", __FUNCTION__, __LINE__,
10677 "An internal error occurred while getting the system reports. "
10678 "The current list of system reports is not available. "
10679 "Diagnostics: Failure to receive response from manager daemon.",
10687 if (gvm_connection_sendf (connection,
10689 " filter=\"sort=name rows=-1 type=4\"/>")
10692 g_string_free (xml, TRUE);
10694 MHD_HTTP_INTERNAL_SERVER_ERROR);
10696 credentials,
"Internal error", __FUNCTION__, __LINE__,
10697 "An internal error occurred while getting the system reports. "
10698 "The current list of system reports is not available. "
10699 "Diagnostics: Failure to send command to manager daemon.",
10703 if (read_string_c (connection, &xml))
10705 g_string_free (xml, TRUE);
10707 MHD_HTTP_INTERNAL_SERVER_ERROR);
10709 credentials,
"Internal error", __FUNCTION__, __LINE__,
10710 "An internal error occurred while getting the system reports. "
10711 "The current list of system reports is not available. "
10712 "Diagnostics: Failure to receive response from manager daemon.",
10719 g_string_append (xml,
"</get_system_reports>");
10721 g_string_free (xml, FALSE), response_data);
10737 const char *url,
params_t *params,
10741 entity_t report_entity;
10743 gchar *gmp_command;
10744 const char *slave_id, *duration;
10746 const char *start_time;
10747 const char *end_time;
10753 if (sscanf (url,
"%500[^ /]./report.png", name) == 1)
10759 if (duration && strcmp (duration,
""))
10762 g_markup_printf_escaped (
"<get_system_reports"
10765 " slave_id=\"%s\"/>",
10766 name, duration, slave_id ? slave_id :
"0");
10776 gmp_command = g_markup_printf_escaped (
"<get_system_reports"
10778 " start_time=\"%s\""
10780 " slave_id=\"%s\"/>",
10781 name, start_time, end_time,
10782 slave_id ? slave_id :
"0");
10785 if (gvm_connection_sendf (connection,
"%s", gmp_command) == -1)
10787 g_free (gmp_command);
10790 g_free (gmp_command);
10793 if (read_entity_c (connection, &entity))
10798 report_entity = entity_child (entity,
"system_report");
10799 if (report_entity == NULL)
10801 free_entity (entity);
10805 report_entity = entity_child (report_entity,
"report");
10806 if (report_entity == NULL)
10808 free_entity (entity);
10813 char *content_64 = entity_text (report_entity);
10814 char *content = NULL;
10815 gsize content_length = 0;
10817 if (content_64 && strlen (content_64))
10819 content = (
char *) g_base64_decode (content_64, &content_length);
10828 content = g_strdup (
"helo");
10833 free_entity (entity);
10854 params_t *params,
const char *extra_xml,
10864 arguments, response_data);
10920 params, response_data);
10938 gchar *command, *html, *response;
10946 command = g_strdup_printf (
"<create_report_format>"
10948 "</create_report_format>",
10951 gmp (connection,
credentials, &response, &entity, response_data, command);
10960 MHD_HTTP_INTERNAL_SERVER_ERROR);
10962 credentials,
"Internal error", __FUNCTION__, __LINE__,
10963 "An internal error occurred while importing a report format. "
10964 "The schedule remains the same. "
10965 "Diagnostics: Failure to send command to manager daemon.",
10969 MHD_HTTP_INTERNAL_SERVER_ERROR);
10971 credentials,
"Internal error", __FUNCTION__, __LINE__,
10972 "An internal error occurred while importing a report format. "
10973 "It is unclear whether the schedule has been saved or not. "
10974 "Diagnostics: Failure to receive response from manager daemon.",
10978 MHD_HTTP_INTERNAL_SERVER_ERROR);
10980 credentials,
"Internal error", __FUNCTION__, __LINE__,
10981 "An internal error occurred while importing a report format. "
10982 "It is unclear whether the schedule has been saved or not. "
10983 "Diagnostics: Internal Error.",
10989 if (entity_attribute (entity,
"id"))
10990 params_add (params,
"report_format_id", entity_attribute (entity,
"id"));
10992 "Create Report Format", response_data);
10994 free_entity (entity);
11015 gchar *html, *response;
11016 params_t *preferences, *id_list_params, *include_id_lists;
11017 const char *report_format_id, *name, *summary, *enable;
11020 report_format_id =
params_value (params,
"report_format_id");
11031 include_id_lists =
params_values (params,
"include_id_list:");
11032 if (include_id_lists)
11034 GHashTable *id_lists;
11036 gchar *param_name, *pref_name, *value, *old_values, *new_values;
11038 GHashTableIter hash_table_iter;
11041 g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
11049 g_hash_table_insert (id_lists, g_strdup (param_name), g_strdup (
""));
11058 gchar *colon_pos = strchr (
param->
value,
':');
11061 value = g_strdup (colon_pos + 1);
11063 old_values = g_hash_table_lookup (id_lists, pref_name);
11065 if (old_values && strcmp (old_values,
""))
11067 new_values = g_strdup_printf (
"%s,%s", old_values, value);
11068 g_hash_table_insert (id_lists, pref_name, new_values);
11071 else if (old_values)
11073 g_hash_table_insert (id_lists, pref_name, value);
11077 g_hash_table_iter_init (&hash_table_iter, id_lists);
11078 while (g_hash_table_iter_next (&hash_table_iter, (
void **) &pref_name,
11083 value_64 = strlen (value)
11084 ? g_base64_encode ((guchar *) value, strlen (value))
11091 "<modify_report_format"
11092 " report_format_id=\"%s\">"
11095 "<value>%s</value>"
11097 "</modify_report_format>",
11098 report_format_id, pref_name, value_64);
11106 response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
11108 credentials,
"Internal error", __FUNCTION__, __LINE__,
11109 "An internal error occurred while saving a Report Format. "
11110 "The Report Format was not saved. "
11111 "Diagnostics: Failure to send command to manager daemon.",
11115 response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
11117 credentials,
"Internal error", __FUNCTION__, __LINE__,
11118 "An internal error occurred while saving a Report Format. "
11119 "It is unclear whether the Report Format has been saved or "
11121 "Diagnostics: Failure to receive response from manager daemon.",
11126 response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
11128 credentials,
"Internal error", __FUNCTION__, __LINE__,
11129 "An internal error occurred while saving a Report Format. "
11130 "It is unclear whether the Report Format has been saved or "
11132 "Diagnostics: Internal Error.",
11158 splits = g_strsplit (param_name,
":", 4);
11159 if (splits && splits[0] && splits[1] && splits[2] && splits[3])
11172 "<modify_report_format"
11173 " report_format_id=\"%s\">"
11176 "<value>%s</value>"
11178 "</modify_report_format>",
11179 report_format_id, splits[3], value);
11187 response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
11188 g_strfreev (splits);
11190 credentials,
"Internal error", __FUNCTION__, __LINE__,
11191 "An internal error occurred while saving a Report Format. "
11192 "The Report Format was not saved. "
11193 "Diagnostics: Failure to send command to manager daemon.",
11197 response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
11198 g_strfreev (splits);
11200 credentials,
"Internal error", __FUNCTION__, __LINE__,
11201 "An internal error occurred while saving a Report Format. "
11202 "It is unclear whether the Report Format has been saved or "
11204 "Diagnostics: Failure to receive response from manager "
11210 response_data, MHD_HTTP_INTERNAL_SERVER_ERROR);
11211 g_strfreev (splits);
11213 credentials,
"Internal error", __FUNCTION__, __LINE__,
11214 "An internal error occurred while saving a Report Format. "
11215 "It is unclear whether the Report Format has been saved or "
11217 "Diagnostics: Internal Error.",
11223 g_strfreev (splits);
11229 ret =
gmpf (connection,
credentials, &response, &entity, response_data,
11230 "<modify_report_format"
11231 " report_format_id=\"%s\">"
11233 "<summary>%s</summary>"
11234 "<active>%s</active>"
11235 "</modify_report_format>",
11236 report_format_id, name, summary, enable);
11246 MHD_HTTP_INTERNAL_SERVER_ERROR);
11248 credentials,
"Internal error", __FUNCTION__, __LINE__,
11249 "An internal error occurred while saving a Report Format. "
11250 "The Report Format was not saved. "
11251 "Diagnostics: Failure to send command to manager daemon.",
11255 MHD_HTTP_INTERNAL_SERVER_ERROR);
11257 credentials,
"Internal error", __FUNCTION__, __LINE__,
11258 "An internal error occurred while saving a Report Format. "
11259 "It is unclear whether the Report Format has been saved or not. "
11260 "Diagnostics: Failure to receive response from manager daemon.",
11264 MHD_HTTP_INTERNAL_SERVER_ERROR);
11266 credentials,
"Internal error", __FUNCTION__, __LINE__,
11267 "An internal error occurred while saving a Report Format. "
11268 "It is unclear whether the Report Format has been saved or not. "
11269 "Diagnostics: Internal Error.",
11274 "Save Report Format", response_data);
11275 free_entity (entity);
11298 gchar *param_name, *html, *response;
11312 credentials,
"Internal error", __FUNCTION__, __LINE__,
11313 "An internal error occurred while trying to start a wizard. "
11314 "Diagnostics: Required parameter 'name' was NULL.",
11317 run = g_string_new (
"<run_wizard>");
11319 g_string_append_printf (run,
11329 xml_string_append (run,
11332 "<value>%s</value>"
11337 g_string_append (run,
"</params></run_wizard>");
11342 gmp (connection,
credentials, &response, &entity, response_data, run->str);
11343 g_string_free (run, TRUE);
11351 MHD_HTTP_INTERNAL_SERVER_ERROR);
11353 credentials,
"Internal error", __FUNCTION__, __LINE__,
11354 "An internal error occurred while running a wizard. "
11355 "The wizard did not start. "
11356 "Diagnostics: Failure to send command to manager daemon.",
11360 MHD_HTTP_INTERNAL_SERVER_ERROR);
11362 credentials,
"Internal error", __FUNCTION__, __LINE__,
11363 "An internal error occurred while running a wizard. "
11364 "It is unclear whether the wizard started or not. "
11365 "Diagnostics: Failure to receive response from manager daemon.",
11369 MHD_HTTP_INTERNAL_SERVER_ERROR);
11372 "An internal error occurred while running a wizard. "
11373 "It is unclear whether the wizard started or not. "
11374 "Diagnostics: Internal Error.",
11379 "Run Wizard", response_data);
11380 free_entity (entity);
11385 #define GET_TRASH_RESOURCE(capability, command, name) \
11386 if (command_enabled (credentials, capability)) \
11388 if (gvm_connection_sendf (connection, \
11389 "<" command " filter=\"rows=-1 sort=name\"" \
11390 " trash=\"1\"/>") \
11393 g_string_free (xml, TRUE); \
11394 cmd_response_data_set_status_code (response_data, \
11395 MHD_HTTP_INTERNAL_SERVER_ERROR); \
11396 return gsad_message ( \
11397 credentials, "Internal error", __FUNCTION__, __LINE__, \
11398 "An internal error occurred while getting " name \
11399 " list for trash." \
11400 "Diagnostics: Failure to send command to" \
11401 " manager daemon.", \
11405 if (read_string_c (connection, &xml)) \
11407 g_string_free (xml, TRUE); \
11408 cmd_response_data_set_status_code (response_data, \
11409 MHD_HTTP_INTERNAL_SERVER_ERROR); \
11410 return gsad_message ( \
11411 credentials, "Internal error", __FUNCTION__, __LINE__, \
11412 "An internal error occurred while getting " name " list." \
11413 "Diagnostics: Failure to receive response from" \
11414 " manager daemon.", \
11432 params_t *params,
const char *extra_xml,
11437 xml = g_string_new (
"<get_trash>");
11440 g_string_append (xml, extra_xml);
11481 g_string_append (xml,
"</get_trash>");
11483 g_string_free (xml, FALSE), response_data);
11485 #undef GET_TRASH_RESOURCE
11517 params_t *changed, GString *xml,
int *modify_failed_flag,
11530 const char *changed_value =
params_value (changed, uuid);
11531 if (changed_value == NULL
11532 || (strcmp (changed_value,
"") && strcmp (changed_value,
"0")))
11536 base64 = g_base64_encode ((guchar *)
param->
value,
11539 base64 = g_strdup (
"");
11540 if (gvm_connection_sendf_xml (connection,
11541 "<modify_setting setting_id=\"%s\">"
11542 "<value>%s</value>"
11543 "</modify_setting>",
11553 xml_string_append (xml,
"<save_setting id=\"%s\">", uuid);
11554 if (read_entity_and_string_c (connection, &entity, &xml))
11556 free_entity (entity);
11559 xml_string_append (xml,
"</save_setting>");
11563 if (modify_failed_flag)
11564 *modify_failed_flag = 1;
11566 free_entity (entity);
11590 params_t *params,
const gchar *accept_language,
11593 const char *lang, *text, *old_passwd, *passwd, *max;
11594 const char *details_fname, *list_fname, *report_fname;
11595 gchar *lang_64, *text_64, *max_64, *fname_64;
11598 params_t *changed, *defaults, *filters;
11599 int modify_failed = 0;
11600 const char *changed_value;
11601 gboolean user_changed = 0;
11612 details_fname =
params_value (params,
"details_fname");
11625 xml = g_string_new (
"");
11628 if ((strlen (passwd) || strlen (old_passwd))
11629 && (changed_value == NULL
11630 || (strcmp (changed_value,
"") && strcmp (changed_value,
"0"))))
11633 gmp_authenticate_info_opts_t auth_opts;
11637 auth_opts = gmp_authenticate_info_opts_defaults;
11639 auth_opts.password = old_passwd;
11640 switch (gmp_authenticate_info_ext_c (connection, auth_opts))
11646 MHD_HTTP_INTERNAL_SERVER_ERROR);
11648 credentials,
"Internal error", __FUNCTION__, __LINE__,
11649 "An internal error occurred while saving settings. "
11650 "The settings remains the same. "
11651 "Diagnostics: Manager closed connection during authenticate.",
11655 MHD_HTTP_INTERNAL_SERVER_ERROR);
11657 credentials,
"Invalid Password", __FUNCTION__, __LINE__,
11658 "You tried to change your password, but the old"
11659 " password was not provided or was incorrect. "
11660 " Please enter the correct old password or remove"
11661 " old and new passwords to apply any other changes"
11662 " of your settings.",
11666 MHD_HTTP_INTERNAL_SERVER_ERROR);
11668 credentials,
"Internal error", __FUNCTION__, __LINE__,
11669 "An internal error occurred while saving settings. "
11670 "The settings remains the same. "
11671 "Diagnostics: Internal Error.",
11675 passwd_64 = g_base64_encode ((guchar *) passwd, strlen (passwd));
11677 if (gvm_connection_sendf (connection,
11679 "<name>Password</name>"
11680 "<value>%s</value>"
11681 "</modify_setting>",
11682 passwd_64 ? passwd_64 :
"")
11685 g_free (passwd_64);
11687 MHD_HTTP_INTERNAL_SERVER_ERROR);
11689 credentials,
"Internal error", __FUNCTION__, __LINE__,
11690 "An internal error occurred while saving settings. "
11691 "It is unclear whether all the settings were saved. "
11692 "Diagnostics: Failure to send command to manager daemon.",
11695 g_free (passwd_64);
11698 xml_string_append (xml,
"<save_setting name=\"Password\">");
11699 if (read_entity_and_string_c (connection, &entity, &xml))
11701 g_string_free (xml, TRUE);
11703 MHD_HTTP_INTERNAL_SERVER_ERROR);
11705 credentials,
"Internal error", __FUNCTION__, __LINE__,
11706 "An internal error occurred while saving settings. "
11707 "Diagnostics: Failure to receive response from manager daemon.",
11710 xml_string_append (xml,
"</save_setting>");
11727 if (changed_value == NULL
11728 || (strcmp (changed_value,
"") && strcmp (changed_value,
"0")))
11730 text_64 = g_base64_encode ((guchar *) text, strlen (text));
11732 if (gvm_connection_sendf (connection,
11734 "<name>Timezone</name>"
11735 "<value>%s</value>"
11736 "</modify_setting>",
11737 text_64 ? text_64 :
"")
11742 MHD_HTTP_INTERNAL_SERVER_ERROR);
11744 credentials,
"Internal error", __FUNCTION__, __LINE__,
11745 "An internal error occurred while saving settings. "
11746 "It is unclear whether all the settings were saved. "
11747 "Diagnostics: Failure to send command to manager daemon.",
11753 xml_string_append (xml,
"<save_setting name=\"Timezone\">");
11754 if (read_entity_and_string_c (connection, &entity, &xml))
11756 g_string_free (xml, TRUE);
11758 MHD_HTTP_INTERNAL_SERVER_ERROR);
11760 credentials,
"Internal error", __FUNCTION__, __LINE__,
11761 "An internal error occurred while saving settings. "
11762 "Diagnostics: Failure to receive response from manager daemon.",
11765 xml_string_append (xml,
"</save_setting>");
11769 const gchar *timezone = strlen (text) ? text :
"UTC";
11777 if (setenv (
"TZ", timezone, 1) == -1)
11779 g_critical (
"%s: failed to set TZ\n", __FUNCTION__);
11780 exit (EXIT_FAILURE);
11793 if (changed_value == NULL
11794 || (strcmp (changed_value,
"") && strcmp (changed_value,
"0")))
11796 max_64 = g_base64_encode ((guchar *) max, strlen (max));
11798 if (gvm_connection_sendf (connection,
11801 "=\"5f5a8712-8017-11e1-8556-406186ea4fc5\">"
11802 "<value>%s</value>"
11803 "</modify_setting>",
11804 max_64 ? max_64 :
"")
11809 MHD_HTTP_INTERNAL_SERVER_ERROR);
11811 credentials,
"Internal error", __FUNCTION__, __LINE__,
11812 "An internal error occurred while saving settings. "
11813 "It is unclear whether all the settings were saved. "
11814 "Diagnostics: Failure to send command to manager daemon.",
11820 xml_string_append (xml,
"<save_setting id=\"%s\">",
11821 "5f5a8712-8017-11e1-8556-406186ea4fc5");
11822 if (read_entity_and_string_c (connection, &entity, &xml))
11824 g_string_free (xml, TRUE);
11826 MHD_HTTP_INTERNAL_SERVER_ERROR);
11828 credentials,
"Internal error", __FUNCTION__, __LINE__,
11829 "An internal error occurred while saving settings. "
11830 "It is unclear whether all the settings were saved. "
11831 "Diagnostics: Failure to receive response from manager daemon.",
11834 xml_string_append (xml,
"</save_setting>");
11843 changed_value =
params_value (changed,
"details_fname");
11844 if (changed_value == NULL
11845 || (strcmp (changed_value,
"") && strcmp (changed_value,
"0")))
11848 g_base64_encode ((guchar *) details_fname, strlen (details_fname));
11850 if (gvm_connection_sendf (connection,
11853 "=\"a6ac88c5-729c-41ba-ac0a-deea4a3441f2\">"
11854 "<value>%s</value>"
11855 "</modify_setting>",
11856 fname_64 ? fname_64 :
"")
11861 MHD_HTTP_INTERNAL_SERVER_ERROR);
11863 credentials,
"Internal error", __FUNCTION__, __LINE__,
11864 "An internal error occurred while saving settings. "
11865 "It is unclear whether all the settings were saved. "
11866 "Diagnostics: Failure to send command to manager daemon.",
11872 xml_string_append (xml,
"<save_setting id=\"%s\">",
11873 "a6ac88c5-729c-41ba-ac0a-deea4a3441f2");
11874 if (read_entity_and_string_c (connection, &entity, &xml))
11876 g_string_free (xml, TRUE);
11878 MHD_HTTP_INTERNAL_SERVER_ERROR);
11880 credentials,
"Internal error", __FUNCTION__, __LINE__,
11881 "An internal error occurred while saving settings. "
11882 "It is unclear whether all the settings were saved. "
11883 "Diagnostics: Failure to receive response from manager daemon.",
11886 xml_string_append (xml,
"</save_setting>");
11896 if (changed_value == NULL
11897 || (strcmp (changed_value,
"") && strcmp (changed_value,
"0")))
11899 fname_64 = g_base64_encode ((guchar *) list_fname, strlen (list_fname));
11901 if (gvm_connection_sendf (connection,
11904 "=\"0872a6ed-4f85-48c5-ac3f-a5ef5e006745\">"
11905 "<value>%s</value>"
11906 "</modify_setting>",
11907 fname_64 ? fname_64 :
"")
11912 MHD_HTTP_INTERNAL_SERVER_ERROR);
11914 credentials,
"Internal error", __FUNCTION__, __LINE__,
11915 "An internal error occurred while saving settings. "
11916 "It is unclear whether all the settings were saved. "
11917 "Diagnostics: Failure to send command to manager daemon.",
11923 xml_string_append (xml,
"<save_setting id=\"%s\">",
11924 "a6ac88c5-729c-41ba-ac0a-deea4a3441f2");
11925 if (read_entity_and_string_c (connection, &entity, &xml))
11927 g_string_free (xml, TRUE);
11929 MHD_HTTP_INTERNAL_SERVER_ERROR);
11931 credentials,
"Internal error", __FUNCTION__, __LINE__,
11932 "An internal error occurred while saving settings. "
11933 "It is unclear whether all the settings were saved. "
11934 "Diagnostics: Failure to receive response from manager daemon.",
11937 xml_string_append (xml,
"</save_setting>");
11946 changed_value =
params_value (changed,
"report_fname");
11947 if (changed_value == NULL
11948 || (strcmp (changed_value,
"") && strcmp (changed_value,
"0")))
11951 g_base64_encode ((guchar *) report_fname, strlen (report_fname));
11953 if (gvm_connection_sendf (connection,
11956 "=\"e1a2ae0b-736e-4484-b029-330c9e15b900\">"
11957 "<value>%s</value>"
11958 "</modify_setting>",
11959 fname_64 ? fname_64 :
"")
11964 MHD_HTTP_INTERNAL_SERVER_ERROR);
11966 credentials,
"Internal error", __FUNCTION__, __LINE__,
11967 "An internal error occurred while saving settings. "
11968 "It is unclear whether all the settings were saved. "
11969 "Diagnostics: Failure to send command to manager daemon.",
11975 xml_string_append (xml,
"<save_setting id=\"%s\">",
11976 "e1a2ae0b-736e-4484-b029-330c9e15b900");
11977 if (read_entity_and_string_c (connection, &entity, &xml))
11979 g_string_free (xml, TRUE);
11981 MHD_HTTP_INTERNAL_SERVER_ERROR);
11983 credentials,
"Internal error", __FUNCTION__, __LINE__,
11984 "An internal error occurred while saving settings. "
11985 "It is unclear whether all the settings were saved. "
11986 "Diagnostics: Failure to receive response from manager daemon.",
11989 xml_string_append (xml,
"</save_setting>");
11999 if (changed_value == NULL
12000 || (strcmp (changed_value,
"") && strcmp (changed_value,
"0")))
12002 lang_64 = g_base64_encode ((guchar *) lang, strlen (lang));
12004 if (gvm_connection_sendf (connection,
12007 "=\"6765549a-934e-11e3-b358-406186ea4fc5\">"
12008 "<value>%s</value>"
12009 "</modify_setting>",
12010 lang_64 ? lang_64 :
"")
12015 MHD_HTTP_INTERNAL_SERVER_ERROR);
12017 credentials,
"Internal error", __FUNCTION__, __LINE__,
12018 "An internal error occurred while saving settings. "
12019 "It is unclear whether all the settings were saved. "
12020 "Diagnostics: Failure to send command to manager daemon.",
12026 xml_string_append (xml,
"<save_setting id=\"%s\">",
12027 "6765549a-934e-11e3-b358-406186ea4fc5");
12028 if (read_entity_and_string_c (connection, &entity, &xml))
12030 g_string_free (xml, TRUE);
12032 MHD_HTTP_INTERNAL_SERVER_ERROR);
12034 credentials,
"Internal error", __FUNCTION__, __LINE__,
12035 "An internal error occurred while saving settings. "
12036 "It is unclear whether all the settings were saved. "
12037 "Diagnostics: Failure to receive response from manager daemon.",
12040 xml_string_append (xml,
"</save_setting>");
12060 MHD_HTTP_INTERNAL_SERVER_ERROR);
12062 credentials,
"Internal error", __FUNCTION__, __LINE__,
12063 "An internal error occurred while saving settings. "
12064 "It is unclear whether all the settings were saved. "
12065 "Diagnostics: Failure to send command to manager daemon.",
12076 MHD_HTTP_INTERNAL_SERVER_ERROR);
12078 credentials,
"Internal error", __FUNCTION__, __LINE__,
12079 "An internal error occurred while saving settings. "
12080 "It is unclear whether all the settings were saved. "
12081 "Diagnostics: Failure to send command to manager daemon.",
12087 changed_value =
params_value (changed,
"severity_class");
12088 if (changed_value == NULL
12089 || (strcmp (changed_value,
"") && strcmp (changed_value,
"0")))
12092 text_64 = (text ? g_base64_encode ((guchar *) text, strlen (text))
12095 if (gvm_connection_sendf (connection,
12098 "=\"f16bb236-a32d-4cd5-a880-e0fcf2599f59\">"
12099 "<value>%s</value>"
12100 "</modify_setting>",
12101 text_64 ? text_64 :
"")
12106 MHD_HTTP_INTERNAL_SERVER_ERROR);
12108 credentials,
"Internal error", __FUNCTION__, __LINE__,
12109 "An internal error occurred while saving settings. "
12110 "It is unclear whether all the settings were saved. "
12111 "Diagnostics: Failure to send command to manager daemon.",
12117 xml_string_append (xml,
"<save_setting id=\"%s\">",
12118 "f16bb236-a32d-4cd5-a880-e0fcf2599f59");
12119 if (read_entity_and_string_c (connection, &entity, &xml))
12121 g_string_free (xml, TRUE);
12123 MHD_HTTP_INTERNAL_SERVER_ERROR);
12125 credentials,
"Internal error", __FUNCTION__, __LINE__,
12126 "An internal error occurred while saving settings. "
12127 "It is unclear whether all the settings were saved. "
12128 "Diagnostics: Failure to receive response from manager daemon.",
12131 xml_string_append (xml,
"</save_setting>");
12135 if ((text != NULL) && (strlen (text) > 0))
12150 changed_value =
params_value (changed,
"dynamic_severity");
12151 if (changed_value == NULL
12152 || (strcmp (changed_value,
"") && strcmp (changed_value,
"0")))
12155 text_64 = (text ? g_base64_encode ((guchar *) text, strlen (text))
12158 if (gvm_connection_sendf (connection,
12161 "=\"77ec2444-e7f2-4a80-a59b-f4237782d93f\">"
12162 "<value>%s</value>"
12163 "</modify_setting>",
12164 text_64 ? text_64 :
"")
12169 MHD_HTTP_INTERNAL_SERVER_ERROR);
12171 credentials,
"Internal error", __FUNCTION__, __LINE__,
12172 "An internal error occurred while saving settings. "
12173 "It is unclear whether all the settings were saved. "
12174 "Diagnostics: Failure to send command to manager daemon.",
12180 xml_string_append (xml,
"<save_setting id=\"%s\">",
12181 "77ec2444-e7f2-4a80-a59b-f4237782d93f");
12182 if (read_entity_and_string_c (connection, &entity, &xml))
12184 g_string_free (xml, TRUE);
12186 MHD_HTTP_INTERNAL_SERVER_ERROR);
12188 credentials,
"Internal error", __FUNCTION__, __LINE__,
12189 "An internal error occurred while saving settings. "
12190 "It is unclear whether all the settings were saved. "
12191 "Diagnostics: Failure to receive response from manager daemon.",
12194 xml_string_append (xml,
"</save_setting>");
12203 changed_value =
params_value (changed,
"default_severity");
12204 if (changed_value == NULL
12205 || (strcmp (changed_value,
"") && strcmp (changed_value,
"0")))
12208 text_64 = (text ? g_base64_encode ((guchar *) text, strlen (text))
12211 if (gvm_connection_sendf (connection,
12214 "=\"7eda49c5-096c-4bef-b1ab-d080d87300df\">"
12215 "<value>%s</value>"
12216 "</modify_setting>",
12217 text_64 ? text_64 :
"")
12222 MHD_HTTP_INTERNAL_SERVER_ERROR);
12224 credentials,
"Internal error", __FUNCTION__, __LINE__,
12225 "An internal error occurred while saving settings. "
12226 "It is unclear whether all the settings were saved. "
12227 "Diagnostics: Failure to send command to manager daemon.",
12233 xml_string_append (xml,
"<save_setting id=\"%s\">",
12234 "7eda49c5-096c-4bef-b1ab-d080d87300df");
12235 if (read_entity_and_string_c (connection, &entity, &xml))
12237 g_string_free (xml, TRUE);
12239 MHD_HTTP_INTERNAL_SERVER_ERROR);
12241 credentials,
"Internal error", __FUNCTION__, __LINE__,
12242 "An internal error occurred while saving settings. "
12243 "It is unclear whether all the settings were saved. "
12244 "Diagnostics: Failure to receive response from manager daemon.",
12247 xml_string_append (xml,
"</save_setting>");
12257 changed_value =
params_value (changed,
"auto_cache_rebuild");
12258 if (changed_value == NULL
12259 || (strcmp (changed_value,
"") && strcmp (changed_value,
"0")))
12262 text_64 = (text ? g_base64_encode ((guchar *) text, strlen (text))
12265 if (gvm_connection_sendf (connection,
12268 "=\"a09285b0-2d47-49b6-a4ef-946ee71f1d5c\">"
12269 "<value>%s</value>"
12270 "</modify_setting>",
12271 text_64 ? text_64 :
"")
12275 gvm_connection_close (connection);
12277 MHD_HTTP_INTERNAL_SERVER_ERROR);
12279 credentials,
"Internal error", __FUNCTION__, __LINE__,
12280 "An internal error occurred while saving settings. "
12281 "It is unclear whether all the settings were saved. "
12282 "Diagnostics: Failure to send command to manager daemon.",
12288 xml_string_append (xml,
"<save_setting id=\"%s\">",
12289 "a09285b0-2d47-49b6-a4ef-946ee71f1d5c");
12290 if (read_entity_and_string_c (connection, &entity, &xml))
12292 g_string_free (xml, TRUE);
12293 gvm_connection_close (connection);
12295 MHD_HTTP_INTERNAL_SERVER_ERROR);
12297 credentials,
"Internal error", __FUNCTION__, __LINE__,
12298 "An internal error occurred while saving settings. "
12299 "It is unclear whether all the settings were saved. "
12300 "Diagnostics: Failure to receive response from manager daemon.",
12303 xml_string_append (xml,
"</save_setting>");
12317 g_string_free (xml, FALSE), response_data);
12335 params_t *params,
const char *extra_xml,
12409 gchar *html, *response, *command, *specials_element;
12410 const char *name, *comment, *
users, *grant_full;
12426 xml = g_string_new (
"");
12428 xml_string_append (xml,
12430 "<comment>%s</comment>"
12431 "<users>%s</users>",
12432 name, comment,
users);
12435 specials_element = g_strdup_printf (
"<full/>");
12437 specials_element = NULL;
12439 command = g_strdup_printf (
"<create_group>"
12445 xml->str, specials_element);
12447 g_string_free (xml, TRUE);
12448 g_free (specials_element);
12451 gmp (connection,
credentials, &response, &entity, response_data, command);
12460 MHD_HTTP_INTERNAL_SERVER_ERROR);
12462 credentials,
"Internal error", __FUNCTION__, __LINE__,
12463 "An internal error occurred while creating a new group. "
12464 "No new group was created. "
12465 "Diagnostics: Failure to send command to manager daemon.",
12469 MHD_HTTP_INTERNAL_SERVER_ERROR);
12471 credentials,
"Internal error", __FUNCTION__, __LINE__,
12472 "An internal error occurred while creating a new group. "
12473 "It is unclear whether the group has been created or not. "
12474 "Diagnostics: Failure to receive response from manager daemon.",
12478 MHD_HTTP_INTERNAL_SERVER_ERROR);
12480 credentials,
"Internal error", __FUNCTION__, __LINE__,
12481 "An internal error occurred while creating a new group. "
12482 "It is unclear whether the group has been created or not. "
12483 "Diagnostics: Internal Error.",
12487 if (entity_attribute (entity,
"id"))
12488 params_add (params,
"group_id", entity_attribute (entity,
"id"));
12490 "Create Group", response_data);
12491 free_entity (entity);
12547 gchar *html, *response;
12548 const char *group_id, *name, *comment, *
users;
12565 ret =
gmpf (connection,
credentials, &response, &entity, response_data,
12566 "<modify_group group_id=\"%s\">"
12568 "<comment>%s</comment>"
12569 "<users>%s</users>"
12571 group_id, name, comment,
users);
12580 MHD_HTTP_INTERNAL_SERVER_ERROR);
12582 credentials,
"Internal error", __FUNCTION__, __LINE__,
12583 "An internal error occurred while saving a group. "
12584 "The group was not saved. "
12585 "Diagnostics: Failure to send command to manager daemon.",
12589 MHD_HTTP_INTERNAL_SERVER_ERROR);
12591 credentials,
"Internal error", __FUNCTION__, __LINE__,
12592 "An internal error occurred while saving a group. "
12593 "It is unclear whether the group has been saved or not. "
12594 "Diagnostics: Failure to receive response from manager daemon.",
12598 MHD_HTTP_INTERNAL_SERVER_ERROR);
12600 credentials,
"Internal error", __FUNCTION__, __LINE__,
12601 "An internal error occurred while saving a group. "
12602 "It is unclear whether the group has been saved or not. "
12603 "Diagnostics: Internal Error.",
12608 "Save Group", response_data);
12609 free_entity (entity);
12629 params_t *params,
const char *extra_xml,
12638 arguments, response_data);
12709 gchar *html, *response;
12710 const char *name, *comment, *resource_id, *resource_type;
12711 const char *subject_id, *subject_type;
12717 resource_type =
params_value (params,
"optional_resource_type");
12729 subject_id =
params_value (params,
"permission_user_id");
12730 else if (
str_equal (subject_type,
"group"))
12731 subject_id =
params_value (params,
"permission_group_id");
12732 else if (
str_equal (subject_type,
"role"))
12733 subject_id =
params_value (params,
"permission_role_id");
12743 ret =
gmpf (connection,
credentials, &response, &entity, response_data,
12744 "<create_permission>"
12746 "<comment>%s</comment>"
12747 "<resource id=\"%s\">"
12750 "<subject id=\"%s\"><type>%s</type></subject>"
12751 "</create_permission>",
12752 name, comment ? comment :
"", resource_id ? resource_id :
"",
12753 resource_type ? resource_type :
"", subject_id, subject_type);
12762 MHD_HTTP_INTERNAL_SERVER_ERROR);
12764 credentials,
"Internal error", __FUNCTION__, __LINE__,
12765 "An internal error occurred while creating a permission. "
12766 "The permission was not created. "
12767 "Diagnostics: Failure to send command to manager daemon.",
12771 MHD_HTTP_INTERNAL_SERVER_ERROR);
12773 credentials,
"Internal error", __FUNCTION__, __LINE__,
12774 "An internal error occurred while creating a permission. "
12775 "It is unclear whether the permission has been created or not. "
12776 "Diagnostics: Failure to receive response from manager daemon.",
12780 MHD_HTTP_INTERNAL_SERVER_ERROR);
12782 credentials,
"Internal error", __FUNCTION__, __LINE__,
12783 "An internal error occurred while creating a permission. "
12784 "It is unclear whether the permission has been created or not. "
12785 "Diagnostics: Internal Error.",
12789 if (entity_attribute (entity,
"id"))
12790 params_add (params,
"permission_id", entity_attribute (entity,
"id"));
12793 "Create Permission", response_data);
12795 free_entity (entity);
12800 #define CHECK_GMPF_RET \
12807 cmd_response_data_set_status_code (response_data, \
12808 MHD_HTTP_INTERNAL_SERVER_ERROR); \
12809 return gsad_message ( \
12810 credentials, "Internal error", __FUNCTION__, __LINE__, \
12811 "An internal error occurred while creating a permission. " \
12812 "The permission was not created. " \
12813 "Diagnostics: Failure to send command to manager daemon.", \
12816 cmd_response_data_set_status_code (response_data, \
12817 MHD_HTTP_INTERNAL_SERVER_ERROR); \
12818 return gsad_message ( \
12819 credentials, "Internal error", __FUNCTION__, __LINE__, \
12820 "An internal error occurred while creating a permission. " \
12821 "It is unclear whether the permission has been created or not. " \
12822 "Diagnostics: Failure to receive response from manager daemon.", \
12825 cmd_response_data_set_status_code (response_data, \
12826 MHD_HTTP_INTERNAL_SERVER_ERROR); \
12827 return gsad_message ( \
12828 credentials, "Internal error", __FUNCTION__, __LINE__, \
12829 "An internal error occurred while creating a permission. " \
12830 "It is unclear whether the permission has been created or not. " \
12831 "Diagnostics: Internal Error.", \
12834 if (gmp_success (entity)) \
12837 free_entity (entity); \
12838 g_free (response); \
12842 html = response_from_entity (connection, credentials, params, entity, \
12843 "Create Permissions", response_data); \
12844 free_entity (entity); \
12845 g_free (response); \
12849 #define INCLUDE_RELATED_CURRENT_RESOURCE_ONLY 0
12850 #define INCLUDE_RELATED_ALL_RESOURCES 1
12851 #define INCLUDE_RELATED_RESOURCES_ONLY 2
12869 gchar *html, *response, *summary_response;
12871 const char *permission, *comment, *resource_id, *resource_type;
12872 const char *subject_id, *subject_type;
12873 const char *permission_resource_type;
12874 int include_related;
12878 permission =
params_value (params,
"permission_type");
12881 resource_type =
params_value (params,
"resource_type");
12885 "Create Permission");
12894 permission_resource_type =
"asset";
12897 permission_resource_type = resource_type;
12899 include_related = atoi (
params_value (params,
"include_related"));
12902 subject_id =
params_value (params,
"permission_user_id");
12903 else if (
str_equal (subject_type,
"group"))
12904 subject_id =
params_value (params,
"permission_group_id");
12905 else if (
str_equal (subject_type,
"role"))
12906 subject_id =
params_value (params,
"permission_role_id");
12925 "<create_permission>"
12926 "<name>get_%ss</name>"
12927 "<comment>%s</comment>"
12928 "<resource id=\"%s\">"
12930 "<subject id=\"%s\"><type>%s</type></subject>"
12931 "</create_permission>",
12932 permission_resource_type, comment ? comment :
"", resource_id,
12933 subject_id, subject_type);
12939 && !
str_equal (permission_resource_type,
"result")
12940 && !
str_equal (permission_resource_type,
"report"))
12947 "<create_permission>"
12948 "<name>modify_%s</name>"
12949 "<comment>%s</comment>"
12950 "<resource id=\"%s\">"
12952 "<subject id=\"%s\"><type>%s</type></subject>"
12953 "</create_permission>",
12954 permission_resource_type, comment ? comment :
"", resource_id,
12955 subject_id, subject_type);
12959 if (
str_equal (permission_resource_type,
"task"))
12966 "<create_permission>"
12967 "<name>start_%s</name>"
12968 "<comment>%s</comment>"
12969 "<resource id=\"%s\">"
12971 "<subject id=\"%s\"><type>%s</type></subject>"
12972 "</create_permission>",
12973 permission_resource_type, comment ? comment :
"",
12974 resource_id, subject_id, subject_type);
12982 "<create_permission>"
12983 "<name>stop_%s</name>"
12984 "<comment>%s</comment>"
12985 "<resource id=\"%s\">"
12987 "<subject id=\"%s\"><type>%s</type></subject>"
12988 "</create_permission>",
12989 permission_resource_type, comment ? comment :
"",
12990 resource_id, subject_id, subject_type);
12998 "<create_permission>"
12999 "<name>resume_%s</name>"
13000 "<comment>%s</comment>"
13001 "<resource id=\"%s\">"
13003 "<subject id=\"%s\"><type>%s</type></subject>"
13004 "</create_permission>",
13005 permission_resource_type, comment ? comment :
"",
13006 resource_id, subject_id, subject_type);
13011 if (
str_equal (permission_resource_type,
"alert"))
13018 "<create_permission>"
13019 "<name>test_%s</name>"
13020 "<comment>%s</comment>"
13021 "<resource id=\"%s\">"
13023 "<subject id=\"%s\"><type>%s</type></subject>"
13024 "</create_permission>",
13025 permission_resource_type, comment ? comment :
"",
13026 resource_id, subject_id, subject_type);
13031 if (
str_equal (permission_resource_type,
"agent")
13032 ||
str_equal (permission_resource_type,
"report_format")
13033 ||
str_equal (permission_resource_type,
"scanner"))
13040 "<create_permission>"
13041 "<name>verify_%s</name>"
13042 "<comment>%s</comment>"
13043 "<resource id=\"%s\">"
13045 "<subject id=\"%s\"><type>%s</type></subject>"
13046 "</create_permission>",
13047 permission_resource_type, comment ? comment :
"",
13048 resource_id, subject_id, subject_type);
13069 char *related_id = name;
13070 char *related_type;
13075 related_type =
"asset";
13080 if (
str_equal (permission,
"read") == 0
13081 ||
str_equal (permission,
"write") == 0)
13087 "<create_permission>"
13088 "<name>get_%ss</name>"
13089 "<comment>%s</comment>"
13090 "<resource id=\"%s\">"
13092 "<subject id=\"%s\"><type>%s</type></subject>"
13093 "</create_permission>",
13094 related_type, comment ? comment :
"", related_id,
13095 subject_id, subject_type);
13102 && !
str_equal (related_type,
"report"))
13108 "<create_permission>"
13109 "<name>modify_%s</name>"
13110 "<comment>%s</comment>"
13111 "<resource id=\"%s\">"
13113 "<subject id=\"%s\"><type>%s</type></subject>"
13114 "</create_permission>",
13115 related_type, comment ? comment :
"", related_id,
13116 subject_id, subject_type);
13126 "<create_permission>"
13127 "<name>start_%s</name>"
13128 "<comment>%s</comment>"
13129 "<resource id=\"%s\">"
13131 "<subject id=\"%s\"><type>%s</type></subject>"
13132 "</create_permission>",
13133 related_type, comment ? comment :
"",
13134 related_id, subject_id, subject_type);
13142 "<create_permission>"
13143 "<name>stop_%s</name>"
13144 "<comment>%s</comment>"
13145 "<resource id=\"%s\">"
13147 "<subject id=\"%s\"><type>%s</type></subject>"
13148 "</create_permission>",
13149 related_type, comment ? comment :
"",
13150 related_id, subject_id, subject_type);
13158 "<create_permission>"
13159 "<name>resume_%s</name>"
13160 "<comment>%s</comment>"
13161 "<resource id=\"%s\">"
13163 "<subject id=\"%s\"><type>%s</type></subject>"
13164 "</create_permission>",
13165 related_type, comment ? comment :
"",
13166 related_id, subject_id, subject_type);
13177 "<create_permission>"
13178 "<name>test_%s</name>"
13179 "<comment>%s</comment>"
13180 "<resource id=\"%s\">"
13182 "<subject id=\"%s\"><type>%s</type></subject>"
13183 "</create_permission>",
13184 related_type, comment ? comment :
"",
13185 related_id, subject_id, subject_type);
13191 ||
str_equal (related_type,
"report_format")
13192 ||
str_equal (related_type,
"scanner"))
13198 "<create_permission>"
13199 "<name>verify_%s</name>"
13200 "<comment>%s</comment>"
13201 "<resource id=\"%s\">"
13203 "<subject id=\"%s\"><type>%s</type></subject>"
13204 "</create_permission>",
13205 related_type, comment ? comment :
"",
13206 related_id, subject_id, subject_type);
13216 g_strdup_printf (
"Successfully created %i permissions", successes);
13219 "Create Permissions", summary_response, NULL, NULL);
13223 #undef CHECK_GMPF_RET
13277 gchar *html, *response;
13278 const char *permission_id, *name, *comment, *resource_id, *resource_type;
13279 const char *subject_id, *subject_type;
13283 permission_id =
params_value (params,
"permission_id");
13288 resource_type =
params_value (params,
"optional_resource_type");
13298 if (strcmp (subject_type,
"user") == 0)
13300 else if (strcmp (subject_type,
"group") == 0)
13302 else if (strcmp (subject_type,
"role") == 0)
13312 ret =
gmpf (connection,
credentials, &response, &entity, response_data,
13313 "<modify_permission permission_id=\"%s\">"
13315 "<comment>%s</comment>"
13316 "<subject id=\"%s\">"
13319 "<resource id=\"%s\">"
13322 "</modify_permission>",
13323 permission_id, name, comment, subject_id, subject_type,
13324 (resource_id && strlen (resource_id)) ? resource_id :
"0",
13325 resource_type ? resource_type :
"");
13333 MHD_HTTP_INTERNAL_SERVER_ERROR);
13335 credentials,
"Internal error", __FUNCTION__, __LINE__,
13336 "An internal error occurred while modifying a permission. "
13337 "The permission was not modified. "
13338 "Diagnostics: Failure to send command to manager daemon.",
13342 MHD_HTTP_INTERNAL_SERVER_ERROR);
13344 credentials,
"Internal error", __FUNCTION__, __LINE__,
13345 "An internal error occurred while modifying a permission. "
13346 "It is unclear whether the permission has been modified or not. "
13347 "Diagnostics: Failure to receive response from manager daemon.",
13351 MHD_HTTP_INTERNAL_SERVER_ERROR);
13353 credentials,
"Internal error", __FUNCTION__, __LINE__,
13354 "An internal error occurred while modifying a permission. "
13355 "It is unclear whether the permission has been modified or not. "
13356 "Diagnostics: Internal Error.",
13361 "Save Permission", response_data);
13362 free_entity (entity);
13383 gchar *html, *response;
13384 const char *name, *comment, *port_range, *from_file;
13400 connection,
credentials, &response, &entity, response_data,
13401 "<create_port_list>"
13403 "<port_range>%s</port_range>"
13404 "<comment>%s</comment>"
13405 "</create_port_list>",
13406 name, strcmp (from_file,
"0") ?
params_value (params,
"file") : port_range,
13407 comment ? comment :
""))
13414 MHD_HTTP_INTERNAL_SERVER_ERROR);
13416 credentials,
"Internal error", __FUNCTION__, __LINE__,
13417 "An internal error occurred while creating a new port list. "
13418 "No new port list was created. "
13419 "Diagnostics: Failure to send command to manager daemon.",
13423 MHD_HTTP_INTERNAL_SERVER_ERROR);
13425 credentials,
"Internal error", __FUNCTION__, __LINE__,
13426 "An internal error occurred while creating a new port list. "
13427 "It is unclear whether the port list has been created or not. "
13428 "Diagnostics: Failure to receive response from manager daemon.",
13432 MHD_HTTP_INTERNAL_SERVER_ERROR);
13434 credentials,
"Internal error", __FUNCTION__, __LINE__,
13435 "An internal error occurred while creating a new port list. "
13436 "It is unclear whether the port list has been created or not. "
13437 "Diagnostics: Internal Error.",
13441 if (entity_attribute (entity,
"id"))
13442 params_add (params,
"port_list_id", entity_attribute (entity,
"id"));
13444 "Create Port List", response_data);
13445 free_entity (entity);
13465 gchar *html, *response;
13466 const char *port_list_id, *start, *end, *type;
13483 ret =
gmpf (connection,
credentials, &response, &entity, response_data,
13484 "<create_port_range>"
13485 "<port_list id=\"%s\"/>"
13486 "<start>%s</start>"
13489 "</create_port_range>",
13490 port_list_id, start, end, type);
13499 MHD_HTTP_INTERNAL_SERVER_ERROR);
13501 credentials,
"Internal error", __FUNCTION__, __LINE__,
13502 "An internal error occurred while creating a Port Range. "
13503 "The Port Range was not created. "
13504 "Diagnostics: Failure to send command to manager daemon.",
13508 MHD_HTTP_INTERNAL_SERVER_ERROR);
13510 credentials,
"Internal error", __FUNCTION__, __LINE__,
13511 "An internal error occurred while creating a Port Range. "
13512 "It is unclear whether the Port Range has been created or not. "
13513 "Diagnostics: Failure to receive response from manager daemon.",
13517 MHD_HTTP_INTERNAL_SERVER_ERROR);
13519 credentials,
"Internal error", __FUNCTION__, __LINE__,
13520 "An internal error occurred while creating a Port Range. "
13521 "It is unclear whether the Port Range has been created or not. "
13522 "Diagnostics: Internal Error.",
13527 "Create Port Range", response_data);
13528 free_entity (entity);
13546 params_t *params,
const char *extra_xml,
13556 arguments, response_data);
13609 gchar *html, *response;
13610 const char *port_list_id, *name, *comment;
13625 ret =
gmpf (connection,
credentials, &response, &entity, response_data,
13626 "<modify_port_list port_list_id=\"%s\">"
13628 "<comment>%s</comment>"
13629 "</modify_port_list>",
13630 port_list_id, name, comment);
13639 MHD_HTTP_INTERNAL_SERVER_ERROR);
13641 credentials,
"Internal error", __FUNCTION__, __LINE__,
13642 "An internal error occurred while saving a Port List. "
13643 "The Port List was not saved. "
13644 "Diagnostics: Failure to send command to manager daemon.",
13648 MHD_HTTP_INTERNAL_SERVER_ERROR);
13650 credentials,
"Internal error", __FUNCTION__, __LINE__,
13651 "An internal error occurred while saving a Port List. "
13652 "It is unclear whether the Port List has been saved or not. "
13653 "Diagnostics: Failure to receive response from manager daemon.",
13657 MHD_HTTP_INTERNAL_SERVER_ERROR);
13659 credentials,
"Internal error", __FUNCTION__, __LINE__,
13660 "An internal error occurred while saving a Port List. "
13661 "It is unclear whether the Port List has been saved or not. "
13662 "Diagnostics: Internal Error.",
13667 "Save Port List", response_data);
13668 free_entity (entity);
13723 gchar *command, *html, *response;
13731 command = g_strdup_printf (
"<create_port_list>"
13733 "</create_port_list>",
13736 gmp (connection,
credentials, &response, &entity, response_data, command);
13745 MHD_HTTP_INTERNAL_SERVER_ERROR);
13747 credentials,
"Internal error", __FUNCTION__, __LINE__,
13748 "An internal error occurred while importing a port_list. "
13749 "The schedule remains the same. "
13750 "Diagnostics: Failure to send command to manager daemon.",
13754 MHD_HTTP_INTERNAL_SERVER_ERROR);
13756 credentials,
"Internal error", __FUNCTION__, __LINE__,
13757 "An internal error occurred while importing a port_list. "
13758 "It is unclear whether the schedule has been saved or not. "
13759 "Diagnostics: Failure to receive response from manager daemon.",
13763 MHD_HTTP_INTERNAL_SERVER_ERROR);
13765 credentials,
"Internal error", __FUNCTION__, __LINE__,
13766 "An internal error occurred while importing a port_list. "
13767 "It is unclear whether the schedule has been saved or not. "
13768 "Diagnostics: Internal Error.",
13775 "Import Port List", response_data);
13776 free_entity (entity);
13817 const char *name, *comment, *
users;
13830 switch (
gmpf (connection,
credentials, &response, &entity, response_data,
13833 "<comment>%s</comment>"
13834 "<users>%s</users>"
13836 name, comment,
users))
13843 MHD_HTTP_INTERNAL_SERVER_ERROR);
13845 credentials,
"Internal error", __FUNCTION__, __LINE__,
13846 "An internal error occurred while creating a new role. "
13847 "No new role was created. "
13848 "Diagnostics: Failure to send command to manager daemon.",
13852 MHD_HTTP_INTERNAL_SERVER_ERROR);
13854 credentials,
"Internal error", __FUNCTION__, __LINE__,
13855 "An internal error occurred while creating a new role. "
13856 "It is unclear whether the role has been created or not. "
13857 "Diagnostics: Failure to receive response from manager daemon.",
13861 MHD_HTTP_INTERNAL_SERVER_ERROR);
13863 credentials,
"Internal error", __FUNCTION__, __LINE__,
13864 "An internal error occurred while creating a new role. "
13865 "It is unclear whether the role has been created or not. "
13866 "Diagnostics: Internal Error.",
13870 if (entity_attribute (entity,
"id"))
13871 params_add (params,
"role_id", entity_attribute (entity,
"id"));
13873 "Create Role", response_data);
13874 free_entity (entity);
13892 params_t *params,
const char *extra_xml,
13985 gchar *html, *response;
13986 const char *role_id, *name, *comment, *
users;
14003 ret =
gmpf (connection,
credentials, &response, &entity, response_data,
14004 "<modify_role role_id=\"%s\">"
14006 "<comment>%s</comment>"
14007 "<users>%s</users>"
14009 role_id, name, comment,
users);
14018 MHD_HTTP_INTERNAL_SERVER_ERROR);
14020 credentials,
"Internal error", __FUNCTION__, __LINE__,
14021 "An internal error occurred while saving a role. "
14022 "The role was not saved. "
14023 "Diagnostics: Failure to send command to manager daemon.",
14027 MHD_HTTP_INTERNAL_SERVER_ERROR);
14029 credentials,
"Internal error", __FUNCTION__, __LINE__,
14030 "An internal error occurred while saving a role. "
14031 "It is unclear whether the role has been saved or not. "
14032 "Diagnostics: Failure to receive response from manager daemon.",
14036 MHD_HTTP_INTERNAL_SERVER_ERROR);
14038 credentials,
"Internal error", __FUNCTION__, __LINE__,
14039 "An internal error occurred while saving a role. "
14040 "It is unclear whether the role has been saved or not. "
14041 "Diagnostics: Internal Error.",
14046 "Save Role", response_data);
14047 free_entity (entity);
14073 gchar current_timestamp[30];
14075 if (gvm_connection_sendf (connection,
"<get_feeds/>") == -1)
14078 MHD_HTTP_INTERNAL_SERVER_ERROR);
14080 credentials,
"Internal error", __FUNCTION__, __LINE__,
14081 "An internal error occurred while getting the feed list. "
14082 "The current list of feeds is not available. "
14083 "Diagnostics: Failure to send command to manager daemon.",
14087 if (read_entity_and_text_c (connection, &entity, &text))
14090 MHD_HTTP_INTERNAL_SERVER_ERROR);
14092 credentials,
"Internal error", __FUNCTION__, __LINE__,
14093 "An internal error occurred while getting the feed. "
14094 "The current list of feeds is not available. "
14095 "Diagnostics: Failure to receive response from manager daemon.",
14100 tm = gmtime (&now);
14102 || (strftime (current_timestamp, 29,
"%Y-%m-%dT%H:%M:%S", tm) == 0))
14104 current_timestamp[0] =
'\0';
14107 response = g_strdup_printf (
"<get_feeds>"
14109 "<current_time_utc>%s</current_time_utc>"
14111 text, current_timestamp);
14134 params_t *params,
const char *sync_cmd,
const char *action,
14141 if (gvm_connection_sendf (connection,
"<%s/>", sync_cmd) == -1)
14144 MHD_HTTP_INTERNAL_SERVER_ERROR);
14146 msg = g_strdup_printf (
14147 "An internal error occurred while synchronizing with %s. "
14148 "Feed synchronization is currently not available. "
14149 "Diagnostics: Failure to send command to manager daemon.",
14152 __LINE__, msg, response_data);
14157 if (read_entity_and_text_c (connection, &entity, &text))
14160 MHD_HTTP_INTERNAL_SERVER_ERROR);
14162 msg = g_strdup_printf (
14163 "An internal error occurred while synchronizing with %s. "
14164 "Feed synchronization is currently not available. "
14165 "Diagnostics: Failure to receive response from manager daemon.",
14168 __LINE__, msg, response_data);
14194 "Synchronize Feed",
"the NVT feed", response_data);
14212 "Synchronize Feed",
"the SCAP feed", response_data);
14230 "Synchronize CERT Feed",
"the CERT feed", response_data);
14248 params_t *params,
const char *extra_xml,
14257 arguments, response_data);
14309 gchar *html, *response;
14310 const char *name, *comment, *term, *type;
14323 switch (
gmpf (connection,
credentials, &response, &entity, response_data,
14326 "<comment>%s</comment>"
14329 "</create_filter>",
14330 name, comment, term, type))
14337 MHD_HTTP_INTERNAL_SERVER_ERROR);
14339 credentials,
"Internal error", __FUNCTION__, __LINE__,
14340 "An internal error occurred while creating a new alert. "
14341 "No new alert was created. "
14342 "Diagnostics: Failure to send command to manager daemon.",
14346 MHD_HTTP_INTERNAL_SERVER_ERROR);
14348 credentials,
"Internal error", __FUNCTION__, __LINE__,
14349 "An internal error occurred while creating a new alert. "
14350 "It is unclear whether the alert has been created or not. "
14351 "Diagnostics: Failure to receive response from manager daemon.",
14355 MHD_HTTP_INTERNAL_SERVER_ERROR);
14357 credentials,
"Internal error", __FUNCTION__, __LINE__,
14358 "An internal error occurred while creating a new alert. "
14359 "It is unclear whether the alert has been created or not. "
14360 "Diagnostics: Internal Error.",
14365 "Create Filter", response_data);
14366 free_entity (entity);
14440 gchar *html, *response;
14441 const char *filter_id, *name, *comment, *term, *type;
14460 ret = gvm_connection_sendf_xml (connection,
14461 "<modify_filter filter_id=\"%s\">"
14463 "<comment>%s</comment>"
14466 "</modify_filter>",
14467 filter_id, name, comment, term, type);
14472 MHD_HTTP_INTERNAL_SERVER_ERROR);
14474 credentials,
"Internal error", __FUNCTION__, __LINE__,
14475 "An internal error occurred while modifying a filter. "
14476 "The filter was not modified. "
14477 "Diagnostics: Failure to send command to manager daemon.",
14482 if (read_entity_and_text_c (connection, &entity, &response))
14485 MHD_HTTP_INTERNAL_SERVER_ERROR);
14487 credentials,
"Internal error", __FUNCTION__, __LINE__,
14488 "An internal error occurred while modifying a filter. "
14489 "It is unclear whether the filter has been modified or not. "
14490 "Diagnostics: Failure to receive response from manager daemon.",
14498 "Save Filter", response_data);
14500 free_entity (entity);
14559 const char *schedule_id, *name, *comment, *timezone, *icalendar;
14576 switch (
gmpf (connection,
credentials, &response, &entity, response_data,
14577 "<modify_schedule schedule_id=\"%s\">"
14579 "<comment>%s</comment>"
14580 "<timezone>%s</timezone>"
14581 "<icalendar>%s</icalendar>"
14582 "</modify_schedule>",
14583 schedule_id, name ? name :
"", comment ? comment :
"", timezone,
14591 MHD_HTTP_INTERNAL_SERVER_ERROR);
14593 credentials,
"Internal error", __FUNCTION__, __LINE__,
14594 "An internal error occurred while saving a schedule. "
14595 "The schedule remains the same. "
14596 "Diagnostics: Failure to send command to manager daemon.",
14600 MHD_HTTP_INTERNAL_SERVER_ERROR);
14602 credentials,
"Internal error", __FUNCTION__, __LINE__,
14603 "An internal error occurred while saving a schedule. "
14604 "It is unclear whether the schedule has been saved or not. "
14605 "Diagnostics: Failure to receive response from manager daemon.",
14609 MHD_HTTP_INTERNAL_SERVER_ERROR);
14611 credentials,
"Internal error", __FUNCTION__, __LINE__,
14612 "An internal error occurred while saving a schedule. "
14613 "It is unclear whether the schedule has been saved or not. "
14614 "Diagnostics: Internal Error.",
14619 "Save Schedule", response_data);
14620 free_entity (entity);
14658 params_t *params,
const char *extra_xml,
14664 extra = g_string_new (
"");
14666 g_string_append (extra, extra_xml);
14674 switch (
gmp (connection,
credentials, &response, &entity, response_data,
14675 "<describe_auth/>"))
14682 MHD_HTTP_INTERNAL_SERVER_ERROR);
14684 credentials,
"Internal error", __FUNCTION__, __LINE__,
14685 "An internal error occurred getting the auth list. "
14686 "Diagnostics: Failure to send command to manager daemon.",
14690 MHD_HTTP_INTERNAL_SERVER_ERROR);
14692 credentials,
"Internal error", __FUNCTION__, __LINE__,
14693 "An internal error occurred getting the auth list. "
14694 "Diagnostics: Failure to receive response from manager daemon.",
14698 MHD_HTTP_INTERNAL_SERVER_ERROR);
14700 credentials,
"Internal error", __FUNCTION__, __LINE__,
14701 "An internal error occurred getting the auth list. "
14702 "Diagnostics: Internal Error.",
14706 g_string_append (extra, response);
14708 free_entity (entity);
14713 g_string_free (extra, TRUE);
14766 const char *name, *password, *hosts, *hosts_allow, *ifaces, *ifaces_allow;
14767 const char *auth_method, *comment;
14770 GString *group_elements, *role_elements, *string;
14771 gchar *buf, *response, *html;
14789 if (auth_method && strcmp (auth_method,
"1") == 0)
14801 string = g_string_new (
"<create_user>");
14802 buf = g_markup_printf_escaped (
"<name>%s</name>"
14803 "<password>%s</password>",
14804 name, password ? password :
"");
14806 g_string_append (
string, buf);
14809 group_elements = g_string_new (
"<groups>");
14825 g_string_append_printf (group_elements,
"<group id=\"%s\"/>",
14829 g_string_append (
string, group_elements->str);
14830 g_string_free (group_elements, TRUE);
14831 g_string_append (
string,
"</groups>");
14833 role_elements = g_string_new (
"");
14849 g_string_append_printf (role_elements,
"<role id=\"%s\"/>",
14853 g_string_append (
string, role_elements->str);
14854 g_string_free (role_elements, TRUE);
14856 buf = g_markup_printf_escaped (
"<hosts allow=\"%s\">%s</hosts>"
14857 "<ifaces allow=\"%s\">%s</ifaces>",
14858 hosts_allow, hosts, ifaces_allow, ifaces);
14859 g_string_append (
string, buf);
14861 if (auth_method && !strcmp (auth_method,
"1"))
14862 g_string_append (
string,
14863 "<sources><source>ldap_connect</source></sources>");
14864 else if (auth_method && !strcmp (auth_method,
"2"))
14865 g_string_append (
string,
14866 "<sources><source>radius_connect</source></sources>");
14870 xml_string_append (
string,
"<comment>%s</comment>", comment);
14873 g_string_append (
string,
"</create_user>");
14875 buf = g_string_free (
string, FALSE);
14879 ret =
gmp (connection,
credentials, &response, &entity, response_data, buf);
14888 MHD_HTTP_INTERNAL_SERVER_ERROR);
14890 credentials,
"Internal error", __FUNCTION__, __LINE__,
14891 "An internal error occurred while creating a new user. "
14892 "No new user was created. "
14893 "Diagnostics: Failure to send command to manager daemon.",
14897 MHD_HTTP_INTERNAL_SERVER_ERROR);
14899 credentials,
"Internal error", __FUNCTION__, __LINE__,
14900 "An internal error occurred while creating a new user. "
14901 "It is unclear whether the user has been created or not. "
14902 "Diagnostics: Failure to receive response from manager daemon.",
14906 MHD_HTTP_INTERNAL_SERVER_ERROR);
14908 credentials,
"Internal error", __FUNCTION__, __LINE__,
14909 "An internal error occurred while creating a new user. "
14910 "It is unclear whether the user has been created or not. "
14911 "Diagnostics: Internal Error.",
14915 if (entity_attribute (entity,
"id"))
14916 params_add (params,
"user_id", entity_attribute (entity,
"id"));
14918 "Create User", response_data);
14919 free_entity (entity);
14954 xml = g_string_new (
"");
14955 buf = g_markup_printf_escaped (
"<auth_settings name=\"%s\">", name);
14956 g_string_append (xml, buf);
14961 gchar *response = NULL;
14962 entity_t entity = NULL;
14964 switch (
gmp (connection,
credentials, &response, &entity, response_data,
14965 "<describe_auth/>"))
14972 MHD_HTTP_INTERNAL_SERVER_ERROR);
14974 credentials,
"Internal error", __FUNCTION__, __LINE__,
14975 "An internal error occurred getting the auth list. "
14976 "Diagnostics: Failure to send command to manager daemon.",
14980 MHD_HTTP_INTERNAL_SERVER_ERROR);
14982 credentials,
"Internal error", __FUNCTION__, __LINE__,
14983 "An internal error occurred getting the auth list. "
14984 "Diagnostics: Failure to receive response from manager daemon.",
14988 MHD_HTTP_INTERNAL_SERVER_ERROR);
14990 credentials,
"Internal error", __FUNCTION__, __LINE__,
14991 "An internal error occurred getting the auth list. "
14992 "Diagnostics: Internal Error.",
14996 g_string_append (xml, response);
14997 free_entity (entity);
15001 g_string_append (xml,
"</auth_settings>");
15004 g_string_free (xml, FALSE), response_data);
15022 gchar *html, *response, *buf;
15023 const char *user_id, *
login, *old_login, *modify_password, *password;
15024 const char *hosts, *hosts_allow, *ifaces, *ifaces_allow, *comment;
15026 GString *command, *group_elements, *role_elements;
15038 modify_password =
params_value (params,
"modify_password");
15052 if (modify_password &&
str_equal (modify_password,
"1"))
15065 command = g_string_new (
"");
15066 buf = g_markup_printf_escaped (
"<modify_user user_id=\"%s\">"
15067 "<password modify=\"%s\">"
15069 user_id, modify_password,
15070 password ? password :
"");
15071 g_string_append (command, buf);
15076 buf = g_markup_printf_escaped (
"<new_name>%s</new_name>",
login);
15077 g_string_append (command, buf);
15081 buf = g_markup_printf_escaped (
"<hosts allow=\"%s\">%s</hosts>"
15082 "<ifaces allow=\"%s\">%s</ifaces>",
15083 hosts_allow, hosts, ifaces_allow, ifaces);
15084 g_string_append (command, buf);
15087 if (modify_password && !strcmp (modify_password,
"2"))
15088 g_string_append (command,
15089 "<sources><source>ldap_connect</source></sources>");
15090 else if (modify_password && !strcmp (modify_password,
"3"))
15091 g_string_append (command,
15092 "<sources><source>radius_connect</source></sources>");
15094 g_string_append (command,
"<sources><source>file</source></sources>");
15096 group_elements = g_string_new (
"<groups>");
15112 g_string_append_printf (group_elements,
"<group id=\"%s\"/>",
15116 g_string_append (command, group_elements->str);
15117 g_string_free (group_elements, TRUE);
15118 g_string_append (command,
"</groups>");
15120 role_elements = g_string_new (
"");
15136 g_string_append_printf (role_elements,
"<role id=\"%s\"/>",
15141 g_string_append_printf (role_elements,
"<role id=\"0\"/>");
15143 g_string_append (command, role_elements->str);
15144 g_string_free (role_elements, TRUE);
15148 xml_string_append (command,
"<comment>%s</comment>", comment);
15151 g_string_append (command,
"</modify_user>");
15155 ret =
gmp (connection,
credentials, &response, &entity, response_data,
15157 g_string_free (command, TRUE);
15195 MHD_HTTP_INTERNAL_SERVER_ERROR);
15197 credentials,
"Internal error", __FUNCTION__, __LINE__,
15198 "An internal error occurred while saving a user. "
15199 "The user was not saved. "
15200 "Diagnostics: Failure to send command to manager daemon.",
15204 MHD_HTTP_INTERNAL_SERVER_ERROR);
15206 credentials,
"Internal error", __FUNCTION__, __LINE__,
15207 "An internal error occurred while saving a user. "
15208 "It is unclear whether the user has been saved or not. "
15209 "Diagnostics: Failure to receive response from manager daemon.",
15213 MHD_HTTP_INTERNAL_SERVER_ERROR);
15215 credentials,
"Internal error", __FUNCTION__, __LINE__,
15216 "An internal error occurred while saving a user. "
15217 "It is unclear whether the user has been saved or not. "
15218 "Diagnostics: Internal Error.",
15226 free_entity (entity);
15231 credentials,
"Authentication Required", __FUNCTION__, __LINE__,
15232 "Authentication method changed. Please login with ", response_data);
15236 "Save User", response_data);
15237 free_entity (entity);
15283 const char *cvss_av, *cvss_au, *cvss_ac, *cvss_c, *cvss_i, *cvss_a;
15284 const char *cvss_vector, *name;
15295 xml = g_string_new (
"<cvss_calculator>");
15298 if (cvss_av && cvss_au && cvss_ac && cvss_c && cvss_i && cvss_a)
15301 g_strdup_printf (
"AV:%c/AC:%c/Au:%c/C:%c/I:%c/A:%c", *cvss_av, *cvss_ac,
15302 *cvss_au, *cvss_c, *cvss_i, *cvss_a);
15304 g_string_append_printf (xml,
15305 "<cvss_vector>%s</cvss_vector>"
15306 "<cvss_score>%.1f</cvss_score>",
15308 get_cvss_score_from_base_metrics (vector));
15310 g_string_append_printf (xml,
15311 "<cvss_av>%c</cvss_av><cvss_au>%c</cvss_au>"
15312 "<cvss_ac>%c</cvss_ac><cvss_c>%c</cvss_c>"
15313 "<cvss_i>%c</cvss_i><cvss_a>%c</cvss_a>",
15314 *cvss_av, *cvss_au, *cvss_ac, *cvss_c, *cvss_i,
15319 else if (cvss_vector)
15321 double cvss_score = get_cvss_score_from_base_metrics (cvss_vector);
15323 g_string_append_printf (xml,
15324 "<cvss_vector>%s</cvss_vector>"
15325 "<cvss_score>%.1f</cvss_score>",
15326 cvss_vector, cvss_score);
15328 if (cvss_score != -1.0)
15330 cvss_av = strstr (cvss_vector,
"AV:");
15331 cvss_ac = strstr (cvss_vector,
"/AC:");
15332 cvss_au = strstr (cvss_vector,
"/Au:");
15333 if (cvss_au == NULL)
15334 cvss_au = strstr (cvss_vector,
"/AU:");
15335 cvss_c = strstr (cvss_vector,
"/C:");
15336 cvss_i = strstr (cvss_vector,
"/I:");
15337 cvss_a = strstr (cvss_vector,
"/A:");
15339 if (cvss_av && cvss_ac && cvss_au && cvss_c && cvss_i && cvss_a)
15340 g_string_append_printf (xml,
15341 "<cvss_av>%c</cvss_av><cvss_ac>%c</cvss_ac>"
15342 "<cvss_au>%c</cvss_au><cvss_c>%c</cvss_c>"
15343 "<cvss_i>%c</cvss_i><cvss_a>%c</cvss_a>",
15344 *(cvss_av + 3), *(cvss_ac + 4),
15345 *(cvss_au + 4), *(cvss_c + 3),
15346 *(cvss_i + 3), *(cvss_a + 3));
15349 else if (name && !strcmp (
"vector", name))
15351 g_string_append_printf (xml,
"<cvss_score>%.1f</cvss_score>", -1.0);
15354 g_string_append (xml,
"</cvss_calculator>");
15356 g_string_free (xml, FALSE), response_data);
15362 #define AUTH_CONF_SETTING(key, value) \
15363 "<auth_conf_setting>" \
15364 "<key>" key "</key>" \
15365 "<value>" value "</value>" \
15366 "</auth_conf_setting>"
15383 entity_t entity = NULL;
15384 char *html, *response = NULL, *truefalse;
15385 const char *method;
15388 && (strcmp (
params_value (params,
"enable"),
"1") == 0))
15389 truefalse =
"true";
15391 truefalse =
"false";
15395 if (!strcmp (method,
"method:ldap_connect"))
15397 const char *ldaphost, *authdn, *certificate;
15404 if (
params_given (params,
"certificate") && strcmp (certificate,
""))
15416 method, truefalse, ldaphost, authdn, certificate);
15420 ret =
gmpf (connection,
credentials, &response, &entity, response_data,
15426 method, truefalse, ldaphost, authdn);
15428 else if (!strcmp (method,
"method:radius_connect"))
15430 const char *radiushost, *radiuskey;
15437 ret =
gmpf (connection,
credentials, &response, &entity, response_data,
15443 method, truefalse, radiushost, radiuskey);
15448 "Given method was invalid",
"Save auth");
15458 MHD_HTTP_INTERNAL_SERVER_ERROR);
15460 credentials,
"Internal error", __FUNCTION__, __LINE__,
15461 "An internal error occurred while saving the auth settings. "
15462 "The settings were not saved. "
15463 "Diagnostics: Failure to send command to manager daemon.",
15467 MHD_HTTP_INTERNAL_SERVER_ERROR);
15469 credentials,
"Internal error", __FUNCTION__, __LINE__,
15470 "An internal error occurred while saving the auth settings. "
15471 "It is unclear whether the settings have been saved or not. "
15472 "Diagnostics: Failure to receive response from manager daemon.",
15476 MHD_HTTP_INTERNAL_SERVER_ERROR);
15478 credentials,
"Internal error", __FUNCTION__, __LINE__,
15479 "An internal error occurred while saving the auth settings. "
15480 "It is unclear whether the settings have been saved or not. "
15481 "Diagnostics: Internal Error.",
15487 "Save Authentication Configuration", response_data);
15488 free_entity (entity);
15509 const gchar *filter;
15511 xml = g_string_new (
"<get_settings>");
15518 command = g_markup_printf_escaped (
"<get_settings"
15520 " sort_field=\"name\""
15521 " sort_order=\"ascending\"/>",
15526 command = g_strdup (
"<get_settings"
15527 " sort_field=\"name\""
15528 " sort_order=\"ascending\"/>");
15531 if (gvm_connection_sendf (connection, command))
15535 g_string_free (xml, TRUE);
15537 MHD_HTTP_INTERNAL_SERVER_ERROR);
15539 credentials,
"Internal error", __FUNCTION__, __LINE__,
15540 "An internal error occurred while getting the settings. "
15541 "The current list of settings is not available. "
15542 "Diagnostics: Failure to send command to manager daemon.",
15546 if (read_string_c (connection, &xml))
15549 g_string_free (xml, TRUE);
15551 MHD_HTTP_INTERNAL_SERVER_ERROR);
15553 credentials,
"Internal error", __FUNCTION__, __LINE__,
15554 "An internal error occurred while getting the settings. "
15555 "The current list of settings is not available. "
15556 "Diagnostics: Failure to receive response from manager daemon.",
15561 g_string_append (xml,
"</get_settings>");
15563 g_string_free (xml, FALSE), response_data);
15580 const gchar *setting_id =
params_value (params,
"setting_id");
15581 const gchar *setting_value =
params_value (params,
"setting_value");
15582 const gchar *setting_name = NULL;
15594 g_base64_encode ((guchar *) setting_value, strlen (setting_value));
15596 gchar *response = NULL;
15597 entity_t entity = NULL;
15599 GString *xml = g_string_new (
"");
15601 xml_string_append (xml,
15602 "<modify_setting setting_id=\"%s\">"
15603 "<value>%s</value>",
15604 setting_id, value_64);
15608 xml_string_append (xml,
"<name>%s</name>", setting_name);
15611 xml_string_append (xml,
"</modify_setting>");
15616 gmp (connection,
credentials, &response, &entity, response_data, xml->str);
15619 g_string_free (xml, TRUE);
15628 MHD_HTTP_INTERNAL_SERVER_ERROR);
15630 credentials,
"Internal error", __FUNCTION__, __LINE__,
15631 "An internal error occurred while saving settings. "
15632 "It is unclear whether all the settings were saved. "
15633 "Diagnostics: Failure to send command to manager daemon.",
15638 MHD_HTTP_INTERNAL_SERVER_ERROR);
15640 credentials,
"Internal error", __FUNCTION__, __LINE__,
15641 "An internal error occurred while saving settings. "
15642 "It is unclear whether all the settings were saved. "
15643 "Diagnostics: Failure to receive response from manager daemon.",
15648 MHD_HTTP_INTERNAL_SERVER_ERROR);
15651 "An internal error occurred while saving settings. "
15652 "It is unclear whether all the settings were saved. "
15653 "Diagnostics: Internal Error.",
15657 "Save Setting", response_data);
15658 free_entity (entity);
15667 const gchar *setting_id =
params_value (params,
"setting_id");
15669 GString *xml = g_string_new (
"<get_settings>");
15671 if (gvm_connection_sendf_xml (connection,
15673 " setting_id=\"%s\"/>",
15676 g_string_free (xml, TRUE);
15678 MHD_HTTP_INTERNAL_SERVER_ERROR);
15681 "An internal error occurred while getting the "
15682 "dashboard settings"
15683 "Diagnostics: Failure to send command to manager "
15688 if (read_string_c (connection, &xml))
15690 g_string_free (xml, TRUE);
15692 MHD_HTTP_INTERNAL_SERVER_ERROR);
15695 "An internal error occurred while getting the "
15696 "dashboard settings"
15697 "Diagnostics: Failure to receive response from "
15702 g_string_append (xml,
"</get_settings>");
15704 g_string_free (xml, FALSE), response_data);
15722 params_t *params,
const char *extra_xml,
15732 credentials,
"Internal error", __FUNCTION__, __LINE__,
15733 "An internal error occurred while getting the wizard. "
15734 "Given name was invalid",
15738 xml = g_string_new (
"");
15739 g_string_append_printf (xml,
"<wizard>%s<%s/>", extra_xml ? extra_xml :
"",
15743 if (gvm_connection_sendf_xml (connection,
15744 "<run_wizard read_only=\"1\">"
15746 "<mode>init</mode>"
15751 g_string_free (xml, TRUE);
15753 MHD_HTTP_INTERNAL_SERVER_ERROR);
15755 credentials,
"Internal error", __FUNCTION__, __LINE__,
15756 "An internal error occurred while getting the wizard. "
15757 "Diagnostics: Failure to send command to manager daemon.",
15761 if (read_string_c (connection, &xml))
15763 g_string_free (xml, TRUE);
15765 MHD_HTTP_INTERNAL_SERVER_ERROR);
15768 "An internal error occurred while getting the"
15770 "Diagnostics: Failure to receive response from"
15771 " manager daemon.",
15777 if (gvm_connection_sendf_xml (
15778 connection,
"<get_settings"
15779 " setting_id=\"20f3034c-e709-11e1-87e7-406186ea4fc5\"/>")
15782 g_string_free (xml, TRUE);
15784 MHD_HTTP_INTERNAL_SERVER_ERROR);
15786 credentials,
"Internal error", __FUNCTION__, __LINE__,
15787 "An internal error occurred while getting the wizard. "
15788 "Diagnostics: Failure to send command to manager daemon.",
15792 if (read_string_c (connection, &xml))
15794 g_string_free (xml, TRUE);
15796 MHD_HTTP_INTERNAL_SERVER_ERROR);
15798 credentials,
"Internal error", __FUNCTION__, __LINE__,
15799 "An internal error occurred while the wizard. "
15800 "Diagnostics: Failure to receive response from manager daemon.",
15806 g_string_append_printf (xml,
"</wizard>");
15808 g_string_free (xml, FALSE), response_data);
15841 params_t *params,
const char *extra_xml,
15848 gchar *param_name, *response;
15863 credentials,
"Internal error", __FUNCTION__, __LINE__,
15864 "An internal error occurred while trying to start a wizard. "
15865 "Diagnostics: Required parameter 'get_name' was NULL.",
15869 run = g_string_new (
"<run_wizard read_only=\"1\">");
15871 g_string_append_printf (run,
15881 xml_string_append (run,
15884 "<value>%s</value>"
15889 g_string_append (run,
"</params></run_wizard>");
15894 gmp (connection,
credentials, &response, &entity, response_data, run->str);
15895 g_string_free (run, TRUE);
15903 MHD_HTTP_INTERNAL_SERVER_ERROR);
15905 credentials,
"Internal error", __FUNCTION__, __LINE__,
15906 "An internal error occurred while running a wizard. "
15907 "The wizard did not start. "
15908 "Diagnostics: Failure to send command to manager daemon.",
15912 MHD_HTTP_INTERNAL_SERVER_ERROR);
15914 credentials,
"Internal error", __FUNCTION__, __LINE__,
15915 "An internal error occurred while running a wizard. "
15916 "It is unclear whether the wizard started or not. "
15917 "Diagnostics: Failure to receive response from manager daemon.",
15921 MHD_HTTP_INTERNAL_SERVER_ERROR);
15924 "An internal error occurred while running a wizard. "
15925 "It is unclear whether the wizard started or not. "
15926 "Diagnostics: Internal Error.",
15930 wizard_xml = g_strdup_printf (
"<wizard><%s/>%s%s</wizard>", name,
15931 extra_xml ? extra_xml :
"", response);
15969 GString *commands_xml;
15974 gchar *html, *response;
15976 gchar *extra_attribs;
15983 credentials,
"Internal error", __FUNCTION__, __LINE__,
15984 "An internal error occurred while deleting resources. "
15985 "The resources were not deleted. "
15986 "Diagnostics: Required parameter 'resource_type' was NULL.",
15991 extra_attribs = NULL;
15994 if (strcmp (type,
"user") == 0)
15996 const char *inheritor_id;
15999 extra_attribs = g_strdup_printf (
"inheritor_id=\"%s\"", inheritor_id);
16002 commands_xml = g_string_new (
"<commands>");
16010 xml_string_append (commands_xml,
16011 "<delete_%s %s_id=\"%s\" ultimate=\"0\"", type,
16014 g_string_append_printf (commands_xml,
" %s/>", extra_attribs);
16016 g_string_append (commands_xml,
"/>");
16020 g_string_append (commands_xml,
"</commands>");
16024 if (gvm_connection_sendf_xml (connection, commands_xml->str) == -1)
16026 g_string_free (commands_xml, TRUE);
16028 MHD_HTTP_INTERNAL_SERVER_ERROR);
16030 credentials,
"Internal error", __FUNCTION__, __LINE__,
16031 "An internal error occurred while deleting resources. "
16032 "The resources were not deleted. "
16033 "Diagnostics: Failure to send command to manager daemon.",
16036 g_string_free (commands_xml, TRUE);
16039 if (read_entity_and_text_c (connection, &entity, &response))
16042 MHD_HTTP_INTERNAL_SERVER_ERROR);
16044 credentials,
"Internal error", __FUNCTION__, __LINE__,
16045 "An internal error occurred while deleting resources. "
16046 "It is unclear whether the resources have been deleted or not. "
16047 "Diagnostics: Failure to read response from manager daemon.",
16053 "Bulk Delete", response_data);
16055 free_entity (entity);
16074 const gchar *type, *filter, *bulk_select;
16076 GString *bulk_string;
16088 if (bulk_select &&
str_equal (bulk_select,
"1"))
16090 bulk_string = g_string_new (
"first=1 rows=-1 uuid=");
16098 xml_string_append (bulk_string,
" uuid=%s", param_name);
16104 bulk_string = g_string_new (filter ?:
"");
16107 params_add (params,
"filter", g_string_free (bulk_string, FALSE));
16129 gchar *html, *response;
16130 const char *name, *comment;
16142 xml = g_string_new (
"");
16144 xml_string_append (xml,
16147 "<type>host</type>"
16149 "<comment>%s</comment>"
16155 gmp (connection,
credentials, &response, &entity, response_data, xml->str);
16156 g_string_free (xml, TRUE);
16164 MHD_HTTP_INTERNAL_SERVER_ERROR);
16166 credentials,
"Internal error", __FUNCTION__, __LINE__,
16167 "An internal error occurred while creating a new host. "
16168 "No new host was created. "
16169 "Diagnostics: Failure to send command to manager daemon.",
16173 MHD_HTTP_INTERNAL_SERVER_ERROR);
16175 credentials,
"Internal error", __FUNCTION__, __LINE__,
16176 "An internal error occurred while creating a new host. "
16177 "It is unclear whether the host has been created or not. "
16178 "Diagnostics: Failure to receive response from manager daemon.",
16182 MHD_HTTP_INTERNAL_SERVER_ERROR);
16184 credentials,
"Internal error", __FUNCTION__, __LINE__,
16185 "An internal error occurred while creating a new host. "
16186 "It is unclear whether the host has been created or not. "
16187 "Diagnostics: Internal Error.",
16191 if (entity_attribute (entity,
"id"))
16192 params_add (params,
"asset_id", entity_attribute (entity,
"id"));
16194 "Create Host", response_data);
16195 free_entity (entity);
16213 params_t *params,
const char *extra_xml,
16216 const gchar *asset_type;
16228 "An internal error occurred while getting an asset. "
16229 "Diagnostics: Both ID and Name set.",
16280 const char *asset_type;
16316 const char *report_id, *filter;
16327 switch (
gmpf (connection,
credentials, &response, &entity, response_data,
16329 "<report id=\"%s\">"
16330 "<filter><term>%s</term></filter>"
16333 report_id, filter))
16340 MHD_HTTP_INTERNAL_SERVER_ERROR);
16342 credentials,
"Internal error", __FUNCTION__, __LINE__,
16343 "An internal error occurred while creating an asset. "
16344 "No new asset was created. "
16345 "Diagnostics: Failure to send command to manager daemon.",
16349 MHD_HTTP_INTERNAL_SERVER_ERROR);
16351 credentials,
"Internal error", __FUNCTION__, __LINE__,
16352 "An internal error occurred while creating an asset. "
16353 "It is unclear whether the asset has been created or not. "
16354 "Diagnostics: Failure to receive response from manager daemon.",
16358 MHD_HTTP_INTERNAL_SERVER_ERROR);
16360 credentials,
"Internal error", __FUNCTION__, __LINE__,
16361 "An internal error occurred while creating an asset. "
16362 "It is unclear whether the asset has been created or not. "
16363 "Diagnostics: Internal Error.",
16368 "Create Asset", response_data);
16369 free_entity (entity);
16388 gchar *html, *response, *resource_id;
16389 const char *next_id;
16393 resource_id = g_strdup (
params_value (params,
"asset_id"));
16395 resource_id = g_strdup (
params_value (params,
"report_id"));
16400 credentials,
"Internal error", __FUNCTION__, __LINE__,
16401 "An internal error occurred while deleting an asset. "
16402 "The asset was not deleted. "
16403 "Diagnostics: Required parameter was NULL.",
16421 if (gvm_connection_sendf (
16422 connection,
"<delete_asset %s_id=\"%s\"/>",
16423 params_value (params,
"asset_id") ?
"asset" :
"report", resource_id)
16426 g_free (resource_id);
16428 MHD_HTTP_INTERNAL_SERVER_ERROR);
16430 credentials,
"Internal error", __FUNCTION__, __LINE__,
16431 "An internal error occurred while deleting an asset. "
16432 "The asset is not deleted. "
16433 "Diagnostics: Failure to send command to manager daemon.",
16437 g_free (resource_id);
16440 if (read_entity_and_text_c (connection, &entity, &response))
16443 MHD_HTTP_INTERNAL_SERVER_ERROR);
16445 credentials,
"Internal error", __FUNCTION__, __LINE__,
16446 "An internal error occurred while deleting an asset. "
16447 "It is unclear whether the asset has been deleted or not. "
16448 "Diagnostics: Failure to read response from manager daemon.",
16455 "Delete Asset", response_data);
16457 free_entity (entity);
16512 gchar *html, *response;
16513 const char *asset_id, *comment;
16526 ret =
gmpf (connection,
credentials, &response, &entity, response_data,
16527 "<modify_asset asset_id=\"%s\">"
16528 "<comment>%s</comment>"
16530 asset_id, comment);
16539 MHD_HTTP_INTERNAL_SERVER_ERROR);
16541 credentials,
"Internal error", __FUNCTION__, __LINE__,
16542 "An internal error occurred while saving an asset. "
16543 "The asset was not saved. "
16544 "Diagnostics: Failure to send command to manager daemon.",
16548 MHD_HTTP_INTERNAL_SERVER_ERROR);
16550 credentials,
"Internal error", __FUNCTION__, __LINE__,
16551 "An internal error occurred while saving an asset. "
16552 "It is unclear whether the asset has been saved or not. "
16553 "Diagnostics: Failure to receive response from manager daemon.",
16557 MHD_HTTP_INTERNAL_SERVER_ERROR);
16559 credentials,
"Internal error", __FUNCTION__, __LINE__,
16560 "An internal error occurred while saving an asset. "
16561 "It is unclear whether the asset has been saved or not. "
16562 "Diagnostics: Internal Error.",
16567 "Save Asset", response_data);
16568 free_entity (entity);
16623 gchar *response = NULL;
16624 entity_t entity = NULL;
16625 const gchar *result_id, *user_id, *note;
16636 switch (
gmpf (connection,
credentials, &response, &entity, response_data,
16638 "<result id=\"%s\"/>"
16640 "<user id=\"%s\"/>"
16642 "<open_note>%s</open_note>"
16643 "</create_ticket>",
16644 result_id, user_id, note ? note :
""))
16651 MHD_HTTP_INTERNAL_SERVER_ERROR);
16653 credentials,
"Internal error", __FUNCTION__, __LINE__,
16654 "An internal error occurred while creating a ticket. "
16655 "Diagnostics: Failure to send command to manager daemon.",
16659 MHD_HTTP_INTERNAL_SERVER_ERROR);
16661 credentials,
"Internal error", __FUNCTION__, __LINE__,
16662 "An internal error occurred while creating a ticket. "
16663 "It is unclear whether the ticket has been created or not. "
16664 "Diagnostics: Failure to receive response from manager daemon.",
16668 MHD_HTTP_INTERNAL_SERVER_ERROR);
16670 credentials,
"Internal error", __FUNCTION__, __LINE__,
16671 "An internal error occurred while creating a ticket. "
16672 "It is unclear whether the ticket has been created or not. "
16673 "Diagnostics: Internal Error.",
16678 "Create Ticket", response_data);
16680 free_entity (entity);
16699 gchar *response = NULL;
16700 entity_t entity = NULL;
16701 const gchar *ticket_id, *status, *open_note, *fixed_note, *closed_note;
16702 const gchar *user_id;
16719 switch (
gmpf (connection,
credentials, &response, &entity, response_data,
16720 "<modify_ticket ticket_id=\"%s\">"
16721 "<assigned_to><user id=\"%s\"/></assigned_to>"
16722 "<status>%s</status>"
16723 "<open_note>%s</open_note>"
16724 "<fixed_note>%s</fixed_note>"
16725 "<closed_note>%s</closed_note>"
16726 "</modify_ticket>",
16727 ticket_id, user_id, status, open_note, fixed_note, closed_note))
16734 MHD_HTTP_INTERNAL_SERVER_ERROR);
16736 credentials,
"Internal error", __FUNCTION__, __LINE__,
16737 "An internal error occurred while saving a ticket. "
16738 "Diagnostics: Failure to send command to manager daemon.",
16742 MHD_HTTP_INTERNAL_SERVER_ERROR);
16744 credentials,
"Internal error", __FUNCTION__, __LINE__,
16745 "An internal error occurred while saving a ticket. "
16746 "It is unclear whether the ticket has been saved or not. "
16747 "Diagnostics: Failure to receive response from manager daemon.",
16751 MHD_HTTP_INTERNAL_SERVER_ERROR);
16753 credentials,
"Internal error", __FUNCTION__, __LINE__,
16754 "An internal error occurred while saving a ticket. "
16755 "It is unclear whether the ticket has been saved or not. "
16756 "Diagnostics: Internal Error.",
16761 "Save Ticket", response_data);
16763 free_entity (entity);
16802 const char *include_certificate_data;
16804 if (
params_given (params,
"include_certificate_data"))
16806 include_certificate_data =
16810 include_certificate_data);
16814 arguments, response_data);
16833 const char *include_certificate_data;
16835 if (
params_given (params,
"include_certificate_data"))
16837 include_certificate_data =
16841 include_certificate_data);
16845 arguments, response_data);
16863 gchar *response = NULL;
16864 entity_t entity = NULL;
16865 const gchar *name, *comment, *trust, *certificate_bin;
16866 size_t certificate_size;
16867 gchar *certificate_b64;
16873 certificate_bin =
params_value (params,
"certificate_bin");
16877 (certificate_size > 0)
16878 ? g_base64_encode ((guchar *) certificate_bin, certificate_size)
16885 switch (
gmpf (connection,
credentials, &response, &entity, response_data,
16886 "<create_tls_certificate>"
16888 "<comment>%s</comment>"
16889 "<trust>%s</trust>"
16890 "<certificate>%s</certificate>"
16891 "</create_tls_certificate>",
16892 name, comment, trust, certificate_b64))
16899 MHD_HTTP_INTERNAL_SERVER_ERROR);
16901 credentials,
"Internal error", __FUNCTION__, __LINE__,
16902 "An internal error occurred while creating a TLS certificate. "
16903 "Diagnostics: Failure to send command to manager daemon.",
16907 MHD_HTTP_INTERNAL_SERVER_ERROR);
16909 credentials,
"Internal error", __FUNCTION__, __LINE__,
16910 "An internal error occurred while creating a TLS certificate. "
16911 "It is unclear whether the TLS certificate has been created or not. "
16912 "Diagnostics: Failure to receive response from manager daemon.",
16916 MHD_HTTP_INTERNAL_SERVER_ERROR);
16918 credentials,
"Internal error", __FUNCTION__, __LINE__,
16919 "An internal error occurred while creating a TLS certificate. "
16920 "It is unclear whether the TLS certificate has been created or not. "
16921 "Diagnostics: Internal Error.",
16926 "Create TLS Certificate", response_data);
16928 free_entity (entity);
16930 g_free (certificate_b64);
16949 gchar *response = NULL;
16950 entity_t entity = NULL;
16951 const gchar *tls_certificate_id, *name, *comment, *trust, *certificate_bin;
16952 size_t certificate_size;
16953 gchar *certificate_b64;
16956 tls_certificate_id =
params_value (params,
"tls_certificate_id");
16960 certificate_bin =
params_value (params,
"certificate_bin");
16964 (certificate_size > 0)
16965 ? g_base64_encode ((guchar *) certificate_bin, certificate_size)
16973 switch (
gmpf (connection,
credentials, &response, &entity, response_data,
16974 "<modify_tls_certificate tls_certificate_id=\"%s\">"
16976 "<comment>%s</comment>"
16977 "<trust>%s</trust>"
16978 "<certificate>%s</certificate>"
16979 "</modify_tls_certificate>",
16980 tls_certificate_id, name, comment, trust, certificate_b64))
16987 MHD_HTTP_INTERNAL_SERVER_ERROR);
16989 credentials,
"Internal error", __FUNCTION__, __LINE__,
16990 "An internal error occurred while saving a TLS certificate. "
16991 "Diagnostics: Failure to send command to manager daemon.",
16995 MHD_HTTP_INTERNAL_SERVER_ERROR);
16997 credentials,
"Internal error", __FUNCTION__, __LINE__,
16998 "An internal error occurred while saving a TLS certificate. "
16999 "It is unclear whether the TLS certificate has been saved or not. "
17000 "Diagnostics: Failure to receive response from manager daemon.",
17004 MHD_HTTP_INTERNAL_SERVER_ERROR);
17006 credentials,
"Internal error", __FUNCTION__, __LINE__,
17007 "An internal error occurred while saving a TLS certificate. "
17008 "It is unclear whether the TLS certificate has been saved or not. "
17009 "Diagnostics: Internal Error.",
17014 "Save TLS Certificate", response_data);
17016 free_entity (entity);
17018 g_free (certificate_b64);
17038 params, response_data);
17055 "renew_session", message, NULL, NULL);
17075 "pong", NULL, NULL);
17082 entity_t entity = NULL;
17085 if (gvm_connection_sendf (connection,
17086 "<help format=\"XML\" type=\"brief\"/>"))
17089 MHD_HTTP_INTERNAL_SERVER_ERROR);
17091 credentials,
"Internal error", __FUNCTION__, __LINE__,
17092 "An internal error occurred while getting the user credentials. "
17093 "Diagnostics: Failure to send command to manager daemon.",
17097 xml = g_string_new (
"");
17098 g_string_append (xml,
"<get_capabilities>");
17101 if (read_entity_and_string_c (connection, &entity, &xml))
17103 g_string_free (xml, TRUE);
17105 MHD_HTTP_INTERNAL_SERVER_ERROR);
17107 credentials,
"Internal error", __FUNCTION__, __LINE__,
17108 "An internal error occurred while getting the user credentials. "
17109 "Diagnostics: Failure to receive response from manager daemon.",
17121 entity_attribute (entity,
"status_text"), response_data);
17123 g_string_free (xml, TRUE);
17124 free_entity (entity);
17129 free_entity (entity);
17131 g_string_append (xml,
"</get_capabilities>");
17133 g_string_free (xml, FALSE), response_data);
17148 struct sockaddr_un address;
17153 sock = socket (AF_UNIX, SOCK_STREAM, 0);
17156 g_warning (
"Failed to create server socket");
17162 address.sun_family = AF_UNIX;
17163 strncpy (address.sun_path, path, sizeof (address.sun_path) - 1);
17164 if (connect (sock, (
struct sockaddr *) &address,
sizeof (address)) == -1)
17166 g_warning (
"Failed to connect to server at %s: %s", path,
17188 if (address == NULL)
17195 connection->socket =
17196 gvm_server_open (&connection->session, address, port);
17197 connection->credentials = NULL;
17202 if (connection->socket == -1)
17224 gchar **timezone, gchar **severity, gchar **capabilities,
17225 gchar **language, gchar **pw_warning)
17227 gvm_connection_t connection;
17229 gmp_authenticate_info_opts_t auth_opts;
17233 g_debug (
"%s failed to acquire socket!\n", __FUNCTION__);
17237 auth_opts = gmp_authenticate_info_opts_defaults;
17238 auth_opts.username = username;
17239 auth_opts.password = password;
17240 auth_opts.role = role;
17241 auth_opts.severity = severity;
17242 auth_opts.timezone = timezone;
17243 auth_opts.pw_warning = pw_warning;
17245 auth = gmp_authenticate_info_ext_c (&connection, auth_opts);
17249 const char *status;
17257 &connection,
"6765549a-934e-11e3-b358-406186ea4fc5", language, NULL);
17265 gvm_connection_close (&connection);
17268 gvm_connection_close (&connection);
17274 ret = gvm_connection_sendf (&connection,
17275 "<help format=\"XML\" type=\"brief\"/>");
17278 gvm_connection_close (&connection);
17285 if (read_entity_and_text_c (&connection, &entity, &response))
17287 gvm_connection_close (&connection);
17293 status = entity_attribute (entity,
"status");
17294 if (status == NULL || strlen (status) == 0)
17297 free_entity (entity);
17302 free_entity (entity);
17306 *capabilities = response;
17310 gvm_connection_close (&connection);
17315 gvm_connection_close (&connection);
17320 gvm_connection_close (&connection);
17353 gchar *capabilities;
17358 const char *password =
params_value (params,
"password");
17361 if ((password == NULL)
17365 if (
login && password)
17368 &capabilities, &language, &pw_warning);
17375 status = MHD_HTTP_SERVICE_UNAVAILABLE;
17379 status = MHD_HTTP_UNAUTHORIZED;
17383 status = MHD_HTTP_INTERNAL_SERVER_ERROR;
17388 g_warning (
"Authentication failure for '%s' from %s. "
17390 login ?:
"", client_address, ret);
17397 capabilities, language, pw_warning, client_address);
17399 g_message (
"Authentication success for '%s' from %s",
login ?:
"",
17416 g_free (capabilities);
17419 g_free (pw_warning);
17426 g_warning (
"Authentication failure for '%s' from %s",
login ?:
"",
17447 gmp_authenticate_info_opts_t auth_opts;
17456 auth_opts = gmp_authenticate_info_opts_defaults;
17460 int ret = gmp_authenticate_info_ext_c (connection, auth_opts);
17464 gvm_connection_close (connection);
17475 g_debug (
"Sleeping!");