1<?php declare(strict_types = 1); 2/* 3** Zabbix 4** Copyright (C) 2001-2021 Zabbix SIA 5** 6** This program is free software; you can redistribute it and/or modify 7** it under the terms of the GNU General Public License as published by 8** the Free Software Foundation; either version 2 of the License, or 9** (at your option) any later version. 10** 11** This program is distributed in the hope that it will be useful, 12** but WITHOUT ANY WARRANTY; without even the implied warranty of 13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14** GNU General Public License for more details. 15** 16** You should have received a copy of the GNU General Public License 17** along with this program; if not, write to the Free Software 18** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19**/ 20 21 22/** 23 * A class for accessing once loaded parameters of Settings API object. 24 */ 25class CSettingsHelper extends CConfigGeneralHelper { 26 27 public const ALERT_USRGRPID = 'alert_usrgrpid'; 28 public const BLINK_PERIOD = 'blink_period'; 29 public const CONNECT_TIMEOUT = 'connect_timeout'; 30 public const CUSTOM_COLOR = 'custom_color'; 31 public const DEFAULT_INVENTORY_MODE = 'default_inventory_mode'; 32 public const DEFAULT_LANG = 'default_lang'; 33 public const DEFAULT_THEME = 'default_theme'; 34 public const DEFAULT_TIMEZONE = 'default_timezone'; 35 public const DISCOVERY_GROUPID = 'discovery_groupid'; 36 public const HISTORY_PERIOD = 'history_period'; 37 public const IFRAME_SANDBOXING_ENABLED = 'iframe_sandboxing_enabled'; 38 public const IFRAME_SANDBOXING_EXCEPTIONS = 'iframe_sandboxing_exceptions'; 39 public const ITEM_TEST_TIMEOUT = 'item_test_timeout'; 40 public const LOGIN_ATTEMPTS = 'login_attempts'; 41 public const LOGIN_BLOCK = 'login_block'; 42 public const MAX_IN_TABLE = 'max_in_table'; 43 public const MAX_PERIOD = 'max_period'; 44 public const MAX_OVERVIEW_TABLE_SIZE = 'max_overview_table_size'; 45 public const MEDIA_TYPE_TEST_TIMEOUT = 'media_type_test_timeout'; 46 public const OK_ACK_COLOR = 'ok_ack_color'; 47 public const OK_ACK_STYLE = 'ok_ack_style'; 48 public const OK_PERIOD = 'ok_period'; 49 public const OK_UNACK_COLOR = 'ok_unack_color'; 50 public const OK_UNACK_STYLE = 'ok_unack_style'; 51 public const PERIOD_DEFAULT = 'period_default'; 52 public const PROBLEM_ACK_COLOR = 'problem_ack_color'; 53 public const PROBLEM_ACK_STYLE = 'problem_ack_style'; 54 public const PROBLEM_UNACK_COLOR = 'problem_unack_color'; 55 public const PROBLEM_UNACK_STYLE = 'problem_unack_style'; 56 public const SCRIPT_TIMEOUT = 'script_timeout'; 57 public const SEARCH_LIMIT = 'search_limit'; 58 public const SERVER_CHECK_INTERVAL = 'server_check_interval'; 59 public const SEVERITY_COLOR_0 = 'severity_color_0'; 60 public const SEVERITY_COLOR_1 = 'severity_color_1'; 61 public const SEVERITY_COLOR_2 = 'severity_color_2'; 62 public const SEVERITY_COLOR_3 = 'severity_color_3'; 63 public const SEVERITY_COLOR_4 = 'severity_color_4'; 64 public const SEVERITY_COLOR_5 = 'severity_color_5'; 65 public const SEVERITY_NAME_0 = 'severity_name_0'; 66 public const SEVERITY_NAME_1 = 'severity_name_1'; 67 public const SEVERITY_NAME_2 = 'severity_name_2'; 68 public const SEVERITY_NAME_3 = 'severity_name_3'; 69 public const SEVERITY_NAME_4 = 'severity_name_4'; 70 public const SEVERITY_NAME_5 = 'severity_name_5'; 71 public const SHOW_TECHNICAL_ERRORS = 'show_technical_errors'; 72 public const SNMPTRAP_LOGGING = 'snmptrap_logging'; 73 public const SOCKET_TIMEOUT = 'socket_timeout'; 74 public const URI_VALID_SCHEMES = 'uri_valid_schemes'; 75 public const VALIDATE_URI_SCHEMES = 'validate_uri_schemes'; 76 public const WORK_PERIOD = 'work_period'; 77 public const X_FRAME_OPTIONS = 'x_frame_options'; 78 public const SESSION_KEY = 'session_key'; 79 public const URL = 'url'; 80 public const SCHEDULED_REPORT_TEST_TIMEOUT = 'report_test_timeout'; 81 public const DBVERSION_STATUS = 'dbversion_status'; 82 83 /** 84 * Settings API object parameters array. 85 * 86 * @static 87 * 88 * @var array 89 */ 90 protected static $params = []; 91 92 /** 93 * @inheritdoc 94 */ 95 protected static function loadParams(?string $param = null, bool $is_global = false): void { 96 if (!self::$params) { 97 self::$params = $is_global 98 ? API::getApiService('settings')->getGlobal(['output' => 'extend'], false) 99 : API::Settings()->get(['output' => 'extend']); 100 } 101 else if (!$is_global && $param && !array_key_exists($param, self::$params)) { 102 $settings = API::Settings()->get(['output' => 'extend']); 103 self::$params = is_array($settings) ? ($settings + self::$params) : false; 104 } 105 106 if (self::$params === false) { 107 throw new Exception(_('Unable to load settings API parameters.')); 108 } 109 } 110 111 /** 112 * Get value by global parameter name of API object (load parameters if need). 113 * 114 * @static 115 * 116 * @param string $name API object global parameter name. 117 * 118 * @return string|null Parameter value. If parameter not exists, return null. 119 */ 120 public static function getGlobal(string $name): ?string { 121 self::loadParams($name, true); 122 123 return array_key_exists($name, self::$params) ? self::$params[$name] : null; 124 } 125} 126