File: CSettingsHelper.php

package info (click to toggle)
zabbix 1%3A7.0.10%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 272,688 kB
  • sloc: sql: 946,050; ansic: 389,440; php: 292,698; javascript: 83,388; sh: 5,680; makefile: 3,285; java: 1,420; cpp: 694; perl: 64; xml: 56
file content (208 lines) | stat: -rw-r--r-- 8,656 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php declare(strict_types = 0);
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** 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 Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/


/**
 * A class for accessing once loaded parameters of Settings API object.
 */
class CSettingsHelper {

	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 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';
	public const SESSION_KEY = 'session_key';
	public const URL = 'url';
	public const SCHEDULED_REPORT_TEST_TIMEOUT = 'report_test_timeout';
	public const DBVERSION_STATUS = 'dbversion_status';
	public const SERVER_STATUS = 'server_status';
	public const AUDITLOG_ENABLED = 'auditlog_enabled';
	public const AUDITLOG_MODE = 'auditlog_mode';
	public const GEOMAPS_TILE_PROVIDER = 'geomaps_tile_provider';
	public const GEOMAPS_TILE_URL = 'geomaps_tile_url';
	public const GEOMAPS_MAX_ZOOM = 'geomaps_max_zoom';
	public const GEOMAPS_ATTRIBUTION = 'geomaps_attribution';
	public const HA_FAILOVER_DELAY = 'ha_failover_delay';
	public const VAULT_PROVIDER = 'vault_provider';
	public const TIMEOUT_ZABBIX_AGENT = 'timeout_zabbix_agent';
	public const TIMEOUT_SIMPLE_CHECK = 'timeout_simple_check';
	public const TIMEOUT_SNMP_AGENT = 'timeout_snmp_agent';
	public const TIMEOUT_EXTERNAL_CHECK = 'timeout_external_check';
	public const TIMEOUT_DB_MONITOR = 'timeout_db_monitor';
	public const TIMEOUT_HTTP_AGENT = 'timeout_http_agent';
	public const TIMEOUT_SSH_AGENT = 'timeout_ssh_agent';
	public const TIMEOUT_TELNET_AGENT = 'timeout_telnet_agent';
	public const TIMEOUT_SCRIPT = 'timeout_script';
	public const TIMEOUT_BROWSER = 'timeout_browser';
	public const SOFTWARE_UPDATE_CHECKID = 'software_update_checkid';
	public const SOFTWARE_UPDATE_CHECK_DATA = 'software_update_check_data';

	private static $params = [];
	private static $params_public = [];
	private static $params_private = [];

	/**
	 * Get the value of the given Settings API object's field.
	 *
	 * @param string $field
	 *
	 * @throws Exception
	 *
	 * @return string
	 */
	public static function get(string $field): string {
		if (!self::$params) {
			self::$params = API::Settings()->get([
				'output' => [
					'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', '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', 'url', 'report_test_timeout',
					'auditlog_enabled', 'auditlog_mode', 'ha_failover_delay', 'geomaps_tile_provider',
					'geomaps_tile_url', 'geomaps_max_zoom', 'geomaps_attribution', 'vault_provider',
					'timeout_zabbix_agent', 'timeout_simple_check', 'timeout_snmp_agent', 'timeout_external_check',
					'timeout_db_monitor', 'timeout_http_agent', 'timeout_ssh_agent', 'timeout_telnet_agent',
					'timeout_script', 'timeout_browser'
				]
			]);

			if (self::$params === false) {
				throw new Exception(_('Unable to load settings API parameters.'));
			}
		}

		return self::$params[$field];
	}

	/**
	 * Get the value of the given Settings API object's field available to parts of the UI without authentication.
	 *
	 * @param string $field
	 *
	 * @return string
	 */
	public static function getPublic(string $field): string {
		if (!self::$params_public) {
			self::$params_public = CSettings::getPublic();
		}

		return self::$params_public[$field];
	}

	/**
	 * Get the value of the given private settings field used in UI.
	 *
	 * @param string $field
	 *
	 * @return string
	 */
	public static function getPrivate(string $field): string {
		if (!self::$params_private) {
			self::$params_private = CSettings::getPrivate();
		}

		$supported_params = array_intersect_key(self::$params_private,
			array_flip([self::SESSION_KEY, self::SOFTWARE_UPDATE_CHECKID])
		);

		return $supported_params[$field];
	}

	public static function getDbVersionStatus(): array {
		if (!self::$params_private) {
			self::$params_private = CSettings::getPrivate();
		}

		return self::$params_private[self::DBVERSION_STATUS];
	}

	public static function getServerStatus(): array {
		if (!self::$params_private) {
			self::$params_private = CSettings::getPrivate();
		}

		return self::$params_private[self::SERVER_STATUS];
	}

	public static function getSoftwareUpdateCheckData(): array {
		if (!self::$params_private) {
			self::$params_private = CSettings::getPrivate();
		}

		return self::$params_private[self::SOFTWARE_UPDATE_CHECK_DATA];
	}

	public static function isGlobalScriptsEnabled(): bool {
		return self::getServerStatus()['configuration']['enable_global_scripts'];
	}

	public static function isSoftwareUpdateCheckEnabled(): bool {
		return !CWebUser::isGuest() && self::getServerStatus()['configuration']['allow_software_update_check'];
	}
}