From 12448cd3570b942b4cfe8e466ed3561c510c630b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Thu, 11 Jan 2024 01:42:20 +0100 Subject: =?UTF-8?q?=C5=A1e=20zobke=20si=20umijem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- prog/sear.php/index.php | 60 ++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 28 deletions(-) (limited to 'prog/sear.php') diff --git a/prog/sear.php/index.php b/prog/sear.php/index.php index 487e29d..fc08c68 100644 --- a/prog/sear.php/index.php +++ b/prog/sear.php/index.php @@ -131,7 +131,7 @@ function template ($title, $queryinfo, $body, $query = "", $additionalform = "", $title :: sear.c - + @@ -218,6 +218,35 @@ function handle_response ($query, $response, $limit, $plaintext, $horseshoe, $ad $resultshtml = results_html($response["results"], $plaintext, $limit); die(template($response["query"], $queryinfo, $resultshtml, $response["query"], $add_form, $image)); } +function try_query_google ($q, $image, $exact) { + $bindstrings = []; + foreach (net_get_interfaces() as $interface) + foreach ($interface["unicast"] as $unicast) { + if (!isset($unicast["address"])) + continue; + $address = $unicast["address"]; + if ($address == "::1") // tu timeouta + continue; + $bindstring = "$address:0"; + if (str_contains($address, ":")) + $bindstring = "[$address]:0"; + $bindstrings[] = $bindstring; + } + if (getenv("BINDSTRINGS")) + $bindstrings = explode(",", getenv("BINDSTRINGS")); + foreach ($bindstrings as $bindstring) { + // file_put_contents("/dev/stderr", "trying bindstring $bindstring\n"); + $response = query_google($q, $image, $exact, $bindstring); + if ($response["status"] == true) + break; + if ($response["code"] == "captcha") + continue; + if ($response["code"] == "failed") + continue; + break; + } + return $response; +} if (!isset($_REQUEST["debug"])) ini_set('display_errors','Off'); $add_form = ""; @@ -236,7 +265,7 @@ if (!empty($_REQUEST["e"])) { } if (!empty($_REQUEST["json"])) { header("Content-Type: application/json"); - $response = query_google($q, $image, $exact); + $response = try_query_google($q, $image, $exact); if ($response["status"] == false) http_response_code(500); die(json_encode($response)); @@ -262,32 +291,7 @@ if (!empty($_REQUEST["f"])) { if ($q == null) { die(template("", "iskalnik sear.php", "dobrodošli v iskalniku sear.php, naslednjiku programa sear.c. za iskanje po spletu nekaj vnesite v iskalno vrstico zgoraj in pritisnite na gumb.")); } -$bindstrings = []; -foreach (net_get_interfaces() as $interface) - foreach ($interface["unicast"] as $unicast) { - if (!isset($unicast["address"])) - continue; - $address = $unicast["address"]; - if ($address == "::1") // tu timeouta - continue; - $bindstring = "$address:0"; - if (str_contains($address, ":")) - $bindstring = "[$address]:0"; - $bindstrings[] = $bindstring; - } -if (getenv("BINDSTRINGS")) - $bindstrings = explode(",", getenv("BINDSTRINGS")); -foreach ($bindstrings as $bindstring) { - // file_put_contents("/dev/stderr", "trying bindstring $bindstring\n"); - $response = query_google($q, $image, $exact, $bindstring); - if ($response["status"] == true) - break; - if ($response["code"] == "captcha") - continue; - if ($response["code"] == "failed") - continue; - break; -} +try_query_google($q, $image, $exact); if ($response["status"] != true) { if ($response["code"] == "captcha") { foreach (["http://searc.oliwerix.com/sear.php?ref=b"] as $fallback) { -- cgit v1.2.3