if ($type == "IPv4") { $maxMask = "30"; $type = 0; } else { $maxMask = "126"; $type = 1; } $n = 2; # step $m = 0; # array id for ($mask = $subnet['mask'] + 1; $mask <= $maxMask; $mask++) { # set vars $opts[$m]['mask'] = $mask; $opts[$m]['number'] = $n; $opts[$m]['max'] = MaxHosts($mask, $type); # next $m++; $n = $n * 2; # max number = 16! if ($n > 256) { $mask = 1000; } } ?> <!-- header --> <div class="pHeader"><?php print _('Split subnet'); ?>
/** * ipCalc calculations */ function calculateIpCalcResult($cidr) { /* first verify address type */ $type = IdentifyAddress($cidr); /* IPv4 */ if ($type == "IPv4") { $net = Net_IPv4::parseAddress($cidr); //set ip address type $out['Type'] = 'IPv4'; //calculate network details $out['IP address'] = $net->ip; // 192.168.0.50 $out['Network'] = $net->network; // 192.168.0.0 $out['Broadcast'] = $net->broadcast; // 192.168.255.255 $out['Subnet bitmask'] = $net->bitmask; // 16 $out['Subnet netmask'] = $net->netmask; // 255.255.0.0 $out['Subnet wildcard'] = long2ip(~ip2long($net->netmask)); //0.0.255.255 //calculate min/max IP address $out['Min host IP'] = long2ip(ip2long($out['Network']) + 1); $out['Max host IP'] = long2ip(ip2long($out['Broadcast']) - 1); $out['Number of hosts'] = ip2long($out['Broadcast']) - ip2long($out['Min host IP']); //subnet class $out['Subnet Class'] = checkIpv4AddressType($out['Network'], $out['Broadcast']); //if IP == subnet clear the Host fields if ($out['IP address'] == $out['Network']) { $out['IP address'] = "/"; } } else { //set ip address type $out['Type'] = 'IPv6'; //calculate network details /* $out['Host address'] = Net_IPv6::removeNetmaskSpec ( $cidr ); */ $out['Host address'] = $cidr; $out['Host address'] = Net_IPv6::compress($out['Host address'], 1); $out['Host address (uncompressed)'] = Net_IPv6::uncompress($out['Host address']); $mask = Net_IPv6::getNetmaskSpec($cidr); $subnet = Net_IPv6::getNetmask($cidr); $out['Subnet prefix'] = Net_IPv6::compress($subnet) . '/' . $mask; $out['Prefix length'] = Net_IPv6::getNetmaskSpec($cidr); // get reverse DNS entries $out['Host Reverse DNS'] = calculateReverseDNS6($out['Host address (uncompressed)']); $out['Subnet Reverse DNS'] = calculateReverseDNS6($subnet, $mask); //if IP == subnet clear the Host fields and Host Reverse DNS if ($out['Host address'] == $out['Subnet prefix']) { $out['Host address'] = '/'; $out['Host address (uncompressed)'] = '/'; unset($out['Host Reverse DNS']); } //min / max hosts $maxIp = gmp_strval(gmp_add(gmp_sub(gmp_pow(2, 128 - $mask), 1), ip2long6($subnet))); $out['Min host IP'] = long2ip6(gmp_strval(gmp_add(ip2long6($subnet), 1))); $out['Max host IP'] = long2ip6($maxIp); $out['Number of hosts'] = MaxHosts($mask, 1); //address type $out['Address type'] = Net_IPv6::getAddressType($cidr); $out['Address type'] = checkIpv6AddressType($out['Address type']); } /* return results */ return $out; }
<?php # get array of IP addresses $ipVisual = getIpAddressesForVisual($subnetId); # if empty if (sizeof($ipVisual) == '0') { $ipVisual = array("a"); } # show squares to display free/used subnet if (sizeof($slaves) == 0 && $type == 0 && $SubnetDetails['mask'] != "31" && $SubnetDetails['mask'] != '32') { print "<br><h4>" . _('Visual subnet display') . " <i class='icon-gray icon-info-sign' rel='tooltip' data-html='true' title='" . _('Click on IP address box<br>to manage IP address') . "!'></i></h4><hr>"; print "<div class='ip_vis'>"; # get max hosts $max = MaxHosts($SubnetDetails['mask'], $type); $max = $SubnetDetails['subnet'] + $max; # set start $start = gmp_strval(gmp_add($SubnetDetails['subnet'], 1)); for ($m = $start; $m <= $max; $m = gmp_strval(gmp_add($m, 1))) { # already exists if (array_key_exists((string) $m, $ipVisual)) { # fix for empty states - if state is disabled, set to active if (strlen($ipVisual[$m]['state']) == 0) { $ipVisual[$m]['state'] = 1; } $class = $ipVisual[$m]['state']; $id = (int) $ipVisual[$m]['id']; $action = 'all-edit'; # tooltip $title = transform2long($ipVisual[$m]['ip_addr']); if (strlen($ipVisual[$m]['dns_name']) > 0) { $title .= "<br>" . $ipVisual[$m]['dns_name'];
$maskDiff = 8; break; } $mask = $subnetOld['mask'] + $maskDiff; # set number of subnets $subNum = pow(2, $maskDiff); # get mas hosts per subnet $type = IdentifyAddress(transform2long($subnetOld['subnet'])); # type for max resize if ($type == "IPv4") { $type = "0"; } else { $type = "1"; } # set max hosts per new subnet $maxHosts = MaxHosts($mask, $type); $maxHosts = gmp_strval(gmp_add(2, $maxHosts)); # create array of new subnets based on number of subnets (number) for ($m = 0; $m < $subNum; $m++) { $newsubnets[$m] = $subnetOld; $newsubnets[$m]['id'] = $m; $newsubnets[$m]['mask'] = $mask; # if group is selected rewrite the masterSubnetId! if ($_POST['group'] == "yes") { $newsubnets[$m]['masterSubnetId'] = $subnetOld['id']; } # recalculate subnet if ($m > 0) { $newsubnets[$m]['subnet'] = gmp_strval(gmp_add($newsubnets[$m - 1]['subnet'], $maxHosts)); } }
/** * Calculate subnet details * * Calculate subnet details based on input! * * We must provide used hosts and subnet mask to calculate free hosts, and subnet to identify type * * $bcastfix = remove bcast and subnets from stats (subnetDetailsGraph) */ function calculateSubnetDetailsNew($subnet, $bitmask, $online, $offline, $reserved, $dhcp, $bcastfix = 0) { $details['online'] = $online; // number of online hosts $details['reserved'] = $reserved; // number of reserved hosts $details['offline'] = $offline; // number of offline hosts $details['dhcp'] = $dhcp; // number of dhcp hosts $details['used'] = gmp_strval(gmp_add($online, $reserved)); $details['used'] = gmp_strval(gmp_add($details['used'], $offline)); $details['used'] = gmp_strval(gmp_add($details['used'], $dhcp)); // calculate max hosts if (IdentifyAddress($subnet) == "IPv4") { $type = 0; } else { $type = 1; } $details['maxhosts'] = MaxHosts($bitmask, $type); $details['maxhosts'] = gmp_strval(gmp_sub($details['maxhosts'], $bcastfix)); // calculate free hosts $details['freehosts'] = gmp_strval(gmp_sub($details['maxhosts'], $details['used'])); //reset maxhosts for /31 and /32 subnets if (gmp_cmp($details['maxhosts'], 1) == -1) { $details['maxhosts'] = "1"; } // calculate use percentage $details['freehosts_percent'] = round($details['freehosts'] * 100 / $details['maxhosts'], 2); $details['used_percent'] = round($details['used'] * 100 / $details['maxhosts'], 2); $details['online_percent'] = round($details['online'] * 100 / $details['maxhosts'], 2); $details['reserved_percent'] = round($details['reserved'] * 100 / $details['maxhosts'], 2); $details['offline_percent'] = round($details['offline'] * 100 / $details['maxhosts'], 2); $details['dhcp_percent'] = round($details['dhcp'] * 100 / $details['maxhosts'], 2); return $details; }
/** * Calculate subnet details accounting for active hosts * * Calculate subnet details based on input! * * We must provide used hosts and subnet mask to calculate free hosts, and subnet to identify type * * $bcastfix = remove bcast and subnets from stats (subnetDetailsGraph) */ function calculateSubnetDetailsNewActive($subnet, $bitmask, $online, $warning, $error, $neutral, $disconnected, $offline, $reserved, $dhcp, $bcastfix = 0) { $details['online'] = $online; // number of online hosts $details['warning'] = $warning; // number of warning hosts $details['error'] = $error; // number of error hosts $details['neutral'] = $neutral; // number of neutral hosts $details['disconnected'] = $disconnected; // number of disconnected hosts $details['reserved'] = $reserved; // number of reserved hosts $details['offline'] = $offline; // number of offline hosts $details['dhcp'] = $dhcp; // number of dhcp hosts $details['used'] = gmp_strval(gmp_add($online, $warning)); $details['used'] = gmp_strval(gmp_add($details['used'], $error)); $details['used'] = gmp_strval(gmp_add($details['used'], $neutral)); $details['used'] = gmp_strval(gmp_add($details['used'], $disconnected)); $details['used'] = gmp_strval(gmp_add($details['used'], $reserved)); $details['used'] = gmp_strval(gmp_add($details['used'], $offline)); $details['used'] = gmp_strval(gmp_add($details['used'], $dhcp)); // calculate max hosts if (IdentifyAddress($subnet) == "IPv4") { $type = 0; } else { $type = 1; } $details['maxhosts'] = MaxHosts($bitmask, $type); $details['maxhosts'] = gmp_strval(gmp_sub($details['maxhosts'], $bcastfix)); // calculate free hosts $details['freehosts'] = gmp_strval(gmp_sub($details['maxhosts'], $details['used'])); //reset maxhosts for /31 and /32 subnets if (gmp_cmp($details['maxhosts'], 1) == -1) { $details['maxhosts'] = "1"; } // calculate use percentage $details['freehosts_percent'] = round($details['freehosts'] * 100 / $details['maxhosts'], 2); $details['used_percent'] = round($details['used'] * 100 / $details['maxhosts'], 2); $details['online_percent'] = round($details['online'] * 100 / $details['maxhosts'], 2); $details['warning_percent'] = round($details['warning'] * 100 / $details['maxhosts'], 2); $details['error_percent'] = round($details['error'] * 100 / $details['maxhosts'], 2); $details['neutral_percent'] = round($details['neutral'] * 100 / $details['maxhosts'], 2); $details['disconnected_percent'] = round($details['disconnected'] * 100 / $details['maxhosts'], 2); $details['reserved_percent'] = round($details['reserved'] * 100 / $details['maxhosts'], 2); $details['offline_percent'] = round($details['offline'] * 100 / $details['maxhosts'], 2); $details['dhcp_percent'] = round($details['dhcp'] * 100 / $details['maxhosts'], 2); return $details; }
if (IdentifyAddress($master['subnet']) == "IPv4") { $type = 0; } else { $type = 1; } # set $diffAdd based on mask! if ($slaves[$m - 1]['mask'] == "32") { $diffAdd = 0; } elseif ($slaves[$m - 1]['mask'] == "31") { $diffAdd = 0; } else { $diffAdd = 2; } # calculate end of master and last slave $maxh_m = gmp_strval(gmp_add(MaxHosts($master['mask'], $type), 2)); $maxh_s = gmp_strval(gmp_add(MaxHosts($slave['mask'], $type), $diffAdd)); $max_m = gmp_strval(gmp_add($master['subnet'], $maxh_m)); $max_s = gmp_strval(gmp_add($slave['subnet'], $maxh_s)); $diff = gmp_strval(gmp_sub($max_m, $max_s)); # if slave stop < master stop print free space if ($max_m > $max_s) { print "<tr class='success'>"; print "\t<td></td>"; print "\t<td class='small description'><a href='#' data-sectionId='{$section['id']}' data-masterSubnetId='{$subnetId}' class='btn btn-sm btn-default createfromfree' data-cidr='" . getFirstPossibleSubnet(transform2long(gmp_strval(gmp_sub($max_m, $diff))), $diff, false) . "'><i class='fa fa-plus'></i></a> " . _('Free space') . "</td>"; print "\t<td colspan='5'>" . transform2long(gmp_strval(gmp_sub($max_m, $diff))) . " - " . transform2long(gmp_strval(gmp_sub($max_m, 1))) . " ( {$diff} )</td>"; print "</tr>"; } } } # graph include_once 'subnetDetailsGraph.php';