Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
             $add = true;
         }
     }
     if ($add) {
         //update status to parent
         $ip_info->set_status("PARENT");
         $ip_info->update();
     }
 } else {
     if (isset($_POST['ip_merge_submit'])) {
         //print_r($_POST);
         if (isset($_POST['merge'])) {
             $merge = $_POST['merge'];
             $match = explode("/", $ip_info->get_address_ip());
             $address = $match[0];
             $ip_manager->set_IP($address . "/" . $merge, $ip_info->get_family());
             if ($ip_info->get_family() == 4) {
                 $max_length = 32;
             } else {
                 if ($ip_info->get_family() == 6) {
                     $max_length = 128;
                 }
             }
             $host_min = $ip_manager->get_hostmin();
             $host_max = $ip_manager->get_hostmax();
             $min_ip_manager = new Netblock($host_min . "/" . $max_length);
             $max_ip_manager = new Netblock($host_max . "/" . $max_length);
             $parent_id = $ip_info->get_parent_id();
             if (is_numeric($parent_id)) {
                 $all_child_ip = IP_Database::get_all_ip($parent_id, $ip_info->get_family());
             }
Ejemplo n.º 3
0
    }
    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 {
                if ($ip_manager->get_family() == 6) {
Ejemplo n.º 4
0
        $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']);
        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();