Skip to content
Snippets Groups Projects
Commit d87a543f authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

added audiocaptcha player

parent 0d767158
No related branches found
No related tags found
1 merge request!1992Resolve "Include Audiocaptcha"
......@@ -14,6 +14,7 @@ use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Redis;
use Input;
use Laravel\SerializableClosure\Signers\Hmac;
use LaravelLocalization;
class HumanVerification extends Controller
{
......@@ -53,7 +54,7 @@ class HumanVerification extends Controller
// Extract the correct solution to this captcha for generating the Audio Captcha
$text = implode(" ", $captcha->getText());
$key = Crypt::decrypt($captcha_key["key"]);
$tts_url = TTSController::CreateTTSUrl($text, LaravelLocalization::getCurrentLocale());
# $captcha = Captcha::create("default", true);
......@@ -64,6 +65,7 @@ class HumanVerification extends Controller
->with('url', $redirect_url)
->with('correct', $captcha_key["key"])
->with('image', $captcha_key["img"])
->with('tts_url', $tts_url)
->with('css', [mix('css/verify/index.css')]);
}
......
<?php
namespace App\Http\Controllers;
use Crypt;
use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Http\Request;
class TTSController extends Controller
{
public function tts(Request $request)
{
$text_params = $request->input("text", "");
try {
$text_params = Crypt::decrypt($text_params);
} catch (DecryptException $exception) {
abort(404);
}
$text = $text_params["text"];
$locale = $text_params["locale"];
$voices = [
"de" => "bits1-hsmm",
"en_GB" => "dfki-prudence-hsmm",
];
$mary_tts_params = [
"INPUT_TEXT" => $text,
"INPUT_TYPE" => "TEXT",
"OUTPUT_TYPE" => "AUDIO",
"AUDIO" => "WAVE_FILE",
"LOCALE" => $locale,
"VOICE" => $voices[$locale]
];
$mary_tts_url = config("metager.metager.tts.base_url");
if (empty($mary_tts_url)) {
abort(404);
}
$get_params = \http_build_query($mary_tts_params, "", "&", PHP_QUERY_RFC1738);
$mary_tts_url .= "/process?" . $get_params;
$content = \file_get_contents($mary_tts_url);
return response($content, 200, [
"Content-Type" => "audio/x-wav",
"Pragma" => "no-cache",
"Cache-Control" => "no-cache, no-store, must-revalidate",
"Content-Length" => strlen($content),
]);
}
/**
* Generates a URL for transforming given text into
* speech in given locale
*
* @param $text The Text to convert to speech
* @param $locale The Locale of the speech (only "de" and "en" supported currently; fallback is en)
*/
public static function CreateTTSUrl(string $text, string $locale = "en_GB")
{
$supported_locales = [
"de" => "de",
"en" => "en_GB"
];
$text_param = [
"text" => $text,
"locale" => in_array($locale, array_keys($supported_locales)) ? $supported_locales[$locale] : "en_GB",
];
$text_param = Crypt::encrypt($text_param);
$url = route("tts", ["text" => $text_param]);
return $url;
}
}
......@@ -17,6 +17,9 @@ return [
"assoziator" => env("ASSO_KEY"),
"berlin" => env("berlin"),
],
"tts" => [
"base_url" => env("TTS_BASE_URL", ""),
],
"fetcher" => [
"proxy" => [
"host" => env("PROXY_HOST", ""),
......
<?php
return [
'1' => 'Sicherheitsabfrage',
'2' => 'Bitte geben Sie die 5 Zeichen aus dem Bild in die Eingabebox und bestätigen Sie mit "OK" um zur Ergebnisseite zu gelangen.',
'2' => 'Bitte geben Sie die 5 Zeichen aus dem Bild oder dem Audioplayer in die Eingabebox ein und bestätigen Sie mit "OK" um zur Ergebnisseite zu gelangen.',
'3' => 'Captcha eingeben',
'4' => 'Auf diesem Gerät nicht erneut fragen (optional; setzt einen Cookie)',
];
<?php
return [
'1' => 'Sorry to bother you',
'2' => 'Please enter the five characters from the picture in the input box and confirm with "OK" to get to the result page.',
'2' => 'Please enter the five characters from the picture or the audioplayer into the input field and confirm with "OK" to get to the result page.',
'3' => 'Enter captcha',
'4' => 'Do not ask again on this device (optional; sets a cookie)',
];
<?php
return [
'1' => 'Perdon por la molestia',
'2' => 'Ingrese los cinco caracteres de la imagen en el cuadro de entrada y confirme con "OK" para llegar a la página de resultados.',
'2' => 'Introduzca los cinco caracteres de la imagen o del reproductor de audio en el campo de entrada y confirme con "OK" para llegar a la página de resultados.',
'3' => 'Entrar en captcha',
'4' => 'No volver a preguntar en este dispositivo (opcional, establece una cookie)',
];
#captcha-container {
display: flex;
justify-content: center;
flex-direction: column;
margin-bottom: 2rem;
>img {
max-width: 100%;
max-width: min
}
>div#audio-captcha>audio {
width: 100%;
}
}
#error {
......
......@@ -10,6 +10,12 @@
<input type="hidden" name="c" value="{{ $correct }}">
<div id="captcha-container">
<img src="{{ $image }}" />
<div id="audio-captcha">
<audio controls="controls" autoplay="autoplay">
<source src="{{$tts_url}}" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</div>
</div>
@if(Request::has('e'))
<p id="error">{{ __('Fehler: Falsche Eingabe!') }}</p>
......
......@@ -3,6 +3,7 @@
use App\Http\Controllers\AdminInterface;
use App\Http\Controllers\Prometheus;
use App\Http\Controllers\SearchEngineList;
use App\Http\Controllers\TTSController;
use Jenssegers\Agent\Agent;
use Illuminate\Http\Request;
use Illuminate\Routing\Router;
......@@ -44,6 +45,8 @@ Route::get('asso', function () {
->with('darkcss', [mix('css/asso/dark.css')]);
});
Route::get('tts', [TTSController::class, 'tts'])->name("tts");
Route::get('asso/meta.ger3', 'Assoziator@asso')->middleware('browserverification:assoresults', 'humanverification')->name("assoresults");
Route::get('impressum', function () {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment