diff --git a/app/Http/Controllers/HumanVerification.php b/app/Http/Controllers/HumanVerification.php index 97f148c24219d5a1236862573cf56a41c22fe541..81f9d71ac8a4599148884ad3b8d7842ec2de45c3 100644 --- a/app/Http/Controllers/HumanVerification.php +++ b/app/Http/Controllers/HumanVerification.php @@ -33,7 +33,7 @@ class HumanVerification extends Controller } if ($request->getMethod() == 'POST') { - + \App\PrometheusExporter::CaptchaAnswered(); $lockedKey = $user["lockedKey"]; $key = $request->input('captcha'); $key = strtolower($key); @@ -42,7 +42,7 @@ class HumanVerification extends Controller $captcha = Captcha::create("default", true); $user["lockedKey"] = $captcha["key"]; HumanVerification::saveUser($user); - + \App\PrometheusExporter::CaptchaShown(); return view('humanverification.captcha')->with('title', 'Bestätigung notwendig') ->with('uid', $user["uid"]) ->with('id', $id) @@ -50,6 +50,7 @@ class HumanVerification extends Controller ->with('image', $captcha["img"]) ->with('errorMessage', 'Fehler: Falsche Eingabe!'); } else { + \App\PrometheusExporter::CaptchaCorrect(); # If we can unlock the Account of this user we will redirect him to the result page if ($user !== null && $user["locked"]) { # The Captcha was correct. We can remove the key from the user @@ -67,7 +68,7 @@ class HumanVerification extends Controller $captcha = Captcha::create("default", true); $user["lockedKey"] = $captcha["key"]; HumanVerification::saveUser($user); - + \App\PrometheusExporter::CaptchaShown(); return view('humanverification.captcha')->with('title', 'Bestätigung notwendig') ->with('uid', $user["uid"]) ->with('id', $id) diff --git a/app/Http/Middleware/HumanVerification.php b/app/Http/Middleware/HumanVerification.php index d646e1fbd935c507be1482104067bf516e63ed97..cf2a4e7033653e465b1591657230396c1b1454d2 100644 --- a/app/Http/Middleware/HumanVerification.php +++ b/app/Http/Middleware/HumanVerification.php @@ -102,6 +102,7 @@ class HumanVerification if ($user["locked"]) { $captcha = Captcha::create("default", true); $user["lockedKey"] = $captcha["key"]; + \App\PrometheusExporter::CaptchaShown(); return new Response( view('humanverification.captcha') diff --git a/app/Jobs/ConvertCountFile.php b/app/Jobs/ConvertCountFile.php index 3813381e3c5cb6b22784f9a17d7a0dc88abe9625..d80142977c6458e356a9594cba5321bd288b40dd 100644 --- a/app/Jobs/ConvertCountFile.php +++ b/app/Jobs/ConvertCountFile.php @@ -2,7 +2,6 @@ namespace App\Jobs; -use Carbon; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; @@ -42,7 +41,6 @@ class ConvertCountFile implements ShouldQueue $error = false; try { $fh = fopen($this->files["logFile"], "r"); - $currentLogTime = Carbon::now()->hour(0)->minute(0)->second(0)->addMinutes(5); while ($fh !== false && ($line = fgets($fh)) !== false) { $logTime = []; $interface = ""; @@ -57,22 +55,22 @@ class ConvertCountFile implements ShouldQueue $thatTime = \DateTime::createFromFormat('H:i:s', $logTime); $thatTime->sub(new \DateInterval("PT" . ($thatTime->format('i') % 5) . "M")); - if(empty($result["time"][$thatTime->format('H:i')])){ + if (empty($result["time"][$thatTime->format('H:i')])) { $result["time"][$thatTime->format('H:i')] = [ "insgesamt" => [ "all" => 0, ], ]; } - if(empty($result["time"][$thatTime->format('H:i')]["all"])){ + if (empty($result["time"][$thatTime->format('H:i')]["all"])) { $result["time"][$thatTime->format('H:i')]["all"] = 1; - }else{ + } else { $result["time"][$thatTime->format('H:i')]["all"]++; } if (!empty($interface)) { - if(empty($result["time"][$thatTime->format('H:i')][$interface])){ + if (empty($result["time"][$thatTime->format('H:i')][$interface])) { $result["time"][$thatTime->format('H:i')][$interface] = 1; - }else{ + } else { $result["time"][$thatTime->format('H:i')][$interface]++; } } diff --git a/app/Mail/Kontakt.php b/app/Mail/Kontakt.php index dc707cfa5bf95eba6616ae24e9791d76cb1e7fed..ff1ed0bd1549b134a75481a8f478f5350410a7c5 100644 --- a/app/Mail/Kontakt.php +++ b/app/Mail/Kontakt.php @@ -18,7 +18,7 @@ class Kontakt extends Mailable public function __construct($name, $from, $subject, $message) { $this->name = $name; - $this->reply = $from; + $this->reply = $from; $this->subject = $subject; $this->message = $message; } diff --git a/app/Models/Quicktips/Quicktips.php b/app/Models/Quicktips/Quicktips.php index 1088e82cd777f49dd400e08e44f0dab80996ce8d..658e0bdd7ce662ad26e9575734e1e3b9f84a8403 100644 --- a/app/Models/Quicktips/Quicktips.php +++ b/app/Models/Quicktips/Quicktips.php @@ -12,7 +12,7 @@ class Quicktips private $quicktipUrl = "/1.1/quicktips.xml"; private $results = []; const QUICKTIP_NAME = "quicktips"; - const CACHE_DURATION = 60; + const CACHE_DURATION = 60 * 60; private $hash; diff --git a/app/PrometheusExporter.php b/app/PrometheusExporter.php new file mode 100644 index 0000000000000000000000000000000000000000..1332e1cf2f5176fbcd91e6b8c704ac7cc692fa9c --- /dev/null +++ b/app/PrometheusExporter.php @@ -0,0 +1,25 @@ +<?php + +namespace App; + +class PrometheusExporter { + + public static function CaptchaShown() { + $registry = \Prometheus\CollectorRegistry::getDefault(); + $counter = $registry->getOrRegisterCounter('metager', 'captcha_shown', 'counts how often the captcha was shown', []); + $counter->inc(); + } + + public static function CaptchaCorrect() { + $registry = \Prometheus\CollectorRegistry::getDefault(); + $counter = $registry->getOrRegisterCounter('metager', 'captcha_correct', 'counts how often the captcha was solved correctly', []); + $counter->inc(); + } + + public static function CaptchaAnswered() { + $registry = \Prometheus\CollectorRegistry::getDefault(); + $counter = $registry->getOrRegisterCounter('metager', 'captcha_answered', 'counts how often the captcha was answered', []); + $counter->inc(); + } + +} \ No newline at end of file diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index ab443c328fc7b19122de43bbd73b9f49c266a5c9..a7106814b59fe8e324ffb208d715e7b8f138e96e 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -34,6 +34,17 @@ class AppServiceProvider extends ServiceProvider \App::setLocale('es'); } + \Prometheus\Storage\Redis::setDefaultOptions( + [ + 'host' => env("REDIS_HOST", '127.0.0.1'), + 'port' => intval(env("REDIS_PORT", 6379)), + 'password' => env("REDIS_PASSWORD", null), + 'timeout' => 0.1, // in seconds + 'read_timeout' => '10', // in seconds + 'persistent_connections' => false + ] + ); + Queue::before(function (JobProcessing $event) { }); Queue::after(function (JobProcessed $event) { diff --git a/composer.json b/composer.json index 7abc86a96724ca0c7eeb71156d8e842812415ac9..44630b480a8433b0a7ceb1f866ca7930aa7bc30a 100644 --- a/composer.json +++ b/composer.json @@ -8,13 +8,13 @@ ], "license": "MIT", "require": { + "laravel/framework": "5.8.*", "php": "^7.1.3", - "facebook/webdriver": "^1.6", "fideloper/proxy": "^4.0", + "laravel/tinker": "^1.0", + "facebook/webdriver": "^1.6", "globalcitizen/php-iban": "^2.6", "jenssegers/agent": "^2.6", - "laravel/framework": "5.7.*", - "laravel/tinker": "^1.0", "mcamara/laravel-localization": "^1.3", "mews/captcha": "^2.2", "monospice/laravel-redis-sentinel-drivers": "^2.6", @@ -27,8 +27,8 @@ "filp/whoops": "^2.0", "fzaninotto/faker": "^1.4", "mockery/mockery": "^1.0", - "nunomaduro/collision": "^2.0", - "phpunit/phpunit": "^7.0" + "nunomaduro/collision": "^3.0", + "phpunit/phpunit": "^7.5" }, "config": { "optimize-autoloader": true, @@ -68,4 +68,4 @@ "@php artisan key:generate --ansi" ] } -} +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 7b15a2087bf2a5a609deeb97fbfa4c75f10cded3..37931232526f165d02a41e49349c556c94538568 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,11 +14,11 @@ services: dependencies: depends_on: - "mgdb" - image: php:7.3-cli + image: php:7.3-cli-alpine volumes: - .:/data working_dir: /data - command: /data/init.sh + command: /bin/sh -c "apk add --update dos2unix && dos2unix ./init.sh && ./init.sh && ./init.sh" mgdb: restart: on-failure image: mariadb:latest diff --git a/init.sh b/init.sh index d1b105df9bc1a594c533fc1328f7869fa68eac05..a668816b25507e21ba39860e9a417e9038aef257 100755 --- a/init.sh +++ b/init.sh @@ -12,6 +12,10 @@ if [ -f "/data/database/useragents.sqlite" ]; then rm /data/database/useragents.sqlite fi +if [ ! -d "/data/storage/logs/metager" ]; then + mkdir -p /data/storage/logs/metager +fi + touch /data/database/useragents.sqlite chmod -R go+w storage bootstrap/cache diff --git a/package-lock.json b/package-lock.json index f3441075deb843be404b45d9267b47d5ea6b8902..2a3cc32cf979ab46e1e114bb8c6b1ae943f2e4a5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2088,7 +2088,7 @@ "cross-spawn": { "version": "6.0.5", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", - "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", + "integrity": "sha1-Sl7Hxk364iw6FBJNus3uhG2Ay8Q=", "dev": true, "requires": { "nice-try": "^1.0.4", @@ -5758,7 +5758,7 @@ "nice-try": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", - "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", + "integrity": "sha1-ozeKdpbOfSI+iPybdkvX7xCJ42Y=", "dev": true }, "no-case": { diff --git a/resources/lang/de/captcha.php b/resources/lang/de/captcha.php index 28a9e6854165839765f5b0bf771fc13d67c8f96b..8ce5e3a4f01a97e2f4df0b48a18d178b0f0f1415 100644 --- a/resources/lang/de/captcha.php +++ b/resources/lang/de/captcha.php @@ -6,6 +6,4 @@ return [ '4' => 'Bitte geben Sie deshalb die Zeichen aus dem Bild in die Eingabebox und bestätigen Sie mit "OK" um zur Ergebnisseite zu gelangen.', '5' => 'Captcha eingeben', '6' => 'Wochentag eingeben', - '7' => 'Sollten Sie diese Nachricht häufiger sehen oder handelt es sich dabei um einen Irrtum, schicken Sie uns gerne eine Nachricht über unser <a href=":url">Kontaktformular</a>.', - '8' => 'Nennen Sie uns in diesem Fall bitte unbedingt folgende Vorgangsnummer:', ]; diff --git a/resources/lang/en/captcha.php b/resources/lang/en/captcha.php index d9f0a4cfc38cf4b3057d9aae9b533e9c99ff4352..b0a7ba529cd768e3cce5d0e1fca80391b11284b1 100644 --- a/resources/lang/en/captcha.php +++ b/resources/lang/en/captcha.php @@ -6,6 +6,4 @@ return [ '4' => 'Please enter the characters from the picture in the input box and confirm with "OK" to get to the result page.', '5' => 'Enter captcha', '6' => 'Enter weekday', - '7' => 'If you see this message more often, or if it is a mistake, feel free to send a message via our <a href=":url"> contact form </a>.', - '8' => 'In this case, please give us the following transaction number:', ]; diff --git a/resources/lang/es/captcha.php b/resources/lang/es/captcha.php index 1b9d3c18ca3bccda5bcf55d72fefd4168649b437..a5307fda5227240d00f51a3a064abeb3a63ab5f4 100644 --- a/resources/lang/es/captcha.php +++ b/resources/lang/es/captcha.php @@ -6,6 +6,4 @@ return [ '4' => 'Ingrese los caracteres de la imagen en el cuadro de entrada y confirme con "OK" para llegar a la página de resultados.', '5' => 'Entrar en captcha', '6' => 'Entrar en dÃa laborable', - '7' => 'Si ve este mensaje con más frecuencia o si es un error, puede enviar un mensaje a través de nuestro <a href=":url"> formulario de contacto </a>.', - '8' => 'En este caso, por favor dénos el siguiente número de transacción:', ]; diff --git a/resources/views/humanverification/captcha.blade.php b/resources/views/humanverification/captcha.blade.php index 65cc092eaaf18fdb1d12241d337fc32820dd3306..f0746da3d022296c979da04c88e9b3c2040eac53 100644 --- a/resources/views/humanverification/captcha.blade.php +++ b/resources/views/humanverification/captcha.blade.php @@ -18,6 +18,4 @@ <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> - <p>@lang('captcha.7', ['url' => LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), 'kontakt')])</p> - <p>@lang('captcha.8') {{ $id }} @endsection