Example #1
0
function post()
{
    list($headers, $kwargs) = @decode_request($_SERVER['HTTP_COOKIE']);
    $method = $kwargs['method'];
    $url = $kwargs['url'];
    $body = @file_get_contents('php://input');
    if ($body) {
        $headers['Content-Length'] = strval(strlen($body));
    }
    $headers['Connection'] = 'close';
    $timeout = $GLOBALS['__timeout__'];
    $curl_opt = array();
    $curl_opt[CURLOPT_RETURNTRANSFER] = true;
    $curl_opt[CURLOPT_BINARYTRANSFER] = true;
    $curl_opt[CURLOPT_HEADER] = false;
    $curl_opt[CURLOPT_HEADERFUNCTION] = 'header_function';
    $curl_opt[CURLOPT_WRITEFUNCTION] = 'write_function';
    $curl_opt[CURLOPT_FAILONERROR] = true;
    $curl_opt[CURLOPT_FOLLOWLOCATION] = false;
    $curl_opt[CURLOPT_CONNECTTIMEOUT] = $timeout;
    $curl_opt[CURLOPT_TIMEOUT] = $timeout;
    $curl_opt[CURLOPT_SSL_VERIFYPEER] = false;
    $curl_opt[CURLOPT_SSL_VERIFYHOST] = false;
    switch (strtoupper($method)) {
        case 'HEAD':
            $curl_opt[CURLOPT_NOBODY] = true;
            break;
        case 'GET':
            break;
        case 'POST':
            $curl_opt[CURLOPT_POST] = true;
            $curl_opt[CURLOPT_POSTFIELDS] = $body;
            break;
        case 'PUT':
        case 'DELETE':
            $curl_opt[CURLOPT_CUSTOMREQUEST] = $method;
            $curl_opt[CURLOPT_POSTFIELDS] = $body;
            break;
        default:
            echo 'Invalid Method: ' . $method;
            exit(-1);
    }
    $header_array = array();
    foreach ($headers as $key => $value) {
        if ($key) {
            $header_array[] = join('-', array_map('ucfirst', explode('-', $key))) . ': ' . $value;
        }
    }
    $curl_opt[CURLOPT_HTTPHEADER] = $header_array;
    $ch = curl_init($url);
    curl_setopt_array($ch, $curl_opt);
    $ret = curl_exec($ch);
    //$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $errno = curl_errno($ch);
    if ($errno && !isset($GLOBALS['header_length'])) {
        echo $errno . ': ' . curl_error($ch);
    }
    curl_close($ch);
}
Example #2
0
function post()
{
    list($method, $url, $headers, $kwargs, $body) = @decode_request(@file_get_contents('php://input'));
    $password = $GLOBALS['__password__'];
    if ($password) {
        if (!isset($kwargs['password']) || $password != $kwargs['password']) {
            header("HTTP/1.0 403 Forbidden");
            echo message_html('403 Forbidden', 'Wrong Password', "please edit proxy.ini");
            exit(-1);
        }
    }
    $hostsdeny = $GLOBALS['__hostsdeny__'];
    if ($hostsdeny) {
        $urlparts = parse_url($url);
        $host = $urlparts['host'];
        foreach ($hostsdeny as $pattern) {
            if (substr($host, strlen($host) - strlen($pattern)) == $pattern) {
                echo_content("HTTP/1.0 403\r\n\r\n" . message_html('403 Forbidden', "hostsdeny matched({$host})", $url));
                exit(-1);
            }
        }
    }
    if ($body) {
        $headers['Content-Length'] = strval(strlen($body));
    }
    if (isset($headers['Connection'])) {
        $headers['Connection'] = 'close';
    }
    $header_array = array();
    foreach ($headers as $key => $value) {
        $header_array[] = join('-', array_map('ucfirst', explode('-', $key))) . ': ' . $value;
    }
    $timeout = $GLOBALS['__timeout__'];
    $curl_opt = array();
    switch (strtoupper($method)) {
        case 'HEAD':
            $curl_opt[CURLOPT_NOBODY] = true;
            break;
        case 'GET':
            break;
        case 'POST':
            $curl_opt[CURLOPT_POST] = true;
            $curl_opt[CURLOPT_POSTFIELDS] = $body;
            break;
        case 'PUT':
        case 'DELETE':
            $curl_opt[CURLOPT_CUSTOMREQUEST] = $method;
            $curl_opt[CURLOPT_POSTFIELDS] = $body;
            break;
        default:
            echo_content("HTTP/1.0 502\r\n\r\n" . message_html('502 Urlfetch Error', 'Invalid Method: ' . $method, $url));
            exit(-1);
    }
    $curl_opt[CURLOPT_HTTPHEADER] = $header_array;
    $curl_opt[CURLOPT_RETURNTRANSFER] = true;
    $curl_opt[CURLOPT_BINARYTRANSFER] = true;
    $curl_opt[CURLOPT_HEADER] = false;
    $curl_opt[CURLOPT_HEADERFUNCTION] = 'curl_header_function';
    $curl_opt[CURLOPT_WRITEFUNCTION] = 'curl_write_function';
    $curl_opt[CURLOPT_FAILONERROR] = false;
    $curl_opt[CURLOPT_FOLLOWLOCATION] = false;
    $curl_opt[CURLOPT_CONNECTTIMEOUT] = $timeout;
    $curl_opt[CURLOPT_TIMEOUT] = $timeout;
    $curl_opt[CURLOPT_SSL_VERIFYPEER] = false;
    $curl_opt[CURLOPT_SSL_VERIFYHOST] = false;
    $ch = curl_init($url);
    curl_setopt_array($ch, $curl_opt);
    $ret = curl_exec($ch);
    $errno = curl_errno($ch);
    if ($GLOBALS['__content__']) {
        echo_content($GLOBALS['__content__']);
    } else {
        if ($errno) {
            if (!headers_sent()) {
                header('Content-Type: ' . $__content_type__);
            }
            $content = "HTTP/1.0 502\r\n\r\n" . message_html('502 Urlfetch Error', "PHP Urlfetch Error curl({$errno})", curl_error($ch));
            echo_content($content);
        }
    }
    curl_close($ch);
}
<?php

decode_request();
function decode_request()
{
    $input = file_get_contents('php://input');
    $data = json_decode($input, true);
    if (!is_array($data)) {
        return;
    }
    foreach ($data as $key => $value) {
        $_REQUEST[$key] = $value;
    }
}
set_session_handle($config);
function set_session_handle($config)
{
    require dirname(__DIR__) . '/libs/MemcacheSessionHandle.class.php';
    $sessionHandle = new MemcacheSessionHandle($config);
    session_set_save_handler($sessionHandle);
}
Example #4
0
function post()
{
    list($method, $url, $headers, $kwargs, $body) = @decode_request(@file_get_contents('php://input'));
    $password = $GLOBALS['__password__'];
    if ($password) {
        if (!isset($kwargs['password']) || $password != $kwargs['password']) {
            header("HTTP/1.0 403 Forbidden");
            echo '403 Forbidden';
            exit(-1);
        }
    }
    if ($body) {
        $headers['Content-Length'] = strval(strlen($body));
    }
    $headers['Connection'] = 'close';
    $timeout = $GLOBALS['__timeout__'];
    $curl_opt = array();
    $curl_opt[CURLOPT_RETURNTRANSFER] = true;
    $curl_opt[CURLOPT_BINARYTRANSFER] = true;
    $curl_opt[CURLOPT_HEADER] = false;
    $curl_opt[CURLOPT_HEADERFUNCTION] = 'header_function';
    $curl_opt[CURLOPT_WRITEFUNCTION] = 'write_function';
    $curl_opt[CURLOPT_FAILONERROR] = true;
    $curl_opt[CURLOPT_FOLLOWLOCATION] = false;
    $curl_opt[CURLOPT_CONNECTTIMEOUT] = $timeout;
    $curl_opt[CURLOPT_TIMEOUT] = $timeout;
    $curl_opt[CURLOPT_SSL_VERIFYPEER] = false;
    $curl_opt[CURLOPT_SSL_VERIFYHOST] = false;
    switch (strtoupper($method)) {
        case 'HEAD':
            $curl_opt[CURLOPT_NOBODY] = true;
            break;
        case 'GET':
            break;
        case 'POST':
            $curl_opt[CURLOPT_POST] = true;
            $curl_opt[CURLOPT_POSTFIELDS] = $body;
            break;
        case 'PUT':
        case 'DELETE':
            $curl_opt[CURLOPT_CUSTOMREQUEST] = $method;
            $curl_opt[CURLOPT_POSTFIELDS] = $body;
            break;
        default:
            echo 'Invalid Method: ' . var_export($method, true);
            exit(-1);
    }
    $header_array = array();
    foreach ($headers as $key => $value) {
        if ($key) {
            $header_array[] = join('-', array_map('ucfirst', explode('-', $key))) . ': ' . $value;
        }
    }
    $curl_opt[CURLOPT_HTTPHEADER] = $header_array;
    $ch = curl_init($url);
    curl_setopt_array($ch, $curl_opt);
    $ret = curl_exec($ch);
    $errno = curl_errno($ch);
    if ($errno && !isset($GLOBALS['__status__'])) {
        echo error_html("cURL({$errno})", "PHP Urlfetch Error: {$method}", curl_error($ch));
    }
    curl_close($ch);
}