From 2976c0a6a4c3ef72784a92867edd7df32ef67d3a Mon Sep 17 00:00:00 2001 From: lolcat Date: Sun, 24 Mar 2024 22:31:19 -0400 Subject: fag protection --- lib/frontend.php | 58 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 22 deletions(-) (limited to 'lib/frontend.php') diff --git a/lib/frontend.php b/lib/frontend.php index d82dba2..68398b5 100644 --- a/lib/frontend.php +++ b/lib/frontend.php @@ -44,7 +44,7 @@ class frontend{ $replacements["timetaken"] !== null ){ - $replacements["timetaken"] = '
Took ' . substr(microtime(true) - $replacements["timetaken"], 0, 4) . 's
'; + $replacements["timetaken"] = '
Took ' . number_format(microtime(true) - $replacements["timetaken"], 2) . 's
'; } $handle = fopen("template/{$template}", "r"); @@ -84,29 +84,54 @@ class frontend{ "filters" => $this->generatehtmlfilters($filters, $get) ]); + $headers_raw = getallheaders(); + $header_keys = []; + $user_agent = ""; + $bad_header = false; + + foreach($headers_raw as $headerkey => $headervalue){ + + $headerkey = strtolower($headerkey); + if($headerkey == "user-agent"){ + + $user_agent = $headervalue; + continue; + } + + // check header key + if(in_array($headerkey, config::FILTERED_HEADER_KEYS)){ + + $bad_header = true; + break; + } + } + if( preg_match( - '/bot|wget|curl|python-requests|scrapy|feedfetcher|go-http-client|ruby|universalfeedparser|yahoo\! slurp|spider|rss/i', - $_SERVER["HTTP_USER_AGENT"] - ) + config::HEADER_REGEX, + $user_agent + ) || + $bad_header === true ){ // bot detected !! apcu_inc("captcha_gen"); + $null = null; $this->drawerror( "Tshh, blocked!", - 'You were blocked from viewing this page. If you wish to scrape data from 4get, please consider running your own 4get instance.', + 'Your browser, IP or IP range has been blocked from this 4get instance. If this is an error, please contact the administrator.', + microtime(true) ); die(); } } - public function drawerror($title, $error){ + public function drawerror($title, $error, $timetaken){ echo $this->load("search.html", [ - "timetaken" => null, + "timetaken" => $timetaken, "class" => "", "right-left" => "", "right-right" => "", @@ -119,7 +144,7 @@ class frontend{ die(); } - public function drawscrapererror($error, $get, $target){ + public function drawscrapererror($error, $get, $target, $timetaken){ $this->drawerror( "Shit", @@ -131,7 +156,8 @@ class frontend{ '
  • Remove keywords that could cause errors
  • ' . '
  • buildquery($get, false) . '">Try your search on another 4get instance
  • ' . '
    ' . - 'If the error persists, please contact the administrator.' + 'If the error persists, please contact the administrator.', + $timetaken ); } @@ -483,10 +509,6 @@ class frontend{ $archives[] = "warosu.org"; break; - case "cm": - $archives[] = "boards.fireden.net"; - break; - case "f": $archives[] = "archive.4plebs.org"; break; @@ -503,12 +525,10 @@ class frontend{ break; case "v": - $archives[] = "boards.fireden.net"; $archives[] = "arch.b4k.co"; break; case "vg": - $archives[] = "boards.fireden.net"; $archives[] = "arch.b4k.co"; break; @@ -579,7 +599,6 @@ class frontend{ break; case "sci": - $archives[] = "boards.fireden.net"; $archives[] = "warosu.org"; $archives[] = "eientei.xyz"; break; @@ -614,7 +633,6 @@ class frontend{ break; case "ic": - $archives[] = "boards.fireden.net"; $archives[] = "warosu.org"; break; @@ -741,10 +759,6 @@ class frontend{ $archives[] = "desuarchive.org"; break; - case "y": - $archives[] = "boards.fireden.net"; - break; - case "t": $archives[] = "archiveofsins.com"; break; @@ -802,7 +816,7 @@ class frontend{ $payload .= 'goGoogle cache' . 'arArchive.org' . - 'arArchive.is' . + 'arArchive.is' . 'ghGhostarchive' . 'biBing cache' . 'meMegalodon' . -- cgit v1.2.3