function bin_sub_carry($bin, $pos) { $str = $bin; if (substr($str, $pos, 1) != "") { if (substr($str, $pos, 1) == "0") { $str = substr_replace($str, "1", $pos, 1); $str = Netblock::bin_sub_carry($str, $pos - 1); } else { if (substr($str, $pos, 1) == "1") { $str = substr_replace($str, "0", $pos, 1); } } } else { $is_negative = true; } return $str; }
<?php include_once '../../plugins/IP Manager/Netblock.php'; if (isset($_POST['net']) && isset($_POST['length']) && is_numeric($_POST['length']) && $_POST['net'] != '') { $net = $_POST['net']; $length = $_POST['length']; $netblock = new Netblock("{$net}/{$length}"); if ($netblock->get_family() != 4 && $netblock->get_family() != 6) { //print "Invalid address<br>"; return; } else { echo "<p><hr>"; echo $netblock->print_all(); } }
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 (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>"; } } else {
else { //echo "<meta http-equiv=\"REFRESH\" content=\"0;url=".$_SERVER['SCRIPT_NAME']."?tab=".$_GET['tab']."&pluginID=".$_GET['pluginID']."&className=".$_GET['className']."&family=".$_GET['family']."&success=delete\">"; }*/ } else { if (isset($_POST['ip_assign'])) { IP_Database::assign_ip_by_id($_POST['id'], $_POST['ip_status']); } else { if (isset($_POST['ip_host'])) { //get the ip and do some calculatins $ip = $_POST['ip_hostip'] . "/" . $_POST['ip_hostsubnet']; $ip_manager->set_IP($ip, $ip_info->get_family()); //check if the host is a valid host if ($ip_manager->get_is_negative() == false) { //if not then create a new manager to calculate for more checks $test_manager = new Netblock($ip_info->get_address_ip()); //if the address is part of the network, then create a new host if (substr($ip_manager->get_binary(), 0, $ip_info->get_subnet_size()) == substr($test_manager->get_binary(), 0, $ip_info->get_subnet_size())) { //set the information $host = new IP_Database(); $host->set_address_int($ip_manager->get_long()); $host->set_subnet_size($ip_manager->get_length()); $host->set_description($ip_info->get_description()); $host->set_family($ip_info->get_family()); //set the parent $host->set_parent_id($ip_info->get_netblock_id()); //if there are any inheritance of information, inherit them if ($_POST['inh_loc'] == "on") { $host->set_location_id($ip_info->get_location_id()); } if ($_POST['inh_owner'] == "on") {
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']); IP_Database::add_split_to_db($ip_manager->get_long(), $ip_manager->get_length(), $ip_info['description'], $ip_manager->get_family(), $ip_info['base_index']); } } else { if (isset($_POST['ip_delete'])) { IP_Database::remove_ip_by_id($_POST['id']); } else { if (isset($_POST['ip_assign'])) { IP_Database::assign_ip_by_id($_POST['id'], $_POST['ip_status']); } } } $arr = array(); $arr = IP_Database::get_all_ip(); $listType = "expanded"; $isID = true;