/usr/share/netmrg/webfiles/device_tree.php is in netmrg 0.20-7.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | <?php
/********************************************
* NetMRG Integrator
*
* device_tree.php
* Device Tree
*
* see doc/LICENSE for copyright information
********************************************/
require_once("../include/config.php");
// require at least read
check_auth($GLOBALS['PERMIT']["SingleViewOnly"]);
// setup cookies
if (!isset($_COOKIE["netmrgDevTree"]) || !is_array($_COOKIE["netmrgDevTree"]))
{
$_COOKIE["netmrgDevTree"] = array();
$_COOKIE["netmrgDevTree"]["group"] = array();
$_COOKIE["netmrgDevTree"]["device"] = array();
$_COOKIE["netmrgDevTree"]["subdevice"] = array();
$_COOKIE["netmrgDevTree"]["monitor"] = array();
} // end if no cookies
else
{
if (!empty($_COOKIE["netmrgDevTree"]["group"]))
{
$_COOKIE["netmrgDevTree"]["group"] = unserialize(urldecode($_COOKIE["netmrgDevTree"]["group"]));
}
else
{
$_COOKIE["netmrgDevTree"]["group"] = array();
} // end if group not empty
if (!empty($_COOKIE["netmrgDevTree"]["device"]))
{
$_COOKIE["netmrgDevTree"]["device"] = unserialize(urldecode($_COOKIE["netmrgDevTree"]["device"]));
}
else
{
$_COOKIE["netmrgDevTree"]["device"] = array();
} // end if device not empty
if (!empty($_COOKIE["netmrgDevTree"]["subdevice"]))
{
$_COOKIE["netmrgDevTree"]["subdevice"] = unserialize(urldecode($_COOKIE["netmrgDevTree"]["subdevice"]));
}
else
{
$_COOKIE["netmrgDevTree"]["subdevice"] = array();
} // end if subdevice not empty
if (!empty($_COOKIE["netmrgDevTree"]["monitor"]))
{
$_COOKIE["netmrgDevTree"]["monitor"] = unserialize(urldecode($_COOKIE["netmrgDevTree"]["monitor"]));
}
else
{
$_COOKIE["netmrgDevTree"]["monitor"] = array();
} // end if monitor not empty
} // end else some cookies
// if we need to do something
if (!empty($_REQUEST["action"]))
{
if ($_REQUEST["action"] == "expand")
{
if (!empty($_REQUEST["groupid"]))
{
if (!in_array($_REQUEST["groupid"], $_COOKIE["netmrgDevTree"]["group"]))
{
array_push($_COOKIE["netmrgDevTree"]["group"], $_REQUEST["groupid"]);
} // end if id not in array, put it there
} // end if group id
else if (!empty($_REQUEST["deviceid"]))
{
if (!in_array($_REQUEST["deviceid"], $_COOKIE["netmrgDevTree"]["device"]))
{
array_push($_COOKIE["netmrgDevTree"]["device"], $_REQUEST["deviceid"]);
} // end if id not in array, put it there
} // end if device id
else if (!empty($_REQUEST["subdevid"]))
{
if (!in_array($_REQUEST["subdevid"], $_COOKIE["netmrgDevTree"]["subdevice"]))
{
array_push($_COOKIE["netmrgDevTree"]["subdevice"], $_REQUEST["subdevid"]);
} // end if id not in array, put it there
}
else if (!empty($_REQUEST["monid"]))
{
if (!in_array($_REQUEST["monid"], $_COOKIE["netmrgDevTree"]["monitor"]))
{
array_push($_COOKIE["netmrgDevTree"]["monitor"], $_REQUEST["monid"]);
} // end if id not in array, put it there
} // end if monitor id
} // end if we need to expand something
else if ($_REQUEST["action"] == "collapse")
{
if (!empty($_REQUEST["groupid"]))
{
if (in_array($_REQUEST["groupid"], $_COOKIE["netmrgDevTree"]["group"]))
{
unset($_COOKIE["netmrgDevTree"]["group"][array_search($_REQUEST["groupid"], $_COOKIE["netmrgDevTree"]["group"])]);
} // end if group is currently expanded
} // end if group id
else if (!empty($_REQUEST["deviceid"]))
{
if (in_array($_REQUEST["deviceid"], $_COOKIE["netmrgDevTree"]["device"]))
{
unset($_COOKIE["netmrgDevTree"]["device"][array_search($_REQUEST["deviceid"], $_COOKIE["netmrgDevTree"]["device"])]);
} // end if device is currently expanded
} // end if device id
else if (!empty($_REQUEST["subdevid"]))
{
if (in_array($_REQUEST["subdevid"], $_COOKIE["netmrgDevTree"]["subdevice"]))
{
unset($_COOKIE["netmrgDevTree"]["subdevice"][array_search($_REQUEST["subdevid"], $_COOKIE["netmrgDevTree"]["subdevice"])]);
}
}
else if (!empty($_REQUEST["monid"]))
{
if (in_array($_REQUEST["monid"], $_COOKIE["netmrgDevTree"]["monitor"]))
{
unset($_COOKIE["netmrgDevTree"]["monitor"][array_search($_REQUEST["monid"], $_COOKIE["netmrgDevTree"]["monitor"])]);
} // end if monitor is currently expanded
} // end if monitor id
} // end if we need to colapse something
} // end if we need to do something
// set our new cookie to last for a week (7days * 24hrs * 60min * 60sec)
setcookie("netmrgDevTree[group]", urlencode(serialize($_COOKIE["netmrgDevTree"]["group"])), time()+604800);
setcookie("netmrgDevTree[device]", urlencode(serialize($_COOKIE["netmrgDevTree"]["device"])), time()+604800);
setcookie("netmrgDevTree[subdevice]", urlencode(serialize($_COOKIE["netmrgDevTree"]["subdevice"])), time()+604800);
setcookie("netmrgDevTree[monitor]", urlencode(serialize($_COOKIE["netmrgDevTree"]["monitor"])), time()+604800);
begin_page("device_tree.php", "Device Tree", 1);
?>
<table style="border-collapse: collapse;" width="100%" border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<td class="editmainheader" colspan="6">
Device Tree
</td>
</tr>
<tr>
<td class="editheader" width="">Group</td>
<td class="editheader" width="">Device</td>
<td class="editheader" width="">Sub-Device</td>
<td class="editheader" width="">Monitors</td>
<td class="editheader" width="">Events</td>
<td class="editheader" width="">Status</td>
</tr>
<?php
$rowcount = 0;
draw_group($_SESSION["netmrgsess"]["group_id"], 0, $rowcount, true);
?>
</table>
<?php
end_page();
?>
<?php
/***** FUCTIONS *****/
function draw_group($grp_id, $depth, &$rowcount, $init = false)
{
// for each group
if ($init && $grp_id != 0)
{
$grp_results = db_query("SELECT * FROM groups WHERE id=$grp_id ORDER BY name");
}
else
{
$grp_results = db_query("SELECT * FROM groups WHERE parent_id=$grp_id ORDER BY name");
}
while ($grp_row = db_fetch_array($grp_results))
{
$grp_id = $grp_row["id"];
$grp_action = "";
$editgroup = ($_SESSION["netmrgsess"]["permit"] > 0) ? '<a class="editfield'.($rowcount%2).'" href="grpdev_list.php?parent_id='.$grp_id.'">'.
'<img src="'.get_image_by_name("edit").'" width="15" height="15" border="0" alt="edit" title="edit" align="middle" />'.
'</a>'."\n" : "";
// draw +- and create link for group to expand/collapse
if (in_array($grp_id, $_COOKIE["netmrgDevTree"]["group"]))
{
$img = get_image_by_name("hide");
$grp_action = "collapse";
}
else
{
$img = get_image_by_name("show");
$grp_action = "expand";
} // end if this group is expanded
// if > 0 associated items, display 'on' viewgraph
if (GetNumAssocItems("group", $grp_id) > 0)
{
make_display_item("editfield".($rowcount%2),
array("text" =>
'<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td>'."\n".
make_nbsp($depth * 4) .
'<a class="editfield'.($rowcount%2).'" href="'.$_SERVER["PHP_SELF"] . '?action='.$grp_action.'&groupid='.$grp_id.'">'.
'<img src="' . $img . '" border="0" width="9" height="9" alt="expand/collapse" />' . " " . $grp_row["name"] ."\n".
'</a>'."\n".
'</td><td align="right">'."\n".
'<a class="editfield'.($rowcount%2).'" href="view.php?action=view&object_type=group&object_id='.$grp_id.'">'.
'<img src="'.get_image_by_name("viewgraph-on").'" width="15" height="15" border="0" alt="View" title="View" align="middle" />'."\n".
'</a>'."\n".
'<a class="editfield'.($rowcount%2).'" href="view.php?action=slideshow&type=1&group_id='.$grp_id.'">'.
'<img src="'.get_image_by_name("slideshow").'" width="15" height="15" border="0" alt="View" title="Slide Show" align="middle" />'."\n".
'</a>'."\n".
$editgroup.
'</td></tr></table>'."\n"
),
array(),
array(),
array(),
array(),
array("text" => get_img_tag_from_status(get_group_status($grp_id)))
); // end make_display_item();
} // end if > 0 assoc items
// else, display 'off' viewgraph
else
{
make_display_item("editfield".($rowcount%2),
array("text" =>
'<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td>'."\n".
make_nbsp($depth * 4) .
'<a class="editfield'.($rowcount%2).'" href="'.$_SERVER["PHP_SELF"] . '?action='.$grp_action.'&groupid='.$grp_id.'">'.
'<img src="' . $img . '" border="0" width="9" height="9" alt="expand/collapse" />' . " " . $grp_row["name"] .
'</a>'."\n".
'</td><td align="right">'."\n".
'<a class="editfield'.($rowcount%2).'" href="view.php?action=view&object_type=group&object_id='.$grp_id.'">'.
'<img src="'.get_image_by_name("viewgraph-off").'" width="15" height="15" border="0" alt="View" title="View" align="middle" />'.
'</a>'."\n".
'<a class="editfield'.($rowcount%2).'" href="view.php?action=slideshow&type=1&group_id='.$grp_id.'">'.
'<img src="'.get_image_by_name("slideshow").'" width="15" height="15" border="0" alt="View" title="Slide Show" align="middle" />'."\n".
'</a>'."\n".
$editgroup.
'</td></tr></table>'."\n"
),
array(),
array(),
array(),
array(),
array("text" => get_img_tag_from_status(get_group_status($grp_id)))
); // end make_display_item();
} // end if 0 assoc items
$rowcount++;
// if group is expanded, show the devices
if (in_array($grp_id, $_COOKIE["netmrgDevTree"]["group"]))
{
$dev_results = db_query("
SELECT dev_parents.dev_id AS id, devices.name AS name, devices.status AS status
FROM dev_parents
LEFT JOIN devices ON dev_parents.dev_id=devices.id
WHERE grp_id = '$grp_id'
ORDER BY name");
// while we still have devices
while ($dev_row = db_fetch_array($dev_results))
{
$device_id = $dev_row["id"];
$device_action = "";
$editdevice = ($_SESSION["netmrgsess"]["permit"] > 0) ? '<a class="editfield'.($rowcount%2).'" href="sub_devices.php?dev_id='.$device_id.'">'.
'<img src="'.get_image_by_name("edit").'" width="15" height="15" border="0" alt="edit" title="edit" align="middle" />'.
'</a>'."\n" : "";
// draw +- and create link for device to expand/collapse
if (in_array($device_id, $_COOKIE["netmrgDevTree"]["device"]))
{
$img = get_image_by_name("hide");
$device_action = "collapse";
}
else
{
$img = get_image_by_name("show");
$device_action = "expand";
} // end if D tree
// if > 0 associated items, display 'on' viewgraph
if (GetNumAssocItems("device", $device_id) > 0)
{
make_display_item("editfield".($rowcount%2),
array(),
array("text" =>
'<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td>'."\n".
'<a class="editfield'.($rowcount%2).'" href="'.$_SERVER["PHP_SELF"] . '?action='.$device_action.'&deviceid='.$device_id.'">'.
'<img src="' . $img . '" border="0" width="9" height="9" alt="expand/collapse" />' . " " . $dev_row["name"] .
'</a>'."\n".
'</td><td align="right">'."\n".
'<a class="editfield'.($rowcount%2).'" href="view.php?action=view&object_type=device&object_id='.$device_id.'">'.
'<img src="'.get_image_by_name("viewgraph-on").'" width="15" height="15" border="0" alt="View" title="View" align="middle" />'.
'</a>'."\n".
$editdevice.
'</td></tr></table>'."\n"
),
array(),
array(),
array(),
array("text" => get_img_tag_from_status($dev_row['status']))
); // end make_display_item();
} // end if > 0 assoc items
// else, display 'off' viewgraph
else
{
make_display_item("editfield".($rowcount%2),
array(),
array("text" =>
'<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td>'."\n".
'<a class="editfield'.($rowcount%2).'" href="'.$_SERVER["PHP_SELF"] . '?action='.$device_action.'&deviceid='.$device_id.'">'.
'<img src="' . $img . '" border="0" width="9" height="9" alt="expand/collapse" />' . " " . $dev_row["name"] .
'</a>'."\n".
'</td><td align="right">'."\n".
'<a class="editfield'.($rowcount%2).'" href="view.php?action=view&object_type=device&object_id='.$device_id.'">'.
'<img src="'.get_image_by_name("viewgraph-off").'" width="15" height="15" border="0" alt="View" title="View" align="middle" />'.
'</a>'."\n".
$editdevice.
'</td></tr></table>'."\n"
),
array(),
array(),
array(),
array("text" => get_img_tag_from_status($dev_row['status']))
); // end make_display_item();
} // end if 0 assoc items
$rowcount++;
// if this device is expanded, show the subdevices
if (in_array($device_id, $_COOKIE["netmrgDevTree"]["device"]))
{
$subdev_results = db_query("
SELECT id, name, status FROM sub_devices WHERE dev_id={$dev_row['id']} ORDER BY type, name");
while ($subdev_row = db_fetch_array($subdev_results))
{
$subdev_id = $subdev_row["id"];
$subdev_action = "";
$editsubdevice = ($_SESSION["netmrgsess"]["permit"] > 0) ? '<a class="editfield'.($rowcount%2).'" href="monitors.php?sub_dev_id='.$subdev_id.'">'.
'<img src="'.get_image_by_name("edit").'" width="15" height="15" border="0" alt="edit" title="edit" align="middle" />'.
'</a>'."\n" : "";
// draw +- and create link for monitor expand/collapse
if (in_array($subdev_id, $_COOKIE["netmrgDevTree"]["subdevice"]))
{
$img = get_image_by_name("hide");
$subdev_action = "collapse";
}
else
{
$img = get_image_by_name("show");
$subdev_action = "expand";
} // end if M tree
// if > 0 associated items, display 'on' viewgraph
if (GetNumAssocItems("subdevice", $subdev_id) > 0)
{
make_display_item("editfield".($rowcount%2),
array(),
array(),
array("text" =>
'<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td>'."\n".
'<a class="editfield'.($rowcount%2).'" href="'.$_SERVER["PHP_SELF"] . '?action='.$subdev_action.'&subdevid='.$subdev_id.'">'.
'<img src="'. $img . '" border="0" width="9" height="9" alt="expand/collapse" />' . " " . $subdev_row['name'].
'</a>'."\n".
'</td><td align="right">'."\n".
'<a class="editfield'.($rowcount%2).'" href="view.php?action=view&object_type=subdevice&object_id='.$subdev_id.'">'.
'<img src="'.get_image_by_name("viewgraph-on").'" width="15" height="15" border="0" alt="View" title="View" align="middle" />'.
'</a>'."\n".
$editsubdevice.
'</td></tr></table>'."\n"
),
array(),
array(),
array("text" => get_img_tag_from_status($subdev_row['status']))
); // end make_display_item();
} // end if > 0 assoc items
// else, display 'off' viewgraph
else
{
make_display_item("editfield".($rowcount%2),
array(),
array(),
array("text" =>
'<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td>'."\n".
'<a class="editfield'.($rowcount%2).'" href="'.$_SERVER["PHP_SELF"] . '?action='.$subdev_action.'&subdevid='.$subdev_id.'">'.
'<img src="'. $img . '" border="0" width="9" height="9" alt="expand/collapse" />' . " " . $subdev_row['name'].
'</a>'."\n".
'</td><td align="right">'."\n".
'<a class="editfield'.($rowcount%2).'" href="view.php?action=view&object_type=subdevice&object_id='.$subdev_id.'">'.
'<img src="'.get_image_by_name("viewgraph-off").'" width="15" height="15" border="0" alt="View" title="View" align="middle" />'.
'</a>'."\n".
$editsubdevice.
'</td></tr></table>'."\n"
),
array(),
array(),
array("text" => get_img_tag_from_status($subdev_row['status']))
); // end make_display_item();
} // end if 0 assoc items
$rowcount++;
// if this subdevice is expanded, show the monitors
if (in_array($subdev_id, $_COOKIE["netmrgDevTree"]["subdevice"]))
{
$mon_results = db_query("SELECT id, status FROM monitors WHERE sub_dev_id={$subdev_row['id']}");
// while we have monitors
while ($mon_row = db_fetch_array($mon_results))
{
$mon_id = $mon_row["id"];
$monitor_action = "";
$editmonitor = ($_SESSION["netmrgsess"]["permit"] > 0) ? '<a class="editfield'.($rowcount%2).'" href="events.php?mon_id='.$mon_id.'">'.
'<img src="'.get_image_by_name("edit").'" width="15" height="15" border="0" alt="edit" title="edit" align="middle" />'.
'</a>'."\n" : "";
// draw +- and create link for monitor expand/collapse
if (in_array($mon_id, $_COOKIE["netmrgDevTree"]["monitor"]))
{
$img = get_image_by_name("hide");
$monitor_action = "collapse";
}
else
{
$img = get_image_by_name("show");
$monitor_action = "expand";
} // end if M tree
make_display_item("editfield".($rowcount%2),
array(),
array(),
array(),
array("text" =>
'<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td>'."\n".
'<a class="editfield'.($rowcount%2).'" href="'. $_SERVER["PHP_SELF"] . '?action='.$monitor_action.'&monid='.$mon_id.'">'.
'<img src="' . $img . '" border="0" width="9" height="9" alt="expand/collapse" />' . " " . get_short_monitor_name($mon_row["id"]).
'</a>'."\n".
'</td><td align="right">'."\n".
'<a class="editfield'.($rowcount%2).'" href="enclose_graph.php?type=mon&id='.$mon_id.'">'.
'<img src="'.get_image_by_name("viewgraph-on").'" width="15" height="15" border="0" alt="View" title="View" align="middle" />'.
'</a>'."\n".
$editmonitor.
'</td></tr></table>'."\n"
),
array(),
array("text" => get_img_tag_from_status($mon_row['status']))
); // end make_display_item();
$rowcount++;
// if this monitor is expanded, show the events
if (in_array($mon_id, $_COOKIE["netmrgDevTree"]["monitor"]))
{
$event_results = db_query("SELECT * FROM events WHERE mon_id=$mon_id");
$event_total = db_num_rows($event_results);
// For each event
for ($event_count = 1; $event_count <= $event_total; ++$event_count)
{
$event_row = db_fetch_array($event_results);
$event_id = $event_row["id"];
$color = get_color_from_situation($event_row["situation"]);
if ($event_row["last_status"] == 1)
{
$img = ("<img src=\"" . get_image_by_name($color . "_led_on") . "\" border=\"0\" />");
}
else
{
$img = ("<img src=\"" . get_image_by_name($color . "_led_off") . "\" border=\"0\" />");
} // end if last status
make_display_item("editfield".($rowcount%2),
array(),
array(),
array(),
array(),
array("text" => $event_row["name"]),
array("text" => $img)
); // end make_display_item();
$rowcount++;
} // end event for
} // end if monitor expanded
}// end while each monitor
} // end if sub-device expanded
} // end while each sub-device
} // end if device expanded
} // end while each device
// this is down here so each group's items show up with that group,
// and not putting all the sub groups together before the devices
draw_group($grp_id, $depth + 1, $rowcount);
} // end if group expanded
} // end while each group
} // end draw_group()
?>
|