Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable redirection #260

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config.php.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

"disable_hidden_service_search" => false,

// You can disable automatic redirection from your instance
"automatic_redirection" => true,

/*
Preset privacy friendly frontends for users, these can be overwritten by users in the settings
e.g.: Preset the invidious instance URL: "instance_url" => "https://yewtu.be",
Expand Down
9 changes: 8 additions & 1 deletion engines/google/text.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function get_text_results($query, $page)
$results = array();

$domain = $config->google_domain;
$automatic_redirection = isset($_COOKIE["automatic_redirection"]);
$site_language = isset($_COOKIE["google_language_site"]) ? trim(htmlspecialchars($_COOKIE["google_language_site"])) : $config->google_language_site;
$results_language = isset($_COOKIE["google_language_results"]) ? trim(htmlspecialchars($_COOKIE["google_language_results"])) : $config->google_language_results;
$number_of_results = isset($_COOKIE["google_number_of_results"]) ? trim(htmlspecialchars($_COOKIE["google_number_of_results"])) : $config->google_number_of_results;
Expand Down Expand Up @@ -70,11 +71,17 @@ function get_text_results($query, $page)
do {
curl_multi_exec($mh, $running);
} while ($running);
if (curl_getinfo($google_ch)['http_code'] == '302') {

if (curl_getinfo($google_ch)['http_code'] != '200') {
if ($automatic_redirection
&& $config->automatic_redirection) {
$instances_json = json_decode(file_get_contents("instances.json"), true);
$instances = array_map(fn($n) => $n['clearnet'], array_filter($instances_json['instances'], fn($n) => !is_null($n['clearnet'])));
header("Location: " . $instances[array_rand($instances)] . "search.php?q=$query");
die();
} else {
return $results;
}
}


Expand Down
10 changes: 9 additions & 1 deletion settings.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php
$config = require "config.php";

if (isset($_REQUEST["reset"]))
// Reset all cookies when resetting, or before saving new cookies
if (isset($_REQUEST["reset"]) || isset($_REQUEST["save"]))
{
if (isset($_SERVER["HTTP_COOKIE"]))
{
Expand Down Expand Up @@ -103,6 +104,13 @@

<h2>Google settings</h2>
<div class="settings-textbox-container">
<?php if ($config->automatic_redirection) : ?>
<div>
<label>Redirect to other instances if this one doesn't work</label>
<input type="checkbox" name="automatic_redirection" <?php echo isset($_COOKIE["automatic_redirection"]) ? "checked" : ""; ?> >
</div>
<?php endif; ?>

<div>
<span>Site language</span>
<?php
Expand Down