changed how the config is stored, rebased the file structure to make it more clean

This commit is contained in:
hnh.mtf 2022-03-11 10:04:36 +01:00
parent fc1fcd3031
commit cbe16e8627
28 changed files with 109 additions and 121 deletions

View File

@ -17,7 +17,6 @@ If you wish to get your instance added create an issue with the `new instance` l
Your request will be **rejected** if your instance: Your request will be **rejected** if your instance:
+ contains JavaScript + contains JavaScript
+ contains cookies
+ contains ads + contains ads
+ has been heavily modified + has been heavily modified

View File

@ -1,5 +1,6 @@
<?php <?php
require "config.php"; $config = require "config.php";
require "misc/tools.php";
if (!isset($_REQUEST["q"])) if (!isset($_REQUEST["q"]))
{ {
@ -29,7 +30,7 @@
$results = get_video_results($query_encoded, $page); $results = get_video_results($query_encoded, $page);
break; break;
case 3: case 3:
if ($config_disable_bittorent_search) if ($config->disable_bittorent_search)
$results = array("error" => "disabled"); $results = array("error" => "disabled");
else else
{ {

View File

@ -1,61 +1,62 @@
<?php <?php
// This user agent will be used when parsing the results return (object) array(
$config_user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36";
// e.g.: fr -> https://google.fr/ // e.g.: fr -> https://google.fr/
$config_google_domain = "com"; "google_domain" => "com",
// Google results will be in this language // Google results will be in this language
$config_google_language = "en"; "google_language" => "en",
$config_disable_bittorent_search = false; "disable_bittorent_search" => false,
$config_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"; "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",
/* /*
These are privacy friendly front-ends for popular sites, these settings can be managed by end users as well for their session via cookies. These are privacy friendly front-ends for popular sites, these settings can be managed by end users as well for their session via cookies.
Online invidious instances: https://docs.invidious.io/Invidious-Instances/ Online invidious instances: https://docs.invidious.io/Invidious-Instances/
Online bibliogram instances: https://git.sr.ht/~cadence/bibliogram-docs/tree/master/docs/Instances.md Online bibliogram instances: https://git.sr.ht/~cadence/bibliogram-docs/tree/master/docs/Instances.md
Online nitter instances: https://github.com/zedeus/nitter/wiki/Instances Online nitter instances: https://github.com/zedeus/nitter/wiki/Instances
Online libreddit instances: https://github.com/spikecodes/libreddit Online libreddit instances: https://github.com/spikecodes/libreddit
If you don't want to replace YouTube for an example:
$replace_youtube_with_invidious = isset($_COOKIE["invidious"]) ? $_COOKIE["invidious"] : null;
*/
"replace_youtube_with_invidious" => isset($_COOKIE["invidious"]) ? $_COOKIE["invidious"] : "https://yewtu.be",
"replace_instagram_with_bibliogram" => isset($_COOKIE["bibliogram"]) ? $_COOKIE["bibliogram"] : "https://bibliogram.pussthecat.org",
"replace_twitter_with_nitter" => isset($_COOKIE["nitter"]) ? $_COOKIE["nitter"] : "https://nitter.namazso.eu",
"replace_reddit_with_libreddit" => isset($_COOKIE["libreddit"]) ? $_COOKIE["libreddit"] : "https://libreddit.dothq.co",
/*
To send requests trough a proxy uncomment CURLOPT_PROXY and CURLOPT_PROXYTYPE:
CURLOPT_PROXYTYPE options:
CURLPROXY_HTTP
CURLPROXY_SOCKS4
CURLPROXY_SOCKS4A
CURLPROXY_SOCKS5
CURLPROXY_SOCKS5_HOSTNAME
As an example, for a TOR connection you would use these settings:
CURLOPT_PROXY => "127.0.0.1:9050",
CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5,
!!! ONLY CHANGE THE OTHER OPTIONS IF YOU KNOW WHAT YOU ARE DOING !!!
*/
"curl_settings" => array(
// CURLOPT_PROXY => "ip:port",
// 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/98.0.4758.102 Safari/537.36",
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYSTATUS => false,
CURLOPT_VERBOSE => false,
CURLOPT_TCP_FASTOPEN => true
)
If you don't want to replace YouTube for an example:
$config_replace_youtube_with_invidious = isset($_COOKIE["invidious"]) ? $_COOKIE["invidious"] : null;
*/
$config_replace_youtube_with_invidious = isset($_COOKIE["invidious"]) ? $_COOKIE["invidious"] : "https://yewtu.be";
$config_replace_instagram_with_bibliogram = isset($_COOKIE["bibliogram"]) ? $_COOKIE["bibliogram"] : "https://bibliogram.pussthecat.org";
$config_replace_twitter_with_nitter = isset($_COOKIE["nitter"]) ? $_COOKIE["nitter"] : "https://nitter.namazso.eu";
$config_replace_reddit_with_libreddit = isset($_COOKIE["libreddit"]) ? $_COOKIE["libreddit"] : "https://libreddit.dothq.co";
/*
To send requests trough a proxy uncomment CURLOPT_PROXY and CURLOPT_PROXYTYPE:
CURLOPT_PROXYTYPE options:
CURLPROXY_HTTP
CURLPROXY_SOCKS4
CURLPROXY_SOCKS4A
CURLPROXY_SOCKS5
CURLPROXY_SOCKS5_HOSTNAME
As an example, for a TOR connection you would use these settings:
CURLOPT_PROXY => "127.0.0.1:9050",
CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5,
!!! ONLY CHANGE THE OTHER OPTIONS IF YOU KNOW WHAT YOU ARE DOING !!!
*/
$config_curl_settings = array(
// CURLOPT_PROXY => "ip:port",
// CURLOPT_PROXYTYPE => CURLPROXY_HTTP,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_USERAGENT => $config_user_agent,
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYSTATUS => false,
CURLOPT_VERBOSE => false,
CURLOPT_TCP_FASTOPEN => true
); );
?> ?>

View File

@ -1,4 +1,5 @@
<?php require "static/header.php"; ?> <?php require "misc/header.php"; ?>
<title>LibreX - Donate</title> <title>LibreX - Donate</title>
</head> </head>
<body> <body>
@ -10,4 +11,4 @@
<img src="static/images/xmr.png" alt="xmr qr code"/> <img src="static/images/xmr.png" alt="xmr qr code"/>
</div> </div>
<?php require "static/footer.html"; ?> <?php require "misc/footer.php"; ?>

View File

@ -22,6 +22,8 @@
{ {
echo "<div class=\"text-result-container\">"; echo "<div class=\"text-result-container\">";
if (!empty($results))
{
foreach($results as $result) foreach($results as $result)
{ {
$source = $result["source"]; $source = $result["source"];
@ -41,6 +43,9 @@
echo "$size</span>"; echo "$size</span>";
echo "</div>"; echo "</div>";
} }
}
else
echo "<p>There are no results. Please try different keywords!</p>";
echo "</div>"; echo "</div>";
} }

View File

@ -1,8 +1,7 @@
<?php <?php
function get_nyaa_results($query) function get_nyaa_results($query)
{ {
require_once "config.php"; global $config;
require_once "misc/tools.php";
$url = "https://nyaa.si/?q=$query"; $url = "https://nyaa.si/?q=$query";
$response = request($url); $response = request($url);
@ -12,13 +11,11 @@
foreach($xpath->query("//tbody/tr") as $result) foreach($xpath->query("//tbody/tr") as $result)
{ {
global $config_bittorent_trackers;
$name = $xpath->evaluate(".//td[@colspan='2']//a[not(contains(@class, 'comments'))]/@title", $result)[0]->textContent; $name = $xpath->evaluate(".//td[@colspan='2']//a[not(contains(@class, 'comments'))]/@title", $result)[0]->textContent;
$centered = $xpath->evaluate(".//td[@class='text-center']", $result); $centered = $xpath->evaluate(".//td[@class='text-center']", $result);
$magnet = $xpath->evaluate(".//a[2]/@href", $centered[0])[0]->textContent; $magnet = $xpath->evaluate(".//a[2]/@href", $centered[0])[0]->textContent;
$magnet_without_tracker = explode("&tr=", $magnet)[0]; $magnet_without_tracker = explode("&tr=", $magnet)[0];
$magnet = $magnet_without_tracker . $config_bittorent_trackers; $magnet = $magnet_without_tracker . $config->bittorent_trackers;
$size = $centered[1]->textContent; $size = $centered[1]->textContent;
$seeders = $centered[3]->textContent; $seeders = $centered[3]->textContent;
$leechers = $centered[4]->textContent; $leechers = $centered[4]->textContent;

View File

@ -1,8 +1,7 @@
<?php <?php
function get_rutor_results($query) function get_rutor_results($query)
{ {
require_once "config.php"; global $config;
require_once "misc/tools.php";
$url = "http://rutor.info/search/$query"; $url = "http://rutor.info/search/$query";
$response = request($url); $response = request($url);
@ -14,12 +13,10 @@
foreach($xpath->query("//table/tr[@class='gai' or @class='tum']") as $result) foreach($xpath->query("//table/tr[@class='gai' or @class='tum']") as $result)
{ {
global $config_bittorent_trackers;
$name = $xpath->evaluate(".//td/a", $result)[2]->textContent; $name = $xpath->evaluate(".//td/a", $result)[2]->textContent;
$magnet = $xpath->evaluate(".//td/a/@href", $result)[1]->textContent; $magnet = $xpath->evaluate(".//td/a/@href", $result)[1]->textContent;
$magnet_without_tracker = explode("&tr=", $magnet)[0]; $magnet_without_tracker = explode("&tr=", $magnet)[0];
$magnet = $magnet_without_tracker . $config_bittorent_trackers; $magnet = $magnet_without_tracker . $config->bittorent_trackers;
$size = $xpath->evaluate(".//td", $result)[3]->textContent; $size = $xpath->evaluate(".//td", $result)[3]->textContent;
$seeders = $xpath->evaluate(".//span", $result)[0]->textContent; $seeders = $xpath->evaluate(".//span", $result)[0]->textContent;
$leechers = $xpath->evaluate(".//span", $result)[1]->textContent; $leechers = $xpath->evaluate(".//span", $result)[1]->textContent;

View File

@ -2,8 +2,7 @@
function get_thepiratebay_results($query) function get_thepiratebay_results($query)
{ {
require_once "config.php"; global $config;
require_once "misc/tools.php";
$query = urlencode($query); $query = urlencode($query);
@ -16,15 +15,16 @@
foreach ($json_response as $response) foreach ($json_response as $response)
{ {
global $config_bittorent_trackers;
$size = human_filesize($response["size"]); $size = human_filesize($response["size"]);
$hash = $response["info_hash"]; $hash = $response["info_hash"];
$name = $response["name"]; $name = $response["name"];
$seeders = (int) $response["seeders"]; $seeders = (int) $response["seeders"];
$leechers = (int) $response["leechers"]; $leechers = (int) $response["leechers"];
$magnet = "magnet:?xt=urn:btih:$hash&dn=$name$config_bittorent_trackers"; $magnet = "magnet:?xt=urn:btih:$hash&dn=$name" . $config->bittorent_trackers;
if ($name == "No results returned")
break;
array_push($results, array_push($results,
array ( array (

View File

@ -2,8 +2,7 @@
function get_yts_results($query) function get_yts_results($query)
{ {
require_once "config.php"; global $config;
require_once "misc/tools.php";
$query = urlencode($query); $query = urlencode($query);
@ -23,14 +22,13 @@
foreach ($movie["torrents"] as $torrent) foreach ($movie["torrents"] as $torrent)
{ {
global $config_bittorent_trackers;
$hash = $torrent["hash"]; $hash = $torrent["hash"];
$seeders = $torrent["seeds"]; $seeders = $torrent["seeds"];
$leechers = $torrent["peers"]; $leechers = $torrent["peers"];
$size = $torrent["size"]; $size = $torrent["size"];
$magnet = "magnet:?xt=urn:btih:$hash&dn=$name_encoded$config_bittorent_trackers"; $magnet = "magnet:?xt=urn:btih:$hash&dn=$name_encoded$config->bittorent_trackers";
array_push($results, array_push($results,
array ( array (

View File

@ -1,10 +1,9 @@
<?php <?php
function get_image_results($query) function get_image_results($query)
{ {
require "config.php"; global $config;
require "misc/tools.php";
$url = "https://www.google.$config_google_domain/search?&q=$query&hl=$config_google_language&tbm=isch"; $url = "https://www.google.$config->google_domain/search?&q=$query&hl=$config->google_language&tbm=isch";
$response = request($url); $response = request($url);
$xpath = get_xpath($response); $xpath = get_xpath($response);
@ -19,7 +18,7 @@
if (!empty($alt)) if (!empty($alt))
{ {
$ch = curl_init($src); $ch = curl_init($src);
curl_setopt_array($ch, $config_curl_settings); curl_setopt_array($ch, $config->curl_settings);
array_push($chs, $ch); array_push($chs, $ch);
curl_multi_add_handle($mh, $ch); curl_multi_add_handle($mh, $ch);

View File

@ -20,17 +20,16 @@
function get_text_results($query, $page=0) function get_text_results($query, $page=0)
{ {
require "config.php"; global $config;
require "misc/tools.php";
$mh = curl_multi_init(); $mh = curl_multi_init();
$query_lower = strtolower($query); $query_lower = strtolower($query);
$query_encoded = urlencode($query); $query_encoded = urlencode($query);
$results = array(); $results = array();
$url = "https://www.google.$config_google_domain/search?&q=$query_encoded&start=$page&hl=$config_google_language"; $url = "https://www.google.$config->google_domain/search?&q=$query_encoded&start=$page&hl=$config->google_language";
$google_ch = curl_init($url); $google_ch = curl_init($url);
curl_setopt_array($google_ch, $config_curl_settings); curl_setopt_array($google_ch, $config->curl_settings);
curl_multi_add_handle($mh, $google_ch); curl_multi_add_handle($mh, $google_ch);
@ -56,7 +55,7 @@
} }
$special_ch = curl_init($url); $special_ch = curl_init($url);
curl_setopt_array($special_ch, $config_curl_settings); curl_setopt_array($special_ch, $config->curl_settings);
curl_multi_add_handle($mh, $special_ch); curl_multi_add_handle($mh, $special_ch);
} }

View File

@ -1,10 +1,9 @@
<?php <?php
function get_video_results($query, $page=0) function get_video_results($query, $page=0)
{ {
require "config.php"; global $config;
require "misc/tools.php";
$url = "https://www.google.$config_google_domain/search?&q=$query&start=$page&hl=$config_google_language&tbm=vid"; $url = "https://www.google.$config->google_domain/search?&q=$query&start=$page&hl=$config->google_language&tbm=vid";
$response = request($url); $response = request($url);
$xpath = get_xpath($response); $xpath = get_xpath($response);

View File

@ -1,9 +1,6 @@
<?php <?php
function currency_results($query, $response) function currency_results($query, $response)
{ {
require "config.php";
require_once "misc/tools.php";
$split_query = explode(" ", $query); $split_query = explode(" ", $query);
$base_currency = strtoupper($split_query[1]); $base_currency = strtoupper($split_query[1]);

View File

@ -1,9 +1,6 @@
<?php <?php
function definition_results($query, $response) function definition_results($query, $response)
{ {
require "config.php";
require_once "misc/tools.php";
$split_query = explode(" ", $query); $split_query = explode(" ", $query);
$reversed_split_q = array_reverse($split_query); $reversed_split_q = array_reverse($split_query);
$word_to_define = $reversed_split_q[1]; $word_to_define = $reversed_split_q[1];

View File

@ -1,9 +1,6 @@
<?php <?php
function wikipedia_results($query, $response) function wikipedia_results($query, $response)
{ {
require "config.php";
require_once "misc/tools.php";
$query_encoded = urlencode($query); $query_encoded = urlencode($query);
$json_response = json_decode($response, true); $json_response = json_decode($response, true);

View File

@ -1,4 +1,4 @@
<?php require "static/header.php"; ?> <?php require "misc/header.php"; ?>
<title>LibreX</title> <title>LibreX</title>
</head> </head>
@ -15,4 +15,4 @@
</div> </div>
</form> </form>
<?php require "static/footer.html"; ?> <?php require "misc/footer.php"; ?>

View File

@ -5,8 +5,8 @@
<meta charset="UTF-8"/> <meta charset="UTF-8"/>
<meta name="description" content="A privacy respecting meta search engine."/> <meta name="description" content="A privacy respecting meta search engine."/>
<meta name="referrer" content="no-referrer"/> <meta name="referrer" content="no-referrer"/>
<link rel="stylesheet" type="text/css" href="static/styles.css"/> <link rel="stylesheet" type="text/css" href="static/css/styles.css"/>
<link title="LibreX search" type="application/opensearchdescription+xml" href="/opensearch.xml?method=POST" rel="search"/> <link title="LibreX search" type="application/opensearchdescription+xml" href="/opensearch.xml?method=POST" rel="search"/>
<link rel="shortcut icon" href="static/images/librex.png" /> <link rel="shortcut icon" href="static/images/librex.png" />
<link rel="stylesheet" type="text/css" href="<?php echo "static/" . (isset($_COOKIE["theme"]) ? $_COOKIE["theme"] . ".css" : "dark.css"); ?>"/> <link rel="stylesheet" type="text/css" href="<?php echo "static/css/" . (isset($_COOKIE["theme"]) ? $_COOKIE["theme"] . ".css" : "dark.css"); ?>"/>

View File

@ -8,21 +8,21 @@
function check_for_privacy_friendly_alternative($url) function check_for_privacy_friendly_alternative($url)
{ {
require "config.php"; $config = require "config.php";
if ($config_replace_youtube_with_invidious != null && strpos($url, "youtube.com")) if ($config->replace_youtube_with_invidious != null && strpos($url, "youtube.com"))
$url = $config_replace_youtube_with_invidious . explode("youtube.com", $url)[1]; $url = $config->replace_youtube_with_invidious . explode("youtube.com", $url)[1];
else if ($config_replace_instagram_with_bibliogram != null && strpos($url, "instagram.com")) else if ($config->replace_instagram_with_bibliogram != null && strpos($url, "instagram.com"))
{ {
if (!strpos($url, "/p/")) if (!strpos($url, "/p/"))
$config_replace_instagram_with_bibliogram .= "/u"; $config->replace_instagram_with_bibliogram .= "/u";
$url = $config_replace_instagram_with_bibliogram . explode("instagram.com", $url)[1]; $url = $config->replace_instagram_with_bibliogram . explode("instagram.com", $url)[1];
} }
else if ($config_replace_twitter_with_nitter != null && strpos($url, "twitter.com")) else if ($config->replace_twitter_with_nitter != null && strpos($url, "twitter.com"))
$url = $config_replace_twitter_with_nitter . explode("twitter.com", $url)[1]; $url = $config->replace_twitter_with_nitter . explode("twitter.com", $url)[1];
else if ($config_replace_reddit_with_libreddit != null && strpos($url, "reddit.com")) else if ($config->replace_reddit_with_libreddit != null && strpos($url, "reddit.com"))
$url = $config_replace_reddit_with_libreddit . explode("reddit.com", $url)[1]; $url = $config->replace_reddit_with_libreddit . explode("reddit.com", $url)[1];
return $url; return $url;
} }
@ -38,10 +38,10 @@
function request($url) function request($url)
{ {
require "config.php"; $config = require "config.php";
$ch = curl_init($url); $ch = curl_init($url);
curl_setopt_array($ch, $config_curl_settings); curl_setopt_array($ch, $config->curl_settings);
$response = curl_exec($ch); $response = curl_exec($ch);
return $response; return $response;

View File

@ -1,4 +1,4 @@
<?php require "static/header.php"; ?> <?php require "misc/header.php"; ?>
<title> <?php echo $_REQUEST["q"]; ?> - LibreX</title> <title> <?php echo $_REQUEST["q"]; ?> - LibreX</title>
</head> </head>
@ -36,7 +36,8 @@
</form> </form>
<?php <?php
require "config.php"; $config = require "config.php";
require "misc/tools.php";
$page = isset($_REQUEST["p"]) ? (int) $_REQUEST["p"] : 0; $page = isset($_REQUEST["p"]) ? (int) $_REQUEST["p"] : 0;
@ -67,7 +68,7 @@
break; break;
case 3: case 3:
if ($config_disable_bittorent_search) if ($config->disable_bittorent_search)
echo "<p class=\"text-result-container\">The host disabled this feature! :C</p>"; echo "<p class=\"text-result-container\">The host disabled this feature! :C</p>";
else else
{ {
@ -108,4 +109,4 @@
} }
?> ?>
<?php require "static/footer.html"; ?> <?php require "misc/footer.php"; ?>

View File

@ -1,4 +1,4 @@
<?php require "static/header.php"; ?> <?php require "misc/header.php"; ?>
<title>LibreX - Settings</title> <title>LibreX - Settings</title>
</head> </head>
@ -97,4 +97,4 @@
?> ?>
</div> </div>
<?php require "static/footer.html"; ?> <?php require "misc/footer.php"; ?>