IP Reg is a IPAM tool to keep track of assets, nodes (IP addresses, MAC addresses, DNS aliases) within different subnets, over different locations or even VLAN's. Written in PHP, used with a MySQL-database to have a unique insight in your local network.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 
ipreg/locationview.php

214 lines
5.5 KiB

<?php
/*****************************************************************************
IP Reg, a PHP/MySQL IPAM tool
Copyright (C) 2007-2009 Wietse Warendorff
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 3 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, see <http://www.gnu.org/licenses/>.
For more information, visit http://sourceforge.net/projects/ipreg,
or contact me at wietsew@users.sourceforge.net
*****************************************************************************/
// start page
// includes
include("includes.php");
// get id
$location_id = sanitize($_GET['location_id']);
// start output
include("header.php");
// set template
$tp = new Template("tpl/locationview.tpl", $config_yapter_error);
// set language variables
$tp->setvars($lang);
// start locationcrumb
// get locations
// build query
$query = "SELECT
location.location_id AS location_id,
location.location_name AS location_name,
location.location_parent AS location_parent
FROM
location";
// run query
$locations = $db->db_select($query);
// count results
$location_counter = count($locations);
// counter to tpl
$tp->set("location_counter", $location_counter);
// any loactions?
if ($location_counter>0) {
// get objects
foreach($locations AS $location) {
// create arrays
$location_names[$location['location_id']] = $location['location_name'];
$parents[$location['location_id']] = $location['location_parent'];
}
}
// build parents array
// function to build array with parents for this location
function parent($location_id) {
// use names index
global $parents;
global $crumbs;
global $location_names;
// fill array with this value
$crumbs[$location_id] = $location_id;
if (($parents[$location_id])>0) {
// still not on top, so do it again
parent($parents[$location_id]);
}
// return the array
return $location_id;
}
// build parents
parent($location_id);
// to tpl
// loop in reverse order
foreach (array_reverse($crumbs) as $key=>$val) {
// send vars to template
$tp->set("location_id", $val);
$tp->set("location_name", $location_names[$val]);
// include seperator?
if (($key>0) ? $tp->set("seperator", ".&nbsp;") : $tp->set("seperator", ""));
// parse block
$tp->parse("locationcrumb_row");
}
// parse block
$tp->parse("locationcrumb_table");
// setup location
// build query
$query = "SELECT
location.location_info AS location_info
FROM
location
WHERE
location.location_id=" . $location_id;
// run query
$location = $db->db_select($query);
// send to tpl
$tp->set("location_id", $location_id);
$tp->set("location_info", nl2br($location[0]['location_info']));
// setup sublocations
// build query
$query = "SELECT
location.location_id AS sublocation_id,
location.location_name AS sublocation_name
FROM
location
WHERE
location.location_parent=" . $location_id . "
ORDER BY
location.location_name";
// run query
$sublocations = $db->db_select($query);
// count results
$sublocation_counter = count($sublocations);
// counter to tpl
$tp->set("sublocation_counter", $sublocation_counter);
// any nodes?
if ($sublocation_counter>0) {
// get objects
foreach($sublocations AS $sublocation) {
// send to tpl
$tp->set("sublocation_id", $sublocation['sublocation_id']);
$tp->set("sublocation_name", $sublocation['sublocation_name']);
// parse row
$tp->parse("sublocation_row");
}
// parse block
$tp->parse("sublocation_table");
} else {
// hide block
$tp->hide("sublocation_table");
}
// setup subnets
// build query
$query = "SELECT
subnet.subnet_id AS subnet_id,
subnet.subnet_address AS subnet_address,
subnet.subnet_mask AS subnet_mask
FROM
subnet,
subnetlocation
WHERE
subnetlocation.location_id=" . $location_id . "
AND subnetlocation.subnet_id=subnet.subnet_id
ORDER BY
INET_ATON(subnet.subnet_address)";
// run query
$subnets = $db->db_select($query);
// count results
$subnet_counter = count($subnets);
// counter to tpl
$tp->set("subnet_counter", $subnet_counter);
// any nodes?
if ($subnet_counter>0) {
// get objects
foreach($subnets AS $subnet) {
// send to tpl
$tp->set("subnet_id", $subnet['subnet_id']);
$tp->set("subnet_address", $subnet['subnet_address']);
$tp->set("subnet_mask", $subnet['subnet_mask']);
// parse row
$tp->parse("subnet_row");
}
// parse block
$tp->parse("subnet_table");
} else {
// hide block
$tp->hide("subnet_table");
}
// end page
// output
$tp->parse();
$tp->spit();
// footer
include("footer.php");
?>