function post() { global $__password__; $request = @gzuncompress(@file_get_contents('php://input')); if ($request === False) { return print_notify($method, $url, 500, 'OOPS! gzuncompress php://input error!'); } $request = decode_data($request); $method = $request['method']; $url = $request['url']; $payload = $request['payload']; $dns = $request['dns']; if ($__password__ && $__password__ != $request['password']) { return print_notify($method, $url, 403, 'Wrong password.'); } if (substr($url, 0, 4) != 'http') { return print_notify($method, $url, 501, 'Unsupported Scheme'); } $FetchMax = 3; $FetchMaxSize = 1024 * 1024; $Deadline = array(0 => 16, 1 => 32); $deadline = $Deadline[0]; $headers = array(); foreach (explode("\r\n", $request['headers']) as $line) { $pair = explode(':', $line, 2); $headers[trim($pair[0])] = trim($pair[1]); } $headers['connection'] = 'close'; $fetchrange = 'bytes=0-' . strval($FetchMaxSize - 1); if (array_key_exists('range', $headers)) { preg_match('/(\\d+)?-(\\d+)?/', $headers['range'], $matches, PREG_OFFSET_CAPTURE); $start = $matches[1][0]; $end = $matches[2][0]; if ($start || $end) { if (!$start and intval($end) > $FetchMaxSize) { $end = '1023'; } else { if (!$end || intval($end) - intval($start) + 1 > $FetchMaxSize) { $end = strval($FetchMaxSize - 1 + intval($start)); } } $fetchrange = 'bytes=' . $start . '-' . $end; } } if ($dns) { preg_match('@://(.+?)[:/]@', $url, $matches, PREG_OFFSET_CAPTURE); if ($matches[1][0]) { $headers['host'] = $matches[1][0]; $url = preg_replace('@://.+?([:/])@', "://{$dns}\\1", $url); } //error_exit('matches', $matches); } //error_exit('url', $url, 'headers:', $headers); $errors = array(); for ($i = 0; $i < $FetchMax; $i++) { $response = urlfetch($url, $payload, $method, $headers, False, $deadline, False); $status_code = $response['status_code']; if (200 <= $status_code && $status_code < 400) { return print_response($status_code, $response['headers'], $response['content']); } else { if ($response['error']) { $errors[] = $response['error']; } else { $errors[] = 'URLError: ' . $status_code; } } } print_notify($request['method'], $request['url'], 502, 'PHP Fetch Server Failed: ' . var_export($errors, true)); }
$res = urlfetch($uri, null, array('Cookie:' => $cookierawdata)); if (!$res) { raiseErr(); } } else { if ($_SERVER["REQUEST_METHOD"] == 'POST') { $postdata = array(); foreach ($_POST as $key => $val) { $postdata[$key] = urlencode($val); } if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { $postdata['image_filename'] = urlencode($_FILES['image']['name']); $imgdata = file_get_contents($_FILES['image']['tmp_name']); $postdata['image'] = urlencode(base64_decode($imgdata)); } $res = urlfetch($uri, $postdata, array('Cookie:' => $cookierawdata), 30); if (!$res) { raiseErr(); } } else { raiseErr('Only support GET or POST method'); } } foreach ($res['headers'] as $header) { header($header, false); } echo $res['body']; exit; function urlfetch($uri, $postdata = null, $headers = null, $timeout = 15) { global $proxy_name, $proxy_ip, $proxy_port, $cacheTime;