diff options
197 files changed, 4459 insertions, 2692 deletions
diff --git a/ChangeLog.d/feature/ZBXNEXT-82 b/ChangeLog.d/feature/ZBXNEXT-82 new file mode 100644 index 00000000000..9237ca8c0da --- /dev/null +++ b/ChangeLog.d/feature/ZBXNEXT-82 @@ -0,0 +1 @@ +A.F.I..... [ZBXNEXT-82] reworked part of parameters from definitions file to configurable parameters using frontend; added new API for settings, authentication, housekeepeing (vmaksimovs) diff --git a/create/src/schema.tmpl b/create/src/schema.tmpl index cc9cc584ae6..33f78a1ca53 100644 --- a/create/src/schema.tmpl +++ b/create/src/schema.tmpl @@ -639,6 +639,23 @@ FIELD |saml_encrypt_assertions|t_integer |'0' |NOT NULL |ZBX_NODATA FIELD |saml_case_sensitive |t_integer |'0' |NOT NULL |ZBX_NODATA FIELD |default_lang |t_varchar(5) |'en_GB'|NOT NULL |ZBX_NODATA FIELD |default_timezone |t_varchar(50) |'system'|NOT NULL |ZBX_NODATA +FIELD |login_attempts |t_integer |'5' |NOT NULL |ZBX_NODATA +FIELD |login_block |t_varchar(32) |'30s' |NOT NULL |ZBX_NODATA +FIELD |show_technical_errors |t_integer |'0' |NOT NULL |ZBX_NODATA +FIELD |validate_uri_schemes |t_integer |'1' |NOT NULL |ZBX_NODATA +FIELD |uri_valid_schemes |t_varchar(255) |'http,https,ftp,file,mailto,tel,ssh' |NOT NULL |ZBX_NODATA +FIELD |x_frame_options |t_varchar(255) |'SAMEORIGIN' |NOT NULL |ZBX_NODATA +FIELD |iframe_sandboxing_enabled |t_integer |'1' |NOT NULL |ZBX_NODATA +FIELD |iframe_sandboxing_exceptions |t_varchar(255) |'' |NOT NULL |ZBX_NODATA +FIELD |max_overview_table_size |t_integer |'50' |NOT NULL |ZBX_NODATA +FIELD |history_period |t_varchar(32)| '24h' |NOT NULL |ZBX_NODATA +FIELD |period_default |t_varchar(32) |'1h' |NOT NULL |ZBX_NODATA +FIELD |max_period |t_varchar(32) |'2y' |NOT NULL |ZBX_NODATA +FIELD |socket_timeout |t_varchar(32) |'3s' |NOT NULL |ZBX_NODATA +FIELD |connect_timeout |t_varchar(32) |'3s' |NOT NULL |ZBX_NODATA +FIELD |media_type_test_timeout |t_varchar(32) |'65s' |NOT NULL |ZBX_NODATA +FIELD |script_timeout |t_varchar(32) |'60s' |NOT NULL |ZBX_NODATA +FIELD |item_test_timeout |t_varchar(32) |'60s' |NOT NULL |ZBX_NODATA INDEX |1 |alert_usrgrpid INDEX |2 |discovery_groupid @@ -1831,4 +1848,4 @@ FIELD |inventory_mode |t_integer |'0' |NOT NULL |0 TABLE|dbversion|| FIELD |mandatory |t_integer |'0' |NOT NULL | FIELD |optional |t_integer |'0' |NOT NULL | -ROW |5010006 |5010006 +ROW |5010023 |5010023 diff --git a/include/dbschema.h b/include/dbschema.h index 15031f846bc..bb8b27a9997 100644 --- a/include/dbschema.h +++ b/include/dbschema.h @@ -38,7 +38,7 @@ #define ZBX_TYPE_SHORTTEXT 7 #define ZBX_TYPE_LONGTEXT 8 -#define ZBX_MAX_FIELDS 88 /* maximum number of fields in a table plus one for null terminator in dbschema.c */ +#define ZBX_MAX_FIELDS 105 /* maximum number of fields in a table plus one for null terminator in dbschema.c */ #define ZBX_TABLENAME_LEN 26 #define ZBX_TABLENAME_LEN_MAX (ZBX_TABLENAME_LEN + 1) #define ZBX_FIELDNAME_LEN 28 diff --git a/src/libs/zbxdbupgrade/dbupgrade_5010.c b/src/libs/zbxdbupgrade/dbupgrade_5010.c index 4cd1e6bf3d1..d8742da3954 100644 --- a/src/libs/zbxdbupgrade/dbupgrade_5010.c +++ b/src/libs/zbxdbupgrade/dbupgrade_5010.c @@ -103,6 +103,125 @@ static int DBpatch_5010006(void) return DBadd_field("users", &field); } +static int DBpatch_5010007(void) +{ + const ZBX_FIELD field = {"login_attempts", "5", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0}; + + return DBadd_field("config", &field); +} + +static int DBpatch_5010008(void) +{ + const ZBX_FIELD field = {"login_block", "30s", NULL, NULL, 32, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0}; + + return DBadd_field("config", &field); +} + +static int DBpatch_5010009(void) +{ + const ZBX_FIELD field = {"show_technical_errors", "0", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0}; + + return DBadd_field("config", &field); +} + +static int DBpatch_5010010(void) +{ + const ZBX_FIELD field = {"validate_uri_schemes", "1", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0}; + + return DBadd_field("config", &field); +} + +static int DBpatch_5010011(void) +{ + const ZBX_FIELD field = {"uri_valid_schemes", "http,https,ftp,file,mailto,tel,ssh", NULL, NULL, 255, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0}; + + return DBadd_field("config", &field); +} + +static int DBpatch_5010012(void) +{ + const ZBX_FIELD field = {"x_frame_options", "SAMEORIGIN", NULL, NULL, 255, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0}; + + return DBadd_field("config", &field); +} + +static int DBpatch_5010013(void) +{ + const ZBX_FIELD field = {"iframe_sandboxing_enabled", "1", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0}; + + return DBadd_field("config", &field); +} + +static int DBpatch_5010014(void) +{ + const ZBX_FIELD field = {"iframe_sandboxing_exceptions", "", NULL, NULL, 255, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0}; + + return DBadd_field("config", &field); +} + +static int DBpatch_5010015(void) +{ + const ZBX_FIELD field = {"max_overview_table_size", "50", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0}; + + return DBadd_field("config", &field); +} + +static int DBpatch_5010016(void) +{ + const ZBX_FIELD field = {"history_period", "24h", NULL, NULL, 32, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0}; + + return DBadd_field("config", &field); +} + +static int DBpatch_5010017(void) +{ + const ZBX_FIELD field = {"period_default", "1h", NULL, NULL, 32, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0}; + + return DBadd_field("config", &field); +} + +static int DBpatch_5010018(void) +{ + const ZBX_FIELD field = {"max_period", "2y", NULL, NULL, 32, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0}; + + return DBadd_field("config", &field); +} + +static int DBpatch_5010019(void) +{ + const ZBX_FIELD field = {"socket_timeout", "3s", NULL, NULL, 32, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0}; + + return DBadd_field("config", &field); +} + +static int DBpatch_5010020(void) +{ + const ZBX_FIELD field = {"connect_timeout", "3s", NULL, NULL, 32, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0}; + + return DBadd_field("config", &field); +} + +static int DBpatch_5010021(void) +{ + const ZBX_FIELD field = {"media_type_test_timeout", "65s", NULL, NULL, 32, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0}; + + return DBadd_field("config", &field); +} + +static int DBpatch_5010022(void) +{ + const ZBX_FIELD field = {"script_timeout", "60s", NULL, NULL, 32, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0}; + + return DBadd_field("config", &field); +} + +static int DBpatch_5010023(void) +{ + const ZBX_FIELD field = {"item_test_timeout", "60s", NULL, NULL, 32, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0}; + + return DBadd_field("config", &field); +} + #endif DBPATCH_START(5010) @@ -116,5 +235,22 @@ DBPATCH_ADD(5010003, 0, 1) DBPATCH_ADD(5010004, 0, 1) DBPATCH_ADD(5010005, 0, 1) DBPATCH_ADD(5010006, 0, 1) +DBPATCH_ADD(5010007, 0, 1) +DBPATCH_ADD(5010008, 0, 1) +DBPATCH_ADD(5010009, 0, 1) +DBPATCH_ADD(5010010, 0, 1) +DBPATCH_ADD(5010011, 0, 1) +DBPATCH_ADD(5010012, 0, 1) +DBPATCH_ADD(5010013, 0, 1) +DBPATCH_ADD(5010014, 0, 1) +DBPATCH_ADD(5010015, 0, 1) +DBPATCH_ADD(5010016, 0, 1) +DBPATCH_ADD(5010017, 0, 1) +DBPATCH_ADD(5010018, 0, 1) +DBPATCH_ADD(5010019, 0, 1) +DBPATCH_ADD(5010020, 0, 1) +DBPATCH_ADD(5010021, 0, 1) +DBPATCH_ADD(5010022, 0, 1) +DBPATCH_ADD(5010023, 0, 1) DBPATCH_END() diff --git a/ui/actionconf.php b/ui/actionconf.php index b96c677f181..bae4f9839c5 100644 --- a/ui/actionconf.php +++ b/ui/actionconf.php @@ -414,8 +414,6 @@ if (hasRequest('action') && hasRequest('g_actionid') && !$result) { */ show_messages(); -$config = select_config(); - if (hasRequest('form')) { $data = [ 'form' => getRequest('form'), @@ -423,8 +421,7 @@ if (hasRequest('form')) { 'new_condition' => getRequest('new_condition', []), 'new_operation' => getRequest('new_operation'), 'new_recovery_operation' => getRequest('new_recovery_operation'), - 'new_ack_operation' => $new_ack_operation, - 'config' => $config + 'new_ack_operation' => $new_ack_operation ]; if ($data['actionid']) { @@ -579,11 +576,11 @@ else { 'sort' => $sortField, 'sortorder' => $sortOrder, 'filter' => $filter, - 'config' => $config, 'profileIdx' => 'web.actionconf.filter', 'active_tab' => CProfile::get('web.actionconf.filter.active', 1) ]; + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1; $data['actions'] = API::Action()->get([ 'output' => API_OUTPUT_EXTEND, 'search' => [ @@ -597,7 +594,7 @@ else { 'selectOperations' => API_OUTPUT_EXTEND, 'editable' => true, 'sortfield' => $sortField, - 'limit' => $config['search_limit'] + 1 + 'limit' => $limit ]); // pager diff --git a/ui/app/controllers/CControllerApplicationList.php b/ui/app/controllers/CControllerApplicationList.php index 56be400c900..ed90258d27c 100644 --- a/ui/app/controllers/CControllerApplicationList.php +++ b/ui/app/controllers/CControllerApplicationList.php @@ -161,13 +161,12 @@ class CControllerApplicationList extends CController { */ private function fetchApplications(array $filter_hostids, array $filter_groupids, string $sort_field, string $sort_order): array { - $config = select_config(); - if ($filter_groupids) { $filter_groupids = getSubGroups($filter_groupids); } // Get applications. + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1; $applications = API::Application()->get([ 'output' => ['applicationid', 'hostid', 'name', 'flags', 'templateids'], 'selectHost' => ['hostid', 'name'], @@ -178,7 +177,7 @@ class CControllerApplicationList extends CController { 'groupids' => $filter_groupids ? $filter_groupids : null, 'editable' => true, 'sortfield' => $sort_field, - 'limit' => $config['search_limit'] + 1 + 'limit' => $limit ]); CArrayHelper::sort($applications, [['field' => $sort_field, 'order' => $sort_order]]); diff --git a/ui/app/controllers/CControllerAuditLogList.php b/ui/app/controllers/CControllerAuditLogList.php index 242ecd3a525..67436b84532 100644 --- a/ui/app/controllers/CControllerAuditLogList.php +++ b/ui/app/controllers/CControllerAuditLogList.php @@ -92,7 +92,6 @@ class CControllerAuditLogList extends CController { $filter['resourceid'] = $data['resourceid']; } - $config = select_config(); $params = [ 'output' => ['auditid', 'userid', 'clock', 'action', 'resourcetype', 'note', 'ip', 'resourceid', 'resourcename' @@ -101,7 +100,7 @@ class CControllerAuditLogList extends CController { 'filter' => $filter, 'sortfield' => 'clock', 'sortorder' => ZBX_SORT_DOWN, - 'limit' => $config['search_limit'] + 1 + 'limit' => CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1 ]; if ($data['timeline']['from_ts'] !== null) { @@ -216,7 +215,10 @@ class CControllerAuditLogList extends CController { AUDIT_RESOURCE_CORRELATION => _('Event correlation'), AUDIT_RESOURCE_DASHBOARD => _('Dashboard'), AUDIT_RESOURCE_AUTOREGISTRATION => _('Autoregistration'), - AUDIT_RESOURCE_MODULE => _('Module') + AUDIT_RESOURCE_MODULE => _('Module'), + AUDIT_RESOURCE_SETTINGS => _('Settings'), + AUDIT_RESOURCE_HOUSEKEEPING => _('Housekeeping'), + AUDIT_RESOURCE_AUTHENTICATION => _('Authentication') ]; } diff --git a/ui/app/controllers/CControllerAuthenticationEdit.php b/ui/app/controllers/CControllerAuthenticationEdit.php index 8e30f6fe3fb..8d6a4f9fa0d 100644 --- a/ui/app/controllers/CControllerAuthenticationEdit.php +++ b/ui/app/controllers/CControllerAuthenticationEdit.php @@ -38,6 +38,9 @@ class CControllerAuthenticationEdit extends CController { 'change_bind_password' => 'in 0,1', 'db_authentication_type' => 'string', 'authentication_type' => 'in '.ZBX_AUTH_INTERNAL.','.ZBX_AUTH_LDAP, + 'http_auth_enabled' => 'in '.ZBX_AUTH_HTTP_DISABLED.','.ZBX_AUTH_HTTP_ENABLED, + 'http_login_form' => 'in '.ZBX_AUTH_FORM_ZABBIX.','.ZBX_AUTH_FORM_HTTP, + 'http_strip_domains' => 'db config.http_strip_domains', 'http_case_sensitive' => 'in '.ZBX_AUTH_CASE_INSENSITIVE.','.ZBX_AUTH_CASE_SENSITIVE, 'ldap_case_sensitive' => 'in '.ZBX_AUTH_CASE_INSENSITIVE.','.ZBX_AUTH_CASE_SENSITIVE, 'ldap_configured' => 'in '.ZBX_AUTH_LDAP_DISABLED.','.ZBX_AUTH_LDAP_ENABLED, @@ -47,9 +50,6 @@ class CControllerAuthenticationEdit extends CController { 'ldap_bind_dn' => 'db config.ldap_bind_dn', 'ldap_search_attribute' => 'db config.ldap_search_attribute', 'ldap_bind_password' => 'db config.ldap_bind_password', - 'http_auth_enabled' => 'in '.ZBX_AUTH_HTTP_DISABLED.','.ZBX_AUTH_HTTP_ENABLED, - 'http_login_form' => 'in '.ZBX_AUTH_FORM_ZABBIX.','.ZBX_AUTH_FORM_HTTP, - 'http_strip_domains' => 'db config.http_strip_domains', 'saml_auth_enabled' => 'in '.ZBX_AUTH_SAML_DISABLED.','.ZBX_AUTH_SAML_ENABLED, 'saml_idp_entityid' => 'db config.saml_idp_entityid', 'saml_sso_url' => 'db config.saml_sso_url', @@ -100,6 +100,41 @@ class CControllerAuthenticationEdit extends CController { 'form_refresh' => 0 ]; + $auth_params = [ + CAuthenticationHelper::AUTHENTICATION_TYPE, + CAuthenticationHelper::HTTP_AUTH_ENABLED, + CAuthenticationHelper::HTTP_LOGIN_FORM, + CAuthenticationHelper::HTTP_STRIP_DOMAINS, + CAuthenticationHelper::HTTP_CASE_SENSITIVE, + CAuthenticationHelper::LDAP_CASE_SENSITIVE, + CAuthenticationHelper::LDAP_CONFIGURED, + CAuthenticationHelper::LDAP_HOST, + CAuthenticationHelper::LDAP_PORT, + CAuthenticationHelper::LDAP_BASE_DN, + CAuthenticationHelper::LDAP_BIND_DN, + CAuthenticationHelper::LDAP_SEARCH_ATTRIBUTE, + CAuthenticationHelper::LDAP_BIND_PASSWORD, + CAuthenticationHelper::SAML_AUTH_ENABLED, + CAuthenticationHelper::SAML_IDP_ENTITYID, + CAuthenticationHelper::SAML_SSO_URL, + CAuthenticationHelper::SAML_SLO_URL, + CAuthenticationHelper::SAML_USERNAME_ATTRIBUTE, + CAuthenticationHelper::SAML_SP_ENTITYID, + CAuthenticationHelper::SAML_NAMEID_FORMAT, + CAuthenticationHelper::SAML_SIGN_MESSAGES, + CAuthenticationHelper::SAML_SIGN_ASSERTIONS, + CAuthenticationHelper::SAML_SIGN_AUTHN_REQUESTS, + CAuthenticationHelper::SAML_SIGN_LOGOUT_REQUESTS, + CAuthenticationHelper::SAML_SIGN_LOGOUT_RESPONSES, + CAuthenticationHelper::SAML_ENCRYPT_NAMEID, + CAuthenticationHelper::SAML_ENCRYPT_ASSERTIONS, + CAuthenticationHelper::SAML_CASE_SENSITIVE + ]; + $auth = []; + foreach ($auth_params as $param) { + $auth[$param] = CAuthenticationHelper::get($param); + } + if ($this->hasInput('form_refresh')) { $data['ldap_bind_password'] = ''; $this->getInputs($data, [ @@ -107,6 +142,9 @@ class CControllerAuthenticationEdit extends CController { 'change_bind_password', 'db_authentication_type', 'authentication_type', + 'http_auth_enabled', + 'http_login_form', + 'http_strip_domains', 'http_case_sensitive', 'ldap_case_sensitive', 'ldap_configured', @@ -118,9 +156,6 @@ class CControllerAuthenticationEdit extends CController { 'ldap_bind_password', 'ldap_test_user', 'ldap_test_password', - 'http_auth_enabled', - 'http_login_form', - 'http_strip_domains', 'saml_auth_enabled', 'saml_idp_entityid', 'saml_sso_url', @@ -138,10 +173,10 @@ class CControllerAuthenticationEdit extends CController { 'saml_case_sensitive' ]); - $data += select_config(); + $data += $auth; } else { - $data += select_config(); + $data += $auth; $data['db_authentication_type'] = $data['authentication_type']; $data['change_bind_password'] = ($data['ldap_bind_password'] === '') ? 1 : 0; } diff --git a/ui/app/controllers/CControllerAuthenticationUpdate.php b/ui/app/controllers/CControllerAuthenticationUpdate.php index 9dba61be15a..e9f80dc9ae5 100644 --- a/ui/app/controllers/CControllerAuthenticationUpdate.php +++ b/ui/app/controllers/CControllerAuthenticationUpdate.php @@ -117,11 +117,20 @@ class CControllerAuthenticationUpdate extends CController { $is_valid = true; $ldap_status = (new CFrontendSetup())->checkPhpLdapModule(); $ldap_fields = ['ldap_host', 'ldap_port', 'ldap_base_dn', 'ldap_search_attribute', 'ldap_configured']; - $config = select_config(); - $this->getInputs($config, array_merge($ldap_fields, ['ldap_bind_dn', 'ldap_bind_password'])); - $ldap_settings_changed = array_diff_assoc($config, select_config()); + $ldap_auth_original = [ + 'ldap_host' => CAuthenticationHelper::get(CAuthenticationHelper::LDAP_HOST), + 'ldap_port' => CAuthenticationHelper::get(CAuthenticationHelper::LDAP_PORT), + 'ldap_base_dn' => CAuthenticationHelper::get(CAuthenticationHelper::LDAP_BASE_DN), + 'ldap_search_attribute' => CAuthenticationHelper::get(CAuthenticationHelper::LDAP_SEARCH_ATTRIBUTE), + 'ldap_configured' => CAuthenticationHelper::get(CAuthenticationHelper::LDAP_CONFIGURED), + 'ldap_bind_dn' => CAuthenticationHelper::get(CAuthenticationHelper::LDAP_BIND_DN), + 'ldap_bind_password' => CAuthenticationHelper::get(CAuthenticationHelper::LDAP_BIND_PASSWORD) + ]; + $ldap_auth = $ldap_auth_original; + $this->getInputs($ldap_auth, array_merge($ldap_fields, ['ldap_bind_dn', 'ldap_bind_password'])); + $ldap_auth_changed = array_diff_assoc($ldap_auth, $ldap_auth_original); - if (!$ldap_settings_changed && !$this->hasInput('ldap_test')) { + if (!$ldap_auth_changed && !$this->hasInput('ldap_test')) { return $is_valid; } @@ -130,7 +139,7 @@ class CControllerAuthenticationUpdate extends CController { } foreach ($ldap_fields as $field) { - if (trim($config[$field]) === '') { + if (trim($ldap_auth[$field]) === '') { $this->response->setMessageError( _s('Incorrect value for field "%1$s": %2$s.', $field, _('cannot be empty')) ); @@ -139,7 +148,9 @@ class CControllerAuthenticationUpdate extends CController { } } - if ($is_valid && ($config['ldap_port'] < ZBX_MIN_PORT_NUMBER || $config['ldap_port'] > ZBX_MAX_PORT_NUMBER)) { + if ($is_valid + && ($ldap_auth['ldap_port'] < ZBX_MIN_PORT_NUMBER + || $ldap_auth['ldap_port'] > ZBX_MAX_PORT_NUMBER)) { $this->response->setMessageError(_s( 'Incorrect value "%1$s" for "%2$s" field: must be between %3$s and %4$s.', $this->getInput('ldap_port'), 'ldap_port', ZBX_MIN_PORT_NUMBER, ZBX_MAX_PORT_NUMBER @@ -154,12 +165,12 @@ class CControllerAuthenticationUpdate extends CController { elseif ($is_valid) { $ldap_validator = new CLdapAuthValidator([ 'conf' => [ - 'host' => $config['ldap_host'], - 'port' => $config['ldap_port'], - 'base_dn' => $config['ldap_base_dn'], - 'bind_dn' => $config['ldap_bind_dn'], - 'bind_password' => $config['ldap_bind_password'], - 'search_attribute' => $config['ldap_search_attribute'] + 'host' => $ldap_auth['ldap_host'], + 'port' => $ldap_auth['ldap_port'], + 'base_dn' => $ldap_auth['ldap_base_dn'], + 'bind_dn' => $ldap_auth['ldap_bind_dn'], + 'bind_password' => $ldap_auth['ldap_bind_password'], + 'search_attribute' => $ldap_auth['ldap_search_attribute'] ] ]); @@ -192,11 +203,16 @@ class CControllerAuthenticationUpdate extends CController { } $saml_fields = ['saml_idp_entityid', 'saml_sso_url', 'saml_sp_entityid', 'saml_username_attribute']; - $config = select_config(); - $this->getInputs($config, $saml_fields); + $saml_auth = [ + 'saml_idp_entityid' => CAuthenticationHelper::get(CAuthenticationHelper::SAML_IDP_ENTITYID), + 'saml_sso_url' => CAuthenticationHelper::get(CAuthenticationHelper::SAML_SSO_URL), + 'saml_sp_entityid' => CAuthenticationHelper::get(CAuthenticationHelper::SAML_SP_ENTITYID), + 'saml_username_attribute' => CAuthenticationHelper::get(CAuthenticationHelper::SAML_USERNAME_ATTRIBUTE) + ]; + $this->getInputs($saml_auth, $saml_fields); foreach ($saml_fields as $field) { - if (trim($config[$field]) === '') { + if (trim($saml_auth[$field]) === '') { $this->response->setMessageError( _s('Incorrect value for field "%1$s": %2$s.', $field, _('cannot be empty')) ); @@ -242,7 +258,41 @@ class CControllerAuthenticationUpdate extends CController { return; } - $config = select_config(); + $auth_params = [ + CAuthenticationHelper::AUTHENTICATION_TYPE, + CAuthenticationHelper::HTTP_AUTH_ENABLED, + CAuthenticationHelper::HTTP_LOGIN_FORM, + CAuthenticationHelper::HTTP_STRIP_DOMAINS, + CAuthenticationHelper::HTTP_CASE_SENSITIVE, + CAuthenticationHelper::LDAP_CASE_SENSITIVE, + CAuthenticationHelper::LDAP_CONFIGURED, + CAuthenticationHelper::LDAP_HOST, + CAuthenticationHelper::LDAP_PORT, + CAuthenticationHelper::LDAP_BASE_DN, + CAuthenticationHelper::LDAP_BIND_DN, + CAuthenticationHelper::LDAP_SEARCH_ATTRIBUTE, + CAuthenticationHelper::LDAP_BIND_PASSWORD, + CAuthenticationHelper::SAML_AUTH_ENABLED, + CAuthenticationHelper::SAML_IDP_ENTITYID, + CAuthenticationHelper::SAML_SSO_URL, + CAuthenticationHelper::SAML_SLO_URL, + CAuthenticationHelper::SAML_USERNAME_ATTRIBUTE, + CAuthenticationHelper::SAML_SP_ENTITYID, + CAuthenticationHelper::SAML_NAMEID_FORMAT, + CAuthenticationHelper::SAML_SIGN_MESSAGES, + CAuthenticationHelper::SAML_SIGN_ASSERTIONS, + CAuthenticationHelper::SAML_SIGN_AUTHN_REQUESTS, + CAuthenticationHelper::SAML_SIGN_LOGOUT_REQUESTS, + CAuthenticationHelper::SAML_SIGN_LOGOUT_RESPONSES, + CAuthenticationHelper::SAML_ENCRYPT_NAMEID, + CAuthenticationHelper::SAML_ENCRYPT_ASSERTIONS, + CAuthenticationHelper::SAML_CASE_SENSITIVE + ]; + $auth = []; + foreach ($auth_params as $param) { + $auth[$param] = CAuthenticationHelper::get($param); + } + $fields = [ 'authentication_type' => ZBX_AUTH_INTERNAL, 'ldap_configured' => ZBX_AUTH_LDAP_DISABLED, @@ -272,7 +322,7 @@ class CControllerAuthenticationUpdate extends CController { $fields['ldap_bind_password'] = ''; } else { - unset($config['ldap_bind_password']); + unset($auth[CAuthenticationHelper::LDAP_BIND_PASSWORD]); } } @@ -295,16 +345,16 @@ class CControllerAuthenticationUpdate extends CController { ]; } - $data = array_merge($config, $fields); + $data = $fields + $auth; $this->getInputs($data, array_keys($fields)); - $data = array_diff_assoc($data, $config); + $data = array_diff_assoc($data, $auth); if (array_key_exists('ldap_bind_dn', $data) && trim($data['ldap_bind_dn']) === '') { $data['ldap_bind_password'] = ''; } if ($data) { - $result = update_config($data); + $result = API::Authentication()->update($data); if ($result) { if (array_key_exists('authentication_type', $data)) { @@ -312,7 +362,6 @@ class CControllerAuthenticationUpdate extends CController { } $this->response->setMessageOk(_('Authentication settings updated')); - add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_ZABBIX_CONFIG, _('Authentication method changed')); } else { $this->response->setFormData($this->getInputAll()); diff --git a/ui/app/controllers/CControllerDashboardList.php b/ui/app/controllers/CControllerDashboardList.php index 9528c844f8f..29f2f3ddebf 100644 --- a/ui/app/controllers/CControllerDashboardList.php +++ b/ui/app/controllers/CControllerDashboardList.php @@ -59,8 +59,6 @@ class CControllerDashboardList extends CControllerDashboardAbstract { CProfile::update('web.dashbrd.list.sort', $sort_field, PROFILE_TYPE_STR); CProfile::update('web.dashbrd.list.sortorder', $sort_order, PROFILE_TYPE_STR); - $config = select_config(); - $data = [ 'uncheck' => $this->hasInput('uncheck'), 'sort' => $sort_field, @@ -68,9 +66,10 @@ class CControllerDashboardList extends CControllerDashboardAbstract { ]; // list of dashboards + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1; $data['dashboards'] = API::Dashboard()->get([ 'output' => ['dashboardid', 'name'], - 'limit' => $config['search_limit'] + 1, + 'limit' => $limit, 'preservekeys' => true ]); diff --git a/ui/app/controllers/CControllerGuiEdit.php b/ui/app/controllers/CControllerGuiEdit.php index 18701069299..f56c255c15e 100644 --- a/ui/app/controllers/CControllerGuiEdit.php +++ b/ui/app/controllers/CControllerGuiEdit.php @@ -27,12 +27,18 @@ class CControllerGuiEdit extends CController { protected function checkInput() { $fields = [ - 'default_lang' => 'db config.default_lang', - 'default_timezone' => 'db config.default_timezone', - 'default_theme' => 'db config.default_theme', - 'search_limit' => 'db config.search_limit', - 'max_in_table' => 'db config.max_in_table', - 'server_check_interval' => 'db config.server_check_interval' + 'default_lang' => 'db config.default_lang', + 'default_timezone' => 'db config.default_timezone', + 'default_theme' => 'db config.default_theme', + 'search_limit' => 'db config.search_limit', + 'max_overview_table_size' => 'db config.max_overview_table_size', + 'max_in_table' => 'db config.max_in_table', + 'server_check_interval' => 'db config.server_check_interval', + 'work_period' => 'db config.work_period', + 'show_technical_errors' => 'db config.show_technical_errors', + 'history_period' => 'db config.history_period', + 'period_default' => 'db config.period_default', + 'max_period' => 'db config.max_period' ]; $ret = $this->validateInput($fields); @@ -49,14 +55,31 @@ class CControllerGuiEdit extends CController { } protected function doAction() { - $config = select_config(); $data = [ - 'default_lang' => $this->getInput('default_lang', $config['default_lang']), - 'default_timezone' => $this->getInput('default_timezone', $config['default_timezone']), - 'default_theme' => $this->getInput('default_theme', $config['default_theme']), - 'search_limit' => $this->getInput('search_limit', $config['search_limit']), - 'max_in_table' => $this->getInput('max_in_table', $config['max_in_table']), - 'server_check_interval' => $this->getInput('server_check_interval', $config['server_check_interval']) + 'default_lang' => $this->getInput('default_lang', CSettingsHelper::get(CSettingsHelper::DEFAULT_LANG)), + 'default_timezone' => $this->getInput('default_timezone', CSettingsHelper::get( + CSettingsHelper::DEFAULT_TIMEZONE + )), + 'default_theme' => $this->getInput('default_theme', CSettingsHelper::get(CSettingsHelper::DEFAULT_THEME)), + 'search_limit' => $this->getInput('search_limit', CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT)), + 'max_overview_table_size' => $this->getInput('max_overview_table_size', CSettingsHelper::get( + CSettingsHelper::MAX_OVERVIEW_TABLE_SIZE + )), + 'max_in_table' => $this->getInput('max_in_table', CSettingsHelper::get(CSettingsHelper::MAX_IN_TABLE)), + 'server_check_interval' => $this->getInput('server_check_interval', CSettingsHelper::get( + CSettingsHelper::SERVER_CHECK_INTERVAL + )), + 'work_period' => $this->getInput('work_period', CSettingsHelper::get(CSettingsHelper::WORK_PERIOD)), + 'show_technical_errors' => $this->getInput('show_technical_errors', CSettingsHelper::get( + CSettingsHelper::SHOW_TECHNICAL_ERRORS + )), + 'history_period' => $this->getInput('history_period', CSettingsHelper::get( + CSettingsHelper::HISTORY_PERIOD + )), + 'period_default' => $this->getInput('period_default', CSettingsHelper::get( + CSettingsHelper::PERIOD_DEFAULT + )), + 'max_period' => $this->getInput('max_period', CSettingsHelper::get(CSettingsHelper::MAX_PERIOD)) ]; $response = new CControllerResponseData($data); diff --git a/ui/app/controllers/CControllerGuiUpdate.php b/ui/app/controllers/CControllerGuiUpdate.php index 9129441eb29..580d2291bc7 100644 --- a/ui/app/controllers/CControllerGuiUpdate.php +++ b/ui/app/controllers/CControllerGuiUpdate.php @@ -24,12 +24,18 @@ class CControllerGuiUpdate extends CController { protected function checkInput() { $themes = array_keys(APP::getThemes()); $fields = [ - 'default_lang' => 'db config.default_lang|in '.implode(',', array_keys(getLocales())), - 'default_timezone' => 'required|in '.ZBX_DEFAULT_TIMEZONE.','.implode(',', DateTimeZone::listIdentifiers()).'|db config.default_timezone', - 'default_theme' => 'required|db config.default_theme|in '.implode(',', $themes), - 'search_limit' => 'required|db config.search_limit|ge 1|le 999999', - 'max_in_table' => 'required|db config.max_in_table|ge 1|le 99999', - 'server_check_interval' => 'required|db config.server_check_interval|in 0,'.SERVER_CHECK_INTERVAL + 'default_lang' => 'db config.default_lang|in '.implode(',', array_keys(getLocales())), + 'default_timezone' => 'required|in '.ZBX_DEFAULT_TIMEZONE.','.implode(',', DateTimeZone::listIdentifiers()).'|db config.default_timezone', + 'default_theme' => 'required|db config.default_theme|in '.implode(',', $themes), + 'search_limit' => 'required|db config.search_limit|ge 1|le 999999', + 'max_overview_table_size' => 'required|db config.max_overview_table_size|ge 5|le 999999', + 'max_in_table' => 'required|db config.max_in_table|ge 1|le 99999', + 'server_check_interval' => 'required|db config.server_check_interval|in 0,'.SERVER_CHECK_INTERVAL, + 'work_period' => 'required|db config.work_period|time_periods', + 'show_technical_errors' => 'db config.show_technical_errors|in 0,1', + 'history_period' => 'required|db config.history_period|time_unit '.implode(':', [SEC_PER_DAY, 7 * SEC_PER_DAY]), + 'period_default' => 'required|db config.period_default|time_unit_year '.implode(':', [SEC_PER_MIN, 10 * SEC_PER_YEAR]), + 'max_period' => 'required|db config.max_period|time_unit_year '.implode(':', [SEC_PER_YEAR, 10 * SEC_PER_YEAR]) ]; $ret = $this->validateInput($fields); @@ -60,15 +66,25 @@ class CControllerGuiUpdate extends CController { } protected function doAction() { - $data = []; + $settings = [ + CSettingsHelper::DEFAULT_THEME => $this->getInput('default_theme'), + CSettingsHelper::DEFAULT_TIMEZONE => $this->getInput('default_timezone'), + CSettingsHelper::SEARCH_LIMIT => $this->getInput('search_limit'), + CSettingsHelper::MAX_OVERVIEW_TABLE_SIZE => $this->getInput('max_overview_table_size'), + CSettingsHelper::MAX_IN_TABLE => $this->getInput('max_in_table'), + CSettingsHelper::SERVER_CHECK_INTERVAL => $this->getInput('server_check_interval'), + CSettingsHelper::WORK_PERIOD => $this->getInput('work_period'), + CSettingsHelper::SHOW_TECHNICAL_ERRORS => $this->getInput('show_technical_errors', 0), + CSettingsHelper::HISTORY_PERIOD => $this->getInput('history_period'), + CSettingsHelper::PERIOD_DEFAULT => $this->getInput('period_default'), + CSettingsHelper::MAX_PERIOD => $this->getInput('max_period') + ]; - $this->getInputs($data, ['default_lang', 'default_timezone', 'default_theme', 'search_limit', 'max_in_table', - 'server_check_interval' - ]); + if ($this->hasInput('default_lang')) { + $settings[CSettingsHelper::DEFAULT_LANG] = $this->getInput('default_lang'); + } - DBstart(); - $result = update_config($data); - $result = DBend($result); + $result = API::Settings()->update($settings); $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) ->setArgument('action', 'gui.edit') diff --git a/ui/app/controllers/CControllerHost.php b/ui/app/controllers/CControllerHost.php index 8d0de19416b..8de30e98e04 100644 --- a/ui/app/controllers/CControllerHost.php +++ b/ui/app/controllers/CControllerHost.php @@ -86,9 +86,7 @@ abstract class CControllerHost extends CController { $groupids = array_keys($filter_groups); } - - $config = select_config(); - + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1; $hosts = API::Host()->get([ 'output' => ['hostid', 'name', 'status'], 'evaltype' => $filter['evaltype'], @@ -112,7 +110,7 @@ abstract class CControllerHost extends CController { : HOST_MAINTENANCE_STATUS_OFF, ], 'sortfield' => 'name', - 'limit' => $config['search_limit'] + 1, + 'limit' => $limit, 'preservekeys' => true ]); @@ -238,8 +236,7 @@ abstract class CControllerHost extends CController { 'hosts' => $hosts, 'maintenances' => $maintenances, 'multiselect_hostgroup_data' => $multiselect_hostgroup_data, - 'filter' => $filter, - 'config' => $config + 'filter' => $filter ]; } } diff --git a/ui/app/controllers/CControllerHousekeepingEdit.php b/ui/app/controllers/CControllerHousekeepingEdit.php index 0ee9fb8c025..c5bad8b810d 100644 --- a/ui/app/controllers/CControllerHousekeepingEdit.php +++ b/ui/app/controllers/CControllerHousekeepingEdit.php @@ -62,30 +62,56 @@ class CControllerHousekeepingEdit extends CController { } protected function doAction() { - $config = select_config(); - $data = [ - 'hk_events_mode' => $this->getInput('hk_events_mode', $config['hk_events_mode']), - 'hk_events_trigger' => $this->getInput('hk_events_trigger', $config['hk_events_trigger']), - 'hk_events_internal' => $this->getInput('hk_events_internal', $config['hk_events_internal']), - 'hk_events_discovery' => $this->getInput('hk_events_discovery', $config['hk_events_discovery']), - 'hk_events_autoreg' => $this->getInput('hk_events_autoreg', $config['hk_events_autoreg']), - 'hk_services_mode' => $this->getInput('hk_services_mode', $config['hk_services_mode']), - 'hk_services' => $this->getInput('hk_services', $config['hk_services']), - 'hk_audit_mode' => $this->getInput('hk_audit_mode', $config['hk_audit_mode']), - 'hk_audit' => $this->getInput('hk_audit', $config['hk_audit']), - 'hk_sessions_mode' => $this->getInput('hk_sessions_mode', $config['hk_sessions_mode']), - 'hk_sessions' => $this->getInput('hk_sessions', $config['hk_sessions']), - 'hk_history_mode' => $this->getInput('hk_history_mode', $config['hk_history_mode']), - 'hk_history_global' => $this->getInput('hk_history_global', $config['hk_history_global']), - 'hk_history' => $this->getInput('hk_history', $config['hk_history']), - 'hk_trends_mode' => $this->getInput('hk_trends_mode', $config['hk_trends_mode']), - 'hk_trends_global' => $this->getInput('hk_trends_global', $config['hk_trends_global']), - 'hk_trends' => $this->getInput('hk_trends', $config['hk_trends']), - 'compression_status' => $this->getInput('compression_status', $config['compression_status']), - 'compress_older' => $this->getInput('compress_older', $config['compress_older']), - 'db_extension' => $config['db_extension'], - 'compression_availability' => $config['compression_availability'] + 'hk_events_mode' => $this->getInput('hk_events_mode', CHousekeepingHelper::get( + CHousekeepingHelper::HK_EVENTS_MODE + )), + 'hk_events_trigger' => $this->getInput('hk_events_trigger', CHousekeepingHelper::get( + CHousekeepingHelper::HK_EVENTS_TRIGGER + )), + 'hk_events_internal' => $this->getInput('hk_events_internal', CHousekeepingHelper::get( + CHousekeepingHelper::HK_EVENTS_INTERNAL + )), + 'hk_events_discovery' => $this->getInput('hk_events_discovery', CHousekeepingHelper::get( + CHousekeepingHelper::HK_EVENTS_DISCOVERY + )), + 'hk_events_autoreg' => $this->getInput('hk_events_autoreg', CHousekeepingHelper::get( + CHousekeepingHelper::HK_EVENTS_AUTOREG + )), + 'hk_services_mode' => $this->getInput('hk_services_mode', CHousekeepingHelper::get( + CHousekeepingHelper::HK_SERVICES_MODE + )), + 'hk_services' => $this->getInput('hk_services', CHousekeepingHelper::get(CHousekeepingHelper::HK_SERVICES)), + 'hk_audit_mode' => $this->getInput('hk_audit_mode', CHousekeepingHelper::get( + CHousekeepingHelper::HK_AUDIT_MODE + )), + 'hk_audit' => $this->getInput('hk_audit', CHousekeepingHelper::get(CHousekeepingHelper::HK_AUDIT)), + 'hk_sessions_mode' => $this->getInput('hk_sessions_mode', CHousekeepingHelper::get( + CHousekeepingHelper::HK_SESSIONS_MODE + )), + 'hk_sessions' => $this->getInput('hk_sessions', CHousekeepingHelper::get(CHousekeepingHelper::HK_SESSIONS)), + 'hk_history_mode' => $this->getInput('hk_history_mode', CHousekeepingHelper::get( + CHousekeepingHelper::HK_HISTORY_MODE + )), + 'hk_history_global' => $this->getInput('hk_history_global', CHousekeepingHelper::get( + CHousekeepingHelper::HK_HISTORY_GLOBAL + )), + 'hk_history' => $this->getInput('hk_history', CHousekeepingHelper::get(CHousekeepingHelper::HK_HISTORY)), + 'hk_trends_mode' => $this->getInput('hk_trends_mode', CHousekeepingHelper::get( + CHousekeepingHelper::HK_TRENDS_MODE + )), + 'hk_trends_global' => $this->getInput('hk_trends_global', CHousekeepingHelper::get( + CHousekeepingHelper::HK_TRENDS_GLOBAL + )), + 'hk_trends' => $this->getInput('hk_trends', CHousekeepingHelper::get(CHousekeepingHelper::HK_TRENDS)), + 'compression_status' => $this->getInput('compression_status', CHousekeepingHelper::get( + CHousekeepingHelper::COMPRESSION_STATUS + )), + 'compress_older' => $this->getInput('compress_older', CHousekeepingHelper::get( + CHousekeepingHelper::COMPRESS_OLDER + )), + 'db_extension' => CHousekeepingHelper::get(CHousekeepingHelper::DB_EXTENSION), + 'compression_availability' => CHousekeepingHelper::get(CHousekeepingHelper::COMPRESSION_AVAILABILITY) ]; $response = new CControllerResponseData($data); diff --git a/ui/app/controllers/CControllerHousekeepingUpdate.php b/ui/app/controllers/CControllerHousekeepingUpdate.php index ea2a3fdb458..6a747348ca8 100644 --- a/ui/app/controllers/CControllerHousekeepingUpdate.php +++ b/ui/app/controllers/CControllerHousekeepingUpdate.php @@ -23,25 +23,25 @@ class CControllerHousekeepingUpdate extends CController { protected function checkInput() { $fields = [ - 'hk_trends' => 'db config.hk_trends', + 'hk_trends' => 'db config.hk_trends|time_unit 0,'.implode(':', [SEC_PER_DAY, 25 * SEC_PER_YEAR]), 'hk_trends_global' => 'db config.hk_trends_global | in 1', 'hk_trends_mode' => 'db config.hk_trends_mode', - 'hk_history' => 'db config.hk_history', + 'hk_history' => 'db config.hk_history|time_unit 0,'.implode(':', [SEC_PER_HOUR, 25 * SEC_PER_YEAR]), 'hk_history_global' => 'db config.hk_history_global | in 1', 'hk_history_mode' => 'db config.hk_history_mode', - 'hk_sessions' => 'db config.hk_sessions', + 'hk_sessions' => 'db config.hk_sessions|time_unit '.implode(':', [SEC_PER_DAY, 25 * SEC_PER_YEAR]), 'hk_sessions_mode' => 'db config.hk_sessions_mode | in 1', - 'hk_audit' => 'db config.hk_audit', + 'hk_audit' => 'db config.hk_audit|time_unit '.implode(':', [SEC_PER_DAY, 25 * SEC_PER_YEAR]), 'hk_audit_mode' => 'db config.hk_audit_mode | in 1', - 'hk_services' => 'db config.hk_services', + 'hk_services' => 'db config.hk_services|time_unit '.implode(':', [SEC_PER_DAY, 25 * SEC_PER_YEAR]), 'hk_services_mode' => 'db config.hk_services_mode | in 1', - 'hk_events_autoreg' => 'db config.hk_events_autoreg', - 'hk_events_discovery' => 'db config.hk_events_discovery', - 'hk_events_internal' => 'db config.hk_events_internal', - 'hk_events_trigger' => 'db config.hk_events_trigger', + 'hk_events_autoreg' => 'db config.hk_events_autoreg|time_unit '.implode(':', [SEC_PER_DAY, 25 * SEC_PER_YEAR]), + 'hk_events_discovery' => 'db config.hk_events_discovery|time_unit '.implode(':', [SEC_PER_DAY, 25 * SEC_PER_YEAR]), + 'hk_events_internal' => 'db config.hk_events_internal|time_unit '.implode(':', [SEC_PER_DAY, 25 * SEC_PER_YEAR]), + 'hk_events_trigger' => 'db config.hk_events_trigger|time_unit '.implode(':', [SEC_PER_DAY, 25 * SEC_PER_YEAR]), 'hk_events_mode' => 'db config.hk_events_mode | in 1', 'compression_status' => 'db config.compression_status | in 1', - 'compress_older' => 'db config.compress_older' + 'compress_older' => 'db config.compress_older|time_unit '.implode(':', [7 * SEC_PER_DAY, 25 * SEC_PER_YEAR]) ]; $ret = $this->validateInput($fields); @@ -71,48 +71,52 @@ class CControllerHousekeepingUpdate extends CController { } protected function doAction() { - $config = [ - 'hk_events_mode' => $this->getInput('hk_events_mode', 0), - 'hk_services_mode' => $this->getInput('hk_services_mode', 0), - 'hk_audit_mode' => $this->getInput('hk_audit_mode', 0), - 'hk_sessions_mode' => $this->getInput('hk_sessions_mode', 0), - 'hk_history_mode' => $this->getInput('hk_history_mode', 0), - 'hk_history_global' => $this->getInput('hk_history_global', 0), - 'hk_trends_mode' => $this->getInput('hk_trends_mode', 0), - 'hk_trends_global' => $this->getInput('hk_trends_global', 0), - 'compression_status' => $this->getInput('compression_status', 0), - 'compress_older' => $this->getInput('compress_older', DB::getDefault('config', 'compress_older')) + $hk = [ + CHousekeepingHelper::HK_EVENTS_MODE => $this->getInput('hk_events_mode', 0), + CHousekeepingHelper::HK_SERVICES_MODE => $this->getInput('hk_services_mode', 0), + CHousekeepingHelper::HK_AUDIT_MODE => $this->getInput('hk_audit_mode', 0), + CHousekeepingHelper::HK_SESSIONS_MODE => $this->getInput('hk_sessions_mode', 0), + CHousekeepingHelper::HK_HISTORY_MODE => $this->getInput('hk_history_mode', 0), + CHousekeepingHelper::HK_HISTORY_GLOBAL => $this->getInput('hk_history_global', 0), + CHousekeepingHelper::HK_TRENDS_MODE => $this->getInput('hk_trends_mode', 0), + CHousekeepingHelper::HK_TRENDS_GLOBAL => $this->getInput('hk_trends_global', 0), + CHousekeepingHelper::COMPRESSION_STATUS => $this->getInput('compression_status', 0), + CHousekeepingHelper::COMPRESS_OLDER => $this->getInput('compress_older', DB::getDefault('config', + 'compress_older' + )) ]; - if ($config['hk_events_mode'] == 1) { - $this->getInputs($config, - ['hk_events_trigger', 'hk_events_internal', 'hk_events_discovery', 'hk_events_autoreg'] - ); + if ($hk[CHousekeepingHelper::COMPRESSION_STATUS] === 0) { + unset($hk[CHousekeepingHelper::COMPRESS_OLDER]); } - if ($config['hk_services_mode'] == 1) { - $config['hk_services'] = $this->getInput('hk_services'); + if ($hk[CHousekeepingHelper::HK_EVENTS_MODE] == 1) { + $this->getInputs($hk, [CHousekeepingHelper::HK_EVENTS_TRIGGER, CHousekeepingHelper::HK_EVENTS_INTERNAL, + CHousekeepingHelper::HK_EVENTS_DISCOVERY, CHousekeepingHelper::HK_EVENTS_AUTOREG + ]); } - if ($config['hk_audit_mode'] == 1) { - $config['hk_audit'] = $this->getInput('hk_audit'); + if ($hk[CHousekeepingHelper::HK_SERVICES_MODE] == 1) { + $hk[CHousekeepingHelper::HK_SERVICES] = $this->getInput('hk_services'); } - if ($config['hk_sessions_mode'] == 1) { - $config['hk_sessions'] = $this->getInput('hk_sessions'); + if ($hk[CHousekeepingHelper::HK_AUDIT_MODE] == 1) { + $hk[CHousekeepingHelper::HK_AUDIT] = $this->getInput('hk_audit'); } - if ($config['hk_history_global'] == 1) { - $config['hk_history'] = $this->getInput('hk_history'); + if ($hk[CHousekeepingHelper::HK_SESSIONS_MODE] == 1) { + $hk[CHousekeepingHelper::HK_SESSIONS] = $this->getInput('hk_sessions'); } - if ($config['hk_trends_global'] == 1) { - $config['hk_trends'] = $this->getInput('hk_trends'); + if ($hk[CHousekeepingHelper::HK_HISTORY_GLOBAL] == 1) { + $hk[CHousekeepingHelper::HK_HISTORY] = $this->getInput('hk_history'); } - DBstart(); - $result = update_config($config); - $result = DBend($result); + if ($hk[CHousekeepingHelper::HK_TRENDS_GLOBAL] == 1) { + $hk[CHousekeepingHelper::HK_TRENDS] = $this->getInput('hk_trends'); + } + + $result = API::Housekeeping()->update($hk); $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) ->setArgument('action', 'housekeeping.edit') diff --git a/ui/app/controllers/CControllerLatest.php b/ui/app/controllers/CControllerLatest.php index 419b608faae..ed1a23e057c 100644 --- a/ui/app/controllers/CControllerLatest.php +++ b/ui/app/controllers/CControllerLatest.php @@ -37,8 +37,6 @@ abstract class CControllerLatest extends CController { * @param string $sort_order Sorting order. */ protected function prepareData(array $filter, $sort_field, $sort_order) { - $config = select_config(); - $multiselect_hostgroup_data = []; $multiselect_host_data = []; @@ -172,13 +170,14 @@ abstract class CControllerLatest extends CController { }); $select_items = []; + $history_period = timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::HISTORY_PERIOD)); foreach ($items_of_hosts as $host_items) { $select_items += $filter['show_without_data'] ? $host_items - : Manager::History()->getItemsHavingValues($host_items, ZBX_HISTORY_PERIOD); + : Manager::History()->getItemsHavingValues($host_items, $history_period); - if (count($select_items) > $config['search_limit']) { + if (count($select_items) > CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT)) { break; } } @@ -267,7 +266,7 @@ abstract class CControllerLatest extends CController { 'applicationid' => $applicationid ]; - if (count($rows) > $config['search_limit']) { + if (count($rows) > CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT)) { break 3; } } @@ -281,7 +280,7 @@ abstract class CControllerLatest extends CController { $items = CMacrosResolverHelper::resolveTimeUnitMacros($items, ['delay', 'history', 'trends']); // Choosing max history period for already filtered items having data. - $history_period = $filter['show_without_data'] ? ZBX_HISTORY_PERIOD : null; + $history_period = $filter['show_without_data'] ? $history_period : null; $history = Manager::History()->getLastValues($items, 2, $history_period); } diff --git a/ui/app/controllers/CControllerLatestView.php b/ui/app/controllers/CControllerLatestView.php index f6465d76e66..2e474cefeca 100644 --- a/ui/app/controllers/CControllerLatestView.php +++ b/ui/app/controllers/CControllerLatestView.php @@ -130,7 +130,13 @@ class CControllerLatestView extends CControllerLatest { 'refresh_url' => $refresh_curl->getUrl(), 'refresh_interval' => CWebUser::getRefresh() * 1000, 'active_tab' => CProfile::get('web.latest.filter.active', 1), - 'paging' => $paging + 'paging' => $paging, + 'config' => [ + 'hk_trends' => CHousekeepingHelper::get(CHousekeepingHelper::HK_TRENDS), + 'hk_trends_global' => CHousekeepingHelper::get(CHousekeepingHelper::HK_TRENDS_GLOBAL), + 'hk_history' => CHousekeepingHelper::get(CHousekeepingHelper::HK_HISTORY), + 'hk_history_global' => CHousekeepingHelper::get(CHousekeepingHelper::HK_HISTORY_GLOBAL) + ] ] + $prepared_data; $response = new CControllerResponseData($data); diff --git a/ui/app/controllers/CControllerLatestViewRefresh.php b/ui/app/controllers/CControllerLatestViewRefresh.php index 6da872d6d83..19cf1dda3a0 100644 --- a/ui/app/controllers/CControllerLatestViewRefresh.php +++ b/ui/app/controllers/CControllerLatestViewRefresh.php @@ -85,7 +85,13 @@ class CControllerLatestViewRefresh extends CControllerLatest { 'sort_field' => $sort_field, 'sort_order' => $sort_order, 'view_curl' => $view_curl, - 'paging' => $paging + 'paging' => $paging, + 'config' => [ + 'hk_trends' => CHousekeepingHelper::get(CHousekeepingHelper::HK_TRENDS), + 'hk_trends_global' => CHousekeepingHelper::get(CHousekeepingHelper::HK_TRENDS_GLOBAL), + 'hk_history' => CHousekeepingHelper::get(CHousekeepingHelper::HK_HISTORY), + 'hk_history_global' => CHousekeepingHelper::get(CHousekeepingHelper::HK_HISTORY_GLOBAL) + ] ] + $prepared_data; $response = new CControllerResponseData($data); diff --git a/ui/app/controllers/CControllerMapView.php b/ui/app/controllers/CControllerMapView.php index d012471d7ab..c8e0ee5b9b4 100644 --- a/ui/app/controllers/CControllerMapView.php +++ b/ui/app/controllers/CControllerMapView.php @@ -115,10 +115,9 @@ class CControllerMapView extends CController { 'editable' => true ]); - $config = select_config(); $severities_dropdown = []; for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_COUNT; $severity++) { - $severity_name = getSeverityName($severity, $config); + $severity_name = getSeverityName($severity); $severities_dropdown[$severity] = ($severity == $map['severity_min']) ? $severity_name.' ('._('default').')' diff --git a/ui/app/controllers/CControllerMediatypeList.php b/ui/app/controllers/CControllerMediatypeList.php index c50bf76fca6..e13e12eae8f 100644 --- a/ui/app/controllers/CControllerMediatypeList.php +++ b/ui/app/controllers/CControllerMediatypeList.php @@ -70,8 +70,6 @@ class CControllerMediatypeList extends CController { 'status' => CProfile::get('web.media_types.filter_status', -1) ]; - $config = select_config(); - $data = [ 'uncheck' => $this->hasInput('uncheck'), 'sort' => $sortField, @@ -82,6 +80,7 @@ class CControllerMediatypeList extends CController { ]; // get media types + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1; $data['mediatypes'] = API::Mediatype()->get([ 'output' => ['mediatypeid', 'name', 'type', 'smtp_server', 'smtp_helo', 'smtp_email', 'exec_path', 'gsm_modem', 'username', 'status' @@ -92,7 +91,7 @@ class CControllerMediatypeList extends CController { 'filter' => [ 'status' => ($filter['status'] == -1) ? null : $filter['status'] ], - 'limit' => $config['search_limit'] + 1, + 'limit' => $limit, 'editable' => true, 'preservekeys' => true ]); diff --git a/ui/app/controllers/CControllerMiscConfigEdit.php b/ui/app/controllers/CControllerMiscConfigEdit.php index f402563da9f..13f8aad09b1 100644 --- a/ui/app/controllers/CControllerMiscConfigEdit.php +++ b/ui/app/controllers/CControllerMiscConfigEdit.php @@ -27,11 +27,23 @@ class CControllerMiscConfigEdit extends CController { protected function checkInput() { $fields = [ - 'refresh_unsupported' => 'string', - 'discovery_groupid' => 'db hstgrp.groupid', - 'default_inventory_mode' => 'in '.HOST_INVENTORY_DISABLED.','.HOST_INVENTORY_MANUAL.','.HOST_INVENTORY_AUTOMATIC, - 'alert_usrgrpid' => 'db usrgrp.usrgrpid', - 'snmptrap_logging' => 'in 0,1' + 'refresh_unsupported' => 'db config.refresh_unsupported', + 'discovery_groupid' => 'db config.discovery_groupid', + 'default_inventory_mode' => 'db config.default_inventory_mode', + 'alert_usrgrpid' => 'db config.alert_usrgrpid', + 'snmptrap_logging' => 'db config.snmptrap_logging', + 'login_attempts' => 'db config.login_attempts', + 'login_block' => 'db config.login_block', + 'validate_uri_schemes' => 'db config.validate_uri_schemes', + 'uri_valid_schemes' => 'db config.uri_valid_schemes', + 'x_frame_options' => 'db config.x_frame_options', + 'iframe_sandboxing_enabled' => 'db config.iframe_sandboxing_enabled', + 'iframe_sandboxing_exceptions' => 'db config.iframe_sandboxing_exceptions', + 'socket_timeout' => 'db config.socket_timeout', + 'connect_timeout' => 'db config.connect_timeout', + 'media_type_test_timeout' => 'db config.media_type_test_timeout', + 'script_timeout' => 'db config.script_timeout', + 'item_test_timeout' => 'db config.item_test_timeout' ]; $ret = $this->validateInput($fields); @@ -48,25 +60,73 @@ class CControllerMiscConfigEdit extends CController { } protected function doAction() { - $config = select_config(); - $data = [ - 'refresh_unsupported' => $this->getInput('refresh_unsupported', $config['refresh_unsupported']), - 'discovery_groupid' => $this->getInput('discovery_groupid', $config['discovery_groupid']), - 'default_inventory_mode' => $this->getInput('default_inventory_mode', $config['default_inventory_mode']), - 'alert_usrgrpid' => $this->getInput('alert_usrgrpid', $config['alert_usrgrpid']), - 'snmptrap_logging' => $this->getInput('snmptrap_logging', $config['snmptrap_logging']) + 'refresh_unsupported' => $this->getInput('refresh_unsupported', CSettingsHelper::get( + CSettingsHelper::REFRESH_UNSUPPORTED + )), + 'discovery_groupid' => $this->getInput('discovery_groupid', CSettingsHelper::get( + CSettingsHelper::DISCOVERY_GROUPID + )), + 'default_inventory_mode' => $this->getInput('default_inventory_mode', CSettingsHelper::get( + CSettingsHelper::DEFAULT_INVENTORY_MODE + )), + 'alert_usrgrpid' => $this->getInput('alert_usrgrpid', CSettingsHelper::get( + CSettingsHelper::ALERT_USRGRPID + )), + 'snmptrap_logging' => $this->getInput('snmptrap_logging', CSettingsHelper::get( + CSettingsHelper::SNMPTRAP_LOGGING + )), + 'login_attempts' => $this->getInput('login_attempts', CSettingsHelper::get( + CSettingsHelper::LOGIN_ATTEMPTS + )), + 'login_block' => $this->getInput('login_block', CSettingsHelper::get(CSettingsHelper::LOGIN_BLOCK)), + 'validate_uri_schemes' => $this->getInput('validate_uri_schemes', CSettingsHelper::get( + CSettingsHelper::VALIDATE_URI_SCHEMES + )), + 'uri_valid_schemes' => $this->getInput('uri_valid_schemes', CSettingsHelper::get( + CSettingsHelper::URI_VALID_SCHEMES + )), + 'x_frame_options' => $this->getInput('x_frame_options', CSettingsHelper::get( + CSettingsHelper::X_FRAME_OPTIONS + )), + 'iframe_sandboxing_enabled' => $this->getInput('iframe_sandboxing_enabled', CSettingsHelper::get( + CSettingsHelper::IFRAME_SANDBOXING_ENABLED + )), + 'iframe_sandboxing_exceptions' => $this->getInput('iframe_sandboxing_exceptions', CSettingsHelper::get( + CSettingsHelper::IFRAME_SANDBOXING_EXCEPTIONS + )), + 'socket_timeout' => $this->getInput('socket_timeout', CSettingsHelper::get( + CSettingsHelper::SOCKET_TIMEOUT + )), + 'connect_timeout' => $this->getInput('connect_timeout', CSettingsHelper::get( + CSettingsHelper::CONNECT_TIMEOUT + )), + 'media_type_test_timeout' => $this->getInput('media_type_test_timeout', CSettingsHelper::get( + CSettingsHelper::MEDIA_TYPE_TEST_TIMEOUT + )), + 'script_timeout' => $this->getInput('script_timeout', CSettingsHelper::get( + CSettingsHelper::SCRIPT_TIMEOUT + )), + 'item_test_timeout' => $this->getInput('item_test_timeout', CSettingsHelper::get( + CSettingsHelper::ITEM_TEST_TIMEOUT + )) ]; - $data['discovery_groups'] = API::HostGroup()->get([ + $data['discovery_group_data'] = API::HostGroup()->get([ 'output' => ['groupid', 'name'], 'filter' => ['flags' => ZBX_FLAG_DISCOVERY_NORMAL], + 'groupids' => $data['discovery_groupid'], 'editable' => true ]); - order_result($data['discovery_groups'], 'name'); + $data['discovery_group_data'] = CArrayHelper::renameObjectsKeys($data['discovery_group_data'], + ['groupid' => 'id'] + ); - $data['alert_usrgrps'] = DBfetchArray(DBselect('SELECT u.usrgrpid,u.name FROM usrgrp u')); - order_result($data['alert_usrgrps'], 'name'); + $data['alert_usrgrp_data'] = API::UserGroup()->get([ + 'output' => ['usrgrpid', 'name'], + 'usrgrpids' => $data['alert_usrgrpid'] + ]); + $data['alert_usrgrp_data'] = CArrayHelper::renameObjectsKeys($data['alert_usrgrp_data'], ['usrgrpid' => 'id']); $response = new CControllerResponseData($data); $response->setTitle(_('Other configuration parameters')); diff --git a/ui/app/controllers/CControllerMiscConfigUpdate.php b/ui/app/controllers/CControllerMiscConfigUpdate.php index a1534a8e527..40b0bd39e8b 100644 --- a/ui/app/controllers/CControllerMiscConfigUpdate.php +++ b/ui/app/controllers/CControllerMiscConfigUpdate.php @@ -23,11 +23,23 @@ class CControllerMiscConfigUpdate extends CController { protected function checkInput() { $fields = [ - 'refresh_unsupported' => 'string', - 'discovery_groupid' => 'db hstgrp.groupid', - 'default_inventory_mode' => 'in '.HOST_INVENTORY_DISABLED.','.HOST_INVENTORY_MANUAL.','.HOST_INVENTORY_AUTOMATIC, - 'alert_usrgrpid' => 'db usrgrp.usrgrpid', - 'snmptrap_logging' => 'in 0,1' + 'refresh_unsupported' => 'required|db config.refresh_unsupported|time_unit '.implode(':', [0, SEC_PER_DAY]), + 'discovery_groupid' => 'required|db config.discovery_groupid', + 'default_inventory_mode' => 'required|in '.HOST_INVENTORY_DISABLED.','.HOST_INVENTORY_MANUAL.','.HOST_INVENTORY_AUTOMATIC, + 'alert_usrgrpid' => 'db config.alert_usrgrpid', + 'snmptrap_logging' => 'required|db config.snmptrap_logging|in 0,1', + 'login_attempts' => 'required|db config.login_attempts|ge 1|le 32', + 'login_block' => 'required|db config.login_block|time_unit '.implode(':', [30, SEC_PER_HOUR]), + 'validate_uri_schemes' => 'required|db config.validate_uri_schemes|in 0,1', + 'uri_valid_schemes' => 'db config.uri_valid_schemes', + 'x_frame_options' => 'required|db config.x_frame_options|not_empty', + 'iframe_sandboxing_enabled' => 'required|db config.iframe_sandboxing_enabled|in 0,1', + 'iframe_sandboxing_exceptions' => 'db config.iframe_sandboxing_exceptions', + 'socket_timeout' => 'required|db config.socket_timeout|time_unit '.implode(':', [1, 300]), + 'connect_timeout' => 'required|db config.connect_timeout|time_unit '.implode(':', [1, 30]), + 'media_type_test_timeout' => 'required|db config.media_type_test_timeout|time_unit '.implode(':', [1, 300]), + 'script_timeout' => 'required|db config.script_timeout|time_unit '.implode(':', [1, 300]), + 'item_test_timeout' => 'required|db config.item_test_timeout|time_unit '.implode(':', [1, 300]) ]; $ret = $this->validateInput($fields); @@ -39,7 +51,10 @@ class CControllerMiscConfigUpdate extends CController { ->setArgument('action', 'miscconfig.edit') ); - $response->setFormData($this->getInputAll()); + $response->setFormData($this->getInputAll() + [ + 'discovery_groupid' => '0', + 'alert_usrgrpid' => '0' + ]); $response->setMessageError(_('Cannot update configuration')); $this->setResponse($response); @@ -59,20 +74,45 @@ class CControllerMiscConfigUpdate extends CController { } protected function doAction() { + $settings = [ + CSettingsHelper::REFRESH_UNSUPPORTED => $this->getInput('refresh_unsupported'), + CSettingsHelper::DISCOVERY_GROUPID => $this->getInput('discovery_groupid'), + CSettingsHelper::DEFAULT_INVENTORY_MODE => $this->getInput('default_inventory_mode'), + CSettingsHelper::SNMPTRAP_LOGGING => $this->getInput('snmptrap_logging'), + CSettingsHelper::LOGIN_ATTEMPTS => $this->getInput('login_attempts'), + CSettingsHelper::LOGIN_BLOCK => $this->getInput('login_block'), + CSettingsHelper::VALIDATE_URI_SCHEMES => $this->getInput('validate_uri_schemes'), + CSettingsHelper::X_FRAME_OPTIONS => $this->getInput('x_frame_options'), + CSettingsHelper::IFRAME_SANDBOXING_ENABLED => $this->getInput('iframe_sandboxing_enabled'), + CSettingsHelper::SOCKET_TIMEOUT => $this->getInput('socket_timeout'), + CSettingsHelper::CONNECT_TIMEOUT => $this->getInput('connect_timeout'), + CSettingsHelper::MEDIA_TYPE_TEST_TIMEOUT => $this->getInput('media_type_test_timeout'), + CSettingsHelper::SCRIPT_TIMEOUT => $this->getInput('script_timeout'), + CSettingsHelper::ITEM_TEST_TIMEOUT => $this->getInput('item_test_timeout') + ]; + + $settings[CSettingsHelper::ALERT_USRGRPID] = $this->hasInput('alert_usrgrpid') + ? $this->getInput('alert_usrgrpid') + : null; + + if ($settings[CSettingsHelper::VALIDATE_URI_SCHEMES] == 1) { + $settings[CSettingsHelper::URI_VALID_SCHEMES] = $this->getInput('uri_valid_schemes', + DB::getSchema('config')['fields']['uri_valid_schemes']['default'] + ); + } + + if ($settings[CSettingsHelper::IFRAME_SANDBOXING_ENABLED] == 1) { + $settings[CSettingsHelper::IFRAME_SANDBOXING_EXCEPTIONS] = $this->getInput('iframe_sandboxing_exceptions', + DB::getSchema('config')['fields']['iframe_sandboxing_exceptions']['default'] + ); + } + + $result = API::Settings()->update($settings); + $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) ->setArgument('action', 'miscconfig.edit') ); - DBstart(); - $result = update_config([ - 'refresh_unsupported' => trim($this->getInput('refresh_unsupported')), - 'alert_usrgrpid' => $this->getInput('alert_usrgrpid'), - 'discovery_groupid' => $this->getInput('discovery_groupid'), - 'default_inventory_mode' => $this->getInput('default_inventory_mode'), - 'snmptrap_logging' => $this->getInput('snmptrap_logging') - ]); - $result = DBend($result); - if ($result) { $response->setMessageOk(_('Configuration updated')); } diff --git a/ui/app/controllers/CControllerModuleList.php b/ui/app/controllers/CControllerModuleList.php index acef10c8b96..be28ec6765c 100644 --- a/ui/app/controllers/CControllerModuleList.php +++ b/ui/app/controllers/CControllerModuleList.php @@ -76,15 +76,14 @@ class CControllerModuleList extends CController { ]; // data prepare - $config = select_config(); - + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1; $db_modules = API::Module()->get([ 'output' => ['id', 'relative_path', 'status'], 'filter' => [ 'status' => ($filter['status'] == -1) ? null : $filter['status'] ], 'sortfield' => 'relative_path', - 'limit' => $config['search_limit'] + 1, + 'limit' => $limit, 'preservekeys' => true ]); diff --git a/ui/app/controllers/CControllerNotificationsGet.php b/ui/app/controllers/CControllerNotificationsGet.php index 604ee3aa10c..1e772334edc 100644 --- a/ui/app/controllers/CControllerNotificationsGet.php +++ b/ui/app/controllers/CControllerNotificationsGet.php @@ -29,8 +29,7 @@ class CControllerNotificationsGet extends CController { $this->notifications = []; $this->settings = getMessageSettings(); - $config = select_config(); - $ok_timeout = (int) timeUnitToSeconds($config['ok_period']); + $ok_timeout = (int) timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::OK_PERIOD)); $timeout = (int) timeUnitToSeconds($this->settings['timeout']); $this->settings['timeout'] = $timeout; $this->settings['ok_timeout'] = min([$timeout, $ok_timeout]); diff --git a/ui/app/controllers/CControllerPopupAcknowledgeEdit.php b/ui/app/controllers/CControllerPopupAcknowledgeEdit.php index de14eaf8bd1..e3bdd843607 100644 --- a/ui/app/controllers/CControllerPopupAcknowledgeEdit.php +++ b/ui/app/controllers/CControllerPopupAcknowledgeEdit.php @@ -93,15 +93,6 @@ class CControllerPopupAcknowledgeEdit extends CController { // Show action list if only one event is requested. if (count($events) == 1) { - $config = select_config(); - $data['config'] = [ - 'severity_name_0' => $config['severity_name_0'], - 'severity_name_1' => $config['severity_name_1'], - 'severity_name_2' => $config['severity_name_2'], - 'severity_name_3' => $config['severity_name_3'], - 'severity_name_4' => $config['severity_name_4'], - 'severity_name_5' => $config['severity_name_5'] - ]; $history = getEventUpdates(reset($events)); $data['history'] = $history['data']; $data['users'] = API::User()->get([ diff --git a/ui/app/controllers/CControllerPopupGeneric.php b/ui/app/controllers/CControllerPopupGeneric.php index c67a5a121da..bc2ce4318fc 100644 --- a/ui/app/controllers/CControllerPopupGeneric.php +++ b/ui/app/controllers/CControllerPopupGeneric.php @@ -796,10 +796,6 @@ class CControllerPopupGeneric extends CController { ] ]; - if ($this->source_table === 'triggers' || $this->source_table === 'trigger_prototypes') { - $data['options']['config'] = select_config(); - } - if (($messages = getMessages()) !== null) { $data['messages'] = $messages; } diff --git a/ui/app/controllers/CControllerPopupItemTestGetValue.php b/ui/app/controllers/CControllerPopupItemTestGetValue.php index bdd224d6ca0..336db58d0c0 100644 --- a/ui/app/controllers/CControllerPopupItemTestGetValue.php +++ b/ui/app/controllers/CControllerPopupItemTestGetValue.php @@ -182,7 +182,9 @@ class CControllerPopupItemTestGetValue extends CControllerPopupItemTest { ]; // Send test to be executed on Zabbix server. - $server = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, ZBX_SOCKET_TIMEOUT, ZBX_SOCKET_BYTES_LIMIT); + $server = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, + timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::ITEM_TEST_TIMEOUT)), ZBX_SOCKET_BYTES_LIMIT + ); $result = $server->testItem($data, CWebUser::getSessionCookie()); // Handle the response. diff --git a/ui/app/controllers/CControllerPopupItemTestSend.php b/ui/app/controllers/CControllerPopupItemTestSend.php index fa9e2a7545f..e5c5a830eab 100644 --- a/ui/app/controllers/CControllerPopupItemTestSend.php +++ b/ui/app/controllers/CControllerPopupItemTestSend.php @@ -292,7 +292,9 @@ class CControllerPopupItemTestSend extends CControllerPopupItemTest { } // Send test to be executed on Zabbix server. - $server = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, ZBX_SOCKET_TIMEOUT, ZBX_SOCKET_BYTES_LIMIT); + $server = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, + timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::ITEM_TEST_TIMEOUT)), ZBX_SOCKET_BYTES_LIMIT + ); $result = $server->testItem($item_test_data, get_cookie('zbx_sessionid')); // Handle the response. @@ -335,7 +337,9 @@ class CControllerPopupItemTestSend extends CControllerPopupItemTest { $preproc_test_data['steps'] = $this->resolvePreprocessingStepMacros($preproc_test_data['steps']); // Send test details to Zabbix server. - $server = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, ZBX_SOCKET_TIMEOUT, ZBX_SOCKET_BYTES_LIMIT); + $server = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, + timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::ITEM_TEST_TIMEOUT)), ZBX_SOCKET_BYTES_LIMIT + ); $result = $server->testPreprocessingSteps($preproc_test_data, get_cookie('zbx_sessionid')); if ($result === false) { diff --git a/ui/app/controllers/CControllerPopupMedia.php b/ui/app/controllers/CControllerPopupMedia.php index 91bf0bc5af9..6d22ce84ed5 100644 --- a/ui/app/controllers/CControllerPopupMedia.php +++ b/ui/app/controllers/CControllerPopupMedia.php @@ -25,9 +25,8 @@ class CControllerPopupMedia extends CController { protected function init() { $this->disableSIDvalidation(); - $config = select_config(); for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_COUNT; $severity++) { - $this->severities[$severity] = getSeverityName($severity, $config); + $this->severities[$severity] = getSeverityName($severity); } } diff --git a/ui/app/controllers/CControllerPopupMediatypeTestSend.php b/ui/app/controllers/CControllerPopupMediatypeTestSend.php index 5db8887a103..1265fcabe34 100644 --- a/ui/app/controllers/CControllerPopupMediatypeTestSend.php +++ b/ui/app/controllers/CControllerPopupMediatypeTestSend.php @@ -130,7 +130,9 @@ class CControllerPopupMediatypeTestSend extends CController { } $params['mediatypeid'] = $this->getInput('mediatypeid'); - $server = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, ZBX_MEDIA_TYPE_TEST_TIMEOUT, ZBX_SOCKET_BYTES_LIMIT); + $server = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, + timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::MEDIA_TYPE_TEST_TIMEOUT)), ZBX_SOCKET_BYTES_LIMIT + ); $result = $server->testMediaType($params, CWebUser::getSessionCookie()); $debug = $server->getDebug(); diff --git a/ui/app/controllers/CControllerPopupTestTriggerExpr.php b/ui/app/controllers/CControllerPopupTestTriggerExpr.php index 1608e034b9e..6ee6d3df5d2 100644 --- a/ui/app/controllers/CControllerPopupTestTriggerExpr.php +++ b/ui/app/controllers/CControllerPopupTestTriggerExpr.php @@ -205,7 +205,9 @@ class CControllerPopupTestTriggerExpr extends CController { global $ZBX_SERVER, $ZBX_SERVER_PORT; - $zabbix_server = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, ZBX_SOCKET_TIMEOUT, 0); + $zabbix_server = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, + timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::SOCKET_TIMEOUT)), 0 + ); $response = $zabbix_server->expressionsEvaluate($data, CWebUser::getSessionCookie()); if ($zabbix_server->getError()) { diff --git a/ui/app/controllers/CControllerProxyList.php b/ui/app/controllers/CControllerProxyList.php index 17d4a64ecfe..83d5dc77ff5 100644 --- a/ui/app/controllers/CControllerProxyList.php +++ b/ui/app/controllers/CControllerProxyList.php @@ -71,20 +71,16 @@ class CControllerProxyList extends CController { 'status' => CProfile::get('web.proxies.filter_status', -1) ]; - $config = select_config(); - $data = [ 'uncheck' => $this->hasInput('uncheck'), 'sort' => $sortField, 'sortorder' => $sortOrder, 'filter' => $filter, - 'config' => [ - 'max_in_table' => $config['max_in_table'] - ], 'profileIdx' => 'web.proxies.filter', 'active_tab' => CProfile::get('web.proxies.filter.active', 1) ]; + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1; $data['proxies'] = API::Proxy()->get([ 'output' => ['proxyid', $sortField], 'search' => [ @@ -94,7 +90,7 @@ class CControllerProxyList extends CController { 'status' => ($filter['status'] == -1) ? null : $filter['status'] ], 'sortfield' => $sortField, - 'limit' => $config['search_limit'] + 1, + 'limit' => $limit, 'editable' => true, 'preservekeys' => true ]); @@ -119,14 +115,16 @@ class CControllerProxyList extends CController { foreach ($data['proxies'] as &$proxy) { order_result($proxy['hosts'], 'name'); - $proxy['hosts'] = array_slice($proxy['hosts'], 0, $data['config']['max_in_table'] + 1); + $proxy['hosts'] = array_slice($proxy['hosts'], 0, CSettingsHelper::get(CSettingsHelper::MAX_IN_TABLE) + 1); } unset($proxy); if ($data['proxies']) { global $ZBX_SERVER, $ZBX_SERVER_PORT; - $server = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, ZBX_SOCKET_TIMEOUT, ZBX_SOCKET_BYTES_LIMIT); + $server = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, + timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::SOCKET_TIMEOUT)), ZBX_SOCKET_BYTES_LIMIT + ); $server_status = $server->getStatus(get_cookie(ZBX_SESSION_NAME)); if ($server_status !== false) { @@ -171,6 +169,8 @@ class CControllerProxyList extends CController { } } + $data['config'] = ['max_in_table' => CSettingsHelper::get(CSettingsHelper::MAX_IN_TABLE)]; + $response = new CControllerResponseData($data); $response->setTitle(_('Configuration of proxies')); $this->setResponse($response); diff --git a/ui/app/controllers/CControllerScriptList.php b/ui/app/controllers/CControllerScriptList.php index 94cecdb77da..47a8c7b9e33 100644 --- a/ui/app/controllers/CControllerScriptList.php +++ b/ui/app/controllers/CControllerScriptList.php @@ -67,8 +67,6 @@ class CControllerScriptList extends CController { 'name' => CProfile::get('web.scripts.filter_name', '') ]; - $config = select_config(); - $data = [ 'uncheck' => $this->hasInput('uncheck'), 'sort' => $sortField, @@ -79,13 +77,14 @@ class CControllerScriptList extends CController { ]; // list of scripts + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1; $data['scripts'] = API::Script()->get([ 'output' => ['scriptid', 'name', 'command', 'host_access', 'usrgrpid', 'groupid', 'type', 'execute_on'], 'search' => [ 'name' => ($filter['name'] === '') ? null : $filter['name'] ], 'editable' => true, - 'limit' => $config['search_limit'] + 1 + 'limit' => $limit ]); // data sort and pager diff --git a/ui/app/controllers/CControllerTimeSelectorUpdate.php b/ui/app/controllers/CControllerTimeSelectorUpdate.php index 6982010dbb1..eb6f4da12e2 100644 --- a/ui/app/controllers/CControllerTimeSelectorUpdate.php +++ b/ui/app/controllers/CControllerTimeSelectorUpdate.php @@ -100,10 +100,16 @@ class CControllerTimeSelectorUpdate extends CController { $value[$field] = $this->getInput($field); $this->range_time_parser->parse($value[$field]); $date_type[$field] = $this->range_time_parser->getTimeType(); - $ts[$field] = $this->range_time_parser->getDateTime($field === 'from')->getTimestamp(); + $ts[$field] = $this->range_time_parser + ->getDateTime($field === 'from') + ->getTimestamp(); } $period = $ts['to'] - $ts['from'] + 1; + $this->range_time_parser->parse('now-'.CSettingsHelper::get(CSettingsHelper::MAX_PERIOD)); + $max_period = 1 + $ts['now'] - $this->range_time_parser + ->getDateTime(true) + ->getTimestamp(); switch ($method) { case 'decrement': @@ -147,8 +153,8 @@ class CControllerTimeSelectorUpdate extends CController { $ts['from'] -= $left_offset; $ts['to'] += $right_offset; - if ($ts['to'] - $ts['from'] + 1 > ZBX_MAX_PERIOD) { - $ts['from'] = $ts['to'] - ZBX_MAX_PERIOD + 1; + if ($ts['to'] - $ts['from'] + 1 > $max_period) { + $ts['from'] = $ts['to'] - $max_period + 1; } $value['from'] = $date->setTimestamp($ts['from'])->format(ZBX_FULL_DATE_TIME); @@ -195,7 +201,7 @@ class CControllerTimeSelectorUpdate extends CController { 'to' => $value['to'], 'to_ts' => $ts['to'], 'to_date' => $date->setTimestamp($ts['to'])->format(ZBX_FULL_DATE_TIME), - 'can_zoomout' => ($ts['to'] - $ts['from'] + 1 < ZBX_MAX_PERIOD), + 'can_zoomout' => ($ts['to'] - $ts['from'] + 1 < $max_period), 'can_decrement' => ($ts['from'] > 0), 'can_increment' => ($ts['to'] < $ts['now'] - ZBX_MIN_PERIOD) ])])); @@ -209,6 +215,7 @@ class CControllerTimeSelectorUpdate extends CController { protected function validateInputDateRange() { $this->data['error'] = []; $ts = []; + $ts['now'] = time(); foreach (['from', 'to'] as $field) { $value = $this->getInput($field); @@ -217,7 +224,9 @@ class CControllerTimeSelectorUpdate extends CController { $this->data['error'][$field] = _('Invalid date.'); } else { - $ts[$field] = $this->range_time_parser->getDateTime($field === 'from')->getTimestamp(); + $ts[$field] = $this->range_time_parser + ->getDateTime($field === 'from') + ->getTimestamp(); } } @@ -231,15 +240,19 @@ class CControllerTimeSelectorUpdate extends CController { } $period = $ts['to'] - $ts['from'] + 1; + $this->range_time_parser->parse('now-'.CSettingsHelper::get(CSettingsHelper::MAX_PERIOD)); + $max_period = 1 + $ts['now'] - $this->range_time_parser + ->getDateTime(true) + ->getTimestamp(); if ($period < ZBX_MIN_PERIOD) { $this->data['error']['from'] = _n('Minimum time period to display is %1$s minute.', 'Minimum time period to display is %1$s minutes.', (int) (ZBX_MIN_PERIOD / SEC_PER_MIN) ); } - elseif ($period > ZBX_MAX_PERIOD) { + elseif ($period > $max_period) { $this->data['error']['from'] = _n('Maximum time period to display is %1$s day.', - 'Maximum time period to display is %1$s days.', (int) (ZBX_MAX_PERIOD / SEC_PER_DAY) + 'Maximum time period to display is %1$s days.', (int) ($max_period / SEC_PER_DAY) ); } diff --git a/ui/app/controllers/CControllerTrigDisplayEdit.php b/ui/app/controllers/CControllerTrigDisplayEdit.php index 18a7d6fe598..dbca5a3f21f 100644 --- a/ui/app/controllers/CControllerTrigDisplayEdit.php +++ b/ui/app/controllers/CControllerTrigDisplayEdit.php @@ -27,17 +27,29 @@ class CControllerTrigDisplayEdit extends CController { protected function checkInput() { $fields = [ - 'custom_color' => 'int32', - 'problem_unack_color' => 'string', - 'problem_ack_color' => 'string', - 'ok_unack_color' => 'string', - 'ok_ack_color' => 'string', - 'problem_unack_style' => 'int32', - 'problem_ack_style' => 'int32', - 'ok_unack_style' => 'int32', - 'ok_ack_style' => 'int32', - 'ok_period' => 'string', - 'blink_period' => 'string' + 'custom_color' => 'db config.custom_color', + 'problem_unack_color' => 'db config.problem_unack_color', + 'problem_ack_color' => 'db config.problem_ack_color', + 'ok_unack_color' => 'db config.ok_unack_color', + 'ok_ack_color' => 'db config.ok_ack_color', + 'problem_unack_style' => 'db config.problem_unack_style', + 'problem_ack_style' => 'db config.problem_ack_style', + 'ok_unack_style' => 'db config.ok_unack_style', + 'ok_ack_style' => 'db config.ok_ack_style', + 'ok_period' => 'db config.ok_period', + 'blink_period' => 'db config.blink_period', + 'severity_name_0' => 'db config.severity_name_0', + 'severity_color_0' => 'db config.severity_color_0', + 'severity_name_1' => 'db config.severity_name_1', + 'severity_color_1' => 'db config.severity_color_1', + 'severity_name_2' => 'db config.severity_name_2', + 'severity_color_2' => 'db config.severity_color_2', + 'severity_name_3' => 'db config.severity_name_3', + 'severity_color_3' => 'db config.severity_color_3', + 'severity_name_4' => 'db config.severity_name_4', + 'severity_color_4' => 'db config.severity_color_4', + 'severity_name_5' => 'db config.severity_name_5', + 'severity_color_5' => 'db config.severity_color_5' ]; $ret = $this->validateInput($fields); @@ -54,20 +66,66 @@ class CControllerTrigDisplayEdit extends CController { } protected function doAction() { - $config = select_config(); - $data = [ - 'custom_color' => $this->getInput('custom_color', $config['custom_color']), - 'problem_unack_color' => $this->getInput('problem_unack_color', $config['problem_unack_color']), - 'problem_ack_color' => $this->getInput('problem_ack_color', $config['problem_ack_color']), - 'ok_unack_color' => $this->getInput('ok_unack_color', $config['ok_unack_color']), - 'ok_ack_color' => $this->getInput('ok_ack_color', $config['ok_ack_color']), - 'problem_unack_style' => $this->getInput('problem_unack_style', $config['problem_unack_style']), - 'problem_ack_style' => $this->getInput('problem_ack_style', $config['problem_ack_style']), - 'ok_unack_style' => $this->getInput('ok_unack_style', $config['ok_unack_style']), - 'ok_ack_style' => $this->getInput('ok_ack_style', $config['ok_ack_style']), - 'ok_period' => $this->getInput('ok_period', $config['ok_period']), - 'blink_period' => $this->getInput('blink_period', $config['blink_period']) + 'custom_color' => $this->getInput('custom_color', CSettingsHelper::get(CSettingsHelper::CUSTOM_COLOR)), + 'problem_unack_color' => $this->getInput('problem_unack_color', CSettingsHelper::get( + CSettingsHelper::PROBLEM_UNACK_COLOR + )), + 'problem_ack_color' => $this->getInput('problem_ack_color', CSettingsHelper::get( + CSettingsHelper::PROBLEM_ACK_COLOR + )), + 'ok_unack_color' => $this->getInput('ok_unack_color', CSettingsHelper::get( + CSettingsHelper::OK_UNACK_COLOR + )), + 'ok_ack_color' => $this->getInput('ok_ack_color', CSettingsHelper::get(CSettingsHelper::OK_ACK_COLOR)), + 'problem_unack_style' => $this->getInput('problem_unack_style', CSettingsHelper::get( + CSettingsHelper::PROBLEM_UNACK_STYLE + )), + 'problem_ack_style' => $this->getInput('problem_ack_style', CSettingsHelper::get( + CSettingsHelper::PROBLEM_ACK_STYLE + )), + 'ok_unack_style' => $this->getInput('ok_unack_style', CSettingsHelper::get( + CSettingsHelper::OK_UNACK_STYLE + )), + 'ok_ack_style' => $this->getInput('ok_ack_style', CSettingsHelper::get(CSettingsHelper::OK_ACK_STYLE)), + 'ok_period' => $this->getInput('ok_period', CSettingsHelper::get(CSettingsHelper::OK_PERIOD)), + 'blink_period' => $this->getInput('blink_period', CSettingsHelper::get(CSettingsHelper::BLINK_PERIOD)), + 'severity_name_0' => $this->getInput('severity_name_0', CSettingsHelper::get( + CSettingsHelper::SEVERITY_NAME_0 + )), + 'severity_color_0' => $this->getInput('severity_color_0', CSettingsHelper::get( + CSettingsHelper::SEVERITY_COLOR_0 + )), + 'severity_name_1' => $this->getInput('severity_name_1', CSettingsHelper::get( + CSettingsHelper::SEVERITY_NAME_1 + )), + 'severity_color_1' => $this->getInput('severity_color_1', CSettingsHelper::get( + CSettingsHelper::SEVERITY_COLOR_1 + )), + 'severity_name_2' => $this->getInput('severity_name_2', CSettingsHelper::get( + CSettingsHelper::SEVERITY_NAME_2 + )), + 'severity_color_2' => $this->getInput('severity_color_2', CSettingsHelper::get( + CSettingsHelper::SEVERITY_COLOR_2 + )), + 'severity_name_3' => $this->getInput('severity_name_3', CSettingsHelper::get( + CSettingsHelper::SEVERITY_NAME_3 + )), + 'severity_color_3' => $this->getInput('severity_color_3', CSettingsHelper::get( + CSettingsHelper::SEVERITY_COLOR_3 + )), + 'severity_name_4' => $this->getInput('severity_name_4', CSettingsHelper::get( + CSettingsHelper::SEVERITY_NAME_4 + )), + 'severity_color_4' => $this->getInput('severity_color_4', CSettingsHelper::get( + CSettingsHelper::SEVERITY_COLOR_4 + )), + 'severity_name_5' => $this->getInput('severity_name_5', CSettingsHelper::get( + CSettingsHelper::SEVERITY_NAME_5 + )), + 'severity_color_5' => $this->getInput('severity_color_5', CSettingsHelper::get( + CSettingsHelper::SEVERITY_COLOR_5 + )) ]; $response = new CControllerResponseData($data); diff --git a/ui/app/controllers/CControllerTrigDisplayUpdate.php b/ui/app/controllers/CControllerTrigDisplayUpdate.php index abc5ce5a675..72b7682c432 100644 --- a/ui/app/controllers/CControllerTrigDisplayUpdate.php +++ b/ui/app/controllers/CControllerTrigDisplayUpdate.php @@ -23,17 +23,29 @@ class CControllerTrigDisplayUpdate extends CController { protected function checkInput() { $fields = [ - 'custom_color' => 'required | int32 | in '.EVENT_CUSTOM_COLOR_DISABLED.','.EVENT_CUSTOM_COLOR_ENABLED, - 'problem_unack_style' => 'required | int32 | in 0,1', - 'problem_ack_style' => 'required | int32 | in 0,1', - 'ok_unack_style' => 'required | int32 | in 0,1', - 'ok_ack_style' => 'required | int32 | in 0,1', - 'ok_period' => 'required | string | not_empty', - 'blink_period' => 'required | string | not_empty', - 'problem_unack_color' => 'rgb', - 'problem_ack_color' => 'rgb', - 'ok_unack_color' => 'rgb', - 'ok_ack_color' => 'rgb' + 'custom_color' => 'required|db config.custom_color|in '.EVENT_CUSTOM_COLOR_DISABLED.','.EVENT_CUSTOM_COLOR_ENABLED, + 'problem_unack_color' => 'db config.problem_unack_color|rgb', + 'problem_ack_color' => 'db config.problem_ack_color|rgb', + 'ok_unack_color' => 'db config.ok_unack_color|rgb', + 'ok_ack_color' => 'db config.ok_ack_color|rgb', + 'problem_unack_style' => 'required|db config.problem_unack_style|in 0,1', + 'problem_ack_style' => 'required|db config.problem_ack_style|in 0,1', + 'ok_unack_style' => 'required|db config.ok_unack_style|in 0,1', + 'ok_ack_style' => 'required|db config.ok_ack_style|in 0,1', + 'ok_period' => 'required|db config.ok_period|not_empty|time_unit '.implode(':', [0, SEC_PER_DAY]), + 'blink_period' => 'required|db config.blink_period|not_empty|time_unit '.implode(':', [0, SEC_PER_DAY]), + 'severity_name_0' => 'required|db config.severity_name_0|not_empty', + 'severity_color_0' => 'required|db config.severity_color_0|rgb', + 'severity_name_1' => 'required|db config.severity_name_1|not_empty', + 'severity_color_1' => 'required|db config.severity_color_1|rgb', + 'severity_name_2' => 'required|db config.severity_name_2|not_empty', + 'severity_color_2' => 'required|db config.severity_color_2|rgb', + 'severity_name_3' => 'required|db config.severity_name_3|not_empty', + 'severity_color_3' => 'required|db config.severity_color_3|rgb', + 'severity_name_4' => 'required|db config.severity_name_4|not_empty', + 'severity_color_4' => 'required|db config.severity_color_4|rgb', + 'severity_name_5' => 'required|db config.severity_name_5|not_empty', + 'severity_color_5' => 'required|db config.severity_color_5|rgb' ]; $ret = $this->validateInput($fields); @@ -57,31 +69,41 @@ class CControllerTrigDisplayUpdate extends CController { } protected function doAction() { - $update_values = [ - 'custom_color' => $this->getInput('custom_color', EVENT_CUSTOM_COLOR_DISABLED), - 'problem_unack_style' => $this->getInput('problem_unack_style'), - 'problem_ack_style' => $this->getInput('problem_ack_style'), - 'ok_unack_style' => $this->getInput('ok_unack_style'), - 'ok_ack_style' => $this->getInput('ok_ack_style'), - 'ok_period' => trim($this->getInput('ok_period')), - 'blink_period' => trim($this->getInput('blink_period')) + $settings = [ + CSettingsHelper::CUSTOM_COLOR => $this->getInput('custom_color', EVENT_CUSTOM_COLOR_DISABLED), + CSettingsHelper::PROBLEM_UNACK_STYLE => $this->getInput('problem_unack_style'), + CSettingsHelper::PROBLEM_ACK_STYLE => $this->getInput('problem_ack_style'), + CSettingsHelper::OK_UNACK_STYLE => $this->getInput('ok_unack_style'), + CSettingsHelper::OK_ACK_STYLE => $this->getInput('ok_ack_style'), + CSettingsHelper::OK_PERIOD => trim($this->getInput('ok_period')), + CSettingsHelper::BLINK_PERIOD => trim($this->getInput('blink_period')), + CSettingsHelper::SEVERITY_NAME_0 => $this->getInput('severity_name_0'), + CSettingsHelper::SEVERITY_COLOR_0 => $this->getInput('severity_color_0'), + CSettingsHelper::SEVERITY_NAME_1 => $this->getInput('severity_name_1'), + CSettingsHelper::SEVERITY_COLOR_1 => $this->getInput('severity_color_1'), + CSettingsHelper::SEVERITY_NAME_2 => $this->getInput('severity_name_2'), + CSettingsHelper::SEVERITY_COLOR_2 => $this->getInput('severity_color_2'), + CSettingsHelper::SEVERITY_NAME_3 => $this->getInput('severity_name_3'), + CSettingsHelper::SEVERITY_COLOR_3 => $this->getInput('severity_color_3'), + CSettingsHelper::SEVERITY_NAME_4 => $this->getInput('severity_name_4'), + CSettingsHelper::SEVERITY_COLOR_4 => $this->getInput('severity_color_4'), + CSettingsHelper::SEVERITY_NAME_5 => $this->getInput('severity_name_5'), + CSettingsHelper::SEVERITY_COLOR_5 => $this->getInput('severity_color_5') ]; + if ($settings[CSettingsHelper::CUSTOM_COLOR] == EVENT_CUSTOM_COLOR_ENABLED) { + $settings[CSettingsHelper::PROBLEM_UNACK_COLOR] = $this->getInput('problem_unack_color'); + $settings[CSettingsHelper::PROBLEM_ACK_COLOR] = $this->getInput('problem_ack_color'); + $settings[CSettingsHelper::OK_UNACK_COLOR] = $this->getInput('ok_unack_color'); + $settings[CSettingsHelper::OK_ACK_COLOR] = $this->getInput('ok_ack_color'); + } + + $result = API::Settings()->update($settings); + $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) ->setArgument('action', 'trigdisplay.edit') ); - if ($update_values['custom_color'] == EVENT_CUSTOM_COLOR_ENABLED) { - $update_values['problem_unack_color'] = $this->getInput('problem_unack_color'); - $update_values['problem_ack_color'] = $this->getInput('problem_ack_color'); - $update_values['ok_unack_color'] = $this->getInput('ok_unack_color'); - $update_values['ok_ack_color'] = $this->getInput('ok_ack_color'); - } - - DBstart(); - $result = update_config($update_values); - $result = DBend($result); - if ($result) { $response->setMessageOk(_('Configuration updated')); } diff --git a/ui/app/controllers/CControllerTrigSeverityEdit.php b/ui/app/controllers/CControllerTrigSeverityEdit.php deleted file mode 100644 index 0281cbc2f3f..00000000000 --- a/ui/app/controllers/CControllerTrigSeverityEdit.php +++ /dev/null @@ -1,79 +0,0 @@ -<?php -/* -** Zabbix -** Copyright (C) 2001-2020 Zabbix SIA -** -** This program is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -**/ - - -class CControllerTrigSeverityEdit extends CController { - - protected function init() { - $this->disableSIDValidation(); - } - - protected function checkInput() { - $fields = [ - 'severity_name_0' => 'string', - 'severity_color_0' => 'string', - 'severity_name_1' => 'string', - 'severity_color_1' => 'string', - 'severity_name_2' => 'string', - 'severity_color_2' => 'string', - 'severity_name_3' => 'string', - 'severity_color_3' => 'string', - 'severity_name_4' => 'string', - 'severity_color_4' => 'string', - 'severity_name_5' => 'string', - 'severity_color_5' => 'string' - ]; - - $ret = $this->validateInput($fields); - - if (!$ret) { - $this->setResponse(new CControllerResponseFatal()); - } - - return $ret; - } - - protected function checkPermissions() { - return ($this->getUserType() == USER_TYPE_SUPER_ADMIN); - } - - protected function doAction() { - $config = select_config(); - - $data = [ - 'severity_name_0' => $this->getInput('severity_name_0', $config['severity_name_0']), - 'severity_color_0' => $this->getInput('severity_color_0', $config['severity_color_0']), - 'severity_name_1' => $this->getInput('severity_name_1', $config['severity_name_1']), - 'severity_color_1' => $this->getInput('severity_color_1', $config['severity_color_1']), - 'severity_name_2' => $this->getInput('severity_name_2', $config['severity_name_2']), - 'severity_color_2' => $this->getInput('severity_color_2', $config['severity_color_2']), - 'severity_name_3' => $this->getInput('severity_name_3', $config['severity_name_3']), - 'severity_color_3' => $this->getInput('severity_color_3', $config['severity_color_3']), - 'severity_name_4' => $this->getInput('severity_name_4', $config['severity_name_4']), - 'severity_color_4' => $this->getInput('severity_color_4', $config['severity_color_4']), - 'severity_name_5' => $this->getInput('severity_name_5', $config['severity_name_5']), - 'severity_color_5' => $this->getInput('severity_color_5', $config['severity_color_5']) - ]; - - $response = new CControllerResponseData($data); - $response->setTitle(_('Configuration of trigger severities')); - $this->setResponse($response); - } -} diff --git a/ui/app/controllers/CControllerTrigSeverityUpdate.php b/ui/app/controllers/CControllerTrigSeverityUpdate.php deleted file mode 100644 index bf7cb2ba6b5..00000000000 --- a/ui/app/controllers/CControllerTrigSeverityUpdate.php +++ /dev/null @@ -1,88 +0,0 @@ -<?php -/* -** Zabbix -** Copyright (C) 2001-2020 Zabbix SIA -** -** This program is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -**/ - - -class CControllerTrigSeverityUpdate extends CController { - - protected function checkInput() { - $fields = [ - 'severity_name_0' => 'required | string | not_empty', - 'severity_name_1' => 'required | string | not_empty', - 'severity_name_2' => 'required | string | not_empty', - 'severity_name_3' => 'required | string | not_empty', - 'severity_name_4' => 'required | string | not_empty', - 'severity_name_5' => 'required | string | not_empty', - 'severity_color_0' => 'required | rgb', - 'severity_color_1' => 'required | rgb', - 'severity_color_2' => 'required | rgb', - 'severity_color_3' => 'required | rgb', - 'severity_color_4' => 'required | rgb', - 'severity_color_5' => 'required | rgb' - ]; - - $ret = $this->validateInput($fields); - - if (!$ret) { - $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) - ->setArgument('action', 'trigseverity.edit') - ); - $response->setMessageError(_('Cannot update configuration')); - $response->setFormData($this->getInputAll()); - $this->setResponse($response); - } - - return $ret; - } - - protected function checkPermissions() { - return ($this->getUserType() == USER_TYPE_SUPER_ADMIN); - } - - protected function doAction() { - $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) - ->setArgument('action', 'trigseverity.edit') - ); - - $result = update_config([ - 'severity_name_0' => $this->getInput('severity_name_0'), - 'severity_color_0' => $this->getInput('severity_color_0'), - 'severity_name_1' => $this->getInput('severity_name_1'), - 'severity_color_1' => $this->getInput('severity_color_1'), - 'severity_name_2' => $this->getInput('severity_name_2'), - 'severity_color_2' => $this->getInput('severity_color_2'), - 'severity_name_3' => $this->getInput('severity_name_3'), - 'severity_color_3' => $this->getInput('severity_color_3'), - 'severity_name_4' => $this->getInput('severity_name_4'), - 'severity_color_4' => $this->getInput('severity_color_4'), - 'severity_name_5' => $this->getInput('severity_name_5'), - 'severity_color_5' => $this->getInput('severity_color_5') - ]); - - if ($result) { - $response->setMessageOk(_('Configuration updated')); - } - else { - $response->setFormData($this->getInputAll()); - $response->setMessageError(_('Cannot update configuration')); - } - - $this->setResponse($response); - } -} diff --git a/ui/app/controllers/CControllerUserEdit.php b/ui/app/controllers/CControllerUserEdit.php index 592af92a6b6..ff5ff025773 100644 --- a/ui/app/controllers/CControllerUserEdit.php +++ b/ui/app/controllers/CControllerUserEdit.php @@ -94,7 +94,6 @@ class CControllerUserEdit extends CControllerUserEditGeneral { protected function doAction() { $db_defaults = DB::getDefaults('users'); - $config = select_config(); $data = [ 'userid' => 0, @@ -114,14 +113,6 @@ class CControllerUserEdit extends CControllerUserEditGeneral { 'medias' => [], 'new_media' => [], 'type' => $db_defaults['type'], - 'config' => [ - 'severity_name_0' => $config['severity_name_0'], - 'severity_name_1' => $config['severity_name_1'], - 'severity_name_2' => $config['severity_name_2'], - 'severity_name_3' => $config['severity_name_3'], - 'severity_name_4' => $config['severity_name_4'], - 'severity_name_5' => $config['severity_name_5'] - ], 'sid' => $this->getUserSID(), 'form_refresh' => 0, 'action' => $this->getAction(), diff --git a/ui/app/controllers/CControllerUserList.php b/ui/app/controllers/CControllerUserList.php index 7d797952aad..4e512a226ab 100644 --- a/ui/app/controllers/CControllerUserList.php +++ b/ui/app/controllers/CControllerUserList.php @@ -82,13 +82,8 @@ class CControllerUserList extends CController { 'type' => CProfile::get('web.user.filter_type', -1) ]; - $config = select_config(); - $data = [ 'uncheck' => $this->hasInput('uncheck'), - 'config' => [ - 'max_in_table' => $config['max_in_table'] - ], 'sort' => $sortfield, 'sortorder' => $sortorder, 'filter' => $filter, @@ -109,6 +104,7 @@ class CControllerUserList extends CController { } $data['user_groups'] = [0 => _('All')] + $data['user_groups']; + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1; $data['users'] = API::User()->get([ 'output' => ['userid', 'alias', 'name', 'surname', 'type', 'autologout', 'attempt_failed'], 'selectUsrgrps' => ['name', 'gui_access', 'users_status'], @@ -122,7 +118,7 @@ class CControllerUserList extends CController { ], 'usrgrpids' => ($filter_usrgrpid == 0) ? null : $filter_usrgrpid, 'getAccess' => true, - 'limit' => $config['search_limit'] + 1 + 'limit' => $limit ]); // data sort and pager @@ -151,6 +147,11 @@ class CControllerUserList extends CController { } } + $data['config'] = [ + 'login_attempts' => CSettingsHelper::get(CSettingsHelper::LOGIN_ATTEMPTS), + 'max_in_table' => CSettingsHelper::get(CSettingsHelper::MAX_IN_TABLE) + ]; + $response = new CControllerResponseData($data); $response->setTitle(_('Configuration of users')); $this->setResponse($response); diff --git a/ui/app/controllers/CControllerUserProfileEdit.php b/ui/app/controllers/CControllerUserProfileEdit.php index b73153ed984..1c6a4b78d0a 100644 --- a/ui/app/controllers/CControllerUserProfileEdit.php +++ b/ui/app/controllers/CControllerUserProfileEdit.php @@ -95,7 +95,6 @@ class CControllerUserProfileEdit extends CControllerUserEditGeneral { * Set user medias if user is at least admin and set messages in data. */ protected function doAction() { - $config = select_config(); $data = [ 'userid' => CWebUser::$data['userid'], @@ -114,14 +113,6 @@ class CControllerUserProfileEdit extends CControllerUserEditGeneral { 'rows_per_page' => $this->user['rows_per_page'], 'url' => $this->user['url'], 'messages' => $this->getInput('messages', []) + getMessageSettings(), - 'config' => [ - 'severity_name_0' => $config['severity_name_0'], - 'severity_name_1' => $config['severity_name_1'], - 'severity_name_2' => $config['severity_name_2'], - 'severity_name_3' => $config['severity_name_3'], - 'severity_name_4' => $config['severity_name_4'], - 'severity_name_5' => $config['severity_name_5'] - ], 'form_refresh' => 0, 'action' => $this->getAction() ]; diff --git a/ui/app/controllers/CControllerUserUpdateGeneral.php b/ui/app/controllers/CControllerUserUpdateGeneral.php index 7a60f359071..194c5a2ab9e 100644 --- a/ui/app/controllers/CControllerUserUpdateGeneral.php +++ b/ui/app/controllers/CControllerUserUpdateGeneral.php @@ -40,10 +40,10 @@ abstract class CControllerUserUpdateGeneral extends CController { * @return int */ private static function hasInternalAuth($usrgrps) { - $config = select_config(); - $system_gui_access = ($config['authentication_type'] == ZBX_AUTH_INTERNAL) - ? GROUP_GUI_ACCESS_INTERNAL - : GROUP_GUI_ACCESS_LDAP; + $system_gui_access = + (CAuthenticationHelper::get(CAuthenticationHelper::AUTHENTICATION_TYPE) == ZBX_AUTH_INTERNAL) + ? GROUP_GUI_ACCESS_INTERNAL + : GROUP_GUI_ACCESS_LDAP; foreach($usrgrps as $usrgrp) { $gui_access = ($usrgrp['gui_access'] == GROUP_GUI_ACCESS_SYSTEM) diff --git a/ui/app/controllers/CControllerUsergroupList.php b/ui/app/controllers/CControllerUsergroupList.php index 2b364a10083..21b745fea08 100644 --- a/ui/app/controllers/CControllerUsergroupList.php +++ b/ui/app/controllers/CControllerUsergroupList.php @@ -75,8 +75,7 @@ class CControllerUsergroupList extends CController { 'user_status' => CProfile::get('web.usergroup.filter_user_status', -1) ]; - $config = select_config(); - + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1; $data = [ 'uncheck' => $this->hasInput('uncheck'), 'sort' => $sort_field, @@ -90,7 +89,7 @@ class CControllerUsergroupList extends CController { 'search' => ['name' => ($filter['name'] !== '') ? $filter['name'] : null], 'filter' => ['users_status' => ($filter['user_status'] != -1) ? $filter['user_status'] : null], 'sortfield' => $sort_field, - 'limit' => $config['search_limit'] + 1 + 'limit' => $limit ]) ]; @@ -107,8 +106,10 @@ class CControllerUsergroupList extends CController { CArrayHelper::sort($usergroup['users'], ['alias']); $usergroup['user_cnt'] = count($usergroup['users']); - if ($usergroup['user_cnt'] > $config['max_in_table']) { - $usergroup['users'] = array_slice($usergroup['users'], 0, $config['max_in_table']); + if ($usergroup['user_cnt'] > CSettingsHelper::get(CSettingsHelper::MAX_IN_TABLE)) { + $usergroup['users'] = array_slice($usergroup['users'], 0, CSettingsHelper::get( + CSettingsHelper::MAX_IN_TABLE + )); } } unset($usergroup); diff --git a/ui/app/controllers/CControllerValuemapList.php b/ui/app/controllers/CControllerValuemapList.php index f44c70c91ed..cb3a9cccdd8 100644 --- a/ui/app/controllers/CControllerValuemapList.php +++ b/ui/app/controllers/CControllerValuemapList.php @@ -44,8 +44,6 @@ class CControllerValuemapList extends CController { } protected function doAction() { - $config = select_config(); - $sortfield = getRequest('sort', CProfile::get('web.valuemap.list.sort', 'name')); $sortorder = getRequest('sortorder', CProfile::get('web.valuemap.list.sortorder', ZBX_SORT_UP)); @@ -58,11 +56,12 @@ class CControllerValuemapList extends CController { 'uncheck' => $this->hasInput('uncheck') ]; + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1; $data['valuemaps'] = API::ValueMap()->get([ 'output' => ['valuemapid', 'name'], 'selectMappings' => ['value', 'newvalue'], 'sortfield' => $sortfield, - 'limit' => $config['search_limit'] + 1 + 'limit' => $limit ]); // data sort and pager diff --git a/ui/app/controllers/CControllerWidgetNavTreeView.php b/ui/app/controllers/CControllerWidgetNavTreeView.php index 54c0a22924b..72e08708cac 100644 --- a/ui/app/controllers/CControllerWidgetNavTreeView.php +++ b/ui/app/controllers/CControllerWidgetNavTreeView.php @@ -438,7 +438,6 @@ class CControllerWidgetNavTreeView extends CControllerWidget { // Get severity levels and colors and select list of sysmapids to count problems per maps. $this->problems_per_severity_tpl = []; - $config = select_config(); $severity_config = []; $maps_accessible = $sysmapids @@ -452,7 +451,7 @@ class CControllerWidgetNavTreeView extends CControllerWidget { for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_COUNT; $severity++) { $this->problems_per_severity_tpl[$severity] = 0; $severity_config[$severity] = [ - 'name' => getSeverityName($severity, $config), + 'name' => getSeverityName($severity), 'style_class' => getSeverityStatusStyle($severity) ]; } diff --git a/ui/app/controllers/CControllerWidgetProblemHostsView.php b/ui/app/controllers/CControllerWidgetProblemHostsView.php index 11fed936ca3..50c105fffaa 100644 --- a/ui/app/controllers/CControllerWidgetProblemHostsView.php +++ b/ui/app/controllers/CControllerWidgetProblemHostsView.php @@ -36,8 +36,6 @@ class CControllerWidgetProblemHostsView extends CControllerWidget { protected function doAction() { $fields = $this->getForm()->getFieldsData(); - $config = select_config(); - $filter_groupids = $fields['groupids'] ? getSubGroups($fields['groupids']) : null; $filter_hostids = $fields['hostids'] ? $fields['hostids'] : null; $filter_problem = ($fields['problem'] !== '') ? $fields['problem'] : null; @@ -243,14 +241,6 @@ class CControllerWidgetProblemHostsView extends CControllerWidget { 'hide_empty_groups' => $fields['hide_empty_groups'], 'ext_ack' => $fields['ext_ack'] ], - 'config' => [ - 'severity_name_0' => $config['severity_name_0'], - 'severity_name_1' => $config['severity_name_1'], - 'severity_name_2' => $config['severity_name_2'], - 'severity_name_3' => $config['severity_name_3'], - 'severity_name_4' => $config['severity_name_4'], - 'severity_name_5' => $config['severity_name_5'] - ], 'hosts_data' => $hosts_data, 'groups' => $groups, 'user' => [ diff --git a/ui/app/controllers/CControllerWidgetProblemsBySvView.php b/ui/app/controllers/CControllerWidgetProblemsBySvView.php index bd57a509fb5..8ad4acbc02f 100644 --- a/ui/app/controllers/CControllerWidgetProblemsBySvView.php +++ b/ui/app/controllers/CControllerWidgetProblemsBySvView.php @@ -37,8 +37,6 @@ class CControllerWidgetProblemsBySvView extends CControllerWidget { protected function doAction() { $fields = $this->getForm()->getFieldsData(); - $config = select_config(); - $filter = [ 'groupids' => getSubGroups($fields['groupids']), 'exclude_groupids' => getSubGroups($fields['exclude_groupids']), @@ -66,14 +64,6 @@ class CControllerWidgetProblemsBySvView extends CControllerWidget { 'name' => $this->getInput('name', $this->getDefaultHeader()), 'initial_load' => (bool) $this->getInput('initial_load', 0), 'data' => $data, - 'severity_names' => [ - 'severity_name_0' => $config['severity_name_0'], - 'severity_name_1' => $config['severity_name_1'], - 'severity_name_2' => $config['severity_name_2'], - 'severity_name_3' => $config['severity_name_3'], - 'severity_name_4' => $config['severity_name_4'], - 'severity_name_5' => $config['severity_name_5'] - ], 'filter' => $filter, 'user' => [ 'debug_mode' => $this->getDebugMode() diff --git a/ui/app/controllers/CControllerWidgetProblemsView.php b/ui/app/controllers/CControllerWidgetProblemsView.php index 0384cc3930b..73bceb7f7e1 100644 --- a/ui/app/controllers/CControllerWidgetProblemsView.php +++ b/ui/app/controllers/CControllerWidgetProblemsView.php @@ -35,8 +35,6 @@ class CControllerWidgetProblemsView extends CControllerWidget { protected function doAction() { $fields = $this->getForm()->getFieldsData(); - $config = select_config(); - $data = CScreenProblem::getData([ 'show' => $fields['show'], 'groupids' => getSubGroups($fields['groupids']), @@ -49,15 +47,15 @@ class CControllerWidgetProblemsView extends CControllerWidget { 'show_suppressed' => $fields['show_suppressed'], 'unacknowledged' => $fields['unacknowledged'], 'show_opdata' => $fields['show_opdata'] - ], $config, true, true); + ], true, true); list($sortfield, $sortorder) = self::getSorting($fields['sort_triggers']); - $data = CScreenProblem::sortData($data, $config, $sortfield, $sortorder); + $data = CScreenProblem::sortData($data, $sortfield, $sortorder); if (count($data['problems']) > $fields['show_lines']) { $info = _n('%1$d of %3$d%2$s problem is shown', '%1$d of %3$d%2$s problems are shown', min($fields['show_lines'], count($data['problems'])), - (count($data['problems']) > $config['search_limit']) ? '+' : '', - min($config['search_limit'], count($data['problems'])) + (count($data['problems']) > CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT)) ? '+' : '', + min(CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT), count($data['problems'])) ); } else { @@ -94,23 +92,17 @@ class CControllerWidgetProblemsView extends CControllerWidget { 'tag_priority' => $fields['tag_priority'], 'show_opdata' => $fields['show_opdata'] ], - 'config' => [ - 'problem_unack_style' => $config['problem_unack_style'], - 'problem_ack_style' => $config['problem_ack_style'], - 'blink_period' => timeUnitToSeconds($config['blink_period']), - 'severity_name_0' => $config['severity_name_0'], - 'severity_name_1' => $config['severity_name_1'], - 'severity_name_2' => $config['severity_name_2'], - 'severity_name_3' => $config['severity_name_3'], - 'severity_name_4' => $config['severity_name_4'], - 'severity_name_5' => $config['severity_name_5'] - ], 'data' => $data, 'info' => $info, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'user' => [ 'debug_mode' => $this->getDebugMode() + ], + 'config' => [ + 'problem_ack_style' => CSettingsHelper::get(CSettingsHelper::PROBLEM_ACK_STYLE), + 'problem_unack_style' => CSettingsHelper::get(CSettingsHelper::PROBLEM_UNACK_STYLE), + 'blink_period' => CSettingsHelper::get(CSettingsHelper::BLINK_PERIOD) ] ])); } diff --git a/ui/app/controllers/CControllerWidgetUrlView.php b/ui/app/controllers/CControllerWidgetUrlView.php index f07324750d8..0b72ea1ec9b 100644 --- a/ui/app/controllers/CControllerWidgetUrlView.php +++ b/ui/app/controllers/CControllerWidgetUrlView.php @@ -64,6 +64,10 @@ class CControllerWidgetUrlView extends CControllerWidget { ], 'user' => [ 'debug_mode' => $this->getDebugMode() + ], + 'config' => [ + 'iframe_sandboxing_enabled' => CSettingsHelper::get(CSettingsHelper::IFRAME_SANDBOXING_ENABLED), + 'iframe_sandboxing_exceptions' => CSettingsHelper::get(CSettingsHelper::IFRAME_SANDBOXING_EXCEPTIONS) ] ])); } diff --git a/ui/app/controllers/CControllerWorkingTimeEdit.php b/ui/app/controllers/CControllerWorkingTimeEdit.php deleted file mode 100644 index bf283f066a7..00000000000 --- a/ui/app/controllers/CControllerWorkingTimeEdit.php +++ /dev/null @@ -1,54 +0,0 @@ -<?php -/* -** Zabbix -** Copyright (C) 2001-2020 Zabbix SIA -** -** This program is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -**/ - - -class CControllerWorkingTimeEdit extends CController { - - protected function init() { - $this->disableSIDValidation(); - } - - protected function checkInput() { - $fields = [ - 'work_period' => 'db config.work_period' - ]; - - $ret = $this->validateInput($fields); - - if (!$ret) { - $this->setResponse(new CControllerResponseFatal()); - } - - return $ret; - } - - protected function checkPermissions() { - return ($this->getUserType() == USER_TYPE_SUPER_ADMIN); - } - - protected function doAction() { - $config = select_config(); - $data = ['work_period' => $this->getInput('work_period', $config['work_period'])]; - - $response = new CControllerResponseData($data); - $response->setTitle(_('Configuration of working time')); - $this->setResponse($response); - } -} diff --git a/ui/app/controllers/CControllerWorkingTimeUpdate.php b/ui/app/controllers/CControllerWorkingTimeUpdate.php deleted file mode 100644 index 1fe158820db..00000000000 --- a/ui/app/controllers/CControllerWorkingTimeUpdate.php +++ /dev/null @@ -1,67 +0,0 @@ -<?php -/* -** Zabbix -** Copyright (C) 2001-2020 Zabbix SIA -** -** This program is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -**/ - - -class CControllerWorkingTimeUpdate extends CController { - - protected function checkInput() { - $fields = [ - 'work_period' => 'required | time_periods' - ]; - - $ret = $this->validateInput($fields); - - if (!$ret) { - $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) - ->setArgument('action', 'workingtime.edit') - ->getUrl() - ); - $response->setFormData($this->getInputAll()); - $response->setMessageError(_('Cannot update configuration')); - $this->setResponse($response); - } - - return $ret; - } - - protected function checkPermissions() { - return ($this->getUserType() == USER_TYPE_SUPER_ADMIN); - } - - protected function doAction() { - $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) - ->setArgument('action', 'workingtime.edit') - ); - - DBstart(); - $result = update_config(['work_period' => $this->getInput('work_period')]); - $result = DBend($result); - - if ($result) { - $response->setMessageOk(_('Configuration updated')); - } - else { - $response->setFormData($this->getInputAll()); - $response->setMessageError(_('Cannot update configuration')); - } - - $this->setResponse($response); - } -} diff --git a/ui/app/partials/common.filter.trigger.php b/ui/app/partials/common.filter.trigger.php index 7b1bc843aed..0d00508ebd9 100644 --- a/ui/app/partials/common.filter.trigger.php +++ b/ui/app/partials/common.filter.trigger.php @@ -31,7 +31,7 @@ $filterForm = (new CFilter((new CUrl('overview.php'))->setArgument('type', 0))) $severityNames = []; for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_COUNT; $severity++) { - $severityNames[] = getSeverityName($severity, $data['config']); + $severityNames[] = getSeverityName($severity); } $column1 = (new CFormList()) diff --git a/ui/app/partials/layout.htmlpage.header.php b/ui/app/partials/layout.htmlpage.header.php index 8c5b7b08abd..1b889399e74 100644 --- a/ui/app/partials/layout.htmlpage.header.php +++ b/ui/app/partials/layout.htmlpage.header.php @@ -36,14 +36,13 @@ $scripts = $data['javascript']['files']; $theme = ZBX_DEFAULT_THEME; if (!empty($DB['DB'])) { - $config = select_config(); $theme = getUserTheme($data['user']); - $pageHeader->addStyle(getTriggerSeverityCss($config)); - $pageHeader->addStyle(getTriggerStatusCss($config)); + $pageHeader->addStyle(getTriggerSeverityCss()); + $pageHeader->addStyle(getTriggerStatusCss()); - // perform Zabbix server check only for standard pages - if ($config['server_check_interval'] && !empty($ZBX_SERVER) && !empty($ZBX_SERVER_PORT)) { + // Perform Zabbix server check only for standard pages. + if ($data['config']['server_check_interval'] && !empty($ZBX_SERVER) && !empty($ZBX_SERVER_PORT)) { $scripts[] = 'servercheck.js'; } } diff --git a/ui/app/partials/monitoring.host.view.html.php b/ui/app/partials/monitoring.host.view.html.php index df237042b31..5e6f1424bcc 100644 --- a/ui/app/partials/monitoring.host.view.html.php +++ b/ui/app/partials/monitoring.host.view.html.php @@ -73,7 +73,7 @@ foreach ($data['hosts'] as $hostid => $host) { $problems_div->addItem((new CSpan($count)) ->addClass(ZBX_STYLE_PROBLEM_ICON_LIST_ITEM) ->addClass(getSeverityStatusStyle($severity)) - ->setAttribute('title', getSeverityName($severity, $data['config'])) + ->setAttribute('title', getSeverityName($severity)) ); } } diff --git a/ui/app/partials/monitoring.latest.view.html.php b/ui/app/partials/monitoring.latest.view.html.php index 1fed6f8a2f2..658e50dd5e6 100644 --- a/ui/app/partials/monitoring.latest.view.html.php +++ b/ui/app/partials/monitoring.latest.view.html.php @@ -75,8 +75,6 @@ else { // Latest data rows. -$config = select_config(); - $simple_interval_parser = new CSimpleIntervalParser(); $update_interval_parser = new CUpdateIntervalParser(['usermacros' => true]); @@ -155,9 +153,9 @@ foreach ($data['rows'] as $row) { // Other row data preparation. - if ($config['hk_history_global']) { - $keep_history = timeUnitToSeconds($config['hk_history']); - $item_history = $config['hk_history']; + if ($data['config']['hk_history_global']) { + $keep_history = timeUnitToSeconds($data['config']['hk_history']); + $item_history = $data['config']['hk_history']; } elseif ($simple_interval_parser->parse($item['history']) == CParser::PARSE_SUCCESS) { $keep_history = timeUnitToSeconds($item['history']); @@ -169,9 +167,9 @@ foreach ($data['rows'] as $row) { } if ($item['value_type'] == ITEM_VALUE_TYPE_FLOAT || $item['value_type'] == ITEM_VALUE_TYPE_UINT64) { - if ($config['hk_trends_global']) { - $keep_trends = timeUnitToSeconds($config['hk_trends']); - $item_trends = $config['hk_trends']; + if ($data['config']['hk_trends_global']) { + $keep_trends = timeUnitToSeconds($data['config']['hk_trends']); + $item_trends = $data['config']['hk_trends']; } elseif ($simple_interval_parser->parse($item['trends']) == CParser::PARSE_SUCCESS) { $keep_trends = timeUnitToSeconds($item['trends']); diff --git a/ui/app/views/administration.gui.edit.php b/ui/app/views/administration.gui.edit.php index 5fa4c690574..4d369a79097 100644 --- a/ui/app/views/administration.gui.edit.php +++ b/ui/app/views/administration.gui.edit.php @@ -23,6 +23,8 @@ * @var CView $this */ +$this->includeJsFile('administration.gui.edit.js.php'); + $widget = (new CWidget()) ->setTitle(_('GUI')) ->setTitleSubmenu(getAdministrationGeneralSubmenu()); @@ -81,6 +83,13 @@ $gui_tab = (new CFormList()) ->setAriaRequired() ->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH) ) + ->addRow( + (new CLabel(_('Max number of columns and rows in overview tables'), 'max_overview_table_size')) + ->setAsteriskMark(), + (new CNumericBox('max_overview_table_size', $data['max_overview_table_size'], 6)) + ->setAriaRequired() + ->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH) + ) ->addRow((new CLabel(_('Max count of elements to show inside table cell'), 'max_in_table'))->setAsteriskMark(), (new CNumericBox('max_in_table', $data['max_in_table'], 5)) ->setAriaRequired() @@ -90,11 +99,42 @@ $gui_tab = (new CFormList()) (new CCheckBox('server_check_interval', SERVER_CHECK_INTERVAL)) ->setUncheckedValue('0') ->setChecked($data['server_check_interval'] == SERVER_CHECK_INTERVAL) + ) + ->addRow((new CLabel(_('Working time'), 'work_period'))->setAsteriskMark(), + (new CTextBox('work_period', $data['work_period'])) + ->setWidth(ZBX_TEXTAREA_MEDIUM_WIDTH) + ->setAriaRequired() + ) + ->addRow(_('Show technical errors'), + (new CCheckBox('show_technical_errors')) + ->setUncheckedValue('0') + ->setChecked($data['show_technical_errors'] == 1) + ) + ->addRow( + (new CLabel(_('Max history display period'), 'history_period'))->setAsteriskMark(), + (new CTextBox('history_period', $data['history_period'], false, DB::getFieldLength('config', 'history_period'))) + ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) + ->setAriaRequired() + ) + ->addRow( + (new CLabel(_('Time filter default period'), 'period_default'))->setAsteriskMark(), + (new CTextBox('period_default', $data['period_default'], false, DB::getFieldLength('config', 'period_default'))) + ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) + ->setAriaRequired() + ) + ->addRow( + (new CLabel(_('Max period'), 'max_period'))->setAsteriskMark(), + (new CTextBox('max_period', $data['max_period'], false, DB::getFieldLength('config', 'max_period'))) + ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) + ->setAriaRequired() ); $gui_view = (new CTabView()) ->addTab('gui', _('GUI'), $gui_tab) - ->setFooter(makeFormFooter(new CSubmit('update', _('Update')))); + ->setFooter(makeFormFooter( + new CSubmit('update', _('Update')), + [new CButton('resetDefaults', _('Reset defaults'))] + )); $form = (new CForm()) ->setAttribute('aria-labeledby', ZBX_STYLE_PAGE_TITLE) diff --git a/ui/app/views/administration.housekeeping.edit.php b/ui/app/views/administration.housekeeping.edit.php index 57985d799bb..f829989d869 100644 --- a/ui/app/views/administration.housekeeping.edit.php +++ b/ui/app/views/administration.housekeeping.edit.php @@ -47,14 +47,18 @@ $house_keeper_tab = (new CFormList()) ) ->addRow( (new CLabel(_('Trigger data storage period'), 'hk_events_trigger'))->setAsteriskMark(), - (new CTextBox('hk_events_trigger', $data['hk_events_trigger'])) + (new CTextBox('hk_events_trigger', $data['hk_events_trigger'], false, + DB::getFieldLength('config', 'hk_events_trigger') + )) ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) ->setEnabled($data['hk_events_mode'] == 1) ->setAriaRequired() ) ->addRow( (new CLabel(_('Internal data storage period'), 'hk_events_internal'))->setAsteriskMark(), - (new CTextBox('hk_events_internal', $data['hk_events_internal'])) + (new CTextBox('hk_events_internal', $data['hk_events_internal'], false, + DB::getFieldLength('config', 'hk_events_internal') + )) ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) ->setEnabled($data['hk_events_mode'] == 1) ->setAriaRequired() @@ -62,7 +66,9 @@ $house_keeper_tab = (new CFormList()) ->addRow( (new CLabel(_('Network discovery data storage period'), 'hk_events_discovery')) ->setAsteriskMark(), - (new CTextBox('hk_events_discovery', $data['hk_events_discovery'])) + (new CTextBox('hk_events_discovery', $data['hk_events_discovery'], false, + DB::getFieldLength('config', 'hk_events_discovery') + )) ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) ->setEnabled($data['hk_events_mode'] == 1) ->setAriaRequired() @@ -70,7 +76,9 @@ $house_keeper_tab = (new CFormList()) ->addRow( (new CLabel(_('Autoregistration data storage period'), 'hk_events_autoreg')) ->setAsteriskMark(), - (new CTextBox('hk_events_autoreg', $data['hk_events_autoreg'])) + (new CTextBox('hk_events_autoreg', $data['hk_events_autoreg'], false, + DB::getFieldLength('config', 'hk_events_autoreg') + )) ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) ->setEnabled($data['hk_events_mode'] == 1) ->setAriaRequired() @@ -84,7 +92,7 @@ $house_keeper_tab = (new CFormList()) ->addRow( (new CLabel(_('Data storage period'), 'hk_services')) ->setAsteriskMark(), - (new CTextBox('hk_services', $data['hk_services'])) + (new CTextBox('hk_services', $data['hk_services'], false, DB::getFieldLength('config', 'hk_services'))) ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) ->setEnabled($data['hk_services_mode'] == 1) ->setAriaRequired() @@ -98,7 +106,7 @@ $house_keeper_tab = (new CFormList()) ->addRow( (new CLabel(_('Data storage period'), 'hk_audit')) ->setAsteriskMark(), - (new CTextBox('hk_audit', $data['hk_audit'])) + (new CTextBox('hk_audit', $data['hk_audit'], false, DB::getFieldLength('config', 'hk_audit'))) ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) ->setEnabled($data['hk_audit_mode'] == 1) ->setAriaRequired() @@ -112,7 +120,7 @@ $house_keeper_tab = (new CFormList()) ->addRow( (new CLabel(_('Data storage period'), 'hk_sessions')) ->setAsteriskMark(), - (new CTextBox('hk_sessions', $data['hk_sessions'])) + (new CTextBox('hk_sessions', $data['hk_sessions'], false, DB::getFieldLength('config', 'hk_sessions'))) ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) ->setEnabled($data['hk_sessions_mode'] == 1) ->setAriaRequired() @@ -130,7 +138,7 @@ $house_keeper_tab = (new CFormList()) ->addRow( (new CLabel(_('Data storage period'), 'hk_history')) ->setAsteriskMark(), - (new CTextBox('hk_history', $data['hk_history'])) + (new CTextBox('hk_history', $data['hk_history'], false, DB::getFieldLength('config', 'hk_history'))) ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) ->setEnabled($data['hk_history_global'] == 1) ->setAriaRequired() @@ -148,7 +156,7 @@ $house_keeper_tab = (new CFormList()) ->addRow( (new CLabel(_('Data storage period'), 'hk_trends')) ->setAsteriskMark(), - (new CTextBox('hk_trends', $data['hk_trends'])) + (new CTextBox('hk_trends', $data['hk_trends'], false, DB::getFieldLength('config', 'hk_trends'))) ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) ->setEnabled($data['hk_trends_global'] == 1) ->setAriaRequired() @@ -167,7 +175,9 @@ $house_keeper_tab = (new CFormList()) ->addRow( (new CLabel(_('Compress records older than'), 'compress_older')) ->setAsteriskMark(), - (new CTextBox('compress_older', $data['compress_older'])) + (new CTextBox('compress_older', $data['compress_older'], false, + DB::getFieldLength('config', 'compress_older') + )) ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) ->setEnabled($data['compression_availability'] == 1 && $data['compression_status'] == 1) ->setAriaRequired() diff --git a/ui/app/views/administration.miscconfig.edit.php b/ui/app/views/administration.miscconfig.edit.php index 3059f0052ac..249f9069018 100644 --- a/ui/app/views/administration.miscconfig.edit.php +++ b/ui/app/views/administration.miscconfig.edit.php @@ -23,31 +23,40 @@ * @var CView $this */ +$this->includeJsFile('administration.miscconfig.edit.js.php'); +$this->addJsFile('multiselect.js'); + $widget = (new CWidget()) ->setTitle(_('Other configuration parameters')) ->setTitleSubmenu(getAdministrationGeneralSubmenu()); -$from_list = new CFormList(); - -$discovery_group = new CComboBox('discovery_groupid', $data['discovery_groupid']); -foreach ($data['discovery_groups'] as $group) { - $discovery_group->addItem($group['groupid'], $group['name']); -} - -$alert_user_group = new CComboBox('alert_usrgrpid', $data['alert_usrgrpid']); -$alert_user_group->addItem(0, _('None')); -foreach ($data['alert_usrgrps'] as $usrgrp) { - $alert_user_group->addItem($usrgrp['usrgrpid'], $usrgrp['name']); -} - -$from_list +$from_list = (new CFormList()) ->addRow((new CLabel(_('Refresh unsupported items'), 'refresh_unsupported'))->setAsteriskMark(), - (new CTextBox('refresh_unsupported', $data['refresh_unsupported'])) + (new CTextBox('refresh_unsupported', $data['refresh_unsupported'], false, + DB::getFieldLength('config', 'refresh_unsupported') + )) ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) ->setAriaRequired() ->setAttribute('autofocus', 'autofocus') ) - ->addRow(_('Group for discovered hosts'), $discovery_group) + ->addRow((new CLabel(_('Group for discovered hosts'), 'discovery_groupid'))->setAsteriskMark(), + (new CMultiSelect([ + 'name' => 'discovery_groupid', + 'object_name' => 'hostGroup', + 'data' => $data['discovery_group_data'], + 'multiple' => false, + 'popup' => [ + 'parameters' => [ + 'srctbl' => 'host_groups', + 'srcfld1' => 'name', + 'dstfrm' => 'otherForm', + 'dstfld1' => 'discovery_groupid', + 'normal_only' => '1', + 'editable' => true + ] + ] + ]))->setWidth(ZBX_TEXTAREA_MEDIUM_WIDTH) + ) ->addRow(_('Default host inventory mode'), (new CRadioButtonList('default_inventory_mode', (int) $data['default_inventory_mode'])) ->addValue(_('Disabled'), HOST_INVENTORY_DISABLED) @@ -55,11 +64,113 @@ $from_list ->addValue(_('Automatic'), HOST_INVENTORY_AUTOMATIC) ->setModern(true) ) - ->addRow(_('User group for database down message'), $alert_user_group) + ->addRow(_('User group for database down message'), + (new CMultiSelect([ + 'name' => 'alert_usrgrpid', + 'object_name' => 'usersGroups', + 'data' => $data['alert_usrgrp_data'], + 'multiple' => false, + 'popup' => [ + 'parameters' => [ + 'srctbl' => 'usrgrp', + 'srcfld1' => 'name', + 'dstfrm' => 'otherForm', + 'dstfld1' => 'alert_usrgrpid', + 'editable' => true + ] + ] + ]))->setWidth(ZBX_TEXTAREA_MEDIUM_WIDTH) + ) ->addRow(_('Log unmatched SNMP traps'), (new CCheckBox('snmptrap_logging')) ->setUncheckedValue('0') ->setChecked($data['snmptrap_logging'] == 1) + ) + ->addRow(null) + ->addRow(new CTag('h4', true, _('Authorization'))) + ->addRow((new CLabel(_('Login attempts'), 'login_attempts'))->setAsteriskMark(), + (new CNumericBox('login_attempts', $data['login_attempts'], 2)) + ->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH) + ->setAriaRequired() + ) + ->addRow( + (new CLabel(_('Login blocking interval'), 'login_block'))->setAsteriskMark(), + (new CTextBox('login_block', $data['login_block'], false, DB::getFieldLength('config', 'login_block'))) + ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) + ->setAriaRequired() + ) + ->addRow(null) + ->addRow(new CTag('h4', true, _('Security'))) + ->addRow(_('Validate URI schemes'), + (new CCheckBox('validate_uri_schemes')) + ->setUncheckedValue('0') + ->setChecked($data['validate_uri_schemes'] == 1) + ) + ->addRow((new CLabel(_('Valid URI schemes'), 'uri_valid_schemes')), + (new CTextBox('uri_valid_schemes', $data['uri_valid_schemes'], false, + DB::getFieldLength('config', 'uri_valid_schemes') + )) + ->setWidth(ZBX_TEXTAREA_MEDIUM_WIDTH) + ->setEnabled($data['validate_uri_schemes'] == 1) + ->setAriaRequired() + ) + ->addRow((new CLabel(_('X-Frame-Options HTTP header'), 'x_frame_options'))->setAsteriskMark(), + (new CTextBox('x_frame_options', $data['x_frame_options'], false, + DB::getFieldLength('config', 'x_frame_options') + )) + ->setWidth(ZBX_TEXTAREA_MEDIUM_WIDTH) + ->setAriaRequired() + ) + ->addRow(_('Use iframe sandboxing'), + (new CCheckBox('iframe_sandboxing_enabled')) + ->setUncheckedValue('0') + ->setChecked($data['iframe_sandboxing_enabled'] == 1) + ) + ->addRow((new CLabel(_('Iframe sandboxing exceptions'), 'iframe_sandboxing_exceptions')), + (new CTextBox('iframe_sandboxing_exceptions', $data['iframe_sandboxing_exceptions'], false, + DB::getFieldLength('config', 'iframe_sandboxing_exceptions') + )) + ->setWidth(ZBX_TEXTAREA_MEDIUM_WIDTH) + ->setEnabled($data['iframe_sandboxing_enabled'] == 1) + ->setAriaRequired() + ) + ->addRow(null) + ->addRow(new CTag('h4', true, _('Communication with Zabbix server'))) + ->addRow( + (new CLabel(_('Network timeout'), 'socket_timeout'))->setAsteriskMark(), + (new CTextBox('socket_timeout', $data['socket_timeout'], false, DB::getFieldLength('config', 'socket_timeout'))) + ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) + ->setAriaRequired() + ) + ->addRow( + (new CLabel(_('Connection timeout'), 'connect_timeout'))->setAsteriskMark(), + (new CTextBox('connect_timeout', $data['connect_timeout'], false, + DB::getFieldLength('config', 'connect_timeout') + )) + ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) + ->setAriaRequired() + ) + ->addRow( + (new CLabel(_('Network timeout for media type test'), 'media_type_test_timeout'))->setAsteriskMark(), + (new CTextBox('media_type_test_timeout', $data['media_type_test_timeout'], false, + DB::getFieldLength('config', 'media_type_test_timeout') + )) + ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) + ->setAriaRequired() + ) + ->addRow( + (new CLabel(_('Network timeout for script execution'), 'script_timeout'))->setAsteriskMark(), + (new CTextBox('script_timeout', $data['script_timeout'], false, DB::getFieldLength('config', 'script_timeout'))) + ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) + ->setAriaRequired() + ) + ->addRow( + (new CLabel(_('Network timeout for item test'), 'item_test_timeout'))->setAsteriskMark(), + (new CTextBox('item_test_timeout', $data['item_test_timeout'], false, + DB::getFieldLength('config', 'item_test_timeout') + )) + ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) + ->setAriaRequired() ); $form = (new CForm()) @@ -72,7 +183,12 @@ $form = (new CForm()) ->addItem( (new CTabView()) ->addTab('other', _('Other parameters'), $from_list) - ->setFooter(makeFormFooter(new CSubmit('update', _('Update')))) + ->setFooter(makeFormFooter( + new CSubmit('update', _('Update')), + [new CButton('resetDefaults', _('Reset defaults'))] + )) ); -$widget->addItem($form)->show(); +$widget + ->addItem($form) + ->show(); diff --git a/ui/app/views/administration.trigdisplay.edit.php b/ui/app/views/administration.trigdisplay.edit.php index 84f6f0df9b3..b2fd788ee63 100644 --- a/ui/app/views/administration.trigdisplay.edit.php +++ b/ui/app/views/administration.trigdisplay.edit.php @@ -41,6 +41,7 @@ $form_list = (new CFormList()) (new CColor('problem_unack_color', $data['problem_unack_color'])) ->setEnabled($data['custom_color'] == EVENT_CUSTOM_COLOR_ENABLED) ->addClass(($data['custom_color'] == EVENT_CUSTOM_COLOR_DISABLED) ? ZBX_STYLE_DISABLED : null) + ->addClass('js-event-color-picker') ->setAriaRequired(), (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), (new CCheckBox('problem_unack_style')) @@ -52,6 +53,7 @@ $form_list = (new CFormList()) (new CColor('problem_ack_color', $data['problem_ack_color'])) ->setEnabled($data['custom_color'] == EVENT_CUSTOM_COLOR_ENABLED) ->addClass(($data['custom_color'] == EVENT_CUSTOM_COLOR_DISABLED) ? ZBX_STYLE_DISABLED : null) + ->addClass('js-event-color-picker') ->setAriaRequired(), (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), (new CCheckBox('problem_ack_style')) @@ -63,6 +65,7 @@ $form_list = (new CFormList()) (new CColor('ok_unack_color', $data['ok_unack_color'])) ->setEnabled($data['custom_color'] == EVENT_CUSTOM_COLOR_ENABLED) ->addClass(($data['custom_color'] == EVENT_CUSTOM_COLOR_DISABLED) ? ZBX_STYLE_DISABLED : null) + ->addClass('js-event-color-picker') ->setAriaRequired(), (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), (new CCheckBox('ok_unack_style')) @@ -74,6 +77,7 @@ $form_list = (new CFormList()) (new CColor('ok_ack_color', $data['ok_ack_color'])) ->setEnabled($data['custom_color'] == EVENT_CUSTOM_COLOR_ENABLED) ->addClass(($data['custom_color'] == EVENT_CUSTOM_COLOR_DISABLED) ? ZBX_STYLE_DISABLED : null) + ->addClass('js-event-color-picker') ->setAriaRequired(), (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), (new CCheckBox('ok_ack_style')) @@ -83,17 +87,72 @@ $form_list = (new CFormList()) ]) ->addRow(null) ->addRow((new CLabel(_('Display OK triggers for'), 'ok_period'))->setAsteriskMark(), [ - (new CTextBox('ok_period', $data['ok_period'])) + (new CTextBox('ok_period', $data['ok_period'], false, DB::getFieldLength('config', 'ok_period'))) ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) ->setAriaRequired() - ->setAttribute('maxlength', '6') ]) ->addRow((new CLabel(_('On status change triggers blink for'), 'blink_period'))->setAsteriskMark(), [ - (new CTextBox('blink_period', $data['blink_period'])) + (new CTextBox('blink_period', $data['blink_period'], false, DB::getFieldLength('config', 'blink_period'))) ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) ->setAriaRequired() - ->setAttribute('maxlength', '6') - ]); + ]) + ->addRow(null) + ->addRow((new CLabel(_('Not classified'), 'severity_name_0'))->setAsteriskMark(), [ + (new CTextBox('severity_name_0', $data['severity_name_0'], false, + DB::getFieldLength('config', 'severity_name_0') + )) + ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) + ->setAriaRequired(), + (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), + new CColor('severity_color_0', $data['severity_color_0']) + ]) + ->addRow((new CLabel(_('Information'), 'severity_name_1'))->setAsteriskMark(), [ + (new CTextBox('severity_name_1', $data['severity_name_1'], false, + DB::getFieldLength('config', 'severity_name_1') + )) + ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) + ->setAriaRequired(), + (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), + new CColor('severity_color_1', $data['severity_color_1']) + ]) + ->addRow((new CLabel(_('Warning'), 'severity_name_2'))->setAsteriskMark(), [ + (new CTextBox('severity_name_2', $data['severity_name_2'], false, + DB::getFieldLength('config', 'severity_name_2') + )) + ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) + ->setAriaRequired(), + (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), + new CColor('severity_color_2', $data['severity_color_2']) + ]) + ->addRow((new CLabel(_('Average'), 'severity_name_3'))->setAsteriskMark(), [ + (new CTextBox('severity_name_3', $data['severity_name_3'], false, + DB::getFieldLength('config', 'severity_name_3') + )) + ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) + ->setAriaRequired(), + (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), + new CColor('severity_color_3', $data['severity_color_3']) + ]) + ->addRow((new CLabel(_('High'), 'severity_name_4'))->setAsteriskMark(), [ + (new CTextBox('severity_name_4', $data['severity_name_4'], false, + DB::getFieldLength('config', 'severity_name_4') + )) + ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) + ->setAriaRequired(), + (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), + new CColor('severity_color_4', $data['severity_color_4']) + ]) + ->addRow((new CLabel(_('Disaster'), 'severity_name_5'))->setAsteriskMark(), [ + (new CTextBox('severity_name_5', $data['severity_name_5'], false, + DB::getFieldLength('config', 'severity_name_5') + )) + ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) + ->setAriaRequired(), + (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), + new CColor('severity_color_5', $data['severity_color_5']) + ]) + ->addRow(null) + ->addInfo(_('Custom severity names affect all locales and require manual translation!')); $form = (new CForm()) ->setAttribute('aria-labeledby', ZBX_STYLE_PAGE_TITLE) diff --git a/ui/app/views/administration.trigseverity.edit.php b/ui/app/views/administration.trigseverity.edit.php deleted file mode 100644 index 5c55028fc79..00000000000 --- a/ui/app/views/administration.trigseverity.edit.php +++ /dev/null @@ -1,102 +0,0 @@ -<?php -/* -** Zabbix -** Copyright (C) 2001-2020 Zabbix SIA -** -** This program is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -**/ - - -/** - * @var CView $this - */ - -$this->addJsFile('colorpicker.js'); - -$this->includeJsFile('administration.trigseverity.edit.js.php'); - -$widget = (new CWidget()) - ->setTitle(_('Trigger severities')) - ->setTitleSubmenu(getAdministrationGeneralSubmenu()); - -$severity_tab = (new CFormList()) - ->addRow((new CLabel(_('Not classified'), 'severity_name_0'))->setAsteriskMark(), [ - (new CTextBox('severity_name_0', $data['severity_name_0'])) - ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) - ->setAriaRequired() - ->setAttribute('maxlength', 32) - ->setAttribute('autofocus', 'autofocus'), - (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), - new CColor('severity_color_0', $data['severity_color_0']) - ]) - ->addRow((new CLabel(_('Information'), 'severity_name_1'))->setAsteriskMark(), [ - (new CTextBox('severity_name_1', $data['severity_name_1'])) - ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) - ->setAriaRequired() - ->setAttribute('maxlength', 32), - (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), - new CColor('severity_color_1', $data['severity_color_1']) - ]) - ->addRow((new CLabel(_('Warning'), 'severity_name_2'))->setAsteriskMark(), [ - (new CTextBox('severity_name_2', $data['severity_name_2'])) - ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) - ->setAriaRequired() - ->setAttribute('maxlength', 32), - (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), - new CColor('severity_color_2', $data['severity_color_2']) - ]) - ->addRow((new CLabel(_('Average'), 'severity_name_3'))->setAsteriskMark(), [ - (new CTextBox('severity_name_3', $data['severity_name_3'])) - ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) - ->setAriaRequired() - ->setAttribute('maxlength', 32), - (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), - new CColor('severity_color_3', $data['severity_color_3']) - ]) - ->addRow((new CLabel(_('High'), 'severity_name_4'))->setAsteriskMark(), [ - (new CTextBox('severity_name_4', $data['severity_name_4'])) - ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) - ->setAriaRequired() - ->setAttribute('maxlength', 32), - (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), - new CColor('severity_color_4', $data['severity_color_4']) - ]) - ->addRow((new CLabel(_('Disaster'), 'severity_name_5'))->setAsteriskMark(), [ - (new CTextBox('severity_name_5', $data['severity_name_5'])) - ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) - ->setAriaRequired() - ->setAttribute('maxlength', 32), - (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), - new CColor('severity_color_5', $data['severity_color_5']) - ]) - ->addRow(null) - ->addInfo(_('Custom severity names affect all locales and require manual translation!')); - -$form = (new CForm()) - ->setAttribute('aria-labeledby', ZBX_STYLE_PAGE_TITLE) - ->setAction((new CUrl('zabbix.php')) - ->setArgument('action', 'trigseverity.update') - ->getUrl() - ) - ->addItem( - (new CTabView()) - ->addTab('severities', _('Trigger severities'), $severity_tab) - ->setFooter(makeFormFooter( - new CSubmit('update', _('Update')), - [new CButton('resetDefaults', _('Reset defaults'))] - )) - ); - -$widget->addItem($form)->show(); diff --git a/ui/app/views/administration.user.edit.php b/ui/app/views/administration.user.edit.php index 427d8ace6e3..10cf06c41b7 100644 --- a/ui/app/views/administration.user.edit.php +++ b/ui/app/views/administration.user.edit.php @@ -261,7 +261,7 @@ if ($data['action'] === 'user.edit' || CWebUser::$data['type'] > USER_TYPE_ZABBI $media_severity = []; for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_COUNT; $severity++) { - $severity_name = getSeverityName($severity, $data['config']); + $severity_name = getSeverityName($severity); $media_active = ($media['severity'] & (1 << $severity)); @@ -425,7 +425,7 @@ if ($data['action'] !== 'user.edit') { for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_COUNT; $severity++) { $triggers_table->addRow([ (new CCheckBox('messages[triggers.severities]['.$severity.']')) - ->setLabel(getSeverityName($severity, $data['config'])) + ->setLabel(getSeverityName($severity)) ->setChecked(array_key_exists($severity, $data['messages']['triggers.severities'])) ->setUncheckedValue(0), [ diff --git a/ui/app/views/administration.user.list.php b/ui/app/views/administration.user.list.php index 24903d69923..837566aab32 100644 --- a/ui/app/views/administration.user.list.php +++ b/ui/app/views/administration.user.list.php @@ -123,7 +123,7 @@ foreach ($data['users'] as $user) { $online = (new CCol(_('No')))->addClass(ZBX_STYLE_RED); } - $blocked = ($user['attempt_failed'] >= ZBX_LOGIN_ATTEMPTS) + $blocked = ($user['attempt_failed'] >= $data['config']['login_attempts']) ? (new CLink(_('Blocked'), 'zabbix.php?action=user.unblock&userids[]='.$userid)) ->addClass(ZBX_STYLE_LINK_ACTION) ->addClass(ZBX_STYLE_RED) diff --git a/ui/app/views/administration.workingtime.edit.php b/ui/app/views/administration.workingtime.edit.php deleted file mode 100644 index 69b1606e3c4..00000000000 --- a/ui/app/views/administration.workingtime.edit.php +++ /dev/null @@ -1,47 +0,0 @@ -<?php -/* -** Zabbix -** Copyright (C) 2001-2020 Zabbix SIA -** -** This program is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -**/ - - -/** - * @var CView $this - */ - -$widget = (new CWidget()) - ->setTitle(_('Working time')) - ->setTitleSubmenu(getAdministrationGeneralSubmenu()); - -$table = (new CTabView()) - ->addTab('workingTime', _('Working time'), - (new CFormList()) - ->addRow((new CLabel(_('Working time'), 'work_period'))->setAsteriskMark(), - (new CTextBox('work_period', $data['work_period'])) - ->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH) - ->setAriaRequired() - ->setAttribute('autofocus', 'autofocus') - ) - ) - ->setFooter(makeFormFooter(new CSubmit('update', _('Update')))); - -$form = (new CForm()) - ->setAttribute('aria-labeledby', ZBX_STYLE_PAGE_TITLE) - ->setAction((new CUrl('zabbix.php'))->setArgument('action', 'workingtime.update')->getUrl()) - ->addItem($table); - -$widget->addItem($form)->show(); diff --git a/ui/app/views/js/administration.gui.edit.js.php b/ui/app/views/js/administration.gui.edit.js.php new file mode 100644 index 00000000000..565d8f31638 --- /dev/null +++ b/ui/app/views/js/administration.gui.edit.js.php @@ -0,0 +1,72 @@ +<?php +/* +** Zabbix +** Copyright (C) 2001-2020 Zabbix SIA +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +**/ + + +/** + * @var CView $this + */ +?> + +<script type="text/javascript"> + $(document).ready(function() { + $("#resetDefaults").click(function() { + overlayDialogue({ + 'title': <?= json_encode(_('Reset confirmation')) ?>, + 'content': $('<span>').text(<?= json_encode(_('Reset all fields to default values?')) ?>), + 'buttons': [ + { + 'title': <?= json_encode(_('Cancel')) ?>, + 'cancel': true, + 'class': '<?= ZBX_STYLE_BTN_ALT ?>', + 'action': function() {} + }, + { + 'title': <?= json_encode(_('Reset defaults')) ?>, + 'focused': true, + 'action': function() { + $('main') + .prev('.msg-bad') + .remove(); + + $('#default_lang').val("<?= DB::getDefault('config', 'default_lang') ?>"); + $('#default_timezone').val("<?= DB::getDefault('config', 'default_timezone') ?>"); + $('#default_theme').val("<?= DB::getDefault('config', 'default_theme') ?>"); + $('#search_limit').val("<?= DB::getDefault('config', 'search_limit') ?>"); + $('#max_overview_table_size').val( + "<?= DB::getDefault('config', 'max_overview_table_size') ?>" + ); + $('#max_in_table').val("<?= DB::getDefault('config', 'max_in_table') ?>"); + $('#server_check_interval').prop('checked', + <?= (DB::getDefault('config', 'server_check_interval') == 0) ? 'false' : 'true' ?> + ); + $('#work_period').val("<?= DB::getDefault('config', 'work_period') ?>"); + $('#show_technical_errors').prop('checked', + <?= (DB::getDefault('config', 'show_technical_errors') == 0) ? 'false' : 'true' ?> + ); + $('#history_period').val("<?= DB::getDefault('config', 'history_period') ?>"); + $('#period_default').val("<?= DB::getDefault('config', 'period_default') ?>"); + $('#max_period').val("<?= DB::getDefault('config', 'max_period') ?>"); + } + } + ] + }, this); + }); + }); +</script> diff --git a/ui/app/views/js/administration.housekeeping.edit.js.php b/ui/app/views/js/administration.housekeeping.edit.js.php index f6cedac52ba..9d1aa1faa12 100644 --- a/ui/app/views/js/administration.housekeeping.edit.js.php +++ b/ui/app/views/js/administration.housekeeping.edit.js.php @@ -22,12 +22,10 @@ /** * @var CView $this */ - -$schema = DB::getSchema('config'); ?> <script type="text/javascript"> - jQuery(function($) { + $(document).ready(function() { var $form = $('form#housekeeping'); $form.on('submit', function() { @@ -36,41 +34,41 @@ $schema = DB::getSchema('config'); ]); }); - jQuery('#hk_events_mode').change(function() { - jQuery('#hk_events_trigger').prop('disabled', !this.checked); - jQuery('#hk_events_internal').prop('disabled', !this.checked); - jQuery('#hk_events_discovery').prop('disabled', !this.checked); - jQuery('#hk_events_autoreg').prop('disabled', !this.checked); + $('#hk_events_mode').change(function() { + $('#hk_events_trigger').prop('disabled', !this.checked); + $('#hk_events_internal').prop('disabled', !this.checked); + $('#hk_events_discovery').prop('disabled', !this.checked); + $('#hk_events_autoreg').prop('disabled', !this.checked); }); - jQuery('#hk_services_mode').change(function() { - jQuery('#hk_services').prop('disabled', !this.checked); + $('#hk_services_mode').change(function() { + $('#hk_services').prop('disabled', !this.checked); }); - jQuery('#hk_audit_mode').change(function() { - jQuery('#hk_audit').prop('disabled', !this.checked); + $('#hk_audit_mode').change(function() { + $('#hk_audit').prop('disabled', !this.checked); }); - jQuery('#hk_sessions_mode').change(function() { - jQuery('#hk_sessions').prop('disabled', !this.checked); + $('#hk_sessions_mode').change(function() { + $('#hk_sessions').prop('disabled', !this.checked); }); - jQuery('#hk_history_global').change(function() { - jQuery('#hk_history').prop('disabled', !this.checked); + $('#hk_history_global').change(function() { + $('#hk_history').prop('disabled', !this.checked); }); - jQuery('#hk_trends_global').change(function() { - jQuery('#hk_trends').prop('disabled', !this.checked); + $('#hk_trends_global').change(function() { + $('#hk_trends').prop('disabled', !this.checked); }); - jQuery('#compression_status').change(function() { - jQuery('#compress_older').prop('disabled', !this.checked); + $('#compression_status').change(function() { + $('#compress_older').prop('disabled', !this.checked); }); - jQuery("#resetDefaults").click(function() { + $("#resetDefaults").click(function() { overlayDialogue({ 'title': <?= json_encode(_('Reset confirmation')) ?>, - 'content': jQuery('<span>').text(<?= json_encode(_('Reset all fields to default values?')) ?>), + 'content': $('<span>').text(<?= json_encode(_('Reset all fields to default values?')) ?>), 'buttons': [ { 'title': <?= json_encode(_('Cancel')) ?>, @@ -82,74 +80,72 @@ $schema = DB::getSchema('config'); 'title': <?= json_encode(_('Reset defaults')) ?>, 'focused': true, 'action': function() { + $('main') + .prev('.msg-bad') + .remove(); + // events and alerts - jQuery('#hk_events_mode') + $('#hk_events_mode') .prop('checked', - <?= ($schema['fields']['hk_events_mode']['default'] == 1) ? 'true' : 'false' ?> + <?= (DB::getDefault('config', 'hk_events_mode') == 1) ? 'true' : 'false' ?> ) .change(); - jQuery('#hk_events_trigger') - .val("<?= $schema['fields']['hk_events_trigger']['default'] ?>"); - jQuery('#hk_events_internal') - .val("<?= $schema['fields']['hk_events_internal']['default'] ?>"); - jQuery('#hk_events_discovery') - .val("<?= $schema['fields']['hk_events_discovery']['default'] ?>"); - jQuery('#hk_events_autoreg') - .val("<?= $schema['fields']['hk_events_autoreg']['default'] ?>"); - - // Services - jQuery('#hk_services_mode') + $('#hk_events_trigger').val("<?= DB::getDefault('config', 'hk_events_trigger') ?>"); + $('#hk_events_internal').val("<?= DB::getDefault('config', 'hk_events_internal') ?>"); + $('#hk_events_discovery').val("<?= DB::getDefault('config', 'hk_events_discovery') ?>"); + $('#hk_events_autoreg').val("<?= DB::getDefault('config', 'hk_events_autoreg') ?>"); + $('#hk_services_mode') .prop('checked', - <?= ($schema['fields']['hk_services_mode']['default'] == 1) ? 'true' : 'false' ?> + <?= (DB::getDefault('config', 'hk_services_mode') == 1) ? 'true' : 'false' ?> ) .change(); - jQuery('#hk_services').val("<?= $schema['fields']['hk_services']['default'] ?>"); + $('#hk_services').val("<?= DB::getDefault('config', 'hk_services') ?>"); // audit - jQuery('#hk_audit_mode') + $('#hk_audit_mode') .prop('checked', - <?= ($schema['fields']['hk_audit_mode']['default'] == 1) ? 'true' : 'false' ?> + <?= (DB::getDefault('config', 'hk_audit_mode') == 1) ? 'true' : 'false' ?> ) .change(); - jQuery('#hk_audit').val("<?= $schema['fields']['hk_audit']['default'] ?>"); + $('#hk_audit').val("<?= DB::getDefault('config', 'hk_audit') ?>"); // user sessions - jQuery('#hk_sessions_mode') + $('#hk_sessions_mode') .prop('checked', - <?= ($schema['fields']['hk_sessions_mode']['default'] == 1) ? 'true' : 'false' ?> + <?= (DB::getDefault('config', 'hk_sessions_mode') == 1) ? 'true' : 'false' ?> ) .change(); - jQuery('#hk_sessions').val("<?= $schema['fields']['hk_sessions']['default'] ?>"); + $('#hk_sessions').val("<?= DB::getDefault('config', 'hk_sessions') ?>"); // history - jQuery('#hk_history_mode').prop('checked', - <?= ($schema['fields']['hk_history_mode']['default'] == 1) ? 'true' : 'false' ?> + $('#hk_history_mode').prop('checked', + <?= (DB::getDefault('config', 'hk_history_mode') == 1) ? 'true' : 'false' ?> ); - jQuery('#hk_history_global') + $('#hk_history_global') .prop('checked', - <?= ($schema['fields']['hk_history_global']['default'] == 1) ? 'true' : 'false' ?> + <?= (DB::getDefault('config', 'hk_history_global') == 1) ? 'true' : 'false' ?> ) .change(); - jQuery('#hk_history').val("<?= $schema['fields']['hk_history']['default'] ?>"); + $('#hk_history').val("<?= DB::getDefault('config', 'hk_history') ?>"); // trends - jQuery('#hk_trends_mode').prop('checked', - <?= ($schema['fields']['hk_trends_mode']['default'] == 1) ? 'true' : 'false' ?> + $('#hk_trends_mode').prop('checked', + <?= (DB::getDefault('config', 'hk_trends_mode') == 1) ? 'true' : 'false' ?> ); - jQuery('#hk_trends_global') + $('#hk_trends_global') .prop('checked', - <?= ($schema['fields']['hk_trends_global']['default'] == 1) ? 'true' : 'false' ?> + <?= (DB::getDefault('config', 'hk_trends_global') == 1) ? 'true' : 'false' ?> ) .change(); - jQuery('#hk_trends').val("<?= $schema['fields']['hk_trends']['default'] ?>"); + $('#hk_trends').val("<?= DB::getDefault('config', 'hk_trends') ?>"); // history and trends compression - jQuery('#compression_status') + $('#compression_status') .prop('checked', - <?= ($schema['fields']['compression_status']['default'] == 1) ? 'true' : 'false' ?> + <?= (DB::getDefault('config', 'compression_status') == 1) ? 'true' : 'false' ?> ) .change(); - jQuery('#compress_older').val("<?= $schema['fields']['compress_older']['default'] ?>"); + $('#compress_older').val("<?= DB::getDefault('config', 'compress_older') ?>"); } } ] diff --git a/ui/app/views/js/administration.miscconfig.edit.js.php b/ui/app/views/js/administration.miscconfig.edit.js.php new file mode 100644 index 00000000000..50bfcedeb3e --- /dev/null +++ b/ui/app/views/js/administration.miscconfig.edit.js.php @@ -0,0 +1,102 @@ +<?php +/* +** Zabbix +** Copyright (C) 2001-2020 Zabbix SIA +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +**/ + + +/** + * @var CView $this + */ + +$default_inventory_mode = DB::getDefault('config', 'default_inventory_mode'); +?> + +<script type="text/javascript"> + $(document).ready(function() { + $('#validate_uri_schemes').change(function() { + $('#uri_valid_schemes').prop('disabled', !this.checked); + }); + + $('#iframe_sandboxing_enabled').change(function() { + $('#iframe_sandboxing_exceptions').prop('disabled', !this.checked); + }); + + $("#resetDefaults").click(function() { + overlayDialogue({ + 'title': <?= json_encode(_('Reset confirmation')) ?>, + 'content': $('<span>').text(<?= json_encode(_('Reset all fields to default values?')) ?>), + 'buttons': [ + { + 'title': <?= json_encode(_('Cancel')) ?>, + 'cancel': true, + 'class': '<?= ZBX_STYLE_BTN_ALT ?>', + 'action': function() {} + }, + { + 'title': <?= json_encode(_('Reset defaults')) ?>, + 'focused': true, + 'action': function() { + $('main') + .prev('.msg-bad') + .remove(); + + $('#refresh_unsupported').val("<?= DB::getDefault('config', 'refresh_unsupported') ?>"); + $('#discovery_groupid').multiSelect('clean'); + $('#default_inventory_mode input[value=<?= $default_inventory_mode ?>]') + .prop('checked', true); + $('#alert_usrgrpid').multiSelect('clean'); + $('#snmptrap_logging').prop('checked', + <?= (DB::getDefault('config', 'snmptrap_logging') == 0) ? 'false' : 'true' ?> + ); + + // authorization + $('#login_attempts').val("<?= DB::getDefault('config', 'login_attempts') ?>"); + $('#login_block').val("<?= DB::getDefault('config', 'login_block') ?>"); + + // security + $('#validate_uri_schemes') + .prop('checked', + <?= (DB::getDefault('config', 'validate_uri_schemes') == 0) ? 'false' : 'true' ?> + ) + .change(); + $('#uri_valid_schemes').val("<?= DB::getDefault('config', 'uri_valid_schemes') ?>"); + $('#x_frame_options').val("<?= DB::getDefault('config', 'x_frame_options') ?>"); + $('#iframe_sandboxing_enabled') + .prop('checked', + <?= (DB::getDefault('config', 'iframe_sandboxing_enabled') == 0) ? 'false' : 'true' ?> + ) + .change(); + $('#iframe_sandboxing_exceptions').val( + "<?= DB::getDefault('config', 'iframe_sandboxing_exceptions') ?>" + ); + + // communication with Zabbix server + $('#socket_timeout').val("<?= DB::getDefault('config', 'socket_timeout') ?>"); + $('#connect_timeout').val("<?= DB::getDefault('config', 'connect_timeout') ?>"); + $('#media_type_test_timeout').val( + "<?= DB::getDefault('config', 'media_type_test_timeout') ?>" + ); + $('#script_timeout').val("<?= DB::getDefault('config', 'script_timeout') ?>"); + $('#item_test_timeout').val("<?= DB::getDefault('config', 'item_test_timeout') ?>"); + } + } + ] + }, this); + }); + }); +</script> diff --git a/ui/app/views/js/administration.trigdisplay.edit.js.php b/ui/app/views/js/administration.trigdisplay.edit.js.php index 92ed415e3e1..c6ee7d5b220 100644 --- a/ui/app/views/js/administration.trigdisplay.edit.js.php +++ b/ui/app/views/js/administration.trigdisplay.edit.js.php @@ -22,24 +22,30 @@ /** * @var CView $this */ - -$schema = DB::getSchema('config'); ?> <script type="text/javascript"> - jQuery(document).ready(function() { - jQuery("input[name=custom_color]").on('change', function() { - var checked = jQuery(this).is(':checked'); - jQuery(".input-color-picker").each(function() { - var $field = jQuery(this); + $(document).ready(function() { + var $form = $('form'); + $form.on('submit', function() { + $form.trimValues(['#severity_name_0', '#severity_name_1', '#severity_name_2', '#severity_name_3', + '#severity_name_4', '#severity_name_5' + ]); + }); + + $("input[name=custom_color]").on('change', function() { + var checked = $(this).is(':checked'); + $(".js-event-color-picker").each(function() { + var $field = $(this); $field.toggleClass('<?= ZBX_STYLE_DISABLED ?>', !checked); - jQuery("input", $field).prop('disabled', !checked); + $("input", $field).prop('disabled', !checked); }); }); - jQuery("#resetDefaults").click(function() { + + $("#resetDefaults").click(function() { overlayDialogue({ 'title': <?= json_encode(_('Reset confirmation')) ?>, - 'content': jQuery('<span>').text(<?= json_encode(_('Reset all fields to default values?')) ?>), + 'content': $('<span>').text(<?= json_encode(_('Reset all fields to default values?')) ?>), 'buttons': [ { 'title': <?= json_encode(_('Cancel')) ?>, @@ -51,54 +57,83 @@ $schema = DB::getSchema('config'); 'title': <?= json_encode(_('Reset defaults')) ?>, 'focused': true, 'action': function() { + $('main') + .prev('.msg-bad') + .remove(); + var custom_color_enabled = <?= - ($schema['fields']['custom_color']['default'] == EVENT_CUSTOM_COLOR_ENABLED) + (DB::getDefault('config', 'custom_color') == EVENT_CUSTOM_COLOR_ENABLED) ? 'true' : 'false' ?>; - jQuery('#custom_color') + $('#custom_color') .prop('checked', custom_color_enabled) - .trigger('change'); + .change(); - // Unacknowledged problem events - jQuery('#problem_unack_color') - .val("<?= $schema['fields']['problem_unack_color']['default'] ?>") + // unacknowledged problem events + $('#problem_unack_color') + .val("<?= DB::getDefault('config', 'problem_unack_color') ?>") .prop('disabled', !custom_color_enabled) - .trigger('change'); - jQuery('#problem_unack_style').prop('checked', - <?= ($schema['fields']['problem_unack_style']['default'] == 0) ? 'false' : 'true' ?> + .change(); + $('#problem_unack_style').prop('checked', + <?= (DB::getDefault('config', 'problem_unack_style') == 0) ? 'false' : 'true' ?> ); - // Acknowledged problem events - jQuery('#problem_ack_color') - .val("<?= $schema['fields']['problem_ack_color']['default'] ?>") + // acknowledged problem events + $('#problem_ack_color') + .val("<?= DB::getDefault('config', 'problem_ack_color') ?>") .prop('disabled', !custom_color_enabled) - .trigger('change'); - jQuery('#problem_ack_style').prop('checked', - <?= ($schema['fields']['problem_ack_style']['default'] == 0) ? 'false' : 'true' ?> + .change(); + $('#problem_ack_style').prop('checked', + <?= (DB::getDefault('config', 'problem_ack_style') == 0) ? 'false' : 'true' ?> ); - // Unacknowledged resolved events - jQuery('#ok_unack_color') - .val("<?= $schema['fields']['ok_unack_color']['default'] ?>") + // unacknowledged resolved events + $('#ok_unack_color') + .val("<?= DB::getDefault('config', 'ok_unack_color') ?>") .prop('disabled', !custom_color_enabled) - .trigger('change'); - jQuery('#ok_unack_style').prop('checked', - <?= ($schema['fields']['ok_unack_style']['default'] == 0) ? 'false' : 'true' ?> + .change(); + $('#ok_unack_style').prop('checked', + <?= (DB::getDefault('config', 'ok_unack_style') == 0) ? 'false' : 'true' ?> ); - // Acknowledged resolved events - jQuery('#ok_ack_color') - .val("<?= $schema['fields']['ok_ack_color']['default'] ?>") + // acknowledged resolved events + $('#ok_ack_color') + .val("<?= DB::getDefault('config', 'ok_ack_color') ?>") .prop('disabled', !custom_color_enabled) - .trigger('change'); - jQuery('#ok_ack_style').prop('checked', - <?= ($schema['fields']['ok_ack_style']['default'] == 0) ? 'false' : 'true' ?> + .change(); + $('#ok_ack_style').prop('checked', + <?= (DB::getDefault('config', 'ok_ack_style') == 0) ? 'false' : 'true' ?> ); - jQuery('#ok_period').val("<?= $schema['fields']['ok_period']['default'] ?>"); - jQuery('#blink_period').val("<?= $schema['fields']['blink_period']['default'] ?>"); + $('#ok_period').val("<?= DB::getDefault('config', 'ok_period') ?>"); + $('#blink_period').val("<?= DB::getDefault('config', 'blink_period') ?>"); + + $('#severity_name_0').val("<?= DB::getDefault('config', 'severity_name_0') ?>"); + $('#severity_name_1').val("<?= DB::getDefault('config', 'severity_name_1') ?>"); + $('#severity_name_2').val("<?= DB::getDefault('config', 'severity_name_2') ?>"); + $('#severity_name_3').val("<?= DB::getDefault('config', 'severity_name_3') ?>"); + $('#severity_name_4').val("<?= DB::getDefault('config', 'severity_name_4') ?>"); + $('#severity_name_5').val("<?= DB::getDefault('config', 'severity_name_5') ?>"); + $('#severity_color_0') + .val("<?= DB::getDefault('config', 'severity_color_0') ?>") + .change(); + $('#severity_color_1') + .val("<?= DB::getDefault('config', 'severity_color_1') ?>") + .change(); + $('#severity_color_2') + .val("<?= DB::getDefault('config', 'severity_color_2') ?>") + .change(); + $('#severity_color_3') + .val("<?= DB::getDefault('config', 'severity_color_3') ?>") + .change(); + $('#severity_color_4') + .val("<?= DB::getDefault('config', 'severity_color_4') ?>") + .change(); + $('#severity_color_5') + .val("<?= DB::getDefault('config', 'severity_color_5') ?>") + .change(); } } ] diff --git a/ui/app/views/js/administration.trigseverity.edit.js.php b/ui/app/views/js/administration.trigseverity.edit.js.php deleted file mode 100644 index 820f6442509..00000000000 --- a/ui/app/views/js/administration.trigseverity.edit.js.php +++ /dev/null @@ -1,83 +0,0 @@ -<?php -/* -** Zabbix -** Copyright (C) 2001-2020 Zabbix SIA -** -** This program is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -**/ - - -/** - * @var CView $this - */ - -$schema = DB::getSchema('config'); -?> - -<script type="text/javascript"> - jQuery(function($) { - $("#resetDefaults").click(function() { - overlayDialogue({ - 'title': <?= json_encode(_('Reset confirmation')) ?>, - 'content': $('<span>').text(<?= json_encode(_('Reset all fields to default values?')) ?>), - 'buttons': [ - { - 'title': <?= json_encode(_('Cancel')) ?>, - 'cancel': true, - 'class': '<?= ZBX_STYLE_BTN_ALT ?>', - 'action': function() {} - }, - { - 'title': <?= json_encode(_('Reset defaults')) ?>, - 'focused': true, - 'action': function() { - $('#severity_name_0').val("<?= $schema['fields']['severity_name_0']['default'] ?>"); - $('#severity_name_1').val("<?= $schema['fields']['severity_name_1']['default'] ?>"); - $('#severity_name_2').val("<?= $schema['fields']['severity_name_2']['default'] ?>"); - $('#severity_name_3').val("<?= $schema['fields']['severity_name_3']['default'] ?>"); - $('#severity_name_4').val("<?= $schema['fields']['severity_name_4']['default'] ?>"); - $('#severity_name_5').val("<?= $schema['fields']['severity_name_5']['default'] ?>"); - $('#severity_color_0') - .val("<?= $schema['fields']['severity_color_0']['default'] ?>") - .change(); - $('#severity_color_1') - .val("<?= $schema['fields']['severity_color_1']['default'] ?>") - .change(); - $('#severity_color_2') - .val("<?= $schema['fields']['severity_color_2']['default'] ?>") - .change(); - $('#severity_color_3') - .val("<?= $schema['fields']['severity_color_3']['default'] ?>") - .change(); - $('#severity_color_4') - .val("<?= $schema['fields']['severity_color_4']['default'] ?>") - .change(); - $('#severity_color_5') - .val("<?= $schema['fields']['severity_color_5']['default'] ?>") - .change(); - } - } - ] - }, this); - }); - - var $form = $('form'); - $form.on('submit', function() { - $form.trimValues(['#severity_name_0', '#severity_name_1', '#severity_name_2', '#severity_name_3', - '#severity_name_4', '#severity_name_5' - ]); - }); - }); -</script> diff --git a/ui/app/views/js/reports.auditlog.list.js.php b/ui/app/views/js/reports.auditlog.list.js.php index 6336542a045..4dcb03b348e 100644 --- a/ui/app/views/js/reports.auditlog.list.js.php +++ b/ui/app/views/js/reports.auditlog.list.js.php @@ -96,7 +96,8 @@ AUDIT_RESOURCE_SCENARIO, AUDIT_RESOURCE_DISCOVERY_RULE, AUDIT_RESOURCE_SLIDESHOW, AUDIT_RESOURCE_PROXY, AUDIT_RESOURCE_REGEXP, AUDIT_RESOURCE_MAINTENANCE, AUDIT_RESOURCE_SCRIPT, AUDIT_RESOURCE_MACRO, AUDIT_RESOURCE_TEMPLATE, AUDIT_RESOURCE_ICON_MAP, - AUDIT_RESOURCE_DASHBOARD, AUDIT_RESOURCE_AUTOREGISTRATION, AUDIT_RESOURCE_MODULE + AUDIT_RESOURCE_DASHBOARD, AUDIT_RESOURCE_AUTOREGISTRATION, AUDIT_RESOURCE_MODULE, + AUDIT_RESOURCE_SETTINGS, AUDIT_RESOURCE_HOUSEKEEPING, AUDIT_RESOURCE_AUTHENTICATION ], AUDIT_ACTION_DISABLE => [AUDIT_RESOURCE_HOST, AUDIT_RESOURCE_DISCOVERY_RULE], AUDIT_ACTION_ENABLE => [AUDIT_RESOURCE_HOST, AUDIT_RESOURCE_DISCOVERY_RULE], diff --git a/ui/app/views/layout.htmlpage.php b/ui/app/views/layout.htmlpage.php index 09aedf97052..26089a7fc04 100644 --- a/ui/app/views/layout.htmlpage.php +++ b/ui/app/views/layout.htmlpage.php @@ -28,13 +28,14 @@ function local_showHeader(array $data): void { header('X-Content-Type-Options: nosniff'); header('X-XSS-Protection: 1; mode=block'); - if (X_FRAME_OPTIONS !== null) { - if (strcasecmp(X_FRAME_OPTIONS, 'SAMEORIGIN') == 0 || strcasecmp(X_FRAME_OPTIONS, 'DENY') == 0) { - $x_frame_options = X_FRAME_OPTIONS; + if ($data['config']['x_frame_options'] !== '') { + if (strcasecmp($data['config']['x_frame_options'], 'SAMEORIGIN') == 0 + || strcasecmp($data['config']['x_frame_options'], 'DENY') == 0) { + $x_frame_options = $data['config']['x_frame_options']; } else { $x_frame_options = 'SAMEORIGIN'; - $allowed_urls = explode(',', X_FRAME_OPTIONS); + $allowed_urls = explode(',', $data['config']['x_frame_options']); $url_to_check = array_key_exists('HTTP_REFERER', $_SERVER) ? parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST) : null; @@ -63,7 +64,10 @@ function local_showHeader(array $data): void { 'lang' => CWebUser::$data['lang'], 'theme' => CWebUser::$data['theme'] ], - 'web_layout_mode' => $data['web_layout_mode'] + 'web_layout_mode' => $data['web_layout_mode'], + 'config' => [ + 'server_check_interval' => $data['config']['server_check_interval'] + ] ]))->getOutput(); } diff --git a/ui/app/views/monitoring.host.view.php b/ui/app/views/monitoring.host.view.php index 6c4dc3d3288..ed9a5376baf 100644 --- a/ui/app/views/monitoring.host.view.php +++ b/ui/app/views/monitoring.host.view.php @@ -88,7 +88,7 @@ $filter_tags_table->addRow( $severities = []; foreach (range(TRIGGER_SEVERITY_NOT_CLASSIFIED, TRIGGER_SEVERITY_COUNT - 1) as $severity) { $severities[] = [ - 'name' => getSeverityName($severity, $data['config']), + 'name' => getSeverityName($severity), 'value' => $severity ]; } @@ -162,7 +162,7 @@ if ($web_layout_mode == ZBX_LAYOUT_NORMAL) { } $widget->addItem(new CPartial('monitoring.host.view.html', array_intersect_key($data, array_flip([ - 'filter', 'sort', 'sortorder', 'view_curl', 'hosts', 'config', 'maintenances', 'paging' + 'filter', 'sort', 'sortorder', 'view_curl', 'hosts', 'maintenances', 'paging' ])))); $widget->show(); diff --git a/ui/app/views/monitoring.latest.view.php b/ui/app/views/monitoring.latest.view.php index 9dc6422ae7f..3c2d655ebf5 100644 --- a/ui/app/views/monitoring.latest.view.php +++ b/ui/app/views/monitoring.latest.view.php @@ -114,7 +114,7 @@ if ($web_layout_mode == ZBX_LAYOUT_NORMAL) { $widget->addItem(new CPartial('monitoring.latest.view.html', array_intersect_key($data, array_flip(['filter', 'sort_field', 'sort_order', 'view_curl', 'rows', 'hosts', 'applications', 'applications_size', 'items', 'history', - 'paging' + 'paging', 'config' ])))); $widget->show(); diff --git a/ui/app/views/monitoring.widget.problemhosts.view.php b/ui/app/views/monitoring.widget.problemhosts.view.php index 47458caabf7..cac7cc7994d 100644 --- a/ui/app/views/monitoring.widget.problemhosts.view.php +++ b/ui/app/views/monitoring.widget.problemhosts.view.php @@ -100,7 +100,7 @@ foreach ($data['groups'] as $group) { $problematic_count = (new CLinkAction($group['hosts_problematic_count'])) ->setHint(makeProblemHostsHintBox($group['hosts_problematic_list'], $data, $url_host)) ->setAttribute('aria-label', _xs('%1$s, Severity, %2$s', 'screen reader', - $group['hosts_problematic_count'], getSeverityName($group['highest_severity'], $data['config']) + $group['hosts_problematic_count'], getSeverityName($group['highest_severity']) )); } diff --git a/ui/app/views/monitoring.widget.problems.view.php b/ui/app/views/monitoring.widget.problems.view.php index c94a73e273f..a87e09e8a7a 100644 --- a/ui/app/views/monitoring.widget.problems.view.php +++ b/ui/app/views/monitoring.widget.problems.view.php @@ -191,7 +191,7 @@ foreach ($data['data']['problems'] as $eventid => $problem) { ) ) ->setAttribute('aria-label', _xs('%1$s, Severity, %2$s', 'screen reader', - $problem['name'], getSeverityName($problem['severity'], $data['config']) + $problem['name'], getSeverityName($problem['severity']) )) ]; @@ -207,14 +207,17 @@ foreach ($data['data']['problems'] as $eventid => $problem) { $description->addClass($description_style); } - if (!$show_recovery_data && $data['config'][$is_acknowledged ? 'problem_ack_style' : 'problem_unack_style']) { + if (!$show_recovery_data + && (($is_acknowledged && $data['config']['problem_ack_style']) + || (!$is_acknowledged && $data['config']['problem_unack_style']))) { // blinking $duration = time() - $problem['clock']; + $blink_period = timeUnitToSeconds($data['config']['blink_period']); - if ($data['config']['blink_period'] != 0 && $duration < $data['config']['blink_period']) { + if ($blink_period != 0 && $duration < $blink_period) { $description ->addClass('blink') - ->setAttribute('data-time-to-blink', $data['config']['blink_period'] - $duration) + ->setAttribute('data-time-to-blink', $blink_period - $duration) ->setAttribute('data-toggle-class', ZBX_STYLE_BLINK_HIDDEN); } } @@ -258,7 +261,7 @@ foreach ($data['data']['problems'] as $eventid => $problem) { ->addClass(ZBX_STYLE_NOWRAP), $problem_update_link, makeEventActionsIcons($problem['eventid'], $data['data']['actions'], $data['data']['mediatypes'], - $data['data']['users'], $data['config'] + $data['data']['users'] ), $data['fields']['show_tags'] ? $data['data']['tags'][$problem['eventid']] : null ])); diff --git a/ui/app/views/monitoring.widget.problemsbysv.view.php b/ui/app/views/monitoring.widget.problemsbysv.view.php index 725e5ab6bab..9611ade1653 100644 --- a/ui/app/views/monitoring.widget.problemsbysv.view.php +++ b/ui/app/views/monitoring.widget.problemsbysv.view.php @@ -41,7 +41,7 @@ else { for ($severity = TRIGGER_SEVERITY_COUNT - 1; $severity >= TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity--) { if (in_array($severity, $filter_severities)) { - $header[] = getSeverityName($severity, $data['severity_names']); + $header[] = getSeverityName($severity); } } diff --git a/ui/app/views/monitoring.widget.url.view.php b/ui/app/views/monitoring.widget.url.view.php index 5564e696fda..cb61ffce5ed 100644 --- a/ui/app/views/monitoring.widget.url.view.php +++ b/ui/app/views/monitoring.widget.url.view.php @@ -29,8 +29,8 @@ if ($data['url']['error'] !== null) { else { $item = (new CIFrame($data['url']['url'], '100%', '100%', 'auto'))->addClass(ZBX_STYLE_WIDGET_URL); - if (ZBX_IFRAME_SANDBOX !== false) { - $item->setAttribute('sandbox', ZBX_IFRAME_SANDBOX); + if ($data['config']['iframe_sandboxing_enabled'] == 1) { + $item->setAttribute('sandbox', $data['config']['iframe_sandboxing_exceptions']); } } diff --git a/ui/app/views/popup.acknowledge.edit.php b/ui/app/views/popup.acknowledge.edit.php index 2831f32f6a0..7acde438f2e 100644 --- a/ui/app/views/popup.acknowledge.edit.php +++ b/ui/app/views/popup.acknowledge.edit.php @@ -40,7 +40,7 @@ $form_list = (new CFormList()) if (array_key_exists('history', $data)) { $form_list->addRow(_('History'), - (new CDiv(makeEventHistoryTable($data['history'], $data['users'], $data['config']))) + (new CDiv(makeEventHistoryTable($data['history'], $data['users']))) ->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR) ->setAttribute('style', 'min-width: '.ZBX_TEXTAREA_BIG_WIDTH.'px;') ); diff --git a/ui/app/views/popup.generic.php b/ui/app/views/popup.generic.php index 1f97502a85a..d7f4ed7f07b 100644 --- a/ui/app/views/popup.generic.php +++ b/ui/app/views/popup.generic.php @@ -242,18 +242,8 @@ switch ($data['popup_type']) { ? new CCheckBox('item['.$item['usrgrpid'].']', $item['usrgrpid']) : null; - if ($data['multiselect']) { - $js_action = "javascript: addValue(".zbx_jsvalue($options['reference']).', '. - zbx_jsvalue($item['usrgrpid']).', '.$options['parentid'].');'; - } - else { - $values = [ - $options['dstfld1'] => $item[$options['srcfld1']], - $options['dstfld2'] => $item[$options['srcfld2']] - ]; - $js_action = 'javascript: addValues('.zbx_jsvalue($options['dstfrm']).', '. - zbx_jsvalue($values).', '.$options['parentid'].');'; - } + $js_action = "javascript: addValue(".zbx_jsvalue($options['reference']).', '. + zbx_jsvalue($item['usrgrpid']).', '.$options['parentid'].');'; $name = (new CLink($item['name'], 'javascript: void(0);')) ->setId('spanid'.$item['usrgrpid']) @@ -318,7 +308,7 @@ switch ($data['popup_type']) { $table->addRow([ $check_box, $description, - getSeverityCell($trigger['priority'], $options['config']), + getSeverityCell($trigger['priority']), (new CSpan(triggerIndicator($trigger['status'], $trigger['state']))) ->addClass(triggerIndicatorStyle($trigger['status'], $trigger['state'])) ]); @@ -644,7 +634,7 @@ if ($data['multiselect'] && $form !== null) { } // Types require results returned as array. -$types = ['users', 'templates', 'hosts', 'host_templates', 'host_groups', 'applications', 'application_prototypes', +$types = ['users', 'usrgrp', 'templates', 'hosts', 'host_templates', 'host_groups', 'applications', 'application_prototypes', 'proxies', 'items', 'item_prototypes', 'graphs', 'graph_prototypes' ]; diff --git a/ui/auditacts.php b/ui/auditacts.php index 3a7bd738204..7f5a50af07c 100644 --- a/ui/auditacts.php +++ b/ui/auditacts.php @@ -100,9 +100,8 @@ if ($data['filter_userids']) { } if (!$data['filter_userids'] || $data['users']) { - $config = select_config(); - // Fetch alerts for different objects and sources and combine them in a single stream. + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1; foreach (eventSourceObjects() as $eventSource) { $data['alerts'] = array_merge($data['alerts'], API::Alert()->get([ 'output' => ['alertid', 'actionid', 'userid', 'clock', 'sendto', 'subject', 'message', 'status', @@ -117,7 +116,7 @@ if (!$data['filter_userids'] || $data['users']) { 'eventobject' => $eventSource['object'], 'sortfield' => 'alertid', 'sortorder' => ZBX_SORT_DOWN, - 'limit' => $config['search_limit'] + 1 + 'limit' => $limit ])); } @@ -125,7 +124,7 @@ if (!$data['filter_userids'] || $data['users']) { ['field' => 'alertid', 'order' => ZBX_SORT_DOWN] ]); - $data['alerts'] = array_slice($data['alerts'], 0, $config['search_limit'] + 1); + $data['alerts'] = array_slice($data['alerts'], 0, CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1); $data['paging'] = CPagerHelper::paginate(getRequest('page', 1), $data['alerts'], ZBX_SORT_DOWN, new CUrl('auditacts.php') diff --git a/ui/correlation.php b/ui/correlation.php index 5270c50ebc3..0ace263d32e 100644 --- a/ui/correlation.php +++ b/ui/correlation.php @@ -336,14 +336,11 @@ elseif (hasRequest('action') && getRequest('action') === 'correlation.massdelete */ show_messages(); -$config = select_config(); - if (hasRequest('form')) { $data = [ 'form' => getRequest('form'), 'correlationid' => $correlationid, - 'new_condition' => getRequest('new_condition', []), - 'config' => $config + 'new_condition' => getRequest('new_condition', []) ]; if ($correlationid !== null) { @@ -453,11 +450,11 @@ else { 'sort' => $sortField, 'sortorder' => $sortOrder, 'filter' => $filter, - 'config' => $config, 'profileIdx' => 'web.correlation.filter', 'active_tab' => CProfile::get('web.correlation.filter.active', 1) ]; + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1; $data['correlations'] = API::Correlation()->get([ 'output' => ['correlationid', 'name', 'description', 'status'], 'search' => [ @@ -470,7 +467,7 @@ else { 'selectOperations' => ['type'], 'editable' => true, 'sortfield' => $sortField, - 'limit' => $config['search_limit'] + 1 + 'limit' => $limit ]); order_result($data['correlations'], $sortField, $sortOrder); diff --git a/ui/disc_prototypes.php b/ui/disc_prototypes.php index a0a8c0caf5e..52e91248ba5 100644 --- a/ui/disc_prototypes.php +++ b/ui/disc_prototypes.php @@ -1200,7 +1200,6 @@ if (isset($_REQUEST['form'])) { } $data = getItemFormData($itemPrototype); - $data['config'] = select_config(); $data['preprocessing_test_type'] = CControllerPopupItemTestEdit::ZBX_TEST_TYPE_ITEM_PROTOTYPE; $data['preprocessing_types'] = CItemPrototype::$supported_preprocessing_types; $data['trends_default'] = DB::getDefault('items', 'trends'); @@ -1476,8 +1475,6 @@ else { CProfile::update('web.'.$page['file'].'.sort', $sortField, PROFILE_TYPE_STR); CProfile::update('web.'.$page['file'].'.sortorder', $sortOrder, PROFILE_TYPE_STR); - $config = select_config(); - $data = [ 'form' => getRequest('form'), 'parent_discoveryid' => getRequest('parent_discoveryid'), @@ -1486,13 +1483,14 @@ else { 'sortorder' => $sortOrder ]; + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1; $data['items'] = API::ItemPrototype()->get([ 'discoveryids' => $data['parent_discoveryid'], 'output' => API_OUTPUT_EXTEND, 'editable' => true, 'selectApplications' => API_OUTPUT_EXTEND, 'sortfield' => $sortField, - 'limit' => $config['search_limit'] + 1 + 'limit' => $limit ]); $data['items'] = expandItemNamesWithMasterItems($data['items'], 'itemprototypes'); diff --git a/ui/discoveryconf.php b/ui/discoveryconf.php index f56913d10df..6e1601072b7 100644 --- a/ui/discoveryconf.php +++ b/ui/discoveryconf.php @@ -346,8 +346,6 @@ else { 'status' => CProfile::get('web.discoveryconf.filter_status', -1) ]; - $config = select_config(); - $data = [ 'sort' => $sortField, 'sortorder' => $sortOrder, @@ -357,6 +355,7 @@ else { ]; // get drules + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1; $data['drules'] = API::DRule()->get([ 'output' => ['proxy_hostid', 'name', 'status', 'iprange', 'delay'], 'selectDChecks' => ['type'], @@ -368,7 +367,7 @@ else { ], 'editable' => true, 'sortfield' => $sortField, - 'limit' => $config['search_limit'] + 1 + 'limit' => $limit ]); if ($data['drules']) { diff --git a/ui/graphs.php b/ui/graphs.php index e0abd6c286c..425b3735567 100644 --- a/ui/graphs.php +++ b/ui/graphs.php @@ -662,8 +662,6 @@ elseif (isset($_REQUEST['form'])) { echo (new CView('configuration.graph.edit', $data))->getOutput(); } else { - $config = select_config(); - $data = [ 'filter' => $filter, 'hostid' => $hostid, @@ -682,7 +680,7 @@ else { 'groupids' => $filter_groupids, 'discoveryids' => hasRequest('parent_discoveryid') ? $discoveryRule['itemid'] : null, 'editable' => true, - 'limit' => $config['search_limit'] + 1 + 'limit' => CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1 ]; $data['graphs'] = hasRequest('parent_discoveryid') diff --git a/ui/host_discovery.php b/ui/host_discovery.php index 94074b9025b..5bca459fd24 100644 --- a/ui/host_discovery.php +++ b/ui/host_discovery.php @@ -801,8 +801,6 @@ if (hasRequest('form')) { } } else { - $config = select_config(); - $data = [ 'filter' => $filter, 'hostid' => (count($filter_hostids) == 1) ? reset($filter_hostids) : 0, @@ -826,7 +824,7 @@ else { 'filter' => [], 'search' => [], 'sortfield' => $sort_field, - 'limit' => $config['search_limit'] + 1 + 'limit' => CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1 ]; if ($filter_groupids) { diff --git a/ui/host_prototypes.php b/ui/host_prototypes.php index cf82fee2e92..2e1d269fd62 100644 --- a/ui/host_prototypes.php +++ b/ui/host_prototypes.php @@ -312,8 +312,6 @@ if (hasRequest('action') && hasRequest('group_hostid') && !$result) { uncheckTableRows($discoveryRule['itemid'], zbx_objectValues($host_prototypes, 'hostid')); } -$config = select_config(); - /* * Display */ @@ -329,7 +327,9 @@ if (hasRequest('form')) { 'discover' => getRequest('discover', DB::getDefault('hosts', 'discover')), 'templates' => [], 'add_templates' => [], - 'inventory_mode' => getRequest('inventory_mode', $config['default_inventory_mode']), + 'inventory_mode' => getRequest('inventory_mode', + CSettingsHelper::get(CSettingsHelper::DEFAULT_INVENTORY_MODE) + ), 'groupPrototypes' => getRequest('group_prototypes', []), 'macros' => $macros ], @@ -485,13 +485,14 @@ else { ]; // get items + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1; $data['hostPrototypes'] = API::HostPrototype()->get([ 'discoveryids' => $data['parent_discoveryid'], 'output' => API_OUTPUT_EXTEND, 'selectTemplates' => ['templateid', 'name'], 'editable' => true, 'sortfield' => $sortField, - 'limit' => $config['search_limit'] + 1 + 'limit' => $limit ]); order_result($data['hostPrototypes'], $sortField, $sortOrder); diff --git a/ui/hostgroups.php b/ui/hostgroups.php index e8306e0ee8a..6bf8dc209a6 100644 --- a/ui/hostgroups.php +++ b/ui/hostgroups.php @@ -266,17 +266,18 @@ else { 'name' => CProfile::get('web.groups.filter_name', '') ]; - $config = select_config(); - $data = [ 'sort' => $sortField, 'sortorder' => $sortOrder, 'filter' => $filter, - 'config' => $config, 'profileIdx' => 'web.groups.filter', - 'active_tab' => CProfile::get('web.groups.filter.active', 1) + 'active_tab' => CProfile::get('web.groups.filter.active', 1), + 'config' => [ + 'max_in_table' => CSettingsHelper::get(CSettingsHelper::MAX_IN_TABLE) + ] ]; + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1; $groups = API::HostGroup()->get([ 'output' => ['groupid', $sortField], 'search' => [ @@ -284,7 +285,7 @@ else { ], 'editable' => true, 'sortfield' => $sortField, - 'limit' => $config['search_limit'] + 1 + 'limit' => $limit ]); order_result($groups, $sortField, $sortOrder); @@ -315,6 +316,7 @@ else { ]); // get host groups + $limit = CSettingsHelper::get(CSettingsHelper::MAX_IN_TABLE) + 1; $data['groups'] = API::HostGroup()->get([ 'output' => ['groupid', 'name', 'flags'], 'groupids' => $groupIds, @@ -322,7 +324,7 @@ else { 'selectTemplates' => ['templateid', 'name'], 'selectGroupDiscovery' => ['ts_delete'], 'selectDiscoveryRule' => ['itemid', 'name'], - 'limitSelects' => $config['max_in_table'] + 1 + 'limitSelects' => $limit ]); order_result($data['groups'], $sortField, $sortOrder); diff --git a/ui/hostinventories.php b/ui/hostinventories.php index 137d50bd5f3..27a2356c9b8 100644 --- a/ui/hostinventories.php +++ b/ui/hostinventories.php @@ -131,7 +131,6 @@ if ($hostId > 0) { } else { $data = [ - 'config' => select_config(), 'hosts' => [], 'sort' => $sortField, 'sortorder' => $sortOrder, @@ -244,7 +243,7 @@ else { unset($host); } - $limit = $data['config']['search_limit'] + 1; + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1; order_result($data['hosts'], $sortField, $sortOrder); diff --git a/ui/hosts.php b/ui/hosts.php index 3aa3ac8f780..d1bed15beff 100644 --- a/ui/hosts.php +++ b/ui/hosts.php @@ -1013,8 +1013,6 @@ elseif (hasRequest('hosts') && hasRequest('action') && str_in_array(getRequest(' /* * Display */ -$config = select_config(); - if (hasRequest('hosts') && (getRequest('action') === 'host.massupdateform' || hasRequest('masssave'))) { $data = [ 'hosts' => getRequest('hosts'), @@ -1120,7 +1118,7 @@ elseif (hasRequest('form')) { 'show_inherited_macros' => getRequest('show_inherited_macros', 0), // Host inventory - 'inventory_mode' => getRequest('inventory_mode', $config['default_inventory_mode']), + 'inventory_mode' => getRequest('inventory_mode', CSettingsHelper::get(CSettingsHelper::DEFAULT_INVENTORY_MODE)), 'host_inventory' => getRequest('host_inventory', []), 'inventory_items' => [], @@ -1469,6 +1467,7 @@ else { } // Select hosts. + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1; $hosts = API::Host()->get([ 'output' => ['hostid', $sortField], 'evaltype' => $filter['evaltype'], @@ -1477,7 +1476,7 @@ else { 'templateids' => $filter['templates'] ? array_keys($filter['templates']) : null, 'editable' => true, 'sortfield' => $sortField, - 'limit' => $config['search_limit'] + 1, + 'limit' => $limit, 'search' => [ 'name' => ($filter['host'] === '') ? null : $filter['host'], 'ip' => ($filter['ip'] === '') ? null : $filter['ip'], @@ -1612,7 +1611,6 @@ else { 'filter' => $filter, 'sortField' => $sortField, 'sortOrder' => $sortOrder, - 'config' => $config, 'templates' => $templates, 'maintenances' => $db_maintenances, 'writable_templates' => $writable_templates, @@ -1620,7 +1618,10 @@ else { 'proxies_ms' => $proxies_ms, 'profileIdx' => 'web.hosts.filter', 'active_tab' => CProfile::get('web.hosts.filter.active', 1), - 'tags' => makeTags($hosts, true, 'hostid', ZBX_TAG_COUNT_DEFAULT, $filter['tags']) + 'tags' => makeTags($hosts, true, 'hostid', ZBX_TAG_COUNT_DEFAULT, $filter['tags']), + 'config' => [ + 'max_in_table' => CSettingsHelper::get(CSettingsHelper::MAX_IN_TABLE) + ] ]; $hostView = new CView('configuration.host.list', $data); diff --git a/ui/httpconf.php b/ui/httpconf.php index 9be3c181e1d..0689dc8c0a6 100644 --- a/ui/httpconf.php +++ b/ui/httpconf.php @@ -806,14 +806,12 @@ else { $data['showInfoColumn'] = true; } - $config = select_config(); - $options = [ 'output' => ['httptestid', $sortField], 'hostids' => $filter['hosts'] ? array_keys($filter['hosts']) : null, 'groupids' => $filter_groupids, 'editable' => true, - 'limit' => $config['search_limit'] + 1 + 'limit' => CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1 ]; if ($data['filter']['status'] != -1) { $options['filter']['status'] = $data['filter']['status']; diff --git a/ui/include/actions.inc.php b/ui/include/actions.inc.php index e3fb39d9ef8..35826aade0f 100644 --- a/ui/include/actions.inc.php +++ b/ui/include/actions.inc.php @@ -94,12 +94,10 @@ function discovery_object2str($object = null) { * @param array $actions array of actions * @param array $action['filter'] array containing arrays of action conditions and other data * @param array $action['filter']['conditions'] array of action conditions - * @param array $config array containing configuration parameters for getting trigger - * severity names * * @return array returns an array of actions condition string values */ -function actionConditionValueToString(array $actions, array $config) { +function actionConditionValueToString(array $actions) { $result = []; $groupIds = []; @@ -158,7 +156,7 @@ function actionConditionValueToString(array $actions, array $config) { break; case CONDITION_TYPE_TRIGGER_SEVERITY: - $result[$i][$j] = getSeverityName($condition['value'], $config); + $result[$i][$j] = getSeverityName($condition['value']); break; case CONDITION_TYPE_DRULE: @@ -1663,14 +1661,13 @@ function getEventUpdates(array $event) { * @param array $actions['actions'] Actions icon data. * @param array $mediatypes Mediatypes with maxattempts value and name. * @param array $users User name, surname and alias. - * @param array $config Zabbix config. * * @return CCol|string */ -function makeEventActionsIcons($eventid, $actions, $mediatypes, $users, $config) { +function makeEventActionsIcons($eventid, $actions, $mediatypes, $users) { $messages_icon = makeEventMessagesIcon($actions['messages'][$eventid], $users); - $severities_icon = makeEventSeverityChangesIcon($actions['severities'][$eventid], $users, $config); - $actions_icon = makeEventActionsIcon($actions['actions'][$eventid], $users, $mediatypes, $config); + $severities_icon = makeEventSeverityChangesIcon($actions['severities'][$eventid], $users); + $actions_icon = makeEventActionsIcon($actions['actions'][$eventid], $users, $mediatypes); $action_icons = []; if ($messages_icon !== null) { @@ -1747,11 +1744,10 @@ function makeEventMessagesIcon(array $data, array $users) { * @param string $data['current_severity'] Current severity. * @param int $data['count'] Total number of severity changes. * @param array $users User name, surname and alias. - * @param array $config Zabbix config. * * @return CSpan|null */ -function makeEventSeverityChangesIcon(array $data, array $users, array $config) { +function makeEventSeverityChangesIcon(array $data, array $users) { $total = $data['count']; $table = (new CTableInfo())->setHeader([_('Time'), _('User'), _('Severity changes')]); @@ -1763,8 +1759,8 @@ function makeEventSeverityChangesIcon(array $data, array $users, array $config) $severity['action_type'] = ZBX_EVENT_HISTORY_MANUAL_UPDATE; // severity changes - $old_severity_name = getSeverityName($severity['old_severity'], $config); - $new_severity_name = getSeverityName($severity['new_severity'], $config); + $old_severity_name = getSeverityName($severity['old_severity']); + $new_severity_name = getSeverityName($severity['new_severity']); $table->addRow([ zbx_date2str(DATE_TIME_FORMAT_SECONDS, $severity['clock']), @@ -1824,11 +1820,10 @@ function makeEventSeverityChangesIcon(array $data, array $users, array $config) * @param array $users User name, surname and alias. * @param array $mediatypes Mediatypes with maxattempts value and name. * @param string $mediatypes[]['name'] Mediatype name. - * @param array $config Zabbix config. * * @return CSpan|null */ -function makeEventActionsIcon(array $data, array $users, array $mediatypes, array $config) { +function makeEventActionsIcon(array $data, array $users, array $mediatypes) { // Number of meaningful actions. $total = $data['count']; // Number of all action entries. @@ -1860,7 +1855,7 @@ function makeEventActionsIcon(array $data, array $users, array $mediatypes, arra $table->addRow([ zbx_date2str(DATE_TIME_FORMAT_SECONDS, $action['clock']), makeActionTableUser($action, $users), - makeActionTableIcon($action, $config), + makeActionTableIcon($action), $message, makeActionTableStatus($action), makeActionTableInfo($action, $mediatypes) @@ -1913,11 +1908,10 @@ function makeEventActionsIcon(array $data, array $users, array $mediatypes, arra * @param string $data['actions'][]['acknowledgeid'] Problem update action that was reason for alert (only for ZBX_EVENT_HISTORY_ALERT). * @param array $users User name, surname and alias. * @param array $mediatypes Mediatypes with maxattempts value. - * @param array $config Zabbix config. * * @return CTableInfo */ -function makeEventDetailsActionsTable(array $data, array $users, array $mediatypes, array $config) { +function makeEventDetailsActionsTable(array $data, array $users, array $mediatypes) { $table = (new CTableInfo())->setHeader([ _('Step'), _('Time'), _('User/Recipient'), _('Action'), _('Message/Command'), _('Status'), _('Info') ]); @@ -1947,7 +1941,7 @@ function makeEventDetailsActionsTable(array $data, array $users, array $mediatyp $esc_step, zbx_date2str(DATE_TIME_FORMAT_SECONDS, $action['clock']), makeEventDetailsTableUser($action, $users), - makeActionTableIcon($action, $config), + makeActionTableIcon($action), $message, makeActionTableStatus($action), makeActionTableInfo($action, $mediatypes) @@ -1964,11 +1958,10 @@ function makeEventDetailsActionsTable(array $data, array $users, array $mediatyp * @param string $actions[]['clock'] Time, when action was performed. * @param string $actions[]['message'] Message sent by alert, or written by manual update, or remote command text. * @param array $users User name, surname and alias. - * @param array $config Zabbix config. * * @return CTable */ -function makeEventHistoryTable(array $actions, array $users, array $config) { +function makeEventHistoryTable(array $actions, array $users) { $table = (new CTable()) ->addStyle('width: 100%;') ->setHeader([_('Time'), _('User'), _('User action'), _('Message')]); @@ -1980,7 +1973,7 @@ function makeEventHistoryTable(array $actions, array $users, array $config) { $table->addRow([ zbx_date2str(DATE_TIME_FORMAT_SECONDS, $action['clock']), makeActionTableUser($action, $users), - makeActionTableIcon($action, $config), + makeActionTableIcon($action), (new CCol(zbx_nl2br($action['message'])))->addClass(ZBX_STYLE_TABLE_FORMS_OVERFLOW_BREAK) ]); } @@ -2048,11 +2041,10 @@ function makeEventDetailsTableUser(array $action, array $users) { * @param int $action['old_severity'] Severity before problem update. (only for ZBX_EVENT_HISTORY_MANUAL_UPDATE) * @param int $action['new_severity'] Severity after problem update. (only for ZBX_EVENT_HISTORY_MANUAL_UPDATE) * @param int $action['alerttype'] Type of alert. (only for ZBX_EVENT_HISTORY_ALERT) - * @param array $config Zabbix config. * * @return CSpan */ -function makeActionTableIcon(array $action, array $config) { +function makeActionTableIcon(array $action) { switch ($action['action_type']) { case ZBX_EVENT_HISTORY_PROBLEM_EVENT: return makeActionIcon(['icon' => ZBX_STYLE_PROBLEM_GENERATED, 'title' => _('Problem created')]); @@ -2087,8 +2079,8 @@ function makeActionTableIcon(array $action, array $config) { ? ZBX_STYLE_ACTION_ICON_SEV_UP : ZBX_STYLE_ACTION_ICON_SEV_DOWN; - $old_severity_name = getSeverityName($action['old_severity'], $config); - $new_severity_name = getSeverityName($action['new_severity'], $config); + $old_severity_name = getSeverityName($action['old_severity']); + $new_severity_name = getSeverityName($action['new_severity']); $hint = $old_severity_name.' ⇒ '.$new_severity_name; $action_icons[] = makeActionIcon(['icon' => $action_type, 'hint' => $hint]); diff --git a/ui/include/blocks.inc.php b/ui/include/blocks.inc.php index 44c26758d93..e37ba22d6a0 100644 --- a/ui/include/blocks.inc.php +++ b/ui/include/blocks.inc.php @@ -325,12 +325,10 @@ function getSystemStatusData(array $filter) { * @param array $data['triggers'][<triggerid>]['hosts'] * @param string $data['triggers'][<triggerid>]['hosts'][]['name'] * @param array $data['triggers'][<triggerid>]['opdata'] - * @param array $config - * @param string $config['severity_name_*'] * * @return CDiv */ -function makeSystemStatus(array $filter, array $data, array $config) { +function makeSystemStatus(array $filter, array $data) { $filter_severities = (array_key_exists('severities', $filter) && $filter['severities']) ? $filter['severities'] : range(TRIGGER_SEVERITY_NOT_CLASSIFIED, TRIGGER_SEVERITY_COUNT - 1); @@ -347,7 +345,7 @@ function makeSystemStatus(array $filter, array $data, array $config) { for ($severity = TRIGGER_SEVERITY_COUNT - 1; $severity >= TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity--) { if (in_array($severity, $filter_severities)) { - $header[] = getSeverityName($severity, $config); + $header[] = getSeverityName($severity); } } @@ -385,36 +383,32 @@ function makeSystemStatus(array $filter, array $data, array $config) { $allTriggersNum = $stat['count']; if ($allTriggersNum) { $allTriggersNum = (new CLinkAction($allTriggersNum)) - ->setHint(makeProblemsPopup($stat['problems'], $data['triggers'], $data['actions'], $config, - $filter - )); + ->setHint(makeProblemsPopup($stat['problems'], $data['triggers'], $data['actions'], $filter)); } $unackTriggersNum = $stat['count_unack']; if ($unackTriggersNum) { $unackTriggersNum = (new CLinkAction($unackTriggersNum)) - ->setHint(makeProblemsPopup($stat['problems_unack'], $data['triggers'], $data['actions'], $config, - $filter - )); + ->setHint(makeProblemsPopup($stat['problems_unack'], $data['triggers'], $data['actions'], $filter)); } switch ($filter_ext_ack) { case EXTACK_OPTION_ALL: - $row[] = getSeverityCell($severity, null, $allTriggersNum); + $row[] = getSeverityCell($severity, $allTriggersNum); break; case EXTACK_OPTION_UNACK: - $row[] = getSeverityCell($severity, null, $unackTriggersNum); + $row[] = getSeverityCell($severity, $unackTriggersNum); break; case EXTACK_OPTION_BOTH: if ($stat['count_unack'] != 0) { - $row[] = getSeverityCell($severity, $config, [ + $row[] = getSeverityCell($severity, [ $unackTriggersNum, ' '._('of').' ', $allTriggersNum ]); } else { - $row[] = getSeverityCell($severity, $config, $allTriggersNum); + $row[] = getSeverityCell($severity, $allTriggersNum); } break; } @@ -559,14 +553,14 @@ function getSeverityTableCell($severity, array $data, array $stat, $is_total = f return ''; } - $severity_name = $is_total ? ' '.getSeverityName($severity, $data['severity_names']) : ''; + $severity_name = $is_total ? ' '.getSeverityName($severity) : ''; $ext_ack = array_key_exists('ext_ack', $data['filter']) ? $data['filter']['ext_ack'] : EXTACK_OPTION_ALL; $allTriggersNum = $stat['count']; if ($allTriggersNum) { $allTriggersNum = (new CLinkAction($allTriggersNum)) ->setHint(makeProblemsPopup($stat['problems'], $data['data']['triggers'], $data['data']['actions'], - $data['severity_names'], $data['filter'] + $data['filter'] )); } @@ -574,25 +568,25 @@ function getSeverityTableCell($severity, array $data, array $stat, $is_total = f if ($unackTriggersNum) { $unackTriggersNum = (new CLinkAction($unackTriggersNum)) ->setHint(makeProblemsPopup($stat['problems_unack'], $data['data']['triggers'], $data['data']['actions'], - $data['severity_names'], $data['filter'] + $data['filter'] )); } switch ($ext_ack) { case EXTACK_OPTION_ALL: - return getSeverityCell($severity, null, [ + return getSeverityCell($severity, [ (new CSpan($allTriggersNum))->addClass(ZBX_STYLE_TOTALS_LIST_COUNT), $severity_name ], false, $is_total); case EXTACK_OPTION_UNACK: - return getSeverityCell($severity, null, [ + return getSeverityCell($severity, [ (new CSpan($unackTriggersNum))->addClass(ZBX_STYLE_TOTALS_LIST_COUNT), $severity_name ], false, $is_total); case EXTACK_OPTION_BOTH: - return getSeverityCell($severity, $data['severity_names'], [ + return getSeverityCell($severity, [ (new CSpan([$unackTriggersNum, ' '._('of').' ', $allTriggersNum])) ->addClass(ZBX_STYLE_TOTALS_LIST_COUNT), $severity_name @@ -729,7 +723,6 @@ function make_status_of_zbx() { * @param string $triggers[<triggerid>]['hosts'][]['name'] * @param string $triggers[<triggerid>]['opdata'] * @param array $actions - * @param array $config * @param array $filter * @param array $filter['show_suppressed'] (optional) * @param array $filter['show_timeline'] (optional) @@ -737,7 +730,7 @@ function make_status_of_zbx() { * * @return CTableInfo */ -function makeProblemsPopup(array $problems, array $triggers, array $actions, array $config, array $filter) { +function makeProblemsPopup(array $problems, array $triggers, array $actions, array $filter) { $url_details = (new CUrl('tr_events.php')) ->setArgument('triggerid', '') ->setArgument('eventid', ''); @@ -874,7 +867,7 @@ function makeProblemsPopup(array $problems, array $triggers, array $actions, arr $table->addRow(array_merge($row, [ makeInformationList($info_icons), $triggers_hosts[$trigger['triggerid']], - getSeverityCell($problem['severity'], null, + getSeverityCell($problem['severity'], (($show_opdata == OPERATIONAL_DATA_SHOW_WITH_PROBLEM && $opdata) ? [$problem['name'], ' (', $opdata, ')'] : $problem['name'] @@ -884,7 +877,7 @@ function makeProblemsPopup(array $problems, array $triggers, array $actions, arr zbx_date2age($problem['clock']), $problem_update_link, makeEventActionsIcons($problem['eventid'], $actions['all_actions'], $actions['mediatypes'], - $actions['users'], $config + $actions['users'] ), $tags[$problem['eventid']] ])); diff --git a/ui/include/classes/api/API.php b/ui/include/classes/api/API.php index 739ed07c633..da9c30c4780 100644 --- a/ui/include/classes/api/API.php +++ b/ui/include/classes/api/API.php @@ -38,7 +38,7 @@ class API { /** * Sets the API wrapper. * - * @param CApiWrapper $wrapper + * @param CApiWrapper|null $wrapper */ public static function setWrapper(CApiWrapper $wrapper = null) { self::$wrapper = $wrapper; @@ -56,7 +56,7 @@ class API { /** * Returns the API wrapper. * - * @return CApiWrapper + * @return CApiWrapper|null */ public static function getWrapper() { return self::$wrapper; @@ -130,6 +130,13 @@ class API { } /** + * @return CAuthentication + */ + public static function Authentication() { + return self::getApi('authentication'); + } + + /** * @return CAutoregistration */ public static function Autoregistration() { @@ -256,6 +263,13 @@ class API { } /** + * @return CHousekeeping + */ + public static function Housekeeping() { + return self::getApi('housekeeping'); + } + + /** * @return CImage */ public static function Image() { @@ -326,13 +340,6 @@ class API { } /** - * @return CService - */ - public static function Service() { - return self::getApi('service'); - } - - /** * @return CScreen */ public static function Screen() { @@ -354,6 +361,20 @@ class API { } /** + * @return CService + */ + public static function Service() { + return self::getApi('service'); + } + + /** + * @return CSettings + */ + public static function Settings() { + return self::getApi('settings'); + } + + /** * @return CTask */ public static function Task() { diff --git a/ui/include/classes/api/CApiServiceFactory.php b/ui/include/classes/api/CApiServiceFactory.php index bb391255450..40414828fcb 100644 --- a/ui/include/classes/api/CApiServiceFactory.php +++ b/ui/include/classes/api/CApiServiceFactory.php @@ -32,6 +32,7 @@ class CApiServiceFactory extends CRegistryFactory { 'apiinfo' => 'CAPIInfo', 'application' => 'CApplication', 'auditlog' => 'CAuditLog', + 'authentication' => 'CAuthentication', 'autoregistration' => 'CAutoregistration', 'configuration' => 'CConfiguration', 'correlation' => 'CCorrelation', @@ -50,6 +51,7 @@ class CApiServiceFactory extends CRegistryFactory { 'hostprototype' => 'CHostPrototype', 'history' => 'CHistory', 'hostinterface' => 'CHostInterface', + 'housekeeping' => 'CHousekeeping', 'httptest' => 'CHttpTest', 'image' => 'CImage', 'iconmap' => 'CIconMap', @@ -65,6 +67,7 @@ class CApiServiceFactory extends CRegistryFactory { 'screen' => 'CScreen', 'screenitem' => 'CScreenItem', 'script' => 'CScript', + 'settings' => 'CSettings', 'task' => 'CTask', 'template' => 'CTemplate', 'templatescreen' => 'CTemplateScreen', diff --git a/ui/include/classes/api/CAudit.php b/ui/include/classes/api/CAudit.php index bb1f7c6453f..c12fb3dddf1 100644 --- a/ui/include/classes/api/CAudit.php +++ b/ui/include/classes/api/CAudit.php @@ -29,6 +29,7 @@ class CAudit { static private $supported_type = [ AUDIT_RESOURCE_ACTION => ['actionid', 'name', 'actions'], AUDIT_RESOURCE_APPLICATION => ['applicationid', 'name', 'applications'], + AUDIT_RESOURCE_AUTHENTICATION => ['configid', null, 'config'], AUDIT_RESOURCE_AUTOREGISTRATION => ['configid', null, 'config'], AUDIT_RESOURCE_CORRELATION => ['correlationid', 'name', 'correlation'], AUDIT_RESOURCE_DASHBOARD => ['dashboardid', 'name', 'dashboard'], @@ -38,6 +39,7 @@ class CAudit { AUDIT_RESOURCE_HOST => ['hostid', 'name', 'hosts'], AUDIT_RESOURCE_HOST_GROUP => ['groupid', 'name', 'groups'], AUDIT_RESOURCE_HOST_PROTOTYPE => ['hostid', 'host', 'hosts'], + AUDIT_RESOURCE_HOUSEKEEPING => ['configid', null, 'config'], AUDIT_RESOURCE_ICON_MAP => ['iconmapid', 'name', 'icon_map'], AUDIT_RESOURCE_ITEM => ['itemid', 'name', 'items'], AUDIT_RESOURCE_ITEM_PROTOTYPE => ['itemid', 'name', 'items'], @@ -47,6 +49,7 @@ class CAudit { AUDIT_RESOURCE_PROXY => ['proxyid', 'host', 'hosts'], AUDIT_RESOURCE_SCENARIO => ['httptestid', 'name', 'httptest'], AUDIT_RESOURCE_SCRIPT => ['scriptid', 'name', 'scripts'], + AUDIT_RESOURCE_SETTINGS => ['configid', null, 'config'], AUDIT_RESOURCE_TRIGGER => ['triggerid', 'description', 'triggers'], AUDIT_RESOURCE_TRIGGER_PROTOTYPE => ['triggerid', 'description', 'triggers'], AUDIT_RESOURCE_USER => ['userid', 'alias', 'users'], diff --git a/ui/include/classes/api/clients/CLocalApiClient.php b/ui/include/classes/api/clients/CLocalApiClient.php index 3f369186735..b538380193f 100644 --- a/ui/include/classes/api/clients/CLocalApiClient.php +++ b/ui/include/classes/api/clients/CLocalApiClient.php @@ -213,6 +213,7 @@ class CLocalApiClient extends CApiClient { protected function requiresAuthentication($api, $method) { return !(($api === 'user' && $method === 'login') || ($api === 'user' && $method === 'checkauthentication') - || ($api === 'apiinfo' && $method === 'version')); + || ($api === 'apiinfo' && $method === 'version') + || ($api === 'settings' && $method === 'getglobal')); } } diff --git a/ui/include/classes/api/managers/CHistoryManager.php b/ui/include/classes/api/managers/CHistoryManager.php index 13bf1c15617..ede0451cadf 100644 --- a/ui/include/classes/api/managers/CHistoryManager.php +++ b/ui/include/classes/api/managers/CHistoryManager.php @@ -333,6 +333,7 @@ class CHistoryManager { 'size' => 1 ]; + $history_period = timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::HISTORY_PERIOD)); $filters = [ [ [ @@ -363,7 +364,7 @@ class CHistoryManager { 'range' => [ 'clock' => [ 'lt' => $clock - ] + (ZBX_HISTORY_PERIOD ? ['gte' => $clock - ZBX_HISTORY_PERIOD] : []) + ] + ($history_period ? ['gte' => $clock - $history_period] : []) ] ] ] @@ -422,11 +423,12 @@ class CHistoryManager { } if ($max_clock == 0) { + $history_period = timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::HISTORY_PERIOD)); $sql = 'SELECT MAX(clock) AS clock'. ' FROM '.$table. ' WHERE itemid='.zbx_dbstr($item['itemid']). ' AND clock<'.zbx_dbstr($clock). - (ZBX_HISTORY_PERIOD ? ' AND clock>='.zbx_dbstr($clock - ZBX_HISTORY_PERIOD) : ''); + ($history_period ? ' AND clock>='.zbx_dbstr($clock - $history_period) : ''); if (($row = DBfetch(DBselect($sql))) !== false) { $max_clock = $row['clock']; @@ -1107,7 +1109,6 @@ class CHistoryManager { */ private function deleteHistoryFromSql(array $items) { global $DB; - $config = select_config(); $item_tables = array_map('self::getTableName', array_unique($items)); $table_names = array_flip(self::getTableName()); @@ -1122,7 +1123,8 @@ class CHistoryManager { $table_names['trends'] = ITEM_VALUE_TYPE_FLOAT; } - if ($DB['TYPE'] == ZBX_DB_POSTGRESQL && $config['db_extension'] == ZBX_DB_EXTENSION_TIMESCALEDB + if ($DB['TYPE'] == ZBX_DB_POSTGRESQL + && CHousekeepingHelper::get(CHousekeepingHelper::DB_EXTENSION) == ZBX_DB_EXTENSION_TIMESCALEDB && PostgresqlDbBackend::isCompressed($item_tables)) { error(_('Some of the history for this item may be compressed, deletion is not available.')); diff --git a/ui/include/classes/api/managers/CHttpTestManager.php b/ui/include/classes/api/managers/CHttpTestManager.php index a528b1bb793..23873014500 100644 --- a/ui/include/classes/api/managers/CHttpTestManager.php +++ b/ui/include/classes/api/managers/CHttpTestManager.php @@ -1282,7 +1282,7 @@ class CHttpTestManager { * - lastfailedstep - number of the last failed step * - error - error message * - * If a HTTP test has not been executed in last ZBX_HISTORY_PERIOD, no value will be returned. + * If a HTTP test has not been executed in last CSettingsHelper::HISTORY_PERIOD, no value will be returned. * * @param array $httpTestIds * @@ -1297,7 +1297,9 @@ class CHttpTestManager { ' AND '.dbConditionInt('hti.httptestid', $httpTestIds) )); - $history = Manager::History()->getLastValues($httpItems, 1, ZBX_HISTORY_PERIOD); + $history = Manager::History()->getLastValues($httpItems, 1, timeUnitToSeconds(CSettingsHelper::get( + CSettingsHelper::HISTORY_PERIOD + ))); $data = []; diff --git a/ui/include/classes/api/services/CAuditLog.php b/ui/include/classes/api/services/CAuditLog.php index 5032b2e3bb5..7c63200ff92 100644 --- a/ui/include/classes/api/services/CAuditLog.php +++ b/ui/include/classes/api/services/CAuditLog.php @@ -91,7 +91,7 @@ class CAuditLog extends CApiService { AUDIT_RESOURCE_MACRO, AUDIT_RESOURCE_TEMPLATE, AUDIT_RESOURCE_TRIGGER_PROTOTYPE, AUDIT_RESOURCE_ICON_MAP, AUDIT_RESOURCE_DASHBOARD, AUDIT_RESOURCE_CORRELATION, AUDIT_RESOURCE_GRAPH_PROTOTYPE, AUDIT_RESOURCE_ITEM_PROTOTYPE, AUDIT_RESOURCE_HOST_PROTOTYPE, AUDIT_RESOURCE_AUTOREGISTRATION, - AUDIT_RESOURCE_MODULE + AUDIT_RESOURCE_MODULE, AUDIT_RESOURCE_SETTINGS, AUDIT_RESOURCE_HOUSEKEEPING, AUDIT_RESOURCE_AUTHENTICATION ]; $api_input_rules = ['type' => API_OBJECT, 'fields' => [ diff --git a/ui/include/classes/api/services/CAuthentication.php b/ui/include/classes/api/services/CAuthentication.php new file mode 100644 index 00000000000..5fcb7014028 --- /dev/null +++ b/ui/include/classes/api/services/CAuthentication.php @@ -0,0 +1,183 @@ +<?php declare(strict_types = 1); +/* +** Zabbix +** Copyright (C) 2001-2020 Zabbix SIA +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +**/ + + +/** + * Class containing methods for operations with authentication parameters. + */ +class CAuthentication extends CApiService { + /** + * @var string + */ + protected $tableName = 'config'; + + /** + * @var string + */ + protected $tableAlias = 'c'; + + /** + * @var array + */ + private $output_fields = ['authentication_type', 'http_auth_enabled', 'http_login_form', 'http_strip_domains', + 'http_case_sensitive', 'ldap_configured', 'ldap_host', 'ldap_port', 'ldap_base_dn', 'ldap_search_attribute', + 'ldap_bind_dn', 'ldap_case_sensitive', 'ldap_bind_password', 'saml_auth_enabled', 'saml_idp_entityid', + 'saml_sso_url', 'saml_slo_url', 'saml_username_attribute', 'saml_sp_entityid', 'saml_nameid_format', + 'saml_sign_messages', 'saml_sign_assertions', 'saml_sign_authn_requests', 'saml_sign_logout_requests', + 'saml_sign_logout_responses', 'saml_encrypt_nameid', 'saml_encrypt_assertions', 'saml_case_sensitive' + ]; + + /** + * Get authentication parameters. + * + * @param array $options + * + * @throws APIException if the input is invalid. + * + * @return array + */ + public function get(array $options): array { + $api_input_rules = ['type' => API_OBJECT, 'fields' => [ + 'output' => ['type' => API_OUTPUT, 'in' => implode(',', $this->output_fields), + 'default' => API_OUTPUT_EXTEND] + ]]; + if (!CApiInputValidator::validate($api_input_rules, $options, '/', $error)) { + self::exception(ZBX_API_ERROR_PARAMETERS, $error); + } + + if ($options['output'] === API_OUTPUT_EXTEND) { + $options['output'] = $this->output_fields; + } + + $db_auth = []; + + $result = DBselect($this->createSelectQuery($this->tableName(), $options)); + while ($row = DBfetch($result)) { + $db_auth[] = $row; + } + $db_auth = $this->unsetExtraFields($db_auth, ['configid'], []); + + return $db_auth[0]; + } + + /** + * Update authentication parameters. + * + * @param array $auth + * + * @return array + */ + public function update(array $auth): array { + $db_auth = $this->validateUpdate($auth); + + $upd_config = []; + + // strings + $field_names = ['http_strip_domains', 'ldap_host', 'ldap_base_dn', 'ldap_search_attribute', 'ldap_bind_dn', + 'ldap_bind_password' + ]; + foreach ($field_names as $field_name) { + if (array_key_exists($field_name, $auth) && $auth[$field_name] !== $db_auth[$field_name]) { + $upd_config[$field_name] = $auth[$field_name]; + } + } + + // integers + $field_names = ['authentication_type', 'http_auth_enabled', 'http_login_form', 'http_case_sensitive', + 'ldap_configured', 'ldap_port', 'ldap_case_sensitive', 'saml_auth_enabled', 'saml_idp_entityid', + 'saml_sso_url', 'saml_slo_url', 'saml_username_attribute', 'saml_sp_entityid', 'saml_nameid_format', + 'saml_sign_messages', 'saml_sign_assertions', 'saml_sign_authn_requests', 'saml_sign_logout_requests', + 'saml_sign_logout_responses', 'saml_encrypt_nameid', 'saml_encrypt_assertions', 'saml_case_sensitive' + ]; + foreach ($field_names as $field_name) { + if (array_key_exists($field_name, $auth) && $auth[$field_name] != $db_auth[$field_name]) { + $upd_config[$field_name] = $auth[$field_name]; + } + } + + if ($upd_config) { + DB::update('config', [ + 'values' => $upd_config, + 'where' => ['configid' => $db_auth['configid']] + ]); + } + + $this->addAuditBulk(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_AUTHENTICATION, + [['configid' => $db_auth['configid']] + $auth], [$db_auth['configid'] => $db_auth] + ); + + return array_keys($auth); + } + + /** + * Validate updated authentication parameters. + * + * @param array $auth + * + * @throws APIException if the input is invalid. + * + * @return array + */ + protected function validateUpdate(array $auth): array { + $api_input_rules = ['type' => API_OBJECT, 'flags' => API_NOT_EMPTY, 'fields' => [ + 'authentication_type' => ['type' => API_INT32, 'in' => ZBX_AUTH_INTERNAL.','.ZBX_AUTH_LDAP], + 'http_auth_enabled' => ['type' => API_INT32, 'in' => ZBX_AUTH_HTTP_DISABLED.','.ZBX_AUTH_HTTP_ENABLED], + 'http_login_form' => ['type' => API_INT32, 'in' => ZBX_AUTH_FORM_ZABBIX.','.ZBX_AUTH_FORM_HTTP], + 'http_strip_domains' => ['type' => API_STRING_UTF8, 'length' => DB::getFieldLength('config', 'http_strip_domains')], + 'http_case_sensitive' => ['type' => API_INT32, 'in' => ZBX_AUTH_CASE_INSENSITIVE.','.ZBX_AUTH_CASE_SENSITIVE], + 'ldap_configured' => ['type' => API_INT32, 'in' => ZBX_AUTH_LDAP_DISABLED.','.ZBX_AUTH_LDAP_ENABLED], + 'ldap_host' => ['type' => API_STRING_UTF8, 'length' => DB::getFieldLength('config', 'ldap_host')], + 'ldap_port' => ['type' => API_INT32], + 'ldap_base_dn' => ['type' => API_STRING_UTF8, 'length' => DB::getFieldLength('config', 'ldap_base_dn')], + 'ldap_search_attribute' => ['type' => API_STRING_UTF8, 'length' => DB::getFieldLength('config', 'ldap_search_attribute')], + 'ldap_bind_dn' => ['type' => API_STRING_UTF8, 'length' => DB::getFieldLength('config', 'ldap_bind_dn')], + 'ldap_case_sensitive' => ['type' => API_INT32, 'in' => ZBX_AUTH_CASE_INSENSITIVE.','.ZBX_AUTH_CASE_SENSITIVE], + 'ldap_bind_password' => ['type' => API_STRING_UTF8, 'length' => DB::getFieldLength('config', 'ldap_bind_password')], + 'saml_auth_enabled' => ['type' => API_INT32, 'in' => ZBX_AUTH_HTTP_DISABLED.','.ZBX_AUTH_HTTP_ENABLED], + 'saml_idp_entityid' => ['type' => API_STRING_UTF8, 'length' => DB::getFieldLength('config', 'saml_idp_entityid')], + 'saml_sso_url' => ['type' => API_STRING_UTF8, 'length' => DB::getFieldLength('config', 'saml_sso_url')], + 'saml_slo_url' => ['type' => API_STRING_UTF8, 'length' => DB::getFieldLength('config', 'saml_slo_url')], + 'saml_username_attribute' => ['type' => API_STRING_UTF8, 'length' => DB::getFieldLength('config', 'saml_username_attribute')], + 'saml_sp_entityid' => ['type' => API_STRING_UTF8, 'length' => DB::getFieldLength('config', 'saml_sp_entityid')], + 'saml_nameid_format' => ['type' => API_STRING_UTF8, 'length' => DB::getFieldLength('config', 'saml_nameid_format')], + 'saml_sign_messages' => ['type' => API_INT32, 'in' => '0,1'], + 'saml_sign_assertions' => ['type' => API_INT32, 'in' => '0,1'], + 'saml_sign_authn_requests' => ['type' => API_INT32, 'in' => '0,1'], + 'saml_sign_logout_requests' => ['type' => API_INT32, 'in' => '0,1'], + 'saml_sign_logout_responses' => ['type' => API_INT32, 'in' => '0,1'], + 'saml_encrypt_nameid' => ['type' => API_INT32, 'in' => '0,1'], + 'saml_encrypt_assertions' => ['type' => API_INT32, 'in' => '0,1'], + 'saml_case_sensitive' => ['type' => API_INT32, 'in' => ZBX_AUTH_CASE_INSENSITIVE.','.ZBX_AUTH_CASE_SENSITIVE] + ]]; + if (!CApiInputValidator::validate($api_input_rules, $auth, '/', $error)) { + self::exception(ZBX_API_ERROR_PARAMETERS, $error); + } + + // Check permissions. + if (self::$userData['type'] != USER_TYPE_SUPER_ADMIN) { + self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!')); + } + + $output_fields = $this->output_fields; + $output_fields[] = 'configid'; + + return DB::select('config', ['output' => $output_fields])[0]; + } +} diff --git a/ui/include/classes/api/services/CHousekeeping.php b/ui/include/classes/api/services/CHousekeeping.php new file mode 100644 index 00000000000..0142c347259 --- /dev/null +++ b/ui/include/classes/api/services/CHousekeeping.php @@ -0,0 +1,172 @@ +<?php declare(strict_types = 1); +/* +** Zabbix +** Copyright (C) 2001-2020 Zabbix SIA +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +**/ + + +/** + * Class containing methods for operations with housekeeping parameters. + */ +class CHousekeeping extends CApiService { + /** + * @var string + */ + protected $tableName = 'config'; + + /** + * @var string + */ + protected $tableAlias = 'c'; + + /** + * @var array + */ + private $output_fields = ['hk_events_mode', 'hk_events_trigger', 'hk_events_internal', 'hk_events_discovery', + 'hk_events_autoreg', 'hk_services_mode', 'hk_services', 'hk_audit_mode', 'hk_audit', 'hk_sessions_mode', + 'hk_sessions', 'hk_history_mode', 'hk_history_global', 'hk_history', 'hk_trends_mode', 'hk_trends_global', + 'hk_trends', 'db_extension', 'compression_status', 'compress_older', 'compression_availability' + ]; + + /** + * Get housekeeping parameters. + * + * @param array $options + * + * @throws APIException if the input is invalid. + * + * @return array + */ + public function get(array $options): array { + $api_input_rules = ['type' => API_OBJECT, 'fields' => [ + 'output' => ['type' => API_OUTPUT, 'in' => implode(',', $this->output_fields), 'default' => API_OUTPUT_EXTEND] + ]]; + if (!CApiInputValidator::validate($api_input_rules, $options, '/', $error)) { + self::exception(ZBX_API_ERROR_PARAMETERS, $error); + } + + if ($options['output'] === API_OUTPUT_EXTEND) { + $options['output'] = $this->output_fields; + } + + $db_hk = []; + + $result = DBselect($this->createSelectQuery($this->tableName(), $options)); + while ($row = DBfetch($result)) { + $db_hk[] = $row; + } + $db_hk = $this->unsetExtraFields($db_hk, ['configid'], []); + + return $db_hk[0]; + } + + /** + * Update housekeeping parameters. + * + * @param array $hk + * + * @return array + */ + public function update(array $hk): array { + $db_hk = $this->validateUpdate($hk); + + if (self::$userData['type'] != USER_TYPE_SUPER_ADMIN) { + return []; + } + + $upd_config = []; + + // strings + $field_names = ['hk_events_trigger', 'hk_events_internal', 'hk_events_discovery', 'hk_events_autoreg', + 'hk_services', 'hk_audit', 'hk_sessions', 'hk_history', 'hk_trends', 'compress_older' + ]; + foreach ($field_names as $field_name) { + if (array_key_exists($field_name, $hk) && $hk[$field_name] !== $db_hk[$field_name]) { + $upd_config[$field_name] = $hk[$field_name]; + } + } + + // integers + $field_names = ['hk_events_mode', 'hk_services_mode', 'hk_audit_mode', 'hk_sessions_mode', 'hk_history_mode', + 'hk_history_global', 'hk_trends_mode', 'hk_trends_global', 'compression_status' + ]; + foreach ($field_names as $field_name) { + if (array_key_exists($field_name, $hk) && $hk[$field_name] != $db_hk[$field_name]) { + $upd_config[$field_name] = $hk[$field_name]; + } + } + + if ($upd_config) { + DB::update('config', [ + 'values' => $upd_config, + 'where' => ['configid' => $db_hk['configid']] + ]); + } + + $this->addAuditBulk(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_HOUSEKEEPING, + [['configid' => $db_hk['configid']] + $hk], [$db_hk['configid'] => $db_hk] + ); + + return array_keys($hk); + } + + /** + * Validate updated housekeeping parameters. + * + * @param array $hk + * + * @throws APIException if the input is invalid. + * + * @return array + */ + protected function validateUpdate(array $hk): array { + $api_input_rules = ['type' => API_OBJECT, 'flags' => API_NOT_EMPTY, 'fields' => [ + 'hk_events_mode' => ['type' => API_INT32, 'in' => '0,1'], + 'hk_events_trigger' => ['type' => API_TIME_UNIT, 'in' => implode(':', [SEC_PER_DAY, 25 * SEC_PER_YEAR])], + 'hk_events_internal' => ['type' => API_TIME_UNIT, 'in' => implode(':', [SEC_PER_DAY, 25 * SEC_PER_YEAR])], + 'hk_events_discovery' => ['type' => API_TIME_UNIT, 'in' => implode(':', [SEC_PER_DAY, 25 * SEC_PER_YEAR])], + 'hk_events_autoreg' => ['type' => API_TIME_UNIT, 'in' => implode(':', [SEC_PER_DAY, 25 * SEC_PER_YEAR])], + 'hk_services_mode' => ['type' => API_INT32, 'in' => '0,1'], + 'hk_services' => ['type' => API_TIME_UNIT, 'in' => implode(':', [SEC_PER_DAY, 25 * SEC_PER_YEAR])], + 'hk_audit_mode' => ['type' => API_INT32, 'in' => '0,1'], + 'hk_audit' => ['type' => API_TIME_UNIT, 'in' => implode(':', [SEC_PER_DAY, 25 * SEC_PER_YEAR])], + 'hk_sessions_mode' => ['type' => API_INT32, 'in' => '0,1'], + 'hk_sessions' => ['type' => API_TIME_UNIT, 'in' => implode(':', [SEC_PER_DAY, 25 * SEC_PER_YEAR])], + 'hk_history_mode' => ['type' => API_INT32, 'in' => '0,1'], + 'hk_history_global' => ['type' => API_INT32, 'in' => '0,1'], + 'hk_history' => ['type' => API_TIME_UNIT, 'in' => '0,'.implode(':', [SEC_PER_HOUR, 25 * SEC_PER_YEAR])], + 'hk_trends_mode' => ['type' => API_INT32, 'in' => '0,1'], + 'hk_trends_global' => ['type' => API_INT32, 'in' => '0,1'], + 'hk_trends' => ['type' => API_TIME_UNIT, 'in' => '0,'.implode(':', [SEC_PER_DAY, 25 * SEC_PER_YEAR])], + 'compression_status' => ['type' => API_INT32, 'in' => '0,1'], + 'compress_older' => ['type' => API_TIME_UNIT, 'in' => implode(':', [7 * SEC_PER_DAY, 25 * SEC_PER_YEAR])] + ]]; + if (!CApiInputValidator::validate($api_input_rules, $hk, '/', $error)) { + self::exception(ZBX_API_ERROR_PARAMETERS, $error); + } + + // Check permissions. + if (self::$userData['type'] != USER_TYPE_SUPER_ADMIN) { + self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!')); + } + + $output_fields = array_diff($this->output_fields, ['db_extension', 'compression_availability']); + $output_fields[] = 'configid'; + + return DB::select('config', ['output' => $output_fields])[0]; + } +} diff --git a/ui/include/classes/api/services/CItem.php b/ui/include/classes/api/services/CItem.php index 4e87a7f645b..5d09d637b49 100644 --- a/ui/include/classes/api/services/CItem.php +++ b/ui/include/classes/api/services/CItem.php @@ -1164,7 +1164,9 @@ class CItem extends CItemGeneral { $requestedOutput['prevvalue'] = true; } if ($requestedOutput) { - $history = Manager::History()->getLastValues($result, 2, ZBX_HISTORY_PERIOD); + $history = Manager::History()->getLastValues($result, 2, timeUnitToSeconds(CSettingsHelper::get( + CSettingsHelper::HISTORY_PERIOD + ))); foreach ($result as &$item) { $lastHistory = isset($history[$item['itemid']][0]) ? $history[$item['itemid']][0] : null; $prevHistory = isset($history[$item['itemid']][1]) ? $history[$item['itemid']][1] : null; diff --git a/ui/include/classes/api/services/CProblem.php b/ui/include/classes/api/services/CProblem.php index c9a58d9cbae..6e32c53dd37 100644 --- a/ui/include/classes/api/services/CProblem.php +++ b/ui/include/classes/api/services/CProblem.php @@ -287,8 +287,7 @@ class CProblem extends CApiService { // recent if ($options['recent'] !== null && $options['recent']) { - $config = select_config(); - $ok_events_from = time() - timeUnitToSeconds($config['ok_period']); + $ok_events_from = time() - timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::OK_PERIOD)); $sqlParts['where'][] = '(p.r_eventid IS NULL OR p.r_clock>'.$ok_events_from.')'; } diff --git a/ui/include/classes/api/services/CScript.php b/ui/include/classes/api/services/CScript.php index 7534b1e54b3..140bf163ad8 100644 --- a/ui/include/classes/api/services/CScript.php +++ b/ui/include/classes/api/services/CScript.php @@ -632,7 +632,9 @@ class CScript extends CApiService { } // execute script - $zabbix_server = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, ZBX_SCRIPT_TIMEOUT, ZBX_SOCKET_BYTES_LIMIT); + $zabbix_server = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, + timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::SCRIPT_TIMEOUT)), ZBX_SOCKET_BYTES_LIMIT + ); $result = $zabbix_server->executeScript($data['scriptid'], $data['hostid'], self::$userData['sessionid']); if ($result !== false) { diff --git a/ui/include/classes/api/services/CSettings.php b/ui/include/classes/api/services/CSettings.php new file mode 100644 index 00000000000..0e0fa64367a --- /dev/null +++ b/ui/include/classes/api/services/CSettings.php @@ -0,0 +1,322 @@ +<?php declare(strict_types = 1); +/* +** Zabbix +** Copyright (C) 2001-2020 Zabbix SIA +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +**/ + + +/** + * Class containing methods for operations with the main part of administration settings. + */ +class CSettings extends CApiService { + /** + * @var string + */ + protected $tableName = 'config'; + + /** + * @var string + */ + protected $tableAlias = 'c'; + + /** + * @var array + */ + private $output_fields = ['default_theme', 'search_limit', 'max_in_table', 'server_check_interval', 'work_period', + 'show_technical_errors', 'history_period', 'period_default', 'max_period', 'severity_color_0', + 'severity_color_1', 'severity_color_2', 'severity_color_3', 'severity_color_4', 'severity_color_5', + 'severity_name_0', 'severity_name_1', 'severity_name_2', 'severity_name_3', 'severity_name_4', + 'severity_name_5', 'custom_color', 'ok_period', 'blink_period', 'problem_unack_color', 'problem_ack_color', + 'ok_unack_color', 'ok_ack_color', 'problem_unack_style', 'problem_ack_style', 'ok_unack_style', + 'ok_ack_style', 'refresh_unsupported', 'discovery_groupid', 'default_inventory_mode', 'alert_usrgrpid', + 'snmptrap_logging', 'default_lang', 'default_timezone', 'login_attempts', 'login_block', 'validate_uri_schemes', + 'uri_valid_schemes', 'x_frame_options', 'iframe_sandboxing_enabled', 'iframe_sandboxing_exceptions', + 'max_overview_table_size', 'connect_timeout', 'socket_timeout', 'media_type_test_timeout', 'script_timeout', + 'item_test_timeout' + ]; + + /** + * Get settings parameters. + * + * @param array $options + * + * @throws APIException if the input is invalid. + * + * @return array + */ + public function get(array $options): array { + $api_input_rules = ['type' => API_OBJECT, 'fields' => [ + 'output' => ['type' => API_OUTPUT, 'in' => implode(',', $this->output_fields), 'default' => API_OUTPUT_EXTEND] + ]]; + if (!CApiInputValidator::validate($api_input_rules, $options, '/', $error)) { + self::exception(ZBX_API_ERROR_PARAMETERS, $error); + } + + if ($options['output'] === API_OUTPUT_EXTEND) { + $options['output'] = $this->output_fields; + } + + $db_settings = []; + + $result = DBselect($this->createSelectQuery($this->tableName(), $options)); + while ($row = DBfetch($result)) { + $db_settings[] = $row; + } + $db_settings = $this->unsetExtraFields($db_settings, ['configid'], []); + + return $db_settings[0]; + } + + /** + * Get global settings parameters. + * + * @param array $options + * + * @throws APIException if the input is invalid. + * + * @return array + */ + public function getGlobal(array $options): array { + $output_fields = ['default_theme', 'show_technical_errors', 'severity_color_0', 'severity_color_1', + 'severity_color_2', 'severity_color_3', 'severity_color_4', 'severity_color_5', 'custom_color', + 'problem_unack_color', 'problem_ack_color', 'ok_unack_color', 'ok_ack_color', 'default_lang', + 'x_frame_options' + ]; + $api_input_rules = ['type' => API_OBJECT, 'fields' => [ + 'output' => ['type' => API_OUTPUT, 'in' => implode(',', $output_fields), 'default' => API_OUTPUT_EXTEND] + ]]; + if (!CApiInputValidator::validate($api_input_rules, $options, '/', $error)) { + self::exception(ZBX_API_ERROR_PARAMETERS, $error); + } + + if ($options['output'] === API_OUTPUT_EXTEND) { + $options['output'] = $output_fields; + } + + $db_settings = []; + + $result = DBselect($this->createSelectQuery($this->tableName(), $options)); + while ($row = DBfetch($result)) { + $db_settings[] = $row; + } + $db_settings = $this->unsetExtraFields($db_settings, ['configid'], []); + + return $db_settings[0]; + } + + /** + * Update settings parameters. + * + * @param array $settings + * + * @return array + */ + public function update(array $settings): array { + $db_settings = $this->validateUpdate($settings); + + $upd_config = []; + + // strings + $field_names = ['default_theme', 'work_period', 'history_period', 'period_default', 'max_period', + 'severity_color_0', 'severity_color_1', 'severity_color_2', 'severity_color_3', 'severity_color_4', + 'severity_color_5', 'severity_name_0', 'severity_name_1', 'severity_name_2', 'severity_name_3', + 'severity_name_4', 'severity_name_5', 'ok_period', 'blink_period', 'problem_unack_color', + 'problem_ack_color', 'ok_unack_color', 'ok_ack_color', 'refresh_unsupported', 'default_lang', + 'default_timezone', 'login_block', 'uri_valid_schemes', 'x_frame_options', 'iframe_sandboxing_exceptions', + 'connect_timeout', 'socket_timeout', 'media_type_test_timeout', 'script_timeout', 'item_test_timeout' + ]; + foreach ($field_names as $field_name) { + if (array_key_exists($field_name, $settings) && $settings[$field_name] !== $db_settings[$field_name]) { + $upd_config[$field_name] = $settings[$field_name]; + } + } + + // integers + $field_names = ['search_limit', 'max_in_table', 'server_check_interval', 'show_technical_errors', + 'custom_color', 'problem_unack_style', 'problem_ack_style', 'ok_unack_style', 'ok_ack_style', + 'discovery_groupid', 'default_inventory_mode', 'alert_usrgrpid', 'snmptrap_logging', 'login_attempts', + 'validate_uri_schemes', 'iframe_sandboxing_enabled', 'max_overview_table_size' + ]; + foreach ($field_names as $field_name) { + if (array_key_exists($field_name, $settings) && $settings[$field_name] != $db_settings[$field_name]) { + $upd_config[$field_name] = $settings[$field_name]; + } + } + + if ($upd_config) { + DB::update('config', [ + 'values' => $upd_config, + 'where' => ['configid' => $db_settings['configid']] + ]); + + if (array_key_exists('discovery_groupid', $upd_config) + && bccomp($upd_config['discovery_groupid'], $db_settings['discovery_groupid']) !== 0) { + $this->setHostGroupInternal($db_settings['discovery_groupid'], ZBX_NOT_INTERNAL_GROUP); + $this->setHostGroupInternal($upd_config['discovery_groupid'], ZBX_INTERNAL_GROUP); + } + } + + $this->addAuditBulk(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_SETTINGS, + [['configid' => $db_settings['configid']] + $settings], [$db_settings['configid'] => $db_settings] + ); + + return array_keys($settings); + } + + /** + * Validate updated settings parameters. + * + * @param array $settings + * + * @throws APIException if the input is invalid. + * + * @return array + */ + protected function validateUpdate(array $settings): array { + $api_input_rules = ['type' => API_OBJECT, 'flags' => API_NOT_EMPTY, 'fields' => [ + 'default_theme' => ['type' => API_STRING_UTF8, 'in' => implode(',', array_keys(APP::getThemes()))], + 'search_limit' => ['type' => API_INT32, 'in' => '1:999999'], + 'max_in_table' => ['type' => API_INT32, 'in' => '1:99999'], + 'server_check_interval' => ['type' => API_INT32, 'in' => '0,'.SERVER_CHECK_INTERVAL], + 'work_period' => ['type' => API_TIME_PERIOD, 'flags' => API_ALLOW_USER_MACRO], + 'show_technical_errors' => ['type' => API_INT32, 'in' => '0,1'], + 'history_period' => ['type' => API_TIME_UNIT, 'in' => implode(':', [SEC_PER_DAY, 7 * SEC_PER_DAY])], + 'period_default' => ['type' => API_TIME_UNIT, 'flags' => API_TIME_UNIT_WITH_YEAR, 'in' => implode(':', [SEC_PER_MIN, 10 * SEC_PER_YEAR])], + 'max_period' => ['type' => API_TIME_UNIT, 'flags' => API_TIME_UNIT_WITH_YEAR, 'in' => implode(':', [SEC_PER_YEAR, 10 * SEC_PER_YEAR])], + 'severity_color_0' => ['type' => API_COLOR, 'flags' => API_NOT_EMPTY], + 'severity_color_1' => ['type' => API_COLOR, 'flags' => API_NOT_EMPTY], + 'severity_color_2' => ['type' => API_COLOR, 'flags' => API_NOT_EMPTY], + 'severity_color_3' => ['type' => API_COLOR, 'flags' => API_NOT_EMPTY], + 'severity_color_4' => ['type' => API_COLOR, 'flags' => API_NOT_EMPTY], + 'severity_color_5' => ['type' => API_COLOR, 'flags' => API_NOT_EMPTY], + 'severity_name_0' => ['type' => API_STRING_UTF8, 'length' => DB::getFieldLength('config', 'severity_name_0')], + 'severity_name_1' => ['type' => API_STRING_UTF8, 'length' => DB::getFieldLength('config', 'severity_name_1')], + 'severity_name_2' => ['type' => API_STRING_UTF8, 'length' => DB::getFieldLength('config', 'severity_name_2')], + 'severity_name_3' => ['type' => API_STRING_UTF8, 'length' => DB::getFieldLength('config', 'severity_name_3')], + 'severity_name_4' => ['type' => API_STRING_UTF8, 'length' => DB::getFieldLength('config', 'severity_name_4')], + 'severity_name_5' => ['type' => API_STRING_UTF8, 'length' => DB::getFieldLength('config', 'severity_name_5')], + 'custom_color' => ['type' => API_INT32, 'in' => EVENT_CUSTOM_COLOR_DISABLED.','.EVENT_CUSTOM_COLOR_ENABLED], + 'ok_period' => ['type' => API_TIME_UNIT], + 'blink_period' => ['type' => API_TIME_UNIT], + 'problem_unack_color' => ['type' => API_COLOR, 'flags' => API_NOT_EMPTY], + 'problem_ack_color' => ['type' => API_COLOR, 'flags' => API_NOT_EMPTY], + 'ok_unack_color' => ['type' => API_COLOR, 'flags' => API_NOT_EMPTY], + 'ok_ack_color' => ['type' => API_COLOR, 'flags' => API_NOT_EMPTY], + 'problem_unack_style' => ['type' => API_INT32, 'in' => '0,1'], + 'problem_ack_style' => ['type' => API_INT32, 'in' => '0,1'], + 'ok_unack_style' => ['type' => API_INT32, 'in' => '0,1'], + 'ok_ack_style' => ['type' => API_INT32, 'in' => '0,1'], + 'refresh_unsupported' => ['type' => API_TIME_UNIT], + 'discovery_groupid' => ['type' => API_ID], + 'default_inventory_mode' => ['type' => API_INT32, 'in' => HOST_INVENTORY_DISABLED.','.HOST_INVENTORY_MANUAL.','.HOST_INVENTORY_AUTOMATIC], + 'alert_usrgrpid' => ['type' => API_ID, 'flags' => API_ALLOW_NULL], + 'snmptrap_logging' => ['type' => API_INT32, 'in' => '0,1'], + 'default_lang' => ['type' => API_STRING_UTF8, 'length' => DB::getFieldLength('config', 'default_lang')], + 'default_timezone' => ['type' => API_STRING_UTF8, 'in' => ZBX_DEFAULT_TIMEZONE.','.implode(',', DateTimeZone::listIdentifiers())], + 'login_attempts' => ['type' => API_INT32, 'in' => '1:32'], + 'login_block' => ['type' => API_TIME_UNIT, 'in' => implode(':', [30, SEC_PER_HOUR])], + 'validate_uri_schemes' => ['type' => API_INT32, 'in' => '0,1'], + 'uri_valid_schemes' => ['type' => API_STRING_UTF8, 'length' => DB::getFieldLength('config', 'uri_valid_schemes')], + 'x_frame_options' => ['type' => API_STRING_UTF8, 'length' => DB::getFieldLength('config', 'x_frame_options')], + 'iframe_sandboxing_enabled' => ['type' => API_INT32, 'in' => '0,1'], + 'iframe_sandboxing_exceptions' => ['type' => API_STRING_UTF8, 'length' => DB::getFieldLength('config', 'iframe_sandboxing_exceptions')], + 'max_overview_table_size' => ['type' => API_INT32, 'in' => '5:999999'], + 'connect_timeout' => ['type' => API_TIME_UNIT, 'in' => '1:30'], + 'socket_timeout' => ['type' => API_TIME_UNIT, 'in' => '1:300'], + 'media_type_test_timeout' => ['type' => API_TIME_UNIT, 'in' => '1:300'], + 'script_timeout' => ['type' => API_TIME_UNIT, 'in' => '1:300'], + 'item_test_timeout' => ['type' => API_TIME_UNIT, 'in' => '1:300'] + ]]; + if (!CApiInputValidator::validate($api_input_rules, $settings, '/', $error)) { + self::exception(ZBX_API_ERROR_PARAMETERS, $error); + } + + // Check permissions. + if (self::$userData['type'] != USER_TYPE_SUPER_ADMIN) { + self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!')); + } + + if (array_key_exists('discovery_groupid', $settings)) { + $db_hstgrp_exists = API::HostGroup()->get([ + 'countOutput' => true, + 'groupids' => $settings['discovery_groupid'], + 'filter' => ['flags' => ZBX_FLAG_DISCOVERY_NORMAL], + 'editable' => true + ]); + if (!$db_hstgrp_exists) { + self::exception(ZBX_API_ERROR_PARAMETERS, + _s('Host group with ID "%1$s" is not available.', $settings['discovery_groupid']) + ); + } + } + + if (array_key_exists('alert_usrgrpid', $settings) && $settings['alert_usrgrpid'] !== null) { + $db_usrgrp_exists = API::UserGroup()->get([ + 'countOutput' => true, + 'usrgrpids' => $settings['alert_usrgrpid'] + ]); + if (!$db_usrgrp_exists) { + self::exception(ZBX_API_ERROR_PARAMETERS, + _s('User group with ID "%1$s" is not available.', $settings['alert_usrgrpid']) + ); + } + } + + $period_default_updated = array_key_exists('period_default', $settings); + $max_period_updated = array_key_exists('max_period', $settings); + if ($period_default_updated || $max_period_updated) { + $period_default = $period_default_updated + ? timeUnitToSeconds($settings['period_default'], true) + : timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::PERIOD_DEFAULT), true); + + $max_period = $max_period_updated + ? timeUnitToSeconds($settings['max_period'], true) + : timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::MAX_PERIOD), true); + + if ($period_default > $max_period) { + $field = 'period_default'; + $message = _('time filter default period exceeds the max period'); + if (!$period_default_updated) { + $field = 'max_period'; + $message = _('max period is less than time filter default period'); + } + + $error = _s('Incorrect value for field "%1$s": %2$s.', $field, $message); + + self::exception(ZBX_API_ERROR_PARAMETERS, $error); + } + } + + $output_fields = $this->output_fields; + $output_fields[] = 'configid'; + + return DB::select('config', ['output' => $output_fields])[0]; + } + + /** + * Set or unset the host group as internal + * + * @param string $groupid Host group ID + * @param int $internal Value of internal option + */ + private function setHostGroupInternal($groupid, $internal): void { + DB::update('hstgrp', [ + 'values' => ['internal' => $internal], + 'where' => ['groupid' => $groupid] + ]); + } +} diff --git a/ui/include/classes/api/services/CTrigger.php b/ui/include/classes/api/services/CTrigger.php index 2e074e35235..934f4b9338b 100644 --- a/ui/include/classes/api/services/CTrigger.php +++ b/ui/include/classes/api/services/CTrigger.php @@ -419,10 +419,10 @@ class CTrigger extends CTriggerGeneral { // only_true if ($options['only_true'] !== null) { - $config = select_config(); $sqlParts['where']['ot'] = '((t.value='.TRIGGER_VALUE_TRUE.')'. ' OR ((t.value='.TRIGGER_VALUE_FALSE.')'. - ' AND (t.lastchange>'.(time() - timeUnitToSeconds($config['ok_period'])). + ' AND (t.lastchange>'. + (time() - timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::OK_PERIOD))). '))'. ')'; } diff --git a/ui/include/classes/api/services/CUser.php b/ui/include/classes/api/services/CUser.php index e61c4d472dd..9e834abeea0 100644 --- a/ui/include/classes/api/services/CUser.php +++ b/ui/include/classes/api/services/CUser.php @@ -612,10 +612,10 @@ class CUser extends CApiService { * @return bool */ private static function hasInternalAuth($user, $db_usrgrps) { - $config = select_config(); - $system_gui_access = ($config['authentication_type'] == ZBX_AUTH_INTERNAL) - ? GROUP_GUI_ACCESS_INTERNAL - : GROUP_GUI_ACCESS_LDAP; + $system_gui_access = + (CAuthenticationHelper::get(CAuthenticationHelper::AUTHENTICATION_TYPE) == ZBX_AUTH_INTERNAL) + ? GROUP_GUI_ACCESS_INTERNAL + : GROUP_GUI_ACCESS_LDAP; foreach($user['usrgrps'] as $usrgrp) { $gui_access = (int) $db_usrgrps[$usrgrp['usrgrpid']]['gui_access']; @@ -1130,13 +1130,20 @@ class CUser extends CApiService { * @return bool */ protected function ldapLogin(array $user) { - $config = select_config(); $cnf = []; + $auth_params = [ + CAuthenticationHelper::LDAP_CASE_SENSITIVE, + CAuthenticationHelper::LDAP_CONFIGURED, + CAuthenticationHelper::LDAP_HOST, + CAuthenticationHelper::LDAP_PORT, + CAuthenticationHelper::LDAP_BASE_DN, + CAuthenticationHelper::LDAP_BIND_DN, + CAuthenticationHelper::LDAP_SEARCH_ATTRIBUTE, + CAuthenticationHelper::LDAP_BIND_PASSWORD + ]; - foreach ($config as $id => $value) { - if (strpos($id, 'ldap_') !== false) { - $cnf[str_replace('ldap_', '', $id)] = $config[$id]; - } + foreach ($auth_params as $param) { + $cnf[str_replace('ldap_', '', $param)] = CAuthenticationHelper::get($param); } $ldap_status = (new CFrontendSetup())->checkPhpLdapModule(); @@ -1211,20 +1218,21 @@ class CUser extends CApiService { self::exception(ZBX_API_ERROR_PARAMETERS, $error); } - $config = select_config(); $group_to_auth_map = [ - GROUP_GUI_ACCESS_SYSTEM => $config['authentication_type'], + GROUP_GUI_ACCESS_SYSTEM => CAuthenticationHelper::get(CAuthenticationHelper::AUTHENTICATION_TYPE), GROUP_GUI_ACCESS_INTERNAL => ZBX_AUTH_INTERNAL, GROUP_GUI_ACCESS_LDAP => ZBX_AUTH_LDAP, - GROUP_GUI_ACCESS_DISABLED => $config['authentication_type'] + GROUP_GUI_ACCESS_DISABLED => CAuthenticationHelper::get(CAuthenticationHelper::AUTHENTICATION_TYPE) ]; - $db_user = $this->findByAlias($user['user'], ($config['ldap_case_sensitive'] == ZBX_AUTH_CASE_SENSITIVE), - $config['authentication_type'], true + $db_user = $this->findByAlias($user['user'], + (CAuthenticationHelper::get(CAuthenticationHelper::LDAP_CASE_SENSITIVE) == ZBX_AUTH_CASE_SENSITIVE), + CAuthenticationHelper::get(CAuthenticationHelper::AUTHENTICATION_TYPE), true ); - if ($db_user['attempt_failed'] >= ZBX_LOGIN_ATTEMPTS) { - $sec_left = ZBX_LOGIN_BLOCK - (time() - $db_user['attempt_clock']); + if ($db_user['attempt_failed'] >= CSettingsHelper::get(CSettingsHelper::LOGIN_ATTEMPTS)) { + $sec_left = timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::LOGIN_BLOCK)) + - (time() - $db_user['attempt_clock']); if ($sec_left > 0) { self::exception(ZBX_API_ERROR_PERMISSIONS, @@ -1268,9 +1276,10 @@ class CUser extends CApiService { $db_user['userip'] ); - if ($e->getCode() == ZBX_API_ERROR_PERMISSIONS && $db_user['attempt_failed'] >= ZBX_LOGIN_ATTEMPTS) { + if ($e->getCode() == ZBX_API_ERROR_PERMISSIONS + && $db_user['attempt_failed'] >= CSettingsHelper::get(CSettingsHelper::LOGIN_ATTEMPTS)) { self::exception(ZBX_API_ERROR_PERMISSIONS, - _n('Account is blocked for %1$s second.', 'Account is blocked for %1$s seconds.', ZBX_LOGIN_BLOCK) + _n('Account is blocked for %1$s second.', 'Account is blocked for %1$s seconds.', timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::LOGIN_BLOCK))) ); } @@ -1401,12 +1410,11 @@ class CUser extends CApiService { $db_user['userip'] = $usrgrps['userip']; $db_user['gui_access'] = $usrgrps['gui_access']; - $config = select_config(); if ($db_user['lang'] === LANG_DEFAULT) { - $db_user['lang'] = $config['default_lang']; + $db_user['lang'] = CSettingsHelper::get(CSettingsHelper::DEFAULT_LANG); } if ($db_user['timezone'] === TIMEZONE_DEFAULT) { - $db_user['timezone'] = $config['default_timezone']; + $db_user['timezone'] = CSettingsHelper::get(CSettingsHelper::DEFAULT_TIMEZONE); } if ($db_user['timezone'] !== ZBX_DEFAULT_TIMEZONE) { date_default_timezone_set($db_user['timezone']); @@ -1640,12 +1648,11 @@ class CUser extends CApiService { $db_user['userip'] = $usrgrps['userip']; $db_user['gui_access'] = $usrgrps['gui_access']; - $config = select_config(); if ($db_user['lang'] === LANG_DEFAULT) { - $db_user['lang'] = $config['default_lang']; + $db_user['lang'] = CSettingsHelper::get(CSettingsHelper::DEFAULT_LANG); } if ($db_user['timezone'] === TIMEZONE_DEFAULT) { - $db_user['timezone'] = $config['default_timezone']; + $db_user['timezone'] = CSettingsHelper::get(CSettingsHelper::DEFAULT_TIMEZONE); } if ($db_user['timezone'] !== ZBX_DEFAULT_TIMEZONE) { date_default_timezone_set($db_user['timezone']); diff --git a/ui/include/classes/api/services/CUserGroup.php b/ui/include/classes/api/services/CUserGroup.php index 9fd58bd7652..f1553af905d 100644 --- a/ui/include/classes/api/services/CUserGroup.php +++ b/ui/include/classes/api/services/CUserGroup.php @@ -913,13 +913,10 @@ class CUserGroup extends CApiService { } // Check if user group are used in config. - $config = select_config(); - - if (array_key_exists($config['alert_usrgrpid'], $db_usrgrps)) { - self::exception(ZBX_API_ERROR_PARAMETERS, _s( - 'User group "%1$s" is used in configuration for database down messages.', - $db_usrgrps[$config['alert_usrgrpid']]['name'] - )); + if (array_key_exists(CSettingsHelper::get(CSettingsHelper::ALERT_USRGRPID), $db_usrgrps)) { + self::exception(ZBX_API_ERROR_PARAMETERS, + _s('User group "%1$s" is used in configuration for database down messages.', $db_usrgrps[CSettingsHelper::get(CSettingsHelper::ALERT_USRGRPID)]['name']) + ); } $this->checkUsersWithoutGroups($usrgrps); diff --git a/ui/include/classes/api/wrappers/CFrontendApiWrapper.php b/ui/include/classes/api/wrappers/CFrontendApiWrapper.php index ef17f48bd52..e2c524675d7 100644 --- a/ui/include/classes/api/wrappers/CFrontendApiWrapper.php +++ b/ui/include/classes/api/wrappers/CFrontendApiWrapper.php @@ -108,6 +108,7 @@ class CFrontendApiWrapper extends CApiWrapper { protected function requiresAuthentication($api, $method) { return !(($api === 'user' && $method === 'login') || ($api === 'user' && $method === 'checkAuthentication') - || ($api === 'apiinfo' && $method === 'version')); + || ($api === 'apiinfo' && $method === 'version') + || ($api === 'settings' && $method === 'getGlobal')); } } diff --git a/ui/include/classes/core/ZBase.php b/ui/include/classes/core/ZBase.php index 1e611be1a8b..38cea08ae77 100644 --- a/ui/include/classes/core/ZBase.php +++ b/ui/include/classes/core/ZBase.php @@ -126,7 +126,6 @@ class ZBase { require_once 'include/js.inc.php'; require_once 'include/users.inc.php'; require_once 'include/validate.inc.php'; - require_once 'include/profiles.inc.php'; require_once 'include/locales.inc.php'; require_once 'include/db.inc.php'; @@ -171,12 +170,11 @@ class ZBase { $this->loadConfigFile(); $this->initDB(); - $config = select_config(); - $this->initLocales($config['default_lang']); + $this->initLocales(CSettingsHelper::getGlobal(CSettingsHelper::DEFAULT_LANG)); $this->authenticateUser(); - if (CWebUser::$data['lang'] !== $config['default_lang']) { + if (CWebUser::$data['lang'] !== CSettingsHelper::get(CSettingsHelper::DEFAULT_LANG)) { $this->initLocales(CWebUser::$data['lang']); } @@ -568,7 +566,11 @@ class ZBase { 'javascript' => [ 'files' => [] ], - 'web_layout_mode' => ZBX_LAYOUT_NORMAL + 'web_layout_mode' => ZBX_LAYOUT_NORMAL, + 'config' => [ + 'server_check_interval' => CSettingsHelper::get(CSettingsHelper::SERVER_CHECK_INTERVAL), + 'x_frame_options' => CSettingsHelper::get(CSettingsHelper::X_FRAME_OPTIONS) + ] ]; if ($router->getView() !== null && $response->isViewEnabled()) { diff --git a/ui/include/classes/graphdraw/CLineGraphDraw.php b/ui/include/classes/graphdraw/CLineGraphDraw.php index 386e8ffb668..fb316f7ce30 100644 --- a/ui/include/classes/graphdraw/CLineGraphDraw.php +++ b/ui/include/classes/graphdraw/CLineGraphDraw.php @@ -200,7 +200,6 @@ class CLineGraphDraw extends CGraphDraw { $this->itemsHost = null; - $config = select_config(); $items = []; for ($i = 0; $i < $this->num; $i++) { @@ -218,15 +217,15 @@ class CLineGraphDraw extends CGraphDraw { $to_resolve = []; // Override item history setting with housekeeping settings, if they are enabled in config. - if ($config['hk_history_global']) { - $item['history'] = timeUnitToSeconds($config['hk_history']); + if (CHousekeepingHelper::get(CHousekeepingHelper::HK_HISTORY_GLOBAL)) { + $item['history'] = timeUnitToSeconds(CHousekeepingHelper::get(CHousekeepingHelper::HK_HISTORY)); } else { $to_resolve[] = 'history'; } - if ($config['hk_trends_global']) { - $item['trends'] = timeUnitToSeconds($config['hk_trends']); + if (CHousekeepingHelper::get(CHousekeepingHelper::HK_TRENDS_GLOBAL)) { + $item['trends'] = timeUnitToSeconds(CHousekeepingHelper::get(CHousekeepingHelper::HK_TRENDS)); } else { $to_resolve[] = 'trends'; @@ -238,7 +237,7 @@ class CLineGraphDraw extends CGraphDraw { $simple_interval_parser = new CSimpleIntervalParser(); - if (!$config['hk_history_global']) { + if (!CHousekeepingHelper::get(CHousekeepingHelper::HK_HISTORY_GLOBAL)) { if ($simple_interval_parser->parse($item['history']) != CParser::PARSE_SUCCESS) { show_error_message(_s('Incorrect value for field "%1$s": %2$s.', 'history', _('invalid history storage period') @@ -248,7 +247,7 @@ class CLineGraphDraw extends CGraphDraw { $item['history'] = timeUnitToSeconds($item['history']); } - if (!$config['hk_trends_global']) { + if (!CHousekeepingHelper::get(CHousekeepingHelper::HK_TRENDS_GLOBAL)) { if ($simple_interval_parser->parse($item['trends']) != CParser::PARSE_SUCCESS) { show_error_message(_s('Incorrect value for field "%1$s": %2$s.', 'trends', _('invalid trend storage period') @@ -1243,10 +1242,10 @@ class CLineGraphDraw extends CGraphDraw { return; } - $config = select_config(); - $config = CMacrosResolverHelper::resolveTimeUnitMacros([$config], ['work_period'])[0]; + $config = [CSettingsHelper::WORK_PERIOD => CSettingsHelper::get(CSettingsHelper::WORK_PERIOD)]; + $config = CMacrosResolverHelper::resolveTimeUnitMacros([$config], [CSettingsHelper::WORK_PERIOD])[0]; - $periods = parse_period($config['work_period']); + $periods = parse_period($config[CSettingsHelper::WORK_PERIOD]); if (!$periods) { return; } diff --git a/ui/include/classes/graphdraw/CPieGraphDraw.php b/ui/include/classes/graphdraw/CPieGraphDraw.php index 7a421083a5d..866c8847076 100644 --- a/ui/include/classes/graphdraw/CPieGraphDraw.php +++ b/ui/include/classes/graphdraw/CPieGraphDraw.php @@ -132,7 +132,6 @@ class CPieGraphDraw extends CGraphDraw { $history = Manager::History()->getLastValues($lastValueItems); } - $config = select_config(); $items = []; for ($i = 0; $i < $this->num; $i++) { @@ -143,15 +142,15 @@ class CPieGraphDraw extends CGraphDraw { $to_resolve = []; // Override item history setting with housekeeping settings, if they are enabled in config. - if ($config['hk_history_global']) { - $item['history'] = timeUnitToSeconds($config['hk_history']); + if (CHousekeepingHelper::get(CHousekeepingHelper::HK_HISTORY_GLOBAL)) { + $item['history'] = timeUnitToSeconds(CHousekeepingHelper::get(CHousekeepingHelper::HK_HISTORY)); } else { $to_resolve[] = 'history'; } - if ($config['hk_trends_global']) { - $item['trends'] = timeUnitToSeconds($config['hk_trends']); + if (CHousekeepingHelper::get(CHousekeepingHelper::HK_TRENDS_GLOBAL)) { + $item['trends'] = timeUnitToSeconds(CHousekeepingHelper::get(CHousekeepingHelper::HK_TRENDS)); } else { $to_resolve[] = 'trends'; @@ -163,7 +162,7 @@ class CPieGraphDraw extends CGraphDraw { $simple_interval_parser = new CSimpleIntervalParser(); - if (!$config['hk_history_global']) { + if (!CHousekeepingHelper::get(CHousekeepingHelper::HK_HISTORY_GLOBAL)) { if ($simple_interval_parser->parse($item['history']) != CParser::PARSE_SUCCESS) { show_error_message(_s('Incorrect value for field "%1$s": %2$s.', 'history', _('invalid history storage period') @@ -173,7 +172,7 @@ class CPieGraphDraw extends CGraphDraw { $item['history'] = timeUnitToSeconds($item['history']); } - if (!$config['hk_trends_global']) { + if (!CHousekeepingHelper::get(CHousekeepingHelper::HK_TRENDS_GLOBAL)) { if ($simple_interval_parser->parse($item['trends']) != CParser::PARSE_SUCCESS) { show_error_message(_s('Incorrect value for field "%1$s": %2$s.', 'trends', _('invalid trend storage period') diff --git a/ui/include/classes/helpers/CAuthenticationHelper.php b/ui/include/classes/helpers/CAuthenticationHelper.php new file mode 100644 index 00000000000..ee86a7fd720 --- /dev/null +++ b/ui/include/classes/helpers/CAuthenticationHelper.php @@ -0,0 +1,77 @@ +<?php declare(strict_types = 1); +/* +** Zabbix +** Copyright (C) 2001-2020 Zabbix SIA +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +**/ + + +/** + * A class for accessing once loaded parameters of Authentication API object. + */ +class CAuthenticationHelper extends CConfigGeneralHelper { + + public const AUTHENTICATION_TYPE = 'authentication_type'; + public const HTTP_AUTH_ENABLED = 'http_auth_enabled'; + public const HTTP_CASE_SENSITIVE = 'http_case_sensitive'; + public const HTTP_LOGIN_FORM = 'http_login_form'; + public const HTTP_STRIP_DOMAINS = 'http_strip_domains'; + public const LDAP_BASE_DN = 'ldap_base_dn'; + public const LDAP_BIND_DN = 'ldap_bind_dn'; + public const LDAP_BIND_PASSWORD = 'ldap_bind_password'; + public const LDAP_CASE_SENSITIVE = 'ldap_case_sensitive'; + public const LDAP_CONFIGURED = 'ldap_configured'; + public const LDAP_HOST = 'ldap_host'; + public const LDAP_PORT = 'ldap_port'; + public const LDAP_SEARCH_ATTRIBUTE = 'ldap_search_attribute'; + public const SAML_AUTH_ENABLED = 'saml_auth_enabled'; + public const SAML_CASE_SENSITIVE = 'saml_case_sensitive'; + public const SAML_ENCRYPT_ASSERTIONS = 'saml_encrypt_assertions'; + public const SAML_ENCRYPT_NAMEID = 'saml_encrypt_nameid'; + public const SAML_IDP_ENTITYID = 'saml_idp_entityid'; + public const SAML_NAMEID_FORMAT = 'saml_nameid_format'; + public const SAML_SIGN_ASSERTIONS = 'saml_sign_assertions'; + public const SAML_SIGN_AUTHN_REQUESTS = 'saml_sign_authn_requests'; + public const SAML_SIGN_LOGOUT_REQUESTS = 'saml_sign_logout_requests'; + public const SAML_SIGN_LOGOUT_RESPONSES = 'saml_sign_logout_responses'; + public const SAML_SIGN_MESSAGES = 'saml_sign_messages'; + public const SAML_SLO_URL = 'saml_slo_url'; + public const SAML_SP_ENTITYID = 'saml_sp_entityid'; + public const SAML_SSO_URL = 'saml_sso_url'; + public const SAML_USERNAME_ATTRIBUTE = 'saml_username_attribute'; + + /** + * Authentication API object parameters array. + * + * @static + * + * @var array + */ + protected static $params = []; + + /** + * @inheritdoc + */ + protected static function loadParams(?string $param = null, bool $is_global = false): void { + if (!self::$params) { + self::$params = API::Authentication()->get(['output' => 'extend']); + + if (self::$params === false) { + throw new Exception(_('Unable to load authentication API parameters.')); + } + } + } +} diff --git a/ui/include/classes/helpers/CConfigGeneralHelper.php b/ui/include/classes/helpers/CConfigGeneralHelper.php new file mode 100644 index 00000000000..53a3668e54d --- /dev/null +++ b/ui/include/classes/helpers/CConfigGeneralHelper.php @@ -0,0 +1,80 @@ +<?php declare(strict_types = 1); +/* +** Zabbix +** Copyright (C) 2001-2020 Zabbix SIA +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +**/ + + +/** + * Class containing methods for accessing once loaded parameters of API object designed to work with 'config' table. + */ +abstract class CConfigGeneralHelper { + + /** + * Load once all parameters of API object. + * + * @static + * + * @param string|null $param API object parameter name. + * @param bool $is_global Set to "true" to allow parameters loading via getglobal API method. + */ + abstract protected static function loadParams(?string $param = null, bool $is_global = false): void; + + /** + * Get value by parameter name of API object (load parameters if need). + * + * @static + * + * @param string $name API object parameter name. + * + * @return string|null Parameter value. If parameter not exists, return null. + */ + public static function get(string $name): ?string { + static::loadParams($name, false); + + return array_key_exists($name, static::$params) ? static::$params[$name] : null; + } + + /** + * Get values of all parameters of API object (load parameters if need). + * + * @static + * + * @return array String array with all values of API object parameters in format <parameter name> => <value>. + */ + public static function getAll(): array { + static::loadParams(); + + return static::$params; + } + + /** + * Set value by parameter name of API object into $params (load parameters if need). + * + * @static + * + * @param string $name API object parameter name. + * @param string $value API object parameter value. + */ + public static function set(string $name, string $value): void { + static::loadParams($name, false); + + if (array_key_exists($name, static::$params)) { + static::$params[$name] = $value; + } + } +} diff --git a/ui/include/classes/helpers/CHousekeepingHelper.php b/ui/include/classes/helpers/CHousekeepingHelper.php new file mode 100644 index 00000000000..4518f79742e --- /dev/null +++ b/ui/include/classes/helpers/CHousekeepingHelper.php @@ -0,0 +1,70 @@ +<?php declare(strict_types = 1); +/* +** Zabbix +** Copyright (C) 2001-2020 Zabbix SIA +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +**/ + + +/** + * A class for accessing once loaded parameters of Housekeeping API object. + */ +class CHousekeepingHelper extends CConfigGeneralHelper { + + public const COMPRESS_OLDER = 'compress_older'; + public const COMPRESSION_AVAILABILITY = 'compression_availability'; + public const COMPRESSION_STATUS = 'compression_status'; + public const DB_EXTENSION = 'db_extension'; + public const HK_AUDIT = 'hk_audit'; + public const HK_AUDIT_MODE = 'hk_audit_mode'; + public const HK_EVENTS_AUTOREG = 'hk_events_autoreg'; + public const HK_EVENTS_DISCOVERY = 'hk_events_discovery'; + public const HK_EVENTS_INTERNAL = 'hk_events_internal'; + public const HK_EVENTS_MODE = 'hk_events_mode'; + public const HK_EVENTS_TRIGGER = 'hk_events_trigger'; + public const HK_HISTORY = 'hk_history'; + public const HK_HISTORY_GLOBAL = 'hk_history_global'; + public const HK_HISTORY_MODE = 'hk_history_mode'; + public const HK_SERVICES = 'hk_services'; + public const HK_SERVICES_MODE = 'hk_services_mode'; + public const HK_SESSIONS = 'hk_sessions'; + public const HK_SESSIONS_MODE = 'hk_sessions_mode'; + public const HK_TRENDS = 'hk_trends'; + public const HK_TRENDS_GLOBAL = 'hk_trends_global'; + public const HK_TRENDS_MODE = 'hk_trends_mode'; + + /** + * Housekeeping API object parameters array. + * + * @static + * + * @var array + */ + protected static $params = []; + + /** + * @inheritdoc + */ + protected static function loadParams(?string $param = null, bool $is_global = false): void { + if (!self::$params) { + self::$params = API::Housekeeping()->get(['output' => 'extend']); + + if (self::$params === false) { + throw new Exception(_('Unable to load housekeeping API parameters.')); + } + } + } +} diff --git a/ui/include/classes/helpers/CPagerHelper.php b/ui/include/classes/helpers/CPagerHelper.php index 7b9bd8489c9..650a8ccfa48 100644 --- a/ui/include/classes/helpers/CPagerHelper.php +++ b/ui/include/classes/helpers/CPagerHelper.php @@ -103,14 +103,13 @@ class CPagerHelper { */ protected static function prepareData($page, $num_rows) { $rows_per_page = (int) CWebUser::$data['rows_per_page']; - $config = select_config(); $offset_down = 0; - $limit_exceeded = ($num_rows > $config['search_limit']); + $limit_exceeded = ($num_rows > CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT)); if ($limit_exceeded) { - $offset_down = $num_rows - $config['search_limit']; - $num_rows = $config['search_limit']; + $offset_down = $num_rows - CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT); + $num_rows = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT); } $num_pages = max(1, (int) ceil($num_rows / $rows_per_page)); diff --git a/ui/include/classes/helpers/CSettingsHelper.php b/ui/include/classes/helpers/CSettingsHelper.php new file mode 100644 index 00000000000..27a55fce3a9 --- /dev/null +++ b/ui/include/classes/helpers/CSettingsHelper.php @@ -0,0 +1,121 @@ +<?php declare(strict_types = 1); +/* +** Zabbix +** Copyright (C) 2001-2020 Zabbix SIA +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation; either version 2 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +**/ + + +/** + * A class for accessing once loaded parameters of Settings API object. + */ +class CSettingsHelper extends CConfigGeneralHelper { + + public const ALERT_USRGRPID = 'alert_usrgrpid'; + public const BLINK_PERIOD = 'blink_period'; + public const CONNECT_TIMEOUT = 'connect_timeout'; + public const CUSTOM_COLOR = 'custom_color'; + public const DEFAULT_INVENTORY_MODE = 'default_inventory_mode'; + public const DEFAULT_LANG = 'default_lang'; + public const DEFAULT_THEME = 'default_theme'; + public const DEFAULT_TIMEZONE = 'default_timezone'; + public const DISCOVERY_GROUPID = 'discovery_groupid'; + public const HISTORY_PERIOD = 'history_period'; + public const IFRAME_SANDBOXING_ENABLED = 'iframe_sandboxing_enabled'; + public const IFRAME_SANDBOXING_EXCEPTIONS = 'iframe_sandboxing_exceptions'; + public const ITEM_TEST_TIMEOUT = 'item_test_timeout'; + public const LOGIN_ATTEMPTS = 'login_attempts'; + public const LOGIN_BLOCK = 'login_block'; + public const MAX_IN_TABLE = 'max_in_table'; + public const MAX_PERIOD = 'max_period'; + public const MAX_OVERVIEW_TABLE_SIZE = 'max_overview_table_size'; + public const MEDIA_TYPE_TEST_TIMEOUT = 'media_type_test_timeout'; + public const OK_ACK_COLOR = 'ok_ack_color'; + public const OK_ACK_STYLE = 'ok_ack_style'; + public const OK_PERIOD = 'ok_period'; + public const OK_UNACK_COLOR = 'ok_unack_color'; + public const OK_UNACK_STYLE = 'ok_unack_style'; + public const PERIOD_DEFAULT = 'period_default'; + public const PROBLEM_ACK_COLOR = 'problem_ack_color'; + public const PROBLEM_ACK_STYLE = 'problem_ack_style'; + public const PROBLEM_UNACK_COLOR = 'problem_unack_color'; + public const PROBLEM_UNACK_STYLE = 'problem_unack_style'; + public const REFRESH_UNSUPPORTED = 'refresh_unsupported'; + public const SCRIPT_TIMEOUT = 'script_timeout'; + public const SEARCH_LIMIT = 'search_limit'; + public const SERVER_CHECK_INTERVAL = 'server_check_interval'; + public const SEVERITY_COLOR_0 = 'severity_color_0'; + public const SEVERITY_COLOR_1 = 'severity_color_1'; + public const SEVERITY_COLOR_2 = 'severity_color_2'; + public const SEVERITY_COLOR_3 = 'severity_color_3'; + public const SEVERITY_COLOR_4 = 'severity_color_4'; + public const SEVERITY_COLOR_5 = 'severity_color_5'; + public const SEVERITY_NAME_0 = 'severity_name_0'; + public const SEVERITY_NAME_1 = 'severity_name_1'; + public const SEVERITY_NAME_2 = 'severity_name_2'; + public const SEVERITY_NAME_3 = 'severity_name_3'; + public const SEVERITY_NAME_4 = 'severity_name_4'; + public const SEVERITY_NAME_5 = 'severity_name_5'; + public const SHOW_TECHNICAL_ERRORS = 'show_technical_errors'; + public const SNMPTRAP_LOGGING = 'snmptrap_logging'; + public const SOCKET_TIMEOUT = 'socket_timeout'; + public const URI_VALID_SCHEMES = 'uri_valid_schemes'; + public const VALIDATE_URI_SCHEMES = 'validate_uri_schemes'; + public const WORK_PERIOD = 'work_period'; + public const X_FRAME_OPTIONS = 'x_frame_options'; + + /** + * Settings API object parameters array. + * + * @static + * + * @var array + */ + protected static $params = []; + + /** + * @inheritdoc + */ + protected static function loadParams(?string $param = null, bool $is_global = false): void { + if (!self::$params) { + self::$params = $is_global + ? API::Settings()->getGlobal(['output' => 'extend']) + : API::Settings()->get(['output' => 'extend']); + } + else if (!$is_global && $param && !array_key_exists($param, self::$params)) { + self::$params = API::Settings()->get(['output' => 'extend']); + } + + if (self::$params === false) { + throw new Exception(_('Unable to load settings API parameters.')); + } + } + + /** + * Get value by global parameter name of API object (load parameters if need). + * + * @static + * + * @param string $name API object global parameter name. + * + * @return string|null Parameter value. If parameter not exists, return null. + */ + public static function getGlobal(string $name): ?string { + self::loadParams($name, true); + + return array_key_exists($name, self::$params) ? self::$params[$name] : null; + } +} diff --git a/ui/include/classes/helpers/CSvgGraphHelper.php b/ui/include/classes/helpers/CSvgGraphHelper.php index 226da6ca1e2..9bfdcee3f14 100644 --- a/ui/include/classes/helpers/CSvgGraphHelper.php +++ b/ui/include/classes/helpers/CSvgGraphHelper.php @@ -338,12 +338,11 @@ class CSvgGraphHelper { * * Do the same with trends. */ - $config = select_config(); $to_resolve = []; - if ($config['hk_history_global']) { + if (CHousekeepingHelper::get(CHousekeepingHelper::HK_HISTORY_GLOBAL)) { foreach ($metrics as &$metric) { - $metric['history'] = timeUnitToSeconds($config['hk_history']); + $metric['history'] = timeUnitToSeconds(CHousekeepingHelper::get(CHousekeepingHelper::HK_HISTORY)); } unset($metric); } @@ -351,9 +350,9 @@ class CSvgGraphHelper { $to_resolve[] = 'history'; } - if ($config['hk_trends_global']) { + if (CHousekeepingHelper::get(CHousekeepingHelper::HK_TRENDS_GLOBAL)) { foreach ($metrics as &$metric) { - $metric['trends'] = timeUnitToSeconds($config['hk_trends']); + $metric['trends'] = timeUnitToSeconds(CHousekeepingHelper::get(CHousekeepingHelper::HK_TRENDS)); } unset($metric); } @@ -368,7 +367,7 @@ class CSvgGraphHelper { foreach ($metrics as $num => &$metric) { // Convert its values to seconds. - if (!$config['hk_history_global']) { + if (!CHousekeepingHelper::get(CHousekeepingHelper::HK_HISTORY_GLOBAL)) { if ($simple_interval_parser->parse($metric['history']) != CParser::PARSE_SUCCESS) { $errors[] = _s('Incorrect value for field "%1$s": %2$s.', 'history', _('invalid history storage period') @@ -380,7 +379,7 @@ class CSvgGraphHelper { } } - if (!$config['hk_trends_global']) { + if (!CHousekeepingHelper::get(CHousekeepingHelper::HK_TRENDS_GLOBAL)) { if ($simple_interval_parser->parse($metric['trends']) != CParser::PARSE_SUCCESS) { $errors[] = _s('Incorrect value for field "%1$s": %2$s.', 'trends', _('invalid trend storage period') diff --git a/ui/include/classes/html/CTriggersInfo.php b/ui/include/classes/html/CTriggersInfo.php index 072dfd51a46..1cba05c7773 100644 --- a/ui/include/classes/html/CTriggersInfo.php +++ b/ui/include/classes/html/CTriggersInfo.php @@ -39,8 +39,6 @@ class CTriggersInfo extends CTable { protected function bodyToString() { $this->cleanItems(); - $config = select_config(); - // array of triggers (not classified, information, warning, average, high, disaster) in problem state $triggersProblemState = []; @@ -73,14 +71,13 @@ class CTriggersInfo extends CTable { } } - $severityCells = [getSeverityCell(null, $config, $triggersOkState.SPACE._('Ok'), true)]; + $severityCells = [getSeverityCell(null, $triggersOkState.SPACE._('Ok'), true)]; for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_COUNT; $severity++) { $severityCount = isset($triggersProblemState[$severity]) ? $triggersProblemState[$severity] : 0; $severityCells[] = getSeverityCell($severity, - $config, - $severityCount.SPACE.getSeverityName($severity, $config), + $severityCount.SPACE.getSeverityName($severity), !$severityCount ); } diff --git a/ui/include/classes/macros/CMacrosResolverGeneral.php b/ui/include/classes/macros/CMacrosResolverGeneral.php index 1049bd20c9d..e63258f0e6b 100644 --- a/ui/include/classes/macros/CMacrosResolverGeneral.php +++ b/ui/include/classes/macros/CMacrosResolverGeneral.php @@ -782,7 +782,9 @@ class CMacrosResolverGeneral { // break; is not missing here case 'ITEM.LASTVALUE': - $history = Manager::History()->getLastValues([$function], 1, ZBX_HISTORY_PERIOD); + $history = Manager::History()->getLastValues([$function], 1, timeUnitToSeconds( + CSettingsHelper::get(CSettingsHelper::HISTORY_PERIOD) + )); if (array_key_exists($function['itemid'], $history)) { $clock = $history[$function['itemid']][0]['clock']; diff --git a/ui/include/classes/mvc/CController.php b/ui/include/classes/mvc/CController.php index bba39eac638..61852060bae 100644 --- a/ui/include/classes/mvc/CController.php +++ b/ui/include/classes/mvc/CController.php @@ -188,14 +188,21 @@ abstract class CController { } $ts = []; + $ts['now'] = time(); $range_time_parser = new CRangeTimeParser(); foreach (['from', 'to'] as $field) { $range_time_parser->parse($this->getInput($field)); - $ts[$field] = $range_time_parser->getDateTime($field === 'from')->getTimestamp(); + $ts[$field] = $range_time_parser + ->getDateTime($field === 'from') + ->getTimestamp(); } $period = $ts['to'] - $ts['from'] + 1; + $range_time_parser->parse('now-'.CSettingsHelper::get(CSettingsHelper::MAX_PERIOD)); + $max_period = 1 + $ts['now'] - $range_time_parser + ->getDateTime(true) + ->getTimestamp(); if ($period < ZBX_MIN_PERIOD) { info(_n('Minimum time period to display is %1$s minute.', @@ -204,9 +211,9 @@ abstract class CController { return false; } - elseif ($period > ZBX_MAX_PERIOD) { + elseif ($period > $max_period) { info(_n('Maximum time period to display is %1$s day.', - 'Maximum time period to display is %1$s days.', (int) (ZBX_MAX_PERIOD / SEC_PER_DAY) + 'Maximum time period to display is %1$s days.', (int) ($max_period / SEC_PER_DAY) )); return false; diff --git a/ui/include/classes/mvc/CRouter.php b/ui/include/classes/mvc/CRouter.php index 4063230b573..ad901204013 100644 --- a/ui/include/classes/mvc/CRouter.php +++ b/ui/include/classes/mvc/CRouter.php @@ -185,11 +185,7 @@ class CRouter { 'system.warning' => ['CControllerSystemWarning', 'layout.warning', 'system.warning'], 'timeselector.update' => ['CControllerTimeSelectorUpdate', 'layout.json', null], 'trigdisplay.edit' => ['CControllerTrigDisplayEdit', 'layout.htmlpage', 'administration.trigdisplay.edit'], - 'trigdisplay.reset' => ['CControllerTrigDisplayReset', null, null], 'trigdisplay.update' => ['CControllerTrigDisplayUpdate', null, null], - 'trigseverity.edit' => ['CControllerTrigSeverityEdit', 'layout.htmlpage', 'administration.trigseverity.edit'], - 'trigseverity.reset' => ['CControllerTrigSeverityReset', null, null], - 'trigseverity.update' => ['CControllerTrigSeverityUpdate', null, null], 'user.create' => ['CControllerUserCreate', null, null], 'user.delete' => ['CControllerUserDelete', null, null], 'user.edit' => ['CControllerUserEdit', 'layout.htmlpage', 'administration.user.edit'], @@ -235,8 +231,6 @@ class CRouter { 'widget.trigover.view' => ['CControllerWidgetTrigOverView', 'layout.widget', 'monitoring.widget.trigover.view'], 'widget.url.view' => ['CControllerWidgetUrlView', 'layout.widget', 'monitoring.widget.url.view'], 'widget.web.view' => ['CControllerWidgetWebView', 'layout.widget', 'monitoring.widget.web.view'], - 'workingtime.edit' => ['CControllerWorkingTimeEdit', 'layout.htmlpage', 'administration.workingtime.edit'], - 'workingtime.update' => ['CControllerWorkingTimeUpdate', null, null], // legacy actions 'actionconf.php' => ['CLegacyAction', null, null], diff --git a/ui/include/classes/parsers/CValidationRule.php b/ui/include/classes/parsers/CValidationRule.php index 33a2f67c42b..1a59509b13a 100644 --- a/ui/include/classes/parsers/CValidationRule.php +++ b/ui/include/classes/parsers/CValidationRule.php @@ -56,9 +56,10 @@ class CValidationRule { $is_empty = false; $rule = []; - if (!$this->parseString($buffer, $pos, $rule) // string + if (!$this->parseString($buffer, $pos, $rule) // string && !$this->parseRangeTime($buffer, $pos, $rule) // range time && !$this->parseTimePeriods($buffer, $pos, $rule) // time periods + && !$this->parseTimeUnit($buffer, $pos, $rule) // time unit && !$this->parseRgb($buffer, $pos, $rule) // rgb && !$this->parseRequired($buffer, $pos, $rule) // required && !$this->parseNotEmpty($buffer, $pos, $rule) // not_empty @@ -190,6 +191,62 @@ class CValidationRule { } /** + * time_unit + * + * 'time_unit' => ['<value1>', ..., '<valueN>'] + */ + private function parseTimeUnit($buffer, &$pos, &$rules): bool { + $TIME_UNIT_LENGTH = mb_strlen('time_unit'); + $TIME_UNIT_YEAR_LENGTH = mb_strlen('time_unit_year'); + + $values = []; + $ranges_string = ''; + $ranges = []; + + if (strncmp(substr($buffer, $pos), 'time_unit_year', $TIME_UNIT_YEAR_LENGTH) === 0) { + $pos += $TIME_UNIT_YEAR_LENGTH; + $values['with_year'] = true; + } + else if (strncmp(substr($buffer, $pos), 'time_unit', $TIME_UNIT_LENGTH) === 0) { + $pos += $TIME_UNIT_LENGTH; + } + else { + return false; + } + + while (isset($buffer[$pos]) && $buffer[$pos] === ' ') { + $pos++; + } + + while (isset($buffer[$pos]) && $buffer[$pos] !== '|') { + $ranges_string .= $buffer[$pos]; + $pos++; + } + + foreach (explode(',', $ranges_string) as $range_string) { + if (strpos($range_string, ':') !== false) { + [$from, $to] = explode(':', $range_string); + } + else { + $from = $range_string; + $to = $range_string; + } + + if (ctype_digit($from) && ctype_digit($to)) { + $ranges[] = ['from' => $from, 'to' => $to]; + } + } + + if ($ranges) { + $values['ranges'] = $ranges; + } + + $rules['time_unit'] = $values; + + return true; + } + + /** * rgb * * 'rgb' => true diff --git a/ui/include/classes/screens/CScreenEvents.php b/ui/include/classes/screens/CScreenEvents.php index 9cdecf7aed8..1f686fdb0d6 100644 --- a/ui/include/classes/screens/CScreenEvents.php +++ b/ui/include/classes/screens/CScreenEvents.php @@ -27,8 +27,6 @@ class CScreenEvents extends CScreenBase { * @return CDiv (screen inside container) */ public function get() { - $config = select_config(); - $table = (new CTableInfo())->setHeader([_('Time'), _('Recovery time'), _('Host'), _('Description'), _('Value'), _('Severity') ]); @@ -136,7 +134,7 @@ class CScreenEvents extends CScreenBase { 'tr_events.php?triggerid='.$event['objectid'].'&eventid='.$event['eventid'] ), $statusSpan, - getSeverityCell($event['severity'], $config) + getSeverityCell($event['severity']) ]); } diff --git a/ui/include/classes/screens/CScreenGraph.php b/ui/include/classes/screens/CScreenGraph.php index 68f7dd8dbb4..2d49166c853 100644 --- a/ui/include/classes/screens/CScreenGraph.php +++ b/ui/include/classes/screens/CScreenGraph.php @@ -170,8 +170,8 @@ class CScreenGraph extends CScreenBase { if ($this->mode == SCREEN_MODE_EDIT) { $src - ->setArgument('from', ZBX_PERIOD_DEFAULT_FROM) - ->setArgument('to', ZBX_PERIOD_DEFAULT_TO); + ->setArgument('from', 'now-'.CSettingsHelper::get(CSettingsHelper::PERIOD_DEFAULT)) + ->setArgument('to', 'now'); } else { $src diff --git a/ui/include/classes/screens/CScreenHistory.php b/ui/include/classes/screens/CScreenHistory.php index b1558ea4a9e..12de6ae3681 100644 --- a/ui/include/classes/screens/CScreenHistory.php +++ b/ui/include/classes/screens/CScreenHistory.php @@ -159,12 +159,10 @@ class CScreenHistory extends CScreenBase { $options['limit'] = 500; } else { - $config = select_config(); - $options += [ 'time_from' => $this->timeline['from_ts'], 'time_till' => $this->timeline['to_ts'], - 'limit' => $config['search_limit'] + 'limit' => CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) ]; } diff --git a/ui/include/classes/screens/CScreenHostTriggers.php b/ui/include/classes/screens/CScreenHostTriggers.php index f0018a11431..4ac62a0ede6 100644 --- a/ui/include/classes/screens/CScreenHostTriggers.php +++ b/ui/include/classes/screens/CScreenHostTriggers.php @@ -160,8 +160,6 @@ class CScreenHostTriggers extends CScreenBase { * @param string $filter['sortorder'] Sort order. */ protected function getProblemsListTable(array $filter) { - $config = select_config(); - // If no hostids and groupids defined show recent problems. if ($filter['hostids'] === null && $filter['groupids'] === null) { $filter['show'] = TRIGGERS_OPTION_RECENT_PROBLEM; @@ -176,7 +174,7 @@ class CScreenHostTriggers extends CScreenBase { 'sort_order' => ZBX_SORT_DOWN ]; - $data = CScreenProblem::getData($filter, $config, true, true); + $data = CScreenProblem::getData($filter, true, true); $header = [ 'hostname' => _('Host'), @@ -193,16 +191,13 @@ class CScreenHostTriggers extends CScreenBase { (new CDiv())->addClass(($sort_order === ZBX_SORT_DOWN) ? ZBX_STYLE_ARROW_DOWN : ZBX_STYLE_ARROW_UP) ]; - $data = CScreenProblem::sortData($data, $config, $sort_field === 'hostname' ? 'host' : $sort_field, + $data = CScreenProblem::sortData($data, $sort_field === 'hostname' ? 'host' : $sort_field, $sort_order ); } - $info = _n('%1$d of %3$d%2$s problem is shown', '%1$d of %3$d%2$s problems are shown', - min($filter['limit'], count($data['problems'])), - (count($data['problems']) > $config['search_limit']) ? '+' : '', - min($config['search_limit'], count($data['problems'])) - ); + $search_limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT); + $info = _n('%1$d of %3$d%2$s problem is shown', '%1$d of %3$d%2$s problems are shown', min($filter['limit'], count($data['problems'])), (count($data['problems']) > $search_limit) ? '+' : '', min($search_limit, count($data['problems']))); $data['problems'] = array_slice($data['problems'], 0, $filter['limit'], true); $data = CScreenProblem::makeData($data, $filter, true, true); @@ -275,9 +270,7 @@ class CScreenHostTriggers extends CScreenBase { zbx_date2age($problem['clock']), makeInformationList($info_icons), $problem_update_link, - makeEventActionsIcons($problem['eventid'], $data['actions'], $data['mediatypes'], $data['users'], - $config - ) + makeEventActionsIcons($problem['eventid'], $data['actions'], $data['mediatypes'], $data['users']) ]); } diff --git a/ui/include/classes/screens/CScreenHttpTest.php b/ui/include/classes/screens/CScreenHttpTest.php index 7ad6397b539..62c1b2849d0 100644 --- a/ui/include/classes/screens/CScreenHttpTest.php +++ b/ui/include/classes/screens/CScreenHttpTest.php @@ -56,8 +56,6 @@ class CScreenHttpTest extends CScreenBase { $httptests = []; $paging = []; - $config = select_config(); - $options = [ 'output' => ['httptestid', 'name', 'hostid'], 'selectHosts' => ['name', 'status'], @@ -65,7 +63,7 @@ class CScreenHttpTest extends CScreenBase { 'templated' => false, 'preservekeys' => true, 'filter' => ['status' => HTTPTEST_STATUS_ACTIVE], - 'limit' => $config['search_limit'] + 1 + 'limit' => CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1 ]; $options['hostids'] = $this->data['hostids'] ? $this->data['hostids'] : null; diff --git a/ui/include/classes/screens/CScreenProblem.php b/ui/include/classes/screens/CScreenProblem.php index e4a56d8f02d..020ded23c1a 100644 --- a/ui/include/classes/screens/CScreenProblem.php +++ b/ui/include/classes/screens/CScreenProblem.php @@ -32,11 +32,6 @@ class CScreenProblem extends CScreenBase { public $data; /** - * @var array - */ - private $config; - - /** * Init screen data. * * @param array $options @@ -50,24 +45,6 @@ class CScreenProblem extends CScreenBase { $this->data['filter']['from'] = $this->timeline['from_ts']; $this->data['filter']['to'] = $this->timeline['to_ts']; } - - $config = select_config(); - - $this->config = [ - 'search_limit' => $config['search_limit'], - 'severity_color_0' => $config['severity_color_0'], - 'severity_color_1' => $config['severity_color_1'], - 'severity_color_2' => $config['severity_color_2'], - 'severity_color_3' => $config['severity_color_3'], - 'severity_color_4' => $config['severity_color_4'], - 'severity_color_5' => $config['severity_color_5'], - 'severity_name_0' => $config['severity_name_0'], - 'severity_name_1' => $config['severity_name_1'], - 'severity_name_2' => $config['severity_name_2'], - 'severity_name_3' => $config['severity_name_3'], - 'severity_name_4' => $config['severity_name_4'], - 'severity_name_5' => $config['severity_name_5'] - ]; } /** @@ -166,8 +143,6 @@ class CScreenProblem extends CScreenBase { * @param string $filter['tags'][]['value'] * @param int $filter['show_suppressed'] (optional) * @param int $filter['show_opdata'] (optional) - * @param array $config - * @param int $config['search_limit'] * @param bool $resolve_comments * @param bool $resolve_urls * @@ -175,7 +150,7 @@ class CScreenProblem extends CScreenBase { * * @return array */ - public static function getData(array $filter, array $config, $resolve_comments = false, $resolve_urls = false) { + public static function getData(array $filter, $resolve_comments = false, $resolve_urls = false) { $filter_groupids = array_key_exists('groupids', $filter) && $filter['groupids'] ? $filter['groupids'] : null; $filter_hostids = array_key_exists('hostids', $filter) && $filter['hostids'] ? $filter['hostids'] : null; $filter_applicationids = null; @@ -257,7 +232,7 @@ class CScreenProblem extends CScreenBase { 'objectids' => $filter_triggerids, 'eventid_till' => $eventid_till, 'suppressed' => false, - 'limit' => $config['search_limit'] + 1 + 'limit' => CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1 ]; if (array_key_exists('name', $filter) && $filter['name'] !== '') { @@ -303,7 +278,7 @@ class CScreenProblem extends CScreenBase { ? self::getDataEvents($options) : self::getDataProblems($options); - $end_of_data = (count($problems) < $config['search_limit'] + 1); + $end_of_data = (count($problems) < CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1); if ($problems) { $eventid_till = end($problems)['eventid'] - 1; @@ -370,9 +345,11 @@ class CScreenProblem extends CScreenBase { $data['problems'] += $problems; } } - while (count($data['problems']) < $config['search_limit'] + 1 && !$end_of_data); + while (count($data['problems']) < CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1 && !$end_of_data); - $data['problems'] = array_slice($data['problems'], 0, $config['search_limit'] + 1, true); + $data['problems'] = array_slice($data['problems'], 0, CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1, + true + ); return $data; } @@ -422,8 +399,6 @@ class CScreenProblem extends CScreenBase { * @param array $data * @param array $data['problems'] * @param array $data['triggers'] - * @param array $config - * @param int $config['search_limit'] * @param string $sort * @param string $sortorder * @@ -431,13 +406,15 @@ class CScreenProblem extends CScreenBase { * * @return array */ - public static function sortData(array $data, array $config, $sort, $sortorder) { + public static function sortData(array $data, $sort, $sortorder) { if (!$data['problems']) { return $data; } $last_problem = end($data['problems']); - $data['problems'] = array_slice($data['problems'], 0, $config['search_limit'], true); + $data['problems'] = array_slice($data['problems'], 0, CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT), + true + ); switch ($sort) { case 'host': @@ -782,8 +759,8 @@ class CScreenProblem extends CScreenBase { $url = (new CUrl('zabbix.php'))->setArgument('action', 'problem.view'); - $data = self::getData($this->data['filter'], $this->config, true); - $data = self::sortData($data, $this->config, $this->data['sort'], $this->data['sortorder']); + $data = self::getData($this->data['filter'], true); + $data = self::sortData($data, $this->data['sort'], $this->data['sortorder']); if ($this->data['action'] === 'problem.view') { $paging = CPagerHelper::paginate($this->page, $data['problems'], ZBX_SORT_UP, $url); @@ -1118,7 +1095,7 @@ class CScreenProblem extends CScreenBase { // Add table row. $table->addRow(array_merge($row, [ new CCheckBox('eventids['.$problem['eventid'].']', $problem['eventid']), - getSeverityCell($problem['severity'], $this->config, null, $value == TRIGGER_VALUE_FALSE), + getSeverityCell($problem['severity'], null, $value == TRIGGER_VALUE_FALSE), $show_recovery_data ? $cell_r_clock : null, $show_recovery_data ? $cell_status : null, $cell_info, @@ -1133,9 +1110,7 @@ class CScreenProblem extends CScreenBase { ? zbx_date2age($problem['clock'], $problem['r_clock']) : zbx_date2age($problem['clock']), $problem_update_link, - makeEventActionsIcons($problem['eventid'], $data['actions'], $data['mediatypes'], $data['users'], - $this->config - ), + makeEventActionsIcons($problem['eventid'], $data['actions'], $data['mediatypes'], $data['users']), $this->data['filter']['show_tags'] ? $tags[$problem['eventid']] : null ]), ($this->data['filter']['highlight_row'] && $value == TRIGGER_VALUE_TRUE) ? getSeverityFlhStyle($problem['severity']) @@ -1154,7 +1129,7 @@ class CScreenProblem extends CScreenBase { * Search limit performs +1 selection to know if limit was exceeded, this will assure that csv has * "search_limit" records at most. */ - array_splice($data['problems'], $this->config['search_limit']); + array_splice($data['problems'], CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT)); $csv = []; @@ -1234,7 +1209,7 @@ class CScreenProblem extends CScreenBase { $row = []; - $row[] = getSeverityName($problem['severity'], $this->config); + $row[] = getSeverityName($problem['severity']); $row[] = zbx_date2str(DATE_TIME_FORMAT_SECONDS, $problem['clock']); $row[] = ($problem['r_eventid'] != 0) ? zbx_date2str(DATE_TIME_FORMAT_SECONDS, $problem['r_clock']) : ''; $row[] = $value_str; @@ -1274,7 +1249,9 @@ class CScreenProblem extends CScreenBase { $latest_values = []; $items = zbx_toHash($items, 'itemid'); - $history_values = Manager::History()->getLastValues($items, 1, ZBX_HISTORY_PERIOD); + $history_values = Manager::History()->getLastValues($items, 1, timeUnitToSeconds(CSettingsHelper::get( + CSettingsHelper::HISTORY_PERIOD + ))); if ($html) { $hint_table = (new CTable())->addClass('list-table'); diff --git a/ui/include/classes/screens/CScreenSimpleGraph.php b/ui/include/classes/screens/CScreenSimpleGraph.php index 389b0dcc558..9a6e197926f 100644 --- a/ui/include/classes/screens/CScreenSimpleGraph.php +++ b/ui/include/classes/screens/CScreenSimpleGraph.php @@ -77,8 +77,8 @@ class CScreenSimpleGraph extends CScreenBase { if ($this->mode == SCREEN_MODE_EDIT) { $src - ->setArgument('from', ZBX_PERIOD_DEFAULT_FROM) - ->setArgument('to', ZBX_PERIOD_DEFAULT_TO); + ->setArgument('from', 'now-'.CSettingsHelper::get(CSettingsHelper::PERIOD_DEFAULT)) + ->setArgument('to', 'now'); } else { $src diff --git a/ui/include/classes/screens/CScreenSystemStatus.php b/ui/include/classes/screens/CScreenSystemStatus.php index 6bfead82217..b69b1c2032c 100644 --- a/ui/include/classes/screens/CScreenSystemStatus.php +++ b/ui/include/classes/screens/CScreenSystemStatus.php @@ -34,17 +34,8 @@ class CScreenSystemStatus extends CScreenBase { // rewrite page file $page['file'] = $this->pageFile; - $config = select_config(); - $severity_config = [ - 'severity_name_0' => $config['severity_name_0'], - 'severity_name_1' => $config['severity_name_1'], - 'severity_name_2' => $config['severity_name_2'], - 'severity_name_3' => $config['severity_name_3'], - 'severity_name_4' => $config['severity_name_4'], - 'severity_name_5' => $config['severity_name_5'] - ]; $data = getSystemStatusData([]); - $table = makeSystemStatus([], $data, $severity_config, $this->pageFile.'?screenid='.$this->screenid); + $table = makeSystemStatus([], $data); $footer = (new CList()) ->addItem(_s('Updated: %1$s', zbx_date2str(TIME_FORMAT_SECONDS))) diff --git a/ui/include/classes/screens/CScreenUrl.php b/ui/include/classes/screens/CScreenUrl.php index 91aa8038d5d..7e5ce8a3882 100644 --- a/ui/include/classes/screens/CScreenUrl.php +++ b/ui/include/classes/screens/CScreenUrl.php @@ -58,8 +58,8 @@ class CScreenUrl extends CScreenBase { 'auto' ); - if (ZBX_IFRAME_SANDBOX !== false) { - $item->setAttribute('sandbox', ZBX_IFRAME_SANDBOX); + if (CSettingsHelper::get(CSettingsHelper::IFRAME_SANDBOXING_ENABLED) == 1) { + $item->setAttribute('sandbox', CSettingsHelper::get(CSettingsHelper::IFRAME_SANDBOXING_EXCEPTIONS)); } return $item; diff --git a/ui/include/classes/server/CZabbixServer.php b/ui/include/classes/server/CZabbixServer.php index da6d65b742b..81a78007593 100644 --- a/ui/include/classes/server/CZabbixServer.php +++ b/ui/include/classes/server/CZabbixServer.php @@ -527,7 +527,9 @@ class CZabbixServer { return false; } - if (!$socket = @fsockopen($this->host, $this->port, $errorCode, $errorMsg, ZBX_CONNECT_TIMEOUT)) { + if (!$socket = @fsockopen($this->host, $this->port, $errorCode, $errorMsg, + timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::CONNECT_TIMEOUT)) + )) { switch ($errorMsg) { case 'Connection refused': $dErrorMsg = _s("Connection to Zabbix server \"%1\$s\" refused. Possible reasons:\n1. Incorrect server IP/DNS in the \"zabbix.conf.php\";\n2. Security environment (for example, SELinux) is blocking the connection;\n3. Zabbix server daemon not running;\n4. Firewall is blocking TCP connection.\n", $this->host); diff --git a/ui/include/classes/tree/CServiceTree.php b/ui/include/classes/tree/CServiceTree.php index e16bd644628..55f2d94ed1a 100644 --- a/ui/include/classes/tree/CServiceTree.php +++ b/ui/include/classes/tree/CServiceTree.php @@ -35,8 +35,6 @@ class CServiceTree extends CTree { * @return CCol */ protected function makeCol($rowId, $colName) { - $config = select_config(); - switch ($colName) { case 'status': if (zbx_is_int($this->tree[$rowId][$colName]) && $this->tree[$rowId]['id'] > 0) { @@ -47,7 +45,7 @@ class CServiceTree extends CTree { return (new CCol(_('OK')))->addClass(ZBX_STYLE_GREEN); } else { - return (new CCol(getSeverityName($status, $config)))->addClass(getSeverityStyle($status)); + return (new CCol(getSeverityName($status)))->addClass(getSeverityStyle($status)); } } break; diff --git a/ui/include/classes/user/CWebUser.php b/ui/include/classes/user/CWebUser.php index a1f7961598e..a825dc5db28 100644 --- a/ui/include/classes/user/CWebUser.php +++ b/ui/include/classes/user/CWebUser.php @@ -184,11 +184,10 @@ class CWebUser { * @static */ public static function setDefault(): void { - $config = select_config(); self::$data = [ 'alias' => ZBX_GUEST_USER, 'userid' => 0, - 'lang' => $config['default_lang'], + 'lang' => CSettingsHelper::get(CSettingsHelper::DEFAULT_LANG), 'type' => 0, 'debug_mode' => false ]; diff --git a/ui/include/classes/validators/CApiInputValidator.php b/ui/include/classes/validators/CApiInputValidator.php index b35ca25c827..6446914a119 100644 --- a/ui/include/classes/validators/CApiInputValidator.php +++ b/ui/include/classes/validators/CApiInputValidator.php @@ -1573,7 +1573,7 @@ class CApiInputValidator { return true; } - $seconds = timeUnitToSeconds($data); + $seconds = timeUnitToSeconds($data, ($flags & API_TIME_UNIT_WITH_YEAR)); if ($seconds < ZBX_MIN_INT32 || $seconds > ZBX_MAX_INT32) { $error = _s('Invalid parameter "%1$s": %2$s.', $path, _('a number is too large')); diff --git a/ui/include/classes/validators/CHtmlUrlValidator.php b/ui/include/classes/validators/CHtmlUrlValidator.php index 80d6623ebfa..9a7642db33b 100644 --- a/ui/include/classes/validators/CHtmlUrlValidator.php +++ b/ui/include/classes/validators/CHtmlUrlValidator.php @@ -22,7 +22,7 @@ class CHtmlUrlValidator { /** - * URL is validated if schema validation is enabled (see VALIDATE_URI_SCHEMES). + * URL is validated if schema validation is enabled by CSettingsHelper::VALIDATE_URI_SCHEMES parameter. * * Relative URL should start with .php file name. * Absolute URL schema must match schemes mentioned in ZBX_URL_VALID_SCHEMES comma separated list. @@ -40,8 +40,8 @@ class CHtmlUrlValidator { * set to INVENTORY_URL_MACRO_HOST; * @param bool $options[allow_event_tags_macro] If set to be true, URLs containing {EVENT.TAGS.<ref>} macros will * be considered as valid. - * @param bool $options[validate_uri_schemes] Parameter allows to overwrite global switch VALIDATE_URI_SCHEMES - * for specific uses. + * @param bool $options[validate_uri_schemes] Parameter allows to overwrite global switch + * CSettingsHelper::VALIDATE_URI_SCHEMES for specific uses. * * @return bool */ @@ -50,7 +50,7 @@ class CHtmlUrlValidator { 'allow_user_macro' => true, 'allow_event_tags_macro' => false, 'allow_inventory_macro' => INVENTORY_URL_MACRO_NONE, - 'validate_uri_schemes' => VALIDATE_URI_SCHEMES + 'validate_uri_schemes' => (bool) CSettingsHelper::get(CSettingsHelper::VALIDATE_URI_SCHEMES) ]; if ($options['validate_uri_schemes'] === false) { @@ -96,7 +96,9 @@ class CHtmlUrlValidator { } if (array_key_exists('scheme', $url_parts)) { - if (!in_array(strtolower($url_parts['scheme']), explode(',', strtolower(ZBX_URI_VALID_SCHEMES)))) { + if (!in_array(strtolower($url_parts['scheme']), explode(',', strtolower(CSettingsHelper::get( + CSettingsHelper::URI_VALID_SCHEMES + ))))) { return false; } diff --git a/ui/include/classes/validators/CNewValidator.php b/ui/include/classes/validators/CNewValidator.php index 3ea006fdb31..1af8f44f455 100644 --- a/ui/include/classes/validators/CNewValidator.php +++ b/ui/include/classes/validators/CNewValidator.php @@ -211,7 +211,7 @@ class CNewValidator { if (!is_string($this->input[$field]) || !self::is_int32($this->input[$field]) || $this->input[$field] < $params) { $this->addError($fatal, - _s('Incorrect value "%1$s" for "%2$s" field.', $this->input[$field], $field) + _s('Incorrect value for field "%1$s": %2$s.', $field, _s('value must be no less than "%1$s"', $params)) ); return false; @@ -227,7 +227,7 @@ class CNewValidator { if (!is_string($this->input[$field]) || !self::is_int32($this->input[$field]) || $this->input[$field] > $params) { $this->addError($fatal, - _s('Incorrect value "%1$s" for "%2$s" field.', $this->input[$field], $field) + _s('Incorrect value for field "%1$s": %2$s.', $field, _s('value must be no greater than "%1$s"', $params)) ); return false; @@ -289,6 +289,21 @@ class CNewValidator { break; /* + * 'time_unit' => true + */ + case 'time_unit': + if (array_key_exists($field, $this->input)) { + $result = $this->isTimeUnit($this->input[$field], $params); + if (!$result['is_valid']) { + $this->addError($fatal, + _s('Incorrect value for field "%1$s": %2$s.', $field, $result['error']) + ); + return false; + } + } + break; + + /* * 'rgb' => true */ case 'rgb': @@ -451,6 +466,67 @@ class CNewValidator { return is_string($value) && $this->time_periods_parser->parse($value) == CParser::PARSE_SUCCESS; } + /** + * Validate a configuration value. Use simple interval parser to parse the string, convert to seconds and check + * if the value is in between given min and max values. In some cases it's possible to enter 0, or even 0s or 0d. + * If the value is incorrect, set an error. + * + * @param string $value Value to parse and validate. + * @param bool $options['with_year'] Set to "true" to allow month and year unit support. + * @param bool $options['allow_zero'] Set to "true" to allow value to be zero. + * @param string $options['min'] Lower bound. + * @param string $options['max'] Upper bound. + * + * @return array An array with parameter 'is_valid' containing validation result. If validation fails, additionally + * returned parameter 'error' containing error message. + */ + private function isTimeUnit($value, $params) { + $simple_interval_parser = new CSimpleIntervalParser( + array_key_exists('with_year', $params) ? ['with_year' => true] : [] + ); + $value = (string) $value; + + if ($simple_interval_parser->parse($value) == CParser::PARSE_SUCCESS) { + if (!$params) { + return ['is_valid' => true]; + } + + if ($value[0] !== '{') { + $value = timeUnitToSeconds($value, + array_key_exists('with_year', $params) ? $params['with_year'] : false + ); + + if (array_key_exists('ranges', $params)) { + $in_range = false; + $message_ranges = []; + + foreach ($params['ranges'] as $range) { + if ($range['from'] <= $value && $value <= $range['to']) { + $in_range = true; + break; + } + + $message_ranges[] = ($range['from'] == $range['to']) + ? $range['from'] + : $range['from'].'-'.$range['to']; + } + + if (!$in_range) { + return [ + 'is_valid' => false, + 'error' => _s('value must be one of %1$s', implode(', ', $message_ranges)) + ]; + } + } + } + } + else { + return ['is_valid' => false, 'error' => _('a time unit is expected')]; + } + + return ['is_valid' => true]; + } + private function isRangeTime($value) { if ($this->range_time_parser === null) { $this->range_time_parser = new CRangeTimeParser(); diff --git a/ui/include/classes/widgets/forms/CWidgetFormSvgGraph.php b/ui/include/classes/widgets/forms/CWidgetFormSvgGraph.php index bca9c985139..c05026b97e7 100644 --- a/ui/include/classes/widgets/forms/CWidgetFormSvgGraph.php +++ b/ui/include/classes/widgets/forms/CWidgetFormSvgGraph.php @@ -432,23 +432,30 @@ class CWidgetFormSvgGraph extends CWidgetForm { private static function validateTimeSelectorPeriod($from, $to) { $errors = []; $ts = []; + $ts['now'] = time(); $range_time_parser = new CRangeTimeParser(); foreach (['from' => $from, 'to' => $to] as $field => $value) { $range_time_parser->parse($value); - $ts[$field] = $range_time_parser->getDateTime($field === 'from')->getTimestamp(); + $ts[$field] = $range_time_parser + ->getDateTime($field === 'from') + ->getTimestamp(); } $period = $ts['to'] - $ts['from'] + 1; + $range_time_parser->parse('now-'.CSettingsHelper::get(CSettingsHelper::MAX_PERIOD)); + $max_period = 1 + $ts['now'] - $range_time_parser + ->getDateTime(true) + ->getTimestamp(); if ($period < ZBX_MIN_PERIOD) { $errors[] = _n('Minimum time period to display is %1$s minute.', 'Minimum time period to display is %1$s minutes.', (int) (ZBX_MIN_PERIOD / SEC_PER_MIN) ); } - elseif ($period > ZBX_MAX_PERIOD) { + elseif ($period > $max_period) { $errors[] = _n('Maximum time period to display is %1$s day.', - 'Maximum time period to display is %1$s days.', (int) (ZBX_MAX_PERIOD / SEC_PER_DAY) + 'Maximum time period to display is %1$s days.', (int) ($max_period / SEC_PER_DAY) ); } diff --git a/ui/include/defines.inc.php b/ui/include/defines.inc.php index 030e983e6ab..a0780555f67 100644 --- a/ui/include/defines.inc.php +++ b/ui/include/defines.inc.php @@ -21,14 +21,11 @@ define('ZABBIX_VERSION', '5.2.0alpha1'); define('ZABBIX_API_VERSION', '5.2.0'); define('ZABBIX_EXPORT_VERSION', '5.0'); -define('ZABBIX_DB_VERSION', 5010006); +define('ZABBIX_DB_VERSION', 5010023); define('ZABBIX_COPYRIGHT_FROM', '2001'); define('ZABBIX_COPYRIGHT_TO', '2020'); -define('ZBX_LOGIN_ATTEMPTS', 5); -define('ZBX_LOGIN_BLOCK', 30); // sec - define('ZBX_BCRYPT_COST', 10); define('ZBX_MD5_SIZE', 32); @@ -40,9 +37,7 @@ define('ZBX_GIBIBYTE', '1073741824'); define('ZBX_TEBIBYTE', '1099511627776'); define('ZBX_MIN_PERIOD', 60); // 1 minute -// The maximum period for the time bar control, ~2 years (2 * 365 * 86400) + 86400 + 3600 + 1. -// Both dates are included to the period, so one second is needed to cover the case from "now" till "now-2y". -define('ZBX_MAX_PERIOD', 63162001); + define('ZBX_MIN_INT32', -2147483648); define('ZBX_MAX_INT32', 2147483647); define('ZBX_MAX_UINT64', '18446744073709551615'); @@ -53,23 +48,15 @@ define('ZBX_FLOAT_MIN', PHP_FLOAT_MIN); define('ZBX_FLOAT_MAX', PHP_FLOAT_MAX); define('ZBX_MAX_DATE', ZBX_MAX_INT32); // 19 Jan 2038 05:14:07 -define('ZBX_PERIOD_DEFAULT_FROM', 'now-1h'); // Default time interval. -define('ZBX_PERIOD_DEFAULT_TO', 'now'); define('ZBX_MIN_TIMESHIFT', -788400000); // Min valid timeshift value in seconds (25 years). define('ZBX_MAX_TIMESHIFT', 788400000); // Max valid timeshift value in seconds (25 years). -// Applied to tables with variable count of columns. Columns above this limit will be truncated. -define('ZBX_MAX_TABLE_COLUMNS', 50); define('ZBX_MAX_GRAPHS_PER_PAGE', 20); // Date and time format separators must be synced with setSDateFromOuterObj() in class.calendar.js. define('ZBX_FULL_DATE_TIME', 'Y-m-d H:i:s'); // Time selector full date and time presentation format. define('ZBX_DATE_TIME', 'Y-m-d H:i'); // Time selector date and time without seconds presentation format. -// the maximum period to display history data for the latest data and item overview pages in seconds -// by default set to 86400 seconds (24 hours) -define('ZBX_HISTORY_PERIOD', 86400); - define('ZBX_HISTORY_SOURCE_ELASTIC', 'elastic'); define('ZBX_HISTORY_SOURCE_SQL', 'sql'); @@ -154,8 +141,6 @@ define('ORACLE_MAX_STRING_SIZE', 4000); define('ORACLE_UTF8_CHARSET', 'AL32UTF8'); define('ORACLE_CESU8_CHARSET', 'UTF8'); -define('ZBX_SHOW_TECHNICAL_ERRORS', false); - define('PAGE_TYPE_HTML', 0); define('PAGE_TYPE_IMAGE', 1); define('PAGE_TYPE_JS', 3); // javascript @@ -188,10 +173,6 @@ define('P_NZERO', 0x0020); define('P_NO_TRIM', 0x0040); define('P_ALLOW_USER_MACRO', 0x0080); define('P_ALLOW_LLD_MACRO', 0x0100); -define('ZBX_URI_VALID_SCHEMES', 'http,https,ftp,file,mailto,tel,ssh'); - -// Validate URI against schemes whitelist defined in ZBX_URI_VALID_SCHEMES. -define('VALIDATE_URI_SCHEMES', true); // misc parameters define('IMAGE_FORMAT_PNG', 'PNG'); @@ -227,7 +208,7 @@ define('AUDIT_ACTION_DISABLE', 6); define('AUDIT_ACTION_EXECUTE', 7); define('AUDIT_RESOURCE_USER', 0); -define('AUDIT_RESOURCE_ZABBIX_CONFIG', 2); +define('AUDIT_RESOURCE_ZABBIX_CONFIG', 2); // Currently not used but need for compatibility with old audit records. define('AUDIT_RESOURCE_MEDIA_TYPE', 3); define('AUDIT_RESOURCE_HOST', 4); define('AUDIT_RESOURCE_ACTION', 5); @@ -261,6 +242,9 @@ define('AUDIT_RESOURCE_ITEM_PROTOTYPE', 36); define('AUDIT_RESOURCE_HOST_PROTOTYPE', 37); define('AUDIT_RESOURCE_AUTOREGISTRATION', 38); define('AUDIT_RESOURCE_MODULE', 39); +define('AUDIT_RESOURCE_SETTINGS', 40); +define('AUDIT_RESOURCE_HOUSEKEEPING', 41); +define('AUDIT_RESOURCE_AUTHENTICATION', 42); define('CONDITION_TYPE_HOST_GROUP', 0); define('CONDITION_TYPE_HOST', 1); @@ -1260,10 +1244,6 @@ define('IPMI_PRIVILEGE_OEM', 5); define('ZBX_HAVE_IPV6', true); define('ZBX_DISCOVERER_IPRANGE_LIMIT', 65536); -define('ZBX_SOCKET_TIMEOUT', 3); // Socket timeout limit. -define('ZBX_CONNECT_TIMEOUT', 3); // Zabbix server connect timeout limit. -define('ZBX_MEDIA_TYPE_TEST_TIMEOUT', 65); // Timeout limit set for media type test. -define('ZBX_SCRIPT_TIMEOUT', 60); // Timeout limit set for scripts. define('ZBX_SOCKET_BYTES_LIMIT', ZBX_MEBIBYTE * 16); // socket response size limit // value is also used in servercheck.js file @@ -1538,9 +1518,6 @@ define('QUEUE_OVERVIEW', 0); define('QUEUE_OVERVIEW_BY_PROXY', 1); define('QUEUE_DETAILS', 2); -// item count to display in the details queue -define('QUEUE_DETAIL_ITEM_COUNT', 500); - // target types to copy items/triggers/graphs define('COPY_TYPE_TO_HOST_GROUP', 0); define('COPY_TYPE_TO_HOST', 1); @@ -1940,23 +1917,3 @@ define('PROBLEMS_TAG_NAME_NONE', 2); define('OPERATIONAL_DATA_SHOW_NONE', 0); define('OPERATIONAL_DATA_SHOW_SEPARATELY', 1); define('OPERATIONAL_DATA_SHOW_WITH_PROBLEM', 2); - -/** - * The sandbox attribute enables an extra set of restrictions for the content in the iframe. Default is set to empty - * string, which means all restrictions are applied. To disable, set to FALSE. To set a specific set of restrictions, - * write a custom string. - * https://www.w3.org/TR/2010/WD-html5-20100624/the-iframe-element.html#attr-iframe-sandbox - */ -define('ZBX_IFRAME_SANDBOX', ''); - -// HTTP headers -/* - * Value of HTTP X-Frame-options header. - * - * Supported options: - * - SAMEORIGIN (string) - compatible with rfc7034. - * - DENY (string) - compatible with rfc7034. - * - a list (string) of comma-separated hostnames. If hostname is not between allowed, the SAMEORIGIN option is used. - * - null - disable X-Frame-options header. - */ -define('X_FRAME_OPTIONS', 'SAMEORIGIN'); diff --git a/ui/include/events.inc.php b/ui/include/events.inc.php index fec2ba656c6..391b3154e39 100644 --- a/ui/include/events.inc.php +++ b/ui/include/events.inc.php @@ -100,12 +100,11 @@ function get_events_unacknowledged($db_element, $value_trigger = null, $value_ev return 0; } - $config = select_config(); $options = [ 'output' => ['triggerid'], 'monitored' => 1, 'skipDependent' => 1, - 'limit' => $config['search_limit'] + 1 + 'limit' => CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1 ]; if (!is_null($value_trigger)) { $options['filter'] = ['value' => $value_trigger]; @@ -148,7 +147,6 @@ function get_events_unacknowledged($db_element, $value_trigger = null, $value_ev * @return CTableInfo */ function make_event_details(array $event) { - $config = select_config(); $is_acknowledged = ($event['acknowledged'] == EVENT_ACKNOWLEDGED); $table = (new CTableInfo()) @@ -162,7 +160,7 @@ function make_event_details(array $event) { ]) ->addRow([ _('Severity'), - getSeverityCell($event['severity'], $config) + getSeverityCell($event['severity']) ]) ->addRow([ _('Time'), @@ -238,8 +236,6 @@ function make_event_details(array $event) { } function make_small_eventlist(array $startEvent) { - $config = select_config(); - $table = (new CTableInfo()) ->setHeader([ _('Time'), @@ -301,14 +297,6 @@ function make_small_eventlist(array $startEvent) { ]) : []; - $severity_config = [ - 'severity_name_0' => $config['severity_name_0'], - 'severity_name_1' => $config['severity_name_1'], - 'severity_name_2' => $config['severity_name_2'], - 'severity_name_3' => $config['severity_name_3'], - 'severity_name_4' => $config['severity_name_4'], - 'severity_name_5' => $config['severity_name_5'] - ]; $actions = getEventsActionsIconsData($events, $triggers, $r_events); $users = API::User()->get([ 'output' => ['alias', 'name', 'surname'], @@ -374,7 +362,7 @@ function make_small_eventlist(array $startEvent) { zbx_date2age($event['clock']), $duration, $problem_update_link, - makeEventActionsIcons($event['eventid'], $actions['data'], $mediatypes, $users, $severity_config) + makeEventActionsIcons($event['eventid'], $actions['data'], $mediatypes, $users) ]); } diff --git a/ui/include/forms.inc.php b/ui/include/forms.inc.php index b1d963b6c07..bd9d02de2d7 100644 --- a/ui/include/forms.inc.php +++ b/ui/include/forms.inc.php @@ -1523,7 +1523,6 @@ function getTriggerMassupdateFormData() { 'parent_discoveryid' => getRequest('parent_discoveryid'), 'g_triggerid' => getRequest('g_triggerid', []), 'priority' => getRequest('priority', 0), - 'config' => select_config(), 'hostid' => getRequest('hostid', 0) ]; diff --git a/ui/include/func.inc.php b/ui/include/func.inc.php index 632f1cf82ef..a08ac80ef57 100644 --- a/ui/include/func.inc.php +++ b/ui/include/func.inc.php @@ -1514,9 +1514,9 @@ function access_deny($mode = ACCESS_DENY_OBJECT) { else { // url to redirect the user to after he logs in $url = (new CUrl(!empty($_REQUEST['request']) ? $_REQUEST['request'] : ''))->removeArgument('sid'); - $config = select_config(); - if ($config['http_login_form'] == ZBX_AUTH_FORM_HTTP && $config['http_auth_enabled'] == ZBX_AUTH_HTTP_ENABLED + if (CAuthenticationHelper::get(CAuthenticationHelper::HTTP_LOGIN_FORM) == ZBX_AUTH_FORM_HTTP + && CAuthenticationHelper::get(CAuthenticationHelper::HTTP_AUTH_ENABLED) == ZBX_AUTH_HTTP_ENABLED && (!CWebUser::isLoggedIn() || CWebUser::isGuest())) { $redirect_to = (new CUrl('index_http.php'))->setArgument('request', $url->toString()); redirect($redirect_to->toString()); @@ -1655,14 +1655,16 @@ function makeMessageBox($good, array $messages, $title = null, $show_close_box = } /** - * Filters messages that can be displayed to user based on defines (see ZBX_SHOW_TECHNICAL_ERRORS) and user settings. + * Filters messages that can be displayed to user based on CSettingsHelper::SHOW_TECHNICAL_ERRORS and user settings. * * @param array $messages List of messages to filter. * * @return array */ function filter_messages(array $messages = []) { - if (!ZBX_SHOW_TECHNICAL_ERRORS && CWebUser::getType() != USER_TYPE_SUPER_ADMIN && !CWebUser::getDebugMode()) { + if (!CSettingsHelper::getGlobal(CSettingsHelper::SHOW_TECHNICAL_ERRORS) + && CWebUser::getType() != USER_TYPE_SUPER_ADMIN + && !CWebUser::getDebugMode()) { $filtered_messages = []; $generic_exists = false; @@ -2022,7 +2024,9 @@ function get_status() { 'has_status' => false ]; - $server = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, ZBX_SOCKET_TIMEOUT, ZBX_SOCKET_BYTES_LIMIT); + $server = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, + timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::SOCKET_TIMEOUT)), ZBX_SOCKET_BYTES_LIMIT + ); $status['is_running'] = $server->isRunning(get_cookie(ZBX_SESSION_NAME)); if ($status['is_running'] === false) { @@ -2487,13 +2491,16 @@ function getTimeSelectorPeriod(array $options) { $profileIdx2 = array_key_exists('profileIdx2', $options) ? $options['profileIdx2'] : null; if ($profileIdx === null) { - $options['from'] = ZBX_PERIOD_DEFAULT_FROM; - $options['to'] = ZBX_PERIOD_DEFAULT_TO; + $options['from'] = 'now-'.CSettingsHelper::get(CSettingsHelper::PERIOD_DEFAULT); + $options['to'] = 'now'; } elseif (!array_key_exists('from', $options) || !array_key_exists('to', $options) || $options['from'] === null || $options['to'] === null) { - $options['from'] = CProfile::get($profileIdx.'.from', ZBX_PERIOD_DEFAULT_FROM, $profileIdx2); - $options['to'] = CProfile::get($profileIdx.'.to', ZBX_PERIOD_DEFAULT_TO, $profileIdx2); + $options['from'] = CProfile::get($profileIdx.'.from', + 'now-'.CSettingsHelper::get(CSettingsHelper::PERIOD_DEFAULT), + $profileIdx2 + ); + $options['to'] = CProfile::get($profileIdx.'.to', 'now', $profileIdx2); } $range_time_parser = new CRangeTimeParser(); diff --git a/ui/include/hostgroups.inc.php b/ui/include/hostgroups.inc.php index a2cccfa799d..89ba110c862 100644 --- a/ui/include/hostgroups.inc.php +++ b/ui/include/hostgroups.inc.php @@ -235,7 +235,6 @@ function getSubGroups(array $groupids, array &$ms_groups = null, array $options * @param array $hosts Array of problematic hosts. * @param array $data Array of host data, filter settings and * severity configuration. - * @param array $data['config'] Severities configuration array. * @param array $data['filter']['severities'] Array of severities. * @param string $data['hosts_data'][<hostid>]['host'] Host name. * @param int $data['hosts_data'][<hostid>]['severities'][<severity>] Severity count. @@ -250,7 +249,7 @@ function makeProblemHostsHintBox(array $hosts, array $data, CUrl $url) { foreach (range(TRIGGER_SEVERITY_COUNT - 1, TRIGGER_SEVERITY_NOT_CLASSIFIED) as $severity) { if (in_array($severity, $data['filter']['severities'])) { - $header[] = getSeverityName($severity, $data['config']); + $header[] = getSeverityName($severity); } } diff --git a/ui/include/html.inc.php b/ui/include/html.inc.php index 482bdfcd3a7..cc8cd249b36 100644 --- a/ui/include/html.inc.php +++ b/ui/include/html.inc.php @@ -882,14 +882,6 @@ function getAdministrationGeneralSubmenu() { ->setArgument('action', 'valuemap.list') ->getUrl(); - $workingtime_url = (new CUrl('zabbix.php')) - ->setArgument('action', 'workingtime.edit') - ->getUrl(); - - $trigseverity_url = (new CUrl('zabbix.php')) - ->setArgument('action', 'trigseverity.edit') - ->getUrl(); - $trigdisplay_url = (new CUrl('zabbix.php')) ->setArgument('action', 'trigdisplay.edit') ->getUrl(); @@ -913,8 +905,6 @@ function getAdministrationGeneralSubmenu() { $regex_url => _('Regular expressions'), $macros_url => _('Macros'), $valuemap_url => _('Value mapping'), - $workingtime_url => _('Working time'), - $trigseverity_url => _('Trigger severities'), $trigdisplay_url => _('Trigger displaying options'), $modules_url => _('Modules'), $miscconfig_url => _('Other') @@ -1097,26 +1087,18 @@ function makeWarningIcon($error) { /** * Returns css for trigger severity backgrounds. * - * @param array $config - * @param array $config[severity_color_0] - * @param array $config[severity_color_1] - * @param array $config[severity_color_2] - * @param array $config[severity_color_3] - * @param array $config[severity_color_4] - * @param array $config[severity_color_5] - * * @return string */ -function getTriggerSeverityCss($config) { +function getTriggerSeverityCss() { $css = ''; $severities = [ - ZBX_STYLE_NA_BG => $config['severity_color_0'], - ZBX_STYLE_INFO_BG => $config['severity_color_1'], - ZBX_STYLE_WARNING_BG => $config['severity_color_2'], - ZBX_STYLE_AVERAGE_BG => $config['severity_color_3'], - ZBX_STYLE_HIGH_BG => $config['severity_color_4'], - ZBX_STYLE_DISASTER_BG => $config['severity_color_5'] + ZBX_STYLE_NA_BG => CSettingsHelper::getGlobal(CSettingsHelper::SEVERITY_COLOR_0), + ZBX_STYLE_INFO_BG => CSettingsHelper::getGlobal(CSettingsHelper::SEVERITY_COLOR_1), + ZBX_STYLE_WARNING_BG => CSettingsHelper::getGlobal(CSettingsHelper::SEVERITY_COLOR_2), + ZBX_STYLE_AVERAGE_BG => CSettingsHelper::getGlobal(CSettingsHelper::SEVERITY_COLOR_3), + ZBX_STYLE_HIGH_BG => CSettingsHelper::getGlobal(CSettingsHelper::SEVERITY_COLOR_4), + ZBX_STYLE_DISASTER_BG => CSettingsHelper::getGlobal(CSettingsHelper::SEVERITY_COLOR_5) ]; foreach ($severities as $class => $color) { @@ -1130,24 +1112,17 @@ function getTriggerSeverityCss($config) { /** * Returns css for trigger status colors, if those are customized. * - * @param array $config - * @param array $config[custom_color] - * @param array $config[problem_unack_color] - * @param array $config[problem_ack_color] - * @param array $config[ok_unack_color] - * @param array $config[ok_ack_color] - * * @return string */ -function getTriggerStatusCss($config) { +function getTriggerStatusCss() { $css = ''; - if ($config['custom_color'] == EVENT_CUSTOM_COLOR_ENABLED) { + if (CSettingsHelper::getGlobal(CSettingsHelper::CUSTOM_COLOR) == EVENT_CUSTOM_COLOR_ENABLED) { $event_statuses = [ - ZBX_STYLE_PROBLEM_UNACK_FG => $config['problem_unack_color'], - ZBX_STYLE_PROBLEM_ACK_FG => $config['problem_ack_color'], - ZBX_STYLE_OK_UNACK_FG => $config['ok_unack_color'], - ZBX_STYLE_OK_ACK_FG => $config['ok_ack_color'] + ZBX_STYLE_PROBLEM_UNACK_FG => CSettingsHelper::get(CSettingsHelper::PROBLEM_UNACK_COLOR), + ZBX_STYLE_PROBLEM_ACK_FG => CSettingsHelper::get(CSettingsHelper::PROBLEM_ACK_COLOR), + ZBX_STYLE_OK_UNACK_FG => CSettingsHelper::get(CSettingsHelper::OK_UNACK_COLOR), + ZBX_STYLE_OK_ACK_FG => CSettingsHelper::get(CSettingsHelper::OK_ACK_COLOR) ]; foreach ($event_statuses as $class => $color) { diff --git a/ui/include/items.inc.php b/ui/include/items.inc.php index 59c03f829d5..ffce7ea98a1 100644 --- a/ui/include/items.inc.php +++ b/ui/include/items.inc.php @@ -1011,7 +1011,9 @@ function getDataOverviewCellData(array &$db_hosts, array &$db_items, array &$ite } } - $history = Manager::History()->getLastValues($visible_items, 1, ZBX_HISTORY_PERIOD); + $history = Manager::History()->getLastValues($visible_items, 1, + timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::HISTORY_PERIOD)) + ); $db_triggers = getTriggersWithActualSeverity([ 'output' => ['triggerid', 'priority', 'value'], @@ -1072,8 +1074,7 @@ function getDataOverviewCellData(array &$db_hosts, array &$db_items, array &$ite * @return array */ function getDataOverviewItems(?array $groupids = null, ?array $hostids = null, ?string $application = ''): array { - $config = select_config(); - + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT); if ($application !== '') { $applicationids = array_keys(API::Application()->get([ 'output' => [], @@ -1088,7 +1089,7 @@ function getDataOverviewItems(?array $groupids = null, ?array $hostids = null, ? 'applicationids' => $applicationids, 'monitored' => true, 'webitems' => true, - 'limit' => $config['search_limit'], + 'limit' => $limit, 'preservekeys' => true ]); } @@ -1099,7 +1100,7 @@ function getDataOverviewItems(?array $groupids = null, ?array $hostids = null, ? 'groupids' => $groupids, 'monitored' => true, 'webitems' => true, - 'limit' => $config['search_limit'], + 'limit' => $limit, 'preservekeys' => true ]); } @@ -1123,7 +1124,7 @@ function getDataOverviewItems(?array $groupids = null, ?array $hostids = null, ? * @return array */ function getDataOverviewHosts(?array $groupids, ?array $hostids, ?array $itemids, ?string $application = ''): array { - $config = select_config(); + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT); if ($application !== '') { $applicationids = array_keys(API::Application()->get([ 'output' => [], @@ -1140,7 +1141,7 @@ function getDataOverviewHosts(?array $groupids, ?array $hostids, ?array $itemids 'monitored_hosts' => true, 'with_monitored_items' => true, 'preservekeys' => true, - 'limit' => $config['search_limit'] + 'limit' => $limit ]); } else { @@ -1152,7 +1153,7 @@ function getDataOverviewHosts(?array $groupids, ?array $hostids, ?array $itemids 'groupids' => $groupids, 'with_monitored_items' => true, 'preservekeys' => true, - 'limit' => $config['search_limit'] + 'limit' => $limit ]); } @@ -1180,7 +1181,9 @@ function getDataOverviewLeft(?array $groupids, ?array $hostids, string $applicat $items_by_name[$db_item['name']][$db_item['hostid']] = $itemid; } - $hidden_items_cnt = count(array_splice($items_by_name, ZBX_MAX_TABLE_COLUMNS)); + $hidden_items_cnt = count(array_splice($items_by_name, (int) CSettingsHelper::get( + CSettingsHelper::MAX_OVERVIEW_TABLE_SIZE + ))); $itemids = []; foreach ($items_by_name as $hostid_to_itemid) { @@ -1192,7 +1195,7 @@ function getDataOverviewLeft(?array $groupids, ?array $hostids, string $applicat $db_hosts = getDataOverviewHosts(null, null, $itemids); $db_hosts_ctn = count($db_hosts); - $db_hosts = array_slice($db_hosts, 0, ZBX_MAX_TABLE_COLUMNS, true); + $db_hosts = array_slice($db_hosts, 0, (int) CSettingsHelper::get(CSettingsHelper::MAX_OVERVIEW_TABLE_SIZE), true); $has_hidden_data = ($hidden_items_cnt || ($db_hosts_ctn > count($db_hosts))); @@ -1209,7 +1212,9 @@ function getDataOverviewLeft(?array $groupids, ?array $hostids, string $applicat function getDataOverviewTop(?array $groupids, ?array $hostids, string $application = ''): array { $db_hosts = getDataOverviewHosts($groupids, $hostids, null, $application); $hostids = array_keys($db_hosts); - $hidden_db_hosts_cnt = count(array_splice($hostids, ZBX_MAX_TABLE_COLUMNS)); + $hidden_db_hosts_cnt = count(array_splice($hostids, (int) CSettingsHelper::get( + CSettingsHelper::MAX_OVERVIEW_TABLE_SIZE + ))); $db_hosts = array_intersect_key($db_hosts, array_flip($hostids)); $db_items = getDataOverviewItems(null, $hostids, $application); @@ -1222,7 +1227,9 @@ function getDataOverviewTop(?array $groupids, ?array $hostids, string $applicati } $items_by_name_ctn = count($items_by_name); - $items_by_name = array_slice($items_by_name, 0, ZBX_MAX_TABLE_COLUMNS, true); + $items_by_name = array_slice($items_by_name, 0, + (int) CSettingsHelper::get(CSettingsHelper::MAX_OVERVIEW_TABLE_SIZE), true + ); $has_hidden_data = ($hidden_db_hosts_cnt || ($items_by_name_ctn > count($items_by_name))); diff --git a/ui/include/maps.inc.php b/ui/include/maps.inc.php index 68b2e9dca7f..2965c3a57ad 100644 --- a/ui/include/maps.inc.php +++ b/ui/include/maps.inc.php @@ -712,8 +712,6 @@ function getSelementsInfo(array $sysmap, array $options = []): array { } } - $config = select_config(); - $info = []; foreach ($selements as $selementId => $selement) { $i = [ @@ -817,7 +815,9 @@ function getSelementsInfo(array $sysmap, array $options = []): array { } } - $i['latelyChanged'] |= ((time() - $lately_changed) < timeUnitToSeconds($config['blink_period'])); + $i['latelyChanged'] |= ((time() - $lately_changed) < timeUnitToSeconds(CSettingsHelper::get( + CSettingsHelper::BLINK_PERIOD + ))); } if ($critical_problem) { @@ -1549,20 +1549,22 @@ function getMapLinkTriggerInfo($sysmap, $options) { * @return string */ function getSelementLabelColor($is_problem, $is_ack) { - static $config = null; static $schema = null; - if ($config === null) { - $config = select_config(); + if ($schema === null) { $schema = DB::getSchema('config'); } - $ack_unack = $is_ack ? 'ack' : 'unack'; - $ok_problem = $is_problem ? 'problem' : 'ok'; + if ($is_problem) { + $param = $is_ack ? CSettingsHelper::PROBLEM_ACK_COLOR : CSettingsHelper::PROBLEM_UNACK_COLOR; + } + else { + $param = $is_ack ? CSettingsHelper::OK_ACK_COLOR : CSettingsHelper::OK_UNACK_COLOR; + } - if ($config['custom_color'] === '1') { - return $config[$ok_problem . '_' . $ack_unack . '_color']; + if (CSettingsHelper::get(CSettingsHelper::CUSTOM_COLOR) === '1') { + return CSettingsHelper::get($param); } - return $schema['fields'][$ok_problem . '_' . $ack_unack . '_color']['default']; + return $schema['fields'][$param]['default']; } diff --git a/ui/include/page_header.php b/ui/include/page_header.php index f9275281ac6..59a9afe2719 100644 --- a/ui/include/page_header.php +++ b/ui/include/page_header.php @@ -85,13 +85,14 @@ switch ($page['type']) { header('X-Content-Type-Options: nosniff'); header('X-XSS-Protection: 1; mode=block'); - if (X_FRAME_OPTIONS !== null) { - if (strcasecmp(X_FRAME_OPTIONS, 'SAMEORIGIN') == 0 || strcasecmp(X_FRAME_OPTIONS, 'DENY') == 0) { - $x_frame_options = X_FRAME_OPTIONS; + if (CSettingsHelper::getGlobal(CSettingsHelper::X_FRAME_OPTIONS) !== '') { + if (strcasecmp(CSettingsHelper::get(CSettingsHelper::X_FRAME_OPTIONS), 'SAMEORIGIN') == 0 + || strcasecmp(CSettingsHelper::get(CSettingsHelper::X_FRAME_OPTIONS), 'DENY') == 0) { + $x_frame_options = CSettingsHelper::get(CSettingsHelper::X_FRAME_OPTIONS); } else { $x_frame_options = 'SAMEORIGIN'; - $allowed_urls = explode(',', X_FRAME_OPTIONS); + $allowed_urls = explode(',', CSettingsHelper::get(CSettingsHelper::X_FRAME_OPTIONS)); $url_to_check = array_key_exists('HTTP_REFERER', $_SERVER) ? parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST) : null; @@ -133,14 +134,14 @@ if ($page['type'] == PAGE_TYPE_HTML) { global $DB; if (!empty($DB['DB'])) { - $config = select_config(); $theme = getUserTheme(CWebUser::$data); - $pageHeader->addStyle(getTriggerSeverityCss($config)); - $pageHeader->addStyle(getTriggerStatusCss($config)); + $pageHeader->addStyle(getTriggerSeverityCss()); + $pageHeader->addStyle(getTriggerStatusCss()); // perform Zabbix server check only for standard pages - if ($is_standard_page && $config['server_check_interval'] && !empty($ZBX_SERVER) && !empty($ZBX_SERVER_PORT)) { + if ($is_standard_page && CSettingsHelper::get(CSettingsHelper::SERVER_CHECK_INTERVAL) && !empty($ZBX_SERVER) + && !empty($ZBX_SERVER_PORT)) { $page['scripts'][] = 'servercheck.js'; } } diff --git a/ui/include/perm.inc.php b/ui/include/perm.inc.php index 6e8c01d2b1b..75b501c13d4 100644 --- a/ui/include/perm.inc.php +++ b/ui/include/perm.inc.php @@ -118,11 +118,9 @@ function getUserGuiAccess($userid) { * @return int */ function getUserAuthenticationType($gui_access) { - $config = select_config(); - switch ($gui_access) { case GROUP_GUI_ACCESS_SYSTEM: - return $config['authentication_type']; + return CAuthenticationHelper::get(CAuthenticationHelper::AUTHENTICATION_TYPE); case GROUP_GUI_ACCESS_INTERNAL: return ZBX_AUTH_INTERNAL; @@ -131,7 +129,7 @@ function getUserAuthenticationType($gui_access) { return ZBX_AUTH_LDAP; default: - return $config['authentication_type']; + return CAuthenticationHelper::get(CAuthenticationHelper::AUTHENTICATION_TYPE); } } diff --git a/ui/include/profiles.inc.php b/ui/include/profiles.inc.php deleted file mode 100644 index fd686e63245..00000000000 --- a/ui/include/profiles.inc.php +++ /dev/null @@ -1,292 +0,0 @@ -<?php -/* -** Zabbix -** Copyright (C) 2001-2020 Zabbix SIA -** -** This program is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -**/ - - -/** - * Select configuration parameters. - * - * @static array $config Array containing configuration parameters. - * - * @return array - */ -function select_config() { - static $config; - - if (!isset($config)) { - $config = DBfetch(DBselect('SELECT c.* FROM config c')); - } - - return $config; -} - -function setHostGroupInternal($groupid, $internal) { - return DBexecute( - 'UPDATE hstgrp'. - ' SET internal='.zbx_dbstr($internal). - ' WHERE '.dbConditionInt('groupid', [$groupid]) - ); -} - -function update_config($config) { - $configOrig = select_config(); - - if (array_key_exists('discovery_groupid', $config)) { - $hostGroups = API::HostGroup()->get([ - 'output' => ['name'], - 'groupids' => $config['discovery_groupid'] - ]); - if (!$hostGroups) { - error(_('Incorrect host group.')); - return false; - } - } - - if (array_key_exists('alert_usrgrpid', $config) && $config['alert_usrgrpid'] != 0) { - $userGroup = DBfetch(DBselect( - 'SELECT u.name'. - ' FROM usrgrp u'. - ' WHERE u.usrgrpid='.zbx_dbstr($config['alert_usrgrpid']) - )); - if (!$userGroup) { - error(_('Incorrect user group.')); - - return false; - } - } - - $fields = [ - 'hk_events_trigger' => [ - 'min' => SEC_PER_DAY, - 'max' => 25 * SEC_PER_YEAR, - 'allow_zero' => false, - 'message' => _('Invalid trigger data storage period: %1$s.') - ], - 'hk_events_internal' => [ - 'min' => SEC_PER_DAY, - 'max' => 25 * SEC_PER_YEAR, - 'allow_zero' => false, - 'message' => _('Invalid internal data storage period: %1$s.') - ], - 'hk_events_discovery' => [ - 'min' => SEC_PER_DAY, - 'max' => 25 * SEC_PER_YEAR, - 'allow_zero' => false, - 'message' => _('Invalid network discovery data storage period: %1$s.') - ], - 'hk_events_autoreg' => [ - 'min' => SEC_PER_DAY, - 'max' => 25 * SEC_PER_YEAR, - 'allow_zero' => false, - 'message' => _('Invalid autoregistration data storage period: %1$s.') - ], - 'hk_services' => [ - 'min' => SEC_PER_DAY, - 'max' => 25 * SEC_PER_YEAR, - 'allow_zero' => false, - 'message' => _('Invalid data storage period for services: %1$s.') - ], - 'hk_audit' => [ - 'min' => SEC_PER_DAY, - 'max' => 25 * SEC_PER_YEAR, - 'allow_zero' => false, - 'message' => _('Invalid audit data storage period: %1$s.') - ], - 'hk_sessions' => [ - 'min' => SEC_PER_DAY, - 'max' => 25 * SEC_PER_YEAR, - 'allow_zero' => false, - 'message' => _('Invalid user sessions data storage period: %1$s.') - ], - 'hk_history' => [ - 'min' => SEC_PER_HOUR, - 'max' => 25 * SEC_PER_YEAR, - 'allow_zero' => true, - 'message' => _('Invalid history data storage period: %1$s.') - ], - 'hk_trends' => [ - 'min' => SEC_PER_DAY, - 'max' => 25 * SEC_PER_YEAR, - 'allow_zero' => true, - 'message' => _('Invalid trends data storage period: %1$s.') - ], - 'ok_period' => [ - 'min' => 0, - 'max' => SEC_PER_DAY, - 'allow_zero' => false, - 'message' => _('Invalid displaying of OK triggers: %1$s.') - ], - 'blink_period' => [ - 'min' => 0, - 'max' => SEC_PER_DAY, - 'allow_zero' => false, - 'message' => _('Invalid blinking on trigger status change: %1$s.') - ], - 'refresh_unsupported' => [ - 'min' => 0, - 'max' => SEC_PER_DAY, - 'allow_zero' => false, - 'message' => _('Invalid refresh of unsupported items: %1$s') - ], - 'compress_older' => [ - 'min' => SEC_PER_DAY * 7, - 'max' => 25 * SEC_PER_YEAR, - 'allow_zero' => false, - 'message' => _s('Invalid parameter "%1$s": %2$s.', _('Compress records older than'), '%1$s') - ], - ]; - - if (array_key_exists('compression_status', $config) && $config['compression_status'] === 0) { - unset($fields['compress_older']); - unset($config['compress_older']); - } - - foreach ($fields as $field => $args) { - if (array_key_exists($field, $config) - && !validateTimeUnit($config[$field], $args['min'], $args['max'], $args['allow_zero'], $error)) { - error(sprintf($args['message'], $error)); - - return false; - } - } - - $updateSeverity = false; - for ($i = 0; $i < TRIGGER_SEVERITY_COUNT; $i++) { - if (isset($config['severity_name_'.$i])) { - $updateSeverity = true; - break; - } - } - - if ($updateSeverity) { - // check duplicate severity names and if name is empty. - $names = []; - for ($i = 0; $i < TRIGGER_SEVERITY_COUNT; $i++) { - $varName = 'severity_name_'.$i; - if (!array_key_exists($varName, $config)) { - $config[$varName] = $configOrig[$varName]; - } - - if (isset($names[$config[$varName]])) { - error(_s('Duplicate severity name "%1$s".', $config[$varName])); - return false; - } - else { - $names[$config[$varName]] = true; - } - } - } - - $update = []; - - foreach ($config as $key => $value) { - if (!is_null($value)) { - if ($key == 'alert_usrgrpid') { - $update[] = $key.'='.(($value == '0') ? 'NULL' : $value); - } - else{ - $update[] = $key.'='.zbx_dbstr($value); - } - } - } - - if (count($update) == 0) { - error(_('Nothing to do.')); - return null; - } - - $result = DBexecute('UPDATE config SET '.implode(',', $update)); - - if ($result) { - $msg = []; - if (array_key_exists('hk_events_trigger', $config)) { - $msg[] = _s('Trigger event and alert data storage period "%1$s".', $config['hk_events_trigger']); - } - if (array_key_exists('hk_events_internal', $config)) { - $msg[] = _s('Internal event and alert data storage period "%1$s".', - $config['hk_events_internal'] - ); - } - if (array_key_exists('hk_events_discovery', $config)) { - $msg[] = _s('Network discovery event and alert data storage period "%1$s".', - $config['hk_events_discovery'] - ); - } - if (array_key_exists('hk_events_autoreg', $config)) { - $msg[] = _s('Autoregistration event and alert data storage period "%1$s".', - $config['hk_events_autoreg'] - ); - } - if (array_key_exists('hk_services', $config)) { - $msg[] = _s('Service data storage period "%1$s".', $config['hk_services']); - } - if (array_key_exists('hk_audit', $config)) { - $msg[] = _s('Audit data storage period "%1$s".', $config['hk_audit']); - } - if (array_key_exists('hk_sessions', $config)) { - $msg[] = _s('User session data storage period "%1$s".', $config['hk_sessions']); - } - if (array_key_exists('hk_history', $config)) { - $msg[] = _s('History data storage period "%1$s".', $config['hk_history']); - } - if (array_key_exists('hk_trends', $config)) { - $msg[] = _s('Trend data storage period "%1$s".', $config['hk_trends']); - } - if (array_key_exists('work_period', $config)) { - $msg[] = _s('Working time "%1$s".', $config['work_period']); - } - if (array_key_exists('default_lang', $config)) { - $msg[] = _s('Default language "%1$s".', $config['default_lang']); - } - if (array_key_exists('default_timezone', $config)) { - $msg[] = _s('Default time zone "%1$s".', $config['default_timezone']); - } - if (array_key_exists('default_theme', $config)) { - $msg[] = _s('Default theme "%1$s".', $config['default_theme']); - } - if (array_key_exists('max_in_table', $config)) { - $msg[] = _s('Max count of elements to show inside table cell "%1$s".', $config['max_in_table']); - } - if (array_key_exists('server_check_interval', $config)) { - $msg[] = _s('Zabbix server is running check interval "%1$s".', $config['server_check_interval']); - } - if (array_key_exists('refresh_unsupported', $config)) { - $msg[] = _s('Refresh unsupported items "%1$s".', $config['refresh_unsupported']); - } - if (array_key_exists('discovery_groupid', $config)) { - $msg[] = _s('Group for discovered hosts "%1$s".', $hostGroups[0]['name']); - - if (bccomp($config['discovery_groupid'], $configOrig['discovery_groupid']) != 0) { - setHostGroupInternal($configOrig['discovery_groupid'], ZBX_NOT_INTERNAL_GROUP); - setHostGroupInternal($config['discovery_groupid'], ZBX_INTERNAL_GROUP); - } - } - if (array_key_exists('alert_usrgrpid', $config)) { - $msg[] = _s('User group for database down message "%1$s".', - $config['alert_usrgrpid'] != 0 ? $userGroup['name'] : _('None') - ); - } - - if ($msg) { - add_audit(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_ZABBIX_CONFIG, implode('; ', $msg)); - } - } - - return $result; -} diff --git a/ui/include/schema.inc.php b/ui/include/schema.inc.php index 8c7b4476a3b..220f245795d 100644 --- a/ui/include/schema.inc.php +++ b/ui/include/schema.inc.php @@ -2999,6 +2999,108 @@ return [ 'length' => 50, 'default' => 'system', ], + 'login_attempts' => [ + 'null' => false, + 'type' => DB::FIELD_TYPE_INT, + 'length' => 10, + 'default' => '5', + ], + 'login_block' => [ + 'null' => false, + 'type' => DB::FIELD_TYPE_CHAR, + 'length' => 32, + 'default' => '30s', + ], + 'show_technical_errors' => [ + 'null' => false, + 'type' => DB::FIELD_TYPE_INT, + 'length' => 10, + 'default' => '0', + ], + 'validate_uri_schemes' => [ + 'null' => false, + 'type' => DB::FIELD_TYPE_INT, + 'length' => 10, + 'default' => '1', + ], + 'uri_valid_schemes' => [ + 'null' => false, + 'type' => DB::FIELD_TYPE_CHAR, + 'length' => 255, + 'default' => 'http,https,ftp,file,mailto,tel,ssh', + ], + 'x_frame_options' => [ + 'null' => false, + 'type' => DB::FIELD_TYPE_CHAR, + 'length' => 255, + 'default' => 'SAMEORIGIN', + ], + 'iframe_sandboxing_enabled' => [ + 'null' => false, + 'type' => DB::FIELD_TYPE_INT, + 'length' => 10, + 'default' => '1', + ], + 'iframe_sandboxing_exceptions' => [ + 'null' => false, + 'type' => DB::FIELD_TYPE_CHAR, + 'length' => 255, + 'default' => '', + ], + 'max_overview_table_size' => [ + 'null' => false, + 'type' => DB::FIELD_TYPE_INT, + 'length' => 10, + 'default' => '50', + ], + 'history_period' => [ + 'null' => false, + 'type' => DB::FIELD_TYPE_CHAR, + 'length' => 32, + 'default' => '24h', + ], + 'period_default' => [ + 'null' => false, + 'type' => DB::FIELD_TYPE_CHAR, + 'length' => 32, + 'default' => '1h', + ], + 'max_period' => [ + 'null' => false, + 'type' => DB::FIELD_TYPE_CHAR, + 'length' => 32, + 'default' => '2y', + ], + 'socket_timeout' => [ + 'null' => false, + 'type' => DB::FIELD_TYPE_CHAR, + 'length' => 32, + 'default' => '3s', + ], + 'connect_timeout' => [ + 'null' => false, + 'type' => DB::FIELD_TYPE_CHAR, + 'length' => 32, + 'default' => '3s', + ], + 'media_type_test_timeout' => [ + 'null' => false, + 'type' => DB::FIELD_TYPE_CHAR, + 'length' => 32, + 'default' => '65s', + ], + 'script_timeout' => [ + 'null' => false, + 'type' => DB::FIELD_TYPE_CHAR, + 'length' => 32, + 'default' => '60s', + ], + 'item_test_timeout' => [ + 'null' => false, + 'type' => DB::FIELD_TYPE_CHAR, + 'length' => 32, + 'default' => '60s', + ], ], ], 'triggers' => [ diff --git a/ui/include/triggers.inc.php b/ui/include/triggers.inc.php index 0c7a61851ae..c08d4bea618 100644 --- a/ui/include/triggers.inc.php +++ b/ui/include/triggers.inc.php @@ -98,24 +98,23 @@ function getSeverityStyle($severity, $type = true) { * Get trigger severity name by given state and configuration. * * @param int $severity Trigger severity. - * @param array $config Array with configuration parameters containing severity names. * * @return string */ -function getSeverityName($severity, array $config) { +function getSeverityName($severity) { switch ($severity) { case TRIGGER_SEVERITY_NOT_CLASSIFIED: - return _($config['severity_name_0']); + return _(CSettingsHelper::get(CSettingsHelper::SEVERITY_NAME_0)); case TRIGGER_SEVERITY_INFORMATION: - return _($config['severity_name_1']); + return _(CSettingsHelper::get(CSettingsHelper::SEVERITY_NAME_1)); case TRIGGER_SEVERITY_WARNING: - return _($config['severity_name_2']); + return _(CSettingsHelper::get(CSettingsHelper::SEVERITY_NAME_2)); case TRIGGER_SEVERITY_AVERAGE: - return _($config['severity_name_3']); + return _(CSettingsHelper::get(CSettingsHelper::SEVERITY_NAME_3)); case TRIGGER_SEVERITY_HIGH: - return _($config['severity_name_4']); + return _(CSettingsHelper::get(CSettingsHelper::SEVERITY_NAME_4)); case TRIGGER_SEVERITY_DISASTER: - return _($config['severity_name_5']); + return _(CSettingsHelper::get(CSettingsHelper::SEVERITY_NAME_5)); default: return _('Unknown'); } @@ -125,29 +124,28 @@ function getSeverityColor($severity, $value = TRIGGER_VALUE_TRUE) { if ($value == TRIGGER_VALUE_FALSE) { return 'AAFFAA'; } - $config = select_config(); switch ($severity) { case TRIGGER_SEVERITY_DISASTER: - $color = $config['severity_color_5']; + $color = CSettingsHelper::get(CSettingsHelper::SEVERITY_COLOR_5); break; case TRIGGER_SEVERITY_HIGH: - $color = $config['severity_color_4']; + $color = CSettingsHelper::get(CSettingsHelper::SEVERITY_COLOR_4); break; case TRIGGER_SEVERITY_AVERAGE: - $color = $config['severity_color_3']; + $color = CSettingsHelper::get(CSettingsHelper::SEVERITY_COLOR_3); break; case TRIGGER_SEVERITY_WARNING: - $color = $config['severity_color_2']; + $color = CSettingsHelper::get(CSettingsHelper::SEVERITY_COLOR_2); break; case TRIGGER_SEVERITY_INFORMATION: - $color = $config['severity_color_1']; + $color = CSettingsHelper::get(CSettingsHelper::SEVERITY_COLOR_1); break; case TRIGGER_SEVERITY_NOT_CLASSIFIED: - $color = $config['severity_color_0']; + $color = CSettingsHelper::get(CSettingsHelper::SEVERITY_COLOR_0); break; default: - $color = $config['severity_color_0']; + $color = CSettingsHelper::get(CSettingsHelper::SEVERITY_COLOR_0); } return $color; @@ -163,11 +161,10 @@ function getSeverityColor($severity, $value = TRIGGER_VALUE_TRUE) { */ function getSeverities($min = TRIGGER_SEVERITY_NOT_CLASSIFIED, $max = TRIGGER_SEVERITY_COUNT - 1) { $severities = []; - $config = select_config(); foreach (range($min, $max) as $severity) { $severities[] = [ - 'name' => getSeverityName($severity, $config), + 'name' => getSeverityName($severity), 'value' => $severity, 'style' => getSeverityStyle($severity) ]; @@ -180,17 +177,15 @@ function getSeverities($min = TRIGGER_SEVERITY_NOT_CLASSIFIED, $max = TRIGGER_SE * Returns HTML representation of trigger severity cell containing severity name and color. * * @param int $severity Trigger, Event or Problem severity. - * @param array|null $config Array of configuration parameters to get trigger severity name; can be omitted - * if $text is not null. * @param string|null $text Trigger severity name. * @param bool $force_normal True to return 'normal' class, false to return corresponding severity class. * @param bool $return_as_div True to return severity cell as DIV element. * * @return CDiv|CCol */ -function getSeverityCell($severity, array $config = null, $text = null, $force_normal = false, $return_as_div = false) { +function getSeverityCell($severity, $text = null, $force_normal = false, $return_as_div = false) { if ($text === null) { - $text = CHtml::encode(getSeverityName($severity, $config)); + $text = CHtml::encode(getSeverityName($severity)); } if ($force_normal) { @@ -211,27 +206,25 @@ function getSeverityCell($severity, array $config = null, $text = null, $force_n * @param bool $isAcknowledged */ function addTriggerValueStyle($object, $triggerValue, $triggerLastChange, $isAcknowledged) { - $config = select_config(); - $color_class = null; $blinks = null; // Color class for text and blinking depends on trigger value and whether event is acknowledged. if ($triggerValue == TRIGGER_VALUE_TRUE && !$isAcknowledged) { $color_class = ZBX_STYLE_PROBLEM_UNACK_FG; - $blinks = $config['problem_unack_style']; + $blinks = CSettingsHelper::get(CSettingsHelper::PROBLEM_UNACK_STYLE); } elseif ($triggerValue == TRIGGER_VALUE_TRUE && $isAcknowledged) { $color_class = ZBX_STYLE_PROBLEM_ACK_FG; - $blinks = $config['problem_ack_style']; + $blinks = CSettingsHelper::get(CSettingsHelper::PROBLEM_ACK_STYLE); } elseif ($triggerValue == TRIGGER_VALUE_FALSE && !$isAcknowledged) { $color_class = ZBX_STYLE_OK_UNACK_FG; - $blinks = $config['ok_unack_style']; + $blinks = CSettingsHelper::get(CSettingsHelper::OK_UNACK_STYLE); } elseif ($triggerValue == TRIGGER_VALUE_FALSE && $isAcknowledged) { $color_class = ZBX_STYLE_OK_ACK_FG; - $blinks = $config['ok_ack_style']; + $blinks = CSettingsHelper::get(CSettingsHelper::OK_ACK_STYLE); } if ($color_class != null && $blinks != null) { @@ -239,11 +232,11 @@ function addTriggerValueStyle($object, $triggerValue, $triggerLastChange, $isAck // blinking $timeSinceLastChange = time() - $triggerLastChange; - $config['blink_period'] = timeUnitToSeconds($config['blink_period']); + $blink_period = timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::BLINK_PERIOD)); - if ($blinks && $timeSinceLastChange < $config['blink_period']) { + if ($blinks && $timeSinceLastChange < $blink_period) { $object->addClass('blink'); // elements with this class will blink - $object->setAttribute('data-time-to-blink', $config['blink_period'] - $timeSinceLastChange); + $object->setAttribute('data-time-to-blink', $blink_period - $timeSinceLastChange); } } else { @@ -784,8 +777,8 @@ function getTriggersOverviewData(array $groupids, string $application, array $ho $triggers_by_name = []; $hosts_by_name = []; - $limit = ZBX_MAX_TABLE_COLUMNS; - $axis_limit = ZBX_MAX_TABLE_COLUMNS; + $limit = (int) CSettingsHelper::get(CSettingsHelper::MAX_OVERVIEW_TABLE_SIZE); + $axis_limit = (int) CSettingsHelper::get(CSettingsHelper::MAX_OVERVIEW_TABLE_SIZE); do { if (!$exhausted_hosts) { @@ -982,13 +975,12 @@ function getTriggerOverviewCell(array $trigger, array $dependencies): CCol { ->addClass(ZBX_STYLE_CURSOR_POINTER); $eventid = 0; - $config = select_config(); - $config['blink_period'] = timeUnitToSeconds($config['blink_period']); + $blink_period = timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::BLINK_PERIOD)); $duration = time() - $trigger['lastchange']; - if ($config['blink_period'] > 0 && $duration < $config['blink_period']) { + if ($blink_period > 0 && $duration < $blink_period) { $column->addClass('blink'); - $column->setAttribute('data-time-to-blink', $config['blink_period'] - $duration); + $column->setAttribute('data-time-to-blink', $blink_period - $duration); $column->setAttribute('data-toggle-class', ZBX_STYLE_BLINK_HIDDEN); } @@ -1145,13 +1137,11 @@ function get_triggers_unacknowledged($db_element, $count_problems = null, $ack = return 0; } - $config = select_config(); - $options = [ 'monitored' => true, 'countOutput' => true, 'filter' => [], - 'limit' => $config['search_limit'] + 1 + 'limit' => CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1 ]; if ($ack) { @@ -1188,8 +1178,6 @@ function get_triggers_unacknowledged($db_element, $count_problems = null, $ack = function make_trigger_details($trigger, $eventid) { $hostNames = []; - $config = select_config(); - $hostIds = zbx_objectValues($trigger['hosts'], 'hostid'); $hosts = API::Host()->get([ @@ -1220,7 +1208,7 @@ function make_trigger_details($trigger, $eventid) { ]) ->addRow([ _('Severity'), - getSeverityCell($trigger['priority'], $config) + getSeverityCell($trigger['priority']) ]); $trigger = CMacrosResolverHelper::resolveTriggerExpressions(zbx_toHash($trigger, 'triggerid'), [ diff --git a/ui/include/users.inc.php b/ui/include/users.inc.php index 0a2f765864b..788e1cfe9f7 100644 --- a/ui/include/users.inc.php +++ b/ui/include/users.inc.php @@ -27,10 +27,8 @@ * @return string */ function getUserTheme($userData) { - $config = select_config(); - - if (isset($config['default_theme'])) { - $css = $config['default_theme']; + if (null !== CSettingsHelper::getGlobal(CSettingsHelper::DEFAULT_THEME)) { + $css = CSettingsHelper::get(CSettingsHelper::DEFAULT_THEME); } if (isset($userData['theme']) && $userData['theme'] != THEME_DEFAULT) { $css = $userData['theme']; diff --git a/ui/include/validate.inc.php b/ui/include/validate.inc.php index d4e0f49fe61..958f9f31b3a 100644 --- a/ui/include/validate.inc.php +++ b/ui/include/validate.inc.php @@ -448,14 +448,21 @@ function validateTimeSelectorPeriod($from, $to) { } $ts = []; + $ts['now'] = time(); $range_time_parser = new CRangeTimeParser(); foreach (['from' => $from, 'to' => $to] as $field => $value) { $range_time_parser->parse($value); - $ts[$field] = $range_time_parser->getDateTime($field === 'from')->getTimestamp(); + $ts[$field] = $range_time_parser + ->getDateTime($field === 'from') + ->getTimestamp(); } $period = $ts['to'] - $ts['from'] + 1; + $range_time_parser->parse('now-'.CSettingsHelper::get(CSettingsHelper::MAX_PERIOD)); + $max_period = 1 + $ts['now'] - $range_time_parser + ->getDateTime(true) + ->getTimestamp(); if ($period < ZBX_MIN_PERIOD) { error(_n('Minimum time period to display is %1$s minute.', @@ -464,9 +471,9 @@ function validateTimeSelectorPeriod($from, $to) { invalid_url(); } - elseif ($period > ZBX_MAX_PERIOD) { + elseif ($period > $max_period) { error(_n('Maximum time period to display is %1$s day.', - 'Maximum time period to display is %1$s days.', (int) (ZBX_MAX_PERIOD / SEC_PER_DAY) + 'Maximum time period to display is %1$s days.', (int) ($max_period / SEC_PER_DAY) )); invalid_url(); @@ -558,6 +565,7 @@ function validateDateInterval($year, $month, $day) { * @param array $options * @param bool $options['usermacros'] * @param bool $options['lldmacros'] + * @param bool $options['with_year'] * * @return bool */ @@ -567,7 +575,7 @@ function validateTimeUnit($value, $min, $max, $allow_zero, &$error, array $optio if ($simple_interval_parser->parse($value) == CParser::PARSE_SUCCESS) { if ($value[0] !== '{') { - $value = timeUnitToSeconds($value); + $value = timeUnitToSeconds($value, array_key_exists('with_year', $options) ? $options['with_year'] : false); if ($allow_zero && $value == 0) { return true; diff --git a/ui/include/views/configuration.action.edit.php b/ui/include/views/configuration.action.edit.php index be4edd38b6b..aa6e4eda09a 100644 --- a/ui/include/views/configuration.action.edit.php +++ b/ui/include/views/configuration.action.edit.php @@ -58,7 +58,7 @@ $condition_table = (new CTable(_('No conditions defined.'))) $i = 0; if ($data['action']['filter']['conditions']) { - $actionConditionStringValues = actionConditionValueToString([$data['action']], $data['config']); + $actionConditionStringValues = actionConditionValueToString([$data['action']]); foreach ($data['action']['filter']['conditions'] as $cIdx => $condition) { if (!isset($condition['conditiontype'])) { diff --git a/ui/include/views/configuration.action.list.php b/ui/include/views/configuration.action.list.php index 8d6424b20de..53ebdf25d8b 100644 --- a/ui/include/views/configuration.action.list.php +++ b/ui/include/views/configuration.action.list.php @@ -92,7 +92,7 @@ $actionTable = (new CTableInfo()) ]); if ($this->data['actions']) { - $actionConditionStringValues = actionConditionValueToString($this->data['actions'], $this->data['config']); + $actionConditionStringValues = actionConditionValueToString($this->data['actions']); $actionOperationDescriptions = getActionOperationDescriptions($this->data['actions'], ACTION_OPERATION); foreach ($this->data['actions'] as $aIdx => $action) { diff --git a/ui/include/views/configuration.hostgroups.list.php b/ui/include/views/configuration.hostgroups.list.php index b2661c80b56..6b2eb812404 100644 --- a/ui/include/views/configuration.hostgroups.list.php +++ b/ui/include/views/configuration.hostgroups.list.php @@ -76,7 +76,7 @@ foreach ($this->data['groups'] as $group) { foreach ($group['templates'] as $template) { $n++; - if ($n > $this->data['config']['max_in_table']) { + if ($n > $data['config']['max_in_table']) { $hostsOutput[] = ' …'; break; @@ -104,7 +104,7 @@ foreach ($this->data['groups'] as $group) { foreach ($group['hosts'] as $host) { $n++; - if ($n > $this->data['config']['max_in_table']) { + if ($n > $data['config']['max_in_table']) { $hostsOutput[] = ' …'; break; diff --git a/ui/include/views/configuration.item.edit.php b/ui/include/views/configuration.item.edit.php index 7d152d673a4..2888ef5c525 100644 --- a/ui/include/views/configuration.item.edit.php +++ b/ui/include/views/configuration.item.edit.php @@ -664,8 +664,8 @@ $form_list->addRow(_('Custom intervals'), // Append history storage to form list. $keep_history_hint = null; -if ($data['config']['hk_history_global'] - && ($host['status'] == HOST_STATUS_MONITORED || $host['status'] == HOST_STATUS_NOT_MONITORED)) { +if ($data['config']['hk_history_global'] && ($host['status'] == HOST_STATUS_MONITORED + || $host['status'] == HOST_STATUS_NOT_MONITORED)) { $link = (CWebUser::getType() == USER_TYPE_SUPER_ADMIN) ? (new CLink(_x('global housekeeping settings', 'item_form'), (new CUrl('zabbix.php')) ->setArgument('action', 'housekeeping.edit') @@ -700,8 +700,8 @@ $form_list->addRow((new CLabel(_('History storage period'), 'history'))->setAste // Append trend storage to form list. $keep_trend_hint = null; -if ($data['config']['hk_trends_global'] - && ($host['status'] == HOST_STATUS_MONITORED || $host['status'] == HOST_STATUS_NOT_MONITORED)) { +if ($data['config']['hk_trends_global'] && ($host['status'] == HOST_STATUS_MONITORED + || $host['status'] == HOST_STATUS_NOT_MONITORED)) { $link = (CWebUser::getType() == USER_TYPE_SUPER_ADMIN) ? (new CLink(_x('global housekeeping settings', 'item_form'), (new CUrl('zabbix.php')) ->setArgument('action', 'housekeeping.edit') diff --git a/ui/include/views/configuration.item.list.php b/ui/include/views/configuration.item.list.php index a79212aa35d..b53560bbe4f 100644 --- a/ui/include/views/configuration.item.list.php +++ b/ui/include/views/configuration.item.list.php @@ -178,7 +178,7 @@ foreach ($data['items'] as $item) { } $triggerHintTable->addRow([ - getSeverityCell($trigger['priority'], $data['config']), + getSeverityCell($trigger['priority']), $trigger_description, (new CDiv($expression))->addClass(ZBX_STYLE_WORDWRAP), (new CSpan(triggerIndicator($trigger['status'], $trigger['state']))) diff --git a/ui/include/views/configuration.trigger.prototype.list.php b/ui/include/views/configuration.trigger.prototype.list.php index ebd011fae10..514f7edfd8c 100644 --- a/ui/include/views/configuration.trigger.prototype.list.php +++ b/ui/include/views/configuration.trigger.prototype.list.php @@ -162,7 +162,7 @@ foreach ($this->data['triggers'] as $trigger) { $triggersTable->addRow([ $checkBox, - getSeverityCell($trigger['priority'], $this->data['config']), + getSeverityCell($trigger['priority']), $description, $trigger['opdata'], (new CDiv($expression))->addClass(ZBX_STYLE_WORDWRAP), diff --git a/ui/include/views/configuration.triggers.list.php b/ui/include/views/configuration.triggers.list.php index be6081aeb88..e9dadd047b2 100644 --- a/ui/include/views/configuration.triggers.list.php +++ b/ui/include/views/configuration.triggers.list.php @@ -317,7 +317,7 @@ foreach ($data['triggers'] as $tnum => $trigger) { $triggers_table->addRow([ new CCheckBox('g_triggerid['.$triggerid.']', $triggerid), - getSeverityCell($trigger['priority'], $data['config']), + getSeverityCell($trigger['priority']), $data['show_value_column'] ? $trigger_value : null, $hosts, $description, diff --git a/ui/include/views/monitoring.overview.items.php b/ui/include/views/monitoring.overview.items.php index 60f8c600f41..a5409e68dd0 100644 --- a/ui/include/views/monitoring.overview.items.php +++ b/ui/include/views/monitoring.overview.items.php @@ -32,7 +32,7 @@ for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_C (new CDiv()) ->addClass(ZBX_STYLE_NOTIF_INDIC) ->addClass(getSeverityStyle($severity)), - new CTag('h4', true, getSeverityName($severity, $data['config'])), + new CTag('h4', true, getSeverityName($severity)), (new CTag('p', true, _('PROBLEM')))->addClass(ZBX_STYLE_GREY) ]); } diff --git a/ui/include/views/monitoring.overview.triggers.php b/ui/include/views/monitoring.overview.triggers.php index 0a711fc9c04..cd3ee35b7e8 100644 --- a/ui/include/views/monitoring.overview.triggers.php +++ b/ui/include/views/monitoring.overview.triggers.php @@ -41,7 +41,7 @@ for ($severity = TRIGGER_SEVERITY_NOT_CLASSIFIED; $severity < TRIGGER_SEVERITY_C (new CDiv()) ->addClass(ZBX_STYLE_NOTIF_INDIC) ->addClass(getSeverityStyle($severity)), - new CTag('h4', true, getSeverityName($severity, $data['config'])), + new CTag('h4', true, getSeverityName($severity)), (new CTag('p', true, _('PROBLEM')))->addClass(ZBX_STYLE_GREY) ]); } @@ -137,7 +137,6 @@ if ($web_layout_mode == ZBX_LAYOUT_NORMAL) { 'groups' => $data['filter']['groups'], 'hosts' => $data['filter']['hosts'] ], - 'config' => $data['config'], 'profileIdx' => $data['profileIdx'], 'active_tab' => $data['active_tab'] ])); diff --git a/ui/include/views/reports.toptriggers.php b/ui/include/views/reports.toptriggers.php index 2f1c300919d..f80cfef6045 100644 --- a/ui/include/views/reports.toptriggers.php +++ b/ui/include/views/reports.toptriggers.php @@ -28,7 +28,7 @@ $filterForm = new CFilter(new CUrl('toptriggers.php')); $severities = []; foreach (range(TRIGGER_SEVERITY_NOT_CLASSIFIED, TRIGGER_SEVERITY_COUNT - 1) as $severity) { $severities[] = [ - 'name' => getSeverityName($severity, $data['config']), + 'name' => getSeverityName($severity), 'value' => $severity ]; } @@ -96,7 +96,7 @@ foreach ($data['triggers'] as $trigger) { $table->addRow([ $hostName, $triggerDescription, - getSeverityCell($trigger['priority'], $data['config']), + getSeverityCell($trigger['priority']), $trigger['cnt_event'] ]); } diff --git a/ui/index.php b/ui/index.php index b7607a5d18a..529a3c4aaf9 100644 --- a/ui/index.php +++ b/ui/index.php @@ -41,10 +41,9 @@ $fields = [ ]; check_fields($fields); -$config = select_config(); - if (hasRequest('reconnect') && CWebUser::isLoggedIn()) { - if ($config['saml_auth_enabled'] == ZBX_AUTH_SAML_ENABLED && $config['saml_slo_url'] !== '' + if (CAuthenticationHelper::get(CAuthenticationHelper::SAML_AUTH_ENABLED) == ZBX_AUTH_SAML_ENABLED + && CAuthenticationHelper::get(CAuthenticationHelper::SAML_SLO_URL) !== '' && CSession::keyExists('saml_data')) { redirect('index_sso.php?slo'); } @@ -65,8 +64,9 @@ if ($request) { : ''; } -if (!hasRequest('form') && $config['http_auth_enabled'] == ZBX_AUTH_HTTP_ENABLED - && $config['http_login_form'] == ZBX_AUTH_FORM_HTTP && !hasRequest('enter')) { +if (!hasRequest('form') && CAuthenticationHelper::get(CAuthenticationHelper::HTTP_AUTH_ENABLED) == ZBX_AUTH_HTTP_ENABLED + && CAuthenticationHelper::get(CAuthenticationHelper::HTTP_LOGIN_FORM) == ZBX_AUTH_FORM_HTTP + && !hasRequest('enter')) { redirect('index_http.php'); exit; @@ -94,10 +94,10 @@ if (CWebUser::isLoggedIn() && !CWebUser::isGuest()) { $messages = clear_messages(); echo (new CView('general.login', [ - 'http_login_url' => ($config['http_auth_enabled'] == ZBX_AUTH_HTTP_ENABLED) + 'http_login_url' => (CAuthenticationHelper::get(CAuthenticationHelper::HTTP_AUTH_ENABLED) == ZBX_AUTH_HTTP_ENABLED) ? (new CUrl('index_http.php'))->setArgument('request', getRequest('request')) : '', - 'saml_login_url' => ($config['saml_auth_enabled'] == ZBX_AUTH_SAML_ENABLED) + 'saml_login_url' => (CAuthenticationHelper::get(CAuthenticationHelper::SAML_AUTH_ENABLED) == ZBX_AUTH_SAML_ENABLED) ? (new CUrl('index_sso.php'))->setArgument('request', getRequest('request')) : '', 'guest_login_url' => CWebUser::isGuestAllowed() ? (new CUrl())->setArgument('enter', ZBX_GUEST_USER) : '', diff --git a/ui/index_http.php b/ui/index_http.php index 73203a59aa9..8a9318a10e7 100644 --- a/ui/index_http.php +++ b/ui/index_http.php @@ -23,7 +23,6 @@ require_once dirname(__FILE__).'/include/classes/user/CWebUser.php'; CWebUser::disableSessionCookie(); require_once dirname(__FILE__).'/include/config.inc.php'; -$config = select_config(); $redirect_to = (new CUrl('index.php'))->setArgument('form', 'default'); $request = getRequest('request', ''); @@ -39,7 +38,7 @@ if ($request !== '') { $redirect_to->setArgument('request', $request); } -if ($config['http_auth_enabled'] != ZBX_AUTH_HTTP_ENABLED) { +if (CAuthenticationHelper::get(CAuthenticationHelper::HTTP_AUTH_ENABLED) != ZBX_AUTH_HTTP_ENABLED) { redirect($redirect_to->toString()); exit; @@ -57,7 +56,7 @@ if ($http_user) { $parser = new CADNameAttributeParser(['strict' => true]); if ($parser->parse($http_user) === CParser::PARSE_SUCCESS) { - $strip_domain = explode(',', $config['http_strip_domains']); + $strip_domain = explode(',', CAuthenticationHelper::get(CAuthenticationHelper::HTTP_STRIP_DOMAINS)); $strip_domain = array_map('trim', $strip_domain); if ($strip_domain && in_array($parser->getDomainName(), $strip_domain)) { @@ -67,7 +66,8 @@ if ($http_user) { try { $user = API::getApiService('user')->loginByAlias($http_user, - ($config['http_case_sensitive'] == ZBX_AUTH_CASE_SENSITIVE), $config['authentication_type'] + (CAuthenticationHelper::get(CAuthenticationHelper::HTTP_CASE_SENSITIVE) == ZBX_AUTH_CASE_SENSITIVE), + CAuthenticationHelper::get(CAuthenticationHelper::AUTHENTICATION_TYPE) ); if ($user) { diff --git a/ui/index_sso.php b/ui/index_sso.php index b48eeb64616..1242c73bc56 100644 --- a/ui/index_sso.php +++ b/ui/index_sso.php @@ -21,7 +21,6 @@ require_once __DIR__.'/include/config.inc.php'; -$config = select_config(); $redirect_to = (new CUrl('index.php'))->setArgument('form', 'default'); $request = CSession::getValue('request'); @@ -42,7 +41,7 @@ if (hasRequest('request')) { } } -if ($config['saml_auth_enabled'] == ZBX_AUTH_SAML_DISABLED) { +if (CAuthenticationHelper::get(CAuthenticationHelper::SAML_AUTH_ENABLED) == ZBX_AUTH_SAML_DISABLED) { CSession::unsetValue(['request']); redirect($redirect_to->toString()); @@ -92,36 +91,36 @@ elseif (file_exists('conf/certs/idp.crt')) { $settings = [ 'sp' => [ - 'entityId' => $config['saml_sp_entityid'], + 'entityId' => CAuthenticationHelper::get(CAuthenticationHelper::SAML_SP_ENTITYID), 'assertionConsumerService' => [ 'url' => $baseurl.'?acs' ], 'singleLogoutService' => [ 'url' => $baseurl.'?sls', ], - 'NameIDFormat' => $config['saml_nameid_format'], + 'NameIDFormat' => CAuthenticationHelper::get(CAuthenticationHelper::SAML_NAMEID_FORMAT), 'x509cert' => $sp_cert, 'privateKey' => $sp_key ], 'idp' => [ - 'entityId' => $config['saml_idp_entityid'], + 'entityId' => CAuthenticationHelper::get(CAuthenticationHelper::SAML_IDP_ENTITYID), 'singleSignOnService' => [ - 'url' => $config['saml_sso_url'], + 'url' => CAuthenticationHelper::get(CAuthenticationHelper::SAML_SSO_URL), ], 'singleLogoutService' => [ - 'url' => $config['saml_slo_url'], + 'url' => CAuthenticationHelper::get(CAuthenticationHelper::SAML_SLO_URL), ], 'x509cert' => $idp_cert ], 'security' => [ - 'nameIdEncrypted' => (bool) $config['saml_encrypt_nameid'], - 'authnRequestsSigned' => (bool) $config['saml_sign_authn_requests'], - 'logoutRequestSigned' => (bool) $config['saml_sign_logout_requests'], - 'logoutResponseSigned' => (bool) $config['saml_sign_logout_responses'], - 'wantMessagesSigned' => (bool) $config['saml_sign_messages'], - 'wantAssertionsEncrypted' => (bool) $config['saml_encrypt_assertions'], - 'wantAssertionsSigned' => (bool) $config['saml_sign_assertions'], - 'wantNameIdEncrypted' => (bool) $config['saml_encrypt_nameid'] + 'nameIdEncrypted' => (bool) CAuthenticationHelper::get(CAuthenticationHelper::SAML_ENCRYPT_NAMEID), + 'authnRequestsSigned' => (bool) CAuthenticationHelper::get(CAuthenticationHelper::SAML_SIGN_AUTHN_REQUESTS), + 'logoutRequestSigned' => (bool) CAuthenticationHelper::get(CAuthenticationHelper::SAML_SIGN_LOGOUT_REQUESTS), + 'logoutResponseSigned' => (bool) CAuthenticationHelper::get(CAuthenticationHelper::SAML_SIGN_LOGOUT_RESPONSES), + 'wantMessagesSigned' => (bool) CAuthenticationHelper::get(CAuthenticationHelper::SAML_SIGN_MESSAGES), + 'wantAssertionsEncrypted' => (bool) CAuthenticationHelper::get(CAuthenticationHelper::SAML_ENCRYPT_ASSERTIONS), + 'wantAssertionsSigned' => (bool) CAuthenticationHelper::get(CAuthenticationHelper::SAML_SIGN_ASSERTIONS), + 'wantNameIdEncrypted' => (bool) CAuthenticationHelper::get(CAuthenticationHelper::SAML_ENCRYPT_NAMEID) ] ]; @@ -177,14 +176,18 @@ try { $user_attributes = $auth->getAttributes(); - if (!array_key_exists($config['saml_username_attribute'], $user_attributes)) { + if (!array_key_exists(CAuthenticationHelper::get(CAuthenticationHelper::SAML_USERNAME_ATTRIBUTE), + $user_attributes + )) { throw new Exception( - _s('The parameter "%1$s" is missing from the user attributes.', $config['saml_username_attribute']) + _s('The parameter "%1$s" is missing from the user attributes.', CAuthenticationHelper::get(CAuthenticationHelper::SAML_USERNAME_ATTRIBUTE)) ); } CSession::setValue('saml_data', [ - 'username_attribute' => reset($user_attributes[$config['saml_username_attribute']]), + 'username_attribute' => reset( + $user_attributes[CAuthenticationHelper::get(CAuthenticationHelper::SAML_USERNAME_ATTRIBUTE)] + ), 'nameid' => $auth->getNameId(), 'nameid_format' => $auth->getNameIdFormat(), 'nameid_name_qualifier' => $auth->getNameIdNameQualifier(), @@ -197,7 +200,7 @@ try { } } - if ($config['saml_slo_url'] !== '') { + if (CAuthenticationHelper::get(CAuthenticationHelper::SAML_SLO_URL) !== '') { if (hasRequest('slo') && CSession::keyExists('saml_data')) { $saml_data = CSession::getValue('saml_data'); @@ -222,7 +225,8 @@ try { if (CSession::keyExists('saml_data')) { $saml_data = CSession::getValue('saml_data'); $user = API::getApiService('user')->loginByAlias($saml_data['username_attribute'], - ($config['saml_case_sensitive'] == ZBX_AUTH_CASE_SENSITIVE), $config['authentication_type'] + (CAuthenticationHelper::get(CAuthenticationHelper::SAML_CASE_SENSITIVE) == ZBX_AUTH_CASE_SENSITIVE), + CAuthenticationHelper::get(CAuthenticationHelper::AUTHENTICATION_TYPE) ); if ($user['gui_access'] == GROUP_GUI_ACCESS_DISABLED) { diff --git a/ui/items.php b/ui/items.php index 6963a06cdba..55e4caf736a 100644 --- a/ui/items.php +++ b/ui/items.php @@ -864,9 +864,8 @@ elseif (hasRequest('check_now') && hasRequest('itemid')) { // cleaning history for one item elseif (hasRequest('del_history') && hasRequest('itemid')) { $result = false; - $config = select_config(); - if ($config['compression_status']) { + if (CHousekeepingHelper::get(CHousekeepingHelper::COMPRESSION_STATUS)) { $error_message = _('History cleanup is not supported if compression is enabled'); } else { @@ -1278,9 +1277,8 @@ elseif (hasRequest('action') && getRequest('action') === 'item.masscopyto' && ha elseif (hasRequest('action') && getRequest('action') === 'item.massclearhistory' && hasRequest('group_itemid') && is_array(getRequest('group_itemid'))) { $result = false; - $config = select_config(); - if ($config['compression_status']) { + if (CHousekeepingHelper::get(CHousekeepingHelper::COMPRESSION_STATUS)) { $error_message = _('History cleanup is not supported if compression is enabled'); } else { @@ -1447,7 +1445,6 @@ if (isset($_REQUEST['form']) && str_in_array($_REQUEST['form'], ['create', 'upda $data = getItemFormData($item); $data['inventory_link'] = getRequest('inventory_link'); - $data['config'] = select_config(); $data['host'] = $host; $data['preprocessing_test_type'] = CControllerPopupItemTestEdit::ZBX_TEST_TYPE_ITEM; $data['preprocessing_types'] = CItem::$supported_preprocessing_types; @@ -1480,6 +1477,14 @@ if (isset($_REQUEST['form']) && str_in_array($_REQUEST['form'], ['create', 'upda $data['inventory_link'] = $item['inventory_link']; } + $data['config'] = [ + 'compression_status' => CHousekeepingHelper::get(CHousekeepingHelper::COMPRESSION_STATUS), + 'hk_history_global' => CHousekeepingHelper::get(CHousekeepingHelper::HK_HISTORY_GLOBAL), + 'hk_history' => CHousekeepingHelper::get(CHousekeepingHelper::HK_HISTORY), + 'hk_trends_global' => CHousekeepingHelper::get(CHousekeepingHelper::HK_TRENDS_GLOBAL), + 'hk_trends' => CHousekeepingHelper::get(CHousekeepingHelper::HK_TRENDS) + ]; + // render view if (!$has_errors) { echo (new CView('configuration.item.edit', $data))->getOutput(); @@ -1712,7 +1717,6 @@ else { 'form' => getRequest('form'), 'sort' => $sortField, 'sortorder' => $sortOrder, - 'config' => select_config(), 'hostid' => $hostid, 'is_template' => true ]; @@ -1731,7 +1735,7 @@ else { 'selectDiscoveryRule' => API_OUTPUT_EXTEND, 'selectItemDiscovery' => ['ts_delete'], 'sortfield' => $sortField, - 'limit' => $data['config']['search_limit'] + 1 + 'limit' => CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1 ]; $preFilter = count($options, COUNT_RECURSIVE); @@ -2038,6 +2042,10 @@ else { sort($filter_hostids); $data['checkbox_hash'] = crc32(implode('', $filter_hostids)); + $data['config'] = [ + 'compression_status' => CHousekeepingHelper::get(CHousekeepingHelper::COMPRESSION_STATUS) + ]; + // render view echo (new CView('configuration.item.list', $data))->getOutput(); } diff --git a/ui/jsrpc.php b/ui/jsrpc.php index 964756c388d..9c3ff8228f9 100644 --- a/ui/jsrpc.php +++ b/ui/jsrpc.php @@ -52,6 +52,7 @@ if (!is_array($data) || !isset($data['method']) } $result = []; +$limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT); switch ($data['method']) { case 'search': @@ -68,7 +69,9 @@ switch ($data['method']) { CSession::start(); if (!CSession::keyExists('serverCheckResult') || (CSession::getValue('serverCheckTime') + SERVER_CHECK_INTERVAL) <= time()) { - $zabbixServer = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, ZBX_SOCKET_TIMEOUT, 0); + $zabbixServer = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, + timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::SOCKET_TIMEOUT)), 0 + ); CSession::setValue('serverCheckResult', $zabbixServer->isRunning(CWebUser::getSessionCookie())); CSession::setValue('serverCheckTime', time()); } @@ -97,13 +100,12 @@ switch ($data['method']) { break; case 'trigger.get': - $config = select_config(); $result = []; $triggers = API::Trigger()->get([ 'output' => ['triggerid', 'priority'], 'triggerids' => $data['triggerids'], - 'limit' => $config['search_limit'] + 'limit' => $limit ]); if ($triggers) { @@ -129,8 +131,6 @@ switch ($data['method']) { * @return array(int => array('value' => int, 'text' => string)) */ case 'multiselect.get': - $config = select_config(); - switch ($data['object_name']) { case 'hostGroup': $options = [ @@ -181,7 +181,7 @@ switch ($data['method']) { 'with_triggers' => array_key_exists('with_triggers', $data) ? $data['with_triggers'] : null, 'search' => array_key_exists('search', $data) ? ['name' => $data['search']] : null, 'editable' => array_key_exists('editable', $data) ? $data['editable'] : false, - 'limit' => $config['search_limit'] + 'limit' => CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) ]; if ($data['object_name'] === 'host_templates') { @@ -225,7 +225,7 @@ switch ($data['method']) { 'templated' => array_key_exists('real_hosts', $data) ? false : null, 'search' => array_key_exists('search', $data) ? ['name' => $data['search']] : null, 'filter' => array_key_exists('filter', $data) ? $data['filter'] : null, - 'limit' => $config['search_limit'] + 'limit' => CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) ]; if ($data['object_name'] === 'item_prototypes') { @@ -266,7 +266,7 @@ switch ($data['method']) { 'templated' => array_key_exists('real_hosts', $data) ? false : null, 'search' => array_key_exists('search', $data) ? ['name' => $data['search']] : null, 'filter' => array_key_exists('filter', $data) ? $data['filter'] : null, - 'limit' => $config['search_limit'] + 'limit' => CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) ]; if ($data['object_name'] === 'graph_prototypes') { @@ -296,7 +296,7 @@ switch ($data['method']) { 'editable' => isset($data['editable']) ? $data['editable'] : false, 'output' => ['templateid', 'name'], 'search' => isset($data['search']) ? ['name' => $data['search']] : null, - 'limit' => $config['search_limit'] + 'limit' => $limit ]); if ($templates) { @@ -316,7 +316,7 @@ switch ($data['method']) { $proxies = API::Proxy()->get([ 'output' => ['proxyid', 'host'], 'search' => array_key_exists('search', $data) ? ['host' => $data['search']] : null, - 'limit' => $config['search_limit'] + 'limit' => $limit ]); if ($proxies) { @@ -335,7 +335,7 @@ switch ($data['method']) { 'output' => ['applicationid', 'name'], 'hostids' => zbx_toArray($data['hostid']), 'search' => isset($data['search']) ? ['name' => $data['search']] : null, - 'limit' => $config['search_limit'] + 'limit' => $limit ]); if ($applications) { @@ -356,7 +356,7 @@ switch ($data['method']) { 'output' => [], 'selectApplicationPrototypes' => ['application_prototypeid', 'name'], 'itemids' => [$data['parent_discoveryid']], - 'limitSelects' => $config['search_limit'] + 'limitSelects' => $limit ]); if ($discovery_rules) { @@ -394,7 +394,7 @@ switch ($data['method']) { 'editable' => isset($data['editable']) ? $data['editable'] : false, 'monitored' => isset($data['monitored']) ? $data['monitored'] : null, 'search' => isset($data['search']) ? ['description' => $data['search']] : null, - 'limit' => $config['search_limit'] + 'limit' => $limit ]); if ($triggers) { @@ -447,7 +447,7 @@ switch ($data['method']) { ] : null, 'searchByAny' => true, - 'limit' => $config['search_limit'] + 'limit' => $limit ]); if ($users) { @@ -472,7 +472,7 @@ switch ($data['method']) { $groups = API::UserGroup()->get([ 'output' => ['usrgrpid', 'name'], 'search' => array_key_exists('search', $data) ? ['name' => $data['search']] : null, - 'limit' => $config['search_limit'] + 'limit' => $limit ]); if ($groups) { @@ -493,7 +493,7 @@ switch ($data['method']) { 'output' => ['druleid', 'name'], 'search' => array_key_exists('search', $data) ? ['name' => $data['search']] : null, 'filter' => ['status' => DRULE_STATUS_ACTIVE], - 'limit' => $config['search_limit'] + 'limit' => $limit ]); if ($drules) { @@ -513,7 +513,6 @@ switch ($data['method']) { break; case 'patternselect.get': - $config = select_config(); $search = (array_key_exists('search', $data) && $data['search'] !== '') ? $data['search'] : null; $wildcard_enabled = (strpos($search, '*') !== false); $result = []; @@ -525,7 +524,7 @@ switch ($data['method']) { 'search' => ['name' => $search.($wildcard_enabled ? '*' : '')], 'searchWildcardsEnabled' => $wildcard_enabled, 'preservekeys' => true, - 'limit' => $config['search_limit'] + 'limit' => CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) ]; $db_result = API::Host()->get($options); @@ -542,7 +541,7 @@ switch ($data['method']) { ], 'templated' => array_key_exists('real_hosts', $data) ? false : null, 'webitems' => array_key_exists('webitems', $data) ? $data['webitems'] : null, - 'limit' => $config['search_limit'] + 'limit' => CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) ]; $db_result = API::Item()->get($options); @@ -555,7 +554,7 @@ switch ($data['method']) { 'hostids' => array_key_exists('hostid', $data) ? $data['hostid'] : null, 'templated' => array_key_exists('real_hosts', $data) ? false : null, 'searchWildcardsEnabled' => $wildcard_enabled, - 'limit' => $config['search_limit'] + 'limit' => CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) ]; $db_result = API::Graph()->get($options); diff --git a/ui/maintenance.php b/ui/maintenance.php index 024ac8855c5..f6dd4232a31 100644 --- a/ui/maintenance.php +++ b/ui/maintenance.php @@ -341,8 +341,6 @@ else { $filter_groupids = getSubGroups($filter_groupids); } - $config = select_config(); - $data = [ 'sort' => $sortField, 'sortorder' => $sortOrder, @@ -361,7 +359,7 @@ else { 'editable' => true, 'sortfield' => $sortField, 'sortorder' => $sortOrder, - 'limit' => $config['search_limit'] + 1 + 'limit' => CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1 ]; $data['maintenances'] = API::Maintenance()->get($options); diff --git a/ui/overview.php b/ui/overview.php index 717a78cbcd5..cf566e9c894 100644 --- a/ui/overview.php +++ b/ui/overview.php @@ -57,7 +57,6 @@ $fields = [ ]; check_fields($fields); -$config = select_config(); if (hasRequest('filter_set')) { CProfile::update('web.overview.filter.show_triggers', getRequest('show_triggers', TRIGGERS_OPTION_RECENT_PROBLEM), PROFILE_TYPE_INT @@ -128,7 +127,6 @@ if (hasRequest('view_style')) { $data = [ 'type' => $type, 'view_style' => CProfile::get('web.overview.view_style', STYLE_TOP), - 'config' => $config, 'profileIdx' => 'web.overview.filter', 'active_tab' => CProfile::get('web.overview.filter.active', 1), 'db_hosts' => [], @@ -220,6 +218,10 @@ if ($type == SHOW_TRIGGERS) { $data['filter'] = $filter; + $data['config'] = [ + 'blink_period' => CSettingsHelper::get(CSettingsHelper::BLINK_PERIOD) + ]; + // Render view. echo (new CView('monitoring.overview.triggers', $data))->getOutput(); } diff --git a/ui/queue.php b/ui/queue.php index 87232b33707..15325978be6 100644 --- a/ui/queue.php +++ b/ui/queue.php @@ -46,13 +46,17 @@ $config = getRequest('config', CProfile::get('web.queue.config', 0)); CProfile::update('web.queue.config', $config, PROFILE_TYPE_INT); // fetch data -$zabbixServer = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, ZBX_SOCKET_TIMEOUT, ZBX_SOCKET_BYTES_LIMIT); +$zabbixServer = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, + timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::SOCKET_TIMEOUT)), ZBX_SOCKET_BYTES_LIMIT +); $queueRequests = [ QUEUE_OVERVIEW => CZabbixServer::QUEUE_OVERVIEW, QUEUE_OVERVIEW_BY_PROXY => CZabbixServer::QUEUE_OVERVIEW_BY_PROXY, QUEUE_DETAILS => CZabbixServer::QUEUE_DETAILS ]; -$queueData = $zabbixServer->getQueue($queueRequests[$config], get_cookie(ZBX_SESSION_NAME), QUEUE_DETAIL_ITEM_COUNT); +$queueData = $zabbixServer->getQueue($queueRequests[$config], get_cookie(ZBX_SESSION_NAME), CSettingsHelper::get( + CSettingsHelper::SEARCH_LIMIT +)); // check for errors error if ($zabbixServer->getError()) { @@ -85,8 +89,6 @@ $widget = (new CWidget()) $table = new CTableInfo(); -$severityConfig = select_config(); - // overview if ($config == QUEUE_OVERVIEW) { $itemTypes = [ @@ -136,22 +138,22 @@ if ($config == QUEUE_OVERVIEW) { $table->addRow([ item_type2str($type), - getSeverityCell(TRIGGER_SEVERITY_NOT_CLASSIFIED, $severityConfig, $itemTypeData['delay5'], + getSeverityCell(TRIGGER_SEVERITY_NOT_CLASSIFIED, $itemTypeData['delay5'], !$itemTypeData['delay5'] ), - getSeverityCell(TRIGGER_SEVERITY_INFORMATION, $severityConfig, $itemTypeData['delay10'], + getSeverityCell(TRIGGER_SEVERITY_INFORMATION, $itemTypeData['delay10'], !$itemTypeData['delay10'] ), - getSeverityCell(TRIGGER_SEVERITY_WARNING, $severityConfig, $itemTypeData['delay30'], + getSeverityCell(TRIGGER_SEVERITY_WARNING, $itemTypeData['delay30'], !$itemTypeData['delay30'] ), - getSeverityCell(TRIGGER_SEVERITY_AVERAGE, $severityConfig, $itemTypeData['delay60'], + getSeverityCell(TRIGGER_SEVERITY_AVERAGE, $itemTypeData['delay60'], !$itemTypeData['delay60'] ), - getSeverityCell(TRIGGER_SEVERITY_HIGH, $severityConfig, $itemTypeData['delay300'], + getSeverityCell(TRIGGER_SEVERITY_HIGH, $itemTypeData['delay300'], !$itemTypeData['delay300'] ), - getSeverityCell(TRIGGER_SEVERITY_DISASTER, $severityConfig, $itemTypeData['delay600'], + getSeverityCell(TRIGGER_SEVERITY_DISASTER, $itemTypeData['delay600'], !$itemTypeData['delay600'] ) ]); @@ -198,16 +200,16 @@ elseif ($config == QUEUE_OVERVIEW_BY_PROXY) { $table->addRow([ $proxy['host'], - getSeverityCell(TRIGGER_SEVERITY_NOT_CLASSIFIED, $severityConfig, $proxyData['delay5'], + getSeverityCell(TRIGGER_SEVERITY_NOT_CLASSIFIED, $proxyData['delay5'], !$proxyData['delay5'] ), - getSeverityCell(TRIGGER_SEVERITY_INFORMATION, $severityConfig, $proxyData['delay10'], + getSeverityCell(TRIGGER_SEVERITY_INFORMATION, $proxyData['delay10'], !$proxyData['delay10'] ), - getSeverityCell(TRIGGER_SEVERITY_WARNING, $severityConfig, $proxyData['delay30'], !$proxyData['delay30']), - getSeverityCell(TRIGGER_SEVERITY_AVERAGE, $severityConfig, $proxyData['delay60'], !$proxyData['delay60']), - getSeverityCell(TRIGGER_SEVERITY_HIGH, $severityConfig, $proxyData['delay300'], !$proxyData['delay300']), - getSeverityCell(TRIGGER_SEVERITY_DISASTER, $severityConfig, $proxyData['delay600'], !$proxyData['delay600']) + getSeverityCell(TRIGGER_SEVERITY_WARNING, $proxyData['delay30'], !$proxyData['delay30']), + getSeverityCell(TRIGGER_SEVERITY_AVERAGE, $proxyData['delay60'], !$proxyData['delay60']), + getSeverityCell(TRIGGER_SEVERITY_HIGH, $proxyData['delay300'], !$proxyData['delay300']), + getSeverityCell(TRIGGER_SEVERITY_DISASTER, $proxyData['delay600'], !$proxyData['delay600']) ]); } } @@ -279,9 +281,12 @@ elseif ($config == QUEUE_DETAILS) { continue; } - // display only the first QUEUE_DETAIL_ITEM_COUNT items (can only occur when using old server versions) + /** + * Display only the first CSettingsHelper::SEARCH_LIMIT items (can only occur when using old server + * versions). + */ $i++; - if ($i > QUEUE_DETAIL_ITEM_COUNT) { + if ($i > CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT)) { break; } diff --git a/ui/report2.php b/ui/report2.php index b6a42aa192a..cbc87b25a67 100644 --- a/ui/report2.php +++ b/ui/report2.php @@ -144,8 +144,6 @@ $timeselector_options = [ ]; updateTimeSelectorPeriod($timeselector_options); -$config = select_config(); - /* * Header */ @@ -347,6 +345,7 @@ else { if ($templated_triggers_all) { // Select monitored host triggers, derived from templates and belonging to the requested groups. + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1; $triggers = API::Trigger()->get([ 'output' => ['triggerid', 'description', 'expression', 'value'], 'selectHosts' => ['name'], @@ -354,7 +353,7 @@ else { 'monitored' => true, 'groupids' => ($data['filter']['hostgroupid'] == 0) ? null : array_keys($hostgroupids), 'filter' => ['templateid' => array_keys($templated_triggers_all)], - 'limit' => $config['search_limit'] + 1 + 'limit' => $limit ]); } else { @@ -407,6 +406,7 @@ else { // Select monitored host triggers, derived from templates and belonging to the requested groups. $groups = enrichParentGroups($data['filter']['groups']); + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1; $triggers = API::Trigger()->get([ 'output' => ['triggerid', 'description', 'expression', 'value'], 'selectHosts' => ['name'], @@ -414,7 +414,7 @@ else { 'hostids' => $data['filter']['hostids'] ? array_keys($data['filter']['hostids']) : null, 'expandDescription' => true, 'monitored' => true, - 'limit' => $config['search_limit'] + 1 + 'limit' => $limit ]); $filter_column diff --git a/ui/screenconf.php b/ui/screenconf.php index b624eb08454..7af3141f769 100644 --- a/ui/screenconf.php +++ b/ui/screenconf.php @@ -369,20 +369,19 @@ else { CProfile::update('web.'.$page['file'].'.sort', $sortField, PROFILE_TYPE_STR); CProfile::update('web.'.$page['file'].'.sortorder', $sortOrder, PROFILE_TYPE_STR); - $config = select_config(); - $data = [ 'templateid' => getRequest('templateid'), 'sort' => $sortField, 'sortorder' => $sortOrder ]; + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1; if ($data['templateid']) { $data['screens'] = API::TemplateScreen()->get([ 'output' => ['screenid', 'name', 'hsize', 'vsize'], 'templateids' => $data['templateid'], 'sortfield' => $sortField, - 'limit' => $config['search_limit'] + 1, + 'limit' => $limit, 'editable' => true, 'preservekeys' => true ]); @@ -404,7 +403,7 @@ else { $data['screens'] = API::Screen()->get([ 'output' => ['screenid', 'name', 'hsize', 'vsize'], 'sortfield' => $sortField, - 'limit' => $config['search_limit'] + 1, + 'limit' => $limit, 'search' => [ 'name' => ($data['filter']['name'] === '') ? null : $data['filter']['name'] ], diff --git a/ui/slideconf.php b/ui/slideconf.php index 4050a259ad0..f01f9092d26 100644 --- a/ui/slideconf.php +++ b/ui/slideconf.php @@ -364,8 +364,7 @@ else { DBend(); } - $config = select_config(); - $limit = $config['search_limit'] + 1; + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1; $data = [ 'filter' => [ diff --git a/ui/sysmaps.php b/ui/sysmaps.php index 2eb0253da5d..96c2ec0de08 100644 --- a/ui/sysmaps.php +++ b/ui/sysmaps.php @@ -346,9 +346,6 @@ if (hasRequest('form')) { $data['current_user_userid'] = $current_userid; $data['form_refresh'] = getRequest('form_refresh'); - // config - $data['config'] = select_config(); - // advanced labels $data['labelTypes'] = sysmapElementLabel(); $data['labelTypesLimited'] = $data['labelTypes']; @@ -391,8 +388,6 @@ else { DBend(); } - $config = select_config(); - $data = [ 'filter' => [ 'name' => CProfile::get('web.sysmapconf.filter_name', '') @@ -404,10 +399,11 @@ else { ]; // get maps + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1; $data['maps'] = API::Map()->get([ 'output' => ['sysmapid', 'name', 'width', 'height'], 'sortfield' => $sortField, - 'limit' => $config['search_limit'] + 1, + 'limit' => $limit, 'search' => [ 'name' => ($data['filter']['name'] === '') ? null : $data['filter']['name'] ], diff --git a/ui/templates.php b/ui/templates.php index f575d1c2414..bacdfc6215b 100644 --- a/ui/templates.php +++ b/ui/templates.php @@ -1032,8 +1032,6 @@ else { ]; } - $config = select_config(); - $filter['templates'] = $filter['templates'] ? CArrayHelper::renameObjectsKeys(API::Template()->get([ 'output' => ['templateid', 'name'], @@ -1058,6 +1056,7 @@ else { } // Select templates. + $limit = CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1; $templates = API::Template()->get([ 'output' => ['templateid', $sortField], 'evaltype' => $filter['evaltype'], @@ -1069,7 +1068,7 @@ else { 'groupids' => $filter_groupids, 'editable' => true, 'sortfield' => $sortField, - 'limit' => $config['search_limit'] + 1 + 'limit' => $limit ]); order_result($templates, $sortField, $sortOrder); @@ -1150,14 +1149,14 @@ else { 'filter' => $filter, 'sortField' => $sortField, 'sortOrder' => $sortOrder, - 'config' => [ - 'max_in_table' => $config['max_in_table'] - ], 'editable_templates' => $editable_templates, 'editable_hosts' => $editable_hosts, 'profileIdx' => 'web.templates.filter', 'active_tab' => CProfile::get('web.templates.filter.active', 1), - 'tags' => makeTags($templates, true, 'templateid', ZBX_TAG_COUNT_DEFAULT, $filter['tags']) + 'tags' => makeTags($templates, true, 'templateid', ZBX_TAG_COUNT_DEFAULT, $filter['tags']), + 'config' => [ + 'max_in_table' => CSettingsHelper::get(CSettingsHelper::MAX_IN_TABLE) + ] ]; $view = new CView('configuration.template.list', $data); diff --git a/ui/tests/include/CIntegrationTest.php b/ui/tests/include/CIntegrationTest.php index d6976e256ed..30f313001e5 100644 --- a/ui/tests/include/CIntegrationTest.php +++ b/ui/tests/include/CIntegrationTest.php @@ -570,7 +570,7 @@ class CIntegrationTest extends CAPITest { } return new CZabbixClient('localhost', self::getConfigurationValue($component, 'ListenPort', 10051), - ZBX_SOCKET_TIMEOUT, ZBX_SOCKET_BYTES_LIMIT + timeUnitToSeconds(CSettingsHelper::get(CSettingsHelper::SOCKET_TIMEOUT)), ZBX_SOCKET_BYTES_LIMIT ); } diff --git a/ui/tests/include/web/elements/COverlayDialogElement.php b/ui/tests/include/web/elements/COverlayDialogElement.php index 20b044040e4..d3b18973fef 100644 --- a/ui/tests/include/web/elements/COverlayDialogElement.php +++ b/ui/tests/include/web/elements/COverlayDialogElement.php @@ -36,7 +36,7 @@ class COverlayDialogElement extends CElement { * @inheritdoc */ public static function find() { - return (new CElementQuery('xpath://div[contains(@class, "overlay-dialogue modal modal-popup")]'))->asOverlayDialog(); + return (new CElementQuery('xpath://div['.CXPathHelper::fromClass('overlay-dialogue modal').']'))->asOverlayDialog(); } /** diff --git a/ui/tests/selenium/SeleniumTests.php b/ui/tests/selenium/SeleniumTests.php index 791246fea38..6a85d4b9d78 100644 --- a/ui/tests/selenium/SeleniumTests.php +++ b/ui/tests/selenium/SeleniumTests.php @@ -82,9 +82,7 @@ require_once dirname(__FILE__).'/testFormAdministrationGeneralMacro.php'; require_once dirname(__FILE__).'/testFormAdministrationGeneralOtherParams.php'; require_once dirname(__FILE__).'/testFormAdministrationGeneralRegexp.php'; require_once dirname(__FILE__).'/testFormAdministrationGeneralTrigDisplOptions.php'; -require_once dirname(__FILE__).'/testFormAdministrationGeneralTriggerSeverities.php'; require_once dirname(__FILE__).'/testFormAdministrationGeneralValuemap.php'; -require_once dirname(__FILE__).'/testFormAdministrationGeneralWorkperiod.php'; require_once dirname(__FILE__).'/testFormAdministrationGeneralInstallation.php'; require_once dirname(__FILE__).'/testFormAdministrationMediaTypes.php'; require_once dirname(__FILE__).'/testFormAdministrationMediaTypeMessageTemplates.php'; @@ -229,9 +227,7 @@ class SeleniumTests { $suite->addTestSuite('testFormAdministrationGeneralOtherParams'); $suite->addTestSuite('testFormAdministrationGeneralRegexp'); $suite->addTestSuite('testFormAdministrationGeneralTrigDisplOptions'); - $suite->addTestSuite('testFormAdministrationGeneralTriggerSeverities'); $suite->addTestSuite('testFormAdministrationGeneralValuemap'); - $suite->addTestSuite('testFormAdministrationGeneralWorkperiod'); $suite->addTestSuite('testFormAdministrationGeneralInstallation'); $suite->addTestSuite('testFormAdministrationMediaTypes'); $suite->addTestSuite('testFormAdministrationMediaTypeMessageTemplates'); diff --git a/ui/tests/selenium/testFormAdministrationGeneralGUI.php b/ui/tests/selenium/testFormAdministrationGeneralGUI.php index 15174464785..0429276518a 100644 --- a/ui/tests/selenium/testFormAdministrationGeneralGUI.php +++ b/ui/tests/selenium/testFormAdministrationGeneralGUI.php @@ -19,225 +19,921 @@ **/ require_once dirname(__FILE__).'/../include/CLegacyWebTest.php'; +require_once dirname(__FILE__).'/behaviors/CMessageBehavior.php'; /** * @backup config */ -class testFormAdministrationGeneralGUI extends CLegacyWebTest { - - public static function allValues() { - return CDBHelper::getDataProvider( - 'SELECT default_theme,search_limit,max_in_table,server_check_interval'. - ' FROM config'. - ' ORDER BY configid' - ); - } +class testFormAdministrationGeneralGUI extends CWebTest { + + private $default = [ + 'Default language' => 'English (en_GB)', + 'Default time zone' => 'System', + 'Default theme' => 'Blue', + 'Limit for search and filter results' => '1000', + 'Max number of columns and rows in overview tables' => '50', + 'Max count of elements to show inside table cell' => '50', + 'Show warning if Zabbix server is down' => true, + 'Working time' => '1-5,09:00-18:00', + 'Show technical errors' => false, + 'Max history display period' => '24h', + 'Time filter default period' => '1h', + 'Max period' => '2y' + ]; + + private $db_default = [ + 'default_lang' => 'en_GB', + 'default_timezone' => 'system', + 'default_theme' => 'blue-theme', + 'search_limit' => 1000, + 'max_overview_table_size' => 50, + 'max_in_table' => 50, + 'server_check_interval' => 10, + 'work_period' => '1-5,09:00-18:00', + 'show_technical_errors' => 0, + 'history_period' => '24h', + 'period_default' => '1h', + 'max_period' => '2y' + ]; + + private $custom = [ + 'Default language' => 'English (en_US)', + 'Default theme' => 'Dark', + 'Limit for search and filter results' => '50', + 'Max number of columns and rows in overview tables' => '25', + 'Max count of elements to show inside table cell' => '100', + 'Show warning if Zabbix server is down' => false, + 'Working time' => '1-3,03:15-22:45', + 'Show technical errors' => true, + 'Max history display period' => '24h', + 'Time filter default period' => '1h', + 'Max period' => '2y' + ]; /** - * @dataProvider allValues - */ - public function testFormAdministrationGeneralGUI_CheckLayout($allValues) { - - $this->zbxTestLogin('zabbix.php?action=gui.edit'); - $this->query('id:page-title-general')->asPopupButton()->one()->select('GUI'); - $this->zbxTestCheckTitle('Configuration of GUI'); - $this->zbxTestCheckHeader('GUI'); - $this->zbxTestTextPresent([ - 'Default theme', - 'Limit for search and filter results', - 'Max count of elements to show inside table cell', - 'Show warning if Zabbix server is down' - ]); - - $this->zbxTestDropdownHasOptions('default_theme', ['Blue', 'Dark']); - - $this->zbxTestAssertElementPresentId('search_limit'); - $this->zbxTestAssertAttribute('//input[@id="search_limit"]', 'maxlength', '6'); - $this->zbxTestAssertElementPresentId('max_in_table'); - $this->zbxTestAssertAttribute('//input[@id="max_in_table"]','maxlength', '5'); - - $this->zbxTestAssertElementPresentId('server_check_interval'); - - $this->zbxTestAssertElementPresentId('update'); - - $this->zbxTestAssertAttribute("//select[@id='default_theme']/option[@selected='selected']", "value", $allValues['default_theme']); + * Attach MessageBehavior to the test. + * + * @return array + */ + public function getBehaviors() { + return [ + CMessageBehavior::class + ]; + } - if ($allValues['server_check_interval']) { - $this->assertTrue($this->zbxTestCheckboxSelected('server_check_interval')); - } - if ($allValues['server_check_interval']==0) { - $this->assertFalse($this->zbxTestCheckboxSelected('server_check_interval')); + public function testFormAdministrationGeneralGUI_CheckLayout() { + $this->page->login()->open('zabbix.php?action=gui.edit'); + $this->assertPageTitle('Configuration of GUI'); + $this->assertPageHeader('GUI'); + + $limits = [ + 'search_limit' => 6, + 'max_overview_table_size' => 6, + 'max_in_table' => 5, + 'work_period' => 255, + 'history_period' => 32, + 'period_default' => 32, + 'max_period' => 32 + ]; + foreach ($limits as $id => $limit) { + $this->assertEquals($limit, $this->query('id', $id)->one()->getAttribute('maxlength')); } - $this->zbxTestAssertElementValue('search_limit', $allValues['search_limit']); - $this->zbxTestAssertElementValue('max_in_table', $allValues['max_in_table']); + $this->query('xpath://span[@class="icon-info status-red"]')->one()->click(); + $this->assertEquals( + 'You are not able to choose some of the languages,'. + ' because locales for them are not installed on the web server.', + $this->query('class:red')->one()->getText() + ); } - public function testFormAdministrationGeneralGUI_ChangeTheme() { - - $this->zbxTestLogin('zabbix.php?action=gui.edit'); - $sql_hash = 'SELECT '.CDBHelper::getTableFields('config', ['default_theme']).' FROM config ORDER BY configid'; - $old_hash = CDBHelper::getHash($sql_hash); + public function testFormAdministrationGeneralGUI_SimpleUpdate() { + $sqlHash = 'SELECT * FROM config ORDER BY configid'; + $oldHash = CDBHelper::getHash($sqlHash); - $this->zbxTestDropdownSelect('default_theme', 'Dark'); - $this->zbxTestAssertElementValue('default_theme', 'dark-theme'); - $this->zbxTestClickWait('update'); - $this->zbxTestTextPresent(['Configuration updated', 'GUI', 'Default theme']); - $sql = 'SELECT default_theme FROM config WHERE default_theme='.zbx_dbstr('dark-theme'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: "Dark" theme can not be selected as default theme: it does not exist in the DB'); - - $this->zbxTestDropdownSelect('default_theme', 'Blue'); - $this->zbxTestAssertElementValue('default_theme', 'blue-theme'); - $this->zbxTestClickWait('update'); - $this->zbxTestTextPresent(['Configuration updated', 'GUI', 'Default theme']); - $sql = 'SELECT default_theme FROM config WHERE default_theme='.zbx_dbstr('blue-theme'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: "Blue" theme can not be selected as default theme: it does not exist in the DB'); - - $this->assertEquals($old_hash, CDBHelper::getHash($sql_hash)); + $this->page->login()->open('zabbix.php?action=gui.edit'); + $form = $this->query('xpath://form[contains(@action, "gui.update")]')->waitUntilPresent()->asForm()->one(); + $form->submit(); + $this->page->waitUntilReady(); + $this->assertMessage(TEST_GOOD, 'Configuration updated'); + $this->assertEquals($oldHash, CDBHelper::getHash($sqlHash)); } - public function testFormAdministrationGeneralGUI_ChangeSearchLimit() { - $this->zbxTestLogin('zabbix.php?action=gui.edit'); - $sql_hash = 'SELECT '.CDBHelper::getTableFields('config', ['search_limit']).' FROM config ORDER BY configid'; - $old_hash = CDBHelper::getHash($sql_hash); - - $this->zbxTestInputType('search_limit', '1000'); - $this->zbxTestClickWait('update'); - $this->zbxTestTextPresent(['Configuration updated', 'GUI', 'Limit for search and filter results']); - - $sql = 'SELECT search_limit FROM config WHERE search_limit=1000'; - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect value in the DB field "search_limit"'); - - $this->query('id:page-title-general')->asPopupButton()->one()->select('GUI'); - $this->zbxTestCheckTitle('Configuration of GUI'); - $this->zbxTestCheckHeader('GUI'); - $this->zbxTestInputTypeOverwrite('search_limit', '1'); - $this->zbxTestClickWait('update'); - $this->zbxTestTextPresent(['Configuration updated', 'GUI', 'Limit for search and filter results']); - - $sql = 'SELECT search_limit FROM config WHERE search_limit=1'; - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect value in the DB field "search_limit"'); - - $this->query('id:page-title-general')->asPopupButton()->one()->select('GUI'); - $this->zbxTestCheckTitle('Configuration of GUI'); - $this->zbxTestCheckHeader('GUI'); - $this->zbxTestInputTypeOverwrite('search_limit', '999999'); - $this->zbxTestClickWait('update'); - $this->zbxTestTextPresent(['Configuration updated', 'GUI', 'Limit for search and filter results']); - - $sql = 'SELECT search_limit FROM config WHERE search_limit=999999'; - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect value in the DB field "search_limit"'); - - // Check to enter 0 value - $this->query('id:page-title-general')->asPopupButton()->one()->select('GUI'); - $this->zbxTestCheckTitle('Configuration of GUI'); - $this->zbxTestCheckHeader('GUI'); - $this->zbxTestInputTypeOverwrite('search_limit', '0'); - $this->zbxTestClickWait('update'); - - $this->zbxTestTextPresent(['GUI', 'Limit for search and filter results']); - $this->zbxTestWaitUntilMessageTextPresent('msg-bad', 'Cannot update configuration'); - $this->zbxTestTextPresent('Incorrect value "0" for "search_limit" field.'); - $this->zbxTestTextNotPresent('Configuration updated'); - - // Check to enter -1 value - $this->query('id:page-title-general')->asPopupButton()->one()->select('GUI'); - $this->zbxTestCheckTitle('Configuration of GUI'); - $this->zbxTestCheckHeader('GUI'); - $this->zbxTestInputTypeOverwrite('search_limit', '-1'); - $this->zbxTestClickWait('update'); - - $this->zbxTestTextPresent(['GUI', 'Limit for search and filter results']); - $this->zbxTestTextPresent(['Cannot update configuration', 'Incorrect value "-1" for "search_limit" field.']); - $this->zbxTestTextNotPresent('Configuration updated'); - - $this->assertEquals($old_hash, CDBHelper::getHash($sql_hash)); + /** + * Test data for GUI form. + */ + public function getCheckFormData() { + return [ + [ + [ + 'expected' => TEST_GOOD, + 'fields' => [ + 'Default language' => 'English (en_US)', + 'Default time zone' => 'Africa/Bissau', + 'Default theme' => 'Dark', + 'Limit for search and filter results' => '1', + 'Max number of columns and rows in overview tables' => '5', + 'Max count of elements to show inside table cell' => '1', + 'Show warning if Zabbix server is down' => false, + 'Working time' => '1-1,00:00-00:01', + 'Show technical errors' => true, + // Minimal valid time in seconds with 's'. + 'Max history display period' => '86400s', + 'Time filter default period' => '60s', + 'Max period' => '31536000s' + ], + 'db' => [ + 'default_lang' => 'en_US', + 'default_timezone' => 'Africa/Bissau', + 'default_theme' => 'dark-theme', + 'search_limit' => 1, + 'max_overview_table_size' => 5, + 'max_in_table' => 1, + 'server_check_interval' => 0, + 'work_period' => '1-1,00:00-00:01', + 'show_technical_errors' => 1, + 'history_period' => '86400s', + 'period_default' => '60s', + 'max_period' => '31536000s' + ], + 'message' => 'Configuration updated' + ] + ], + [ + [ + 'expected' => TEST_GOOD, + 'fields' => [ + 'Working time' => '1-5,09:00-18:00;5-7,12:00-16:00', + // Minimal valid time in seconds without 's'. + 'Max history display period' => '86400', + 'Time filter default period' => '60', + 'Max period' => '31536000' + ], + 'db' => [ + 'work_period' => '1-5,09:00-18:00;5-7,12:00-16:00', + 'history_period' => '86400', + 'period_default' => '60', + 'max_period' => '31536000' + ], + 'message' => 'Configuration updated' + ] + ], + [ + [ + 'expected' => TEST_GOOD, + 'fields' => [ + // Minimal valid time in minutes. + 'Max history display period' => '1440m', + 'Time filter default period' => '1m', + 'Max period' => '525600m' + ], + 'db' => [ + 'history_period' => '1440m', + 'period_default' => '1m', + 'max_period' => '525600m' + ], + 'message' => 'Configuration updated' + ] + ], + [ + [ + 'expected' => TEST_GOOD, + 'fields' => [ + // Minimal valid time in hours. + 'Max history display period' => '24h', + 'Max period' => '8760h' + ], + 'db' => [ + 'history_period' => '24h', + 'max_period' => '8760h' + ], + 'message' => 'Configuration updated' + ] + ], + [ + [ + 'expected' => TEST_GOOD, + 'fields' => [ + // Minimal valid time in days. + 'Max history display period' => '1d', + 'Max period' => '365d' + ], + 'db' => [ + 'history_period' => '1d', + 'max_period' => '365d' + ], + 'message' => 'Configuration updated' + ] + ], + [ + [ + 'expected' => TEST_GOOD, + 'fields' => [ + // Minimal valid time in weeks. + 'Max period' => '53w' + ], + 'db' => [ + 'max_period' => '53w' + ], + 'message' => 'Configuration updated' + ] + ], + [ + [ + 'expected' => TEST_GOOD, + 'fields' => [ + // Minimal valid time in Months. + 'Max period' => '13M' + ], + 'db' => [ + 'max_period' => '13M' + ], + 'message' => 'Configuration updated' + ] + ], + [ + [ + 'expected' => TEST_GOOD, + 'fields' => [ + // Minimal valid time in years. + 'Max period' => '1y' + ], + 'db' => [ + 'max_period' => '1y' + ], + 'message' => 'Configuration updated' + ] + ], + [ + [ + 'expected' => TEST_GOOD, + 'fields' => [ + // Maximal valid time in seconds with 's'. + 'Max history display period' => '604800s', + 'Time filter default period' => '315360000s', + 'Max period' => '315360000s' + ], + 'db' => [ + 'history_period' => '604800s', + 'period_default' => '315360000s', + 'max_period' => '315360000s' + ], + 'message' => 'Configuration updated' + ] + ], + [ + [ + 'expected' => TEST_GOOD, + 'fields' => [ + 'Default time zone' => 'Europe/Riga', + 'Default theme' => 'High-contrast dark', + // Maximal valid time in seconds without 's'. + 'Max history display period' => '604800', + 'Time filter default period' => '315360000', + 'Max period' => '315360000' + ], + 'db' => [ + 'default_timezone' => 'Europe/Riga', + 'default_theme' => 'hc-dark', + 'history_period' => '604800', + 'period_default' => '315360000', + 'max_period' => '315360000' + ], + 'message' => 'Configuration updated' + ] + ], + [ + [ + 'expected' => TEST_GOOD, + 'fields' => [ + // Maximal valid time in minutes. + 'Max history display period' => '10080m', + 'Time filter default period' => '5256000m', + 'Max period' => '5256000m' + ], + 'db' => [ + 'history_period' => '10080m', + 'period_default' => '5256000m', + 'max_period' => '5256000m' + ], + 'message' => 'Configuration updated' + ] + ], + [ + [ + 'expected' => TEST_GOOD, + 'fields' => [ + // Maximal valid time in days. + 'Max history display period' => '7d', + 'Time filter default period' => '3650d', + 'Max period' => '3650d' + ], + 'db' => [ + 'history_period' => '7d', + 'period_default' => '3650d', + 'max_period' => '3650d' + ], + 'message' => 'Configuration updated' + ] + ], + [ + [ + 'expected' => TEST_GOOD, + 'fields' => [ + // Maximal valid time in weeks. + 'Max history display period' => '7d', + 'Time filter default period' => '3650d', + 'Max period' => '3650d' + ], + 'db' => [ + 'history_period' => '7d', + 'period_default' => '3650d', + 'max_period' => '3650d' + ], + 'message' => 'Configuration updated' + ] + ], + [ + [ + 'expected' => TEST_GOOD, + 'fields' => [ + // Maximal valid time in Months. + 'Time filter default period' => '121M', + 'Max period' => '121M' + ], + 'db' => [ + 'period_default' => '121M', + 'max_period' => '121M' + ], + 'message' => 'Configuration updated' + ] + ], + [ + [ + 'expected' => TEST_GOOD, + 'fields' => [ + 'Default time zone' => 'UTC', + 'Default theme' => 'High-contrast light', + 'Limit for search and filter results' => '999999', + 'Max number of columns and rows in overview tables' => '999999', + 'Max count of elements to show inside table cell' => '99999', + 'Working time' => '{$WORKING_HOURS}', + // Maximal valid time in years. + 'Time filter default period' => '10y', + 'Max period' => '10y' + ], + 'db' => [ + 'default_timezone' => 'UTC', + 'default_theme' => 'hc-light', + 'search_limit' => 999999, + 'max_overview_table_size' => 999999, + 'max_in_table' => 99999, + 'work_period' => '{$WORKING_HOURS}', + 'period_default' => '10y', + 'max_period' => '10y' + ], + 'message' => 'Configuration updated' + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + 'Limit for search and filter results' => '0', + 'Max number of columns and rows in overview tables' => '0', + 'Max count of elements to show inside table cell' => '0', + 'Working time' => '0', + 'Max history display period' => '0', + 'Time filter default period' => '0', + 'Max period' => '0' + ], + 'message' => 'Cannot update configuration', + 'details' => [ + 'Incorrect value for field "search_limit": value must be no less than "1".', + 'Incorrect value for field "max_overview_table_size": value must be no less than "5".', + 'Incorrect value for field "max_in_table": value must be no less than "1".', + 'Incorrect value for field "work_period": a time period is expected.', + 'Incorrect value for field "history_period": value must be one of 86400-604800.', + 'Incorrect value for field "period_default": value must be one of 60-315360000.', + 'Incorrect value for field "max_period": value must be one of 31536000-315360000.' + ] + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + 'Limit for search and filter results' => '', + 'Max number of columns and rows in overview tables' => '', + 'Max count of elements to show inside table cell' => '', + 'Working time' => '', + 'Max history display period' => '', + 'Time filter default period' => '', + 'Max period' => '' + ], + 'message' => 'Cannot update configuration', + 'details' => [ + 'Incorrect value for field "search_limit": value must be no less than "1".', + 'Incorrect value for field "max_overview_table_size": value must be no less than "5".', + 'Incorrect value for field "max_in_table": value must be no less than "1".', + 'Incorrect value for field "work_period": a time period is expected.', + 'Incorrect value for field "history_period": a time unit is expected.', + 'Incorrect value for field "period_default": a time unit is expected.', + 'Incorrect value for field "max_period": a time unit is expected.' + ] + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + 'Max number of columns and rows in overview tables' => '4', + 'Working time' => 'test', + // Minimal invalid time in seconds with "s". + 'Max history display period' => '86399s', + 'Time filter default period' => '59s', + 'Max period' => '31535999s' + ], + 'message' => 'Cannot update configuration', + 'details' => [ + 'Incorrect value for field "max_overview_table_size": value must be no less than "5".', + 'Incorrect value for field "work_period": a time period is expected.', + 'Incorrect value for field "history_period": value must be one of 86400-604800', + 'Incorrect value for field "period_default": value must be one of 60-315360000.', + 'Incorrect value for field "max_period": value must be one of 31536000-315360000.' + ] + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + // Minimal invalid time in seconds without "s". + 'Max history display period' => '86399', + 'Time filter default period' => '59', + 'Max period' => '31535999' + ], + 'message' => 'Cannot update configuration', + 'details' => [ + 'Incorrect value for field "history_period": value must be one of 86400-604800', + 'Incorrect value for field "period_default": value must be one of 60-315360000.', + 'Incorrect value for field "max_period": value must be one of 31536000-315360000.' + ] + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + // Minimal invalid time in minutes. + 'Max history display period' => '1439m', + 'Time filter default period' => '0m', + 'Max period' => '525599m' + ], + 'message' => 'Cannot update configuration', + 'details' => [ + 'Incorrect value for field "history_period": value must be one of 86400-604800', + 'Incorrect value for field "period_default": value must be one of 60-315360000.', + 'Incorrect value for field "max_period": value must be one of 31536000-315360000.' + ] + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + // Minimal invalid time in hours. + 'Max history display period' => '23h', + 'Time filter default period' => '0h', + 'Max period' => '8759h' + ], + 'message' => 'Cannot update configuration', + 'details' => [ + 'Incorrect value for field "history_period": value must be one of 86400-604800', + 'Incorrect value for field "period_default": value must be one of 60-315360000.', + 'Incorrect value for field "max_period": value must be one of 31536000-315360000.' + ] + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + // Minimal invalid time in weeks. + 'Max history display period' => '0w', + 'Time filter default period' => '0w', + 'Max period' => '52w' + ], + 'message' => 'Cannot update configuration', + 'details' => [ + 'Incorrect value for field "history_period": value must be one of 86400-604800', + 'Incorrect value for field "period_default": value must be one of 60-315360000.', + 'Incorrect value for field "max_period": value must be one of 31536000-315360000.' + ] + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + // Minimal invalid time in Month. + 'Max history display period' => '0M', + 'Time filter default period' => '0M', + 'Max period' => '12M' + ], + 'message' => 'Cannot update configuration', + 'details' => [ + 'Incorrect value for field "history_period": a time unit is expected.', + 'Incorrect value for field "period_default": value must be one of 60-315360000.', + 'Incorrect value for field "max_period": value must be one of 31536000-315360000.' + ] + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + // Minimal invalid time in years. + 'Time filter default period' => '0y', + 'Max period' => '0y' + ], + 'message' => 'Cannot update configuration', + 'details' => [ + 'Incorrect value for field "period_default": value must be one of 60-315360000.', + 'Incorrect value for field "max_period": value must be one of 31536000-315360000.' + ] + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + // Maximal invalid time in seconds without 's'. + 'Max history display period' => '604801', + 'Time filter default period' => '315360001', + 'Max period' => '315360001' + ], + 'message' => 'Cannot update configuration', + 'details' => [ + 'Incorrect value for field "history_period": value must be one of 86400-604800', + 'Incorrect value for field "period_default": value must be one of 60-315360000.', + 'Incorrect value for field "max_period": value must be one of 31536000-315360000.' + ] + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + // Maximal invalid time in seconds with 's'. + 'Max history display period' => '604801s', + 'Time filter default period' => '315360001s', + 'Max period' => '315360001s' + ], + 'message' => 'Cannot update configuration', + 'details' => [ + 'Incorrect value for field "history_period": value must be one of 86400-604800', + 'Incorrect value for field "period_default": value must be one of 60-315360000.', + 'Incorrect value for field "max_period": value must be one of 31536000-315360000.' + ] + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + // Maximal invalid time in minutes. + 'Max history display period' => '10081m', + 'Time filter default period' => '5256001m', + 'Max period' => '5256001m' + ], + 'message' => 'Cannot update configuration', + 'details' => [ + 'Incorrect value for field "history_period": value must be one of 86400-604800', + 'Incorrect value for field "period_default": value must be one of 60-315360000.', + 'Incorrect value for field "max_period": value must be one of 31536000-315360000.' + ] + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + + // Maximal invalid time in hours. + 'Max history display period' => '169h', + 'Time filter default period' => '87601h', + 'Max period' => '87601h' + ], + 'message' => 'Cannot update configuration', + 'details' => [ + 'Incorrect value for field "history_period": value must be one of 86400-604800', + 'Incorrect value for field "period_default": value must be one of 60-315360000.', + 'Incorrect value for field "max_period": value must be one of 31536000-315360000.' + ] + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + // Maximal invalid time in days. + 'Max history display period' => '8d', + 'Time filter default period' => '3651d', + 'Max period' => '3651d' + ], + 'message' => 'Cannot update configuration', + 'details' => [ + 'Incorrect value for field "history_period": value must be one of 86400-604800', + 'Incorrect value for field "period_default": value must be one of 60-315360000.', + 'Incorrect value for field "max_period": value must be one of 31536000-315360000.' + ] + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + // Maximal invalid time in weeks. + 'Max history display period' => '2w', + 'Time filter default period' => '522w', + 'Max period' => '522w' + ], + 'message' => 'Cannot update configuration', + 'details' => [ + 'Incorrect value for field "history_period": value must be one of 86400-604800', + 'Incorrect value for field "period_default": value must be one of 60-315360000.', + 'Incorrect value for field "max_period": value must be one of 31536000-315360000.' + ] + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + // Maximal invalid time in months. + 'Time filter default period' => '122M', + 'Max period' => '122M' + ], + 'message' => 'Cannot update configuration', + 'details' => [ + 'Incorrect value for field "period_default": value must be one of 60-315360000.', + 'Incorrect value for field "max_period": value must be one of 31536000-315360000.' + ] + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + // Maximal invalid time in years. + 'Time filter default period' => '11y', + 'Max period' => '11y' + ], + 'message' => 'Cannot update configuration', + 'details' => [ + 'Incorrect value for field "period_default": value must be one of 60-315360000.', + 'Incorrect value for field "max_period": value must be one of 31536000-315360000.' + ] + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + 'Max history display period' => '99999999999999999999999999999999', + 'Time filter default period' => '99999999999999999999999999999999', + 'Max period' => '99999999999999999999999999999999' + ], + 'message' => 'Cannot update configuration', + 'details' => [ + 'Incorrect value for field "history_period": value must be one of 86400-604800', + 'Incorrect value for field "period_default": value must be one of 60-315360000.', + 'Incorrect value for field "max_period": value must be one of 31536000-315360000.' + ] + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + 'Time filter default period' => '10y', + 'Max period' => '5y' + ], + 'message' => 'Cannot update configuration', + 'details' => [ + 'Incorrect value for field "period_default": time filter default period exceeds the max period.' + ] + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + 'Working time' => '1-7 09:00-24:00' + ], + 'message' => 'Cannot update configuration', + 'details' => 'Incorrect value for field "work_period": a time period is expected.' + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + 'Working time' => '0-7,09:00-24:00' + ], + 'message' => 'Cannot update configuration', + 'details' => 'Incorrect value for field "work_period": a time period is expected.' + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + 'Working time' => '1-5,09:00-18:00,6-7,10:00-16:00' + ], + 'message' => 'Cannot update configuration', + 'details' => 'Incorrect value for field "work_period": a time period is expected.' + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + 'Working time' => '1-8,09:00-24:00' + ], + 'message' => 'Cannot update configuration', + 'details' => 'Incorrect value for field "work_period": a time period is expected.' + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + 'Working time' => '1-7,09:00-25:00' + ], + 'message' => 'Cannot update configuration', + 'details' => 'Incorrect value for field "work_period": a time period is expected.' + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + 'Working time' => '1-7,24:00-00:00' + ], + 'message' => 'Cannot update configuration', + 'details' => 'Incorrect value for field "work_period": a time period is expected.' + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + 'Working time' => '1-7,14:00-13:00' + ], + 'message' => 'Cannot update configuration', + 'details' => 'Incorrect value for field "work_period": a time period is expected.' + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + 'Working time' => '1-7,25:00-26:00' + ], + 'message' => 'Cannot update configuration', + 'details' => 'Incorrect value for field "work_period": a time period is expected.' + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + 'Working time' => '1-7,13:60-14:00' + ], + 'message' => 'Cannot update configuration', + 'details' => 'Incorrect value for field "work_period": a time period is expected.' + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + 'Working time' => '1-0' + ], + 'message' => 'Cannot update configuration', + 'details' => 'Incorrect value for field "work_period": a time period is expected.' + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + 'Working time' => '09:00-24:00' + ], + 'message' => 'Cannot update configuration', + 'details' => 'Incorrect value for field "work_period": a time period is expected.' + ] + ], + [ + [ + 'expected' => TEST_BAD, + 'fields' => [ + 'Working time' => '{WORKING_HOURS}' + ], + 'message' => 'Cannot update configuration', + 'details' => 'Incorrect value for field "work_period": a time period is expected.' + ] + ] + ]; } - public function testFormAdministrationGeneralGUI_ChangeMaxInTable() { - $sql_hash = 'SELECT '.CDBHelper::getTableFields('config', ['max_in_table']).' FROM config ORDER BY configid'; - $old_hash = CDBHelper::getHash($sql_hash); - - $this->zbxTestLogin('zabbix.php?action=gui.edit'); - $this->zbxTestInputTypeOverwrite('max_in_table', '1000'); - $this->zbxTestClickWait('update'); - $this->zbxTestTextPresent([ - 'Configuration updated', - 'GUI', - 'Max count of elements to show inside table cell' - ]); - - $this->assertEquals(1, CDBHelper::getCount('SELECT NULL FROM config WHERE max_in_table=1000')); - - $this->query('id:page-title-general')->asPopupButton()->one()->select('GUI'); - $this->zbxTestCheckTitle('Configuration of GUI'); - $this->zbxTestCheckHeader('GUI'); - $this->zbxTestInputType('max_in_table', '1'); - $this->zbxTestClickWait('update'); - $this->zbxTestTextPresent([ - 'Configuration updated', - 'GUI', - 'Max count of elements to show inside table cell' - ]); - - $this->assertEquals(1, CDBHelper::getCount('SELECT NULL FROM config WHERE max_in_table=1')); - - $this->query('id:page-title-general')->asPopupButton()->one()->select('GUI'); - $this->zbxTestCheckTitle('Configuration of GUI'); - $this->zbxTestCheckHeader('GUI'); - $this->zbxTestInputTypeOverwrite('max_in_table', '99999'); - $this->zbxTestClickWait('update'); - $this->zbxTestTextPresent([ - 'Configuration updated', - 'GUI', - 'Max count of elements to show inside table cell' - ]); - - $this->assertEquals(1, CDBHelper::getCount('SELECT NULL FROM config WHERE max_in_table=99999')); - - $this->query('id:page-title-general')->asPopupButton()->one()->select('GUI'); - $this->zbxTestCheckTitle('Configuration of GUI'); - $this->zbxTestCheckHeader('GUI'); - $this->zbxTestInputTypeOverwrite('max_in_table', '-1'); - $this->zbxTestClickWait('update'); - $this->zbxTestTextPresent([ - 'Cannot update configuration', - 'Incorrect value "-1" for "max_in_table" field.', - 'GUI', - 'Max count of elements to show inside table cell' - ]); - $this->zbxTestTextNotPresent('Configuration updated'); - - $this->assertEquals($old_hash, CDBHelper::getHash($sql_hash)); + /** + * @dataProvider getCheckFormData + */ + public function testFormAdministrationGeneralGUI_CheckForm($data) { + $this->page->login()->open('zabbix.php?action=gui.edit'); + $form = $this->query('xpath://form[contains(@action, "gui.update")]')->waitUntilPresent()->asForm()->one(); + // Reset form in case of previous test case. + $this->resetConfiguration($form, $this->default, 'Reset defaults'); + // Fill form with new data. + $form->fill($data['fields']); + $form->submit(); + $this->page->waitUntilReady(); + $this->assertMessage($data['expected'], $data['message'], CTestArrayHelper::get($data, 'details')); + // Check saved configuration in frontend. + $this->page->open('zabbix.php?action=gui.edit'); + $form->invalidate(); + $values = (CTestArrayHelper::get($data, 'expected')) === TEST_GOOD + ? $data['fields'] + : $this->default; + $form->checkValue($values); + // Check saved configuration in database. + $sql = CDBHelper::getRow('SELECT * FROM config'); + $db = (CTestArrayHelper::get($data, 'expected')) === TEST_GOOD + ? CTestArrayHelper::get($data, 'db', []) + : $this->db_default; + foreach ($db as $key => $value) { + $this->assertArrayHasKey($key, $sql); + $this->assertEquals($value, $sql[$key]); + } } - public function testFormAdministrationGeneralGUI_EventCheckInterval() { - $this->zbxTestLogin('zabbix.php?action=gui.edit'); - $sql_hash = 'SELECT '.CDBHelper::getTableFields('config', ['server_check_interval']).' FROM config ORDER BY configid'; - $old_hash = CDBHelper::getHash($sql_hash); - - $this->zbxTestCheckboxSelect('server_check_interval'); - $this->zbxTestClickWait('update'); - $this->zbxTestTextPresent('Configuration updated'); - $this->zbxTestCheckHeader('GUI'); - $this->zbxTestTextPresent('Show warning if Zabbix server is down'); - $this->assertTrue($this->zbxTestCheckboxSelected('server_check_interval')); - - $sql = 'SELECT server_check_interval FROM config WHERE server_check_interval=10'; - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect value in the DB field "server_check_interval"'); - - $this->query('id:page-title-general')->asPopupButton()->one()->select('GUI'); - $this->zbxTestCheckTitle('Configuration of GUI'); - $this->zbxTestCheckHeader('GUI'); - $this->zbxTestCheckboxSelect('server_check_interval', false); - - $this->zbxTestClickWait('update'); - $this->zbxTestTextPresent(['Configuration updated', 'GUI', 'Show warning if Zabbix server is down']); - $this->assertFalse($this->zbxTestCheckboxSelected('server_check_interval')); + public function getResetButtonData() { + return [ + [ + [ + 'action' => 'Reset defaults', + ] + ], + [ + [ + 'action' => 'Cancel', + ] + ] + ]; + } - $sql = 'SELECT server_check_interval FROM config WHERE server_check_interval=0'; - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect value in the DB field "server_check_interval"'); + /** + * @dataProvider getResetButtonData + */ + public function testFormAdministrationGeneralGUI_ResetButton($data) { + $this->page->login()->open('zabbix.php?action=gui.edit'); + $form = $this->query('xpath://form[contains(@action, "gui.update")]')->waitUntilPresent()->asForm()->one(); + // Reset form in case of some previous scenario. + $this->resetConfiguration($form, $this->default, 'Reset defaults'); + $default_sql = CDBHelper::getRow('SELECT * FROM config'); + // Fill form with custom data. + $form->fill($this->custom); + $form->submit(); + $this->assertMessage(TEST_GOOD, 'Configuration updated'); + $custom_sql = CDBHelper::getRow('SELECT * FROM config'); + // Check custom data in form. + $this->page->refresh(); + $form->invalidate(); + $form->checkValue($this->custom); + // Reset form after customly filled data and check that values are reset to default or reset is cancelled. + $this->resetConfiguration($form, $this->default, $data['action'], $this->custom); + $sql = ($data['action'] === 'Reset defaults') ? $default_sql : $custom_sql; + $this->assertEquals($sql, CDBHelper::getRow('SELECT * FROM config')); + } - $this->assertEquals($old_hash, CDBHelper::getHash($sql_hash)); + private function resetConfiguration($form, $default, $action, $custom = null) { + $form->query('button:Reset defaults')->one()->click(); + COverlayDialogElement::find()->waitUntilPresent()->one()->query('button', $action)->one()->click(); + switch ($action) { + case 'Reset defaults': + $form->submit(); + $this->assertMessage(TEST_GOOD, 'Configuration updated'); + $this->page->refresh(); + $form->invalidate(); + // Check reset form. + $form->checkValue($default); + break; + case 'Cancel': + $form->checkValue($custom); + break; + } } } diff --git a/ui/tests/selenium/testFormAdministrationGeneralHousekeeper.php b/ui/tests/selenium/testFormAdministrationGeneralHousekeeper.php index d7949a27405..1591ec5ab27 100644 --- a/ui/tests/selenium/testFormAdministrationGeneralHousekeeper.php +++ b/ui/tests/selenium/testFormAdministrationGeneralHousekeeper.php @@ -20,6 +20,9 @@ require_once dirname(__FILE__).'/../include/CLegacyWebTest.php'; +/** + * @backup config + */ class testFormAdministrationGeneralHousekeeper extends CLegacyWebTest { public function testFormAdministrationGeneralHousekeeper_CheckLayout() { @@ -37,25 +40,25 @@ class testFormAdministrationGeneralHousekeeper extends CLegacyWebTest { $this->zbxTestTextPresent('Trigger data storage period'); $this->zbxTestAssertElementPresentId('hk_events_trigger'); - $this->zbxTestAssertAttribute("//input[@id='hk_events_trigger']", "maxlength", 255); + $this->zbxTestAssertAttribute("//input[@id='hk_events_trigger']", "maxlength", 32); $this->zbxTestAssertAttribute("//input[@id='hk_events_trigger']", "value", '365d'); $this->zbxTestAssertElementNotPresentXpath("//input[@id='hk_events_trigger'][@disabled]"); $this->zbxTestTextPresent('Internal data storage period'); $this->zbxTestAssertElementPresentId('hk_events_internal'); - $this->zbxTestAssertAttribute("//input[@id='hk_events_internal']", "maxlength", 255); + $this->zbxTestAssertAttribute("//input[@id='hk_events_internal']", "maxlength", 32); $this->zbxTestAssertAttribute("//input[@id='hk_events_internal']", "value", '1d'); $this->zbxTestAssertElementNotPresentXpath("//input[@id='hk_events_internal'][@disabled]"); $this->zbxTestTextPresent('Network discovery data storage period'); $this->zbxTestAssertElementPresentId('hk_events_discovery'); - $this->zbxTestAssertAttribute("//input[@id='hk_events_discovery']", "maxlength", 255); + $this->zbxTestAssertAttribute("//input[@id='hk_events_discovery']", "maxlength", 32); $this->zbxTestAssertAttribute("//input[@id='hk_events_discovery']", "value", '1d'); $this->zbxTestAssertElementNotPresentXpath("//input[@id='hk_events_discovery'][@disabled]"); $this->zbxTestTextPresent('Autoregistration data storage period'); $this->zbxTestAssertElementPresentId('hk_events_autoreg'); - $this->zbxTestAssertAttribute("//input[@id='hk_events_autoreg']", "maxlength", 255); + $this->zbxTestAssertAttribute("//input[@id='hk_events_autoreg']", "maxlength", 32); $this->zbxTestAssertAttribute("//input[@id='hk_events_autoreg']", "value", '1d'); $this->zbxTestAssertElementNotPresentXpath("//input[@id='hk_events_autoreg'][@disabled]"); @@ -74,7 +77,7 @@ class testFormAdministrationGeneralHousekeeper extends CLegacyWebTest { $this->zbxTestTextPresent('Data storage period'); $this->zbxTestAssertElementPresentId('hk_services'); - $this->zbxTestAssertAttribute("//input[@id='hk_services']", "maxlength", 255); + $this->zbxTestAssertAttribute("//input[@id='hk_services']", "maxlength", 32); $this->zbxTestAssertAttribute("//input[@id='hk_services']", "value", '365d'); $this->zbxTestAssertElementNotPresentXpath("//input[@id='hk_services'][@disabled]"); @@ -90,7 +93,7 @@ class testFormAdministrationGeneralHousekeeper extends CLegacyWebTest { $this->zbxTestTextPresent('Data storage period'); $this->zbxTestAssertElementPresentId('hk_audit'); - $this->zbxTestAssertAttribute("//input[@id='hk_audit']", "maxlength", 255); + $this->zbxTestAssertAttribute("//input[@id='hk_audit']", "maxlength", 32); $this->zbxTestAssertAttribute("//input[@id='hk_audit']", "value", '365d'); $this->zbxTestAssertElementNotPresentXpath("//input[@id='hk_audit'][@disabled]"); @@ -106,7 +109,7 @@ class testFormAdministrationGeneralHousekeeper extends CLegacyWebTest { $this->zbxTestTextPresent('Data storage period'); $this->zbxTestAssertVisibleId('hk_sessions'); - $this->zbxTestAssertAttribute("//input[@id='hk_sessions']", "maxlength", 255); + $this->zbxTestAssertAttribute("//input[@id='hk_sessions']", "maxlength", 32); $this->zbxTestAssertAttribute("//input[@id='hk_sessions']", "value", '365d'); $this->zbxTestAssertElementNotPresentXpath("//input[@id='hk_sessions'][@disabled]"); @@ -126,7 +129,7 @@ class testFormAdministrationGeneralHousekeeper extends CLegacyWebTest { $this->zbxTestTextPresent('Data storage period'); $this->zbxTestAssertVisibleId('hk_history'); - $this->zbxTestAssertAttribute("//input[@id='hk_history']", "maxlength", 255); + $this->zbxTestAssertAttribute("//input[@id='hk_history']", "maxlength", 32); $this->zbxTestAssertAttribute("//input[@id='hk_history']", "value", '90d'); $this->zbxTestAssertElementPresentXpath("//input[@id='hk_history'][@disabled]"); @@ -150,7 +153,7 @@ class testFormAdministrationGeneralHousekeeper extends CLegacyWebTest { $this->zbxTestTextPresent('Data storage period'); $this->zbxTestAssertVisibleId('hk_trends'); - $this->zbxTestAssertAttribute("//input[@id='hk_trends']", "maxlength", 255); + $this->zbxTestAssertAttribute("//input[@id='hk_trends']", "maxlength", 32); $this->zbxTestAssertAttribute("//input[@id='hk_trends']", "value", '365d'); $this->zbxTestAssertElementPresentXpath("//input[@id='hk_trends'][@disabled]"); @@ -224,7 +227,7 @@ class testFormAdministrationGeneralHousekeeper extends CLegacyWebTest { 'hk_events_mode' => true, 'hk_events_trigger' => 0, 'errors' => [ - 'Invalid trigger data storage period: value must be one of 86400-788400000', + 'Incorrect value for field "hk_events_trigger": value must be one of 86400-788400000.', ] ] ], @@ -234,7 +237,7 @@ class testFormAdministrationGeneralHousekeeper extends CLegacyWebTest { 'hk_events_mode' => true, 'hk_events_trigger' => '1439m', 'errors' => [ - 'Invalid trigger data storage period: value must be one of 86400-788400000', + 'Incorrect value for field "hk_events_trigger": value must be one of 86400-788400000.', ] ] ], @@ -244,7 +247,7 @@ class testFormAdministrationGeneralHousekeeper extends CLegacyWebTest { 'hk_events_mode' => true, 'hk_events_trigger' => '23h', 'errors' => [ - 'Invalid trigger data storage period: value must be one of 86400-788400000', + 'Incorrect value for field "hk_events_trigger": value must be one of 86400-788400000.', ] ] ], @@ -254,7 +257,7 @@ class testFormAdministrationGeneralHousekeeper extends CLegacyWebTest { 'hk_events_mode' => true, 'hk_events_trigger' => '13140001m', 'errors' => [ - 'Invalid trigger data storage period: value must be one of 86400-788400000', + 'Incorrect value for field "hk_events_trigger": value must be one of 86400-788400000.', ] ] ], @@ -264,7 +267,7 @@ class testFormAdministrationGeneralHousekeeper extends CLegacyWebTest { 'hk_events_mode' => true, 'hk_events_trigger' => '219001h', 'errors' => [ - 'Invalid trigger data storage period: value must be one of 86400-788400000', + 'Incorrect value for field "hk_events_trigger": value must be one of 86400-788400000.', ] ] ], @@ -274,7 +277,7 @@ class testFormAdministrationGeneralHousekeeper extends CLegacyWebTest { 'hk_events_mode' => true, 'hk_events_trigger' => '9126d', 'errors' => [ - 'Invalid trigger data storage period: value must be one of 86400-788400000', + 'Incorrect value for field "hk_events_trigger": value must be one of 86400-788400000.', ] ] ], @@ -284,7 +287,7 @@ class testFormAdministrationGeneralHousekeeper extends CLegacyWebTest { 'hk_events_mode' => true, 'hk_events_trigger' => '1304w', 'errors' => [ - 'Invalid trigger data storage period: value must be one of 86400-788400000', + 'Incorrect value for field "hk_events_trigger": value must be one of 86400-788400000.', ] ] ], @@ -294,7 +297,7 @@ class testFormAdministrationGeneralHousekeeper extends CLegacyWebTest { 'hk_events_mode' => true, 'hk_events_internal' => 0, 'errors' => [ - 'Invalid internal data storage period: value must be one of 86400-788400000', + 'Incorrect value for field "hk_events_internal": value must be one of 86400-788400000.', ] ] ], @@ -304,7 +307,7 @@ class testFormAdministrationGeneralHousekeeper extends CLegacyWebTest { 'hk_events_mode' => true, 'hk_events_discovery' => 0, 'errors' => [ - 'Invalid network discovery data storage period: value must be one of 86400-788400000', + 'Incorrect value for field "hk_events_discovery": value must be one of 86400-788400000.', ] ] ], @@ -314,7 +317,7 @@ class testFormAdministrationGeneralHousekeeper extends CLegacyWebTest { 'hk_events_mode' => true, 'hk_events_autoreg' => 0, 'errors' => [ - 'Invalid autoregistration data storage period: value must be one of 86400-788400000', + 'Incorrect value for field "hk_events_autoreg": value must be one of 86400-788400000.', ] ] ], @@ -324,7 +327,7 @@ class testFormAdministrationGeneralHousekeeper extends CLegacyWebTest { 'hk_services_mode' => true, 'hk_services' => 0, 'errors' => [ - 'Invalid data storage period for services: value must be one of 86400-788400000', + 'Incorrect value for field "hk_services": value must be one of 86400-788400000.', ] ] ], @@ -334,7 +337,7 @@ class testFormAdministrationGeneralHousekeeper extends CLegacyWebTest { 'hk_audit_mode' => true, 'hk_audit' => 0, 'errors' => [ - 'Invalid audit data storage period: value must be one of 86400-788400000', + 'Incorrect value for field "hk_audit": value must be one of 86400-788400000.', ] ] ], @@ -344,7 +347,7 @@ class testFormAdministrationGeneralHousekeeper extends CLegacyWebTest { 'hk_sessions_mode' => true, 'hk_sessions' => 0, 'errors' => [ - 'Invalid user sessions data storage period: value must be one of 86400-788400000', + 'Incorrect value for field "hk_sessions": value must be one of 86400-788400000.', ] ] ], @@ -355,7 +358,7 @@ class testFormAdministrationGeneralHousekeeper extends CLegacyWebTest { 'hk_history_global' => true, 'hk_history' => -1, 'errors' => [ - 'Invalid history data storage period: a time unit is expected.', + 'Incorrect value for field "hk_history": a time unit is expected.', ] ] ], @@ -366,7 +369,7 @@ class testFormAdministrationGeneralHousekeeper extends CLegacyWebTest { 'hk_trends_global' => true, 'hk_trends' => -1, 'errors' => [ - 'Invalid trends data storage period: a time unit is expected.', + 'Incorrect value for field "hk_trends": a time unit is expected.', ] ] ], diff --git a/ui/tests/selenium/testFormAdministrationGeneralOtherParams.php b/ui/tests/selenium/testFormAdministrationGeneralOtherParams.php index 46832d777d7..087a9eb078c 100644 --- a/ui/tests/selenium/testFormAdministrationGeneralOtherParams.php +++ b/ui/tests/selenium/testFormAdministrationGeneralOtherParams.php @@ -58,44 +58,18 @@ class testFormAdministrationGeneralOtherParams extends CLegacyWebTest { $this->zbxTestAssertElementPresentId('snmptrap_logging'); $this->zbxTestAssertElementPresentId('default_inventory_mode'); - // ckecking presence of drop-down elements + // ckecking presence of multiselect elements $this->zbxTestAssertElementPresentId('discovery_groupid'); $this->zbxTestAssertElementPresentId('alert_usrgrpid'); } - } - - // checking possible values in the drop-down "Group for discovered hosts" - public function testFormAdministrationGeneralOtherParams_CheckHostGroupsLayout() { - - $this->zbxTestLogin('zabbix.php?action=miscconfig.edit'); - $this->query('id:page-title-general')->asPopupButton()->one()->select('Other'); - $this->zbxTestCheckTitle('Other configuration parameters'); - $this->zbxTestCheckHeader('Other configuration parameters'); - - $sql = 'SELECT groupid FROM hstgrp'; - $hgroups = DBfetchArray(DBselect($sql)); - foreach ($hgroups as $group) { - $this->zbxTestAssertElementPresentXpath("//select[@id='discovery_groupid']/option[@value='".$group['groupid']."']"); - } - } - - // checking possible values in the drop-down "User group for database down message" - public function testFormAdministrationGeneralOtherParams_CheckUserGroupLayout() { - - $this->zbxTestLogin('zabbix.php?action=miscconfig.edit'); - - $this->query('id:page-title-general')->asPopupButton()->one()->select('Other'); - $this->zbxTestCheckTitle('Other configuration parameters'); - $this->zbxTestCheckHeader('Other configuration parameters'); - - $sql = 'SELECT usrgrpid FROM usrgrp'; - $usrgrp = DBfetchArray(DBselect($sql)); - foreach ($usrgrp as $usrgroup) { - $this->zbxTestAssertElementPresentXpath("//select[@id='alert_usrgrpid']/option[@value='".$usrgroup['usrgrpid']."']"); - } - - $this->zbxTestDropdownHasOptions('alert_usrgrpid', ['None']); + $form = $this->query('name:otherForm')->waitUntilPresent()->asForm()->one(); + $form->checkValue( + [ + 'Group for discovered hosts' => 'Discovered hosts', + 'User group for database down message' => 'Selenium user group in configuration' + ] + ); } public function testFormAdministrationGeneralOtherParams_OtherParams() { @@ -105,8 +79,14 @@ class testFormAdministrationGeneralOtherParams extends CLegacyWebTest { $this->zbxTestCheckHeader('Other configuration parameters'); $this->zbxTestInputType('refresh_unsupported', '700'); - $this->zbxTestDropdownSelect('discovery_groupid', 'Linux servers'); - $this->zbxTestDropdownSelect('alert_usrgrpid', 'Zabbix administrators'); + + $form = $this->query('name:otherForm')->waitUntilPresent()->asForm()->one(); + $form->fill( + [ + 'Group for discovered hosts' => 'Linux servers', + 'User group for database down message' => 'Zabbix administrators' + ] + ); $this->zbxTestCheckboxSelect('snmptrap_logging'); // 1 - yes, 0 - no $this->zbxTestClickWait('update'); $this->zbxTestTextPresent('Configuration updated'); @@ -121,8 +101,13 @@ class testFormAdministrationGeneralOtherParams extends CLegacyWebTest { // trying to enter max possible value $this->zbxTestInputTypeOverwrite('refresh_unsupported', '86400'); - $this->zbxTestDropdownSelect('discovery_groupid', 'Linux servers'); - $this->zbxTestDropdownSelect('alert_usrgrpid', 'Enabled debug mode'); + $form->invalidate(); + $form->checkValue( + [ + 'Group for discovered hosts' => 'Linux servers', + 'User group for database down message' => 'Zabbix administrators' + ] + ); $this->zbxTestCheckboxSelect('snmptrap_logging', false); $this->zbxTestClickWait('update'); $this->zbxTestTextPresent('Configuration updated'); @@ -138,6 +123,6 @@ class testFormAdministrationGeneralOtherParams extends CLegacyWebTest { $this->zbxTestInputTypeOverwrite('refresh_unsupported', '86401'); $this->zbxTestClickWait('update'); $this->zbxTestWaitUntilMessageTextPresent('msg-bad', 'Cannot update configuration'); - $this->zbxTestTextPresent('Invalid refresh of unsupported items: value must be one of 0-86400'); + $this->zbxTestTextPresent('Incorrect value for field "refresh_unsupported": value must be one of 0-86400.'); } } diff --git a/ui/tests/selenium/testFormAdministrationGeneralTrigDisplOptions.php b/ui/tests/selenium/testFormAdministrationGeneralTrigDisplOptions.php index 4ddbf695b1a..e25b7a6e343 100644 --- a/ui/tests/selenium/testFormAdministrationGeneralTrigDisplOptions.php +++ b/ui/tests/selenium/testFormAdministrationGeneralTrigDisplOptions.php @@ -20,12 +20,18 @@ require_once dirname(__FILE__).'/../include/CLegacyWebTest.php'; +/** + * @backup config + */ class testFormAdministrationGeneralTrigDisplOptions extends CLegacyWebTest { public static function allValues() { return CDBHelper::getDataProvider( 'SELECT custom_color,problem_unack_color,problem_unack_style,problem_ack_color,problem_ack_style,'. - 'ok_unack_color,ok_unack_style,ok_ack_color,ok_ack_style,ok_period,blink_period'. + 'ok_unack_color,ok_unack_style,ok_ack_color,ok_ack_style,ok_period,blink_period,'. + 'severity_name_0,severity_color_0,severity_name_1,severity_color_1,'. + 'severity_name_2,severity_color_2,severity_name_3,severity_color_3,severity_name_4,'. + 'severity_color_4,severity_name_5,severity_color_5'. ' FROM config' ); } @@ -36,6 +42,7 @@ class testFormAdministrationGeneralTrigDisplOptions extends CLegacyWebTest { public function testFormAdministrationGeneralTrigDisplOptions_Layout($allValues) { $this->zbxTestLogin('zabbix.php?action=trigdisplay.edit'); $this->zbxTestCheckHeader('Trigger displaying options'); + $this->zbxTestCheckTitle('Configuration of trigger displaying options'); $this->zbxTestTextPresent( [ 'Trigger displaying options', @@ -69,6 +76,54 @@ class testFormAdministrationGeneralTrigDisplOptions extends CLegacyWebTest { $this->zbxTestAssertElementPresentXpath("//input[@id='problem_ack_color'][@disabled]"); $this->zbxTestAssertElementPresentXpath("//input[@id='ok_unack_color'][@disabled]"); $this->zbxTestAssertElementPresentXpath("//input[@id='ok_ack_color'][@disabled]"); + + $this->zbxTestTextPresent(['Not classified', 'Information', 'Warning', 'Average', 'High', 'Disaster']); + $this->zbxTestTextPresent(['Info', 'Custom severity names affect all locales and require manual translation!']); + + $this->zbxTestAssertElementPresentId('severity_name_0'); + $this->zbxTestAssertElementPresentId('severity_name_1'); + $this->zbxTestAssertElementPresentId('severity_name_2'); + $this->zbxTestAssertElementPresentId('severity_name_3'); + $this->zbxTestAssertElementPresentId('severity_name_4'); + $this->zbxTestAssertElementPresentId('severity_name_5'); + $this->zbxTestAssertElementPresentId('severity_color_0'); + $this->zbxTestAssertElementPresentId('severity_color_1'); + $this->zbxTestAssertElementPresentId('severity_color_2'); + $this->zbxTestAssertElementPresentId('severity_color_3'); + $this->zbxTestAssertElementPresentId('severity_color_4'); + $this->zbxTestAssertElementPresentId('severity_color_5'); + $this->zbxTestAssertElementPresentId('lbl_severity_color_0'); + $this->zbxTestAssertElementPresentId('lbl_severity_color_1'); + $this->zbxTestAssertElementPresentId('lbl_severity_color_2'); + $this->zbxTestAssertElementPresentId('lbl_severity_color_3'); + $this->zbxTestAssertElementPresentId('lbl_severity_color_4'); + $this->zbxTestAssertElementPresentId('lbl_severity_color_5'); + $this->zbxTestAssertAttribute("//input[@id='severity_name_0']", "maxlength", '32'); + $this->zbxTestAssertAttribute("//input[@id='severity_name_0']", "size", '20'); + $this->zbxTestAssertAttribute("//input[@id='severity_name_1']", "maxlength", '32'); + $this->zbxTestAssertAttribute("//input[@id='severity_name_1']", "size", '20'); + $this->zbxTestAssertAttribute("//input[@id='severity_name_2']", "maxlength", '32'); + $this->zbxTestAssertAttribute("//input[@id='severity_name_2']", "size", '20'); + $this->zbxTestAssertAttribute("//input[@id='severity_name_3']", "maxlength", '32'); + $this->zbxTestAssertAttribute("//input[@id='severity_name_3']", "size", '20'); + $this->zbxTestAssertAttribute("//input[@id='severity_name_4']", "maxlength", '32'); + $this->zbxTestAssertAttribute("//input[@id='severity_name_4']", "size", '20'); + $this->zbxTestAssertAttribute("//input[@id='severity_name_5']", "maxlength", '32'); + $this->zbxTestAssertAttribute("//input[@id='severity_name_5']", "size", '20'); + + // checking values in this report + $this->zbxTestAssertElementValue('severity_name_0', $allValues['severity_name_0']); + $this->zbxTestAssertElementValue('severity_name_1', $allValues['severity_name_1']); + $this->zbxTestAssertElementValue('severity_name_2', $allValues['severity_name_2']); + $this->zbxTestAssertElementValue('severity_name_3', $allValues['severity_name_3']); + $this->zbxTestAssertElementValue('severity_name_4', $allValues['severity_name_4']); + $this->zbxTestAssertElementValue('severity_name_5', $allValues['severity_name_5']); + $this->zbxTestAssertElementValue('severity_color_0', $allValues['severity_color_0']); + $this->zbxTestAssertElementValue('severity_color_1', $allValues['severity_color_1']); + $this->zbxTestAssertElementValue('severity_color_2', $allValues['severity_color_2']); + $this->zbxTestAssertElementValue('severity_color_3', $allValues['severity_color_3']); + $this->zbxTestAssertElementValue('severity_color_4', $allValues['severity_color_4']); + $this->zbxTestAssertElementValue('severity_color_5', $allValues['severity_color_5']); } public function testFormAdministrationGeneralTrigDisplOptions_UpdateTrigDisplOptions() { @@ -117,43 +172,48 @@ class testFormAdministrationGeneralTrigDisplOptions extends CLegacyWebTest { return [ [[ 'expected' => TEST_BAD, + 'period' => '', + 'error_msg' => 'Incorrect value for field "ok_period": cannot be empty.' + ]], + [[ + 'expected' => TEST_BAD, 'period' => ' ', - 'error_msg' => 'Invalid displaying of OK triggers: a time unit is expected.' + 'error_msg' => 'Incorrect value for field "ok_period": a time unit is expected.' ]], [[ 'expected' => TEST_BAD, 'period' => 's', - 'error_msg' => 'Invalid displaying of OK triggers: a time unit is expected.' + 'error_msg' => 'Incorrect value for field "ok_period": a time unit is expected.' ]], [[ 'expected' => TEST_BAD, 'period' => '1.5', - 'error_msg' => 'Invalid displaying of OK triggers: a time unit is expected.' + 'error_msg' => 'Incorrect value for field "ok_period": a time unit is expected.' ]], [[ 'expected' => TEST_BAD, 'period' => '{$BAD}', - 'error_msg' => 'Invalid displaying of OK triggers: a time unit is expected.' + 'error_msg' => 'Incorrect value for field "ok_period": a time unit is expected.' ]], [[ 'expected' => TEST_BAD, 'period' => '1441m', - 'error_msg' => 'Invalid displaying of OK triggers: value must be one of 0-86400.' + 'error_msg' => 'Incorrect value for field "ok_period": value must be one of 0-86400.' ]], [[ 'expected' => TEST_BAD, 'period' => '2d', - 'error_msg' => 'Invalid displaying of OK triggers: value must be one of 0-86400.' + 'error_msg' => 'Incorrect value for field "ok_period": value must be one of 0-86400.' ]], [[ 'expected' => TEST_BAD, 'period' => '86401', - 'error_msg' => 'Invalid displaying of OK triggers: value must be one of 0-86400.' + 'error_msg' => 'Incorrect value for field "ok_period": value must be one of 0-86400.' ]], [[ 'expected' => TEST_BAD, 'period' => '1y', - 'error_msg' => 'Invalid displaying of OK triggers: a time unit is expected.' + 'error_msg' => 'Incorrect value for field "ok_period": a time unit is expected.' ]], [[ 'expected' => TEST_GOOD, @@ -205,43 +265,48 @@ class testFormAdministrationGeneralTrigDisplOptions extends CLegacyWebTest { return [ [[ 'expected' => TEST_BAD, + 'period' => '', + 'error_msg' => 'Incorrect value for field "blink_period": cannot be empty.' + ]], + [[ + 'expected' => TEST_BAD, 'period' => ' ', - 'error_msg' => 'Invalid blinking on trigger status change: a time unit is expected.' + 'error_msg' => 'Incorrect value for field "blink_period": a time unit is expected.' ]], [[ 'expected' => TEST_BAD, 'period' => 's', - 'error_msg' => 'Invalid blinking on trigger status change: a time unit is expected.' + 'error_msg' => 'Incorrect value for field "blink_period": a time unit is expected.' ]], [[ 'expected' => TEST_BAD, 'period' => '1.5', - 'error_msg' => 'Invalid blinking on trigger status change: a time unit is expected.' + 'error_msg' => 'Incorrect value for field "blink_period": a time unit is expected.' ]], [[ 'expected' => TEST_BAD, 'period' => '{$BAD}', - 'error_msg' => 'Invalid blinking on trigger status change: a time unit is expected.' + 'error_msg' => 'Incorrect value for field "blink_period": a time unit is expected.' ]], [[ 'expected' => TEST_BAD, 'period' => '1441m', - 'error_msg' => 'Invalid blinking on trigger status change: value must be one of 0-86400.' + 'error_msg' => 'Incorrect value for field "blink_period": value must be one of 0-86400.' ]], [[ 'expected' => TEST_BAD, 'period' => '2d', - 'error_msg' => 'Invalid blinking on trigger status change: value must be one of 0-86400.' + 'error_msg' => 'Incorrect value for field "blink_period": value must be one of 0-86400.' ]], [[ 'expected' => TEST_BAD, 'period' => '86401', - 'error_msg' => 'Invalid blinking on trigger status change: value must be one of 0-86400.' + 'error_msg' => 'Incorrect value for field "blink_period": value must be one of 0-86400.' ]], [[ 'expected' => TEST_BAD, 'period' => '1y', - 'error_msg' => 'Invalid blinking on trigger status change: a time unit is expected.' + 'error_msg' => 'Incorrect value for field "blink_period": a time unit is expected.' ]], [[ 'expected' => TEST_GOOD, @@ -296,7 +361,8 @@ class testFormAdministrationGeneralTrigDisplOptions extends CLegacyWebTest { $this->query('id:page-title-general')->asPopupButton()->one()->select('Trigger displaying options'); // hash calculation for the DB fields that should be changed in this report - $sql_hash = 'SELECT '.CDBHelper::getTableFields('config', ['custom_color', 'problem_unack_style', 'problem_ack_style', 'ok_unack_style', 'ok_ack_style', 'ok_period', 'blink_period']).' FROM config ORDER BY configid'; + $sql_hash = 'SELECT '.CDBHelper::getTableFields('config', ['custom_color', 'problem_unack_style', 'problem_ack_style', + 'ok_unack_style', 'ok_ack_style', 'ok_period', 'blink_period']).' FROM config ORDER BY configid'; $old_hash = CDBHelper::getHash($sql_hash); $this->zbxTestClick('resetDefaults'); @@ -316,4 +382,130 @@ class testFormAdministrationGeneralTrigDisplOptions extends CLegacyWebTest { // hash calculation for the DB fields that should be changed in this report $this->assertEquals($old_hash, CDBHelper::getHash($sql_hash)); } + + public function testFormAdministrationGeneralTrigDisplOptions_ChangeTriggerSeverities() { + + $this->zbxTestLogin('zabbix.php?action=trigdisplay.edit'); + $this->zbxTestCheckTitle('Configuration of trigger displaying options'); + $this->zbxTestCheckHeader('Trigger displaying options'); + $this->zbxTestTextPresent('Custom severity names affect all locales and require manual translation!'); + + $this->zbxTestInputType('severity_name_0', 'Not classified2'); + $this->zbxTestInputType('severity_name_1', 'Information2'); + $this->zbxTestInputType('severity_name_2', 'Warning2'); + $this->zbxTestInputType('severity_name_3', 'Average2'); + $this->zbxTestInputType('severity_name_4', 'High2'); + $this->zbxTestInputType('severity_name_5', 'Disaster2'); + + $this->zbxTestClick('lbl_severity_color_5'); + $this->zbxTestClickXpath('//div[@title="#FF0000"]'); + + $this->zbxTestClick('lbl_severity_color_4'); + $this->zbxTestClickXpath('//div[@title="#CC6600"]'); + + $this->zbxTestClick('lbl_severity_color_3'); + $this->zbxTestClickXpath('//div[@title="#E57373"]'); + + $this->zbxTestClick('lbl_severity_color_2'); + $this->zbxTestClickXpath('//div[@title="#FFA000"]'); + + $this->zbxTestClick('lbl_severity_color_1'); + $this->zbxTestClickXpath('//div[@title="#0097A7"]'); + + $this->zbxTestClick('lbl_severity_color_0'); + $this->zbxTestClickXpath('//div[@title="#A5A5A5"]'); + + $this->zbxTestClickWait('update'); + $this->zbxTestTextPresent('Configuration updated'); + + $sql = 'SELECT severity_name_0 FROM config WHERE severity_name_0='.zbx_dbstr('Not classified2'); + $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity name in the DB field "severity_name_0"'); + + $sql = 'SELECT severity_name_1 FROM config WHERE severity_name_1='.zbx_dbstr('Information2'); + $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity name in the DB field "severity_name_1"'); + + $sql = 'SELECT severity_name_2 FROM config WHERE severity_name_2='.zbx_dbstr('Warning2'); + $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity name in the DB field "severity_name_2"'); + + $sql = 'SELECT severity_name_3 FROM config WHERE severity_name_3='.zbx_dbstr('Average2'); + $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity name in the DB field "severity_name_3"'); + + $sql = 'SELECT severity_name_4 FROM config WHERE severity_name_4='.zbx_dbstr('High2'); + $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity name in the DB field "severity_name_4"'); + + $sql = 'SELECT severity_name_5 FROM config WHERE severity_name_5='.zbx_dbstr('Disaster2'); + $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity name in the DB field "severity_name_5"'); + + // checking severity colors in the DB + + $sql = 'SELECT severity_color_0 FROM config where severity_color_0='.zbx_dbstr('A5A5A5'); + $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity color in the DB field "severity_color_0"'); + + $sql = 'SELECT severity_color_1 FROM config WHERE severity_color_1='.zbx_dbstr('0097A7'); + $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity color in the DB field "severity_color_1"'); + + $sql = 'SELECT severity_color_2 FROM config WHERE severity_color_2='.zbx_dbstr('FFA000'); + $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity color in the DB field "severity_color_2"'); + + $sql = 'SELECT severity_color_3 FROM config WHERE severity_color_3='.zbx_dbstr('E57373'); + $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity color in the DB field "severity_color_3"'); + + $sql = 'SELECT severity_color_4 FROM config WHERE severity_color_4='.zbx_dbstr('CC6600'); + $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity color in the DB field "severity_color_4"'); + + $sql = 'SELECT severity_color_5 FROM config WHERE severity_color_5='.zbx_dbstr('FF0000'); + $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity color in the DB field "severity_color_5"'); + } + + public function testFormAdministrationGeneralTrigDisplOptions_ResetDefaults() { + + $this->zbxTestLogin('zabbix.php?action=trigdisplay.edit'); + $this->zbxTestCheckHeader('Trigger displaying options'); + $this->zbxTestCheckTitle('Configuration of trigger displaying options'); + $this->zbxTestTextPresent(['Custom severity names affect all locales and require manual translation!']); + $this->zbxTestClick('resetDefaults'); + $this->zbxTestClickXpath("//div[contains(@class, 'overlay-dialogue modal')]//button[text()='Reset defaults']"); + $this->zbxTestClickWait('update'); + $this->zbxTestTextPresent('Configuration updated'); + + // checking that values were reset in the DB + $sql = 'SELECT severity_name_0 FROM config WHERE severity_name_0='.zbx_dbstr('Not classified'); + $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity name in the DB field "severity_name_0"'); + + $sql = 'SELECT severity_name_1 FROM config WHERE severity_name_1='.zbx_dbstr('Information'); + $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity name in the DB field "severity_name_1"'); + + $sql = 'SELECT severity_name_2 FROM config WHERE severity_name_2='.zbx_dbstr('Warning'); + $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity name in the DB field "severity_name_2"'); + + $sql = 'SELECT severity_name_3 FROM config WHERE severity_name_3='.zbx_dbstr('Average'); + $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity name in the DB field "severity_name_3"'); + + $sql = 'SELECT severity_name_4 FROM config WHERE severity_name_4='.zbx_dbstr('High'); + $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity name in the DB field "severity_name_4"'); + + $sql = 'SELECT severity_name_5 FROM config WHERE severity_name_5='.zbx_dbstr('Disaster'); + $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity name in the DB field "severity_name_5"'); + + $sql = 'SELECT severity_color_0 FROM config WHERE severity_color_0='.zbx_dbstr('97AAB3'); + $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity color in the DB field "severity_color_0"'); + + $sql = 'SELECT severity_color_1 FROM config WHERE severity_color_1='.zbx_dbstr('7499FF'); + $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity color in the DB field "severity_color_2"'); + + $sql = 'SELECT severity_color_2 FROM config WHERE severity_color_2='.zbx_dbstr('FFC859'); + $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity color in the DB field "severity_color_3"'); + + $sql = 'SELECT severity_color_3 FROM config WHERE severity_color_3='.zbx_dbstr('FFA059'); + $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity color in the DB field "severity_color_3"'); + + $sql = 'SELECT severity_color_4 FROM config WHERE severity_color_4='.zbx_dbstr('E97659'); + $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity color in the DB field "severity_color_4"'); + + $sql = 'SELECT severity_color_5 FROM config WHERE severity_color_5='.zbx_dbstr('E45959'); + $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity color in the DB field "severity_color_5"'); + +// TODO: can also check that trigger severities have NOT been reset after clicking Cancel in the "Reset confirmation" dialog box after clicking "Reset defaults" button + + } } diff --git a/ui/tests/selenium/testFormAdministrationGeneralTriggerSeverities.php b/ui/tests/selenium/testFormAdministrationGeneralTriggerSeverities.php deleted file mode 100644 index 85edc7c0346..00000000000 --- a/ui/tests/selenium/testFormAdministrationGeneralTriggerSeverities.php +++ /dev/null @@ -1,219 +0,0 @@ -<?php -/* -** Zabbix -** Copyright (C) 2001-2020 Zabbix SIA -** -** This program is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -**/ - -require_once dirname(__FILE__).'/../include/CLegacyWebTest.php'; - -class testFormAdministrationGeneralTriggerSeverities extends CLegacyWebTest { - - public static function allValues() { - return CDBHelper::getDataProvider('SELECT severity_name_0,severity_color_0,severity_name_1,severity_color_1,'. - 'severity_name_2,severity_color_2,severity_name_3,severity_color_3,severity_name_4,'. - 'severity_color_4,severity_name_5,severity_color_5 FROM config ORDER BY configid'); - } - - /** - * @dataProvider allValues - */ - public function testFormAdministrationGeneralTriggerSeverities_CheckLayout($allValues) { - - $this->zbxTestLogin('zabbix.php?action=trigseverity.edit'); - $this->zbxTestCheckTitle('Configuration of trigger severities'); - $this->zbxTestCheckHeader('Trigger severities'); - $this->zbxTestTextPresent(['Not classified', 'Information', 'Warning', 'Average', 'High', 'Disaster']); - $this->zbxTestTextPresent(['Info', 'Custom severity names affect all locales and require manual translation!']); - - $this->zbxTestAssertElementPresentId('severity_name_0'); - $this->zbxTestAssertElementPresentId('severity_name_1'); - $this->zbxTestAssertElementPresentId('severity_name_2'); - $this->zbxTestAssertElementPresentId('severity_name_3'); - $this->zbxTestAssertElementPresentId('severity_name_4'); - $this->zbxTestAssertElementPresentId('severity_name_5'); - $this->zbxTestAssertElementPresentId('severity_color_0'); - $this->zbxTestAssertElementPresentId('severity_color_1'); - $this->zbxTestAssertElementPresentId('severity_color_2'); - $this->zbxTestAssertElementPresentId('severity_color_3'); - $this->zbxTestAssertElementPresentId('severity_color_4'); - $this->zbxTestAssertElementPresentId('severity_color_5'); - $this->zbxTestAssertElementPresentId('lbl_severity_color_0'); - $this->zbxTestAssertElementPresentId('lbl_severity_color_1'); - $this->zbxTestAssertElementPresentId('lbl_severity_color_2'); - $this->zbxTestAssertElementPresentId('lbl_severity_color_3'); - $this->zbxTestAssertElementPresentId('lbl_severity_color_4'); - $this->zbxTestAssertElementPresentId('lbl_severity_color_5'); - $this->zbxTestAssertAttribute("//input[@id='severity_name_0']", "maxlength", '32'); - $this->zbxTestAssertAttribute("//input[@id='severity_name_0']", "size", '20'); - $this->zbxTestAssertAttribute("//input[@id='severity_name_1']", "maxlength", '32'); - $this->zbxTestAssertAttribute("//input[@id='severity_name_1']", "size", '20'); - $this->zbxTestAssertAttribute("//input[@id='severity_name_2']", "maxlength", '32'); - $this->zbxTestAssertAttribute("//input[@id='severity_name_2']", "size", '20'); - $this->zbxTestAssertAttribute("//input[@id='severity_name_3']", "maxlength", '32'); - $this->zbxTestAssertAttribute("//input[@id='severity_name_3']", "size", '20'); - $this->zbxTestAssertAttribute("//input[@id='severity_name_4']", "maxlength", '32'); - $this->zbxTestAssertAttribute("//input[@id='severity_name_4']", "size", '20'); - $this->zbxTestAssertAttribute("//input[@id='severity_name_5']", "maxlength", '32'); - $this->zbxTestAssertAttribute("//input[@id='severity_name_5']", "size", '20'); - - // checking values in this report - $this->zbxTestAssertElementValue('severity_name_0', $allValues['severity_name_0']); - $this->zbxTestAssertElementValue('severity_name_1', $allValues['severity_name_1']); - $this->zbxTestAssertElementValue('severity_name_2', $allValues['severity_name_2']); - $this->zbxTestAssertElementValue('severity_name_3', $allValues['severity_name_3']); - $this->zbxTestAssertElementValue('severity_name_4', $allValues['severity_name_4']); - $this->zbxTestAssertElementValue('severity_name_5', $allValues['severity_name_5']); - $this->zbxTestAssertElementValue('severity_color_0', $allValues['severity_color_0']); - $this->zbxTestAssertElementValue('severity_color_1', $allValues['severity_color_1']); - $this->zbxTestAssertElementValue('severity_color_2', $allValues['severity_color_2']); - $this->zbxTestAssertElementValue('severity_color_3', $allValues['severity_color_3']); - $this->zbxTestAssertElementValue('severity_color_4', $allValues['severity_color_4']); - $this->zbxTestAssertElementValue('severity_color_5', $allValues['severity_color_5']); - } - - public function testFormAdministrationGeneralTriggerSeverities_ChangeTriggerSeverities() { - - $this->zbxTestLogin('zabbix.php?action=trigseverity.edit'); - $this->zbxTestCheckTitle('Configuration of trigger severities'); - $this->zbxTestCheckHeader('Trigger severities'); - $this->zbxTestTextPresent('Custom severity names affect all locales and require manual translation!'); - - $this->zbxTestInputType('severity_name_0', 'Not classified2'); - $this->zbxTestInputType('severity_name_1', 'Information2'); - $this->zbxTestInputType('severity_name_2', 'Warning2'); - $this->zbxTestInputType('severity_name_3', 'Average2'); - $this->zbxTestInputType('severity_name_4', 'High2'); - $this->zbxTestInputType('severity_name_5', 'Disaster2'); - - $this->zbxTestClick('lbl_severity_color_5'); - $this->zbxTestClickXpath('//div[@title="#FF0000"]'); - - $this->zbxTestClick('lbl_severity_color_4'); - $this->zbxTestClickXpath('//div[@title="#CC6600"]'); - - $this->zbxTestClick('lbl_severity_color_3'); - $this->zbxTestClickXpath('//div[@title="#E57373"]'); - - $this->zbxTestClick('lbl_severity_color_2'); - $this->zbxTestClickXpath('//div[@title="#FFA000"]'); - - $this->zbxTestClick('lbl_severity_color_1'); - $this->zbxTestClickXpath('//div[@title="#0097A7"]'); - - $this->zbxTestClick('lbl_severity_color_0'); - $this->zbxTestClickXpath('//div[@title="#A5A5A5"]'); - - $this->zbxTestClickWait('update'); - $this->zbxTestTextPresent('Configuration updated'); - - $sql = 'SELECT severity_name_0 FROM config WHERE severity_name_0='.zbx_dbstr('Not classified2'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity name in the DB field "severity_name_0"'); - - $sql = 'SELECT severity_name_1 FROM config WHERE severity_name_1='.zbx_dbstr('Information2'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity name in the DB field "severity_name_1"'); - - $sql = 'SELECT severity_name_2 FROM config WHERE severity_name_2='.zbx_dbstr('Warning2'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity name in the DB field "severity_name_2"'); - - $sql = 'SELECT severity_name_3 FROM config WHERE severity_name_3='.zbx_dbstr('Average2'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity name in the DB field "severity_name_3"'); - - $sql = 'SELECT severity_name_4 FROM config WHERE severity_name_4='.zbx_dbstr('High2'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity name in the DB field "severity_name_4"'); - - $sql = 'SELECT severity_name_5 FROM config WHERE severity_name_5='.zbx_dbstr('Disaster2'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity name in the DB field "severity_name_5"'); - - // checking severity colors in the DB - - $sql = 'SELECT severity_color_0 FROM config where severity_color_0='.zbx_dbstr('A5A5A5'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity color in the DB field "severity_color_0"'); - - $sql = 'SELECT severity_color_1 FROM config WHERE severity_color_1='.zbx_dbstr('0097A7'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity color in the DB field "severity_color_1"'); - - $sql = 'SELECT severity_color_2 FROM config WHERE severity_color_2='.zbx_dbstr('FFA000'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity color in the DB field "severity_color_2"'); - - $sql = 'SELECT severity_color_3 FROM config WHERE severity_color_3='.zbx_dbstr('E57373'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity color in the DB field "severity_color_3"'); - - $sql = 'SELECT severity_color_4 FROM config WHERE severity_color_4='.zbx_dbstr('CC6600'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity color in the DB field "severity_color_4"'); - - $sql = 'SELECT severity_color_5 FROM config WHERE severity_color_5='.zbx_dbstr('FF0000'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity color in the DB field "severity_color_5"'); - } - - public function testFormAdministrationGeneralTriggerSeverities_ResetDefaults() { - - $this->zbxTestLogin('zabbix.php?action=trigseverity.edit'); - $this->zbxTestCheckHeader('Trigger severities'); - $this->zbxTestCheckTitle('Configuration of trigger severities'); - $this->zbxTestTextPresent( - [ - 'Trigger severities', - 'Custom severity names affect all locales and require manual translation!' - ] - ); - $this->zbxTestClick('resetDefaults'); - $this->zbxTestClickXpath("//div[contains(@class, 'overlay-dialogue modal')]//button[text()='Reset defaults']"); - $this->zbxTestClickWait('update'); - $this->zbxTestTextPresent('Configuration updated'); - $this->zbxTestTextPresent('Trigger severities'); - - // checking that values were reset in the DB - $sql = 'SELECT severity_name_0 FROM config WHERE severity_name_0='.zbx_dbstr('Not classified'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity name in the DB field "severity_name_0"'); - - $sql = 'SELECT severity_name_1 FROM config WHERE severity_name_1='.zbx_dbstr('Information'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity name in the DB field "severity_name_1"'); - - $sql = 'SELECT severity_name_2 FROM config WHERE severity_name_2='.zbx_dbstr('Warning'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity name in the DB field "severity_name_2"'); - - $sql = 'SELECT severity_name_3 FROM config WHERE severity_name_3='.zbx_dbstr('Average'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity name in the DB field "severity_name_3"'); - - $sql = 'SELECT severity_name_4 FROM config WHERE severity_name_4='.zbx_dbstr('High'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity name in the DB field "severity_name_4"'); - - $sql = 'SELECT severity_name_5 FROM config WHERE severity_name_5='.zbx_dbstr('Disaster'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity name in the DB field "severity_name_5"'); - - $sql = 'SELECT severity_color_0 FROM config WHERE severity_color_0='.zbx_dbstr('97AAB3'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity color in the DB field "severity_color_0"'); - - $sql = 'SELECT severity_color_1 FROM config WHERE severity_color_1='.zbx_dbstr('7499FF'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity color in the DB field "severity_color_2"'); - - $sql = 'SELECT severity_color_2 FROM config WHERE severity_color_2='.zbx_dbstr('FFC859'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity color in the DB field "severity_color_3"'); - - $sql = 'SELECT severity_color_3 FROM config WHERE severity_color_3='.zbx_dbstr('FFA059'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity color in the DB field "severity_color_3"'); - - $sql = 'SELECT severity_color_4 FROM config WHERE severity_color_4='.zbx_dbstr('E97659'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity color in the DB field "severity_color_4"'); - - $sql = 'SELECT severity_color_5 FROM config WHERE severity_color_5='.zbx_dbstr('E45959'); - $this->assertEquals(1, CDBHelper::getCount($sql), 'Chuck Norris: Incorrect severity color in the DB field "severity_color_5"'); - -// TODO: can also check that trigger severities have NOT been reset after clicking Cancel in the "Reset confirmation" dialog box after clicking "Reset defaults" button - - } -} diff --git a/ui/tests/selenium/testFormAdministrationGeneralWorkperiod.php b/ui/tests/selenium/testFormAdministrationGeneralWorkperiod.php deleted file mode 100644 index cf827fa21e7..00000000000 --- a/ui/tests/selenium/testFormAdministrationGeneralWorkperiod.php +++ /dev/null @@ -1,171 +0,0 @@ -<?php -/* -** Zabbix -** Copyright (C) 2001-2020 Zabbix SIA -** -** This program is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -**/ - -require_once dirname(__FILE__).'/../include/CLegacyWebTest.php'; - -class testFormAdministrationGeneralWorkperiod extends CLegacyWebTest { - - public static function WorkingTime() { - return CDBHelper::getDataProvider('SELECT work_period FROM config ORDER BY configid'); - } - - /** - * @dataProvider WorkingTime - */ - public function testFormAdministrationGeneralWorkperiod_CheckLayout($WorkingTime) { - $this->zbxTestLogin('zabbix.php?action=gui.edit'); - $this->zbxTestCheckHeader('GUI'); - $this->query('id:page-title-general')->asPopupButton()->one()->select('Working time'); - $this->zbxTestCheckTitle('Configuration of working time'); - $this->zbxTestCheckHeader('Working time'); - - $this->zbxTestAssertAttribute("//input[@id='work_period']", "maxlength", 255); - $this->zbxTestAssertAttribute("//input[@id='work_period']", "size", 20); - $this->zbxTestAssertAttribute("//input[@id='work_period']", "value", $WorkingTime['work_period']); - } - - public function testFormAdministrationGeneralWorkperiod_SimpleUpdate() { - $sqlHash = 'SELECT * FROM config ORDER BY configid'; - $oldHash = CDBHelper::getHash($sqlHash); - - $this->zbxTestLogin('zabbix.php?action=workingtime.edit'); - $this->zbxTestCheckTitle('Configuration of working time'); - $this->zbxTestCheckHeader('Working time'); - $this->zbxTestClickWait('update'); - $this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Configuration updated'); - - $this->assertEquals($oldHash, CDBHelper::getHash($sqlHash)); - } - - public static function data() { - return [ - [ - 'work_period' => 'test', - 'success_expected' => TEST_BAD, - 'error-msg' => 'Incorrect value for field "work_period": a time period is expected.' - ], - [ - 'work_period' => '1-7 09:00-24:00', - 'success_expected' => TEST_BAD, - 'error-msg' => 'Incorrect value for field "work_period": a time period is expected.' - ], - [ - 'work_period' => '0-7,09:00-24:00', - 'success_expected' => TEST_BAD, - 'error-msg' => 'Incorrect value for field "work_period": a time period is expected.' - ], - [ - 'work_period' => '1-5,09:00-18:00,6-7,10:00-16:00', - 'success_expected' => TEST_BAD, - 'error-msg' => 'Incorrect value for field "work_period": a time period is expected.' - ], - [ - 'work_period' => '1-8,09:00-24:00', - 'success_expected' => TEST_BAD, - 'error-msg' => 'Incorrect value for field "work_period": a time period is expected.' - ], - [ - 'work_period' => '1-7,09:00-25:00', - 'success_expected' => TEST_BAD, - 'error-msg' => 'Incorrect value for field "work_period": a time period is expected.' - ], - [ - 'work_period' => '1-7,24:00-00:00', - 'success_expected' => TEST_BAD, - 'error-msg' => 'Incorrect value for field "work_period": a time period is expected.' - ], - [ - 'work_period' => '1-7,14:00-13:00', - 'success_expected' => TEST_BAD, - 'error-msg' => 'Incorrect value for field "work_period": a time period is expected.' - ], - [ - 'work_period' => '1-7,25:00-26:00', - 'success_expected' => TEST_BAD, - 'error-msg' => 'Incorrect value for field "work_period": a time period is expected.' - ], - [ - 'work_period' => '1-7,13:60-14:00', - 'success_expected' => TEST_BAD, - 'error-msg' => 'Incorrect value for field "work_period": a time period is expected.' - ], - [ - 'work_period' => '1-7', - 'success_expected' => TEST_BAD, - 'error-msg' => 'Incorrect value for field "work_period": a time period is expected.' - ], - [ - 'work_period' => '09:00-24:00', - 'success_expected' => TEST_BAD, - 'error-msg' => 'Incorrect value for field "work_period": a time period is expected.' - ], - [ - 'work_period' => '', - 'success_expected' => TEST_BAD, - 'error-msg' => 'Incorrect value for field "work_period": a time period is expected.' - ], - [ - 'work_period' => '{WORKING_HOURS}', - 'success_expected' => TEST_BAD, - 'error-msg' => 'Incorrect value for field "work_period": a time period is expected.' - ], - [ - 'work_period' => '{$WORKING_HOURS}', - 'success_expected' => TEST_GOOD, - 'error-msg' => null - ], - [ - 'work_period' => '1-5,09:00-18:00', - 'success_expected' => TEST_GOOD, - 'error-msg' => null - ], - [ - 'work_period' => '1-5,09:00-18:00;5-7,12:00-16:00', - 'success_expected' => TEST_GOOD, - 'error-msg' => null - ] - ]; - } - - /** - * @dataProvider data - */ - public function testFormAdministrationGeneralWorkperiod_SavingWorkperiod($work_period, $expected, $msg) { - $this->zbxTestLogin('zabbix.php?action=workingtime.edit'); - $this->zbxTestCheckTitle('Configuration of working time'); - $this->zbxTestCheckHeader('Working time'); - - $this->zbxTestInputType('work_period', $work_period); - $this->zbxTestClickWait('update'); - - switch ($expected) { - case TEST_GOOD: - $this->zbxTestTextNotPresent('Page received incorrect data'); - $this->zbxTestWaitUntilMessageTextPresent('msg-good', 'Configuration updated'); - $result = DBfetch(DBselect('SELECT work_period FROM config')); - $this->assertEquals($work_period, $result['work_period']); - break; - case TEST_BAD: - $this->zbxTestWaitUntilMessageTextPresent('msg-bad', 'Cannot update configuration'); - $this->zbxTestTextPresent($msg); - break; - } - } -} diff --git a/ui/tests/selenium/testFormConfigTriggerSeverity.php b/ui/tests/selenium/testFormConfigTriggerSeverity.php index 56aa4ba96e6..176eb08aa1d 100644 --- a/ui/tests/selenium/testFormConfigTriggerSeverity.php +++ b/ui/tests/selenium/testFormConfigTriggerSeverity.php @@ -111,11 +111,11 @@ class testFormConfigTriggerSeverity extends CLegacyWebTest { } public function testFormTriggerSeverity_Layout() { - $this->zbxTestLogin('zabbix.php?action=trigseverity.edit'); - $this->zbxTestCheckTitle('Configuration of trigger severities'); - $this->zbxTestCheckHeader('Trigger severities'); + $this->zbxTestLogin('zabbix.php?action=trigdisplay.edit'); + $this->zbxTestCheckTitle('Configuration of trigger displaying options'); + $this->zbxTestCheckHeader('Trigger displaying options'); - $this->query('id:page-title-general')->asPopupButton()->one()->select('Trigger severities'); + $this->query('id:page-title-general')->asPopupButton()->one()->select('Trigger displaying options'); $this->zbxTestTextPresent(['Not classified', 'Information', 'Warning', 'Average', 'High', 'Disaster']); $this->zbxTestAssertElementPresentId('severity_name_0'); @@ -148,9 +148,9 @@ class testFormConfigTriggerSeverity extends CLegacyWebTest { * @dataProvider providerTriggerSeverity */ public function testFormTriggerSeverity_Update($data, $resultSave, $DBvalues) { - $this->zbxTestLogin('zabbix.php?action=trigseverity.edit'); - $this->zbxTestCheckTitle('Configuration of trigger severities'); - $this->zbxTestCheckHeader('Trigger severities'); + $this->zbxTestLogin('zabbix.php?action=trigdisplay.edit'); + $this->zbxTestCheckTitle('Configuration of trigger displaying options'); + $this->zbxTestCheckHeader('Trigger displaying options'); foreach ($data as $field => $value) { $this->zbxTestInputType($field, $value); diff --git a/ui/tests/selenium/testGeneric.php b/ui/tests/selenium/testGeneric.php index 268059a27a7..12cf3de1aef 100644 --- a/ui/tests/selenium/testGeneric.php +++ b/ui/tests/selenium/testGeneric.php @@ -91,8 +91,6 @@ class testGeneric extends CLegacyWebTest { ['zabbix.php?action=regex.list', 'Configuration of regular expressions'], ['zabbix.php?action=macros.edit', 'Configuration of macros'], ['zabbix.php?action=valuemap.list', 'Configuration of value mapping'], - ['zabbix.php?action=workingtime.edit', 'Configuration of working time'], - ['zabbix.php?action=trigseverity.edit', 'Configuration of trigger severities'], ['zabbix.php?action=trigdisplay.edit', 'Configuration of trigger displaying options'], ['zabbix.php?action=miscconfig.edit', 'Other configuration parameters'], diff --git a/ui/tests/selenium/testPageAdministrationGeneralRegexp.php b/ui/tests/selenium/testPageAdministrationGeneralRegexp.php index f557d6aa0a0..2534aa328fd 100644 --- a/ui/tests/selenium/testPageAdministrationGeneralRegexp.php +++ b/ui/tests/selenium/testPageAdministrationGeneralRegexp.php @@ -56,8 +56,8 @@ class testPageAdministrationGeneralRegexp extends CLegacyWebTest { $this->zbxTestCheckHeader('Regular expressions'); $popup_menu = $this->query('id:page-title-general')->asPopupButton()->one()->getMenu(); $this->assertEquals([ - 'GUI', 'Autoregistration', 'Housekeeping', 'Images', 'Icon mapping', 'Regular expressions', 'Macros', 'Value mapping', - 'Working time', 'Trigger severities', 'Trigger displaying options', 'Modules', 'Other' + 'GUI', 'Autoregistration', 'Housekeeping', 'Images', 'Icon mapping', 'Regular expressions', 'Macros', + 'Value mapping','Trigger displaying options', 'Modules', 'Other' ], $popup_menu->getItems()->asText()); $this->zbxTestAssertElementPresentXpath('//button[text()="New regular expression"]'); diff --git a/ui/tests/selenium/testUrlUserPermissions.php b/ui/tests/selenium/testUrlUserPermissions.php index 71e3f9b1f76..cf199bf60fe 100644 --- a/ui/tests/selenium/testUrlUserPermissions.php +++ b/ui/tests/selenium/testUrlUserPermissions.php @@ -601,24 +601,6 @@ class testUrlUserPermissions extends CLegacyWebTest { ] ]], [[ - 'url' => 'zabbix.php?action=workingtime.edit', - 'title' => 'Configuration of working time', - 'users' => [ - 'guest' => false, - 'user-zabbix' => false, - 'admin-zabbix' => false - ] - ]], - [[ - 'url' => 'zabbix.php?action=trigseverity.edit', - 'title' => 'Configuration of trigger severities', - 'users' => [ - 'guest' => false, - 'user-zabbix' => false, - 'admin-zabbix' => false - ] - ]], - [[ 'url' => 'zabbix.php?action=trigdisplay.edit', 'title' => 'Configuration of trigger displaying options', 'users' => [ diff --git a/ui/tests/unit/include/classes/api/APITest.php b/ui/tests/unit/include/classes/api/APITest.php index 7327a390449..782e7b124fc 100644 --- a/ui/tests/unit/include/classes/api/APITest.php +++ b/ui/tests/unit/include/classes/api/APITest.php @@ -51,5 +51,7 @@ class CAPITest extends PHPUnit_Framework_TestCase { $item = API::getApi('item'); $this->assertEquals(get_class($item), 'CApiWrapper'); $this->assertEquals($item->api, 'item'); + + API::setWrapper(); } } diff --git a/ui/tests/unit/include/classes/parsers/CValidationRuleTest.php b/ui/tests/unit/include/classes/parsers/CValidationRuleTest.php index 797bf190447..f533385a986 100644 --- a/ui/tests/unit/include/classes/parsers/CValidationRuleTest.php +++ b/ui/tests/unit/include/classes/parsers/CValidationRuleTest.php @@ -139,6 +139,55 @@ class CValidationRuleTest extends PHPUnit_Framework_TestCase { 'range_time' => true ] ], + ['time_unit', '', + [ + 'time_unit' => [] + ] + ], + ['time_unit 60:3600', '', + [ + 'time_unit' => [ + 'ranges' => [['from' => '60', 'to' => '3600']] + ] + ] + ], + ['time_unit 0,60:3600', '', + [ + 'time_unit' => [ + 'ranges' => [ + ['from' => '0', 'to' => '0'], + ['from' => '60', 'to' => '3600'] + ] + ] + ] + ], + ['time_unit_year', '', + [ + 'time_unit' => [ + 'with_year' => true + ] + ] + ], + ['time_unit_year 60:3600', '', + [ + 'time_unit' => [ + 'with_year' => true, + 'ranges' => [['from' => '60', 'to' => '3600']] + ] + ] + ], + ['time_unit_year 0,60:3600,7200:9800', '', + [ + 'time_unit' => [ + 'with_year' => true, + 'ranges' => [ + ['from' => '0', 'to' => '0'], + ['from' => '60', 'to' => '3600'], + ['from' => '7200', 'to' => '9800'] + ] + ] + ] + ], ['array_id', '', [ 'array_id' => true diff --git a/ui/tests/unit/include/classes/validators/CApiInputValidatorTest.php b/ui/tests/unit/include/classes/validators/CApiInputValidatorTest.php index 6e7cbcec47d..69dfd95ba77 100644 --- a/ui/tests/unit/include/classes/validators/CApiInputValidatorTest.php +++ b/ui/tests/unit/include/classes/validators/CApiInputValidatorTest.php @@ -21,6 +21,24 @@ class CApiInputValidatorTest extends PHPUnit_Framework_TestCase { + public function setUp() { + $settings = $this->createMock(CSettings::class); + $settings->method('get') + ->will($this->returnValue([ + CSettingsHelper::VALIDATE_URI_SCHEMES => '1', + CSettingsHelper::URI_VALID_SCHEMES => 'http,https,ftp,file,mailto,tel,ssh' + ])); + + $instances_map = [ + ['settings', $settings] + ]; + $api_service_factory = $this->createMock('CApiServiceFactory'); + $api_service_factory->method('getObject') + ->will($this->returnValueMap($instances_map)); + + API::setApiServiceFactory($api_service_factory); + } + public function dataProviderInput() { return [ [ diff --git a/ui/tests/unit/include/classes/validators/CHtmlUrlValidatorTest.php b/ui/tests/unit/include/classes/validators/CHtmlUrlValidatorTest.php index b6c6e7abc80..ba0979dd986 100644 --- a/ui/tests/unit/include/classes/validators/CHtmlUrlValidatorTest.php +++ b/ui/tests/unit/include/classes/validators/CHtmlUrlValidatorTest.php @@ -20,8 +20,25 @@ class CHtmlUrlValidatorTest extends PHPUnit_Framework_TestCase { + public function setUp() { + $settings = $this->createMock(CSettings::class); + $settings->method('get') + ->will($this->returnValue([ + CSettingsHelper::VALIDATE_URI_SCHEMES => '1', + CSettingsHelper::URI_VALID_SCHEMES => 'http,https,ftp,file,mailto,tel,ssh' + ])); - // Expected results are defined assuming that VALIDATE_URI_SCHEMES is enabled (set to be true). + $instances_map = [ + ['settings', $settings] + ]; + $api_service_factory = $this->createMock(CApiServiceFactory::class); + $api_service_factory->method('getObject') + ->will($this->returnValueMap($instances_map)); + + API::setApiServiceFactory($api_service_factory); + } + + // Expected results are defined assuming that CSettingsHelper::VALIDATE_URI_SCHEMES is enabled (set to be 1). public function providerValidateURL() { return [ // Valid URLs. diff --git a/ui/toptriggers.php b/ui/toptriggers.php index 88aec08b4cd..b711d879afd 100644 --- a/ui/toptriggers.php +++ b/ui/toptriggers.php @@ -41,8 +41,6 @@ $fields = [ check_fields($fields); validateTimeSelectorPeriod(getRequest('from'), getRequest('to')); -$data['config'] = select_config(); - /* * Filter */ diff --git a/ui/tr_events.php b/ui/tr_events.php index 68e2e3dd147..181567bdbeb 100644 --- a/ui/tr_events.php +++ b/ui/tr_events.php @@ -141,15 +141,6 @@ else { $event['opdata'] = (new CCol(CScreenProblem::getLatestValues($db_items)))->addClass('latest-values'); } -$config = select_config(); -$severity_config = [ - 'severity_name_0' => $config['severity_name_0'], - 'severity_name_1' => $config['severity_name_1'], - 'severity_name_2' => $config['severity_name_2'], - 'severity_name_3' => $config['severity_name_3'], - 'severity_name_4' => $config['severity_name_4'], - 'severity_name_5' => $config['severity_name_5'] -]; $actions = getEventDetailsActions($event); $users = API::User()->get([ 'output' => ['alias', 'name', 'surname'], @@ -174,7 +165,7 @@ $event_tab = (new CDiv([ ]), new CDiv([ (new CCollapsibleUiWidget(WIDGET_HAT_EVENTACTIONS, - makeEventDetailsActionsTable($actions, $users, $mediatypes, $severity_config) + makeEventDetailsActionsTable($actions, $users, $mediatypes) )) ->setExpanded((bool) CProfile::get('web.tr_events.hats.'.WIDGET_HAT_EVENTACTIONS.'.state', true)) ->setHeader(_('Actions'), [], 'web.tr_events.hats.'.WIDGET_HAT_EVENTACTIONS.'.state') diff --git a/ui/trigger_prototypes.php b/ui/trigger_prototypes.php index 6d78b3ea8ce..3dc02896c25 100644 --- a/ui/trigger_prototypes.php +++ b/ui/trigger_prototypes.php @@ -530,8 +530,6 @@ if (hasRequest('action') && getRequest('action') !== 'triggerprototype.massupdat uncheckTableRows(getRequest('parent_discoveryid'), zbx_objectValues($triggerPrototypes, 'triggerid')); } -$config = select_config(); - /* * Display */ @@ -546,7 +544,6 @@ if ((getRequest('action') === 'triggerprototype.massupdateform' || hasRequest('m } elseif (isset($_REQUEST['form'])) { $data = getTriggerFormData([ - 'config' => $config, 'form' => getRequest('form'), 'form_refresh' => getRequest('form_refresh'), 'parent_discoveryid' => getRequest('parent_discoveryid'), @@ -598,7 +595,6 @@ else { 'triggers' => [], 'sort' => $sortField, 'sortorder' => $sortOrder, - 'config' => $config, 'dependencyTriggers' => [] ]; @@ -608,7 +604,7 @@ else { 'output' => ['triggerid', $sortField], 'discoveryids' => $data['parent_discoveryid'], 'sortfield' => $sortField, - 'limit' => $config['search_limit'] + 1 + 'limit' => CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1 ]; $data['triggers'] = API::TriggerPrototype()->get($options); diff --git a/ui/triggers.php b/ui/triggers.php index ca68548e3b1..db667813496 100644 --- a/ui/triggers.php +++ b/ui/triggers.php @@ -615,8 +615,6 @@ elseif (hasRequest('action') && getRequest('action') === 'trigger.massdelete' && show_messages($result, _('Triggers deleted'), _('Cannot delete triggers')); } -$config = select_config(); - /* * Display */ @@ -629,7 +627,6 @@ if ((getRequest('action') === 'trigger.massupdateform' || hasRequest('massupdate } elseif (isset($_REQUEST['form'])) { $data = [ - 'config' => $config, 'form' => getRequest('form'), 'form_refresh' => getRequest('form_refresh'), 'parent_discoveryid' => null, @@ -777,7 +774,7 @@ else { 'inherited' => ($filter_inherited != -1) ? $filter_inherited : null, 'preservekeys' => true, 'sortfield' => $sort, - 'limit' => $config['search_limit'] + 1 + 'limit' => CSettingsHelper::get(CSettingsHelper::SEARCH_LIMIT) + 1 ]; if ($sort === 'status') { @@ -1010,7 +1007,6 @@ else { $checkbox_hash = crc32(implode('', $filter_hostids)); $data = [ - 'config' => $config, 'triggers' => $triggers, 'profileIdx' => 'web.triggers.filter', 'active_tab' => $active_tab, |