foreach ($all_vrfs as $vrf) {
    //cast
    $vrf = (array) $vrf;
    $vrf_data[$vrf['name']] = $vrf;
    $vrf_data[$vrf['rd']] = $vrf;
    # add also RD as VRF name, will allow matches against both name and RD
}
# fetch all sections and load all subnets
$all_sections = $Sections->fetch_all_sections();
# get all subnets in all sections
$edata = array();
$section_names = array();
foreach ($all_sections as $section) {
    $section = (array) $section;
    $section_names[$section['name']] = $section;
    $section_subnets = $Subnets->fetch_section_subnets($section['id']);
    # skip empty sections
    if (sizeof($section_subnets) == 0) {
        continue;
    }
    foreach ($section_subnets as $subnet) {
        $subnet = (array) $subnet;
        # load whole record in array
        $edata[$section['id']][$subnet['vrfId']][$subnet['ip']][$subnet['mask']] = $subnet;
        $edata[$section['id']][$subnet['vrfId']][$subnet['ip']][$subnet['mask']]['type'] = $Subnets->identify_address($subnet['ip']);
    }
}
#print_r($vlan_data);
$rows = "";
$counters = array();
$ndata = array();
Beispiel #2
0
 /**
  * Delete section, subsections, subnets and ip addresses
  *
  * @access private
  * @param mixed $values
  * @return void
  */
 private function section_delete($values)
 {
     # subnets class
     $Subnets = new Subnets($this->Database);
     # save old values
     $old_section = $this->fetch_section("id", $values['id']);
     # check for subsections and store all ids
     $all_ids = $this->get_all_section_and_subsection_ids($values['id']);
     //array of section + all subsections
     # truncate and delete all subnets in all sections, than delete sections
     foreach ($all_ids as $id) {
         $section_subnets = $Subnets->fetch_section_subnets($id);
         if (sizeof($section_subnets) > 0) {
             foreach ($section_subnets as $ss) {
                 //delete subnet
                 $Subnets->modify_subnet("delete", array("id" => $ss->id));
             }
         }
         # delete all sections
         try {
             $this->Database->deleteRow("sections", "id", $id);
         } catch (Exception $e) {
             $this->Log->write("Section {$old_section->name} delete", "Failed to delete section {$old_section->name}<hr>" . $e->getMessage() . "<hr>" . $this->array_to_log($this->reformat_empty_array_fields($values, "NULL")), 2);
             $this->Result->show("danger", _("Error: ") . $e->getMessage(), false);
             return false;
         }
     }
     # write changelog
     $this->Log->write_changelog('section', "delete", 'success', $old_section, array());
     # log
     $this->Log->write("Section {$old_section->name} delete", "Section {$old_section->name} deleted<hr>" . $this->array_to_log($this->reformat_empty_array_fields((array) $old_section)), 0);
     return true;
 }
Beispiel #3
0
$Subnets = new Subnets($Database);
$Addresses = new Addresses($Database);
$Result = new Result();
# verify that user is logged in
$User->check_user_session();
# If confirm is not set print delete warning
if ($_POST['action'] == "delete" && !isset($_POST['deleteconfirm'])) {
    //for ajax to prevent reload
    print "<div style='display:none'>alert alert-danger</div>";
    //result
    print "<div class='alert alert-warning'>";
    //fetch all subsections
    $subsections = $Sections->fetch_subsections($_POST['id']);
    //print what will be deleted
    if (sizeof($subsections) > 0) {
        $subnets = $Subnets->fetch_section_subnets($_POST['id']);
        //fetch all subnets in section
        $num_subnets = sizeof($subnets);
        //number of subnets to be deleted
        if (sizeof($subnets) > 0) {
            foreach ($subnets as $s) {
                $out[] = $s;
            }
        }
        //fetch subsection subnets
        foreach ($subsections as $ss) {
            $subsection_subnets = $Subnets->fetch_section_subnets($ss->id);
            //fetch all subnets in subsection
            if (sizeof($subsection_subnets) > 0) {
                foreach ($subsection_subnets as $sss) {
                    $out[] = $sss;
    $vrf = (array) $vrf;
    $vrf_name[$vrf['vrfId']] = $vrf['name'];
}
# Precompute masks values, to avoid too much CPU load
$masks = array();
for ($i = 0; $i <= 32; $i++) {
    $masks["IPv4"][$i] = 0xffffffff >> 32 - $i << 32 - $i;
}
# IPv4 masks, long
for ($i = 0; $i <= 128; $i++) {
    $masks["IPv6"][$i] = str_repeat('1', $i) . str_repeat('0', 128 - $i);
}
# IPv6 masks, bin str
# Read IPs for the sections we need to order
foreach ($rlist as $sect_id => $sect_check) {
    $section_subnets = $Subnets->fetch_section_subnets($sect_id);
    # skip empty sections
    if (sizeof($section_subnets) == 0) {
        continue;
    }
    $isFolder[$sect_id] = array();
    foreach ($section_subnets as &$subnet) {
        $subnet = (array) $subnet;
        $subnet['ip'] = $Subnets->transform_to_dotted($subnet['subnet']);
        $subnet['type'] = $Subnets->identify_address($subnet['ip']);
        # Precompute subnet in AND format (long for IPv4 and bin str for IPv6)
        $subnet['andip'] = $subnet['type'] == "IPv4" ? $subnet['subnet'] : my_ip2Bin($pi6, $subnet['ip']);
        # Add to array
        $edata[$sect_id][] = $subnet;
        $isFolder[$sect_id][$subnet['id']] = $subnet['isFolder'];
    }