diff options
| author | Pinapelz <yukais@pinapelz.com> | 2026-05-27 21:30:45 -0700 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2026-05-27 21:46:34 -0700 |
| commit | af79a76c78d7886a365784ac6d1895f65c1c381e (patch) | |
| tree | a7f70fca59cda25a97bcfdf932eea643231161d9 | |
| parent | 1da02013c535c85b39417ba5f17f23a8b4ad6782 (diff) | |
update IQ test text and font
| -rwxr-xr-x | captcha.php | 60 | ||||
| -rw-r--r-- | data/fonts/captcha.ttf | bin | 125972 -> 15372 bytes | |||
| -rw-r--r-- | docker-compose.yaml | 1 | ||||
| -rw-r--r-- | lib/bot_protection.php | 106 |
4 files changed, 84 insertions, 83 deletions
diff --git a/captcha.php b/captcha.php index 286a277..49e6c5b 100755 --- a/captcha.php +++ b/captcha.php @@ -8,7 +8,7 @@ if( $_GET["v"] ) === 0 ){ - + http_response_code(401); header("Content-Type: text/plain"); echo "Fuck my feathered cloaca"; @@ -19,7 +19,7 @@ if( include "data/config.php"; if(config::BOT_PROTECTION !== 1){ - + header("Content-Type: text/plain"); echo "The IQ test is disabled"; die(); @@ -28,7 +28,7 @@ if(config::BOT_PROTECTION !== 1){ $grid = apcu_fetch($_GET["v"]); if($grid !== false){ - + // captcha already generated http_response_code(304); // not modified die(); @@ -48,7 +48,7 @@ array_splice($range, 0, 1); $picks = random_int(3, 6); for($i=0; $i<$picks; $i++){ - + $answer_pos_tmp = array_splice( $range, @@ -58,7 +58,7 @@ for($i=0; $i<$picks; $i++){ ), 1 ); - + $answer_pos[] = $answer_pos_tmp[0]; } @@ -68,12 +68,12 @@ $choosen = config::CAPTCHA_DATASET[random_int(0, $c - 1)]; $choices = []; for($i=0; $i<$c; $i++){ - + if(config::CAPTCHA_DATASET[$i][0] == $choosen[0]){ - + continue; } - + $choices[] = config::CAPTCHA_DATASET[$i]; } @@ -81,12 +81,12 @@ for($i=0; $i<$c; $i++){ $grid = []; for($i=0; $i<16; $i++){ - + if(in_array($i, $answer_pos)){ - + $grid[] = $choosen; }else{ - + $grid[] = $choices[random_int(0, count($choices) - 1)]; } } @@ -100,13 +100,13 @@ apcu_store( // generate image if(random_int(0,1) === 0){ - + $theme = [ "bg" => "#ebdbb2", "fg" => "#1d2021" ]; }else{ - + $theme = [ "bg" => "#1d2021", "fg" => "#ebdbb2" @@ -130,52 +130,52 @@ $distort = [ $i = 0; for($y=0; $y<4; $y++){ - + for($x=0; $x<4; $x++){ - + $tmp = new Imagick("./data/captcha/" . $grid[$i][0] . "/" . random_int(1, $grid[$i][1]) . ".png"); - + // convert transparency correctly $tmp->setImageBackgroundColor("black"); $tmp->setImageAlphaChannel(Imagick::ALPHACHANNEL_REMOVE); - + // randomly mirror if(random_int(0,1) === 1){ - + $tmp->flopImage(); } - + // distort $tmp $tmp->distortImage( $distort[random_int(0,1)], [ 0, 0, random_int(-15, 15), random_int(-15, 15), - + 100, 0, random_int(80, 120), random_int(-15, 15), - + 100, 100, random_int(80, 120), random_int(80, 120), - + 0, 100, random_int(-15, 15), random_int(80, 120) ], false ); - + $tmp->addNoiseImage($noise[random_int(0, 1)]); - + // append image $im->compositeImage($tmp->getImage(), Imagick::COMPOSITE_DEFAULT, $x * 100, ($y * 100) + 27); - + $i++; } } // add text $draw = new ImagickDraw(); -$draw->setFontSize(20); +$draw->setFontSize(24); $draw->setFillColor($theme["fg"]); //$draw->setTextAntialias(false); $draw->setFont("./data/fonts/captcha.ttf"); @@ -185,17 +185,17 @@ $text = "Pick " . $picks . " images of " . str_replace("_", " ", $choosen[0]); $pos = 200 - ($im->queryFontMetrics($draw, $text)["textWidth"] / 2); for($i=0; $i<strlen($text); $i++){ - + $im->annotateImage( $draw, $pos, - 20, + 22, random_int(-15, 15), $text[$i] ); - + $pos += $im->queryFontMetrics($draw, $text[$i])["textWidth"]; - + } $im->setFormat("jpeg"); diff --git a/data/fonts/captcha.ttf b/data/fonts/captcha.ttf Binary files differindex 13f5dc7..e2bd7e5 100644 --- a/data/fonts/captcha.ttf +++ b/data/fonts/captcha.ttf diff --git a/docker-compose.yaml b/docker-compose.yaml index 8596e6e..3053f33 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -10,6 +10,7 @@ services: - FOURGET_SERVER_NAME=find.moekyun.me - FOURGET_BOT_PROTECTION=1 - FOURGET_API_ENABLED=0 + - FOURGET_MAX_SEARCHES=300 ports: - "8081:80" volumes: diff --git a/lib/bot_protection.php b/lib/bot_protection.php index 5a823e0..465190f 100644 --- a/lib/bot_protection.php +++ b/lib/bot_protection.php @@ -1,12 +1,12 @@ <?php class bot_protection{ - + public function __construct($frontend, $get, $filters, $page, $output){ - + // check if we want captcha if(config::BOT_PROTECTION !== 1){ - + apcu_inc("real_requests"); if($output === true){ $frontend->loadheader( @@ -17,12 +17,12 @@ class bot_protection{ } return; } - + /* Validate cookie, if it exists */ if(isset($_COOKIE["pass"])){ - + if( // check if key is not malformed preg_match( @@ -32,22 +32,22 @@ class bot_protection{ // does key exist apcu_exists($_COOKIE["pass"]) ){ - + // exists, increment counter $inc = apcu_inc($_COOKIE["pass"]); - + // we start counting from 1 // when it has been incremented to 102, it has reached // 100 reqs if($inc >= config::MAX_SEARCHES + 2){ - + // reached limit, delete and give captcha apcu_delete($_COOKIE["pass"]); }else{ - + // the cookie is OK! dont die() and give results apcu_inc("real_requests"); - + if($output === true){ $frontend->loadheader( $get, @@ -59,16 +59,16 @@ class bot_protection{ } } } - + if($output === false){ - + http_response_code(401); // forbidden echo json_encode([ "status" => "The \"pass\" token in your cookies is missing or has expired!!" ]); die(); } - + /* Validate form data */ @@ -84,26 +84,26 @@ class bot_protection{ $error = ""; foreach($lines as $line){ - + $line = explode("=", $line, 2); - + if(count($line) !== 2){ - + $invalid = true; break; } - + preg_match( '/^c\[([0-9]+)\]$/', $line[0], $regex ); - + if( $line[1] != "on" || !isset($regex[0][1]) ){ - + // check if its the v key if( $line[0] == "v" && @@ -112,61 +112,61 @@ class bot_protection{ $line[1] ) ){ - + $key = apcu_fetch($line[1]); apcu_delete($line[1]); } break; } - + $regex = (int)$regex[1]; - + if( $regex >= 16 || $regex <= -1 ){ - + $invalid = true; break; } - + $answers[] = $regex; } - + // dedup $answers = array_unique($answers); - + if( !$invalid && $key !== false // has captcha been gen'd? ){ $check = count($key); - + // validate answer for($i=0; $i<count($answers); $i++){ - + if(in_array($answers[$i], $key)){ - + $check--; }else{ - + $check = -1; break; } } - + if($check === 0){ - + // we passed the captcha // set cookie $inc = apcu_inc("cookie"); - + $key = "k" . $inc . "." . $this->randomchars(); - + apcu_inc($key, 1, $stupid, 86400); - + apcu_inc("real_requests"); - + setcookie( "pass", $key, @@ -176,22 +176,22 @@ class bot_protection{ "path" => "/" ] ); - + $frontend->loadheader( $get, $filters, $page ); return; - + }else{ - - $error = "<div class=\"quote\">You were <a href=\"https://www.youtube.com/watch?v=e1d7fkQx2rk\" target=\"_BLANK\" rel=\"noreferrer nofollow\">kicked out of Mensa.</a> Please try again.</div>"; + + $error = "<div class=\"quote\">You got it wrong lol. Try again.</div>"; } } - + $key = "c" . apcu_inc("captcha_gen", 1) . "." . $this->randomchars(); - + $payload = [ "timetaken" => microtime(true), "class" => "", @@ -201,7 +201,7 @@ class bot_protection{ '<div class="infobox">' . '<h1>IQ test</h1>' . 'IQ test has been enabled due to bot abuse on the network.<br>' . - 'Solving this IQ test will let you make 100 searches today. I will add an invite system to bypass this soon...' . + 'Solving this IQ test will let you make 300 searches today.' . $error . '<form method="POST" enctype="text/plain" autocomplete="off">' . '<div class="captcha-wrapper">' . @@ -248,37 +248,37 @@ class bot_protection{ '</form>' . '</div>' ]; - + $frontend->loadheader( $get, $filters, $page ); - + echo $frontend->load("search.html", $payload); die(); } - + private function randomchars(){ - + $chars = array_merge( range("A", "Z"), range("a", "z"), range(0, 9) ); - + $chars[] = "_"; - + $c = count($chars) - 1; - + $key = ""; - + for($i=0; $i<20; $i++){ - + $key .= $chars[random_int(0, $c)]; } - + return $key; } } |
