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; }
$ip = $_POST['ip1'] . "." . $_POST['ip2'] . "." . $_POST['ip3'] . "." . $_POST['ip4'] . "/" . $_POST['netmask']; } else { $ip = ""; } } //If nothing is entered, a warning is issued if ($ip == "/") { echo Form::warning("Enter an IP!"); exit; } //create a new manager to do the calculation $ip_manager = new Netblock($ip); //if it's adding a new network if (isset($_POST['add'])) { //check if the ip is valid if ($ip_manager->get_IP() != "INVALID") { //set all the values if it's valid $n_ip = new IP_Database(); $n_ip->set_address_int($ip_manager->get_long()); $n_ip->set_subnet_size($ip_manager->get_length()); $n_ip->set_description(""); $n_ip->set_family($ip_manager->get_family()); $n_ip->set_title($_POST['title']); //IAM HERE TRYING TO INSTALL SEARCH AND ADD IP $i_match = explode("/", $ip_manager->get_IP()); //check if the ip and subnet are valid combinations if ($ip_manager->get_long_ip() != $ip_manager->get_long()) { echo Form::warning("Your IP is invalid, the IP is changed from " . $i_match[0] . " to " . $ip_manager->get_network()); } //inserting the IP, if it fails show the error if (!$n_ip->insert()) {
$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>"; print "<div class = 'box'>Wildcard = <span id='sub'>" . $netblock->get_wildcard() . "</span></div>"; print "<div class = 'box'>Network = <span id='sub'>" . $netblock->get_network() . "</span></div>"; print "<div class = 'box'>Broadcast = <span id='sub'>" . $netblock->get_broadcast() . "</span></div>"; print "<div class = 'box'>Hostmin = <span id='sub'>" . $netblock->get_hostmin() . "</span></div>"; print "<div class = 'box'>Hostmax = <span id='sub'>" . $netblock->get_hostmax() . "</span></div>"; print "<div class = 'box'>Host Per Net = <span id='sub'>" . $netblock->get_hostPerNet(); } else { if ($_GET['action'] == 'desc') { $name = "NO OWNER"; if ($ip_db->get_owner_name() != "") { $name = $ip_db->get_owner_name(); } $assigned = "NO ASSIGNED TO"; if ($ip_db->get_assigned_to_name() != "") {
} if (isset($_POST['desc'])) { $desc = $_POST['desc']; } else { $desc = ""; } if ($ip == "/") { echo "<h1>Enter an IP!</h1>"; exit; } $ip_manager = new Netblock($ip, $desc); if (isset($_POST['view'])) { $ip_manager->print_all(); } else { if (isset($_POST['add'])) { if ($ip_manager->get_IP() != "INVALID") { IP_Database::add_ip_to_db($ip_manager->get_long(), $ip_manager->get_length(), $ip_manager->get_desc(), $ip_manager->get_family()); } else { echo "INVALID INFO TRY AGAIN"; exit; } } } } echo "<hr/>"; if (isset($_POST['ip_split_submit'])) { $ip_info = IP_Database::get_ip_by_id($_POST['id']); $ip_manager->set_IP($ip_info->get_address_ip() . "/" . $ip_info['subnet_size'], $ip_info['family']); $split = $ip_manager->split_IP($_POST['split']); foreach ($split as $id => $ip) { $ip_manager = new Netblock($ip, $ip_info['description']);