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
22define('ZBX_PAGE_NO_AUTHERIZATION', 1);
23
24require_once dirname(__FILE__).'/include/config.inc.php';
25require_once dirname(__FILE__).'/include/maps.inc.php';
26
27$page['file'] = 'imgstore.php';
28$page['type'] = detect_page_type(PAGE_TYPE_IMAGE);
29
30require_once dirname(__FILE__).'/include/page_header.php';
31
32//	VAR		TYPE	OPTIONAL 	FLAGS	VALIDATION	EXCEPTION
33$fields = [
34	'css' =>			[T_ZBX_INT, O_OPT, P_SYS, null,				null],
35	'imageid' =>		[T_ZBX_STR, O_OPT, P_SYS, null,				null],
36	'iconid' =>			[T_ZBX_INT, O_OPT, P_SYS, DB_ID,				null],
37	'width' =>			[T_ZBX_INT, O_OPT, P_SYS, BETWEEN(1, 2000),	null],
38	'height' =>			[T_ZBX_INT, O_OPT, P_SYS, BETWEEN(1, 2000),	null],
39	'unavailable' =>	[T_ZBX_INT, O_OPT, null, IN([0, 1]),		null]
40];
41check_fields($fields);
42
43$resize = false;
44if (isset($_REQUEST['width']) || isset($_REQUEST['height'])) {
45	$resize = true;
46	$width = getRequest('width', 0);
47	$height = getRequest('height', 0);
48}
49
50if (isset($_REQUEST['css'])) {
51	$css = '';
52
53	$images = API::Image()->get([
54		'output' => ['imageid'],
55		'filter' => ['imagetype' => IMAGE_TYPE_ICON],
56		'select_image' => true
57	]);
58	foreach ($images as $image) {
59		$image['image'] = base64_decode($image['image']);
60		$ico = imagecreatefromstring($image['image']);
61
62		if ($resize) {
63			$ico = imageThumb($ico, $width, $height);
64		}
65		$w = imagesx($ico);
66		$h = imagesy($ico);
67
68		$css .= 'div.sysmap_iconid_'.$image['imageid'].'{'.
69					' height: '.$h.'px;'.
70					' width: '.$w.'px;'.
71					' background: url("imgstore.php?iconid='.$image['imageid'].'&width='.$w.'&height='.$h.'") no-repeat center center;}'."\n";
72	}
73	echo $css;
74}
75elseif (isset($_REQUEST['iconid'])) {
76	$iconid = getRequest('iconid', 0);
77	$unavailable = getRequest('unavailable', 0);
78
79	if ($iconid > 0) {
80		$image = get_image_by_imageid($iconid);
81
82		$source = $image['image'] ? imageFromString($image['image']) : get_default_image();
83	}
84	else {
85		$source = get_default_image();
86	}
87
88	if ($resize) {
89		$source = imageThumb($source, $width, $height);
90	}
91
92	if ($unavailable == 1) {
93		imagefilter($source, IMG_FILTER_GRAYSCALE);
94		imagefilter($source, IMG_FILTER_BRIGHTNESS, 75);
95	}
96
97	imageOut($source);
98}
99elseif (isset($_REQUEST['imageid'])) {
100	$imageid = getRequest('imageid', 0);
101
102	if (CSession::keyExists('image_id')) {
103		$image_data = CSession::getValue('image_id');
104		if (array_key_exists($imageid, $image_data)) {
105			echo $image_data[$imageid];
106			unset($image_data[$imageid]);
107			CSession::setValue('image_id', $image_data);
108		}
109	}
110}
111
112require_once dirname(__FILE__).'/include/page_footer.php';
113