. For more information, visit http://sourceforge.net/projects/ipreg, or contact me at wietsew@users.sourceforge.net *****************************************************************************/ // includes include("includes.php"); // get id $subnet_id = $_GET['subnet_id']; // check authorisation $auth = auth("subnet", $config_auth_subnetview, $subnet_id); // start output include("header.php"); // get page if(isset($_GET['page'])) { $page = $_GET['page']; } // 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]; // create array for these addresses $subnet = array(); if ($subnet_mask>=24) { // Class C // calculate hosts $hostcount = pow(2,(32-$subnet_mask)); // 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 .= ''; $tp->set("pagination", $pagination); } 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 array with addresses we want to see for($i=0;$i<256;$i++) { $ip = $iprange1 . '.' . $page2 . '.' . $page3 . '.' . $i; $subnet[$ip] = array(); } // calculate broadcast address $broadcast_address = $iprange1 . '.' . ($iprange+$i-1) . '.255.255'; // create pagination $pagination = 'Page: '; // selectbox 1 $pagination .= ''; $tp->set("pagination", $pagination); } // 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="