From 17f1753c1c0c2b6cfa64bd718db693240d56576d Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Tue, 25 Jun 2024 16:30:41 +0900 Subject: [PATCH] Update methods relay_get_geolocation, relay_fetch_url --- assets/php/index.php | 42 +++++++++++++++++++++++++++++++++++------- console.html | 14 ++++++++++++++ 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/assets/php/index.php b/assets/php/index.php index 1b6c715..8f76b0f 100644 --- a/assets/php/index.php +++ b/assets/php/index.php @@ -9,17 +9,18 @@ * Updated at: 2024-06-25 */ -define("PHP_HTTPPROXY_VERSION", "0.1.5.22"); +define("PHP_HTTPPROXY_VERSION", "0.1.5.23"); define("DEFAULT_SOCKET_TIMEOUT", 1); define("STATEFUL_SOCKET_TIMEOUT", 30); define("MAX_EXECUTION_TIME", 0); +define("DEFAULT_USER_AGENT", $_SERVER['HTTP_USER_AGENT'] . '


php-httpproxy/' . PHP_HTTPPROXY_VERSION . ' (Server; PHP ' . phpversion() . '; Caterpillar; abuse@catswords.net)'); header('Access-Control-Allow-Origin: *'); 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('It works!

It works!

Download the client

' . $_SERVER['HTTP_USER_AGENT'] . '


php-httpproxy/' . PHP_HTTPPROXY_VERSION . ' (Server; PHP ' . phpversion() . '; Caterpillar; abuse@catswords.net)

'); + exit('It works!

It works!

Download the client

' . DEFAULT_USER_AGENT . '

'); } ini_set("default_socket_timeout", DEFAULT_SOCKET_TIMEOUT); // must be. because of `feof()` works @@ -386,12 +387,13 @@ function relay_dns_get_record($params) { ); } -function relay_get_geolocation() { - $url = "https://ipapi.co/json/"; +function relay_fetch_url($params) { + $url = $params['url']; try { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_USERAGENT, DEFAULT_USER_AGENT); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); @@ -412,13 +414,12 @@ function relay_get_geolocation() { ); } curl_close($ch); - $data = json_decode($response, true); return array( "success" => true, "result" => array( "status" => 200, - "data" => $data + "data" => $response ) ); } catch (Exception $e) { @@ -433,6 +434,24 @@ function relay_get_geolocation() { } } +function relay_get_geolocation() { + $result = relay_fetch_url(array( + "url" => "http://ip-api.com/json" + )); + if ($result['success']) { + return array( + "success" => true, + "result" => array( + "status" => 200, + "data" => json_decode($result['result']['data'], true) + ) + ); + } else { + return $result; + } +} + + function relay_invoke_method($params) { $callback = $params['callback']; $args = (is_array($params['args']) ? $params['args'] : array()); @@ -537,8 +556,17 @@ if ($context['jsonrpc'] == "2.0") { } break; + case "relay_fetch_url": + $result = relay_fetch_url($context['params']); + if ($result['success']) { + echo jsonrpc2_result_encode($result['result'], $context['id']); + } else { + echo jsonrpc2_error_encode($result['error'], $context['id']); + } + break; + case "relay_get_geolocation": - $result = relay_get_geolocation(); + $result = relay_get_geolocation($context['params']); if ($result['success']) { echo jsonrpc2_result_encode($result['result'], $context['id']); } else { diff --git a/console.html b/console.html index b3cf9e6..8f682a2 100644 --- a/console.html +++ b/console.html @@ -206,6 +206,20 @@ return; } + + // method(relay_fetch_url) + if (env.method == "relay_fetch_url") { + if (args.length < 1) { + this.echo("Please set a URL"); + return; + } + + jsonrpc2_request(this, env.method, { + "url": args[0] + }); + + return; + } // method(relay_mysql_query) if (env.method == "relay_mysql_query") {