From 6e018559ffb854b91355a55b011466276b05187a Mon Sep 17 00:00:00 2001 From: "neelkanth.kaushik" Date: Wed, 14 Oct 2020 18:55:24 +0530 Subject: [PATCH 01/13] Added icons in README --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index acf9145..0d34a91 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,15 @@ # Surveillance A Laravel package to put malicious users, IP addresses and anonymous browser fingerprints under surveillance, write surveillance logs and block malicious ones from accessing the app. +![](https://img.shields.io/packagist/php-v/neelkanthk/laravel-surveillance.svg?style=for-the-badge) +![](https://img.shields.io/badge/Laravel-%3E%3D6.0-red?style=for-the-badge) +![](https://img.shields.io/github/stars/neelkanthk/laravel-surveillance?style=for-the-badge) +![](https://img.shields.io/packagist/dt/neelkanthk/laravel-surveillance.svg?style=for-the-badge) +![](https://img.shields.io/github/issues/neelkanthk/laravel-surveillance?style=for-the-badge) +![](https://img.shields.io/github/forks/neelkanthk/laravel-surveillance?style=for-the-badge) +![](https://img.shields.io/github/license/neelkanthk/laravel-surveillance?style=for-the-badge) +![](https://img.shields.io/packagist/v/neelkanthk/laravel-surveillance.svg?style=for-the-badge) +![](https://img.shields.io/twitter/url?url=https%3A%2F%2Fgithub.com%2Fneelkanthk%2Flaravel-surveillance?style=social) > **Please read the IMPORTANT INFORMATION below before using this package** From ea4e68e18224a9f37e29054bb7237ad6fa68055e Mon Sep 17 00:00:00 2001 From: "neelkanth.kaushik" Date: Wed, 14 Oct 2020 18:56:33 +0530 Subject: [PATCH 02/13] Added icons in README --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0d34a91..343ff5d 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,9 @@ # Surveillance A Laravel package to put malicious users, IP addresses and anonymous browser fingerprints under surveillance, write surveillance logs and block malicious ones from accessing the app. + +------------ + ![](https://img.shields.io/packagist/php-v/neelkanthk/laravel-surveillance.svg?style=for-the-badge) ![](https://img.shields.io/badge/Laravel-%3E%3D6.0-red?style=for-the-badge) ![](https://img.shields.io/github/stars/neelkanthk/laravel-surveillance?style=for-the-badge) @@ -13,6 +16,8 @@ A Laravel package to put malicious users, IP addresses and anonymous browser fin ![](https://img.shields.io/packagist/v/neelkanthk/laravel-surveillance.svg?style=for-the-badge) ![](https://img.shields.io/twitter/url?url=https%3A%2F%2Fgithub.com%2Fneelkanthk%2Flaravel-surveillance?style=social) +------------ + > **Please read the IMPORTANT INFORMATION below before using this package** @@ -210,7 +215,7 @@ Surveillance::logger()->writeLog(); ## Customizing and Overriding the defaults -### To override the default surveillance management funtionality +### To override the default surveillance management functionality #### Step 1: Extend the `SurveillanceManagerRepository` Class and override all of its methods From 30425302ba117f3ade30f4445df5c344a40a3fa4 Mon Sep 17 00:00:00 2001 From: "neelkanth.kaushik" Date: Wed, 14 Oct 2020 18:59:11 +0530 Subject: [PATCH 03/13] Added icons in README --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 343ff5d..8de05a6 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,6 @@ A Laravel package to put malicious users, IP addresses and anonymous browser fingerprints under surveillance, write surveillance logs and block malicious ones from accessing the app. ------------- - ![](https://img.shields.io/packagist/php-v/neelkanthk/laravel-surveillance.svg?style=for-the-badge) ![](https://img.shields.io/badge/Laravel-%3E%3D6.0-red?style=for-the-badge) ![](https://img.shields.io/github/stars/neelkanthk/laravel-surveillance?style=for-the-badge) @@ -14,7 +12,7 @@ A Laravel package to put malicious users, IP addresses and anonymous browser fin ![](https://img.shields.io/github/forks/neelkanthk/laravel-surveillance?style=for-the-badge) ![](https://img.shields.io/github/license/neelkanthk/laravel-surveillance?style=for-the-badge) ![](https://img.shields.io/packagist/v/neelkanthk/laravel-surveillance.svg?style=for-the-badge) -![](https://img.shields.io/twitter/url?url=https%3A%2F%2Fgithub.com%2Fneelkanthk%2Flaravel-surveillance?style=social) +[![Twitter](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Fgithub.com%2Fneelkanthk%2Flaravel-surveillance)](https://twitter.com/intent/tweet?text=Wow:&url=https%3A%2F%2Fgithub.com%2Fneelkanthk%2Flaravel-surveillance) ------------ From 0e46261e73ac665bf0e007dcae8c14bb730fa907 Mon Sep 17 00:00:00 2001 From: "neelkanth.kaushik" Date: Wed, 14 Oct 2020 20:19:21 +0530 Subject: [PATCH 04/13] Added icons in README --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8de05a6..5b66372 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,15 @@ ![Laravel Surveillance Logo](https://github.com/neelkanthk/repo_logos/blob/master/surveillance_small.png?raw=true) -# Surveillance +# Laravel Surveillance A Laravel package to put malicious users, IP addresses and anonymous browser fingerprints under surveillance, write surveillance logs and block malicious ones from accessing the app. ![](https://img.shields.io/packagist/php-v/neelkanthk/laravel-surveillance.svg?style=for-the-badge) ![](https://img.shields.io/badge/Laravel-%3E%3D6.0-red?style=for-the-badge) ![](https://img.shields.io/github/stars/neelkanthk/laravel-surveillance?style=for-the-badge) -![](https://img.shields.io/packagist/dt/neelkanthk/laravel-surveillance.svg?style=for-the-badge) +![](https://img.shields.io/packagist/dt/neelkanthk/laravel-surveillance.svg?style=for-the-badge) + ![](https://img.shields.io/github/issues/neelkanthk/laravel-surveillance?style=for-the-badge) -![](https://img.shields.io/github/forks/neelkanthk/laravel-surveillance?style=for-the-badge) ![](https://img.shields.io/github/license/neelkanthk/laravel-surveillance?style=for-the-badge) ![](https://img.shields.io/packagist/v/neelkanthk/laravel-surveillance.svg?style=for-the-badge) [![Twitter](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Fgithub.com%2Fneelkanthk%2Flaravel-surveillance)](https://twitter.com/intent/tweet?text=Wow:&url=https%3A%2F%2Fgithub.com%2Fneelkanthk%2Flaravel-surveillance) From cbf2bc9358c1bdfd6b35e50cd002a69548d055a9 Mon Sep 17 00:00:00 2001 From: "neelkanth.kaushik" Date: Wed, 14 Oct 2020 20:44:16 +0530 Subject: [PATCH 05/13] Added logo in README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5b66372..c4edb58 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Laravel Surveillance Logo](https://github.com/neelkanthk/repo_logos/blob/master/surveillance_small.png?raw=true) +![Laravel Surveillance Logo](https://github.com/neelkanthk/repo_logos/blob/master/LaravelSurveillance.png?raw=true) # Laravel Surveillance @@ -12,7 +12,7 @@ A Laravel package to put malicious users, IP addresses and anonymous browser fin ![](https://img.shields.io/github/issues/neelkanthk/laravel-surveillance?style=for-the-badge) ![](https://img.shields.io/github/license/neelkanthk/laravel-surveillance?style=for-the-badge) ![](https://img.shields.io/packagist/v/neelkanthk/laravel-surveillance.svg?style=for-the-badge) -[![Twitter](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Fgithub.com%2Fneelkanthk%2Flaravel-surveillance)](https://twitter.com/intent/tweet?text=Wow:&url=https%3A%2F%2Fgithub.com%2Fneelkanthk%2Flaravel-surveillance) +[![Twitter](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Fgithub.com%2Fneelkanthk%2Flaravel-surveillance)](https://twitter.com/intent/tweet?text=Laravel%20Surveillance:&url=https%3A%2F%2Fgithub.com%2Fneelkanthk%2Flaravel-surveillance) ------------ From 103857d6e546fe72b160dd1cb19bcbaed4c0c76f Mon Sep 17 00:00:00 2001 From: "neelkanth.kaushik" Date: Wed, 14 Oct 2020 20:47:53 +0530 Subject: [PATCH 06/13] Added logo in README --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c4edb58..b2c0abe 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # Laravel Surveillance -A Laravel package to put malicious users, IP addresses and anonymous browser fingerprints under surveillance, write surveillance logs and block malicious ones from accessing the app. +Laravel Surveillance is a package to put malicious users, IP addresses and anonymous browser fingerprints under surveillance, write surveillance logs and block malicious ones from accessing the app. ![](https://img.shields.io/packagist/php-v/neelkanthk/laravel-surveillance.svg?style=for-the-badge) ![](https://img.shields.io/badge/Laravel-%3E%3D6.0-red?style=for-the-badge) @@ -178,6 +178,8 @@ php artisan surveillance:remove ip 192.5.4.3 #### You can use the 'surveillance' middleware on any route or route group just like any other middleware. +#### _NOTE: The middleware looks for the browser fingerprint in the header name as set in the `fingerprint-header-key` inside `config/surveillance.php`_ + ```php Route::middleware(["surveillance"])->get('/', function () { From 9d25dc50ad4c7590c5b7e6ce669f8fa075c184da Mon Sep 17 00:00:00 2001 From: "neelkanth.kaushik" Date: Thu, 15 Oct 2020 00:55:51 +0530 Subject: [PATCH 07/13] Updated logo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b2c0abe..a9fc0b8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Laravel Surveillance Logo](https://github.com/neelkanthk/repo_logos/blob/master/LaravelSurveillance.png?raw=true) +![Laravel Surveillance Logo](https://github.com/neelkanthk/repo_logos/blob/master/LaravelSurveillance_small.png?raw=true) # Laravel Surveillance From ef32dab77beb7b35649a62efd8999d716cb22956 Mon Sep 17 00:00:00 2001 From: "neelkanth.kaushik" Date: Thu, 15 Oct 2020 01:01:38 +0530 Subject: [PATCH 08/13] Updated logo --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index a9fc0b8..6979872 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,15 @@ ![Laravel Surveillance Logo](https://github.com/neelkanthk/repo_logos/blob/master/LaravelSurveillance_small.png?raw=true) -# Laravel Surveillance +# Laravel Surveillance [![Twitter](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Fgithub.com%2Fneelkanthk%2Flaravel-surveillance)](https://twitter.com/intent/tweet?text=Laravel%20Surveillance:&url=https%3A%2F%2Fgithub.com%2Fneelkanthk%2Flaravel-surveillance) Laravel Surveillance is a package to put malicious users, IP addresses and anonymous browser fingerprints under surveillance, write surveillance logs and block malicious ones from accessing the app. ![](https://img.shields.io/packagist/php-v/neelkanthk/laravel-surveillance.svg?style=for-the-badge) ![](https://img.shields.io/badge/Laravel-%3E%3D6.0-red?style=for-the-badge) ![](https://img.shields.io/github/stars/neelkanthk/laravel-surveillance?style=for-the-badge) -![](https://img.shields.io/packagist/dt/neelkanthk/laravel-surveillance.svg?style=for-the-badge) - ![](https://img.shields.io/github/issues/neelkanthk/laravel-surveillance?style=for-the-badge) ![](https://img.shields.io/github/license/neelkanthk/laravel-surveillance?style=for-the-badge) ![](https://img.shields.io/packagist/v/neelkanthk/laravel-surveillance.svg?style=for-the-badge) -[![Twitter](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Fgithub.com%2Fneelkanthk%2Flaravel-surveillance)](https://twitter.com/intent/tweet?text=Laravel%20Surveillance:&url=https%3A%2F%2Fgithub.com%2Fneelkanthk%2Flaravel-surveillance) ------------ From 6a37219e1f4e117dee5f297bbf2d72c8ae661a5b Mon Sep 17 00:00:00 2001 From: "neelkanth.kaushik" Date: Thu, 15 Oct 2020 01:06:42 +0530 Subject: [PATCH 09/13] Updated badges --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6979872..5780349 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,12 @@ Laravel Surveillance is a package to put malicious users, IP addresses and anonymous browser fingerprints under surveillance, write surveillance logs and block malicious ones from accessing the app. +![](https://img.shields.io/github/v/release/neelkanthk/laravel-surveillance?style=for-the-badge) ![](https://img.shields.io/packagist/php-v/neelkanthk/laravel-surveillance.svg?style=for-the-badge) ![](https://img.shields.io/badge/Laravel-%3E%3D6.0-red?style=for-the-badge) ![](https://img.shields.io/github/stars/neelkanthk/laravel-surveillance?style=for-the-badge) ![](https://img.shields.io/github/issues/neelkanthk/laravel-surveillance?style=for-the-badge) ![](https://img.shields.io/github/license/neelkanthk/laravel-surveillance?style=for-the-badge) -![](https://img.shields.io/packagist/v/neelkanthk/laravel-surveillance.svg?style=for-the-badge) ------------ From bdbdbfe6b5a6fd5106a354351d4e72b1a5f97219 Mon Sep 17 00:00:00 2001 From: "neelkanth.kaushik" Date: Mon, 19 Oct 2020 01:40:54 +0530 Subject: [PATCH 10/13] added isSurveillanceEnabled, isAccessBlocked, getRecordById methods in Service and getRecordById method in interface and repository --- .../SurveillanceManagerRepository.php | 11 ++++++ .../SurveillanceManagerInterface.php | 8 ++++ src/Services/Surveillance.php | 37 +++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/src/Implementations/SurveillanceManagerRepository.php b/src/Implementations/SurveillanceManagerRepository.php index 248e162..b5f4a16 100644 --- a/src/Implementations/SurveillanceManagerRepository.php +++ b/src/Implementations/SurveillanceManagerRepository.php @@ -231,4 +231,15 @@ public function isSurveillanceEnabled($userId = null, $ipAddress = null, $finger } return $exists; } + + /** + * Get a single surveillance record by its id from database + * + * @param [int] $id + * @return void + */ + public function getRecordById(int $id) + { + return SurveillanceManager::findOrFail($id); + } } diff --git a/src/Interfaces/SurveillanceManagerInterface.php b/src/Interfaces/SurveillanceManagerInterface.php index 2ee53b5..c345ee4 100644 --- a/src/Interfaces/SurveillanceManagerInterface.php +++ b/src/Interfaces/SurveillanceManagerInterface.php @@ -72,4 +72,12 @@ public function isAccessBlocked(); * Checks if surveillance is enabled ot not */ public function isSurveillanceEnabled(); + + /** + * Get a single surveillance record by its id from database + * + * @param [int] $id + * @return void + */ + public function getRecordById(int $id); } diff --git a/src/Services/Surveillance.php b/src/Services/Surveillance.php index ae98b44..a712a2c 100644 --- a/src/Services/Surveillance.php +++ b/src/Services/Surveillance.php @@ -125,4 +125,41 @@ public function writeLog() { return $this->surveillanceLogger->makeLogFromRequest(request())->writeLog(); } + + /** + * Check if surveillance is enabled + * + * @param [string] $userId + * @param [string] $ipAddress + * @param [string] $fingerprint + * @return boolean + */ + public function isSurveillanceEnabled($userId = null, $ipAddress = null, $fingerprint = null) + { + return $this->surveillanceManager->isSurveillanceEnabled($userId, $ipAddress, $fingerprint); + } + + /** + * Check if access is blocked + * + * @param [string] $userId + * @param [string] $ipAddress + * @param [string] $fingerprint + * @return boolean + */ + public function isAccessBlocked($userId = null, $ipAddress = null, $fingerprint = null) + { + return $this->surveillanceManager->isAccessBlocked($userId, $ipAddress, $fingerprint); + } + + /** + * Get a single surveillance record by its id from database + * + * @param [int] $id + * @return void + */ + public function getRecordById(int $id) + { + return $this->surveillanceManager->getRecordById($id); + } } From d528bf7e26ee94970422f4978cc2be96dd5e1402 Mon Sep 17 00:00:00 2001 From: "neelkanth.kaushik" Date: Tue, 20 Oct 2020 22:07:31 +0530 Subject: [PATCH 11/13] Fixed composer 2.0 compatibilty error message and added some methods in Log and Manager Interface --- .../SurveillanceLogRepository.php | 53 ++++++++++++++ .../SurveillanceManagerRepository.php | 57 +++++++++++++++ src/Interfaces/SurveillanceLogInterface.php | 52 +++++++++++++ src/Interfaces/SurveillanceLogsInterface.php | 22 ------ .../SurveillanceManagerInterface.php | 22 ++++++ src/Services/Surveillance.php | 73 +++++++++++++++++++ 6 files changed, 257 insertions(+), 22 deletions(-) create mode 100644 src/Interfaces/SurveillanceLogInterface.php delete mode 100644 src/Interfaces/SurveillanceLogsInterface.php diff --git a/src/Implementations/SurveillanceLogRepository.php b/src/Implementations/SurveillanceLogRepository.php index 367689e..a81e2bf 100644 --- a/src/Implementations/SurveillanceLogRepository.php +++ b/src/Implementations/SurveillanceLogRepository.php @@ -89,4 +89,57 @@ public function writeLog($dataToLog = null) return $surveillanceLog; } } + + /** + * Return a paginated and filtered list of the logs + * + * @param [array] $filters + * @return array + */ + public function getPaginatedAndFilteredLogs($filters = array()) + { + $query = SurveillanceLog::where("id", ">=", 1); + if (!empty($filters["search"])) { + $query->where("ip", "LIKE", "%" . $filters["search"] . "%") + ->orWhere("userid", "LIKE", "%" . $filters["search"] . "%") + ->orWhere("fingerprint", "LIKE", "%" . $filters["search"] . "%") + ->orWhere("url", "LIKE", "%" . $filters["search"] . "%") + ->orWhere("user_agent", "LIKE", "%" . $filters["search"] . "%") + ->orWhere("cookies", "LIKE", "%" . $filters["search"] . "%") + ->orWhere("session", "LIKE", "%" . $filters["search"] . "%") + ->orWhere("files", "LIKE", "%" . $filters["search"] . "%"); + } + return $query->orderBy("created_at", "desc")->paginate(!empty($filters["limit"]) ? $filters["limit"] : 10, ["*"], 'page', !empty($filters["page"]) ? $filters["page"] : 1)->toArray(); + } + + /** + * Delete log by its id from database + * + * @param [int] $id + * @return bool + */ + public function deleteLogById(int $id) + { + return SurveillanceLog::destroy($id); + } + + /** + * Get count of total logs from database + * @return int + */ + public function totalLogs() + { + return SurveillanceLog::count(); + } + + /** + * Get a single log by its id from database + * + * @param [int] $id + * @return void + */ + public function getLogById(int $id) + { + return SurveillanceLog::findOrFail($id); + } } diff --git a/src/Implementations/SurveillanceManagerRepository.php b/src/Implementations/SurveillanceManagerRepository.php index b5f4a16..705b806 100644 --- a/src/Implementations/SurveillanceManagerRepository.php +++ b/src/Implementations/SurveillanceManagerRepository.php @@ -242,4 +242,61 @@ public function getRecordById(int $id) { return SurveillanceManager::findOrFail($id); } + + /** + * Return a paginated and filtered list of the surveillance records + * + * @param [array] $filters + * @return array + */ + public function getPaginatedAndFilteredRecords($filters = array()) + { + $query = SurveillanceManager::where("id", ">=", 1); + if (!empty($filters["type"])) { + $query->where("type", $filters["type"]); + } + if (!empty($filters["status"]) && $filters["status"] == "enabled") { + $query->where("surveillance_enabled", 1); + } + if (!empty($filters["status"]) && $filters["status"] == "blocked") { + $query->where("access_blocked", 1); + } + if (!empty($filters["status"]) && $filters["status"] == "disabled") { + $query->whereNull("surveillance_enabled")->orWhere("surveillance_enabled", 0); + } + if (!empty($filters["status"]) && $filters["status"] == "unblocked") { + $query->whereNull("access_blocked")->orWhere("access_blocked", 0); + } + if (!empty($filters["search"])) { + $query->where("value", "LIKE", "%" . $filters["search"] . "%"); + } + //orderBy + if (!empty($filters["search"])) { + $query->orderBy("value"); + } else { + $query->orderBy("id", "desc"); + } + + return $query->paginate(!empty($filters["limit"]) ? $filters["limit"] : 10, ["*"], 'page', !empty($filters["page"]) ? $filters["page"] : 1)->toArray(); + } + + /** + * Delete surveillance record by its id from database + * + * @param [int] $id + * @return bool + */ + public function removeRecordById(int $id) + { + return SurveillanceManager::destroy($id); + } + + /** + * Get count of total surveillance records from database + * @return int + */ + public function totalRecords() + { + return SurveillanceManager::count(); + } } diff --git a/src/Interfaces/SurveillanceLogInterface.php b/src/Interfaces/SurveillanceLogInterface.php new file mode 100644 index 0000000..3561997 --- /dev/null +++ b/src/Interfaces/SurveillanceLogInterface.php @@ -0,0 +1,52 @@ +surveillanceManager->getRecordById($id); } + + /** + * Return a paginated and filtered list of the surveillance records + * + * @param [array] $filters + * @return array + */ + public function getPaginatedAndFilteredRecords($filters = array()) + { + return $this->surveillanceManager->getPaginatedAndFilteredRecords($filters); + } + + /** + * Delete surveillance record by its id from database + * + * @param [int] $id + * @return bool + */ + public function removeRecordById(int $id) + { + return $this->surveillanceManager->removeRecordById($id); + } + + /** + * Get count of total surveillance records from database + * @return int + */ + public function totalRecords() + { + return $this->surveillanceManager->totalRecords(); + } + + /** + * Get a single surveillance log by its id from database + * + * @param [int] $id + * @return void + */ + public function getLogById(int $id) + { + return $this->surveillanceLogger->getLogById($id); + } + + /** + * Return a paginated and filtered list of the surveillance logs + * + * @param [array] $filters + * @return array + */ + public function getPaginatedAndFilteredLogs($filters = array()) + { + return $this->surveillanceLogger->getPaginatedAndFilteredLogs($filters); + } + + /** + * Delete surveillance log by its id from database + * + * @param [int] $id + * @return bool + */ + public function deleteLogById(int $id) + { + return $this->surveillanceLogger->deleteLogById($id); + } + + /** + * Get count of total surveillance logs from database + * @return int + */ + public function totalLogs() + { + return $this->surveillanceLogger->totalLogs(); + } } From eda143d3614ecedffb60803d51ad8ea8bc2612fd Mon Sep 17 00:00:00 2001 From: "neelkanth.kaushik" Date: Tue, 20 Oct 2020 23:46:29 +0530 Subject: [PATCH 12/13] Added date range filter in getPaginatedAndFilteredLogs --- .../SurveillanceLogRepository.php | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Implementations/SurveillanceLogRepository.php b/src/Implementations/SurveillanceLogRepository.php index a81e2bf..6c0b0da 100644 --- a/src/Implementations/SurveillanceLogRepository.php +++ b/src/Implementations/SurveillanceLogRepository.php @@ -101,13 +101,19 @@ public function getPaginatedAndFilteredLogs($filters = array()) $query = SurveillanceLog::where("id", ">=", 1); if (!empty($filters["search"])) { $query->where("ip", "LIKE", "%" . $filters["search"] . "%") - ->orWhere("userid", "LIKE", "%" . $filters["search"] . "%") - ->orWhere("fingerprint", "LIKE", "%" . $filters["search"] . "%") - ->orWhere("url", "LIKE", "%" . $filters["search"] . "%") - ->orWhere("user_agent", "LIKE", "%" . $filters["search"] . "%") - ->orWhere("cookies", "LIKE", "%" . $filters["search"] . "%") - ->orWhere("session", "LIKE", "%" . $filters["search"] . "%") - ->orWhere("files", "LIKE", "%" . $filters["search"] . "%"); + ->orWhere("userid", "LIKE", "%" . $filters["search"] . "%") + ->orWhere("fingerprint", "LIKE", "%" . $filters["search"] . "%") + ->orWhere("url", "LIKE", "%" . $filters["search"] . "%") + ->orWhere("user_agent", "LIKE", "%" . $filters["search"] . "%") + ->orWhere("cookies", "LIKE", "%" . $filters["search"] . "%") + ->orWhere("session", "LIKE", "%" . $filters["search"] . "%") + ->orWhere("files", "LIKE", "%" . $filters["search"] . "%"); + } + if (!empty($filters["from_datetime"])) { + $query->where("created_at", ">=", $filters["from_datetime"]); + } + if (!empty($filters["to_datetime"])) { + $query->where("created_at", "<=", $filters["to_datetime"]); } return $query->orderBy("created_at", "desc")->paginate(!empty($filters["limit"]) ? $filters["limit"] : 10, ["*"], 'page', !empty($filters["page"]) ? $filters["page"] : 1)->toArray(); } From 4b42121df4bc7e596c0755d43395e4cfb645192a Mon Sep 17 00:00:00 2001 From: "neelkanth.kaushik" Date: Thu, 22 Oct 2020 00:34:17 +0530 Subject: [PATCH 13/13] Updated Readme --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 09b021d..a5703b6 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,5 @@ ![Laravel Surveillance Logo](https://github.com/neelkanthk/repo_logos/blob/master/LaravelSurveillance_small.png?raw=true) -# Laravel Surveillance [![Twitter](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Fgithub.com%2Fneelkanthk%2Flaravel-surveillance)](https://twitter.com/intent/tweet?text=Laravel%20Surveillance:&url=https%3A%2F%2Fgithub.com%2Fneelkanthk%2Flaravel-surveillance) - -Laravel Surveillance is a package to put malicious users, IP addresses and anonymous browser fingerprints under surveillance, write surveillance logs and block malicious ones from accessing the app. - ![](https://img.shields.io/github/v/release/neelkanthk/laravel-surveillance?style=for-the-badge) ![](https://img.shields.io/packagist/php-v/neelkanthk/laravel-surveillance.svg?style=for-the-badge) ![](https://img.shields.io/badge/Laravel-%3E%3D6.0-red?style=for-the-badge) @@ -11,6 +7,11 @@ Laravel Surveillance is a package to put malicious users, IP addresses and anony ![](https://img.shields.io/github/issues/neelkanthk/laravel-surveillance?style=for-the-badge) ![](https://img.shields.io/github/license/neelkanthk/laravel-surveillance?style=for-the-badge) +# Laravel Surveillance [![Twitter](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Fgithub.com%2Fneelkanthk%2Flaravel-surveillance)](https://twitter.com/intent/tweet?text=Laravel%20Surveillance:&url=https%3A%2F%2Fgithub.com%2Fneelkanthk%2Flaravel-surveillance) + +Laravel Surveillance is a package to put malicious users, IP addresses and anonymous browser fingerprints under surveillance, write surveillance logs and block malicious ones from accessing the app. + + ------------