1<?php 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 22require_once dirname(__FILE__).'/include/classes/core/Z.php'; 23 24$page['file'] = 'setup.php'; 25 26try { 27 Z::getInstance()->run(ZBase::EXEC_MODE_SETUP); 28} 29catch (Exception $e) { 30 (new CView('general.warning', [ 31 'header' => $e->getMessage(), 32 'messages' => [], 33 'theme' => ZBX_DEFAULT_THEME 34 ]))->render(); 35 36 exit; 37} 38 39// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION 40$fields = [ 41 'type' => [T_ZBX_STR, O_OPT, null, IN('"'.ZBX_DB_MYSQL.'","'.ZBX_DB_POSTGRESQL.'","'.ZBX_DB_ORACLE.'","'.ZBX_DB_DB2.'"'), null], 42 'server' => [T_ZBX_STR, O_OPT, null, null, null], 43 'port' => [T_ZBX_INT, O_OPT, null, BETWEEN(0, 65535), null, _('Database port')], 44 'database' => [T_ZBX_STR, O_OPT, null, NOT_EMPTY, null, _('Database name')], 45 'user' => [T_ZBX_STR, O_OPT, null, null, null], 46 'password' => [T_ZBX_STR, O_OPT, null, null, null], 47 'schema' => [T_ZBX_STR, O_OPT, null, null, null], 48 'zbx_server' => [T_ZBX_STR, O_OPT, null, null, null], 49 'zbx_server_name' => [T_ZBX_STR, O_OPT, null, null, null], 50 'zbx_server_port' => [T_ZBX_INT, O_OPT, null, BETWEEN(0, 65535), null, _('Port')], 51 // actions 52 'save_config' => [T_ZBX_STR, O_OPT, P_SYS, null, null], 53 'retry' => [T_ZBX_STR, O_OPT, P_SYS, null, null], 54 'cancel' => [T_ZBX_STR, O_OPT, P_SYS, null, null], 55 'finish' => [T_ZBX_STR, O_OPT, P_SYS, null, null], 56 'next' => [T_ZBX_STR, O_OPT, P_SYS, null, null], 57 'back' => [T_ZBX_STR, O_OPT, P_SYS, null, null] 58]; 59 60CSession::start(); 61CSession::setValue('check_fields_result', check_fields($fields, false)); 62if (!CSession::keyExists('step')) { 63 CSession::setValue('step', 0); 64} 65 66// if a guest or a non-super admin user is logged in 67if (CWebUser::$data && CWebUser::getType() < USER_TYPE_SUPER_ADMIN) { 68 // on the last step of the setup we always have a guest user logged in; 69 // when he presses the "Finish" button he must be redirected to the login screen 70 if (CWebUser::isGuest() && CSession::getValue('step') == 5 && hasRequest('finish')) { 71 CSession::clear(); 72 redirect('index.php'); 73 } 74 // the guest user can also view the last step of the setup 75 // all other user types must not have access to the setup 76 elseif (!(CWebUser::isGuest() && CSession::getValue('step') == 5)) { 77 access_deny(ACCESS_DENY_PAGE); 78 } 79} 80// if a super admin or a non-logged in user presses the "Finish" or "Login" button - redirect him to the login screen 81elseif (hasRequest('cancel') || hasRequest('finish')) { 82 CSession::clear(); 83 redirect('index.php'); 84} 85 86$theme = CWebUser::$data ? getUserTheme(CWebUser::$data) : ZBX_DEFAULT_THEME; 87 88DBclose(); 89 90/* 91 * Setup wizard 92 */ 93$ZBX_SETUP_WIZARD = new CSetupWizard(); 94 95// if init fails due to missing configuration, set user as guest with default en_GB language 96if (!CWebUser::$data) { 97 CWebUser::setDefault(); 98} 99 100// page title 101(new CPageHeader(_('Installation'))) 102 ->addCssFile('assets/styles/'.CHtml::encode($theme).'.css') 103 ->addJsFile((new CUrl('js/browsers.js'))->getUrl()) 104 ->addJsFile((new CUrl('jsLoader.php')) 105 ->setArgument('ver', ZABBIX_VERSION) 106 ->setArgument('lang', CWebUser::$data['lang']) 107 ->getUrl() 108 ) 109 ->display(); 110 111/* 112 * Displaying 113 */ 114$link = (new CLink('GPL v2', 'https://www.zabbix.com/license')) 115 ->setTarget('_blank') 116 ->addClass(ZBX_STYLE_GREY) 117 ->addClass(ZBX_STYLE_LINK_ALT); 118$sub_footer = (new CDiv(['Licensed under ', $link]))->addClass(ZBX_STYLE_SIGNIN_LINKS); 119 120(new CTag('body', true, [(new CTag('main', true, [$ZBX_SETUP_WIZARD, $sub_footer])), makePageFooter()])) 121 ->setAttribute('lang', CWebUser::getLang()) 122 ->show(); 123?> 124</html> 125