function display_report($ip_manager, $arr = array(), $search_str = "") { $ip_fam = 4; if (isset($_GET['report'])) { $ip_fam = $_GET['report']; } $all_ip = $arr; $free = 0; $reserved = 0; $assigned = 0; $allstats = 0; $totalspace = "0"; $limit = 0; foreach ($all_ip as $n_ip => $n_name) { if (!IP_Database::is_parent($n_ip)) { $t_ip = new IP_Database($n_ip); $allstats++; $ip_manager->set_IP($t_ip->get_address_ip(), $ip_fam); switch ($t_ip->get_status()) { case "FREE": $free = bcadd($ip_manager->get_ipPerNet(), $free); break; case "RESERVED": $reserved = bcadd($ip_manager->get_ipPerNet(), $reserved); break; case "ASSIGNED": $assigned = bcadd($ip_manager->get_ipPerNet(), $assigned); break; } $totalspace = bcadd($ip_manager->get_ipPerNet(), $totalspace); } } $limit = strlen($totalspace) - 10; if ($limit < 10) { $limit = 0; } //set the default column $form = new Form("auto", 2); $temp_space = explode(".", $totalspace); $totalspace = $temp_space[0]; if ($totalspace == 0) { $divisor = 1; } else { $divisor = $totalspace; } //their calories and locations correspondingly $num_slash = ""; if ($_GET['report'] == 6) { $num_slash = "Number of /48s"; $data_slash = bcdiv($totalspace, bcpow(2, 80), 2); $num_slash2 = "Number of /64s"; $data_slash2 = bcdiv($totalspace, bcpow(2, 64), 2); //create the headings for these if ($search_str != "") { $search_str = " for " . $search_str; } $heading = array("IPV6 Report" . $search_str); $free = bcdiv($free, bcpow(10, $limit), 2); $assigned = bcdiv($assigned, bcpow(10, $limit), 2); $reserved = bcdiv($reserved, bcpow(10, $limit), 2); $divisor = bcdiv($divisor, bcpow(10, $limit), 2); if ($divisor == 0) { $divisor = 1; } $titles = array("Number of IPs", $num_slash, $num_slash2, "Percent of free IPs", "Percent of assigned IPs", "Percent of reserved IPs"); $data = array(number_format($totalspace) . " IPs in " . number_format($allstats) . " Networks", number_format($data_slash), number_format($data_slash2), bcmul(bcdiv($free, $divisor, 5), 100, 2) . "%", bcmul(bcdiv($assigned, $divisor, 5), 100, 2) . "%", bcmul(bcdiv($reserved, $divisor, 5), 100, 2) . "%"); } else { if ($_GET['report'] == 4 || !isset($_GET['report'])) { $num_slash = "Number of /24s"; $data_slash = bcdiv($totalspace, 256, 2); //create the headings for these if ($search_str != "") { $search_str = " for " . $search_str; } $heading = array("IPV4 Report" . $search_str); $titles = array("Number of IPs", $num_slash, "Percent of free IPs", "Percent of assigned IPs", "Percent of reserved IPs"); $data = array(number_format($totalspace) . " IPs in " . number_format($allstats) . " Networks", number_format($data_slash), bcmul(bcdiv($free, $divisor, 5), 100, 2) . "%", bcmul(bcdiv($assigned, $divisor, 5), 100, 2) . "%", bcmul(bcdiv($reserved, $divisor, 5), 100, 2) . "%"); } } $form->setSortable(false); // or false for not sortable $form->setTitles($titles); $form->setHeadings($heading); $form->setData($data); //set the table size $form->setTableWidth("600px"); $form->setTitleWidth("20%"); echo $form->showForm(); $chart_arr = array(free => $free, assigned => $assigned, reserved => $reserved); print report_chart($chart_arr); }
function remove($force = false) { //test mandatory fields if (!is_numeric($this->netblock_id)) { print "NO id"; exit; } if ($force == true) { $query = "DELETE FROM ipmanager_netblocks WHERE netblock_id = '" . $this->netblock_id . "'"; $results = mysql_query($query) or die(mysql_error()); return true; } //if the ip is a parent then change the netblock into free instead of removing it if (IP_Database::is_parent($this->netblock_id)) { $query = "SELECT * FROM ipmanager_netblocks WHERE parent = '" . $this->netblock_id . "'"; $results = mysql_query($query) or die(mysql_error()); //checks if all the childs are free if ($results) { while ($obj = mysql_fetch_object($results)) { $ip_calc = new Netblock(); $ip_calc->set_IP($obj->base_addr . "/" . $obj->subnet_size, $obj->family); if (IP_Database::is_parent($obj->netblock_id)) { $this->error = "Please delete the child within first. Please look at " . $ip_calc->get_IP(); return false; } if ($obj->status != "FREE") { $this->error = "All children of the network needs to be FREE. Please look at " . $ip_calc->get_IP(); return false; } } } //delete the netblocks childs $query = "DELETE FROM ipmanager_netblocks WHERE parent = '" . $this->netblock_id . "'"; $results = mysql_query($query) or die(mysql_error()); if ($this->parent_id === NULL) { $query = "DELETE FROM ipmanager_netblocks WHERE netblock_id = '" . $this->netblock_id . "'"; $results = mysql_query($query) or die(mysql_error()); } else { $query = "UPDATE ipmanager_netblocks SET title= '', description='', owner = NULL, location = NULL, assigned_to = NULL, status = 'FREE', stub = '0' WHERE netblock_id = '" . $this->netblock_id . "'"; $results = mysql_query($query) or die(mysql_error()); } } else { if (!IP_Database::is_parent($this->netblock_id)) { //if it doesn't have any parent as well delete it if ($this->parent_id === NULL) { $query = "DELETE FROM ipmanager_netblocks WHERE netblock_id = '" . $this->netblock_id . "'"; } else { $query = "UPDATE ipmanager_netblocks SET title= '', description='', owner = NULL, location = NULL, assigned_to = NULL, status = 'FREE', stub = '0' WHERE netblock_id = '" . $this->netblock_id . "'"; } $results = mysql_query($query) or die(mysql_error()); } } return true; }
function display_all_ip($arr, $ip_manager, $listType = "", $isID = "") { if ($isID) { print "\n<ul id='demo1' class='menu'>"; $isID = false; } else { print "\n<ul class='menu'>"; } foreach ($arr as $id => $name) { if (!IP_Database::is_parent($id)) { $listType = "leaf"; print "\n<li class='" . $listType . "'>"; //<form method='post'>"; $ip_2 = IP_Database::get_ip_by_id($id); $ip_manager->set_IP($ip_2['base_addr'] . "/" . $ip_2['subnet_size'], $ip_2['family']); print "\n<a style='cursor:default' class='tooltip' title='Subnet mask = " . $ip_manager->get_netmask() . " <br/> Wildcard = " . $ip_manager->get_wildcard() . " <br/> Network = " . $ip_manager->get_network() . " <br/> Broadcast = " . $ip_manager->get_broadcast() . " <br/> Hostmin = " . $ip_manager->get_hostmin() . " <br/> Hostmax = " . $ip_manager->get_hostmax() . "<br/>Host Per Net = " . $ip_manager->get_hostPerNet() . "'>" . $ip_manager->get_ip() . "</a><br/>"; /*echo "Split <select name='split'>"; if ($ip_manager->get_family()==4) { for ($i = $ip_manager->get_length(); $i<32; $i++) { echo "<option value='".($i+1)."'>".($i+1)."</option>"; } } else if ($ip_manager->get_family()==6) { for ($i = $ip_manager->get_length(); $i<128; $i++) { echo "<option value='".($i+1)."'>".($i+1)."</option>"; } } echo"</select> <input type='hidden' name='id' value='".$id."' />"; if($ip_2['stub'] == 0) { echo "<input type='submit' name='ip_split_submit' value='SPLIT NETWORK' />"; } else if ($ip_2['stub'] == 1) { echo "<input type='submit' disabled name='ip_split_submit' value='SPLIT NETWORK' />"; } echo "<input type='submit' name='ip_delete' value='DELETE NETWORK' /> <input type='text' name='ip_host' style='width:200px;'/> / <input type='text' name='ip_subnet' style='width:50px;'/> <input type='submit' name='ip_host' value='MAKE HOST' /> <input type='text' name='ip_status' style='width:200px;'/> <input type='submit' name='ip_assign' value='ASSIGN NETWORK' /> - ".$ip_2['status'].""; echo "</form>";*/ } else { $listType = "expanded"; print "\n<li class='" . $listType . "'>"; //<form method='post'>"; $ip_2 = IP_Database::get_ip_by_id($id); $ip_manager->set_IP($ip_2['base_addr'] . "/" . $ip_2['subnet_size'], $ip_2['family']); print "\n<a style='cursor:default' class='tooltip' title='Subnet mask = " . $ip_manager->get_netmask() . " <br/> Wildcard = " . $ip_manager->get_wildcard() . " <br/> Network = " . $ip_manager->get_network() . " <br/> Broadcast = " . $ip_manager->get_broadcast() . " <br/> Hostmin = " . $ip_manager->get_hostmin() . " <br/> Hostmax = " . $ip_manager->get_hostmax() . "<br/>Host Per Net = " . $ip_manager->get_hostPerNet() . "'>" . $ip_manager->get_ip() . "</a><br/>"; /*echo "<input type='hidden' name='id' value='".$id."' /> <input type='submit' name='ip_delete' value='DELETE NETWORK' /> <input type='text' name='ip_status' style='width:200px;'/> <input type='submit' name='ip_assign' value='ASSIGN NETWORK' /> - ".$ip_2['status']." </form>*/ echo "<br/>"; display_all_ip(IP_Database::get_all_ip($id), $ip_manager, $listType, $isID); } echo "</li>"; } echo "</ul>"; echo "<div style='border:1px solid green' id='thecurrent'> </div>"; }