Example #1
0
File: index.php Project: runcz/lvip
    foreach ($lines as $k => $l) {
        if (false !== strpos($l, $match)) {
            $nets[$i][] = $l;
            unset($lines[$k]);
        }
    }
}
unset($i, $l, $lines, $match);
//novācam tos subnetus, kas pārklājas
foreach ($nets as $cidr => $n) {
    foreach ($n as $k => $a) {
        list($base, $trash) = explode('/', $a);
        foreach ($nets as $cidr2 => $n2) {
            if ($cidr2 < $cidr) {
                foreach ($n2 as $k2 => $s) {
                    if (net_match($s, $base)) {
                        if (isset($_GET['v'])) {
                            echo $a . ' ietilpst iekš ' . $s . "\n";
                        }
                        unset($nets[$cidr][$k]);
                    }
                }
            }
        }
    }
}
if (isset($_GET['v'])) {
    echo "\n\n";
}
//savienojam tos subnetus, kas ir viens aiz otra
$cidr_maskas = array_keys($nets);
Example #2
0
/**
 * Twitter api proxy
 */
/**
 * Determines if a network in the form of 192.168.17.1/16 or
 * 127.0.0.1/255.255.255.255 or 10.0.0.1 matches a given ip
 * @param $network The network and mask
 * @param $ip The ip to check
 * @return bool true or false
 */
function net_match($network, $ip)
{
    $ip_arr = explode('/', $network);
    $network_long = ip2long($ip_arr[0]);
    $x = ip2long($ip_arr[1]);
    $mask = long2ip($x) == $ip_arr[1] ? $x : 4294967295.0 << 32 - $ip_arr[1];
    $ip_long = ip2long($ip);
    return ($ip_long & $mask) == ($network_long & $mask);
}
if (isset($_SERVER['REMOTE_ADDR'])) {
    $validIPs = array('129.93.0.0/16', '65.123.32.0/19', '64.39.240.0/20', '216.128.208.0/20', '67.208.34.248/249');
    foreach ($validIPs as $range) {
        if (net_match($range, $_SERVER['REMOTE_ADDR'])) {
            $result = file_get_contents($_GET['u']);
            header('Content-Type:·application/json;·charset=utf-8');
            echo $result;
            exit;
        }
    }
}
exit;
    $x = ip2long($ip_arr[1]);
    $mask = long2ip($x) == $ip_arr[1] ? $x : 0xffffffff << 32 - $ip_arr[1];
    $ip_long = ip2long($ip);
    // echo ">".$ip_arr[1]."> ".decbin($mask)."\n";
    return ($ip_long & $mask) == ($network_long & $mask);
}
function fullpath($file)
{
    $host = $_SERVER['HTTP_HOST'];
    $uri = rtrim($_SERVER['PHP_SELF'], "/\\");
    $uri = str_replace(basename($_SERVER['PHP_SELF']), "", $uri);
    return "http://{$host}{$uri}{$file}";
}
$is_ll = FALSE;
foreach ($ll_subnets as $network) {
    if (net_match($network, $_SERVER['REMOTE_ADDR'])) {
        $is_ll = TRUE;
        break;
    }
}
// -- Process all request headers -- //
$request = new http_request();
$nheaders = array_map('strtolower', $request->headers());
$headers = array();
foreach ($nheaders as $key => $value) {
    $headers[strtolower($key)] = $value;
}
// -- Put Headers into Variables --//
// -- Simulator Information
$ll_grid = $headers['x-secondlife-shard'];
$ll_region_name = $headers['x-secondlife-region'];
Example #4
0
/**
 * @return bool
 */
function is_rpc_client_allowed()
{
    // If no server address supplied
    if (!isset($_SERVER['SERVER_ADDR']) || empty($_SERVER['SERVER_ADDR'])) {
        return true;
    }
    // Get list of allowed clients
    if (defined('RPC_ALLOWED_CLIENTS') && !RPC_ALLOWED_CLIENTS === false) {
        // Read in space separated list
        $clients = explode(' ', constant('RPC_ALLOWED_CLIENTS'));
        // Validate each client type
        foreach ($clients as $client) {
            if ($client == 'allprivate' && (net_match('10.0.0.0/8', $_SERVER['SERVER_ADDR']) || net_match('172.16.0.0/12', $_SERVER['SERVER_ADDR']) || net_match('192.168.0.0/16', $_SERVER['SERVER_ADDR']))) {
                return true;
            }
            if ($client == 'local24') {
                // Get machine IP address from the hostname
                $ip = gethostbyname(rtrim(gethostname()));
                // Change IP address to a /24 network
                $ipsplit = explode('.', $ip);
                $ipsplit[3] = '0';
                $ip = implode('.', $ipsplit);
                if (net_match("{$ip}/24", $_SERVER['SERVER_ADDR'])) {
                    return true;
                }
            }
            // All any others
            if (net_match($client, $_SERVER['SERVER_ADDR'])) {
                return true;
            }
            // Try hostname
            $iplookup = gethostbyname($client);
            if ($client !== $iplookup && net_match($iplookup, $_SERVER['SERVER_ADDR'])) {
                return true;
            }
        }
        // If all else fails
        return false;
    } else {
        return false;
    }
}
function current_ip_ignored()
{
    $subnets = explode("\n", get_option('wp_power_stats_ip_exclusion'));
    $current_ip = wp_power_stats_get_ip();
    foreach ($subnets as $subnet) {
        $subnet = trim($subnet);
        if (strlen($subnet) > 6) {
            if (net_match($subnet, $current_ip)) {
                return true;
            }
        }
    }
    return false;
}
Example #6
0
         $Cache->commit_transaction(0);
     }
     if (!empty($Country) && $LoggedUser['Country'] != $Country) {
         $CurCountry = db_string($LoggedUser['Country']);
         $NewCountry = db_string($Country);
         if (!empty($CurCountry) && !empty($NewCountry)) {
             send_irc("privmsg #watched :!mod Country change? {$CurCountry} -> {$NewCountry} | http://musiceye.tv/user.php?id={$LoggedUser['ID']} (" . $LoggedUser['Username'] . ")");
         }
         $DB->query("UPDATE users_history_country SET\n\t\t\t\t\t\t\t\tEndTime='" . sqltime() . "'\n\t\t\t\t\t\t\t\tWHERE EndTime IS NULL\n\t\t\t\t\t\t\t\tAND UserID='{$LoggedUser['ID']}'\n\t\t\t\t\t\t\t\tAND CountryCode='{$CurCountry}'");
         $DB->query("INSERT IGNORE INTO users_history_country\n\t\t\t\t\t\t\t\t(UserID, CountryCode, StartTime) VALUES\n\t\t\t\t\t\t\t\t('{$LoggedUser['ID']}', '{$NewCountry}', '" . sqltime() . "')");
         $DB->query("UPDATE users_main SET Country='{$NewCountry}' WHERE ID='{$LoggedUser['ID']}'");
         $Cache->begin_transaction('user_info_heavy_' . $LoggedUser['ID']);
         $Cache->update_row(false, array('Country' => $NewCountry));
         $Cache->commit_transaction(0);
     }
     if (!empty($Cidr) && $LoggedUser['Cidr'] != $CIDR || !net_match($CIDR, $LoggedUser['IP'])) {
         $CurCidr = db_string($LoggedUser['CIDR']);
         $NewCidr = db_string($CIDR);
         if (!empty($CurCidr) && !empty($NewCidr)) {
             send_irc("privmsg #watched :!mod Cidr change? {$CurCidr} -> {$NewCidr} | http://musiceye.tv/user.php?id={$LoggedUser['ID']} (" . $LoggedUser['Username'] . ")");
         }
         $DB->query("UPDATE users_history_cidr SET\n\t\t\t\t\t\t\t\tEndTime='" . sqltime() . "'\n\t\t\t\t\t\t\t\tWHERE EndTime IS NULL\n\t\t\t\t\t\t\t\tAND UserID='{$LoggedUser['ID']}'\n\t\t\t\t\t\t\t\tAND Cidr='{$CurCidr}'");
         $DB->query("INSERT IGNORE INTO users_history_cidr\n\t\t\t\t\t\t\t\t(UserID, Cidr, StartTime) VALUES\n\t\t\t\t\t\t\t\t('{$LoggedUser['ID']}', '{$NewCidr}', '" . sqltime() . "')");
         $DB->query("UPDATE users_main SET Cidr='{$NewCidr}' WHERE ID='{$LoggedUser['ID']}'");
         $Cache->begin_transaction('user_info_heavy_' . $LoggedUser['ID']);
         $Cache->update_row(false, array('Cidr' => $NewCidr));
         $Cache->commit_transaction(0);
     }
 }
 // Get stylesheets
 $Stylesheets = $Cache->get_value('stylesheets');