Esempio n. 1
0
 /**
  * Determines whether or not the supplied IP is within the supplied network.
  *
  * This function determines whether an IP address is within a network.
  * The IP address ($ip) must be supplied in dot-quad format, and the
  * network ($network) may be either a string containing a CIDR
  * formatted network definition, or a Net_IPv4 object.
  *
  * @param  string  $ip      A dot quad representation of an IP address
  * @param  string  $network A string representing the network in CIDR format or a Net_IPv4 object.
  * @return bool             true if the IP address exists within the network
  */
 function ipInNetwork($ip, $network)
 {
     if (!is_object($network) || strcasecmp(get_class($network), 'net_ipv4') != 0) {
         $network = Net_IPv4::parseAddress($network);
     }
     if (strcasecmp(get_class($network), 'pear_error') === 0) {
         return false;
     }
     $net = Net_IPv4::ip2double($network->network);
     $bcast = Net_IPv4::ip2double($network->broadcast);
     $ip = Net_IPv4::ip2double($ip);
     unset($network);
     if ($ip >= $net && $ip <= $bcast) {
         return true;
     }
     return false;
 }
 /**
  * Determines whether or not the supplied IP is within the supplied network.
  *
  * This function determines whether an IP address is within a network.
  * The IP address ($ip) must be supplied in dot-quad format, and the
  * network ($network) may be either a string containing a CIDR
  * formatted network definition, or a Net_IPv4 object.
  *
  * @param  string $ip A quad-dot representation of an IP address 
  * @param  string $network A string representing the network in CIDR format or a Net_IPv4 object.
  * @return boolean  true if the IP address exists within the network
  */
 function ipInNetwork($ip, $network)
 {
     if (!is_object($network) || get_class($network) != 'net_ipv4') {
         $network = Net_IPv4::parseAddress($network);
     }
     if (!is_object($network) || get_class($network) != 'net_ipv4') {
         return $network;
     }
     $net = Net_IPv4::ip2double($network->network);
     $bcast = Net_IPv4::ip2double($network->broadcast);
     $ip = Net_IPv4::ip2double($ip);
     unset($network);
     if ($ip >= $net && $ip <= $bcast) {
         return TRUE;
     }
     return FALSE;
     return (double) sprintf("%u", ip2long($ip));
 }
Esempio n. 3
0
function drawPool($id)
{
    $pools = fullIPUsage();
    $mypool = $pools[$id];
    $out = "";
    $out .= "<h2>" . $mypool["location"] . ": " . $mypool["ip_addr"] . "/" . $mypool["netmask"] . "</h2>";
    $out .= _("IP pool size:") . " " . $mypool["pool_size"] . "<br>";
    $out .= _("Number of SSL IP(s):") . " " . $mypool["nbr_ssl"] . "<br>";
    $out .= _("Number of dom0 IP(s):") . " " . $mypool["nbr_dom0"] . "<br>";
    $out .= _("Number of VPS IP(s):") . " " . $mypool["nbr_vps"] . "<br>";
    $out .= _("Number of dedicated IP(s):") . " " . $mypool["nbr_dedicated"] . "<br>";
    $out .= _("Total number of used IPs:") . " " . $mypool["nbr_total_used"] . "<br>";
    $out .= _("Number of IPs remaining in the pool:") . " " . $mypool["ip_remaining"] . "<br>";
    $ip_calc = new Net_IPv4();
    $ip_long = $ip_calc->ip2double($mypool["ip_addr"]);
    $out .= "<table class=\"dtcDatagrid_table_props\" border=\"1\"><tr><td class=\"dtcDatagrid_table_titles\">" . _("IP address") . "</td><td class=\"dtcDatagrid_table_titles\">" . _("Type") . "</td><td class=\"dtcDatagrid_table_titles\">" . _("Name") . "</td><td class=\"dtcDatagrid_table_titles\">" . _("Provision") . "</td></tr>";
    for ($i = 0; $i < $mypool["pool_size"]; $i++) {
        $ip = long2ip($ip_long);
        if ($i % 2) {
            $class = "dtcDatagrid_table_flds_alt";
        } else {
            $class = "dtcDatagrid_table_flds";
        }
        $out .= "<tr><td class=\"{$class}\" style=\"text-align:right;\">" . $ip . "</td>";
        if (isset($mypool["all_ips"][$ip])) {
            $all_ips = $mypool["all_ips"];
            $out .= "<td class=\"{$class}\" style=\"text-align:center;\">" . $mypool["all_ips"][$ip]["type"] . "</td>";
            if (isset($all_ips[$ip]["available"])) {
                if ($all_ips[$ip]["available"] == "yes") {
                    $av = "<b>" . _("FREE") . "</b>";
                } else {
                    $av = _("no");
                }
            } else {
                $av = "-";
            }
            switch ($all_ips[$ip]["type"]) {
                case "vps":
                    $out .= "<td class=\"{$class}\" style=\"text-align:center;\">" . $all_ips[$ip]["vps_xen_name"] . ":" . $all_ips[$ip]["vps_server_hostname"] . "</td><td class=\"{$class}\" style=\"text-align:center;\">" . $av . "</td>";
                    break;
                case "ssl":
                    $out .= "<td class=\"{$class}\" style=\"text-align:center;\">-</td><td class=\"{$class}\" style=\"text-align:center;\">" . $av . "</td>";
                    break;
                case "dedicated":
                    $out .= "<td class=\"{$class}\">" . $all_ips[$ip]["dedicated_server_hostname"] . "</td><td class=\"{$class}\" style=\"text-align:center;\">-</td>";
                    break;
                case "dom0":
                    $out .= "<td class=\"{$class}\">" . $all_ips[$ip]["hostname"] . "</td><td class=\"{$class}\" style=\"text-align:center;\">-</td>";
                    break;
                default:
                    $out .= "<td class=\"{$class}\" style=\"text-align:center;\">-</td><td class=\"{$class}\" style=\"text-align:center;\">-</td>";
                    break;
            }
            $out .= "</tr>";
        } else {
            $out .= "<td class=\"{$class}\" colspan=\"3\" style=\"text-align:center;\"><b>" . _("FREE") . "</b></td></tr>";
        }
        $ip_long++;
    }
    $out .= "</table>";
    return $out;
}