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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
|
<?php
/*
** Zabbix
** Copyright (C) 2000,2001,2002,2003 Alexei Vladishev
**
** 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
include "include/config.inc.php";
$page["title"] = "Hosts";
$page["file"] = "hosts.php";
show_header($page["title"],0,0);
insert_confirm_javascript();
?>
<?php
if(!check_right("Host","U",0))
{
show_table_header("<font color=\"AA0000\">No permissions !</font>");
show_footer();
exit;
}
?>
<?php
if(isset($HTTP_GET_VARS["register"]))
{
if($HTTP_GET_VARS["register"]=="add")
{
$result=add_host($HTTP_GET_VARS["host"],$HTTP_GET_VARS["port"],$HTTP_GET_VARS["status"],$HTTP_GET_VARS["useip"],$HTTP_GET_VARS["ip"],$HTTP_GET_VARS["host_templateid"],$HTTP_GET_VARS["newgroup"],$HTTP_GET_VARS["groups"]);
show_messages($result,"Host added","Cannot add host");
unset($HTTP_GET_VARS["hostid"]);
}
if($HTTP_GET_VARS["register"]=="update")
{
$result=@update_host($HTTP_GET_VARS["hostid"],$HTTP_GET_VARS["host"],$HTTP_GET_VARS["port"],$HTTP_GET_VARS["status"],$HTTP_GET_VARS["useip"],$HTTP_GET_VARS["ip"],$HTTP_GET_VARS["newgroup"],$HTTP_GET_VARS["groups"]);
show_messages($result,"Host details updated","Cannot update host details");
unset($HTTP_GET_VARS["hostid"]);
}
if($HTTP_GET_VARS["register"]=="changestatus")
{
$result=update_host_status($HTTP_GET_VARS["hostid"],$HTTP_GET_VARS["status"]);
show_messages($result,"Host status updated","Cannot update host status");
unset($HTTP_GET_VARS["hostid"]);
}
if($HTTP_GET_VARS["register"]=="delete")
{
$result=delete_host($HTTP_GET_VARS["hostid"]);
show_messages($result,"Host deleted","Cannot delete host");
unset($HTTP_GET_VARS["hostid"]);
}
}
?>
<?php
show_table_header_begin();
echo "CONFIGURATION OF HOSTS";
show_table_v_delimiter();
if(isset($HTTP_GET_VARS["groupid"]))
{
// echo "all ";
echo "<a href='hosts.php'>all</a> ";
}
else
{
echo "<b>[<a href='hosts.php'>all</a>]</b> ";
}
$result=DBselect("select groupid,name from groups order by name");
while($row=DBfetch($result))
{
// if(!check_right("Host","R",$row["hostid"]))
// {
// continue;
// }
if( isset($HTTP_GET_VARS["groupid"]) && ($HTTP_GET_VARS["groupid"] == $row["groupid"]) )
{
echo "<b>[";
}
echo "<a href='hosts.php?groupid=".$row["groupid"]."'>".$row["name"]."</a>";
if(isset($HTTP_GET_VARS["groupid"]) && ($HTTP_GET_VARS["groupid"] == $row["groupid"]) )
{
echo "]</b>";
}
echo " ";
}
show_table_header_end();
echo "<br>";
?>
<?php
if(!isset($HTTP_GET_VARS["hostid"]))
{
echo "<TABLE BORDER=0 COLS=4 align=center WIDTH=100% BGCOLOR=\"#CCCCCC\" cellspacing=1 cellpadding=3>";
echo "<TR>";
echo "<TD WIDTH=3% NOSAVE><B>Id</B></TD>";
echo "<TD WIDTH=10% NOSAVE><B>Host</B></TD>";
echo "<TD WIDTH=10% NOSAVE><B>Port</B></TD>";
echo "<TD WIDTH=10% NOSAVE><B>Status</B></TD>";
echo "<TD WIDTH=10% NOSAVE><B>Actions</B></TD>";
echo "</TR>";
if(isset($HTTP_GET_VARS["groupid"]))
{
$sql="select h.hostid,h.host,h.port,h.status from hosts h,hosts_groups hg where hg.groupid=".$HTTP_GET_VARS["groupid"]." and hg.hostid=h.hostid order by h.host";
}
else
{
$sql="select h.hostid,h.host,h.port,h.status from hosts h order by h.host";
}
$result=DBselect($sql);
$col=0;
while($row=DBfetch($result))
{
if(!check_right("Host","R",$row["hostid"]))
{
continue;
}
if($col++%2==0) { echo "<TR BGCOLOR=#EEEEEE>"; }
else { echo "<TR BGCOLOR=#DDDDDD>"; }
echo "<TD>".$row["hostid"]."</TD>";
echo "<TD><a href=\"items.php?hostid=".$row["hostid"]."\">".$row["host"]."</a></TD>";
echo "<TD>".$row["port"]."</TD>";
echo "<TD>";
if(check_right("Host","U",$row["hostid"]))
{
if($row["status"] == 0)
echo "<a href=\"hosts.php?hostid=".$row["hostid"]."®ister=changestatus&status=1\"><font color=\"00AA00\">Monitored</font></a>";
else if($row["status"] == 1)
echo "<a href=\"hosts.php?hostid=".$row["hostid"]."®ister=changestatus&status=0\"><font color=\"AA0000\">Not monitored</font></a>";
else if($row["status"] == 2)
echo "<font color=\"AAAAAA\">Unreachable</font>";
else if($row["status"] == 3)
echo "<font color=\"AAAAAA\">Template</font>";
else
echo "Unknown";
}
else
{
if($row["status"] == 0)
echo "<font color=\"00AA00\">Monitored</font>";
else if($row["status"] == 1)
echo "<font color=\"AA0000\">Not monitored</font>";
else if($row["status"] == 2)
echo "<font color=\"AAAAAA\">Unreachable</font>";
else if($row["status"] == 3)
echo "<font color=\"AAAAAA\">Template</font>";
else
echo "Unknown";
}
echo "</TD>";
if(check_right("Host","U",$row["hostid"]))
{
if(isset($HTTP_GET_VARS["groupid"]))
{
echo "<TD><A HREF=\"hosts.php?register=change&hostid=".$row["hostid"]."&groupid=".$HTTP_GET_VARS["groupid"]."#form\">Change</A></TD>";
}
else
{
echo "<TD><A HREF=\"hosts.php?register=change&hostid=".$row["hostid"]."#form\">Change</A></TD>";
}
}
else
{
echo "<TD>Change</TD>";
}
echo "</TR>";
}
echo "</TABLE>";
}
?>
<?php
$host=@iif(isset($HTTP_GET_VARS["host"]),$HTTP_GET_VARS["host"],"");
$port=@iif(isset($HTTP_GET_VARS["port"]),$HTTP_GET_VARS["port"],get_profile("HOST_PORT",10000));
$status=@iif(isset($HTTP_GET_VARS["status"]),$HTTP_GET_VARS["status"],0);
$useip=@iif(isset($HTTP_GET_VARS["useip"]),$HTTP_GET_VARS["useip"],"off");
$newgroup=@iif(isset($HTTP_GET_VARS["newgroup"]),$HTTP_GET_VARS["newgroup"],"");
$ip=@iif(isset($HTTP_GET_VARS["ip"]),$HTTP_GET_VARS["ip"],"");
$host_templateid=@iif(isset($HTTP_GET_VARS["host_templateid"]),$HTTP_GET_VARS["host_templateid"],"");
if($useip!="on")
{
$useip="";
}
else
{
$useip="checked";
}
if(isset($HTTP_GET_VARS["register"]) && ($HTTP_GET_VARS["register"] == "change"))
{
$result=DBselect("select host,port,status,useip,ip from hosts where hostid=".$HTTP_GET_VARS["hostid"]);
$host=DBget_field($result,0,0);
$port=DBget_field($result,0,1);
$status=DBget_field($result,0,2);
$useip=DBget_field($result,0,3);
$ip=DBget_field($result,0,4);
if($useip==0)
{
$useip="";
}
else
{
$useip="checked";
}
}
else
{
}
echo "<br>";
echo "<a name=\"form\"></a>";
show_table2_header_begin();
echo "Host";
show_table2_v_delimiter();
echo "<form method=\"get\" action=\"hosts.php#form\">";
if(isset($HTTP_GET_VARS["hostid"]))
{
echo "<input class=\"biginput\" name=\"hostid\" type=\"hidden\" value=\"".$HTTP_GET_VARS["hostid"]."\">";
}
if(isset($HTTP_GET_VARS["groupid"]))
{
echo "<input class=\"biginput\" name=\"groupid\" type=\"hidden\" value=\"".$HTTP_GET_VARS["groupid"]."\">";
}
echo "Host";
show_table2_h_delimiter();
echo "<input class=\"biginput\" name=\"host\" value=\"$host\" size=20>";
show_table2_v_delimiter();
echo "Groups";
show_table2_h_delimiter();
echo "<select multiple class=\"biginput\" name=\"groups[]\" size=\"5\">";
$result=DBselect("select distinct groupid,name from groups order by name");
while($row=DBfetch($result))
{
if(isset($HTTP_GET_VARS["hostid"]))
{
$sql="select count(*) as count from hosts_groups where hostid=".$HTTP_GET_VARS["hostid"]." and groupid=".$row["groupid"];
$result2=DBselect($sql);
$row2=DBfetch($result2);
if($row2["count"]==0)
{
echo "<option value=\"".$row["groupid"]."\">".$row["name"];
}
else
{
echo "<option value=\"".$row["groupid"]."\" selected>".$row["name"];
}
}
else
{
echo "<option value=\"".$row["groupid"]."\">".$row["name"];
}
}
echo "</select>";
show_table2_v_delimiter();
echo "New group";
show_table2_h_delimiter();
echo "<input class=\"biginput\" name=\"newgroup\" size=20 value=\"$newgroup\">";
show_table2_v_delimiter();
echo "Use IP address";
show_table2_h_delimiter();
echo "<INPUT TYPE=\"CHECKBOX\" class=\"biginput\" NAME=\"useip\" $useip onChange=\"submit()\">";
if($useip=="checked")
{
show_table2_v_delimiter();
echo "IP address";
show_table2_h_delimiter();
echo "<input class=\"biginput\" name=\"ip\" value=\"$ip\" size=15>";
}
else
{
echo "<input class=\"biginput\" type=\"hidden\"name=\"ip\" value=\"$ip\" size=15>";
}
show_table2_v_delimiter();
echo "Port";
show_table2_h_delimiter();
echo "<input class=\"biginput\" name=\"port\" size=6 value=\"$port\">";
show_table2_v_delimiter();
echo "Status";
show_table2_h_delimiter();
echo "<select class=\"biginput\" name=\"status\" size=\"1\">";
if($status==0)
{
echo "<option value=\"0\" selected>Monitored";
echo "<option value=\"1\">Not monitored";
echo "<option value=\"3\">Template";
}
else if($status==3)
{
echo "<option value=\"0\">Monitored";
echo "<option value=\"1\">Not monitored";
echo "<option value=\"3\" selected>Template";
}
else
{
echo "<option value=\"0\">Monitored";
echo "<option value=\"1\" selected>Not monitored";
echo "<option value=\"3\">Template";
}
echo "</select>";
show_table2_v_delimiter();
echo "Use the host as a template";
show_table2_h_delimiter();
echo "<select class=\"biginput\" name=\"host_templateid\" size=\"1\">";
echo "<option value=\"0\" selected>...";
// $result=DBselect("select host,hostid from hosts where status=3 order by host");
$result=DBselect("select host,hostid from hosts order by host");
while($row=DBfetch($result))
{
if($host_templateid == $row["hostid"])
{
echo "<option value=\"".$row["hostid"]."\" selected>".$row["host"];
}
else
{
echo "<option value=\"".$row["hostid"]."\">".$row["host"];
}
}
echo "</select>";
show_table2_v_delimiter2();
echo "<input type=\"submit\" name=\"register\" value=\"add\">";
if(isset($HTTP_GET_VARS["hostid"]))
{
echo "<input type=\"submit\" name=\"register\" value=\"update\">";
echo "<input type=\"submit\" name=\"register\" value=\"delete\" onClick=\"return Confirm('Delete selected host?');\">";
}
show_table2_header_end();
?>
<?php
show_footer();
?>
|