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/APP.php';
23
24$page['file'] = 'setup.php';
25
26try {
27	APP::getInstance()->run(APP::EXEC_MODE_SETUP);
28}
29catch (Exception $e) {
30	echo (new CView('general.warning', [
31		'header' => $e->getMessage(),
32		'messages' => [],
33		'theme' => ZBX_DEFAULT_THEME
34	]))->getOutput();
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.'"'), 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	'tls_encryption' =>		[T_ZBX_INT, O_OPT, null,	IN([0,1]),			null],
49	'verify_certificate' =>	[T_ZBX_INT, O_OPT, null,	IN([0,1]),			null],
50	'verify_host' =>		[T_ZBX_INT, O_OPT, null,	IN([0,1]),			null],
51	'key_file' =>			[T_ZBX_STR, O_OPT, null,	null, 				null],
52	'cert_file' =>			[T_ZBX_STR, O_OPT, null,	null, 				null],
53	'ca_file' =>			[T_ZBX_STR, O_OPT, null,	null, 				null],
54	'cipher_list' =>		[T_ZBX_STR, O_OPT, null,	null, 				null],
55	'zbx_server' =>			[T_ZBX_STR, O_OPT, null,	null,				null],
56	'zbx_server_name' =>	[T_ZBX_STR, O_OPT, null,	null,				null],
57	'zbx_server_port' =>	[T_ZBX_INT, O_OPT, null,	BETWEEN(0, 65535),	null, _('Port')],
58	// actions
59	'save_config' =>		[T_ZBX_STR, O_OPT, P_SYS,	null,				null],
60	'retry' =>				[T_ZBX_STR, O_OPT, P_SYS,	null,				null],
61	'cancel' =>				[T_ZBX_STR, O_OPT, P_SYS,	null,				null],
62	'finish' =>				[T_ZBX_STR, O_OPT, P_SYS,	null,				null],
63	'next' =>				[T_ZBX_STR, O_OPT, P_SYS,	null,				null],
64	'back' =>				[T_ZBX_STR, O_OPT, P_SYS,	null,				null]
65];
66
67CSession::start();
68
69$check_fields_result = check_fields($fields, false);
70
71if (hasRequest('cancel') || hasRequest('finish')) {
72	CSession::clear();
73	redirect('index.php');
74}
75
76if (CWebUser::$data && CWebUser::getType() < USER_TYPE_SUPER_ADMIN && CSession::getValue('step') != 5) {
77	access_deny(ACCESS_DENY_PAGE);
78}
79
80CSession::setValue('check_fields_result', $check_fields_result);
81
82$theme = CWebUser::$data ? getUserTheme(CWebUser::$data) : ZBX_DEFAULT_THEME;
83
84DBclose();
85
86/*
87 * Setup wizard
88 */
89$ZBX_SETUP_WIZARD = new CSetupWizard();
90
91// page title
92(new CPageHeader(_('Installation')))
93	->addCssFile('assets/styles/'.CHtml::encode($theme).'.css')
94	->addJsFile((new CUrl('js/browsers.js'))->getUrl())
95	->addJsFile((new CUrl('js/vendors/jquery.js'))->getUrl())
96	->addJsFile((new CUrl('js/class.overlaycollection.js'))->getUrl())
97	->addJsFile((new CUrl('js/common.js'))->getUrl())
98	->addJsFile((new CUrl('js/class.template.js'))->getUrl())
99	->addJsFile((new CUrl('js/component.z-select.js'))->getUrl())
100	->addJsFile((new CUrl('jsLoader.php'))
101		->setArgument('ver', ZABBIX_VERSION)
102		->setArgument('lang', 'en_gb')
103		->setArgument('files', ['setup.js'])
104		->getUrl()
105	)
106	->display();
107
108/*
109 * Displaying
110 */
111$link = (new CLink('GPL v2', 'https://www.zabbix.com/license'))
112	->setTarget('_blank')
113	->addClass(ZBX_STYLE_GREY)
114	->addClass(ZBX_STYLE_LINK_ALT);
115$sub_footer = (new CDiv(['Licensed under ', $link]))->addClass(ZBX_STYLE_SIGNIN_LINKS);
116
117(new CTag('body', true,
118	(new CDiv([
119		(new CTag('main', true, [$ZBX_SETUP_WIZARD, $sub_footer])), makePageFooter()])
120	)->addClass(ZBX_STYLE_LAYOUT_WRAPPER)
121))
122	->setAttribute('lang', CWebUser::getLang())
123	->show();
124?>
125</html>
126