assign("scripts",'changetext.js'); include("header.php"); // subnet $sql = "SELECT s.subnet_id AS id, s.subnet_address AS address, s.subnet_mask AS mask, s.subnet_dhcp_start AS dhcp_start, s.subnet_dhcp_end AS dhcp_end, s.subnet_info AS info, s.protocol_version AS proto_vers, s.ntp_server, COUNT(node.subnet_id) AS node_counter FROM subnet AS s LEFT JOIN node USING (subnet_id) WHERE s.subnet_id=? GROUP BY s.subnet_id"; $sth = $dbh->prepare($sql); $sth->execute([$subnet_id]); $subnet = $sth->fetch(PDO::FETCH_OBJ); $smarty->assign("subnet", $subnet); // set counters $host_counter = pow(2, (32-$subnet->mask)); $node_counter = $subnet->node_counter; $subnet_usedpercentage = round((($node_counter/($host_counter-2))*100), 1); $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)); // 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 $subnetdata = 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 $subnetdata[$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 $subnetdata[$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 $subnetdata[$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", ""); } } // 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", ""); } } $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 $sql = "SELECT a.asset_name, g.assetclassgroup_color, n.node_id, n.node_ip FROM asset AS a, assetclass AS c, assetclassgroup AS g, node AS n WHERE n.node_ip IN ('".implode("','",array_keys($subnetdata))."') AND n.subnet_id=? AND a.asset_id=n.asset_id AND c.assetclass_id=a.assetclass_id AND g.assetclassgroup_id=c.assetclassgroup_id"; $sth = $dbh->prepare($sql); $sth->execute([$subnet_id]); $nodes = $sth->fetchAll(); $smarty->assign("nodes", $nodes); if (count($nodes) > 0) { foreach ($nodes AS $node) { $subnetdata[$node['node_ip']] = $node; } } // replace ip's in subnet-array (if necessary) // check for subnet address if (array_key_exists($subnet->address, $subnet)) { // replace $subnetdata[$subnet->address] = array("subnet_address"); } // check for broadcast address if (array_key_exists($broadcast_address, $subnet)) { // replace $subnetdata[$broadcast_address] = array("broadcast_address"); } $dhcpstart = 0; if ($subnet->dhcp_start && $subnet->dhcp_end) { $dhcpstart = ip2long($subnet->dhcp_start); $dhcpend = ip2long($subnet->dhcp_end); } // loop subnet-array and send to template // start counter // $i=1; // loop subnet-array foreach ($subnetdata AS $node_ip => $node) { // make new line? // if(($i%$_SESSION['suser_imagecount']==0 && $i!=$nodes_displayed) ? $tr="