diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index cb14ae7025a3077233dfb5cd09cd401242a20a52..e5eb7fc686bc6c83efc1d401d68080e329df9f41 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -63,5 +63,6 @@ class Kernel extends HttpKernel 'humanverification' => \App\Http\Middleware\HumanVerification::class, 'useragentmaster' => \App\Http\Middleware\UserAgentMaster::class, 'browserverification' => \App\Http\Middleware\BrowserVerification::class, + 'keyvalidation' => \App\Http\Middleware\KeyValidation::class, ]; } diff --git a/app/Http/Middleware/KeyValidation.php b/app/Http/Middleware/KeyValidation.php new file mode 100644 index 0000000000000000000000000000000000000000..4218076c515391109c643b3a3a2035a6da76e946 --- /dev/null +++ b/app/Http/Middleware/KeyValidation.php @@ -0,0 +1,31 @@ +<?php + +namespace App\Http\Middleware; + +use Closure; +use Cookie; +use App\Models\Key; + +class KeyValidation +{ + /** + * Handle an incoming request. + * + * @param \Illuminate\Http\Request $request + * @param \Closure $next + * @return mixed + */ + public function handle($request, Closure $next) + { + if(isset($request->key)){ + $pKey = new Key($request->key); + } + + if(Cookie::get('key')){ + $cKey = new Key($request->key); + } + + if($pKey->getStatus() || $cKey->getStatus()) + return $next($request); + } +} diff --git a/app/Models/Key.php b/app/Models/Key.php index 3bc38367902ef78ea671cf73bb45891cc69e0136..cbe3f237d3e1c57ec231cc015d5f6177a24d34a2 100644 --- a/app/Models/Key.php +++ b/app/Models/Key.php @@ -15,7 +15,7 @@ class Key{ # always returns true or false public function getStatus() { if($this->status === null) { - updateStatus(); + $this->updateStatus(); } if($this->status === null || $this->status === false) { return false; @@ -60,7 +60,7 @@ class Key{ if ($result->{'api-access'} == true) { return true; } else { - $this->status = false; + $this->status = false; return false; } } catch (\ErrorException $e) { diff --git a/routes/web.php b/routes/web.php index 875b21d7f2f49d35c24081b0bb4bcf5ff88f289e..247daff2d73da48eda18547e16ff738784707b34 100644 --- a/routes/web.php +++ b/routes/web.php @@ -197,7 +197,7 @@ Route::group( return redirect(LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), '/')); }); - Route::match(['get', 'post'], 'meta/meta.ger3', 'MetaGerSearch@search')->middleware('browserverification', 'humanverification', 'useragentmaster')->name("resultpage"); + Route::match(['get', 'post'], 'meta/meta.ger3', 'MetaGerSearch@search')->middleware('keyvalidation', 'browserverification', 'humanverification', 'useragentmaster')->name("resultpage"); Route::get('meta/loadMore', 'MetaGerSearch@loadMore'); Route::post('img/cat.jpg', 'HumanVerification@remove');