mirror of
https://github.com/hnhx/librex.git
synced 2025-01-10 03:37:25 -03:00
added wikiless frontend, frontends can now be preset by the host, wikipedia images are converted to base64 now
This commit is contained in:
parent
ae23a9cdde
commit
e64e9a79db
8 changed files with 68 additions and 39 deletions
12
config.php
12
config.php
|
@ -10,6 +10,16 @@
|
||||||
"disable_bittorent_search" => false,
|
"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",
|
"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" => "",
|
||||||
|
"wikiless" => "",
|
||||||
|
|
||||||
/*
|
/*
|
||||||
To send requests trough a proxy uncomment CURLOPT_PROXY and CURLOPT_PROXYTYPE:
|
To send requests trough a proxy uncomment CURLOPT_PROXY and CURLOPT_PROXYTYPE:
|
||||||
|
|
||||||
|
@ -28,7 +38,7 @@
|
||||||
// CURLOPT_PROXYTYPE => CURLPROXY_HTTP,
|
// CURLOPT_PROXYTYPE => CURLPROXY_HTTP,
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_ENCODING => "",
|
CURLOPT_ENCODING => "",
|
||||||
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.82 Safari/537.36",
|
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
|
||||||
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
|
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
|
||||||
CURLOPT_CUSTOMREQUEST => "GET",
|
CURLOPT_CUSTOMREQUEST => "GET",
|
||||||
CURLOPT_SSL_VERIFYHOST => false,
|
CURLOPT_SSL_VERIFYHOST => false,
|
||||||
|
|
|
@ -110,7 +110,7 @@
|
||||||
|
|
||||||
$url = $url->textContent;
|
$url = $url->textContent;
|
||||||
|
|
||||||
$url = privacy_friendly_alternative($url);
|
$url = check_for_privacy_frontend($url);
|
||||||
|
|
||||||
$title = $xpath->evaluate(".//h3", $result)[0];
|
$title = $xpath->evaluate(".//h3", $result)[0];
|
||||||
$description = $xpath->evaluate(".//div[contains(@class, 'VwiC3b')]", $result)[0];
|
$description = $xpath->evaluate(".//div[contains(@class, 'VwiC3b')]", $result)[0];
|
||||||
|
@ -142,7 +142,7 @@
|
||||||
|
|
||||||
echo "<p class=\"special-result-container\">";
|
echo "<p class=\"special-result-container\">";
|
||||||
if (array_key_exists("image", $special["special_response"]))
|
if (array_key_exists("image", $special["special_response"]))
|
||||||
echo "<img src=\"" . $special["special_response"]["image"] . "\">";
|
echo "<img src=\"data:image/jpeg;base64," . $special["special_response"]["image"] . "\">";
|
||||||
echo $response;
|
echo $response;
|
||||||
echo "<a href=\"$source\" target=\"_blank\">$source</a>";
|
echo "<a href=\"$source\" target=\"_blank\">$source</a>";
|
||||||
echo "</p>";
|
echo "</p>";
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
$url = $url->textContent;
|
$url = $url->textContent;
|
||||||
|
|
||||||
$url = privacy_friendly_alternative($url);
|
$url = check_for_privacy_frontend($url);
|
||||||
|
|
||||||
$title = $xpath->evaluate(".//h3", $result)[0];
|
$title = $xpath->evaluate(".//h3", $result)[0];
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
{
|
{
|
||||||
$description = substr($first_page["extract"], 0, 250) . "...";
|
$description = substr($first_page["extract"], 0, 250) . "...";
|
||||||
|
|
||||||
$source = "https://en.wikipedia.org/wiki/$query";
|
$source = check_for_privacy_frontend("https://wikipedia.org/wiki/$query");
|
||||||
$response = array(
|
$response = array(
|
||||||
"special_response" => array(
|
"special_response" => array(
|
||||||
"response" => $description,
|
"response" => $description,
|
||||||
|
@ -20,7 +20,12 @@
|
||||||
);
|
);
|
||||||
|
|
||||||
if (array_key_exists("thumbnail", $first_page))
|
if (array_key_exists("thumbnail", $first_page))
|
||||||
$response["special_response"]["image"] = $first_page["thumbnail"]["source"];
|
{
|
||||||
|
$img_url = $first_page["thumbnail"]["source"];
|
||||||
|
$img_src = request($img_url);
|
||||||
|
$base64_src = base64_encode($img_src);
|
||||||
|
$response["special_response"]["image"] = $base64_src;
|
||||||
|
}
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
<div class="footer-container">
|
<div class="footer-container">
|
||||||
<a href="/">LibreX</a>
|
<a href="./">LibreX</a>
|
||||||
<a href="https://github.com/hnhx/librex/" target="_blank">Source & Instance list</a>
|
<a href="https://github.com/hnhx/librex/" target="_blank">Source & Instance list</a>
|
||||||
<a href="/settings.php">Settings</a>
|
<a href="./settings.php">Settings</a>
|
||||||
<a href="https://based-or-botnet.neocities.org/" target="_blank">Privacy guides</a>
|
<a href="./api.php" target="_blank">API</a>
|
||||||
<a href="/api.php" target="_blank">API</a>
|
<a href="./donate.php">Donate ❤️</a>
|
||||||
<a href="/donate.php">Donate ❤️</a>
|
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -6,11 +6,18 @@
|
||||||
return $base_url;
|
return $base_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
function check_for_privacy_friendly_alternative($url, $frontend, $tobereplaced)
|
function try_replace_with_frontend($url, $frontend, $tobereplaced)
|
||||||
{
|
{
|
||||||
if (isset($_COOKIE[$frontend]) || isset($_REQUEST[$frontend]))
|
$config = require "config.php";
|
||||||
|
|
||||||
|
if (isset($_COOKIE[$frontend]) || isset($_REQUEST[$frontend]) || !empty($config->$frontend))
|
||||||
{
|
{
|
||||||
$frontend = isset($_COOKIE[$frontend]) ? $_COOKIE[$frontend] : $_REQUEST[$frontend];
|
if (isset($_COOKIE[$frontend]))
|
||||||
|
$frontend = $_COOKIE[$frontend];
|
||||||
|
else if (isset($_REQUEST[$frontend]))
|
||||||
|
$frontend = $_REQUEST[$frontend];
|
||||||
|
else if (!empty($config->$frontend))
|
||||||
|
$frontend = $config->$frontend;
|
||||||
|
|
||||||
if ($tobereplaced == "instagram.com")
|
if ($tobereplaced == "instagram.com")
|
||||||
{
|
{
|
||||||
|
@ -26,16 +33,18 @@
|
||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
function privacy_friendly_alternative($url)
|
function check_for_privacy_frontend($url)
|
||||||
{
|
{
|
||||||
if (strpos($url, "youtube.com"))
|
if (strpos($url, "youtube.com"))
|
||||||
$url = check_for_privacy_friendly_alternative($url, "invidious", "youtube.com");
|
$url = try_replace_with_frontend($url, "invidious", "youtube.com");
|
||||||
else if (strpos($url, "instagram.com"))
|
else if (strpos($url, "instagram.com"))
|
||||||
$url = check_for_privacy_friendly_alternative($url, "bibliogram", "instagram.com");
|
$url = try_replace_with_frontend($url, "bibliogram", "instagram.com");
|
||||||
else if (strpos($url, "twitter.com"))
|
else if (strpos($url, "twitter.com"))
|
||||||
$url = check_for_privacy_friendly_alternative($url, "nitter", "twitter.com");
|
$url = try_replace_with_frontend($url, "nitter", "twitter.com");
|
||||||
else if (strpos($url, "reddit.com"))
|
else if (strpos($url, "reddit.com"))
|
||||||
$url = check_for_privacy_friendly_alternative($url, "libreddit", "reddit.com");
|
$url = try_replace_with_frontend($url, "libreddit", "reddit.com");
|
||||||
|
else if (strpos($url, "wikipedia.org"))
|
||||||
|
$url = try_replace_with_frontend($url, "wikiless", "wikipedia.org");
|
||||||
|
|
||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,14 +4,15 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<form class="sub-search-container" method="post" enctype="multipart/form-data" autocomplete="off">
|
<form class="sub-search-container" method="post" enctype="multipart/form-data" autocomplete="off">
|
||||||
<a href="/"><img id="logo" src="static/images/librex.png" alt="librex"></a>
|
<a href="./"><img id="logo" src="static/images/librex.png" alt="librex"></a>
|
||||||
<input type="text" name="q"
|
<input type="text" name="q"
|
||||||
<?php
|
<?php
|
||||||
$query = trim($_REQUEST["q"]);
|
$query = trim($_REQUEST["q"]);
|
||||||
|
$query_encoded = urlencode($query);
|
||||||
|
|
||||||
if (1 > strlen($query) || strlen($query) > 256)
|
if (1 > strlen($query) || strlen($query) > 256)
|
||||||
{
|
{
|
||||||
header("Location: /");
|
header("Location: ./");
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +32,6 @@
|
||||||
<button name="type" value="2"><img src="static/images/video_result.png">Videos</button>
|
<button name="type" value="2"><img src="static/images/video_result.png">Videos</button>
|
||||||
<button name="type" value="3"><img src="static/images/torrent_result.png">Torrents</button>
|
<button name="type" value="3"><img src="static/images/torrent_result.png">Torrents</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
@ -41,8 +41,6 @@
|
||||||
|
|
||||||
$page = isset($_REQUEST["p"]) ? (int) $_REQUEST["p"] : 0;
|
$page = isset($_REQUEST["p"]) ? (int) $_REQUEST["p"] : 0;
|
||||||
|
|
||||||
$query_encoded = urlencode($query);
|
|
||||||
|
|
||||||
$start_time = microtime(true);
|
$start_time = microtime(true);
|
||||||
switch ($type)
|
switch ($type)
|
||||||
{
|
{
|
||||||
|
|
38
settings.php
38
settings.php
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
require "misc/header.php";
|
require "misc/header.php";
|
||||||
|
$config = require "config.php";
|
||||||
|
|
||||||
function better_setcookie($name)
|
function better_setcookie($name)
|
||||||
{
|
{
|
||||||
|
@ -20,8 +21,9 @@
|
||||||
better_setcookie("bibliogram");
|
better_setcookie("bibliogram");
|
||||||
better_setcookie("nitter");
|
better_setcookie("nitter");
|
||||||
better_setcookie("libreddit");
|
better_setcookie("libreddit");
|
||||||
|
better_setcookie("wikiless");
|
||||||
|
|
||||||
header("Location: /settings.php");
|
header("Location: ./settings.php");
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
else if (isset($_REQUEST["reset"]))
|
else if (isset($_REQUEST["reset"]))
|
||||||
|
@ -34,7 +36,7 @@
|
||||||
setcookie($name, "", time() - 1000);
|
setcookie($name, "", time() - 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
header("Location: /settings.php");
|
header("Location: ./settings.php");
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,33 +77,39 @@
|
||||||
</div>
|
</div>
|
||||||
<h2>Privacy friendly frontends</h2>
|
<h2>Privacy friendly frontends</h2>
|
||||||
<p>For an example if you want to view YouTube without getting spied on, click on "Invidious", find the instance that is most suitable for you then paste it in (correct format: https://example.com)</p>
|
<p>For an example if you want to view YouTube without getting spied on, click on "Invidious", find the instance that is most suitable for you then paste it in (correct format: https://example.com)</p>
|
||||||
<div class="instances-container">
|
<div class="instances-container">
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<a for="invidious" href="https://docs.invidious.io/Invidious-Instances/" target="_blank">Invidious</a>
|
<a for="invidious" href="https://docs.invidious.io/instances/" target="_blank">Invidious</a>
|
||||||
<input pattern="https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)" type="text" name="invidious" placeholder="Replace YouTube" value=
|
<input type="text" name="invidious" placeholder="Replace YouTube" value=
|
||||||
<?php echo isset($_COOKIE["invidious"]) ? $_COOKIE["invidious"] : "\"\""; ?>
|
<?php echo isset($_COOKIE["invidious"]) ? $_COOKIE["invidious"] : "\"$config->invidious\""; ?>
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<a for="bibliogram" href="https://git.sr.ht/~cadence/bibliogram-docs/tree/master/docs/Instances.md" target="_blank">Bibliogram</a>
|
<a for="bibliogram" href="https://git.sr.ht/~cadence/bibliogram-docs/tree/master/docs/Instances.md" target="_blank">Bibliogram</a>
|
||||||
<input pattern="https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)" type="text" name="bibliogram" placeholder="Replace Instagram" value=
|
<input type="text" name="bibliogram" placeholder="Replace Instagram" value=
|
||||||
<?php echo isset($_COOKIE["bibliogram"]) ? $_COOKIE["bibliogram"] : "\"\""; ?>
|
<?php echo isset($_COOKIE["bibliogram"]) ? $_COOKIE["bibliogram"] : "\"$config->bibliogram\""; ?>
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<a for="nitter" href="https://github.com/zedeus/nitter/wiki/Instances" target="_blank">Nitter</a>
|
<a for="nitter" href="https://github.com/zedeus/nitter/wiki/Instances" target="_blank">Nitter</a>
|
||||||
<input pattern="https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)" type="text" name="nitter" placeholder="Replace Twitter" value=
|
<input type="text" name="nitter" placeholder="Replace Twitter" value=
|
||||||
<?php echo isset($_COOKIE["nitter"]) ? $_COOKIE["nitter"] : "\"\""; ?>
|
<?php echo isset($_COOKIE["nitter"]) ? $_COOKIE["nitter"] : "\"$config->nitter\""; ?>
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<a for="libreddit" href="https://github.com/spikecodes/libreddit" target="_blank">Libreddit</a>
|
<a for="libreddit" href="https://github.com/spikecodes/libreddit" target="_blank">Libreddit</a>
|
||||||
<input pattern="https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)" type="text" name="libreddit" placeholder="Replace Reddit" value=
|
<input type="text" name="libreddit" placeholder="Replace Reddit" value=
|
||||||
<?php echo isset($_COOKIE["libreddit"]) ? $_COOKIE["libreddit"] : "\"\""; ?>
|
<?php echo isset($_COOKIE["libreddit"]) ? $_COOKIE["libreddit"] : "\"$config->libreddit\""; ?>
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<a for="wikiless" href="https://codeberg.org/orenom/wikiless" target="_blank">Wikiless</a>
|
||||||
|
<input type="text" name="wikiless" placeholder="Replace Wikipedia" value=
|
||||||
|
<?php echo isset($_COOKIE["wikiless"]) ? $_COOKIE["wikiless"] : "\"$config->wikiless\""; ?>
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -129,4 +137,4 @@
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php require "misc/footer.php"; ?>
|
<?php require "misc/footer.php"; ?>
|
Loading…
Reference in a new issue