From 9a6b68cf9ac0bbbe37bdcb13868a3cf2b81daa30 Mon Sep 17 00:00:00 2001
From: "Namhyeon, Go"
php-httpproxy/' . PHP_HTTPPROXY_VERSION . ' (Server; PHP ' . phpversion() . '; Caterpillar; abuse@catswords.net)'); +define("DEFAULT_USER_AGENT", 'php-httpproxy/' . PHP_HTTPPROXY_VERSION . ' (Server; PHP ' . phpversion() . '; Caterpillar; abuse@catswords.net)'); error_reporting(E_ALL); ini_set("display_errors", 0); @@ -25,7 +25,7 @@ header('Access-Control-Allow-Methods: *'); header("Access-Control-Allow-Headers: *"); if (strpos($_SERVER['HTTP_USER_AGENT'], "php-httpproxy/") !== 0 && strpos($_SERVER['HTTP_X_USER_AGENT'], "php-httpproxy/") !== 0) { - exit('
' . DEFAULT_USER_AGENT . '
'); + exit('' . $_SERVER['HTTP_USER_AGENT'] . '
' . DEFAULT_USER_AGENT . '
'); } function jsonrpc2_cast_to_array($data) { @@ -86,6 +86,23 @@ function fatal_handler() { } register_shutdown_function("fatal_handler"); +function load_script($data) { + $loaded_script = false; + + $fh = tmpfile(); + if ($fh !== false) { + if (!(strpos($data, "") !== false)) { + $data = ""; + } + fwrite($fh, $data); + $path = stream_get_meta_data($fh)['uri']; + $loaded_script = include($path); + fclose($fh); + } + + return $loaded_script; +} + // https://stackoverflow.com/questions/16934409/curl-as-proxy-deal-with-https-connect-method // https://stackoverflow.com/questions/12433958/how-to-parse-response-headers-in-php function parse_headers($str) { // Parses HTTP headers into an array @@ -434,7 +451,7 @@ function relay_fetch_url($params) { } // check it is POST request - if ($data == "POST") { + if ($method == "POST") { curl_setopt($ch, CURLOPT_POSTFIELDS, jsonrpc2_cast_to_array($data)); curl_setopt($ch, CURLOPT_POST, true); } @@ -493,7 +510,6 @@ function relay_get_geolocation() { } } - function relay_invoke_method($params) { $callback = $params['callback']; $requires = jsonrpc2_cast_to_array($params['requires']); @@ -501,19 +517,15 @@ function relay_invoke_method($params) { foreach($requires as $required_url) { try { - $result = relay_fetch_url($required_url); - if ($result['success']) { - $fh = tmpfile(); - if ($fh !== false) { - fwrite($fh, $result['data']); - $path = stream_get_meta_data($fh)['uri']; - @require($path); - fclose($fh); - @unlink($path); - } + $result = relay_fetch_url(array( + "url" => $required_url + )); + if ($result['success'] && $result['result']['status'] == 200) { + load_script($result['result']['data']); } } catch (Exception $e) { // ignore an exception + //echo $e->message; } }