diff options
author | Vladimirs Maksimovs <vladimirs.maksimovs@zabbix.com> | 2020-07-06 09:31:59 +0300 |
---|---|---|
committer | Vladimirs Maksimovs <vladimirs.maksimovs@zabbix.com> | 2020-07-06 09:31:59 +0300 |
commit | f3a39b8b4b897d668d5bbc553c40e4cbd4b726ba (patch) | |
tree | 41282fc62494f3b348dba53306a4c0380f845508 | |
parent | f605c13d7f32b9641686e9d14670ed757ca8ebd6 (diff) |
A.F....... [ZBXNEXT-82] implemented helpers parameters usage in Aministration -> General -> Other page; fixed wrong validation and preserving for settings.update API method
-rw-r--r-- | ui/app/controllers/CControllerGuiUpdate.php | 9 | ||||
-rw-r--r-- | ui/app/controllers/CControllerMiscConfigEdit.php | 75 | ||||
-rw-r--r-- | ui/app/controllers/CControllerMiscConfigUpdate.php | 152 | ||||
-rw-r--r-- | ui/app/controllers/CControllerTrigDisplayUpdate.php | 10 | ||||
-rw-r--r-- | ui/app/views/administration.gui.edit.php | 6 | ||||
-rw-r--r-- | ui/app/views/administration.miscconfig.edit.php | 128 | ||||
-rw-r--r-- | ui/app/views/js/administration.miscconfig.edit.js.php | 78 | ||||
-rw-r--r-- | ui/app/views/popup.generic.php | 16 | ||||
-rw-r--r-- | ui/include/classes/api/services/CSettings.php | 14 | ||||
-rw-r--r-- | ui/include/profiles.inc.php | 75 |
10 files changed, 410 insertions, 153 deletions
diff --git a/ui/app/controllers/CControllerGuiUpdate.php b/ui/app/controllers/CControllerGuiUpdate.php index 0583170e1f9..73567a8dba9 100644 --- a/ui/app/controllers/CControllerGuiUpdate.php +++ b/ui/app/controllers/CControllerGuiUpdate.php @@ -79,10 +79,9 @@ class CControllerGuiUpdate extends CController { foreach ($fields as $field => $args) { $options = array_key_exists('with_year', $args) ? ['with_year' => true] : []; - if ($this->hasInput($field) - && !validateTimeUnit($this->getInput($field), $args['min'], $args['max'], $args['allow_zero'], - $error, $options - )) { + if (!validateTimeUnit($this->getInput($field), $args['min'], $args['max'], $args['allow_zero'],$error, + $options + )) { $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) ->setArgument('action', 'gui.edit') ->getUrl() @@ -112,7 +111,7 @@ class CControllerGuiUpdate extends CController { 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'), + 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') diff --git a/ui/app/controllers/CControllerMiscConfigEdit.php b/ui/app/controllers/CControllerMiscConfigEdit.php index f402563da9f..27de7a36780 100644 --- a/ui/app/controllers/CControllerMiscConfigEdit.php +++ b/ui/app/controllers/CControllerMiscConfigEdit.php @@ -27,11 +27,22 @@ 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', + 'session_name' => 'db config.session_name', + 'validate_uri_schemes' => 'db config.validate_uri_schemes', + 'uri_valid_schemes' => 'db config.uri_valid_schemes', + 'x_frame_options' => 'db config.x_frame_options', + '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 +59,57 @@ 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)), + 'session_name' => + $this->getInput('session_name', CSettingsHelper::get(CSettingsHelper::SESSION_NAME)), + '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)), + '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..6fc4c7c9e29 100644 --- a/ui/app/controllers/CControllerMiscConfigUpdate.php +++ b/ui/app/controllers/CControllerMiscConfigUpdate.php @@ -22,12 +22,24 @@ class CControllerMiscConfigUpdate extends CController { protected function checkInput() { + $host_inventory_values = HOST_INVENTORY_DISABLED.','.HOST_INVENTORY_MANUAL.','.HOST_INVENTORY_AUTOMATIC; $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', + 'discovery_groupid' => 'required|db config.discovery_groupid', + 'default_inventory_mode' => 'required|db config.default_inventory_mode|in '.$host_inventory_values, + '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', + 'session_name' => 'required|db config.session_name', + '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', + 'socket_timeout' => 'required|db config.socket_timeout', + 'connect_timeout' => 'required|db config.connect_timeout', + 'media_type_test_timeout' => 'required|db config.media_type_test_timeout', + 'script_timeout' => 'required|db config.script_timeout', + 'item_test_timeout' => 'required|db config.item_test_timeout' ]; $ret = $this->validateInput($fields); @@ -39,7 +51,7 @@ class CControllerMiscConfigUpdate extends CController { ->setArgument('action', 'miscconfig.edit') ); - $response->setFormData($this->getInputAll()); + $response->setFormData($this->getInputAll() + ['discovery_groupid' => '0']); $response->setMessageError(_('Cannot update configuration')); $this->setResponse($response); @@ -50,6 +62,95 @@ class CControllerMiscConfigUpdate extends CController { break; } } + else { + $fields = [ + 'refresh_unsupported' => [ + 'min' => 0, + 'max' => SEC_PER_DAY, + 'allow_zero' => false, + 'message' => _('Invalid refresh of unsupported items: %1$s') + ], + 'login_block' => [ + 'min' => 30, + 'max' => SEC_PER_HOUR, + 'allow_zero' => false, + 'message' => _('Invalid login blocking interval: %1$s.') + ], + 'socket_timeout' => [ + 'min' => 1, + 'max' => 300, + 'allow_zero' => false, + 'message' => _('Invalid network timeout: %1$s.') + ], + 'connect_timeout' => [ + 'min' => 1, + 'max' => 30, + 'allow_zero' => false, + 'message' => _('Invalid connection timeout: %1$s.') + ], + 'media_type_test_timeout' => [ + 'min' => 1, + 'max' => 300, + 'allow_zero' => false, + 'message' => _('Invalid network timeout for media type test: %1$s.') + ], + 'script_timeout' => [ + 'min' => 1, + 'max' => 300, + 'allow_zero' => false, + 'message' => _('Invalid network timeout for script execution: %1$s.') + ], + 'item_test_timeout' => [ + 'min' => 1, + 'max' => 300, + 'allow_zero' => false, + 'message' => _('Invalid network timeout for item test: %1$s.') + ], + ]; + + foreach ($fields as $field => $args) { + if (!validateTimeUnit($this->getInput($field), $args['min'], $args['max'], $args['allow_zero'], + $error + )) { + error(sprintf($args['message'], $error)); + + $ret = false; + break; + } + } + + $discovery_group_exists = API::HostGroup()->get([ + 'countOutput' => true, + 'groupids' => $this->getInput('discovery_groupid') + ]); + if (!$discovery_group_exists) { + error(_('Incorrect host group.')); + + $ret = false; + } + + if ($this->hasInput('alert_usrgrpid')) { + $user_group_exists = API::UserGroup()->get([ + 'countOutput' => true, + 'usrgrpids' => $this->getInput('alert_usrgrpid'), + ]); + if (!$user_group_exists) { + error(_('Incorrect user group.')); + + $ret = false; + } + } + + if (!$ret) { + $response = new CControllerResponseRedirect((new CUrl('zabbix.php')) + ->setArgument('action', 'miscconfig.edit') + ->getUrl() + ); + $response->setFormData($this->getInputAll()); + $response->setMessageError(_('Cannot update configuration')); + $this->setResponse($response); + } + } return $ret; } @@ -59,20 +160,39 @@ 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::SESSION_NAME => $this->getInput('session_name'), + CSettingsHelper::VALIDATE_URI_SCHEMES => $this->getInput('validate_uri_schemes'), + CSettingsHelper::X_FRAME_OPTIONS => $this->getInput('x_frame_options'), + 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'] + ); + } + + $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/CControllerTrigDisplayUpdate.php b/ui/app/controllers/CControllerTrigDisplayUpdate.php index 0e2220aae03..3c33af3cd6d 100644 --- a/ui/app/controllers/CControllerTrigDisplayUpdate.php +++ b/ui/app/controllers/CControllerTrigDisplayUpdate.php @@ -23,7 +23,8 @@ class CControllerTrigDisplayUpdate extends CController { protected function checkInput() { $fields = [ - 'custom_color' => 'required|db config.custom_color|in '.EVENT_CUSTOM_COLOR_DISABLED.','.EVENT_CUSTOM_COLOR_ENABLED, + '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', @@ -77,10 +78,9 @@ class CControllerTrigDisplayUpdate extends CController { ]; foreach ($fields as $field => $args) { - if ($this->hasInput($field) - && !validateTimeUnit($this->getInput($field), $args['min'], $args['max'], $args['allow_zero'], - $error - )) { + if (!validateTimeUnit($this->getInput($field), $args['min'], $args['max'], $args['allow_zero'], + $error + )) { error(sprintf($args['message'], $error)); $ret = false; diff --git a/ui/app/views/administration.gui.edit.php b/ui/app/views/administration.gui.edit.php index f2527133e14..cd1d88ae6b8 100644 --- a/ui/app/views/administration.gui.edit.php +++ b/ui/app/views/administration.gui.edit.php @@ -48,9 +48,9 @@ $gui_tab = (new CFormList()) ->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() + (new CTextBox('work_period', $data['work_period'])) + ->setWidth(ZBX_TEXTAREA_MEDIUM_WIDTH) + ->setAriaRequired() ) ->addRow(_('Show technical errors'), (new CCheckBox('show_technical_errors')) diff --git a/ui/app/views/administration.miscconfig.edit.php b/ui/app/views/administration.miscconfig.edit.php index 3059f0052ac..8b5048ef7a8 100644 --- a/ui/app/views/administration.miscconfig.edit.php +++ b/ui/app/views/administration.miscconfig.edit.php @@ -23,31 +23,38 @@ * @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'])) ->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 +62,95 @@ $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'])) + ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) + ->setAriaRequired() + ) + ->addRow((new CLabel(_('Session name'), 'session_name'))->setAsteriskMark(), + (new CTextBox('session_name', $data['session_name'])) + ->setWidth(ZBX_TEXTAREA_MEDIUM_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'])) + ->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'])) + ->setWidth(ZBX_TEXTAREA_MEDIUM_WIDTH) + ->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'])) + ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) + ->setAriaRequired() + ) + ->addRow( + (new CLabel(_('Connection timeout'), 'connect_timeout'))->setAsteriskMark(), + (new CTextBox('connect_timeout', $data['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'])) + ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) + ->setAriaRequired() + ) + ->addRow( + (new CLabel(_('Network timeout for script execution'), 'script_timeout'))->setAsteriskMark(), + (new CTextBox('script_timeout', $data['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'])) + ->setWidth(ZBX_TEXTAREA_TINY_WIDTH) + ->setAriaRequired() ); $form = (new CForm()) @@ -72,7 +163,10 @@ $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(); 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..49dcb6cdfed --- /dev/null +++ b/ui/app/views/js/administration.miscconfig.edit.js.php @@ -0,0 +1,78 @@ +<?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'); +$default_inventory_mode = $schema['fields']['default_inventory_mode']['default']; +?> + +<script type="text/javascript"> + $(document).ready(function() { + $('#validate_uri_schemes').change(function() { + $('#uri_valid_schemes').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() { + $('#refresh_unsupported').val("<?= $schema['fields']['refresh_unsupported']['default'] ?>"); + $('#discovery_groupid').multiSelect('clean'); + $('#default_inventory_mode input[value=<?= $default_inventory_mode ?>]') + .prop('checked', true); + $('#alert_usrgrpid').multiSelect('clean'); + $('#snmptrap_logging').prop('checked', + <?= ($schema['fields']['snmptrap_logging']['default'] == 0) ? 'false' : 'true' ?> + ); + $('#login_attempts').val("<?= $schema['fields']['login_attempts']['default'] ?>"); + $('#login_block').val("<?= $schema['fields']['login_block']['default'] ?>"); + $('#session_name').val("<?= $schema['fields']['session_name']['default'] ?>"); + $('#validate_uri_schemes').prop('checked', + <?= ($schema['fields']['validate_uri_schemes']['default'] == 0) ? 'false' : 'true' ?> + ); + $('#uri_valid_schemes').val("<?= $schema['fields']['uri_valid_schemes']['default'] ?>"); + $('#x_frame_options').val("<?= $schema['fields']['x_frame_options']['default'] ?>"); + $('#socket_timeout').val("<?= $schema['fields']['socket_timeout']['default'] ?>"); + $('#connect_timeout').val("<?= $schema['fields']['connect_timeout']['default'] ?>"); + $('#media_type_test_timeout').val("<?= $schema['fields']['media_type_test_timeout']['default'] ?>"); + $('#script_timeout').val("<?= $schema['fields']['script_timeout']['default'] ?>"); + $('#item_test_timeout').val("<?= $schema['fields']['item_test_timeout']['default'] ?>"); + } + } + ] + }, this); + }); + }); +</script> diff --git a/ui/app/views/popup.generic.php b/ui/app/views/popup.generic.php index 1f97502a85a..e8ae48dd655 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']) @@ -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/include/classes/api/services/CSettings.php b/ui/include/classes/api/services/CSettings.php index 203b626c4e8..6cc2229eaf3 100644 --- a/ui/include/classes/api/services/CSettings.php +++ b/ui/include/classes/api/services/CSettings.php @@ -125,6 +125,12 @@ class CSettings extends CApiService { '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) { + setHostGroupInternal($db_settings['discovery_groupid'], ZBX_NOT_INTERNAL_GROUP); + setHostGroupInternal($upd_config['discovery_groupid'], ZBX_INTERNAL_GROUP); + } } $this->addAuditBulk(AUDIT_ACTION_UPDATE, AUDIT_RESOURCE_SETTINGS, @@ -185,7 +191,7 @@ class CSettings extends CApiService { '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], + 'alert_usrgrpid' => ['type' => API_ID, 'flags' => API_ALLOW_NULL], 'snmptrap_logging' => ['type' => API_INT32, 'in' => '0,1'], 'login_attempts' => ['type' => API_INT32, 'in' => '1:32'], 'login_block' => ['type' => API_TIME_UNIT, 'in' => implode(':', [30, SEC_PER_HOUR])], @@ -221,12 +227,12 @@ class CSettings extends CApiService { } } - if (array_key_exists('alert_usrgrpid', $settings)) { - $db_usrgrp_exists = DB::select('usrgrp', [ + 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[0]['rowscount']) { + if (!$db_usrgrp_exists) { self::exception(ZBX_API_ERROR_PARAMETERS, _s('User group with ID "%1$s" is not available.', $settings['alert_usrgrpid'])); } diff --git a/ui/include/profiles.inc.php b/ui/include/profiles.inc.php index cdfc6afd93b..58ed6e9dd8e 100644 --- a/ui/include/profiles.inc.php +++ b/ui/include/profiles.inc.php @@ -45,60 +45,11 @@ function setHostGroupInternal($groupid, $internal) { } 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 = [ - 'refresh_unsupported' => [ - 'min' => 0, - 'max' => SEC_PER_DAY, - 'allow_zero' => false, - 'message' => _('Invalid refresh of unsupported items: %1$s') - ], - ]; - - 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; - } - } - $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); - } + $update[] = $key.'='.zbx_dbstr($value); } } @@ -109,29 +60,5 @@ function update_config($config) { $result = DBexecute('UPDATE config SET '.implode(',', $update)); - if ($result) { - $msg = []; - 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; } |