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:
+ contains JavaScript
+ contains cookies
+ contains ads
+ has been heavily modified

View File

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

View File

@ -1,61 +1,62 @@
<?php
// This user agent will be used when parsing the results
$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";
return (object) array(
// e.g.: fr -> https://google.fr/
$config_google_domain = "com";
// e.g.: fr -> https://google.fr/
"google_domain" => "com",
// Google results will be in this language
$config_google_language = "en";
// Google results will be in this language
"google_language" => "en",
$config_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";
"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",
/*
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 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 libreddit instances: https://github.com/spikecodes/libreddit
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 nitter instances: https://github.com/zedeus/nitter/wiki/Instances
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>
</head>
<body>
@ -10,4 +11,4 @@
<img src="static/images/xmr.png" alt="xmr qr code"/>
</div>
<?php require "static/footer.html"; ?>
<?php require "misc/footer.php"; ?>

View File

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

View File

@ -1,8 +1,7 @@
<?php
function get_nyaa_results($query)
{
require_once "config.php";
require_once "misc/tools.php";
global $config;
$url = "https://nyaa.si/?q=$query";
$response = request($url);
@ -12,13 +11,11 @@
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;
$centered = $xpath->evaluate(".//td[@class='text-center']", $result);
$magnet = $xpath->evaluate(".//a[2]/@href", $centered[0])[0]->textContent;
$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;
$seeders = $centered[3]->textContent;
$leechers = $centered[4]->textContent;

View File

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

View File

@ -2,8 +2,7 @@
function get_thepiratebay_results($query)
{
require_once "config.php";
require_once "misc/tools.php";
global $config;
$query = urlencode($query);
@ -16,15 +15,16 @@
foreach ($json_response as $response)
{
global $config_bittorent_trackers;
$size = human_filesize($response["size"]);
$hash = $response["info_hash"];
$name = $response["name"];
$seeders = (int) $response["seeders"];
$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 (

View File

@ -2,8 +2,7 @@
function get_yts_results($query)
{
require_once "config.php";
require_once "misc/tools.php";
global $config;
$query = urlencode($query);
@ -23,14 +22,13 @@
foreach ($movie["torrents"] as $torrent)
{
global $config_bittorent_trackers;
$hash = $torrent["hash"];
$seeders = $torrent["seeds"];
$leechers = $torrent["peers"];
$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 (

View File

@ -1,10 +1,9 @@
<?php
function get_image_results($query)
{
require "config.php";
require "misc/tools.php";
global $config;
$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);
$xpath = get_xpath($response);
@ -19,7 +18,7 @@
if (!empty($alt))
{
$ch = curl_init($src);
curl_setopt_array($ch, $config_curl_settings);
curl_setopt_array($ch, $config->curl_settings);
array_push($chs, $ch);
curl_multi_add_handle($mh, $ch);

View File

@ -20,17 +20,16 @@
function get_text_results($query, $page=0)
{
require "config.php";
require "misc/tools.php";
global $config;
$mh = curl_multi_init();
$query_lower = strtolower($query);
$query_encoded = urlencode($query);
$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);
curl_setopt_array($google_ch, $config_curl_settings);
curl_setopt_array($google_ch, $config->curl_settings);
curl_multi_add_handle($mh, $google_ch);
@ -56,7 +55,7 @@
}
$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);
}

View File

@ -1,10 +1,9 @@
<?php
function get_video_results($query, $page=0)
{
require "config.php";
require "misc/tools.php";
global $config;
$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);
$xpath = get_xpath($response);

View File

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

View File

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

View File

@ -1,9 +1,6 @@
<?php
function wikipedia_results($query, $response)
{
require "config.php";
require_once "misc/tools.php";
$query_encoded = urlencode($query);
$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>
</head>
@ -15,4 +15,4 @@
</div>
</form>
<?php require "static/footer.html"; ?>
<?php require "misc/footer.php"; ?>

View File

@ -5,8 +5,8 @@
<meta charset="UTF-8"/>
<meta name="description" content="A privacy respecting meta search engine."/>
<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 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)
{
require "config.php";
$config = require "config.php";
if ($config_replace_youtube_with_invidious != null && strpos($url, "youtube.com"))
$url = $config_replace_youtube_with_invidious . explode("youtube.com", $url)[1];
else if ($config_replace_instagram_with_bibliogram != null && strpos($url, "instagram.com"))
if ($config->replace_youtube_with_invidious != null && strpos($url, "youtube.com"))
$url = $config->replace_youtube_with_invidious . explode("youtube.com", $url)[1];
else if ($config->replace_instagram_with_bibliogram != null && strpos($url, "instagram.com"))
{
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"))
$url = $config_replace_twitter_with_nitter . explode("twitter.com", $url)[1];
else if ($config_replace_reddit_with_libreddit != null && strpos($url, "reddit.com"))
$url = $config_replace_reddit_with_libreddit . explode("reddit.com", $url)[1];
else if ($config->replace_twitter_with_nitter != null && strpos($url, "twitter.com"))
$url = $config->replace_twitter_with_nitter . explode("twitter.com", $url)[1];
else if ($config->replace_reddit_with_libreddit != null && strpos($url, "reddit.com"))
$url = $config->replace_reddit_with_libreddit . explode("reddit.com", $url)[1];
return $url;
}
@ -38,10 +38,10 @@
function request($url)
{
require "config.php";
$config = require "config.php";
$ch = curl_init($url);
curl_setopt_array($ch, $config_curl_settings);
curl_setopt_array($ch, $config->curl_settings);
$response = curl_exec($ch);
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>
</head>
@ -36,7 +36,8 @@
</form>
<?php
require "config.php";
$config = require "config.php";
require "misc/tools.php";
$page = isset($_REQUEST["p"]) ? (int) $_REQUEST["p"] : 0;
@ -67,7 +68,7 @@
break;
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>";
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>
</head>
@ -97,4 +97,4 @@
?>
</div>
<?php require "static/footer.html"; ?>
<?php require "misc/footer.php"; ?>