Commit fd9fa01b authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

parallel captcha requests are now possible

parent aea78d20
...@@ -46,20 +46,19 @@ class HumanVerification extends Controller ...@@ -46,20 +46,19 @@ class HumanVerification extends Controller
if ($request->getMethod() == 'POST') { if ($request->getMethod() == 'POST') {
\App\PrometheusExporter::CaptchaAnswered(); \App\PrometheusExporter::CaptchaAnswered();
$lockedKey = $user["lockedKey"]; $lockedKey = $request->input("c", "");
$rules = ['captcha' => 'required|captcha_api:' . $lockedKey . ',math']; $rules = ['captcha' => 'required|captcha_api:' . $lockedKey . ',math'];
$validator = validator()->make(request()->all(), $rules); $validator = validator()->make(request()->all(), $rules);
if($validator->fails()) { if (empty($lockedKey) || $validator->fails()) {
$captcha = Captcha::create("default", true); $captcha = Captcha::create("default", true);
$user["lockedKey"] = $captcha["key"];
HumanVerification::saveUser($user);
\App\PrometheusExporter::CaptchaShown(); \App\PrometheusExporter::CaptchaShown();
return view('humanverification.captcha')->with('title', 'Bestätigung notwendig') return view('humanverification.captcha')->with('title', 'Bestätigung notwendig')
->with('uid', $user["uid"]) ->with('uid', $user["uid"])
->with('id', $id) ->with('id', $id)
->with('url', $url) ->with('url', $url)
->with('correct', $captcha["key"])
->with('image', $captcha["img"]) ->with('image', $captcha["img"])
->with('errorMessage', 'Fehler: Falsche Eingabe!'); ->with('errorMessage', 'Fehler: Falsche Eingabe!');
} else { } else {
...@@ -69,7 +68,6 @@ class HumanVerification extends Controller ...@@ -69,7 +68,6 @@ class HumanVerification extends Controller
# The Captcha was correct. We can remove the key from the user # The Captcha was correct. We can remove the key from the user
# Additionally we will whitelist him so he is not counted towards botnetwork # Additionally we will whitelist him so he is not counted towards botnetwork
$user["locked"] = false; $user["locked"] = false;
$user["lockedKey"] = "";
$user["whitelist"] = true; $user["whitelist"] = true;
HumanVerification::saveUser($user); HumanVerification::saveUser($user);
return redirect($url); return redirect($url);
...@@ -80,39 +78,37 @@ class HumanVerification extends Controller ...@@ -80,39 +78,37 @@ class HumanVerification extends Controller
} }
$captcha = Captcha::create("default", true); $captcha = Captcha::create("default", true);
$user["lockedKey"] = $captcha["key"];
HumanVerification::saveUser($user);
\App\PrometheusExporter::CaptchaShown(); \App\PrometheusExporter::CaptchaShown();
return view('humanverification.captcha')->with('title', 'Bestätigung notwendig') return view('humanverification.captcha')->with('title', 'Bestätigung notwendig')
->with('uid', $user["uid"]) ->with('uid', $user["uid"])
->with('id', $id) ->with('id', $id)
->with('url', $url) ->with('url', $url)
->with('correct', $captcha["key"])
->with('image', $captcha["img"]); ->with('image', $captcha["img"]);
} }
public static function logCaptcha(Request $request){ public static function logCaptcha(Request $request)
{
$fail2banEnabled = config("metager.metager.fail2ban.enabled"); $fail2banEnabled = config("metager.metager.fail2ban.enabled");
if(empty($fail2banEnabled) || !$fail2banEnabled || !config("metager.metager.fail2ban.url") || !config("metager.metager.fail2ban.user") || !config("metager.metager.fail2ban.password")){ if (empty($fail2banEnabled) || !$fail2banEnabled || !config("metager.metager.fail2ban.url") || !config("metager.metager.fail2ban.user") || !config("metager.metager.fail2ban.password")) {
return; return;
} }
// Submit fetch job to worker // Submit fetch job to worker
$mission = [ $mission = [
"resulthash" => "captcha", "resulthash" => "captcha",
"url" => config("metager.metager.fail2ban.url") . "/captcha/", "url" => config("metager.metager.fail2ban.url") . "/captcha/",
"useragent" => "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0", "useragent" => "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0",
"username" => config("metager.metager.fail2ban.user"), "username" => config("metager.metager.fail2ban.user"),
"password" => config("metager.metager.fail2ban.password"), "password" => config("metager.metager.fail2ban.password"),
"headers" => [ "headers" => [
"ip" => $request->ip() "ip" => $request->ip()
], ],
"cacheDuration" => 0, "cacheDuration" => 0,
"name" => "Captcha", "name" => "Captcha",
]; ];
$mission = json_encode($mission); $mission = json_encode($mission);
Redis::rpush(\App\MetaGer::FETCHQUEUE_KEY, $mission); Redis::rpush(\App\MetaGer::FETCHQUEUE_KEY, $mission);
} }
public static function remove(Request $request) public static function remove(Request $request)
......
...@@ -3,19 +3,22 @@ ...@@ -3,19 +3,22 @@
@section('title', $title ) @section('title', $title )
@section('content') @section('content')
<h1>@lang('captcha.1')</h1> <h1>@lang('captcha.1')</h1>
<p>@lang('captcha.2')</p> <p>@lang('captcha.2')</p>
<p>@lang('captcha.3')</p> <p>@lang('captcha.3')</p>
<p>@lang('captcha.4')</p> <p>@lang('captcha.4')</p>
<form method="post" action="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('verification', ['id' => $id, 'uid' => $uid])) }}"> <form method="post" action="{{ LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('verification', ['id' => $id, 'uid' => $uid])) }}">
<input type="hidden" name="url" value="{!! $url !!}"> <input type="hidden" name="url" value="{!! $url !!}">
<input type="hidden" name="uid" value="{{ $uid }}"> <input type="hidden" name="uid" value="{{ $uid }}">
<input type="hidden" name="id" value="{{ $id }}"> <input type="hidden" name="id" value="{{ $id }}">
<p><img src="{{ $image }}" /></p> <input type="hidden" name="c" value="{{ $correct }}">
@if(isset($errorMessage)) <p><img src="{{ $image }}" /></p>
<p><font color="red">{{$errorMessage}}</font></p> @if(isset($errorMessage))
@endif <p>
<p><input type="text" class="form-control" name="captcha" placeholder="@lang('captcha.5')" autofocus></p> <font color="red">{{$errorMessage}}</font>
<p><button type="submit" class="btn btn-success" name="check">OK</button></p> </p>
</form> @endif
@endsection <p><input type="text" class="form-control" name="captcha" placeholder="@lang('captcha.5')" autofocus></p>
<p><button type="submit" class="btn btn-success" name="check">OK</button></p>
</form>
@endsection
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment