Make use of Yapter Template Engine
This commit is contained in:
399
subnetview.php
399
subnetview.php
@@ -1,229 +1,216 @@
|
||||
<?php
|
||||
include("header.php");
|
||||
|
||||
// get id
|
||||
$subnet_id = $_GET['subnet_id'];
|
||||
|
||||
// get page
|
||||
if(isset($_GET['page'])) {
|
||||
$page = $_GET['page'];
|
||||
} else {
|
||||
$page = 0;
|
||||
}
|
||||
?>
|
||||
|
||||
<script language="javascript">
|
||||
function linkTo(optVal){
|
||||
if(optVal=="")
|
||||
return false;
|
||||
window.location='subnetview.php?subnet_id='+optVal;
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
function change(id,newtext) {
|
||||
document.getElementById(id).innerHTML=newtext
|
||||
}
|
||||
</script>
|
||||
|
||||
<?php
|
||||
// get all info
|
||||
$result = mysql_query("SELECT subnet_address, subnet_mask, vlan_id, subnet_info FROM subnet WHERE subnet_id='$subnet_id'");
|
||||
while ($row = mysql_fetch_object($result)) {
|
||||
$subnet_address = $row->subnet_address;
|
||||
$subnet_mask = $row->subnet_mask;
|
||||
$vlan_id = $row->vlan_id;
|
||||
$subnet_info = $row->subnet_info;
|
||||
}
|
||||
|
||||
// determine current range
|
||||
// set template
|
||||
$tp = new Template("tpl/subnetview.tpl");
|
||||
|
||||
// set language variables
|
||||
$tp->setvars($lang);
|
||||
|
||||
// get subnet info
|
||||
$result = mysql_query("SELECT subnet_address, subnet_mask, vlan_id, subnet_info FROM subnet WHERE subnet_id='$subnet_id'") or die(mysql_error());
|
||||
$row = mysql_fetch_object($result);
|
||||
$tp->set("subnet_id", $subnet_id);
|
||||
$tp->set("subnet_address", $row->subnet_address);
|
||||
$tp->set("subnet_mask", $row->subnet_mask);
|
||||
$tp->set("subnet_info", nl2br($row->subnet_info));
|
||||
|
||||
// set needed variables
|
||||
$subnet_address = $row->subnet_address;
|
||||
$subnet_mask = $row->subnet_mask;
|
||||
$vlan_id = $row->vlan_id;
|
||||
|
||||
// split up the range
|
||||
$iprange = explode('.', $subnet_address);
|
||||
$iprange1 = $iprange[0];
|
||||
$iprange2 = $iprange[1];
|
||||
$iprange3 = $iprange[2];
|
||||
$iprange4 = $iprange[3];
|
||||
|
||||
// calculate no. of hosts
|
||||
$hostcount = pow(2,(32-$subnet_mask));
|
||||
|
||||
// is there a need for pagination?
|
||||
if ($hostcount>256) {
|
||||
$maxdisplayedip = 256;
|
||||
// create array for these addresses
|
||||
$subnet = array();
|
||||
if ($subnet_mask>=24) {
|
||||
// Class C
|
||||
// calculate hosts
|
||||
$hostcount = pow(2,(32-$subnet_mask));
|
||||
|
||||
// calculate broadcast address and create pagination
|
||||
if ($hostcount>65536) {
|
||||
// class A subnet
|
||||
echo 'Class A subnets (>65536 nodes) are not supported';
|
||||
exit;
|
||||
} else {
|
||||
// class B subnet
|
||||
$broadcast_address = $iprange1 . '.' . $iprange2 . '.' . ($hostcount/256-1) . '.255';
|
||||
|
||||
$pagination = 'Page: <select name="pagination" onchange="linkTo(this.options[this.selectedIndex].value);">';
|
||||
for ($i=0;$i<($hostcount/256);$i++) {
|
||||
if ($i==$page) {
|
||||
$selected = ' selected';
|
||||
} else {
|
||||
$selected = '';
|
||||
}
|
||||
$pagination .= '<option value="' . $subnet_id . '&page=' . $i . '"' . $selected . '>' . $iprange1 . '.' . $iprange2 . '.' . ($i) . '.0</option>';
|
||||
}
|
||||
$pagination .= '</select>';
|
||||
// fill array with addresses we want to see
|
||||
for($i=0;$i<$hostcount;$i++) {
|
||||
$ip = $iprange1 . '.' . $iprange2 . '.' . $iprange3 . '.' . ($iprange4+$i);
|
||||
$subnet[$ip] = array();
|
||||
}
|
||||
|
||||
// calculate broadcast address
|
||||
$broadcast_address = $iprange1 . '.' . $iprange2 . '.' . $iprange3 . '.' . ($iprange4+$i-1);
|
||||
|
||||
// no pagination needed
|
||||
$tp->set("pagination", ' ');
|
||||
} 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 array with addresses we want to see
|
||||
for($i=0;$i<256;$i++) {
|
||||
$ip = $iprange1 . '.' . $iprange2 . '.' . $page2 . '.' . $i;
|
||||
$subnet[$ip] = array();
|
||||
}
|
||||
|
||||
// calculate broadcast address
|
||||
$broadcast_address = $iprange1 . '.' . $iprange2 . '.' . ($iprange3+$i-1) . '.255';
|
||||
|
||||
// create pagination
|
||||
$pagination = 'Page: ' . $iprange1 . '.' . $iprange2 . '. ';
|
||||
$pagination .= '<select name="pagination" onchange="linkTo(this.options[this.selectedIndex].value);">';
|
||||
for($i=$iprange3;$i<(pow(2,(32-$subnet_mask))/256);$i++) {
|
||||
if(($i==$page2) ? $selected='selected' : $selected='');
|
||||
$pagination .= '<option value="' . $subnet_id . '&page=' . $iprange1 . '.' . $iprange2 . '.' . $i . '.0"' . $selected . '>' . $i . '.0</option>';
|
||||
}
|
||||
$pagination .= '</select>';
|
||||
$tp->set("pagination", $pagination);
|
||||
} else {
|
||||
// // class C subnet so no pagination needed, set static variables
|
||||
$pagination = ' ';
|
||||
$page = 0;
|
||||
$maxdisplayedip = $hostcount;
|
||||
$broadcast_address = $iprange1 . '.' . $iprange2 . '.' . $iprange3 . '.' . ($iprange4+$hostcount-1);
|
||||
}
|
||||
?>
|
||||
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td colspan="32">
|
||||
<b>Subnet: </b><?php echo $subnet_address . '/'. $subnet_mask; ?>
|
||||
</td>
|
||||
<td colspan="32" align="right">
|
||||
<?php echo $pagination; ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
echo '<tr>';
|
||||
// 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];
|
||||
|
||||
for ($i=1;$i<=$maxdisplayedip;$i++) {
|
||||
// build current ip
|
||||
$ip = $iprange1 . '.' . $iprange2 . '.' . ($iprange3+$page) . '.' . ($i+$iprange4-1);
|
||||
|
||||
// disable subnet_address and broadcast_address
|
||||
if ($ip==$subnet_address) {
|
||||
echo '<td><img src="images/cross.jpg" onMouseOver="change(\'remotetext\',\'' . $ip . ' (Subnet address)\')" onMouseOut="change(\'remotetext\',\' \')"></td>';
|
||||
} else if ($ip==$broadcast_address) {
|
||||
echo '<td><img src="images/cross.jpg" onMouseOver="change(\'remotetext\',\'' . $ip . ' (Broadcast address)\')" onMouseOut="change(\'remotetext\',\' \')"></td>';
|
||||
} else {
|
||||
// check for current ip address
|
||||
$result = mysql_query("SELECT a.asset_name, acg.color, n.node_id FROM asset a, assetclass ac, assetclassgroup acg, node n WHERE n.ip='$ip' AND a.asset_id=n.asset_id AND ac.assetclass_id=a.assetclass_id AND acg.assetclassgroup_id=ac.assetclassgroup_id");
|
||||
if (mysql_num_rows($result)==0) {
|
||||
// ip not in use
|
||||
echo '<td><a href="assigniptonode.php?ip='. $ip . '&subnet_id=' . $subnet_id . '"><img src="images/grey.jpg" border="0" onMouseOver="change(\'remotetext\',\'' . $ip . '\')" onMouseOut="change(\'remotetext\',\' \')"></a></td>';
|
||||
} else {
|
||||
// ip in use
|
||||
while ($row = mysql_fetch_object($result)) {
|
||||
$node_id = $row->node_id;
|
||||
echo '<td><a href="nodeview.php?node_id=' . $node_id . '"><img src="images/' . $row->color . '.jpg" border="0" onMouseOver="change(\'remotetext\',\'' . $ip . ' ' . $row->asset_name . '\')" onMouseOut="change(\'remotetext\',\' \')"></a></td>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($i%64==0) {
|
||||
echo '</tr><tr>';
|
||||
}
|
||||
// fill array with addresses we want to see
|
||||
for($i=0;$i<256;$i++) {
|
||||
$ip = $iprange1 . '.' . $page2 . '.' . $page3 . '.' . $i;
|
||||
$subnet[$ip] = array();
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td colspan="64">
|
||||
<a id="remotetext"> </a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td>
|
||||
<b>VLAN(s):</b>
|
||||
</td>
|
||||
<td>
|
||||
|
||||
<?php
|
||||
// search vlan(s) for this subnet
|
||||
$result = mysql_query("SELECT vlan_id, vlan_number, vlan_name FROM vlan WHERE vlan_id='$vlan_id'");
|
||||
while ($row = mysql_fetch_object($result)) {
|
||||
echo '<a href="vlanview.php?vlan_id=' . $row->vlan_id . '">' . $row->vlan_name . ' ('. $row->vlan_number . ')</a>';
|
||||
}
|
||||
?>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<b>Location(s):</b>
|
||||
</td>
|
||||
<td>
|
||||
|
||||
<?php
|
||||
// search location(s) for this subnet
|
||||
$result = mysql_query("SELECT l.location_id FROM location l INNER JOIN subnetlocation sl ON l.location_id=sl.location_id WHERE sl.subnet_id='$subnet_id'");
|
||||
while ($row = mysql_fetch_object($result)) {
|
||||
echo location_name($row->location_id, '') . '<br>';
|
||||
}
|
||||
?>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<b>Subnet info:</b>
|
||||
</td>
|
||||
<td>
|
||||
<?php echo nl2br($subnet_info); ?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
<td width="100">
|
||||
|
||||
</td>
|
||||
<td>
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td>
|
||||
<img src="images/grey.jpg"> Unassigned
|
||||
</td>
|
||||
</tr>
|
||||
</tr>
|
||||
<?php
|
||||
// display assetclass(es)
|
||||
$result = mysql_query("SELECT assetclassgroup_id, assetclassgroup_name, color FROM assetclassgroup ORDER BY assetclassgroup_id");
|
||||
while ($row = mysql_fetch_object($result)) {
|
||||
echo '<tr><td><img src="images/' . $row->color . '.jpg"> <a href="assetclassgroupview.php?assetclassgroup_id=' . $row->assetclassgroup_id . '">' . $row->assetclassgroup_name . '</a></td></tr>';
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p>
|
||||
|
||||
<?php
|
||||
// display only if admin
|
||||
if($_SESSION['suser_level'] >= 2) {
|
||||
?>
|
||||
|
||||
<table border="0">
|
||||
<tr>
|
||||
<td>
|
||||
<img src="images/arrow.gif" border="0"><a href="subnetedit.php?subnet_id=<?php echo $subnet_id; ?>">Modify subnet</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<img src="images/arrow.gif" border="0"><a href="assignsubnettolocation.php?subnet_id=<?php echo $subnet_id; ?>">Assign location</a>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
// end display only if admin
|
||||
|
||||
// calculate broadcast address
|
||||
$broadcast_address = $iprange1 . '.' . ($iprange+$i-1) . '.255.255';
|
||||
|
||||
// create pagination
|
||||
$pagination = 'Page: ';
|
||||
// selectbox 1
|
||||
$pagination .= '<select name="pagination" onchange="linkTo(this.options[this.selectedIndex].value);">';
|
||||
for($i=$iprange2;$i<(pow(2,(24-$subnet_mask))/256);$i++) {
|
||||
if(($i==$page2) ? $selected='selected' : $selected='');
|
||||
$pagination .= '<option value="' . $subnet_id . '&page=' . $iprange1 . '.' . $i . '.' . $page3 . '.0"' . $selected . '>' . $iprange1 . '.' . $i . '</option>';
|
||||
}
|
||||
$pagination .= '</select><select name="pagination" onchange="linkTo(this.options[this.selectedIndex].value);">';
|
||||
// selectbox 2
|
||||
for($i=0;$i<256;$i++) {
|
||||
if(($i==$page3) ? $selected='selected' : $selected='');
|
||||
$pagination .= '<option value="' . $subnet_id . '&page=' . $iprange1 . '.' . $page2 . '.' . $i . '.0"' . $selected . '>' . $i . '.0</option>';
|
||||
}
|
||||
$pagination .= '</select>';
|
||||
$tp->set("pagination", $pagination);
|
||||
}
|
||||
?>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<img src="images/arrow.gif" border="0"><a href="nodelist.php?subnet_id=<?php echo $subnet_id; ?>">View assigned IP addresses in subnet</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
// get nodes for this subnet and implement the values into the array
|
||||
$result = mysql_query("SELECT a.asset_name, acg.color, n.node_id, n.ip FROM asset a, assetclass ac, assetclassgroup acg, node n WHERE n.ip IN ('".implode("','",array_keys($subnet))."') AND n.subnet_id='$subnet_id' AND a.asset_id=n.asset_id AND ac.assetclass_id=a.assetclass_id AND acg.assetclassgroup_id=ac.assetclassgroup_id") or die(mysql_error());
|
||||
while ($row = mysql_fetch_array($result)) {
|
||||
$subnet[$row['ip']] = $row;
|
||||
}
|
||||
|
||||
// replace subnet address (if in array)
|
||||
if(array_key_exists($subnet_address, $subnet)) {
|
||||
$subnet[$subnet_address]=array("subnet_address");
|
||||
}
|
||||
|
||||
// replace broadcast address (if in array)
|
||||
if(array_key_exists($broadcast_address, $subnet)) {
|
||||
$subnet[$broadcast_address]=array("broadcast_address");
|
||||
}
|
||||
|
||||
// loop array and send to template
|
||||
$i=1;
|
||||
foreach($subnet as $ip => $node) {
|
||||
if(($i%64==0) ? $tr="</tr><tr>" : $tr="");
|
||||
if(empty($node)) {
|
||||
$tp->set("url", 'assigniptonode.php?subnet_id=' . $subnet_id . '&ip='. $ip);
|
||||
$tp->set("remotetext", $ip);
|
||||
$tp->set("color", 'grey');
|
||||
} else if ($node[0]=="subnet_address") {
|
||||
$tp->set("url", "");
|
||||
$tp->set("remotetext", $ip . ' ' . $lang['lang_subnet_subnetaddress']);
|
||||
$tp->set("color", 'cross');
|
||||
} else if ($node[0]=="broadcast_address") {
|
||||
$tp->set("url", "");
|
||||
$tp->set("remotetext", $ip . ' ' . $lang['lang_subnet_broadcastaddress']);
|
||||
$tp->set("color", 'cross');
|
||||
} else {
|
||||
$tp->set("url", 'nodeview.php?node_id=' . $node['node_id']);
|
||||
$tp->set("remotetext", $ip . ' ' . $node['asset_name']);
|
||||
$tp->set("color", $node['color']);
|
||||
}
|
||||
$tp->set("tr", $tr);
|
||||
$tp->parse("iprow");
|
||||
$i++;
|
||||
}
|
||||
$tp->parse("subnet");
|
||||
|
||||
|
||||
// get vlan info
|
||||
$result = mysql_query("SELECT vlan_id, vlan_number, vlan_name FROM vlan WHERE vlan_id='$vlan_id'") or die(mysql_error());
|
||||
for ($i=0;$row=mysql_fetch_object($result);$i++) {
|
||||
$tp->set("vlan_id", $row->vlan_id);
|
||||
$tp->set("vlan_name", $row->vlan_name);
|
||||
$tp->parse("vlanrow");
|
||||
}
|
||||
if (($i>0) ? $tp->parse("vlan") : $tp->hide("vlan"));
|
||||
|
||||
// get location info
|
||||
$result = mysql_query("SELECT l.location_id, l.location_name FROM location l INNER JOIN subnetlocation sl ON l.location_id=sl.location_id WHERE sl.subnet_id='$subnet_id'") or die(mysql_error());
|
||||
for ($i=0;$row=mysql_fetch_object($result);$i++) {
|
||||
$tp->set("location_id", $row->location_id);
|
||||
$tp->set("location_name", $row->location_name);
|
||||
$tp->parse("locationrow");
|
||||
}
|
||||
if (($i>0) ? $tp->parse("location") : $tp->hide("location"));
|
||||
|
||||
// get assetclass info
|
||||
$result = mysql_query("SELECT assetclassgroup_id, assetclassgroup_name, color FROM assetclassgroup ORDER BY assetclassgroup_id") or die(mysql_error());
|
||||
for ($i=0;$row=mysql_fetch_object($result);$i++) {
|
||||
$tp->set("assetclassgroup_id", $row->assetclassgroup_id);
|
||||
$tp->set("assetclassgroup_name", $row->assetclassgroup_name);
|
||||
$tp->set("color", $row->color);
|
||||
$tp->parse("assetclassgrouprow");
|
||||
}
|
||||
if (($i>0) ? $tp->parse("assetclassgroup") : $tp->hide("assetclassgroup"));
|
||||
|
||||
// display options
|
||||
if($_SESSION['suser_level'] >= $config_userlevel_assignlocationtosubnet) {
|
||||
$tp->parse("assignlocationtosubnet");
|
||||
} else {
|
||||
$tp->hide("assignlocationtosubnet");
|
||||
}
|
||||
if($_SESSION['suser_level'] >= $config_userlevel_assignvlantosubnet) {
|
||||
$tp->set("vlan_id", $vlan_id);
|
||||
$tp->parse("assignvlantosubnet");
|
||||
} else {
|
||||
$tp->hide("assignvlantosubnet");
|
||||
}
|
||||
if($_SESSION['suser_level'] >= $config_userlevel_subnetedit) {
|
||||
$tp->parse("subnetedit");
|
||||
} else {
|
||||
$tp->hide("subnetedit");
|
||||
}
|
||||
if($_SESSION['suser_level'] >= $config_userlevel_subnetdel) {
|
||||
$tp->parse("subnetdel");
|
||||
} else {
|
||||
$tp->hide("subnetdel");
|
||||
}
|
||||
|
||||
// output
|
||||
$tp->parse();
|
||||
$tp->spit();
|
||||
|
||||
include("footer.php");
|
||||
?>
|
||||
Reference in New Issue
Block a user