9135f9395c
8e0d2ca264
bfca82f4e3
ca1c804eba
836521b8d7
This commit is contained in:
FbIN Support 2026-10-11 16:49:01 +05:30
commit 0049f0a983
2 changed files with 144 additions and 21 deletions

View file

@ -42,6 +42,29 @@ class config{
// Or "https://your-endpoint.com/my-endpoint" (excluding get parameters like &pw) // Or "https://your-endpoint.com/my-endpoint" (excluding get parameters like &pw)
const FPLAY_EXTERNAL_ENDPOINT = null; const FPLAY_EXTERNAL_ENDPOINT = null;
//
// RATELIMITING
// Limits also applies to the captcha page
//
// Amount of requests allowed before we block
// Set to 0 to disable ratelimiting
const RATELIMIT_BURST = 0;
// IP source for ratelimiting. Choices: false for getting the IP directly,
// or "X-Header-Name" to get the IP from a forwarded header
const RATELIMIT_IP_SOURCE = false;
// How long till the counter resets? Note: counter resets everytime
// a new request occurs while being blocked.
const RATELIMIT_TIME = 2;
// How many seconds to add every time a new request occurs while being blocked?
const RATELIMIT_PUNISH = 1;
// Add seconds of punishment time to users of the API?
const RATELIMIT_PUNISH_API = false;
// //
// BOT PROTECTION // BOT PROTECTION
// //
@ -96,11 +119,9 @@ class config{
const MAX_SEARCHES = 100; const MAX_SEARCHES = 100;
// List of domains that point to your servers. Include your tor/i2p // List of domains that point to your servers. Include your tor/i2p
// addresses here! Must be a valid URL. Won't affect links placed on // addresses here! Must be a valid URL.
// the homepage. const ADDRESSES = [
const ALT_ADDRESSES = [ //"https://fossq.com",
//"https://4get.alt-tld",
//"http://4getwebfrq5zr4sxugk6htxvawqehxtdgjrbcn2oslllcol2vepa23yd.onion"
]; ];
// Known FOSS-Q instances. MUST use the https protocol if your instance uses // Known FOSS-Q instances. MUST use the https protocol if your instance uses
@ -110,30 +131,30 @@ class config{
const INSTANCES = [ const INSTANCES = [
"https://4get.ca", "https://4get.ca",
"https://search.fischbytes.de", "https://search.fischbytes.de",
"https://FOSS-Q.nadeko.net", "https://4get.nadeko.net",
"https://FOSS-Q.silly.computer", "https://4get.silly.computer",
"https://FOSS-Q.sijh.net", "https://4get.sijh.net",
"https://FOSS-Q.hbubli.cc", "https://4get.hbubli.cc",
"https://FOSS-Q.lunar.icu", "https://4get.lunar.icu",
"https://FOSS-Q.dcs0.hu", "https://4get.dcs0.hu",
"https://FOSS-Q.neco.lol", "https://4get.neco.lol",
"https://FOSS-Q.edmateo.site", "https://4get.edmateo.site",
"https://FOSS-Q.sudovanilla.org", "https://4get.sudovanilla.org",
"https://search.mint.lgbt", "https://search.mint.lgbt",
"https://FOSS-Q.aishiteiru.moe", "https://4get.aishiteiru.moe",
"https://4.nboeck.de", "https://4.nboeck.de",
"https://search.yonderly.org", "https://search.yonderly.org",
"https://FOSS-Q.lurx.net", "https://4get.lurx.net",
"https://FOSS-Q.canine.tools", "https://4get.canine.tools",
"https://FOSS-Q.sny.sh", "https://4get.sny.sh",
"https://4g.opnxng.com", "https://4g.opnxng.com",
"https://s.307200.xyz", "https://s.307200.xyz",
"https://FOSS-Q.privadency.com/" "https://4get.privadency.com/"
]; ];
// Default user agent to use for scraper requests. Sometimes ignored to get specific webpages // Default user agent to use for scraper requests. Sometimes ignored to get specific webpages
// Changing this might break things. // Changing this might break things.
const USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:155.0) Gecko/20100101 Firefox/155.0"; const USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:157.0) Gecko/20100101 Firefox/157.0";
// User agent to use with 4get-friendly APIs // User agent to use with 4get-friendly APIs
const USER_AGENT_FRIENDLY = "4get-scrapist (+https://4get.ca)"; const USER_AGENT_FRIENDLY = "4get-scrapist (+https://4get.ca)";
@ -167,6 +188,7 @@ class config{
const PROXY_ARCHIVEORG = false; const PROXY_ARCHIVEORG = false;
const PROXY_SEPIASEARCH = false; const PROXY_SEPIASEARCH = false;
const PROXY_ODYSEE = false; const PROXY_ODYSEE = false;
const PROXY_DAILYMOTION = false;
const PROXY_VIMEO = false; const PROXY_VIMEO = false;
const PROXY_YEP = false; const PROXY_YEP = false;
const PROXY_PINTEREST = false; const PROXY_PINTEREST = false;

View file

@ -4,6 +4,93 @@ class bot_protection{
public function __construct($frontend, $get, $filters, $page, $output){ public function __construct($frontend, $get, $filters, $page, $output){
if(config::RATELIMIT_BURST !== 0){
// ratelimit requests per IP
if(config::RATELIMIT_IP_SOURCE === false){
$source = $_SERVER["REMOTE_ADDR"];
}else{
$source = $_SERVER[explode(";", strtoupper(str_replace("-", "_", config::IP_SOURCE)))[0]];
}
// check if its not a local IP. Probably local tor bridge, dont ratelimit
if(
filter_var(
$source,
FILTER_VALIDATE_IP,
FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE
) !== false
){
$source = "r." . $source;
// counter
// resets on every req
$counter = apcu_fetch($source);
$counter = (int)$counter + 1;
if(
(
CONFIG::RATELIMIT_PUNISH !== 0 &&
$counter > config::RATELIMIT_BURST + 1
) &&
(
(
$output === false &&
CONFIG::RATELIMIT_PUNISH_API === true
) ||
$output === true
)
){
$block_time = config::RATELIMIT_TIME + (($counter - 1) * config::RATELIMIT_PUNISH);
}else{
$block_time = config::RATELIMIT_TIME;
}
apcu_store($source, $counter, $block_time);
if($counter > config::RATELIMIT_BURST){
apcu_inc(intdiv(time(), 3600) . ".bot_requests", 1, $s, 262800);
if($output === false){
http_response_code(429);
echo json_encode([
"status" => "You love 4get too much. Try again in " . $this->format_time($block_time) . "."
]);
die();
}
$payload = [
"timetaken" => microtime(true),
"class" => "",
"right-left" => "",
"right-right" => "",
"left" =>
'<div class="infobox">' .
'<h1>You\'re damaging my calm</h1>' .
'You love 4get too much. Try again in <b>' . $this->format_time($block_time) . '</b>.' .
'</div>'
];
$frontend->loadheader(
$get,
$filters,
$page,
false
);
echo $frontend->load("search.html", $payload);
die();
}
}
}
// check if we want captcha // check if we want captcha
if(config::BOT_PROTECTION !== 1){ if(config::BOT_PROTECTION !== 1){
@ -186,7 +273,7 @@ class bot_protection{
} }
} }
apcu_inc(intdiv(time(), 3600) . ".bot_requests", 1, $s, 259200); apcu_inc(intdiv(time(), 3600) . ".bot_requests", 1, $s, 262800);
$key = "c" . apcu_inc("captcha_gen", 1) . "." . $this->randomchars(); $key = "c" . apcu_inc("captcha_gen", 1) . "." . $this->randomchars();
$payload = [ $payload = [
@ -257,6 +344,20 @@ class bot_protection{
die(); die();
} }
private function format_time($seconds){
$hours = floor($seconds / 3600);
$minutes = floor(($seconds % 3600) / 60);
$secs = $seconds % 60;
if($hours > 0){
return sprintf('%dh%02dm%02ds', $hours, $minutes, $secs);
}
return sprintf('%dm%02ds', $minutes, $secs);
}
private function randomchars(){ private function randomchars(){
$chars = $chars =