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/maps.inc.php'; 24 25$page['title'] = _('Map'); 26$page['file'] = 'map.php'; 27$page['type'] = detect_page_type(PAGE_TYPE_IMAGE); 28 29require_once dirname(__FILE__).'/include/page_header.php'; 30 31// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION 32$fields = [ 33 'sysmapid' => [T_ZBX_INT, O_MAND, P_SYS, DB_ID, null], 34 'selements' => [T_ZBX_STR, O_OPT, P_SYS, null, null], 35 'links' => [T_ZBX_STR, O_OPT, P_SYS, null, null], 36 'noselements' => [T_ZBX_INT, O_OPT, null, IN('0,1'), null], 37 'nolinks' => [T_ZBX_INT, O_OPT, null, IN('0,1'), null], 38 'nocalculations' => [T_ZBX_INT, O_OPT, null, IN('0,1'), null], 39 'expand_macros' => [T_ZBX_INT, O_OPT, null, IN('0,1'), null], 40 'show_triggers' => [T_ZBX_INT, O_OPT, P_SYS, IN('0,1,2,3'), null], 41 'severity_min' => [T_ZBX_INT, O_OPT, null, IN('0,1,2,3,4,5'), null], 42 'grid' => [T_ZBX_INT, O_OPT, null, BETWEEN(0, 500), null], 43 'base64image' => [T_ZBX_INT, O_OPT, null, IN('0,1'), null] 44]; 45check_fields($fields); 46 47$maps = API::Map()->get([ 48 'sysmapids' => $_REQUEST['sysmapid'], 49 'selectSelements' => API_OUTPUT_EXTEND, 50 'selectLinks' => API_OUTPUT_EXTEND, 51 'output' => API_OUTPUT_EXTEND, 52 'preservekeys' => true 53]); 54$map = reset($maps); 55if (empty($map)) { 56 access_deny(); 57} 58 59$graphtheme = [ 60 'theme' => 'blue-theme', 61 'textcolor' => '1F2C33', 62 'highlightcolor' => 'E33734', 63 'backgroundcolor' => 'FFFFFF', 64 'graphcolor' => 'FFFFFF', 65 'gridcolor' => 'CCD5D9', 66 'maingridcolor' => 'ACBBC2', 67 'gridbordercolor' => 'ACBBC2', 68 'nonworktimecolor' => 'EBEBEB', 69 'leftpercentilecolor' => '429E47', 70 'righttpercentilecolor' => 'E33734' 71]; 72 73$themes = DB::find('graph_theme', [ 74 'theme' => getUserTheme(CWebUser::$data) 75]); 76if ($themes) { 77 $graphtheme = $themes[0]; 78} 79 80$mapPainter = new CMapPainter($map, [ 81 'map' => [ 82 'drawAreas' => (!isset($_REQUEST['selements']) && !isset($_REQUEST['noselements'])) 83 ], 84 'grid' => [ 85 'size' => getRequest('grid', 0) 86 ], 87 'graphtheme' => $graphtheme 88]); 89 90$im = $mapPainter->paint(); 91 92$x = imagesx($im); 93$y = imagesy($im); 94 95/* 96 * Actions 97 */ 98$json = new CJson(); 99 100if (isset($_REQUEST['selements']) || isset($_REQUEST['noselements'])) { 101 $map['selements'] = getRequest('selements', '[]'); 102 $map['selements'] = $json->decode($map['selements'], true); 103} 104else { 105 add_elementNames($map['selements']); 106} 107 108if (isset($_REQUEST['links']) || isset($_REQUEST['nolinks'])) { 109 $map['links'] = getRequest('links', '[]'); 110 $map['links'] = $json->decode($map['links'], true); 111} 112 113if (getRequest('nocalculations', false)) { 114 foreach ($map['selements'] as $selement) { 115 if ($selement['elementtype'] != SYSMAP_ELEMENT_TYPE_IMAGE) { 116 add_elementNames($map['selements']); 117 break; 118 } 119 } 120 121 // get default iconmap id to use for elements that use icon map 122 if ($map['iconmapid']) { 123 $iconMaps = API::IconMap()->get([ 124 'iconmapids' => $map['iconmapid'], 125 'output' => ['default_iconid'], 126 'preservekeys' => true 127 ]); 128 $iconMap = reset($iconMaps); 129 130 $defaultAutoIconId = $iconMap['default_iconid']; 131 } 132 133 $mapInfo = []; 134 foreach ($map['selements'] as $selement) { 135 // if element use icon map and icon map is set for map, and is host like element, we use default icon map icon 136 if ($map['iconmapid'] && $selement['use_iconmap'] 137 && ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST 138 || ($selement['elementtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP 139 && $selement['elementsubtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP_ELEMENTS))) { 140 $iconid = $defaultAutoIconId; 141 } 142 else { 143 $iconid = $selement['iconid_off']; 144 } 145 146 $mapInfo[$selement['selementid']] = [ 147 'iconid' => $iconid, 148 'icon_type' => SYSMAP_ELEMENT_ICON_OFF 149 ]; 150 151 $mapInfo[$selement['selementid']]['name'] = ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_IMAGE) 152 ? _('Image') 153 : $selement['elementName']; 154 } 155 156 $allLinks = true; 157} 158else { 159 // we need selements to be a hash for further processing 160 $map['selements'] = zbx_toHash($map['selements'], 'selementid'); 161 162 add_triggerExpressions($map['selements']); 163 164 $areas = populateFromMapAreas($map); 165 $mapInfo = getSelementsInfo($map, ['severity_min' => getRequest('severity_min')]); 166 processAreasCoordinates($map, $areas, $mapInfo); 167 $allLinks = false; 168} 169 170resolveMapLinksTriggersState($map); 171 172/* 173 * Draw map 174 */ 175drawMapConnectors($im, $map, $mapInfo, $allLinks); 176 177if (!isset($_REQUEST['noselements'])) { 178 drawMapHighligts($im, $map, $mapInfo); 179 drawMapSelements($im, $map, $mapInfo); 180} 181 182$expandMacros = getRequest('expand_macros', true); 183drawMapLabels($im, $map, $mapInfo, $expandMacros, $graphtheme); 184drawMapLinkLabels($im, $map, $mapInfo, $expandMacros, $graphtheme); 185 186if (!isset($_REQUEST['noselements']) && $map['markelements'] == 1) { 187 drawMapSelementsMarks($im, $map, $mapInfo); 188} 189 190show_messages(); 191 192if (getRequest('base64image')) { 193 ob_start(); 194 imagepng($im); 195 $imageSource = ob_get_contents(); 196 ob_end_clean(); 197 $json = new CJson(); 198 echo $json->encode(['result' => base64_encode($imageSource)]); 199 imagedestroy($im); 200} 201else { 202 imageOut($im); 203} 204 205require_once dirname(__FILE__).'/include/page_footer.php'; 206