From ddaceff4e5032719ee1211c3bac6ea2dcd69f920 Mon Sep 17 00:00:00 2001
From: hnhx
Date: Tue, 25 Oct 2022 13:02:01 +0200
Subject: [PATCH] added "my ip", "my user agent" special queries, settings set
via parameters now persist, changed "type" to "t" for consistency
---
api.php | 6 +++---
config.php.example | 2 +-
engines/google/text.php | 27 ++++++++++++++++++++++++++-
engines/special/ip.php | 11 +++++++++++
engines/special/user_agent.php | 11 +++++++++++
index.php | 6 +++---
misc/header.php | 2 +-
misc/tools.php | 9 ++++++++-
search.php | 18 ++++++++++++------
9 files changed, 76 insertions(+), 16 deletions(-)
create mode 100644 engines/special/ip.php
create mode 100644 engines/special/user_agent.php
diff --git a/api.php b/api.php
index b582e0e..374800f 100644
--- a/api.php
+++ b/api.php
@@ -4,11 +4,11 @@
if (!isset($_REQUEST["q"]))
{
- echo "Example API request: ./api.php?q=gentoo&p=2&type=0
+ echo "Example API request: ./api.php?q=gentoo&p=2&t=0
\"q\" is the keyword
\"p\" is the result page (the first page is 0)
- \"type\" is the search type (0=text, 1=image, 2=video, 3=torrent)
+ \"t\" is the search type (0=text, 1=image, 2=video, 3=torrent)
The results are going to be in JSON format.
The API supports both POST and GET requests.
";
@@ -19,7 +19,7 @@
$query = $_REQUEST["q"];
$query_encoded = urlencode($query);
$page = isset($_REQUEST["p"]) ? (int) $_REQUEST["p"] : 0;
- $type = isset($_REQUEST["type"]) ? (int) $_REQUEST["type"] : 0;
+ $type = isset($_REQUEST["t"]) ? (int) $_REQUEST["t"] : 0;
$results = array();
diff --git a/config.php.example b/config.php.example
index c43bb25..75e9717 100644
--- a/config.php.example
+++ b/config.php.example
@@ -39,7 +39,7 @@
// CURLOPT_PROXYTYPE => CURLPROXY_HTTP,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
- CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36",
+ CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36",
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_PROTOCOLS => CURLPROTO_HTTPS | CURLPROTO_HTTP,
diff --git a/engines/google/text.php b/engines/google/text.php
index 67b4e3b..5fb33a7 100644
--- a/engines/google/text.php
+++ b/engines/google/text.php
@@ -14,9 +14,24 @@
return 1;
}
else if (strpos($query_lower, "mean") && count($split_query) >= 2) // definition
+ {
return 2;
+ }
+ else if (strpos($query_lower, "my") !== false)
+ {
+ if (strpos($query_lower, "ip"))
+ {
+ return 4;
+ }
+ else if (strpos($query_lower, "user agent") || strpos($query_lower, "ua"))
+ {
+ return 5;
+ }
+ }
else if (3 > count(explode(" ", $query))) // wikipedia
+ {
return 3;
+ }
return 0;
}
@@ -68,6 +83,7 @@
curl_multi_exec($mh, $running);
} while ($running);
+
if ($special_search != 0)
{
$special_result = null;
@@ -86,6 +102,14 @@
require "engines/special/wikipedia.php";
$special_result = wikipedia_results($query, curl_multi_getcontent($special_ch));
break;
+ case 4:
+ require "engines/special/ip.php";
+ $special_result = ip_result();
+ break;
+ case 5:
+ require "engines/special/user_agent.php";
+ $special_result = user_agent_result();
+ break;
}
if ($special_result != null)
@@ -145,7 +169,8 @@
echo "
";
}
echo $response;
- echo "$source";
+ if ($source)
+ echo "$source";
echo "
";
array_shift($results);
diff --git a/engines/special/ip.php b/engines/special/ip.php
new file mode 100644
index 0000000..63e01c7
--- /dev/null
+++ b/engines/special/ip.php
@@ -0,0 +1,11 @@
+ array(
+ "response" => $_SERVER["REMOTE_ADDR"],
+ "source" => null
+ )
+ );
+ }
+?>
diff --git a/engines/special/user_agent.php b/engines/special/user_agent.php
new file mode 100644
index 0000000..336606e
--- /dev/null
+++ b/engines/special/user_agent.php
@@ -0,0 +1,11 @@
+ array(
+ "response" => $_SERVER["HTTP_USER_AGENT"],
+ "source" => null
+ )
+ );
+ }
+?>
diff --git a/index.php b/index.php
index 462aaad..9146e9a 100644
--- a/index.php
+++ b/index.php
@@ -7,11 +7,11 @@
LibreX
-
+
-
-
+
+
diff --git a/misc/header.php b/misc/header.php
index 96a64f4..933364a 100644
--- a/misc/header.php
+++ b/misc/header.php
@@ -12,5 +12,5 @@
if (isset($_COOKIE["theme"]) || isset($_REQUEST["theme"]))
echo htmlspecialchars((isset($_COOKIE["theme"]) ? $_COOKIE["theme"] : $_REQUEST["theme"]) . ".css");
else
- echo "dark.css";
+ echo "dark.css";
?>"/>
diff --git a/misc/tools.php b/misc/tools.php
index 6811697..45d5ca8 100644
--- a/misc/tools.php
+++ b/misc/tools.php
@@ -141,9 +141,16 @@
function print_next_page_button($text, $page, $query, $type)
{
echo "";
}
diff --git a/search.php b/search.php
index 0596614..d7a9104 100644
--- a/search.php
+++ b/search.php
@@ -24,16 +24,21 @@
>
";
+ foreach($_REQUEST as $key=>$value)
+ {
+ if ($key != "q" && $key != "p" && $key != "t")
+ {
+ echo "";
+ }
+ }
?>
@@ -42,6 +47,7 @@
$config = require "config.php";
require "misc/tools.php";
+ $type = isset($_REQUEST["t"]) ? (int) $_REQUEST["t"] : 0;
$page = isset($_REQUEST["p"]) ? (int) $_REQUEST["p"] : 0;
$start_time = microtime(true);