Exemplo n.º 1
0
            throw new Exception("No file {$pagefile}");
        }
        //		ob_start();
        require_once $pagefile;
        //		ob_end_clean();
        $class = ucfirst($name) . 'Page';
        if (!class_exists($class)) {
            throw new Exception("Class {$class} not found");
        }
        $page = new $class($config, $services);
        if (!$page instanceof AdminPage) {
            throw new Exception("Not an admin page");
        }
        return $page;
    }
}
try {
    $config = Server::getDefaultConfig();
    $services = new SblamServices(sblambaseconnect($config));
    Admin::process($config, $services);
} catch (Exception $e) {
    header('HTTP/1.1 500 ERR');
    header("Content-Type: text/plain;charset=UTF-8");
    if (ini_get('display_errors')) {
        echo $e;
    } else {
        echo "Error " . $e->getSourceLine();
    }
    error_log($e->getMessage() . " in " . $e->getSourceFile() . ':' . $e->getSourceLine());
    warn($e, "Died");
}
Exemplo n.º 2
0
 /** extract all IPs from request headers
 
 		@param headers $_SERVER array
 		@return array
 	*/
 static function getRequestIPs($headers = NULL, $routable = true)
 {
     if (NULL === $headers) {
         $headers = $_SERVER;
     }
     if (!isset($headers['REMOTE_ADDR'])) {
         $headers['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR'];
     }
     $out = array($headers['REMOTE_ADDR'] => true);
     // order IS important for security
     $search = array('X_FORWARDED_FOR', 'FORWARDED_FOR', 'CLIENT_IP', 'X_CLIENT_IP', 'X_CLUSTER_CLIENT_IP', 'X_FORWARDED', 'PC_REMOTE_ADDR', 'FORWARDED', 'X_WAP_CLIENT_IP', 'X_COMING_FROM', 'X_REAL_IP');
     foreach ($search as $h) {
         $h = 'HTTP_' . $h;
         if (isset($headers[$h]) && preg_match_all('!\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}!', $headers[$h], $t)) {
             foreach ($t[0] as $ip) {
                 if (!isset($out[$ip])) {
                     $out[$ip] = true;
                 }
             }
         }
     }
     foreach ($out as $ip => $whatever) {
         if (self::isPrivateOrReservedIP($ip)) {
             //d($ip,'Unroutable IP - dropping');
             unset($out[$ip]);
         }
     }
     if (count($out) > 1) {
         d('checking for proxies');
         $db = sblambaseconnect(Server::getDefaultConfig());
         $prep = $db->prepare("/*maxtime=1*/SELECT 1 FROM trustedproxies p JOIN dnscache d ON p.host = d.host WHERE d.ip = ?");
         if (!$prep) {
             throw new Exception("b0rked" . implode(',', $db->errorInfo()));
         }
         foreach ($out as $ip => $whatever) {
             if (!$prep->execute(array(sprintf("%u", ip2long($ip))))) {
                 throw new Exception("bork" . implode($prep->errorInfo()));
             }
             if (count($prep->fetchAll())) {
                 d($ip, 'found to be a trusted proxy');
                 unset($out[$ip]);
             } else {
                 d($ip, 'not a trusted proxy, bye!');
                 break;
             }
         }
     }
     return array_keys($out);
 }