Moved towards smarty templates, support php7, switched to mysqli,
finalized language support and fixed some more bugs
This commit is contained in:
939
subnetview.php
939
subnetview.php
@@ -1,499 +1,440 @@
|
||||
<?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
|
||||
$subnet_id = sanitize($_GET['subnet_id']);
|
||||
|
||||
// get page
|
||||
if(isset($_GET['page'])) {
|
||||
$page = sanitize($_GET['page']);
|
||||
}
|
||||
|
||||
// start output
|
||||
include("header.php");
|
||||
|
||||
// set template
|
||||
$tp = new Template("tpl/subnetview.tpl", $config_yapter_error);
|
||||
|
||||
// set language variables
|
||||
$tp->setvars($lang);
|
||||
|
||||
// setup subnet
|
||||
// build query
|
||||
$query = "SELECT
|
||||
subnet.subnet_address AS subnet_address,
|
||||
subnet.subnet_mask AS subnet_mask,
|
||||
subnet.subnet_info AS subnet_info,
|
||||
COUNT(node.subnet_id) AS node_counter
|
||||
FROM
|
||||
subnet
|
||||
LEFT JOIN
|
||||
node
|
||||
ON
|
||||
node.subnet_id=subnet.subnet_id
|
||||
WHERE
|
||||
subnet.subnet_id=" . $subnet_id . "
|
||||
GROUP BY
|
||||
subnet.subnet_id";
|
||||
|
||||
// run query
|
||||
$subnet = $db->db_select($query);
|
||||
|
||||
// set needed variables
|
||||
$subnet_address = $subnet[0]['subnet_address'];
|
||||
$subnet_mask = $subnet[0]['subnet_mask'];
|
||||
|
||||
// set counters
|
||||
$host_counter = pow(2,(32-$subnet_mask));
|
||||
$node_counter = $subnet[0]['node_counter'];
|
||||
$subnet_usedpercentage = round((($node_counter/($host_counter-2))*100),1);
|
||||
|
||||
// send to tpl
|
||||
$tp->set("subnet_id", $subnet_id);
|
||||
$tp->set("subnet_address", $subnet_address);
|
||||
$tp->set("subnet_mask", $subnet_mask);
|
||||
$tp->set("subnet_info", nl2br($subnet[0]['subnet_info']));
|
||||
$tp->set("node_counter", $node_counter);
|
||||
$tp->set("subnet_usedpercentage", $subnet_usedpercentage);
|
||||
$tp->set("config_color_unused", $config_color_unused);
|
||||
$tp->set("host_counter", $host_counter-2);
|
||||
$tp->set("free_counter", (($host_counter-2)-$node_counter));
|
||||
|
||||
// setup subnet
|
||||
// split up the range
|
||||
$iprange = explode('.', $subnet_address);
|
||||
$iprange1 = $iprange[0];
|
||||
$iprange2 = $iprange[1];
|
||||
$iprange3 = $iprange[2];
|
||||
$iprange4 = $iprange[3];
|
||||
|
||||
// create empty subnet-array
|
||||
$subnet = array();
|
||||
|
||||
// determine range (Class A/B/C)
|
||||
if ($subnet_mask>=24) {
|
||||
// Class C
|
||||
// fill subnet-array with addresses we want to see
|
||||
for($i=0;$i<$host_counter;$i++) {
|
||||
// build ip
|
||||
$ip = $iprange1 . '.' . $iprange2 . '.' . $iprange3 . '.' . ($iprange4+$i);
|
||||
|
||||
// fill subnet-array
|
||||
$subnet[$ip] = array();
|
||||
}
|
||||
|
||||
// calculate broadcast address
|
||||
$broadcast_address = $iprange1 . '.' . $iprange2 . '.' . $iprange3 . '.' . ($iprange4+$i-1);
|
||||
|
||||
// to tpl
|
||||
$tp->set("iprange1", $iprange1);
|
||||
$tp->set("iprange2", $iprange2);
|
||||
$tp->set("iprange3", $iprange3);
|
||||
$tp->set("iprange4", $iprange4);
|
||||
$tp->set("subnetmask1", 255);
|
||||
$tp->set("subnetmask2", 255);
|
||||
$tp->set("subnetmask3", 255);
|
||||
$tp->set("subnetmask4", 256-$host_counter);
|
||||
|
||||
// no pagination needed
|
||||
$tp->parse("noselect");
|
||||
$tp->hide("one_select");
|
||||
$tp->hide("two_select");
|
||||
|
||||
// set displayed nodes
|
||||
$nodes_displayed = $host_counter;
|
||||
} else if ($subnet_mask>=16) {
|
||||
// Class B
|
||||
// which part do we want to see?
|
||||
if((empty($page)) ? $page=$subnet_address : $page=$page);
|
||||
$page = explode('.', $page);
|
||||
$page2 = $page[2];
|
||||
|
||||
// fill subnet-array with addresses we want to see
|
||||
for($i=0;$i<256;$i++) {
|
||||
// build ip
|
||||
$ip = $iprange1 . '.' . $iprange2 . '.' . $page2 . '.' . $i;
|
||||
|
||||
// fill subnet-array
|
||||
$subnet[$ip] = array();
|
||||
}
|
||||
|
||||
// calculate broadcast address
|
||||
$broadcast_address = $iprange1 . '.' . $iprange2 . '.' . ($iprange3+$i-1) . '.255';
|
||||
|
||||
// to tpl
|
||||
$tp->set("iprange1", $iprange1);
|
||||
$tp->set("iprange2", $iprange2);
|
||||
|
||||
// loop addresses in range3
|
||||
for($i=$iprange3;$i<(pow(2,(32-$subnet_mask))/256);$i++) {
|
||||
// send to tpl
|
||||
$tp->set("iprange3", $i);
|
||||
$tp->set("iprange4", 0);
|
||||
|
||||
// set select box
|
||||
if($i==$page2) {
|
||||
$tp->set("row_selected", "selected");
|
||||
|
||||
} else {
|
||||
$tp->set("row_selected", "");
|
||||
}
|
||||
|
||||
// parse block
|
||||
$tp->parse("one_select_row");
|
||||
}
|
||||
|
||||
$tp->set("subnetmask1", 255);
|
||||
$tp->set("subnetmask2", 255);
|
||||
$tp->set("subnetmask3", 256-($host_counter/256));
|
||||
$tp->set("subnetmask4", 0);
|
||||
|
||||
// one select box
|
||||
$tp->hide("noselect");
|
||||
$tp->parse("one_select");
|
||||
$tp->hide("two_select");
|
||||
|
||||
// set displayed nodes
|
||||
$nodes_displayed = 256;
|
||||
} else {
|
||||
// Class A
|
||||
// which part do we want to see?
|
||||
if((empty($page)) ? $page=$subnet_address : $page=$page);
|
||||
$page = explode('.', $page);
|
||||
$page2 = $page[1];
|
||||
$page3 = $page[2];
|
||||
|
||||
// fill subnet-array with addresses we want to see
|
||||
for($i=0;$i<256;$i++) {
|
||||
// build ip
|
||||
$ip = $iprange1 . '.' . $page2 . '.' . $page3 . '.' . $i;
|
||||
|
||||
// fill subnet-array
|
||||
$subnet[$ip] = array();
|
||||
}
|
||||
|
||||
// calculate broadcast address
|
||||
$broadcast_address = $iprange1 . '.' . ($iprange2+$i-1) . '.255.255';
|
||||
|
||||
// to tpl
|
||||
$tp->set("iprange1", $iprange1);
|
||||
$tp->set("iprange2", $iprange2);
|
||||
|
||||
// loop addresses in range 2
|
||||
for($i=$iprange2;$i<(pow(2,(24-$subnet_mask))/256);$i++) {
|
||||
// send to tpl
|
||||
$tp->set("iprange1", $iprange1);
|
||||
$tp->set("iprange2", $i);
|
||||
$tp->set("iprange3", $page3);
|
||||
$tp->set("iprange4", $iprange4);
|
||||
|
||||
// set select box
|
||||
if($i==$page2) {
|
||||
$tp->set("row1_selected", "selected");
|
||||
|
||||
} else {
|
||||
$tp->set("row1_selected", "");
|
||||
}
|
||||
|
||||
// parse block
|
||||
$tp->parse("two_select_row1");
|
||||
}
|
||||
|
||||
// loop addresses in range 3
|
||||
for($i=0;$i<256;$i++) {
|
||||
// send to tpl
|
||||
$tp->set("iprange1", $iprange1);
|
||||
$tp->set("iprange2", $page2);
|
||||
$tp->set("iprange3", $i);
|
||||
$tp->set("iprange4", $iprange4);
|
||||
|
||||
// set select box
|
||||
if($i==$page3) {
|
||||
$tp->set("row2_selected", "selected");
|
||||
|
||||
} else {
|
||||
$tp->set("row2_selected", "");
|
||||
}
|
||||
|
||||
// parse block
|
||||
$tp->parse("two_select_row2");
|
||||
}
|
||||
|
||||
$tp->set("subnetmask1", 255);
|
||||
$tp->set("subnetmask2", 256-($host_counter/65536));
|
||||
$tp->set("subnetmask3", 0);
|
||||
$tp->set("subnetmask4", 0);
|
||||
|
||||
// one select box
|
||||
$tp->hide("noselect");
|
||||
$tp->hide("one_select");
|
||||
$tp->parse("two_select");
|
||||
|
||||
// set displayed nodes
|
||||
$nodes_displayed = 256;
|
||||
}
|
||||
|
||||
// get nodes for this subnetview and implement the values into the array
|
||||
// build query
|
||||
$query = "SELECT
|
||||
asset.asset_name AS asset_name,
|
||||
assetclassgroup.assetclassgroup_color AS assetclassgroup_color,
|
||||
node.node_id AS node_id,
|
||||
node.node_ip AS node_ip
|
||||
FROM
|
||||
asset,
|
||||
assetclass,
|
||||
assetclassgroup,
|
||||
node
|
||||
WHERE
|
||||
node.node_ip IN ('".implode("','",array_keys($subnet))."')
|
||||
AND node.subnet_id='$subnet_id'
|
||||
AND asset.asset_id=node.asset_id
|
||||
AND assetclass.assetclass_id=asset.assetclass_id
|
||||
AND assetclassgroup.assetclassgroup_id=assetclass.assetclassgroup_id";
|
||||
|
||||
// run query
|
||||
$nodes = $db->db_select($query);
|
||||
|
||||
// count results
|
||||
$node_counter = count($nodes);
|
||||
|
||||
// any nodes?
|
||||
if ($node_counter>0) {
|
||||
// get objects
|
||||
foreach($nodes AS $node) {
|
||||
// add node-values to ip in subnet-array
|
||||
$subnet[$node['node_ip']] = $node;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// replace ip's in subnet-array (if necessary)
|
||||
// check for subnet address
|
||||
if(array_key_exists($subnet_address, $subnet)) {
|
||||
// replace
|
||||
$subnet[$subnet_address] = array("subnet_address");
|
||||
}
|
||||
|
||||
// check for broadcast address
|
||||
if(array_key_exists($broadcast_address, $subnet)) {
|
||||
// replace
|
||||
$subnet[$broadcast_address] = array("broadcast_address");
|
||||
}
|
||||
|
||||
// loop subnet-array and send to template
|
||||
// start counter
|
||||
$i=1;
|
||||
|
||||
// loop subnet-array
|
||||
foreach($subnet AS $node_ip => $node) {
|
||||
// make new line?
|
||||
if(($i%$_SESSION['suser_imagecount']==0 && $i!=$nodes_displayed) ? $tr="</tr><tr>" : $tr="");
|
||||
|
||||
// check node
|
||||
if(empty($node)) {
|
||||
// empty node to tpl
|
||||
$tp->set("url", 'assigniptonode.php?subnet_id=' . $subnet_id . '&node_ip='. $node_ip);
|
||||
$tp->set("remotetext", $node_ip);
|
||||
$tp->set("assetclassgroup_color", $config_color_unused);
|
||||
} else if ($node[0]=="subnet_address") {
|
||||
// subnet address to tpl
|
||||
$tp->set("url", "");
|
||||
$tp->set("remotetext", $node_ip . ' ' . $lang['lang_subnet_subnetaddress']);
|
||||
$tp->set("assetclassgroup_color", $config_color_blocked);
|
||||
} else if ($node[0]=="broadcast_address") {
|
||||
// broadcast address to tpl
|
||||
$tp->set("url", "");
|
||||
$tp->set("remotetext", $node_ip . ' ' . $lang['lang_subnet_broadcastaddress']);
|
||||
$tp->set("assetclassgroup_color", $config_color_blocked);
|
||||
} else {
|
||||
// node to tpl
|
||||
$tp->set("url", 'nodeview.php?node_id=' . $node['node_id']);
|
||||
$tp->set("remotetext", $node_ip . ' ' . $node['asset_name']);
|
||||
$tp->set("assetclassgroup_color", $node['assetclassgroup_color']);
|
||||
}
|
||||
|
||||
// set other vars
|
||||
$tp->set("tr", $tr);
|
||||
|
||||
// parse block
|
||||
$tp->parse("node_row");
|
||||
|
||||
// update counter
|
||||
$i++;
|
||||
}
|
||||
|
||||
// parse block
|
||||
$tp->parse("node_table");
|
||||
|
||||
// setup vlan
|
||||
// build query
|
||||
$query = "SELECT
|
||||
vlan.vlan_id AS vlan_id,
|
||||
vlan.vlan_name AS vlan_name,
|
||||
vlan.vlan_number AS vlan_number
|
||||
FROM
|
||||
subnetvlan,
|
||||
vlan
|
||||
WHERE
|
||||
subnetvlan.subnet_id=" . $subnet_id . "
|
||||
AND vlan.vlan_id=subnetvlan.vlan_id
|
||||
ORDER BY
|
||||
vlan.vlan_name";
|
||||
|
||||
// run query
|
||||
$vlans = $db->db_select($query);
|
||||
|
||||
// count results
|
||||
$vlan_counter = count($vlans);
|
||||
|
||||
// counter to tpl
|
||||
$tp->set("vlan_counter", $vlan_counter);
|
||||
|
||||
// any nodes?
|
||||
if ($vlan_counter>0) {
|
||||
// get objects
|
||||
foreach($vlans AS $vlan) {
|
||||
// send to tpl
|
||||
$tp->set("vlan_id", $vlan['vlan_id']);
|
||||
$tp->set("vlan_name", $vlan['vlan_name']);
|
||||
$tp->set("vlan_number", $vlan['vlan_number']);
|
||||
|
||||
// parse block
|
||||
$tp->parse("vlan_row");
|
||||
}
|
||||
// parse block
|
||||
$tp->parse("vlan_table");
|
||||
} else {
|
||||
// parse block
|
||||
$tp->hide("vlan_table");
|
||||
}
|
||||
|
||||
// setup location
|
||||
// build query
|
||||
$query = "SELECT
|
||||
location.location_id,
|
||||
location.location_name
|
||||
FROM
|
||||
location
|
||||
LEFT JOIN
|
||||
subnetlocation
|
||||
ON
|
||||
subnetlocation.location_id=location.location_id
|
||||
WHERE
|
||||
subnetlocation.subnet_id=". $subnet_id . "
|
||||
ORDER BY
|
||||
location.location_name";
|
||||
|
||||
// run query
|
||||
$locations = $db->db_select($query);
|
||||
|
||||
// count results
|
||||
$location_counter = count($locations);
|
||||
|
||||
// counter to tpl
|
||||
$tp->set("location_counter", $location_counter);
|
||||
|
||||
// any nodes?
|
||||
if ($location_counter>0) {
|
||||
// get objects
|
||||
foreach($locations AS $location) {
|
||||
// send to tpl
|
||||
$tp->set("location_id", $location['location_id']);
|
||||
$tp->set("location_name", $location['location_name']);
|
||||
|
||||
// parse block
|
||||
$tp->parse("location_row");
|
||||
}
|
||||
// parse block
|
||||
$tp->parse("location_table");
|
||||
} else {
|
||||
// parse block
|
||||
$tp->hide("location_table");
|
||||
}
|
||||
|
||||
// setup assetclassgroup
|
||||
// build query
|
||||
$query = "SELECT
|
||||
assetclassgroup.assetclassgroup_id,
|
||||
assetclassgroup.assetclassgroup_name,
|
||||
assetclassgroup.assetclassgroup_color,
|
||||
(SELECT
|
||||
COUNT(node.node_id)
|
||||
FROM
|
||||
asset,
|
||||
assetclass,
|
||||
node
|
||||
WHERE
|
||||
asset.assetclass_id=assetclass.assetclass_id
|
||||
AND assetclass.assetclassgroup_id=assetclassgroup.assetclassgroup_id
|
||||
AND node.asset_id=asset.asset_id
|
||||
AND node.subnet_id=" . $subnet_id . ") AS node_counter
|
||||
FROM
|
||||
assetclassgroup
|
||||
GROUP BY
|
||||
assetclassgroup.assetclassgroup_id
|
||||
ORDER BY
|
||||
assetclassgroup.assetclassgroup_name";
|
||||
|
||||
// run query
|
||||
$assetclassgroups = $db->db_select($query);
|
||||
|
||||
// count results
|
||||
$assetclassgroup_counter = count($assetclassgroups);
|
||||
|
||||
// counter to tpl
|
||||
$tp->set("assetclassgroup_counter", $assetclassgroup_counter);
|
||||
|
||||
// any nodes?
|
||||
if ($assetclassgroup_counter>0) {
|
||||
// get objects
|
||||
foreach($assetclassgroups AS $assetclassgroup) {
|
||||
// send to tpl
|
||||
$tp->set("assetclassgroup_id", $assetclassgroup['assetclassgroup_id']);
|
||||
$tp->set("assetclassgroup_name", $assetclassgroup['assetclassgroup_name']);
|
||||
$tp->set("assetclassgroup_color", $assetclassgroup['assetclassgroup_color']);
|
||||
|
||||
$tp->set("assetclassgroup_node_counter", $assetclassgroup['node_counter']);
|
||||
|
||||
// parse block
|
||||
$tp->parse("assetclassgroup_row");
|
||||
}
|
||||
// parse block
|
||||
$tp->parse("assetclassgroup_table");
|
||||
} else {
|
||||
// parse block
|
||||
$tp->hide("assetclassgroup_table");
|
||||
}
|
||||
|
||||
// end page
|
||||
// output
|
||||
$tp->parse();
|
||||
$tp->spit();
|
||||
|
||||
// end output
|
||||
include("footer.php");
|
||||
?>
|
||||
<?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
|
||||
$subnet_id = sanitize($_GET['subnet_id']);
|
||||
|
||||
// get page
|
||||
if(isset($_GET['page'])) {
|
||||
$page = sanitize($_GET['page']);
|
||||
}
|
||||
|
||||
// start output
|
||||
$smarty->assign("scripts",'changetext.js');
|
||||
include("header.php");
|
||||
|
||||
// set language variables
|
||||
$smarty->assign($lang);
|
||||
|
||||
// setup subnet
|
||||
// build query
|
||||
$query = "SELECT
|
||||
subnet.subnet_address,
|
||||
subnet.subnet_mask,
|
||||
subnet.subnet_dhcp_start,
|
||||
subnet.subnet_dhcp_end,
|
||||
subnet.subnet_info,
|
||||
subnet.protocol_version,
|
||||
subnet.ntp_server,
|
||||
COUNT(node.subnet_id) AS node_counter
|
||||
FROM
|
||||
subnet
|
||||
LEFT JOIN
|
||||
node
|
||||
ON
|
||||
node.subnet_id=subnet.subnet_id
|
||||
WHERE
|
||||
subnet.subnet_id=" . $subnet_id . "
|
||||
GROUP BY
|
||||
subnet.subnet_id";
|
||||
|
||||
// run query
|
||||
$subnet = $db->db_select($query);
|
||||
|
||||
// set needed variables
|
||||
$subnet_address = $subnet[0]['subnet_address'];
|
||||
$subnet_mask = $subnet[0]['subnet_mask'];
|
||||
$subnet_dhcpstart = $subnet[0]['subnet_dhcp_start'];
|
||||
$subnet_dhcpend = $subnet[0]['subnet_dhcp_end'];
|
||||
$subnet_proto_vers = $subnet[0]['protocol_version'];
|
||||
$subnet_ntp_server = $subnet[0]['ntp_server'];
|
||||
|
||||
// set counters
|
||||
$host_counter = pow(2,(32-$subnet_mask));
|
||||
$node_counter = $subnet[0]['node_counter'];
|
||||
$subnet_usedpercentage = round((($node_counter/($host_counter-2))*100), 1);
|
||||
|
||||
// send to tpl
|
||||
$smarty->assign("subnet_id", $subnet_id);
|
||||
$smarty->assign("subnet_address", $subnet_address);
|
||||
$smarty->assign("subnet_mask", $subnet_mask);
|
||||
$smarty->assign("subnet_dhcpstart", $subnet_dhcpstart);
|
||||
$smarty->assign("subnet_dhcpend", $subnet_dhcpend);
|
||||
$smarty->assign("subnet_info", nl2br($subnet[0]['subnet_info']));
|
||||
$smarty->assign("subnet_proto_vers", $subnet_proto_vers);
|
||||
$smarty->assign("subnet_ntp_server", $subnet_ntp_server);
|
||||
$smarty->assign("node_counter", $node_counter);
|
||||
$smarty->assign("subnet_usedpercentage", $subnet_usedpercentage);
|
||||
$smarty->assign("config_color_unused", $config_color_unused);
|
||||
$smarty->assign("host_counter", $host_counter-2);
|
||||
$smarty->assign("free_counter", (($host_counter-2)-$node_counter));
|
||||
|
||||
// setup subnet
|
||||
// split up the range
|
||||
$iprange = explode('.', $subnet_address);
|
||||
$iprange1 = $iprange[0];
|
||||
$iprange2 = $iprange[1];
|
||||
$iprange3 = $iprange[2];
|
||||
$iprange4 = $iprange[3];
|
||||
|
||||
// create empty subnet-array
|
||||
$subnet = array();
|
||||
|
||||
// determine range (Class A/B/C)
|
||||
if ($subnet_mask>=24) {
|
||||
// Class C
|
||||
// fill subnet-array with addresses we want to see
|
||||
for($i=0;$i<$host_counter;$i++) {
|
||||
// build ip
|
||||
$ip = $iprange1 . '.' . $iprange2 . '.' . $iprange3 . '.' . ($iprange4+$i);
|
||||
|
||||
// fill subnet-array
|
||||
$subnet[$ip] = array();
|
||||
}
|
||||
|
||||
// calculate broadcast address
|
||||
$broadcast_address = $iprange1 . '.' . $iprange2 . '.' . $iprange3 . '.' . ($iprange4+$i-1);
|
||||
|
||||
// to tpl
|
||||
$smarty->assign("iprange1", $iprange1);
|
||||
$smarty->assign("iprange2", $iprange2);
|
||||
$smarty->assign("iprange3", $iprange3);
|
||||
$smarty->assign("iprange4", $iprange4);
|
||||
$smarty->assign("subnetmask1", 255);
|
||||
$smarty->assign("subnetmask2", 255);
|
||||
$smarty->assign("subnetmask3", 255);
|
||||
$smarty->assign("subnetmask4", 256-$host_counter);
|
||||
|
||||
// no pagination needed
|
||||
$smarty->assign("noselect", TRUE);
|
||||
$smarty->assign("one_select", FALSE);
|
||||
$smarty->assign("two_select", FALSE);
|
||||
|
||||
// set displayed nodes
|
||||
$nodes_displayed = $host_counter;
|
||||
} else if ($subnet_mask>=16) {
|
||||
// Class B
|
||||
// which part do we want to see?
|
||||
if((empty($page)) ? $page=$subnet_address : $page=$page);
|
||||
$page = explode('.', $page);
|
||||
$page2 = $page[2];
|
||||
|
||||
// fill subnet-array with addresses we want to see
|
||||
for($i=0;$i<256;$i++) {
|
||||
// build ip
|
||||
$ip = $iprange1 . '.' . $iprange2 . '.' . $page2 . '.' . $i;
|
||||
|
||||
// fill subnet-array
|
||||
$subnet[$ip] = array();
|
||||
}
|
||||
|
||||
// calculate broadcast address
|
||||
$broadcast_address = $iprange1 . '.' . $iprange2 . '.' . ($iprange3+$i-1) . '.255';
|
||||
|
||||
// to tpl
|
||||
$smarty->assign("iprange1", $iprange1);
|
||||
$smarty->assign("iprange2", $iprange2);
|
||||
|
||||
// loop addresses in range3
|
||||
for($i=$iprange3;$i<(pow(2,(32-$subnet_mask))/256);$i++) {
|
||||
// send to tpl
|
||||
$smarty->assign("iprange3", $i);
|
||||
$smarty->assign("iprange4", 0);
|
||||
|
||||
// set select box
|
||||
if($i==$page2) {
|
||||
$smarty->assign("row_selected", "selected");
|
||||
|
||||
} else {
|
||||
$smarty->assign("row_selected", "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$smarty->assign("subnetmask1", 255);
|
||||
$smarty->assign("subnetmask2", 255);
|
||||
$smarty->assign("subnetmask3", 256-($host_counter/256));
|
||||
$smarty->assign("subnetmask4", 0);
|
||||
|
||||
// one select box
|
||||
$smarty->assign("noselect", FALSE);
|
||||
$smarty->assign("one_select", TRUE);
|
||||
$smarty->assign("two_select", FALSE);
|
||||
|
||||
// set displayed nodes
|
||||
$nodes_displayed = 256;
|
||||
} else {
|
||||
// Class A
|
||||
// which part do we want to see?
|
||||
if((empty($page)) ? $page=$subnet_address : $page=$page);
|
||||
$page = explode('.', $page);
|
||||
$page2 = $page[1];
|
||||
$page3 = $page[2];
|
||||
|
||||
// fill subnet-array with addresses we want to see
|
||||
for($i=0;$i<256;$i++) {
|
||||
// build ip
|
||||
$ip = $iprange1 . '.' . $page2 . '.' . $page3 . '.' . $i;
|
||||
|
||||
// fill subnet-array
|
||||
$subnet[$ip] = array();
|
||||
}
|
||||
|
||||
// calculate broadcast address
|
||||
$broadcast_address = $iprange1 . '.' . ($iprange2+$i-1) . '.255.255';
|
||||
|
||||
// to tpl
|
||||
$smarty->assign("iprange1", $iprange1);
|
||||
$smarty->assign("iprange2", $iprange2);
|
||||
|
||||
// loop addresses in range 2
|
||||
for($i=$iprange2;$i<(pow(2,(24-$subnet_mask))/256);$i++) {
|
||||
// send to tpl
|
||||
$smarty->assign("iprange1", $iprange1);
|
||||
$smarty->assign("iprange2", $i);
|
||||
$smarty->assign("iprange3", $page3);
|
||||
$smarty->assign("iprange4", $iprange4);
|
||||
|
||||
// set select box
|
||||
if($i==$page2) {
|
||||
$smarty->assign("row1_selected", "selected");
|
||||
|
||||
} else {
|
||||
$smarty->assign("row1_selected", "");
|
||||
}
|
||||
|
||||
// parse block
|
||||
$tp->parse("two_select_row1");
|
||||
}
|
||||
|
||||
// loop addresses in range 3
|
||||
for($i=0;$i<256;$i++) {
|
||||
// send to tpl
|
||||
$smarty->assign("iprange1", $iprange1);
|
||||
$smarty->assign("iprange2", $page2);
|
||||
$smarty->assign("iprange3", $i);
|
||||
$smarty->assign("iprange4", $iprange4);
|
||||
|
||||
// set select box
|
||||
if($i==$page3) {
|
||||
$smarty->assign("row2_selected", "selected");
|
||||
|
||||
} else {
|
||||
$smarty->assign("row2_selected", "");
|
||||
}
|
||||
|
||||
// parse block
|
||||
$tp->parse("two_select_row2");
|
||||
}
|
||||
|
||||
$smarty->assign("subnetmask1", 255);
|
||||
$smarty->assign("subnetmask2", 256-($host_counter/65536));
|
||||
$smarty->assign("subnetmask3", 0);
|
||||
$smarty->assign("subnetmask4", 0);
|
||||
|
||||
// one select box
|
||||
$smarty->assign("noselect", FALSE);
|
||||
$smarty->assign("one_select", FALSE);
|
||||
$smarty->assign("two_select", TRUE);
|
||||
|
||||
// set displayed nodes
|
||||
$nodes_displayed = 256;
|
||||
}
|
||||
|
||||
// get nodes for this subnetview and implement the values into the array
|
||||
// build query
|
||||
$query = "SELECT
|
||||
asset.asset_name,
|
||||
assetclassgroup.assetclassgroup_color,
|
||||
node.node_id,
|
||||
node.node_ip
|
||||
FROM
|
||||
asset,
|
||||
assetclass,
|
||||
assetclassgroup,
|
||||
node
|
||||
WHERE
|
||||
node.node_ip IN ('".implode("','",array_keys($subnet))."')
|
||||
AND node.subnet_id='$subnet_id'
|
||||
AND asset.asset_id=node.asset_id
|
||||
AND assetclass.assetclass_id=asset.assetclass_id
|
||||
AND assetclassgroup.assetclassgroup_id=assetclass.assetclassgroup_id";
|
||||
|
||||
// run query
|
||||
$nodes = $db->db_select($query);
|
||||
|
||||
// count results
|
||||
$node_counter = count($nodes);
|
||||
|
||||
// any nodes?
|
||||
if ($node_counter>0) {
|
||||
// get objects
|
||||
foreach($nodes AS $node) {
|
||||
// add node-values to ip in subnet-array
|
||||
$subnet[$node['node_ip']] = $node;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// replace ip's in subnet-array (if necessary)
|
||||
// check for subnet address
|
||||
if(array_key_exists($subnet_address, $subnet)) {
|
||||
// replace
|
||||
$subnet[$subnet_address] = array("subnet_address");
|
||||
}
|
||||
|
||||
// check for broadcast address
|
||||
if(array_key_exists($broadcast_address, $subnet)) {
|
||||
// replace
|
||||
$subnet[$broadcast_address] = array("broadcast_address");
|
||||
}
|
||||
|
||||
$dhcpstart = 0;
|
||||
if ($subnet_dhcpstart && $subnet_dhcpend) {
|
||||
$dhcpstart = ip2long($subnet_dhcpstart);
|
||||
$dhcpend = ip2long($subnet_dhcpend);
|
||||
}
|
||||
|
||||
// loop subnet-array and send to template
|
||||
// start counter
|
||||
// $i=1;
|
||||
// loop subnet-array
|
||||
foreach($subnet AS $node_ip => $node) {
|
||||
|
||||
// make new line?
|
||||
// if(($i%$_SESSION['suser_imagecount']==0 && $i!=$nodes_displayed) ? $tr="</tr><tr>" : $tr="");
|
||||
|
||||
// check if node-ip in DHCP-area
|
||||
$subnet[$node_ip]["dynamic"] = False;
|
||||
if ($dhcpstart > 0) {
|
||||
$ipval = ip2long($node_ip);
|
||||
if (($ipval >= $dhcpstart) and ($ipval <= $dhcpend)) {
|
||||
$subnet[$node_ip]["dynamic"] = True;
|
||||
}
|
||||
}
|
||||
|
||||
// check node
|
||||
if (empty($node)) {
|
||||
// empty node to tpl
|
||||
$subnet[$node_ip]["url"] = 'assigniptonode.php?subnet_id=' . $subnet_id . '&node_ip='. $node_ip;
|
||||
$subnet[$node_ip]["remotetext"] = $node_ip;
|
||||
if ($subnet[$node_ip]["dynamic"]) {
|
||||
$subnet[$node_ip]["assetclassgroup_color"] = $config_color_dynamic;
|
||||
} else {
|
||||
$subnet[$node_ip]["assetclassgroup_color"] = $config_color_unused;
|
||||
}
|
||||
|
||||
} else if (array_key_exists(0, $node) && $node[0]=="subnet_address") {
|
||||
// subnet address to tpl
|
||||
$subnet[$node_ip]["url"] = "";
|
||||
$subnet[$node_ip]["remotetext"] = $node_ip . ' ' . $lang['lang_subnet_subnetaddress'];
|
||||
$subnet[$node_ip]["assetclassgroup_color"] = $config_color_blocked;
|
||||
} else if (array_key_exists(0, $node) && $node[0]=="broadcast_address") {
|
||||
// broadcast address to tpl
|
||||
$subnet[$node_ip]["url"] = "";
|
||||
$subnet[$node_ip]["remotetext"] = $node_ip . ' ' . $lang['lang_subnet_broadcastaddress'];
|
||||
$subnet[$node_ip]["assetclassgroup_color"] = $config_color_blocked;
|
||||
} else {
|
||||
// node to tpl
|
||||
$subnet[$node_ip]["url"] = 'nodeview.php?node_id=' . $node['node_id'];
|
||||
$subnet[$node_ip]["remotetext"] = $node_ip . ' ' . $node['asset_name'];
|
||||
$subnet[$node_ip]["assetclassgroup_color"] = $node['assetclassgroup_color'];
|
||||
}
|
||||
|
||||
|
||||
// update counter
|
||||
// $i++;
|
||||
}
|
||||
|
||||
$smarty->assign("subnet", $subnet);
|
||||
$smarty->assign("imagewrap", $_SESSION['suser_imagecount']);
|
||||
|
||||
// setup vlan
|
||||
// build query
|
||||
$query = "SELECT
|
||||
vlan.vlan_id AS vlan_id,
|
||||
vlan.vlan_name AS vlan_name,
|
||||
vlan.vlan_number AS vlan_number
|
||||
FROM
|
||||
subnetvlan,
|
||||
vlan
|
||||
WHERE
|
||||
subnetvlan.subnet_id=" . $subnet_id . "
|
||||
AND vlan.vlan_id=subnetvlan.vlan_id
|
||||
ORDER BY
|
||||
vlan.vlan_name";
|
||||
|
||||
// run query
|
||||
$vlans = $db->db_select($query);
|
||||
$smarty->assign("vlans", $vlans);
|
||||
|
||||
// setup location
|
||||
// build query
|
||||
$query = "SELECT
|
||||
location.location_id,
|
||||
location.location_name
|
||||
FROM
|
||||
location
|
||||
LEFT JOIN
|
||||
subnetlocation
|
||||
ON
|
||||
subnetlocation.location_id=location.location_id
|
||||
WHERE
|
||||
subnetlocation.subnet_id=". $subnet_id . "
|
||||
ORDER BY
|
||||
location.location_name";
|
||||
|
||||
// run query
|
||||
$locations = $db->db_select($query);
|
||||
$smarty->assign("locations", $locations);
|
||||
|
||||
// setup assetclassgroup
|
||||
// build query
|
||||
$query = "SELECT
|
||||
assetclassgroup_id AS id,
|
||||
assetclassgroup_name AS name,
|
||||
assetclassgroup_color AS color,
|
||||
COUNT(assetclass_id) AS counter
|
||||
FROM subnet
|
||||
LEFT JOIN node USING (subnet_id)
|
||||
LEFT JOIN asset USING (asset_id)
|
||||
LEFT JOIN assetclass USING (assetclass_id)
|
||||
LEFT JOIN assetclassgroup USING (assetclassgroup_id)
|
||||
WHERE subnet_id=" . $subnet_id . "
|
||||
GROUP BY assetclass_id
|
||||
ORDER BY counter DESC";
|
||||
|
||||
// run query
|
||||
$assetclassgroups = $db->db_select($query);
|
||||
$smarty->assign("assetclassgroups", $assetclassgroups);
|
||||
|
||||
// end page
|
||||
// output
|
||||
$smarty->display("subnetview.tpl");
|
||||
|
||||
// end output
|
||||
include("footer.php");
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user