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;}'."\n"; 71 } 72 echo $css; 73} 74elseif (isset($_REQUEST['iconid'])) { 75 $iconid = getRequest('iconid', 0); 76 $unavailable = getRequest('unavailable', 0); 77 78 if ($iconid > 0) { 79 $image = get_image_by_imageid($iconid); 80 81 $source = $image['image'] ? imageFromString($image['image']) : get_default_image(); 82 83 list(,, $img_type) = getimagesizefromstring($image['image']); 84 85 $img_types = [ 86 IMAGETYPE_GIF => IMAGE_FORMAT_GIF, 87 IMAGETYPE_JPEG => IMAGE_FORMAT_JPEG, 88 IMAGETYPE_PNG => IMAGE_FORMAT_PNG 89 ]; 90 } 91 else { 92 $source = get_default_image(); 93 } 94 95 if ($resize) { 96 $source = imageThumb($source, $width, $height); 97 } 98 99 if ($unavailable == 1) { 100 imagefilter($source, IMG_FILTER_GRAYSCALE); 101 imagefilter($source, IMG_FILTER_BRIGHTNESS, 75); 102 } 103 104 if ($iconid > 0 && !$resize && $unavailable != 1 && array_key_exists($img_type, $img_types)) { 105 set_image_header($img_types[$img_type]); 106 107 echo $image['image']; 108 } 109 else { 110 imageOut($source); 111 } 112} 113elseif (isset($_REQUEST['imageid'])) { 114 $imageid = getRequest('imageid', 0); 115 116 if (CSessionHelper::has('image_id')) { 117 $image_data = CSessionHelper::get('image_id'); 118 if (array_key_exists($imageid, $image_data)) { 119 echo $image_data[$imageid]; 120 unset($image_data[$imageid]); 121 CSessionHelper::set('image_id', $image_data); 122 } 123 } 124} 125 126require_once dirname(__FILE__).'/include/page_footer.php'; 127