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); }
include_once '../../classes/Contact.php'; // Opend DB $ini_array = parse_ini_file("../../config/cmdb.conf"); $dbhost = $ini_array['db_host']; $dbport = $ini_array['db_port']; $dbuser = $ini_array['db_user']; $dbpass = $ini_array['db_pass']; $dbname = $ini_array['db_name']; $conn = mysql_connect("{$dbhost}:{$dbport}", $dbuser, $dbpass) or die('Error connecting to mysql'); mysql_select_db($dbname); if (isset($_GET['getIPInfo'])) { $ip_id = explode("@", $_GET['getIPInfo']); $netblock = new Netblock($ip_id[0]); $ip_db = new IP_Database($ip_id[1]); $color = "black"; $status = $ip_db->get_status(); switch ($status) { case "FREE": $color = "green"; break; case "RESERVED": $color = "blue"; break; case "ASSIGNED": $color = "red"; break; } if (isset($_GET['action'])) { if ($_GET['action'] == 'calc') { print "<span id='head' style='color:" . $color . ";'>" . $netblock->get_IP() . "</span><br / > "; print "<div class = 'box'>Subnet mask = <span id='sub'>" . $netblock->get_netmask() . "</span></div>";
function export_csv() { if (isset($_GET['report_name']) && $_GET['report_name'] != '') { $name = $_GET['report_name']; } else { return "<b>Sorry invalid report name " . $_GET['report_name'] . "</b>"; } if (isset($_GET['vlan_id'])) { if ($_GET['vlan_id'] == 'showALL') { $vlan_manager = new Vlan_database(); $all_vlans = $vlan_manager->get_all_vlans(); $num_max = 4096; $heading = array("VLAN ID", "Name", "Status", "Location", "Assigned To", "VLAN Distinguisher"); $content = implode(",", $heading); $content .= "\n"; $arr = array(); foreach ($all_vlans as $id => $v_id) { $arr[$v_id] = $id; } for ($i = 1; $i < $num_max; $i++) { $data = array(); if (in_array($i, $all_vlans)) { foreach ($all_vlans as $id => $v_id) { if ($v_id == $i) { $my_vlan = new Vlan_database($id); if ($my_vlan->get_id() !== NULL) { $data = array(); array_push($data, $my_vlan->get_vlan_id()); array_push($data, $my_vlan->get_name()); array_push($data, $my_vlan->get_status()); array_push($data, $my_vlan->get_location_name()); array_push($data, $my_vlan->get_assigned_to_name()); array_push($data, $my_vlan->get_vlan_distinguisher()); $content .= stripslashes(implode(",", $data)); $content .= "\n"; } } } } else { //if it doesn't create a free vlan array_push($data, $i); array_push($data, ""); array_push($data, "FREE"); array_push($data, ""); array_push($data, ""); array_push($data, ""); $content .= stripslashes(implode(",", $data)); $content .= "\n"; } } } else { $results = Vlan_database::Search($_GET['vlan_id'], $_GET['name'], $_GET['status'], $_GET['location'], $_GET['assign'], $_GET['distinguish'], $_GET['notes']); $heading = array("VLAN ID", "Name", "Status", "Location", "Assigned To", "VLAN Distinguisher"); $content = implode(",", $heading); $content .= "\n"; foreach ($results as $v_id => $vlan_id) { $data = array(); $my_vlan = new Vlan_database($v_id); array_push($data, $my_vlan->get_vlan_id()); array_push($data, $my_vlan->get_name()); array_push($data, $my_vlan->get_status()); array_push($data, $my_vlan->get_location_name()); array_push($data, $my_vlan->get_assigned_to_name()); array_push($data, $my_vlan->get_vlan_distinguisher()); $content .= stripslashes(implode(",", $data)); $content .= "\n"; } } } else { $title = $_GET['title']; $str_tag = $_GET['tags']; while (strpos($str_tag, ", ")) { $str_tag = str_replace(", ", ",", $str_tag); } $tags = explode(",", $str_tag); if (count($tags) == 1 && $tags[0] == "") { $tags = array(); } $location = $_GET['location']; $owner = $_GET['owner']; $assigned_to = $_GET['assigned']; $status = $_GET['status']; $IP_Search = new IP_Database(); $s_results = $IP_Search->search($title, $tags, $location, $owner, $assigned_to, $status); $heading = array("Master Block", "Prefix", "Length", "Family", "Status", "Location", "Owner", "Assigned To", "Tags"); $content = implode(",", $heading); $content .= "\n"; foreach ($s_results as $id => $n_name) { $data = array(); $my_netblock = new IP_Database($id); $master_id = IP_Database::get_master($id); $master_block = new IP_Database($master_id); $ip = explode("/", $my_netblock->get_address_ip()); array_push($data, $master_block->get_address_ip()); array_push($data, $ip[0]); array_push($data, $my_netblock->get_subnet_size()); array_push($data, $my_netblock->get_family()); array_push($data, $my_netblock->get_status()); array_push($data, $my_netblock->get_location_name()); array_push($data, $my_netblock->get_owner_name()); array_push($data, $my_netblock->get_assigned_to_name()); $tags = $my_netblock->get_tags(); $n_tags = stripslashes(implode(" ", $tags)); array_push($data, $n_tags); $content .= stripslashes(implode(",", $data)); $content .= "\n"; } } return $content; }