# 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(); # store new networks in a similar format with edata for easier processing # check the fields foreach ($data as &$cdata) { $msg = ""; $action = ""; $cfieldtds = ""; # check if required fields are present and not empty foreach ($reqfields as $creq) { if (!isset($cdata[$creq]) or $cdata[$creq] == "") {
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']; } } $rows = ""; $counters = array(); # Recompute master/nested relations for the selected sections and address families foreach ($rlist as $sect_id => $sect_check) { # Skip empty sections if (!$edata[$sect_id]) { continue; }
$Result = new Result(); # verify that user is logged in $User->check_user_session(); # ID must be numeric if (!is_numeric($_POST['subnetId'])) { $Result->show("danger", _("Invalid ID"), true, true); } # verify that user has write permissionss for subnet if ($Subnets->check_permission($User->user, $_POST['subnetId']) != 3) { $Result->show("danger", _('You do not have permissions to modify hosts in this subnet') . "!", true, true); } # fetch subnet details $subnet = $Subnets->fetch_subnet(null, $_POST['subnetId']); $subnet !== false ?: $Result->show("danger", _("Invalid ID"), true, true); # IPv6 scanning is not supported if ($Subnets->identify_address($subnet->subnet) == "IPv6") { $Result->show("danger", _('IPv6 scanning is not supported') . '!', true, true); } # fix description $subnet->description = strlen($subnet->description) > 0 ? "(" . $subnet->description . ")" : ""; ?> <!-- header --> <div class="pHeader"><?php print _('Scan subnet'); ?> </div> <!-- content --> <div class="pContent">
if (!is_numeric($_POST['subnetId'])) { $Result->show("danger", _("Invalid ID"), true, true); } # get subnet details $subnet = $Subnets->fetch_subnet(null, $_POST['subnetId']); # verify that user has write permissions for subnet $subnetPerm = $Subnets->check_permission($User->user, $subnet->id); if ($subnetPerm < 3) { $Result->show("danger", _('You do not have permissions to resize subnet') . '!', true, true); } # check if it has slaves - if yes it cannot be splitted! if ($Subnets->has_slaves($subnet->id)) { $Result->show("danger", _('Only subnets that have no nested subnets can be splitted') . "!", true, true); } # calculate max mask $max_new_mask = $Subnets->identify_address($Subnets->transform_to_dotted($subnet->subnet)) == "IPv4" ? 32 : 128; # die if too small if ($max_new_mask < $subnet->mask) { $Result->show("danger", _("Subnet too small to be splitted"), true, true); } $n = 2; # step $m = 0; # array id //set mask options for ($mask = $subnet->mask + 1; $mask <= $max_new_mask; $mask++) { # set vars $opts[$m]['mask'] = $mask; $opts[$m]['number'] = $n; $opts[$m]['max'] = $Subnets->get_max_hosts($mask, $Subnets->identify_address($Subnets->transform_to_dotted($subnet->subnet))); # next
// count usage foreach ($out as $k => $s) { //check if subnet has slaves and set slaves flag true/false $slaves = $Subnets->has_slaves($s->id) ? true : false; # fetch all addresses and calculate usage if ($slaves) { $addresses = $Addresses->fetch_subnet_addresses_recursive($s->id, false); $slave_subnets = (array) $Subnets->fetch_subnet_slaves($s->id); // save count $addresses_cnt = gmp_strval(sizeof($addresses)); # full ? if (sizeof($slave_subnets) > 0) { foreach ($slave_subnets as $ss) { if ($ss->isFull == 1) { # calculate max $max_hosts = $Subnets->get_max_hosts($ss->mask, $Subnets->identify_address($ss->subnet), true); # count $count_hosts = $Addresses->count_subnet_addresses($ss->id); # add $addresses_cnt = gmp_strval(gmp_add($addresses_cnt, gmp_sub($max_hosts, $count_hosts))); } } } $subnet_usage = $Subnets->calculate_subnet_usage($addresses_cnt, $s->mask, $s->subnet, $s->isFull); //Calculate free/used etc } else { # fetch addresses in subnet $addresses_cnt = $Addresses->count_subnet_addresses($s->id); # calculate usage $subnet_usage = $Subnets->calculate_subnet_usage($addresses_cnt, $s->mask, $s->subnet, $s->isFull); }
/** * Function to get RIPe info for network ********************************************/ /* functions */ require dirname(__FILE__) . '/../../../functions/functions.php'; # initialize user object $Database = new Database_PDO(); $User = new User($Database); $Subnets = new Subnets($Database); $Result = new Result(); # verify that user is logged in $User->check_user_session(); /* http://apps.db.ripe.net/whois/lookup/ripe/inetnum/212.58.224.0-212.58.255.255.html.xml */ /* http://apps.db.ripe.net/whois/lookup/ripe/inet6num/2102:840::/32.xml */ # identify address and set proper url $type = $Subnets->identify_address($_POST['subnet']); if ($type == "IPv4") { $url = "http://apps.db.ripe.net/whois/lookup/ripe/inetnum/{$_POST['subnet']}.xml"; } else { $url = "http://apps.db.ripe.net/whois/lookup/ripe/inet6num/{$_POST['subnet']}.xml"; } /* querry ripe db and parse result */ $xml = @simplexml_load_file($url); /* fail */ if (!$xml) { /* save to json and return */ header("Content-type: text/javascript"); echo json_encode(array("Error" => "Subnet not present in RIPE DB<br>Error opening URL {$url}")); } else { foreach ($xml->objects->object[0]->attributes->children() as $m => $subtag) { $a = (string) $subtag->attributes()->name;
$Result = new Result(); $User = new User($Database); $Subnets = new Subnets($Database); $Tools = new Tools($Database); $Addresses = new Addresses($Database); $Ping = new Scan($Database); # verify that user is logged in $User->check_user_session(); # validate post is_numeric($_POST['subnetId']) ?: $Result->show("danger", _("Invalid ID"), true, true, false, true); if (is_numeric($_POST['id'])) { strlen($_POST['id']) != 0 ?: $Result->show("danger", _("Invalid ID"), true, true, false, true); # fetch address $address = (array) $Addresses->fetch_address(null, $_POST['id']); } else { $validate = $Subnets->identify_address($_POST['id']) == "IPv4" ? filter_var($_POST['id'], FILTER_VALIDATE_IP) : filter_var($_POST['id'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6); if ($validate === false) { $Result->show("danger", _("Invalid IP address"), true, true, false, true); } else { $address['ip'] = $_POST['id']; } } # set and check permissions $subnet_permission = $Subnets->check_permission($User->user, $_POST['subnetId']); $subnet_permission > 2 ?: $Result->show("danger", _('Cannot edit IP address details') . '! <br>' . _('You do not have write access for this network'), true, true); # try to ping it $pingRes = $Ping->ping_address($address['ip']); # update last seen if success if ($pingRes == 0 && is_numeric($_POST['id'])) { @$Ping->ping_update_lastseen($address['id']); }
/** * Search inside subnets if host address is provided! * * @access private * @param mixed $search_term * @param number $high * @param number $low * @return array */ private function search_subnets_inside($high, $low) { if ($low == $high) { # subnets class $Subnets = new Subnets($this->Database); # fetch all subnets $subnets = $Subnets->fetch_all_subnets_search(); # loop and search foreach ($subnets as $s) { # cast $s = (array) $s; //first verify address type $type = $Subnets->identify_address($s['subnet']); if ($type == "IPv4") { # Initialize PEAR NET object $this->initialize_pear_net_IPv4(); # parse address $net = $this->Net_IPv4->parseAddress($Subnets->transform_to_decimal($s['subnet']) . '/' . $s['mask']); if ($low > $Subnets->transform_to_decimal(@$net->network) && $low < $Subnets->transform_to_decimal($net->broadcast)) { $ids[] = $s['id']; } } } # filter $ids = sizeof(@$ids) > 0 ? array_filter($ids) : array(); # search if (sizeof($ids) > 0) { foreach ($ids as $id) { $result[] = $Subnets->fetch_subnet(null, $id); } } # return return sizeof(@$result) > 0 ? array_filter($result) : array(); } else { return array(); } }