// dead hosts // get scan type (update or discovery) // get subnet to be scanned from argument1 $argv[1] // get subnetId from $argv2 $scanType = $argv[1]; $subnetFull = $argv[2]; $subnetId = $argv[3]; $subTemp = explode("/", $subnetFull); $subnet = $subTemp[0]; $mask = $subTemp[1]; /* for discovery ping */ if ($scanType == "discovery") { // get all existing IP addresses $addresses = getIpAddressesBySubnetId($subnetId); // set start and end IP address $calc = calculateSubnetDetailsNew($subnet, $mask, 0, 0, 0, 0); $max = $calc['maxhosts']; // we should support only up to 4094 hosts! if ($max - sizeof($addresses) > 4094) { $res['errors'] = "Scanning from GUI is only available for subnets up to /20 or 4094 hosts!"; $res = json_encode($res); print_r($res); die; } // loop and get all IP addresses for ping for ($m = 1; $m <= $max; $m++) { $ip[] = transform2decimal($subnet) + $m; } // remove already existing foreach ($addresses as $a) { $key = array_search($a['ip_addr'], $ip);
} else { if ($ip['state'] == "1") { $out['online']++; } else { if ($ip['state'] == "2") { $out['reserved']++; } else { if ($ip['state'] == "3") { $out['dhcp']++; } } } } } # get details $details = calculateSubnetDetailsNew($SubnetDetails['subnet'], $SubnetDetails['mask'], $out['online'], $out['offline'], $out['reserved'], $out['dhcp'], $d); ?> <!-- charts --> <script language="javascript" type="text/javascript" src="js/flot/jquery.flot.js"></script> <script language="javascript" type="text/javascript" src="js/flot/jquery.flot.pie.js"></script> <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="js/flot/excanvas.min.js"></script><![endif]--> <script type="text/javascript"> $(function () { var data = [ <?php if ($details['freehosts_percent'] > 0) { $details['freehosts_percent'] = str_replace(",", ".", $details['freehosts_percent']);
require_once '../../../functions/functions.php'; /* verify that user is logged in */ isUserAuthenticated(true); /* verify that user has write permissions for subnet */ $subnetPerm = checkSubnetPermission($_REQUEST['subnetId']); if ($subnetPerm < 2) { die('<div class="alert alert-error">' . _('You do not have permissions to modify hosts in this subnet') . '!</div>'); } # verify post */ CheckReferrer(); # get subnet details $subnet = getSubnetDetailsById($_POST['subnetId']); # get all existing IP addresses $addresses = getIpAddressesBySubnetId($_POST['subnetId']); # set start and end IP address $calc = calculateSubnetDetailsNew($subnet['subnet'], $subnet['mask'], 0, 0, 0, 0); $max = $calc['maxhosts']; # loop and get all IP addresses for ping for ($m = 1; $m <= $max; $m++) { // create array of IP addresses (if they do not already exist!) if (!checkDuplicate(transform2long($subnet['subnet'] + $m), $_POST['subnetId'])) { $ip[] = $subnet['subnet'] + $m; } } # create 1 line for $argv // <eNovance> // Print a message if no host is found then exit if (count($ip) == 0) { print "<div class='alert alert-info'>All host already listed</div>"; exit; }
/** * Get all subnets to be discovered */ function getSubnetsToDiscover() { global $database; /* set query */ $query = 'select * from `subnets` where `discoverSubnet` = "1";'; /* execute */ try { $subnets = $database->getArray($query); } catch (Exception $e) { $error = $e->getMessage(); print "<div class='alert alert-danger'>" . _('Error') . ": {$error}</div>"; return false; } # set vars $ip = array(); //we store IPs to scan to this array # ok, we have subnets. Now we create array of all possible IPs for each subnet, # and remove all existing foreach ($subnets as $s) { // get all existing IP addresses $addresses = getIpAddressesBySubnetId($s['id']); // set start and end IP address $calc = calculateSubnetDetailsNew($s['subnet'], $s['mask'], 0, 0, 0, 0); // loop and get all IP addresses for ping for ($m = 1; $m <= $calc['maxhosts']; $m++) { // save to array for return $ip[$m]['ip_addr'] = $s['subnet'] + $m; $ip[$m]['subnetId'] = $s['id']; // save to array for existing check $ipCheck[$m] = $s['subnet'] + $m; } // remove already existing foreach ($addresses as $a) { $key = array_search($a['ip_addr'], $ipCheck); if ($key !== false) { unset($ip[$key]); } } } # return result return $ip; }