<!-- actions --> <th class="actions"></th> </tr> </tbody> <?php /* Addresses content print */ $n = 0; //addresses index $m = sizeof($addresses) - 1; //last address index # if no IP is configured only display free subnet! if ($addresses === false || sizeof($addresses) == 0) { if ($User->user->hideFreeRange != 1) { $unused = $Addresses->find_unused_addresses($Subnets->transform_to_decimal($subnet_detailed['network']), $Subnets->transform_to_decimal($subnet_detailed['broadcast']), $subnet['mask'], $empty = true); print '<tr class="th"><td colspan="' . $colspan['empty'] . '" class="unused">' . $unused['ip'] . ' (' . $Subnets->reformat_number($unused['hosts']) . ')</td></tr>' . "\n"; } } else { # break into arrays $addresses_chunk = array_chunk($addresses, $page_limit, true); $c = 1; //count for print for pages - $c++ per page $n = 0; //count for IP addresses - $n++ per IP address $g = 0; //count for compress consecutive class foreach ($addresses_chunk as $address_chunk) { # show current page if ($c == $_REQUEST['sPage']) { $show = true;
$child_response = unserialize($child_response); //store $scan_subnets[$index]->discovered = $child_response; //now, child is dead, and parent close the pipe unlink($child_pipe); unset($threads[$index]); } } usleep(200000); } } //fping finds all subnet addresses, we must remove existing ones ! foreach ($scan_subnets as $sk => $s) { if (isset($s->discovered)) { foreach ($s->discovered as $rk => $result) { if (!in_array($Subnets->transform_to_decimal($result), $addresses_tmp[$s->id])) { unset($scan_subnets[$sk]->discovered[$rk]); } } //rekey $scan_subnets[$sk]->discovered = array_values($scan_subnets[$sk]->discovered); } } } else { //run per MAX_THREADS for ($m = 0; $m <= $size_addresses; $m += $Scan->settings->scanMaxThreads) { // create threads $threads = array(); //fork processes for ($i = 0; $i <= $Scan->settings->scanMaxThreads && $i <= $size_addresses; $i++) { //only if index exists!
$address['start'] = $range[0]; $address['stop'] = $range[1]; # verify both IP addresses if ($subnet['isFolder'] == "1") { if ($Addresses->validate_ip($address['start']) === false) { $Result->show("danger", _("Invalid IP address") . "!", true); } if ($Addresses->validate_ip($address['stop']) === false) { $Result->show("danger", _("Invalid IP address") . "!", true); } } else { $Addresses->verify_address($address['start'], "{$subnet['ip']}/{$subnet['mask']}", $not_strict); $Addresses->verify_address($address['stop'], "{$subnet['ip']}/{$subnet['mask']}", $not_strict); } # go from start to stop and insert / update / delete IPs $start = $Subnets->transform_to_decimal($address['start']); $stop = $Subnets->transform_to_decimal($address['stop']); # start cannot be higher than stop! if ($start > $stop) { $Result->show("danger", _("Invalid address range") . "!", true); } # we can manage only 4096 IP's at once! if (gmp_strval(gmp_sub($stop, $start)) > 4096) { $Result->show("danger", _("Only 4096 IP addresses at once") . "!", true); } # set limits $m = gmp_strval($start); $n = gmp_strval(gmp_add($stop, 1)); # check if delete is confirmed if ($action == "delete" && !isset($address['deleteconfirm'])) { $range = str_replace("-", " - ", $address['ip_addr']);
} print "</ul>"; print "<hr><div style='text-align:right'>"; print _("Are you sure you want to delete above items?") . " "; print "<div class='btn-group'>"; print "\t<a class='btn btn-sm btn-danger editSubnetSubmitDelete' id='editSubnetSubmitDelete'>" . _("Confirm") . "</a>"; print "</div>"; print "</div>"; print "</div>"; } else { # remove scanagent if not needed if (!isset($_POST['pingSubnet']) && !isset($_POST['discoverSubnet'])) { $_POST['scanAgent'] = 0; } # create array of default update values $values = array("id" => @$_POST['subnetId'], "isFolder" => 0, "masterSubnetId" => $_POST['masterSubnetId'], "subnet" => $Subnets->transform_to_decimal($_POST['subnet']), "mask" => $_POST['mask'], "description" => @$_POST['description'], "vlanId" => $_POST['vlanId'], "allowRequests" => $Admin->verify_checkbox(@$_POST['allowRequests']), "showName" => $Admin->verify_checkbox(@$_POST['showName']), "discoverSubnet" => $Admin->verify_checkbox(@$_POST['discoverSubnet']), "pingSubnet" => $Admin->verify_checkbox(@$_POST['pingSubnet']), "scanAgent" => @$_POST['scanAgent'], "DNSrecursive" => $Admin->verify_checkbox(@$_POST['DNSrecursive']), "DNSrecords" => $Admin->verify_checkbox(@$_POST['DNSrecords']), "nameserverId" => $_POST['nameserverId'], "device" => $_POST['device'], "isFull" => $Admin->verify_checkbox($_POST['isFull'])); # for new subnets we add permissions if ($_POST['action'] == "add") { $values['permissions'] = $_POST['permissions']; $values['sectionId'] = $_POST['sectionId']; // add vrf $values['vrfId'] = $_POST['vrfId']; } else { # if section change if (@$_POST['sectionId'] != @$_POST['sectionIdNew']) { $values['sectionId'] = $_POST['sectionIdNew']; } # if vrf change if (@$_POST['vrfId'] != @$_POST['vrfIdOld']) { $values['vrfId'] = $_POST['vrfId']; }
} # loop and make sure that we do not have any duplicate IPs ! $unique_ips = array(); foreach ($res as $r) { if (in_array($r['ip_addr'], $unique_ips)) { $Result->show("danger", "Duplicated IP address {$r['ip_addr']} cannot be imported!", true); } else { $unique_ips[] = $r['ip_addr']; } } # insert entries if (sizeof($res) > 0) { $errors = 0; foreach ($res as $r) { # set insert values $values = array("ip_addr" => $Subnets->transform_to_decimal($r['ip_addr']), "dns_name" => $r['dns_name'], "subnetId" => $_POST['subnetId'], "description" => $r['description'], "switch" => $r['switch'], "mac" => $r['mac'], "state" => 2, "lastSeen" => date("Y-m-d H:i:s"), "action" => "add"); # port if (isset($r['port'])) { $values['port'] = $r['port']; } # custom fields if (isset($required_fields)) { foreach ($required_fields as $k => $f) { $values[$f['name']] = $r[$f['name']]; } } # insert if (!$Addresses->modify_address($values)) { $Result->show("danger", _("Failed to import entry") . " " . $r['ip_addr'], false); $errors++; }
} // dns name if (substr($key, 0, 8) == "dns_name") { $res[substr($key, 8)]['dns_name'] = $line; } //verify that it is not already in table! if (substr($key, 0, 2) == "ip") { if ($Addresses->address_exists($line, $_POST['subnetId']) === true) { $Result->show("danger", "IP address {$line} already exists!", true); } } } # insert entries if (sizeof($res) > 0) { $errors = 0; foreach ($res as $r) { # set insert values $values = array("ip_addr" => $Subnets->transform_to_decimal($r['ip_addr']), "dns_name" => $r['dns_name'], "subnetId" => $_POST['subnetId'], "description" => $r['description'], "lastSeen" => date("Y-m-d H:i:s")); # insert if (!$Admin->object_modify("ipaddresses", "add", "id", $values)) { $Result->show("danger", "Failed to import entry " . $r['ip_addr'], false); $errors++; } } # success if no errors if ($errors == 0) { $Result->show("success", _("Scan results added to database") . "!", true); } } else { $Result->show("danger", _("No entries available"), true); }
/** * Fetches all possible subnet addresses * * @access private * @param $subnet //subnet in decimal format * @param int $mask //subnet mask * @return void //array of ip addresses in decimal format */ private function get_all_possible_subnet_addresses($subnet, $mask) { # initialize classes $Subnets = new Subnets($this->Database); # make sure we have proper subnet format $subnet = $Subnets->transform_address($subnet, "decimal"); //fetch start and stop addresses $boundaries = (object) $Subnets->get_network_boundaries($subnet, $mask); //create array if ($mask == 32) { $ip[] = $Subnets->transform_to_decimal($boundaries->network); } elseif ($mask == 31) { $ip[] = $Subnets->transform_to_decimal($boundaries->network); $ip[] = $Subnets->transform_to_decimal($boundaries->broadcast); } else { //set loop limits $start = gmp_strval(gmp_add($Subnets->transform_to_decimal($boundaries->network), 1)); $stop = gmp_strval($Subnets->transform_to_decimal($boundaries->broadcast)); //loop for ($m = $start; $m < $stop; $m++) { $ip[] = $m; } } //return return $ip; }
if ($retval == 3) { die(json_encode(array("status" => 1, "error" => "invalid command line arguments"))); } if ($retval == 4) { die(json_encode(array("status" => 1, "error" => "system call failure"))); } # parse result if (sizeof(@$Scan->fping_result) == 0) { die(json_encode(array("status" => 0, "values" => array("alive" => null)))); } else { //check each line foreach ($Scan->fping_result as $l) { //split $field = array_filter(explode(" ", $l)); //create result $out['alive'][] = $Subnets->transform_to_decimal($field[0]); } } } elseif ($Scan->settings->scanPingType == "fping") { # fetch subnet $subnet = $Subnets->fetch_subnet(null, $argv[2]); $subnet !== false ?: die(json_encode(array("status" => 1, "error" => "Invalid subnet ID provided"))); //set exit flag to true $Scan->ping_set_exit(false); # set cidr $subnet_cidr = $Subnets->transform_to_dotted($subnet->subnet) . "/" . $subnet->mask; # execute $retval = $Scan->ping_address_method_fping_subnet($subnet_cidr); # errors if ($retval == 3) { die(json_encode(array("status" => 1, "error" => "invalid command line arguments")));
//get size of subnets - $_POST/4 $size = sizeof($_POST) / 4; //get unique keys for subnets because they are not sequential if deleted!!! foreach ($_POST as $key => $line) { if (strlen(strstr($key, "subnet")) > 0) { $allSubnets[] = $key; } } # format and verify each record foreach ($allSubnets as $subnet) { //get sequential number $m = str_replace("subnet-", "", $subnet); //reformat subnet $_temp = explode("/", $_POST['subnet-' . $m]); //set subnet details for importing $subnet_import['subnet'] = $Subnets->transform_to_decimal($_temp[0]); $subnet_import['mask'] = $_temp[1]; $subnet_import['sectionId'] = $_POST['section-' . $m]; $subnet_import['description'] = $_POST['description-' . $m]; $subnet_import['vlanId'] = $_POST['vlan-' . $m]; $subnet_import['vrfId'] = $_POST['vrf-' . $m]; $subnet_import['showName'] = $_POST['showName-' . $m]; //cidr if (strlen($err = $Subnets->verify_cidr($Subnets->transform_to_dotted($subnet_import['subnet']) . "/" . $subnet_import['mask'])) > 5) { $errors[] = $err; } else { if (strlen($err = $Subnets->verify_subnet_overlapping($subnet_import['sectionId'], $Subnets->transform_to_dotted($subnet_import['subnet']) . "/" . $subnet_import['mask'], $subnet_import['vrfId'])) > 5) { $errors[] = $err; } else { $subnets_to_insert[] = $subnet_import; }
print "<strong>" . _("Warning") . "</strong>: " . _("I will delete") . ":<ul>"; print "\t<li>{$subcnt} " . _("subnets") . "</li>"; if ($ipcnt > 0) { print "\t<li>{$ipcnt} " . _("IP addresses") . "</li>"; } print "</ul>"; print "<hr><div style='text-align:right'>"; print _("Are you sure you want to delete above items?") . " "; print "<div class='btn-group'>"; print "\t<a class='btn btn-sm btn-danger editSubnetSubmitDelete' id='editSubnetSubmitDelete'>" . _("Confirm") . "</a>"; print "</div>"; print "</div>"; print "</div>"; } else { # create array of default update values $values = array("id" => @$_POST['subnetId'], "isFolder" => 0, "masterSubnetId" => $_POST['masterSubnetId'], "subnet" => $Subnets->transform_to_decimal($_POST['subnet']), "mask" => $_POST['mask'], "description" => @$_POST['description'], "vlanId" => $_POST['vlanId'], "allowRequests" => $Admin->verify_checkbox(@$_POST['allowRequests']), "showName" => $Admin->verify_checkbox(@$_POST['showName']), "discoverSubnet" => $Admin->verify_checkbox(@$_POST['discoverSubnet']), "pingSubnet" => $Admin->verify_checkbox(@$_POST['pingSubnet'])); # for new subnets we add permissions if ($_POST['action'] == "add") { $values['permissions'] = $_POST['permissions']; $values['sectionId'] = $_POST['sectionId']; } else { # if section change if (@$_POST['sectionId'] != @$_POST['sectionIdNew']) { $values['sectionId'] = $_POST['sectionIdNew']; } # if vrf change if (@$_POST['vrfId'] != @$_POST['vrfIdOld']) { $values['vrfId'] = $_POST['vrfId']; } } # append custom fields
/** * Reformat possible nun-full IPv6 address for search * * @access public * @param mixed $address * @return void */ public function reformat_IPv6_for_search($address) { # we need Subnets class $Subnets = new Subnets($this->Database); # split network and subnet part $address = explode("/", $address); # if subnet is not provided we are looking for host if (sizeof($address) < 2) { $return['low'] = $Subnets->transform_to_decimal($address[0]); $return['high'] = $Subnets->transform_to_decimal($address[0]); } //if network part ends with :: we must search the complete provided subnet! $lastChars = substr($address[0], -2); if ($lastChars == "::") { $return['low'] = $Subnets->transform_to_decimal($address[0]); //set highest IP address $subnet = substr($ip[0], 0, -2); $subnet = $Subnets->transform_to_decimal($subnet); //calculate all possible hosts in subnet mask $maxHosts = $Subnets->get_max_hosts($address[1], "IPv6"); $return['high'] = gmp_strval(gmp_add($return['low'], $maxHosts)); } # return result array low/high return $return; }