summaryrefslogtreecommitdiffstats
path: root/prog/sear.php
diff options
context:
space:
mode:
Diffstat (limited to 'prog/sear.php')
-rw-r--r--prog/sear.php/index.php60
1 files changed, 32 insertions, 28 deletions
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 = "",
<head>
<meta charset=UTF-8>
<title>$title :: sear.c</title>
- <meta name=viewport content=width='device-width, initial-scale=1'>
+ <meta name=viewport content='width=device-width, initial-scale=1'>
<link rel=stylesheet href=/css.css>
<link rel=icon type=image/x-icon href=favicon.ico>
<link title=sear.c rel=search type=application/opensearchdescription+xml href=/osdd.xml>
@@ -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) {