1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
<?php
/*
** ZABBIX
** Copyright (C) 2000-2005 SIA Zabbix
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
?>
<?php
require_once "include/config.inc.php";
require_once "include/maps.inc.php";
require_once "include/forms.inc.php";
$page["title"] = "S_CONFIGURATION_OF_NETWORK_MAPS";
$page["file"] = "sysmap.php";
include_once "include/page_header.php";
?>
<?php
// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION
$fields=array(
"sysmapid"=> array(T_ZBX_INT, O_MAND, P_SYS, DB_ID,NULL),
"selementid"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL),
"elementid"=> array(T_ZBX_INT, O_OPT, NULL, DB_ID, 'isset({save})'),
"elementtype"=> array(T_ZBX_INT, O_OPT, NULL, IN("0,1,2,3"), 'isset({save})'),
"label"=> array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY, 'isset({save})'),
"x"=> array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0,65535),'isset({save})'),
"y"=> array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0,65535),'isset({save})'),
"iconid_off"=> array(T_ZBX_INT, O_OPT, NULL, DB_ID, 'isset({save})'),
"iconid_on"=> array(T_ZBX_INT, O_OPT, NULL, DB_ID, 'isset({save})'),
"iconid_unknown"=> array(T_ZBX_INT, O_OPT, NULL, DB_ID, 'isset({save})'),
"url"=> array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({save})'),
"label_location"=>array(T_ZBX_INT, O_OPT, NULL, IN("-1,0,1,2,3"),'isset({save})'),
"linkid"=> array(T_ZBX_INT, O_OPT, P_SYS, DB_ID,NULL),
"selementid1"=> array(T_ZBX_INT, O_OPT, NULL, DB_ID,'isset({save_link})'),
"selementid2"=> array(T_ZBX_INT, O_OPT, NULL, DB_ID,'isset({save_link})'),
"triggerid"=> array(T_ZBX_INT, O_OPT, NULL, DB_ID,'isset({save_link})'),
"drawtype_off"=>array(T_ZBX_INT, O_OPT, NULL, IN("0,1,2,3,4"),'isset({save_link})'),
"drawtype_on"=> array(T_ZBX_INT, O_OPT, NULL, IN("0,1,2,3,4"),'isset({save_link})'),
"color_off"=> array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY,'isset({save_link})'),
"color_on"=> array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY,'isset({save_link})'),
/* actions */
"save"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL),
"save_link"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL),
"delete"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL),
"cancel"=> array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL),
/* other */
"form"=> array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL),
"form_refresh"=> array(T_ZBX_INT, O_OPT, NULL, NULL, NULL)
);
check_fields($fields);
?>
<?php
show_table_header("CONFIGURATION OF NETWORK MAP");
if(!sysmap_accessiable($_REQUEST["sysmapid"],PERM_READ_WRITE)) access_deny();
$sysmap = DBfetch(DBselect("select * from sysmaps where sysmapid=".$_REQUEST["sysmapid"]));
?>
<?php
if(isset($_REQUEST["save"]))
{
if(isset($_REQUEST["selementid"]))
{ // update element
$result=update_sysmap_element($_REQUEST["selementid"],
$_REQUEST["sysmapid"],$_REQUEST["elementid"],$_REQUEST["elementtype"],
$_REQUEST["label"],$_REQUEST["x"],$_REQUEST["y"],
$_REQUEST["iconid_off"],$_REQUEST["iconid_unknown"],$_REQUEST["iconid_on"],
$_REQUEST["url"],$_REQUEST["label_location"]);
$selementid = $_REQUEST["selementid"];
show_messages($result,"Element updated","Cannot update element");
}
else
{ // add element
$result=add_element_to_sysmap($_REQUEST["sysmapid"],$_REQUEST["elementid"],
$_REQUEST["elementtype"],$_REQUEST["label"],$_REQUEST["x"],$_REQUEST["y"],
$_REQUEST["iconid_off"],$_REQUEST["iconid_unknown"],$_REQUEST["iconid_on"],
$_REQUEST["url"],$_REQUEST["label_location"]);
$selementid = $result;
show_messages($result,"Element added","Cannot add element");
}
add_audit_if($result,AUDIT_ACTION_UPDATE,AUDIT_RESOURCE_MAP,'Name ['.$sysmap['name'].'] Element ['.$selementid.'] updated ');
if($result) unset($_REQUEST["form"]);
}
if(isset($_REQUEST["save_link"]))
{
if(isset($_REQUEST["linkid"]))
{ // update link
$result=update_link($_REQUEST["linkid"],
$_REQUEST["sysmapid"],$_REQUEST["selementid1"],$_REQUEST["selementid2"],
$_REQUEST["triggerid"], $_REQUEST["drawtype_off"],$_REQUEST["color_off"],
$_REQUEST["drawtype_on"],$_REQUEST["color_on"]);
$linkid = $_REQUEST["linkid"];
show_messages($result,"Link updated","Cannot update link");
}
else
{ // add link
$result=add_link($_REQUEST["sysmapid"],$_REQUEST["selementid1"],$_REQUEST["selementid2"],
$_REQUEST["triggerid"], $_REQUEST["drawtype_off"],$_REQUEST["color_off"],
$_REQUEST["drawtype_on"],$_REQUEST["color_on"]);
$linkid = $result;
show_messages($result,"Link added","Cannot add link");
}
add_audit_if($result,AUDIT_ACTION_UPDATE,AUDIT_RESOURCE_MAP,'Name ['.$sysmap['name'].'] Link ['.$linkid.'] updated ');
if($result) unset($_REQUEST["form"]);
}
elseif(isset($_REQUEST["delete"]))
{
if(isset($_REQUEST["linkid"]))
{
$result=delete_link($_REQUEST["linkid"]);
show_messages($result,"Link deleted","Cannot delete link");
add_audit_if($result,AUDIT_ACTION_UPDATE,AUDIT_RESOURCE_MAP,
'Name ['.$sysmap['name'].'] Link ['.$_REQUEST["linkid"].'] deleted');
if($result)
{
unset($_REQUEST["linkid"]);
unset($_REQUEST["form"]);
}
}
elseif(isset($_REQUEST["selementid"]))
{
$result=delete_sysmaps_element($_REQUEST["selementid"]);
show_messages($result,"Element deleted","Cannot delete element");
add_audit_if($result,AUDIT_ACTION_UPDATE,AUDIT_RESOURCE_MAP,
'Name ['.$sysmap['name'].'] Element ['.$_REQUEST["selementid"].'] deleteed ');
if($result)
{
unset($_REQUEST["selementid"]);
unset($_REQUEST["form"]);
}
}
}
?>
<?php
echo BR;
if(isset($_REQUEST["form"]) && ($_REQUEST["form"]=="add_element" ||
($_REQUEST["form"]=="update" && isset($_REQUEST["selementid"]))))
{
show_table_header("DISPLAYED ELEMENTS");
echo BR;
insert_map_element_form();
}
elseif(isset($_REQUEST["form"]) && ($_REQUEST["form"]=="add_link" ||
($_REQUEST["form"]=="update" && isset($_REQUEST["linkid"]))))
{
$row = DBfetch(DBselect("select count(*) as count from sysmaps_elements where sysmapid=".$_REQUEST["sysmapid"]));
if($row["count"]>1)
{
show_table_header("CONNECTORS");
echo BR;
insert_map_link_form();
}
else
{
info("No elements in this map");
}
}
else
{
show_table_header("DISPLAYED ELEMENTS", new CButton("form","Add element",
"return Redirect('".$page["file"]."?form=add_element".url_param("sysmapid")."');"));
$table = new CTableInfo();
$table->SetHeader(array(S_LABEL,S_TYPE,S_X,S_Y,S_ICON_OFF,S_ICON_ON,S_ICON_UNKNOWN));
$db_elements = DBselect("select * from sysmaps_elements where sysmapid=".$_REQUEST["sysmapid"].
" order by label");
while($db_element = DBfetch($db_elements))
{
if( $db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_HOST) $type = S_HOST;
elseif($db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_MAP) $type = S_MAP;
elseif($db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_TRIGGER) $type = S_TRIGGER;
elseif($db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_HOST_GROUP) $type = S_HOST_GROUP;
else $type = "Map element";
$table->addRow(array(
new CLink(
$db_element["label"],
"sysmap.php?sysmapid=".$db_element["sysmapid"].
"&form=update&selementid=".$db_element["selementid"],
"action"),
nbsp($type),
$db_element["x"],
$db_element["y"],
new CImg("image.php?height=24&imageid=".$db_element["iconid_off"],"no image",NULL),
new CImg("image.php?height=24&imageid=".$db_element["iconid_on"],"no image",NULL),
new CImg("image.php?height=24&imageid=".$db_element["iconid_unknown"],"no image",NULL)
));
}
$table->show();
echo BR;
show_table_header("CONNECTORS", new CButton("form","Create connection",
"return Redirect('".$page["file"]."?form=add_link".
url_param("sysmapid")."');"));
$table = new CTableInfo();
$table->SetHeader(array(S_LINK,S_ELEMENT_1,S_ELEMENT_2,S_LINK_STATUS_INDICATOR));
$i = 1;
$result=DBselect("select linkid,selementid1,selementid2,triggerid from sysmaps_links".
" where sysmapid=".$_REQUEST["sysmapid"]." order by linkid");
while($row=DBfetch($result))
{
/* prepare label 1 */
$result1=DBselect("select label from sysmaps_elements".
" where selementid=".$row["selementid1"]);
$row1=DBfetch($result1);
$label1=$row1["label"];
/* prepare label 2 */
$result1=DBselect("select label from sysmaps_elements".
" where selementid=".$row["selementid2"]);
$row1=DBfetch($result1);
$label2=$row1["label"];
/* prepare description */
if(isset($row["triggerid"]))
$description=expand_trigger_description($row["triggerid"]);
else
$description="-";
/* draw row */
$table->addRow(array(
new CLink("link ".$i++,
"sysmap.php?sysmapid=".$_REQUEST["sysmapid"].
"&form=update&linkid=".$row["linkid"],
"action"),
$label1,
$label2,
$description
));
}
$table->Show();
}
echo BR;
$map=get_sysmap_by_sysmapid($_REQUEST["sysmapid"]);
show_table_header($map["name"]);
$table = new CTable(NULL,"map");
if(isset($_REQUEST["sysmapid"]))
{
$linkMap = new CMap("links".$_REQUEST["sysmapid"]."_".rand(0,100000));
$db_elements = DBselect("select * from sysmaps_elements where sysmapid=".$_REQUEST["sysmapid"]);
while($db_element = DBfetch($db_elements))
{
$tmp_img = get_png_by_selementid($db_element["selementid"]);
if(!$tmp_img) continue;
$x1_ = $db_element["x"];
$y1_ = $db_element["y"];
$x2_ = $db_element["x"] + imagesx($tmp_img);
$y2_ = $db_element["y"] + imagesy($tmp_img);
$linkMap->AddRectArea($x1_,$y1_,$x2_,$y2_,
"sysmap.php?form=update&sysmapid=".$_REQUEST["sysmapid"].
"&selementid=".$db_element["selementid"],
$db_element["label"]);
}
$imgMap = new CImg("map.php?sysmapid=".$_REQUEST["sysmapid"]);
$imgMap->SetMap($linkMap->GetName());
$table->AddRow($linkMap);
$table->AddRow($imgMap);
}
$table->Show();
?>
<?php
include_once "include/page_footer.php";
?>
|