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/config.inc.php';
23require_once dirname(__FILE__).'/include/graphs.inc.php';
24require_once dirname(__FILE__).'/include/screens.inc.php';
25require_once dirname(__FILE__).'/include/blocks.inc.php';
26
27$page['title'] = _('Custom screens');
28$page['file'] = 'screens.php';
29$page['scripts'] = [
30	'class.calendar.js',
31	'gtlc.js',
32	'flickerfreescreen.js',
33	'class.svg.canvas.js',
34	'class.svg.map.js',
35	'layout.mode.js'
36];
37$page['type'] = detect_page_type(PAGE_TYPE_HTML);
38
39CView::$has_web_layout_mode = true;
40$page['web_layout_mode'] = CView::getLayoutMode();
41
42define('ZBX_PAGE_DO_JS_REFRESH', 1);
43
44ob_start();
45require_once dirname(__FILE__).'/include/page_header.php';
46
47// VAR	TYPE	OPTIONAL	FLAGS	VALIDATION	EXCEPTION
48$fields = [
49	'groupid' =>	[T_ZBX_INT,			O_OPT, P_SYS,	DB_ID,		null],
50	'hostid' =>		[T_ZBX_INT,			O_OPT, P_SYS,	DB_ID,		null],
51	'tr_groupid' =>	[T_ZBX_INT,			O_OPT, P_SYS,	DB_ID,		null],
52	'tr_hostid' =>	[T_ZBX_INT,			O_OPT, P_SYS,	DB_ID,		null],
53	'elementid' =>	[T_ZBX_INT,			O_OPT, P_SYS|P_NZERO, DB_ID, null],
54	'screenname' =>	[T_ZBX_STR,			O_OPT, P_SYS,	null,		null],
55	'step' =>		[T_ZBX_INT,			O_OPT, P_SYS,	BETWEEN(0, 65535), null],
56	'from' =>		[T_ZBX_RANGE_TIME,	O_OPT, P_SYS,	null,		null],
57	'to' =>			[T_ZBX_RANGE_TIME,	O_OPT, P_SYS,	null,		null],
58	'reset' =>		[T_ZBX_STR,			O_OPT, P_SYS,	IN('"reset"'), null]
59];
60check_fields($fields);
61validateTimeSelectorPeriod(getRequest('from'), getRequest('to'));
62
63/*
64 * Permissions
65 */
66// Validate group IDs.
67if (getRequest('groupid') && !isReadableHostGroups([getRequest('groupid')])) {
68	access_deny();
69}
70if (getRequest('tr_groupid') && !isReadableHostGroups([getRequest('tr_groupid')])) {
71	access_deny();
72}
73
74// Validate host IDs.
75if (getRequest('hostid') && !isReadableHosts([getRequest('hostid')])) {
76	access_deny();
77}
78if (getRequest('tr_hostid') && !isReadableHosts([getRequest('tr_hostid')])) {
79	access_deny();
80}
81
82if ($page['type'] == PAGE_TYPE_JS || $page['type'] == PAGE_TYPE_HTML_BLOCK) {
83	require_once dirname(__FILE__).'/include/page_footer.php';
84	exit;
85}
86
87/*
88 * Display
89 */
90$data = [];
91
92$options = [
93	'output' => ['screenid', 'name']
94];
95
96if (getRequest('elementid')) {
97	$options['screenids'] = getRequest('elementid');
98	CProfile::update('web.screens.elementid', getRequest('elementid') , PROFILE_TYPE_ID);
99}
100elseif (hasRequest('screenname')) {
101	$options['filter']['name'] = getRequest('screenname');
102}
103elseif (CProfile::get('web.screens.elementid')) {
104	$options['screenids'] = CProfile::get('web.screens.elementid');
105}
106else {
107	// Redirect to screen list.
108	ob_end_clean();
109	redirect('screenconf.php');
110}
111
112$screens = API::Screen()->get($options);
113
114if (!$screens && (getRequest('elementid') || hasRequest('screenname'))) {
115	access_deny();
116}
117elseif (!$screens) {
118	// Redirect to screen list.
119	ob_end_clean();
120	redirect('screenconf.php');
121}
122else {
123	$data['screen'] = reset($screens);
124	$data['screen']['editable'] = (bool) API::Screen()->get([
125		'output' => [],
126		'screenids' => [$data['screen']['screenid']],
127		'editable' => true
128	]);
129	$data['active_tab'] = CProfile::get('web.screens.filter.active', 1);
130
131	$timeselector_options = [
132		'profileIdx' => 'web.screens.filter',
133		'profileIdx2' => $data['screen']['screenid'],
134		'from' => getRequest('from'),
135		'to' => getRequest('to')
136	];
137	updateTimeSelectorPeriod($timeselector_options);
138
139	$data += $timeselector_options;
140}
141ob_end_flush();
142
143// render view
144$screenView = new CView('monitoring.screen', $data);
145$screenView->render();
146$screenView->show();
147
148require_once dirname(__FILE__).'/include/page_footer.php';
149