/** * Default server error output * * @param string $errno * @param string $errstr * @param string $errfile * @param string $errline * @return string */ function server_error($errno, $errstr, $errfile = null, $errline = null) { $is_http_error = http_response_status_is_valid($errno); $html = render_error($errno, $errstr, $errfile, $errline, $is_http_error); return error_html($html); }
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); }