function eventHandler() { if (isset($_REQUEST['back'][$this->getStep()])) { $this->doBack(); } if ($this->getStep() == 1) { if (isset($_REQUEST['next'][$this->getStep()])) { $this->doNext(); } $this->DISABLE_NEXT_BUTTON = true; } elseif ($this->getStep() == 2) { $this->setConfig('DB_TYPE', get_request('type', $this->getConfig('DB_TYPE'))); $this->setConfig('DB_SERVER', get_request('server', $this->getConfig('DB_SERVER', 'localhost'))); $this->setConfig('DB_PORT', get_request('port', $this->getConfig('DB_PORT', '0'))); $this->setConfig('DB_DATABASE', get_request('database', $this->getConfig('DB_DATABASE', 'zabbix'))); $this->setConfig('DB_USER', get_request('user', $this->getConfig('DB_USER', 'root'))); $this->setConfig('DB_PASSWORD', get_request('password', $this->getConfig('DB_PASSWORD', ''))); $this->setConfig('DB_SCHEMA', get_request('schema', $this->getConfig('DB_SCHEMA', ''))); if (isset($_REQUEST['retry'])) { if (!$this->checkConnection()) { $this->DISABLE_NEXT_BUTTON = true; unset($_REQUEST['next']); } } elseif (!isset($_REQUEST['next'][$this->getStep()])) { $this->DISABLE_NEXT_BUTTON = true; unset($_REQUEST['next']); } if (isset($_REQUEST['next'][$this->getStep()])) { $this->doNext(); } } elseif ($this->getStep() == 3) { $this->setConfig('ZBX_SERVER', get_request('zbx_server', $this->getConfig('ZBX_SERVER', 'localhost'))); $this->setConfig('ZBX_SERVER_PORT', get_request('zbx_server_port', $this->getConfig('ZBX_SERVER_PORT', '10051'))); $this->setConfig('ZBX_SERVER_NAME', get_request('zbx_server_name', $this->getConfig('ZBX_SERVER_NAME', ''))); if (isset($_REQUEST['next'][$this->getStep()])) { $this->doNext(); } } elseif ($this->getStep() == 4 && isset($_REQUEST['next'][$this->getStep()])) { $this->doNext(); } elseif ($this->getStep() == 5) { if (isset($_REQUEST['save_config'])) { // make zabbix.conf.php downloadable header('Content-Type: application/x-httpd-php'); header('Content-Disposition: attachment; filename="' . basename(CConfigFile::CONFIG_FILE_PATH) . '"'); $config = new CConfigFile(Z::getInstance()->getRootDir() . CConfigFile::CONFIG_FILE_PATH); $config->config = array('DB' => array('TYPE' => $this->getConfig('DB_TYPE'), 'SERVER' => $this->getConfig('DB_SERVER'), 'PORT' => $this->getConfig('DB_PORT'), 'DATABASE' => $this->getConfig('DB_DATABASE'), 'USER' => $this->getConfig('DB_USER'), 'PASSWORD' => $this->getConfig('DB_PASSWORD'), 'SCHEMA' => $this->getConfig('DB_SCHEMA')), 'ZBX_SERVER' => $this->getConfig('ZBX_SERVER'), 'ZBX_SERVER_PORT' => $this->getConfig('ZBX_SERVER_PORT'), 'ZBX_SERVER_NAME' => $this->getConfig('ZBX_SERVER_NAME')); die($config->getString()); } } if (isset($_REQUEST['next'][$this->getStep()])) { $this->doNext(); } }
** 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/func.inc.php'; require_once dirname(__FILE__) . '/include/classes/class.chttp_request.php'; $allowed_content = array('application/json-rpc' => 'json-rpc', 'application/json' => 'json-rpc', 'application/jsonrequest' => 'json-rpc'); $http_request = new CHTTP_request(); $content_type = $http_request->header('Content-Type'); $content_type = explode(';', $content_type); $content_type = $content_type[0]; if (!isset($allowed_content[$content_type])) { header('HTTP/1.0 412 Precondition Failed'); exit; } require_once dirname(__FILE__) . '/include/classes/core/Z.php'; header('Content-Type: application/json'); $data = $http_request->body(); try { Z::getInstance()->run(ZBase::EXEC_MODE_API); $jsonRpc = new CJSONrpc($data); echo $jsonRpc->execute(); } catch (Exception $e) { // decode input json request to get request's id $jsonData = CJs::decodeJson($data); $response = array('jsonrpc' => '2.0', 'error' => array('code' => 1, 'message' => $e->getMessage()), 'id' => isset($jsonData['id']) ? $jsonData['id'] : null); echo CJs::encodeJson($response); }
** 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. **/ // reset the LC_CTYPE locale so that case transformation functions would work correctly // it is also required for PHP to work with the Turkish locale (https://bugs.php.net/bug.php?id=18556) // WARNING: this must be done before executing any other code, otherwise code execution could fail! // this will be unnecessary in PHP 5.5 setlocale(LC_CTYPE, array('C', 'POSIX', 'en', 'en_US', 'en_US.UTF-8', 'English_United States.1252', 'en_GB', 'en_GB.UTF-8')); require_once dirname(__FILE__) . '/classes/core/Z.php'; try { Z::getInstance()->run(); } catch (DBException $e) { $warningView = new CView('general.warning', array('message' => array('header' => 'Database error', 'text' => $e->getMessage()))); $warningView->render(); exit; } catch (ConfigFileException $e) { switch ($e->getCode()) { case CConfigFile::CONFIG_NOT_FOUND: redirect('setup.php'); exit; case CConfigFile::CONFIG_ERROR: $warningView = new CView('general.warning', array('message' => array('header' => 'Configuration file error', 'text' => $e->getMessage()))); $warningView->render(); exit; } } catch (Exception $e) {
break; } } array_multisort($sortClock, SORT_ASC, $sortEvent, SORT_ASC, $result); break; case 'message.closeAll': $msgsettings = getMessageSettings(); switch (strtolower($data['params']['caption'])) { case 'events': $msgsettings['last.clock'] = (int) $data['params']['time'] + 1; updateMessageSettings($msgsettings); break; } break; case 'zabbix.status': $session = Z::getInstance()->getSession(); if (!isset($session['serverCheckResult']) || $session['serverCheckTime'] + SERVER_CHECK_INTERVAL <= time()) { $zabbixServer = new CZabbixServer($ZBX_SERVER, $ZBX_SERVER_PORT, ZBX_SOCKET_TIMEOUT, 0); $session['serverCheckResult'] = $zabbixServer->isRunning(); $session['serverCheckTime'] = time(); } $result = array('result' => (bool) $session['serverCheckResult'], 'message' => $session['serverCheckResult'] ? '' : _('Zabbix server is not running: the information displayed may not be current.')); break; case 'screen.get': $options = array('pageFile' => !empty($data['pageFile']) ? $data['pageFile'] : null, 'mode' => !empty($data['mode']) ? $data['mode'] : null, 'timestamp' => !empty($data['timestamp']) ? $data['timestamp'] : time(), 'resourcetype' => !empty($data['resourcetype']) ? $data['resourcetype'] : null, 'screenid' => isset($data['screenid']) && $data['screenid'] != 0 ? $data['screenid'] : null, 'screenitemid' => !empty($data['screenitemid']) ? $data['screenitemid'] : null, 'groupid' => !empty($data['groupid']) ? $data['groupid'] : null, 'hostid' => !empty($data['hostid']) ? $data['hostid'] : null, 'period' => !empty($data['period']) ? $data['period'] : null, 'stime' => !empty($data['stime']) ? $data['stime'] : null, 'profileIdx' => !empty($data['profileIdx']) ? $data['profileIdx'] : null, 'profileIdx2' => !empty($data['profileIdx2']) ? $data['profileIdx2'] : null, 'updateProfile' => isset($data['updateProfile']) ? $data['updateProfile'] : null); if ($options['resourcetype'] == SCREEN_RESOURCE_HISTORY) { $options['itemids'] = !empty($data['itemids']) ? $data['itemids'] : null; $options['action'] = !empty($data['action']) ? $data['action'] : null; $options['filter'] = !empty($data['filter']) ? $data['filter'] : null; $options['filter_task'] = !empty($data['filter_task']) ? $data['filter_task'] : null; $options['mark_color'] = !empty($data['mark_color']) ? $data['mark_color'] : null;
** 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/classes/core/Z.php'; try { Z::getInstance()->run(ZBase::EXEC_MODE_SETUP); } catch (Exception $e) { $warningView = new CView('general.warning', array('message' => 'Configuration file error: ' . $e->getMessage())); $warningView->render(); exit; } require_once dirname(__FILE__) . '/include/setup.inc.php'; // VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION $fields = array('type' => array(T_ZBX_STR, O_OPT, null, IN('"' . ZBX_DB_MYSQL . '","' . ZBX_DB_POSTGRESQL . '","' . ZBX_DB_ORACLE . '","' . ZBX_DB_DB2 . '","' . ZBX_DB_SQLITE3 . '"'), null), 'server' => array(T_ZBX_STR, O_OPT, null, NOT_EMPTY, null, _('Database host')), 'port' => array(T_ZBX_INT, O_OPT, null, BETWEEN(0, 65535), null, _('Database port')), 'database' => array(T_ZBX_STR, O_OPT, null, NOT_EMPTY, null, _('Database name')), 'user' => array(T_ZBX_STR, O_OPT, null, null, null), 'password' => array(T_ZBX_STR, O_OPT, null, null, null), 'schema' => array(T_ZBX_STR, O_OPT, null, null, null), 'zbx_server' => array(T_ZBX_STR, O_OPT, null, null, null), 'zbx_server_name' => array(T_ZBX_STR, O_OPT, null, null, null), 'zbx_server_port' => array(T_ZBX_INT, O_OPT, null, BETWEEN(0, 65535), null, _('Port')), 'message' => array(T_ZBX_STR, O_OPT, null, null, null), 'save_config' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), 'retry' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), 'cancel' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), 'finish' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), 'next' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), 'back' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), 'form' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), 'form_refresh' => array(T_ZBX_INT, O_OPT, null, null, null)); // config $ZBX_CONFIG = get_cookie('ZBX_CONFIG', null); $ZBX_CONFIG = isset($ZBX_CONFIG) ? unserialize($ZBX_CONFIG) : array(); $ZBX_CONFIG['check_fields_result'] = check_fields($fields, false); if (!isset($ZBX_CONFIG['step'])) { $ZBX_CONFIG['step'] = 0; }
function eventHandler() { if (hasRequest('back') && array_key_exists($this->getStep(), getRequest('back'))) { $this->doBack(); } if ($this->getStep() == 1) { if (hasRequest('next') && array_key_exists(1, getRequest('next'))) { $finalResult = CFrontendSetup::CHECK_OK; foreach ($this->frontendSetup->checkRequirements() as $req) { if ($req['result'] > $finalResult) { $finalResult = $req['result']; } } if ($finalResult == CFrontendSetup::CHECK_FATAL) { $this->STEP_FAILED = true; unset($_REQUEST['next']); } else { $this->doNext(); } } } elseif ($this->getStep() == 2) { $this->setConfig('DB_TYPE', getRequest('type', $this->getConfig('DB_TYPE'))); $this->setConfig('DB_SERVER', getRequest('server', $this->getConfig('DB_SERVER', 'localhost'))); $this->setConfig('DB_PORT', getRequest('port', $this->getConfig('DB_PORT', '0'))); $this->setConfig('DB_DATABASE', getRequest('database', $this->getConfig('DB_DATABASE', 'zabbix'))); $this->setConfig('DB_USER', getRequest('user', $this->getConfig('DB_USER', 'root'))); $this->setConfig('DB_PASSWORD', getRequest('password', $this->getConfig('DB_PASSWORD', ''))); $this->setConfig('DB_SCHEMA', getRequest('schema', $this->getConfig('DB_SCHEMA', ''))); if (hasRequest('next') && array_key_exists(2, getRequest('next'))) { if ($this->checkConnection()) { $this->doNext(); } else { $this->STEP_FAILED = true; unset($_REQUEST['next']); } } } elseif ($this->getStep() == 3) { $this->setConfig('ZBX_SERVER', getRequest('zbx_server', $this->getConfig('ZBX_SERVER', 'localhost'))); $this->setConfig('ZBX_SERVER_PORT', getRequest('zbx_server_port', $this->getConfig('ZBX_SERVER_PORT', '10051'))); $this->setConfig('ZBX_SERVER_NAME', getRequest('zbx_server_name', $this->getConfig('ZBX_SERVER_NAME', ''))); if (hasRequest('next') && array_key_exists(3, getRequest('next'))) { $this->doNext(); } } elseif ($this->getStep() == 4) { if (hasRequest('next') && array_key_exists(4, getRequest('next'))) { $this->doNext(); } } elseif ($this->getStep() == 5) { if (hasRequest('save_config')) { // make zabbix.conf.php downloadable header('Content-Type: application/x-httpd-php'); header('Content-Disposition: attachment; filename="' . basename(CConfigFile::CONFIG_FILE_PATH) . '"'); $config = new CConfigFile(Z::getInstance()->getRootDir() . CConfigFile::CONFIG_FILE_PATH); $config->config = ['DB' => ['TYPE' => $this->getConfig('DB_TYPE'), 'SERVER' => $this->getConfig('DB_SERVER'), 'PORT' => $this->getConfig('DB_PORT'), 'DATABASE' => $this->getConfig('DB_DATABASE'), 'USER' => $this->getConfig('DB_USER'), 'PASSWORD' => $this->getConfig('DB_PASSWORD'), 'SCHEMA' => $this->getConfig('DB_SCHEMA')], 'ZBX_SERVER' => $this->getConfig('ZBX_SERVER'), 'ZBX_SERVER_PORT' => $this->getConfig('ZBX_SERVER_PORT'), 'ZBX_SERVER_NAME' => $this->getConfig('ZBX_SERVER_NAME')]; die($config->getString()); } } if (hasRequest('next') && array_key_exists($this->getStep(), getRequest('next'))) { $this->doNext(); } }
** 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. **/ // reset the LC_CTYPE locale so that case transformation functions would work correctly // it is also required for PHP to work with the Turkish locale (https://bugs.php.net/bug.php?id=18556) // WARNING: this must be done before executing any other code, otherwise code execution could fail! // this will be unnecessary in PHP 5.5 setlocale(LC_CTYPE, ['C', 'POSIX', 'en', 'en_US', 'en_US.UTF-8', 'English_United States.1252', 'en_GB', 'en_GB.UTF-8']); require_once dirname(__FILE__) . '/classes/core/Z.php'; try { Z::getInstance()->run(ZBase::EXEC_MODE_DEFAULT); } catch (DBException $e) { (new CView('general.warning', ['header' => 'Database error', 'messages' => [$e->getMessage()], 'theme' => ZBX_DEFAULT_THEME]))->render(); exit; } catch (ConfigFileException $e) { switch ($e->getCode()) { case CConfigFile::CONFIG_NOT_FOUND: redirect('setup.php'); exit; case CConfigFile::CONFIG_ERROR: (new CView('general.warning', ['header' => 'Configuration file error', 'messages' => [$e->getMessage()], 'theme' => ZBX_DEFAULT_THEME]))->render(); exit; } } catch (Exception $e) { (new CView('general.warning', ['header' => $e->getMessage(), 'messages' => [], 'theme' => ZBX_DEFAULT_THEME]))->render(); exit;