Browse Source

replaced google video results with brave, fixed an xss exploit, added bang search support at the end of query, added instances.json, optimized some image sizes

hnhx 2 years ago
parent
commit
e814e63f0b

+ 3 - 3
README.md

@@ -19,13 +19,13 @@
 | [search.funami.tech](https://search.funami.tech/) | ❌ | ❌ | 🇰🇷 KR |
 | [librex.catalyst.sx](https://librex.catalyst.sx/) | ❌ | ❌ | 🇺🇸 US |
 | [search.madreyk.xyz](https://search.madreyk.xyz/) | ❌ | ❌ | 🇩🇪 DE |
-| ❌ | [✅](http://librex.so2mpiyfo4cje7bof5v52y3cvjyo2haxpqfvut4sr6gj2ul4mddx2jid.onion/) | ❌ | ??? | 
+| ❌ | [✅](http://librex.so2mpiyfo4cje7bof5v52y3cvjyo2haxpqfvut4sr6gj2ul4mddx2jid.onion/) | ❌ | ??? |
 
 <br>
 
 ### About LibreX
 
-LibreX gives you results from Google, Qwant and popular torrent sites without spying on you.
+LibreX gives you results from Google, Brave, Qwant and popular torrent sites without spying on you.
 <br>
 <br>
 If you would like to learn more about LibreX check out the [Wiki](https://github.com/hnhx/librex/wiki).
@@ -33,7 +33,7 @@ If you would like to learn more about LibreX check out the [Wiki](https://github
 <br>
 
 ### Mirror
-In case GitHub would remove LibreX, you can access the source code via this git mirror
+You can access the source code via this git mirror
 ```
 git clone https://git.beparanoid.de/librex
 ```

+ 8 - 8
config.php.example

@@ -10,16 +10,16 @@
         "disable_bittorent_search" => false,
         "bittorent_trackers" => "&tr=http%3A%2F%2Fnyaa.tracker.wf%3A7777%2Fannounce&tr=udp%3A%2F%2Fopen.stealth.si%3A80%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fexodus.desync.com%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.torrent.eu.org%3A451%2Fannounce",
 
-        /* 
+        /*
             Preset privacy friendly frontends for users, these can be overwritten by users in settings
             e.g.: "invidious" => "https://yewtu.be",
         */
-        "invidious" => "",
-        "bibliogram" => "",
-        "nitter" => "",
-        "libreddit" => "",
-        "proxitok" => "",
-        "wikiless" => "",
+        "invidious" => "", // youtube
+        "bibliogram" => "", // instagram
+        "nitter" => "", // twitter
+        "libreddit" => "", // reddit
+        "proxitok" => "", // tiktok
+        "wikiless" => "", // wikipedia
 
         /*
             To send requests trough a proxy uncomment CURLOPT_PROXY and CURLOPT_PROXYTYPE:
@@ -45,7 +45,7 @@
             CURLOPT_PROTOCOLS => CURLPROTO_HTTPS | CURLPROTO_HTTP,
             CURLOPT_REDIR_PROTOCOLS => CURLPROTO_HTTPS | CURLPROTO_HTTP,
             CURLOPT_MAXREDIRS => 5,
-            CURLOPT_TIMEOUT => 8,
+            CURLOPT_TIMEOUT => 18,
             CURLOPT_VERBOSE => false
         )
 

+ 65 - 0
engines/brave/video.php

@@ -0,0 +1,65 @@
+<?php
+    function get_video_results($query)
+    {
+        global $config;
+
+        $url = "https://search.brave.com/videos?q=$query&source=web";
+        $response = request($url);
+        $xpath = get_xpath($response);
+
+        $results = array();
+
+        foreach($xpath->query("//div[@id='results']//div[@class='card']") as $result)
+        {
+            $url = $xpath->evaluate(".//a/@href", $result)[0]->textContent;
+            $title = $xpath->evaluate(".//div/@title", $result)[0]->textContent;
+            $views = $xpath->evaluate(".//div/@title", $result)[1]->textContent;
+            $date = $xpath->evaluate(".//div//span", $result)[0]->textContent;
+            $thumbnail_raw1 = $xpath->evaluate(".//div/@style", $result)[0]->textContent;
+            $thumbnail_raw2 = explode("url('", $thumbnail_raw1)[1];
+            $thumbnail =  explode("'), url", $thumbnail_raw2)[0];
+
+            $url = check_for_privacy_frontend($url);
+
+            array_push($results,
+                array (
+                    "title" => htmlspecialchars($title),
+                    "url" =>  htmlspecialchars($url),
+                    "base_url" => htmlspecialchars(get_base_url($url)),
+                    "views" => htmlspecialchars($views),
+                    "date" => htmlspecialchars($date),
+                    "thumbnail" => htmlspecialchars($thumbnail)
+                )
+            );
+        }
+
+        return $results;
+    }
+
+    function print_video_results($results)
+    {
+        echo "<div class=\"text-result-container\">";
+
+            foreach($results as $result)
+            {
+                $title = $result["title"];
+                $url = $result["url"];
+                $base_url = $result["base_url"];
+                $views = $result["views"];
+                $date = $result["date"];
+                $thumbnail = $result["thumbnail"];
+
+                echo "<div class=\"text-result-wrapper\">";
+                echo "<a href=\"$url\">";
+                echo "$base_url";
+                echo "<h2>$title</h2>";
+                echo "<img src=\"image_proxy.php?url=$thumbnail\">";
+                echo "<br>";
+                echo "<span>$date - $views</span>";
+                echo "</a>";
+                echo "</div>";
+            }
+
+        echo "</div>";
+    }
+?>

+ 0 - 61
engines/google/video.php

@@ -1,61 +0,0 @@
-<?php
-    function get_video_results($query, $page=0)
-    {
-        global $config;
-
-        $url = "https://www.google.$config->google_domain/search?&q=$query&start=$page&hl=$config->google_language&tbm=vid";
-        $response = request($url);
-        $xpath = get_xpath($response);
-
-        $results = array();
-
-        foreach($xpath->query("//div[@id='search']//div[contains(@class, 'g')]") as $result)
-        {
-            $url = $xpath->evaluate(".//a/@href", $result)[0];
-
-            if ($url == null)
-                continue;
-
-            if (!empty($results)) // filter duplicate results
-                if (end($results)["url"] == $url->textContent)
-                    continue;
-
-            $url = $url->textContent;
-            
-            $url = check_for_privacy_frontend($url);
-
-            $title = $xpath->evaluate(".//h3", $result)[0];
-
-            array_push($results,
-                array (
-                    "title" => htmlspecialchars($title->textContent),
-                    "url" =>  htmlspecialchars($url),
-                    "base_url" => htmlspecialchars(get_base_url($url))
-                )
-            );
-        }
-
-        return $results;
-    }
-
-    function print_video_results($results)
-    {
-        echo "<div class=\"text-result-container\">";
-
-            foreach($results as $result)
-            {
-                $title = $result["title"];
-                $url = $result["url"];
-                $base_url = $result["base_url"];
-
-                echo "<div class=\"text-result-wrapper\">";
-                echo "<a href=\"$url\">";
-                echo "$base_url";
-                echo "<h2>$title</h2>";
-                echo "</a>";
-                echo "</div>";
-            }
-
-        echo "</div>";
-    }
-?>

+ 2 - 2
image_proxy.php

@@ -7,11 +7,11 @@
 
     $split_url = explode("/", $url);
     $base_url = $split_url[2];
-    
+
     $base_url_main_split = explode(".", strrev($base_url));
     $base_url_main = strrev($base_url_main_split[1]) . "." . strrev($base_url_main_split[0]);
 
-    if ($base_url_main == "qwant.com" || $base_url_main == "wikimedia.org")
+    if ($base_url_main == "qwant.com" || $base_url_main == "wikimedia.org" || $base_url_main == "brave.com")
     {
       $image = $url;
       $image_src = request($image);

+ 46 - 0
instances.json

@@ -0,0 +1,46 @@
+{
+    "instances": [
+          {
+              "clearnet": "https://librex.beparanoid.de/",
+              "tor": "http://librex.2356uhnbpv5nk3bni5bv6jg2cd6lgj664kwx3lhyelstpttpyv4kk2qd.onion/",
+              "i2p": null,
+              "country": "HU"
+          },
+          {
+              "clearnet": "https://librex.extravi.dev/",
+              "tor": "http://ncblhz7q4sfbf755bdbhebfzxcpypz7ewafgi4agatecojz7pln4i3id.onion/",
+              "i2p": "http://rra33hiaf6nmby7jfpqe2gqmng3jnzkvbu2n7jgce7vbhoyuhzya.b32.i2p/",
+              "country": "DE"
+          },
+          {
+              "clearnet": "https://search.davidovski.xyz/",
+              "tor": null,
+              "i2p": null,
+              "country": "UK"
+          },
+          {
+              "clearnet": "https://search.funami.tech/",
+              "tor": null,
+              "i2p": null,
+              "country": "KR"
+          },
+          {
+              "clearnet": "https://librex.catalyst.sx/",
+              "tor": null,
+              "i2p": null,
+              "country": "US"
+          },
+          {
+              "clearnet": "https://search.madreyk.xyz/",
+              "tor": null,
+              "i2p": null,
+              "country": "DE"
+          },
+          {
+              "clearnet": null,
+              "tor": "http://librex.so2mpiyfo4cje7bof5v52y3cvjyo2haxpqfvut4sr6gj2ul4mddx2jid.onion/",
+              "i2p": null,
+              "country": null
+          }
+    ]
+}

+ 8 - 4
misc/tools.php

@@ -19,12 +19,12 @@
             else if (!empty($config->$frontend))
                 $frontend = $config->$frontend;
 
-            if ($original == "instagram.com") 
+            if ($original == "instagram.com")
             {
                 if (!strpos($url, "/p/"))
                     $frontend .= "/u";
             }
-           
+
             $url =  $frontend . explode($original, $url)[1];
 
             return $url;
@@ -59,10 +59,14 @@
     function check_ddg_bang($query)
     {
 
-        $bangs_json = file_get_contents("static/misc/ddg_bang.json"); 
+        $bangs_json = file_get_contents("static/misc/ddg_bang.json");
         $bangs = json_decode($bangs_json, true);
+
+        if (substr($query, 0, 1) == "!")
+            $search_word = substr(explode(" ", $query)[0], 1);
+        else
+            $search_word = substr(end(explode(" ", $query)), 1);
         
-        $search_word = substr(explode(" ", $query)[0], 1);
         $bang_url = null;
 
         foreach($bangs as $bang)

+ 9 - 6
search.php

@@ -1,6 +1,10 @@
 <?php require "misc/header.php"; ?>
 
-<title> <?php echo $_REQUEST["q"]; ?> - LibreX</title>
+<title>
+<?php
+  $query = htmlspecialchars(trim($_REQUEST["q"]));
+  echo $query;
+?> - LibreX</title>
 </head>
     <body>
         <form class="sub-search-container" method="get" autocomplete="off">
@@ -8,7 +12,6 @@
             <a href="./"><img class="logo" src="static/images/librex.png" alt="librex logo"></a>
             <input type="text" name="q"
                 <?php
-                    $query = htmlspecialchars(trim($_REQUEST["q"]));
                     $query_encoded = urlencode($query);
 
                     if (1 > strlen($query) || strlen($query) > 256)
@@ -46,7 +49,7 @@
             switch ($type)
             {
                 case 0:
-                    if (substr($query, 0, 1) == "!")
+                    if (substr($query, 0, 1) == "!" || substr(end(explode(" ", $query)), 0, 1) == "!")
                         check_ddg_bang($query);
                     require "engines/google/text.php";
                     $results = get_text_results($query, $page);
@@ -62,8 +65,8 @@
                     break;
 
                 case 2:
-                    require "engines/google/video.php";
-                    $results = get_video_results($query_encoded, $page);
+                    require "engines/brave/video.php";
+                    $results = get_video_results($query_encoded);
                     print_elapsed_time($start_time);
                     print_video_results($results);
                     break;
@@ -91,7 +94,7 @@
             }
 
 
-            if ($type != 3)
+            if (2 > $type)
             {
                 echo "<div class=\"next-page-button-wrapper\">";
 

BIN
static/images/image_result.png


BIN
static/images/text_result.png


BIN
static/images/torrent_result.png


BIN
static/images/video_result.png