From 14adda23c8f56d92ea53c53eac896bd4fccf58f4 Mon Sep 17 00:00:00 2001 From: irfan-dahir Date: Wed, 16 May 2018 22:34:33 +0500 Subject: [PATCH 1/5] update --- bootstrap/app.php | 2 +- composer.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bootstrap/app.php b/bootstrap/app.php index 071ff40..028d587 100755 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -19,7 +19,7 @@ define('CACHE_EXPIRE_SEARCH', 3600 * 6); // 6 hours //define('CACHE_EXPIRE_SEARCH', 4); // 60 seconds | dev define('REST_VERSION', '2.2'); -define('SOURCE_VERSION', '1.15.9'); +define('SOURCE_VERSION', '1.15.12'); /* |-------------------------------------------------------------------------- diff --git a/composer.lock b/composer.lock index 22692b4..15105a7 100755 --- a/composer.lock +++ b/composer.lock @@ -1654,12 +1654,12 @@ "source": { "type": "git", "url": "https://github.com/jikan-me/jikan.git", - "reference": "71dd593d6215c84567bf3c0e9d9178af9cb7cea7" + "reference": "fefccdb935aea87f387b6a540429382dc4b3a5a1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/jikan-me/jikan/zipball/71dd593d6215c84567bf3c0e9d9178af9cb7cea7", - "reference": "71dd593d6215c84567bf3c0e9d9178af9cb7cea7", + "url": "https://api.github.com/repos/jikan-me/jikan/zipball/fefccdb935aea87f387b6a540429382dc4b3a5a1", + "reference": "fefccdb935aea87f387b6a540429382dc4b3a5a1", "shasum": "" }, "type": "library", @@ -1681,7 +1681,7 @@ } ], "description": "Jikan is an unofficial MyAnimeList API", - "time": "2018-05-13T22:11:56+00:00" + "time": "2018-05-16T17:06:27+00:00" }, { "name": "laravel/lumen-framework", From 5ea871e89d9b8a94fbd6c192d0edea2ebda7a55c Mon Sep 17 00:00:00 2001 From: irfan-dahir Date: Fri, 25 May 2018 06:59:35 +0500 Subject: [PATCH 2/5] add IP Blacklist Middleware --- app/Http/Middleware/Blacklist.php | 39 +++++++++++++++++++++++++++++++ bootstrap/app.php | 2 ++ composer.lock | 8 +++---- routes/web.php | 2 +- storage/app/.gitignore | 2 ++ 5 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 app/Http/Middleware/Blacklist.php diff --git a/app/Http/Middleware/Blacklist.php b/app/Http/Middleware/Blacklist.php new file mode 100644 index 0000000..0ed9e43 --- /dev/null +++ b/app/Http/Middleware/Blacklist.php @@ -0,0 +1,39 @@ +loadList(); + + if ($this->inList()) { + return response()->json([ + 'error' => 'This IP has been blacklisted' + ]); + } + + return $next($request); + } + + private function loadList() { + if (!file_exists(BLACKLIST_PATH)) { + file_put_contents(BLACKLIST_PATH, json_encode([])); + } + + $this->blacklist = json_decode(file_get_contents(BLACKLIST_PATH), true); + } + + private function inList() { + $ip = $_SERVER['REMOTE_ADDR']; + return in_array($ip, $this->blacklist) ? true : false; + } + +} diff --git a/bootstrap/app.php b/bootstrap/app.php index 028d587..7ce26eb 100755 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -12,6 +12,7 @@ try { Defines */ define('SESSION_STORAGE_PATH', '/var/www/api.jikan/storage/app/sessions.json'); // depreciated. Using Redis now +define('BLACKLIST_PATH', '/var/www/api.jikan/storage/app/blacklist.json'); define('RATE_LIMIT', 5000); // per day define('CACHE_EXPIRE', 3600 * 24 * 3); // 3 days define('CACHE_EXPIRE_SEARCH', 3600 * 6); // 6 hours @@ -80,6 +81,7 @@ $app->middleware([App\Http\Middleware\Throttle::class]);*/ // ]); $app->routeMiddleware([ + 'blacklist' => App\Http\Middleware\Blacklist::class, 'meta' => App\Http\Middleware\Meta::class, 'throttle' => App\Http\Middleware\Throttle::class ]); diff --git a/composer.lock b/composer.lock index 15105a7..66530ec 100755 --- a/composer.lock +++ b/composer.lock @@ -1654,12 +1654,12 @@ "source": { "type": "git", "url": "https://github.com/jikan-me/jikan.git", - "reference": "fefccdb935aea87f387b6a540429382dc4b3a5a1" + "reference": "dd5264fa12962b2964f5faf44dd6713ae6693d85" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/jikan-me/jikan/zipball/fefccdb935aea87f387b6a540429382dc4b3a5a1", - "reference": "fefccdb935aea87f387b6a540429382dc4b3a5a1", + "url": "https://api.github.com/repos/jikan-me/jikan/zipball/dd5264fa12962b2964f5faf44dd6713ae6693d85", + "reference": "dd5264fa12962b2964f5faf44dd6713ae6693d85", "shasum": "" }, "type": "library", @@ -1681,7 +1681,7 @@ } ], "description": "Jikan is an unofficial MyAnimeList API", - "time": "2018-05-16T17:06:27+00:00" + "time": "2018-05-25T01:01:55+00:00" }, { "name": "laravel/lumen-framework", diff --git a/routes/web.php b/routes/web.php index 1f521d2..6c3b2f2 100755 --- a/routes/web.php +++ b/routes/web.php @@ -34,7 +34,7 @@ $router->get('meta/{request:[A-Za-z]+}[/{type:[A-Za-z]+}[/{period:[A-Za-z]+}[/{p 'uses' => 'MetaLiteController@request' ]); -$router->group(['middleware' => ['meta', 'throttle']], function() use ($router) { +$router->group(['middleware' => ['blacklist', 'meta', 'throttle']], function() use ($router) { $router->get('anime[/{id:[0-9]+}[/{extend:[A-Za-z_]+}[/{extendArgs}]]]', [ 'uses' => 'AnimeController@request' diff --git a/storage/app/.gitignore b/storage/app/.gitignore index d6b7ef3..3f34ef0 100755 --- a/storage/app/.gitignore +++ b/storage/app/.gitignore @@ -1,2 +1,4 @@ * !.gitignore +sessions.json +blacklist.json \ No newline at end of file From 5d665a5bda729d34a2efa9c21004fdf96f26b9f5 Mon Sep 17 00:00:00 2001 From: irfan-dahir Date: Sun, 27 May 2018 05:55:46 +0500 Subject: [PATCH 3/5] alternative support for URL/% encoding in searches #152 --- app/Http/Controllers/SearchController.php | 16 +++++++++++++++- routes/web.php | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php index ebe55a8..32fb647 100755 --- a/app/Http/Controllers/SearchController.php +++ b/app/Http/Controllers/SearchController.php @@ -58,10 +58,24 @@ class SearchController extends Controller $antiXss = new \voku\helper\AntiXSS(); + $this->type = $type; - $this->query = urlencode($antiXss->xss_clean($query)); + + if (!is_null($query)) { + $this->query = $antiXss->xss_clean($query); + } else { + if (isset($_GET['q']) && !empty($_GET['q'])) { + $this->query = $antiXss->xss_clean($_GET['q']); + } + } + $this->page = $page; + if (isset($_GET['page'])) { + $this->page = (int) $_GET['page']; + if ($this->page < 1) { $this->page = 1; } + } + $jikan = new \Jikan\Jikan; if ($type == 'anime' || $type == 'manga') { diff --git a/routes/web.php b/routes/web.php index 6c3b2f2..4514ffb 100755 --- a/routes/web.php +++ b/routes/web.php @@ -52,7 +52,7 @@ $router->group(['middleware' => ['blacklist', 'meta', 'throttle']], function() u 'uses' => 'CharacterController@request' ]); - $router->get('search[/{type}/{query}[/{page:[0-9]+}]]', [ + $router->get('search[/{type}[/{query}[/{page:[0-9]+}]]]', [ 'uses' => 'SearchController@request' ]); From 6b703a89f2994420256e90e4a0c65f5e3f817f48 Mon Sep 17 00:00:00 2001 From: irfan-dahir Date: Sun, 27 May 2018 05:58:13 +0500 Subject: [PATCH 4/5] update --- app/Http/Middleware/Throttle.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Http/Middleware/Throttle.php b/app/Http/Middleware/Throttle.php index 8cbc071..d431b77 100755 --- a/app/Http/Middleware/Throttle.php +++ b/app/Http/Middleware/Throttle.php @@ -48,7 +48,6 @@ class Throttle $this->ip = $_SERVER['REMOTE_ADDR']; $date = date("d-m-Y"); - if (!isset($this->sessions[$this->ip])) { // register the session $this->sessions[$this->ip] = [ $date => 0 From 0e4ca7df59aa294e648bd279f6f7f6543f0283d0 Mon Sep 17 00:00:00 2001 From: irfan-dahir Date: Sun, 17 Jun 2018 22:23:51 +0500 Subject: [PATCH 5/5] fix utf8 issue with search controller --- app/Http/Controllers/SearchController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php index 32fb647..460018d 100755 --- a/app/Http/Controllers/SearchController.php +++ b/app/Http/Controllers/SearchController.php @@ -101,7 +101,7 @@ class SearchController extends Controller if (app('redis')->exists($this->hash)) { $this->response['request_cached'] = true; return response()->json( - $this->response + json_decode(app('redis')->get($this->hash), true) + $this->response + json_decode(app('redis')->get($this->hash), true), 200, [], JSON_UNESCAPED_UNICODE ); } @@ -186,7 +186,7 @@ class SearchController extends Controller } return response()->json( - $this->response + $jikan->response + $this->response + $jikan->response, 200, [], JSON_UNESCAPED_UNICODE // fix utf8 issues ); }