From bcaa4e76dfc0b0dbc76fb6c28b881de72fb312b0 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Fri, 21 Jun 2024 12:16:27 +0900 Subject: [PATCH] Update index.php --- assets/php/index.php | 59 ++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/assets/php/index.php b/assets/php/index.php index 083d217..b1c9cf2 100644 --- a/assets/php/index.php +++ b/assets/php/index.php @@ -6,10 +6,10 @@ * Namhyeon Go (Catswords Research) * https://github.com/gnh1201/caterpillar * Created at: 2022-10-06 - * Updated at: 2024-06-20 + * Updated at: 2024-06-21 */ -define("PHP_HTTPPROXY_VERSION", "0.1.5.18"); +define("PHP_HTTPPROXY_VERSION", "0.1.5.19"); define("DEFAULT_SOCKET_TIMEOUT", 1); define("STATEFUL_SOCKET_TIMEOUT", 30); define("MAX_EXECUTION_TIME", 0); @@ -350,37 +350,48 @@ function relay_dns_get_record($params) { function relay_get_geolocation() { $url = "https://ipapi.co/json/"; - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + try { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - $response = curl_exec($ch); - $error_code = curl_errno($ch); - if ($error_code) { - $error_message = curl_error($ch); + $response = curl_exec($ch); + $error_code = curl_errno($ch); + if ($error_code) { + $error_message = curl_error($ch); + curl_close($ch); + + return array( + "success" => false, + "error" => array( + "status" => 502, + "code" => $error_code, + "message" => $error_message + ) + ); + } curl_close($ch); + $data = json_decode($response, true); + return array( + "success" => true, + "result" => array( + "status" => 200, + "data" => $data + ) + ); + } catch (Exception $e) { return array( "success" => false, "error" => array( - "status" => 502, - "code" => $error_code, - "message" => $error_message + "status" => 503, + "code" => -1, + "message" => $e->__toString() ) ); } - curl_close($ch); - $data = json_decode($response, true); - - return array( - "success" => true, - "result" => array( - "status" => 200, - "data" => $data - ) - ); } function relay_invoke_method($params) {