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; }
if ($status != 'undefined') { $ip_2->set_status($status); } } if (isset($_POST['stub'])) { $stub = $_POST['stub']; $ip_2->set_stub($stub); } $ip_2->set_tags($tags); if (!$ip_2->update()) { return false; } } if (isset($_GET['stub'])) { $stub_id = explode("@", $_GET['stub']); $ip_db = new IP_Database($stub_id[1]); $ip_db->set_stub($stub_id[0]); $ip_manager = new Netblock(); $ip_manager->set_IP($ip_db->get_address_int() . "/" . $ip_db->get_subnet_size(), $ip_db->get_family()); if ($ip_db->update()) { if ($ip_db->is_stub() == 0) { if ($ip_manager->get_family() == 4) { if ($ip_db->get_subnet_size() != 32) { echo "Split <select name='split'>"; for ($i = $ip_manager->get_length(); $i < 32; $i++) { echo "<option value='" . ($i + 1) . "'>" . ($i + 1) . "</option>"; } echo "</select>"; echo " <input type='submit' name='ip_split_submit' value='SPLIT NETWORK' />"; } else { echo "<span style='color:red; font-size:14px'>NO MORE SPLITS</span>";
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; }
function get_all_children($id, $family) { $all_child_ip = IP_Database::get_all_ip($id, $family); $ips_to_delete = array(); foreach ($all_child_ip as $a_id => $addr) { $temp_netblock = new IP_Database($a_id); $t_all_child = IP_Database::get_all_ip($temp_netblock->get_netblock_id(), $temp_netblock->get_family()); if (!empty($t_all_child)) { $ips_to_delete = array_merge($ips_to_delete, get_all_children($a_id, $family)); } $ips_to_delete = array_merge($ips_to_delete, array($a_id)); } return $ips_to_delete; }
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>"; }