All Projects → neelkanthk → Laravel Surveillance

neelkanthk / Laravel Surveillance

Licence: mit
Put malicious users, IP addresses and anonymous browser fingerprints under surveillance, log the URLs they visit and block malicious ones from accessing the Laravel app.

Projects that are alternatives of or similar to Laravel Surveillance

Laravel Starter
A CMS like modular starter application project built with Laravel 8.x.
Stars: ✭ 299 (+51.01%)
Mutual labels:  hacktoberfest, laravel, laravel-package
Telegram
✈️ Telegram Notifications Channel for Laravel
Stars: ✭ 450 (+127.27%)
Mutual labels:  hacktoberfest, laravel, laravel-package
Validator Docs
Validação de CPF, CNPJ, CNH, NIS, Título Eleitoral e Cartão Nacional de Saúde com Laravel.
Stars: ✭ 334 (+68.69%)
Mutual labels:  hacktoberfest, laravel, laravel-package
Wagonwheel
Offer an online version of your Laravel emails to users.
Stars: ✭ 224 (+13.13%)
Mutual labels:  hacktoberfest, laravel, laravel-package
Lara Lens
Laravel package for display diagnostic (config, database, http connections...)
Stars: ✭ 96 (-51.52%)
Mutual labels:  hacktoberfest, laravel, laravel-package
Laravel Gamp
📊 Laravel Google Analytics Measurement Protocol Package
Stars: ✭ 271 (+36.87%)
Mutual labels:  hacktoberfest, laravel, laravel-package
Laravel Acl
This package helps you to associate users with permissions and permission groups with laravel framework
Stars: ✭ 404 (+104.04%)
Mutual labels:  hacktoberfest, laravel, access-control
Laravel Query Monitor
Simple artisan command to monitoring triggered queries
Stars: ✭ 230 (+16.16%)
Mutual labels:  hacktoberfest, laravel, laravel-package
Laravel Schedulable
Schedule and unschedule eloquent models elegantly without cron jobs
Stars: ✭ 78 (-60.61%)
Mutual labels:  hacktoberfest, laravel, laravel-package
Laravel Weather
🌤️ A wrapper around Open Weather Map API (Current weather)
Stars: ✭ 36 (-81.82%)
Mutual labels:  hacktoberfest, laravel, laravel-package
Bagisto
An easy to use, free and open source laravel eCommerce platform to build your online shop in no time.
Stars: ✭ 4,140 (+1990.91%)
Mutual labels:  hacktoberfest, laravel, laravel-package
Simple Qrcode
An easy-to-use PHP QrCode generator with first-party support for Laravel.
Stars: ✭ 1,923 (+871.21%)
Mutual labels:  hacktoberfest, laravel, laravel-package
Orm
A drop-in Doctrine ORM 2 implementation for Laravel 5+ and Lumen
Stars: ✭ 712 (+259.6%)
Mutual labels:  hacktoberfest, laravel, laravel-package
Laravel Mail Editor
MailEclipse ⚡ Laravel Mailable Editor!
Stars: ✭ 1,714 (+765.66%)
Mutual labels:  hacktoberfest, laravel, laravel-package
Laravelresources
Speed Up package development for Laravel Apps with API's
Stars: ✭ 152 (-23.23%)
Mutual labels:  hacktoberfest, laravel, laravel-package
Ziggy
Use your Laravel named routes in JavaScript
Stars: ✭ 2,619 (+1222.73%)
Mutual labels:  hacktoberfest, laravel
Laravel Exchange Rates
A Laravel wrapper package for interacting with the exchangeratesapi.io API.
Stars: ✭ 180 (-9.09%)
Mutual labels:  hacktoberfest, laravel
Laravel Adminer
Adminer database manager for Laravel 5+
Stars: ✭ 185 (-6.57%)
Mutual labels:  laravel, laravel-package
Laravel Cross Eloquent Search
Laravel package to search through multiple Eloquent models. Supports sorting, pagination, scoped queries, eager load relationships and searching through single or multiple columns.
Stars: ✭ 189 (-4.55%)
Mutual labels:  laravel, laravel-package
Laravel Identify
📦 📱 Laravel 5 Package to Detect Users Browsers, Devices, Languages and Operating Systems
Stars: ✭ 177 (-10.61%)
Mutual labels:  laravel, laravel-package

Laravel Surveillance Logo

Laravel Surveillance Twitter

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.


Please read the IMPORTANT INFORMATION below before using this package

This package collects and processes various attributes that may be Personal Identifiable Information and this should therefore be disclosed and screened before adopting this package. This packages author does not take responsibility for any compliance issues users may face. Please consult legal expertise to use responsibly.



This package provides:

1. A middleware to be used on routes.

2. A command line interface to enable/disable surveillance and block/unblock access.

3. A fluent API to programmatically enable/disable surveillance, block/unblock access and log the requests at runtime.

4. By default the package used MySQL database as storage but the package can be extended to use virtually any storage technology.

NOTE: This package does not provide a client side library for browser fingerprinting. FingerprintJS Open Source is a good library to use for client side browser fingerprinting.

Important Announcement !

Introducing Laravel Surveillance UI : A package which provides Graphical UI for Laravel Surveillance and integrates within your existing application.

Minimum Requirements

1. Laravel 6.0

2. PHP 7.2

Installation

1. Install the package via composer:

composer require neelkanthk/laravel-surveillance

2.1. Publish the migration files:

php artisan vendor:publish --provider="Neelkanth\Laravel\Surveillance\Providers\SurveillanceServiceProvider" --tag="migrations"

2.2. Publish language files:

php artisan vendor:publish --provider="Neelkanth\Laravel\Surveillance\Providers\SurveillanceServiceProvider" --tag="lang"

3. Run the migrations

php artisan migrate

4. After migrations have been run two tables will be created in the database namely surveillance_managers and surveillance_logs

5. You can publish the config file with:

php artisan vendor:publish --provider="Neelkanth\Laravel\Surveillance\Providers\SurveillanceServiceProvider" --tag="config"

This is the contents of the file that will be published at config/surveillance.php:

return [

    /*
     * The name of the header to be used for browser fingerprint
     */
    "fingerprint-header-key" => "fingerprint",

    /*
     *  This class is responsible enabling, disabling, blocking and unblocking.
     *  To override the default functionality extend the below class and provide its name here.
     */
    "manager-repository" => 'Neelkanth\Laravel\Surveillance\Implementations\SurveillanceManagerRepository',

    /*
     *  This class is responsible for logging the surveillance enabled requests
     *  To override the default functionality extend the below class and provide its name here.
     */
    "log-repository" => 'Neelkanth\Laravel\Surveillance\Implementations\SurveillanceLogRepository',

    /*
     *  The types which are allowed currently.
     *  DO NOT MODIFY THESE
     */
    "allowed-types" => ["userid", "ip", "fingerprint"]
];

CLI Usage

Enable surveillance for an IP Address

php artisan surveillance:enable ip 192.1.2.4

Disable surveillance for an IP Address

php artisan surveillance:disable ip 192.1.2.4

Enable surveillance for a User ID

php artisan surveillance:enable userid 1234

Disable surveillance for a User ID

php artisan surveillance:disable userid 1234

Enable surveillance for Browser Fingerprint

php artisan surveillance:enable fingerprint hjP0tLyIUy7SXaSY6gyb

Disable surveillance for Browser Fingerprint

php artisan surveillance:disable fingerprint hjP0tLyIUy7SXaSY6gyb

Block an IP Address

php artisan surveillance:block ip 192.1.2.4

UnBlock an IP Address

php artisan surveillance:unblock ip 192.1.2.4

Block a User ID

php artisan surveillance:block userid 1234

UnBlock a User ID

php artisan surveillance:unblock userid 1234

Block a Browser Fingerprint

php artisan surveillance:block fingerprint hjP0tLyIUy7SXaSY6gyb

UnBlock a Browser Fingerprint

php artisan surveillance:unblock fingerprint hjP0tLyIUy7SXaSY6gyb

Remove a Surveillance record from Database

php artisan surveillance:remove ip 192.5.4.3

Middleware Usage

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

Route::middleware(["surveillance"])->get('/', function () {
    
});

Programmatic Usage

Enable Surveillance

use Neelkanth\Laravel\Surveillance\Services\Surveillance;
Surveillance::manager()->type("ip")->value("192.5.4.1")->enableSurveillance();

Block Access

use Neelkanth\Laravel\Surveillance\Services\Surveillance;
Surveillance::manager()->type("userid")->value(2121)->blockAccess();

Logging a Request (Works when surveillance in enabled on User ID, IP Address or Browser Fingerprint)

use Neelkanth\Laravel\Surveillance\Services\Surveillance;
Surveillance::logger()->writeLog();

Allowed Types

Currently only userid, ip and fingerprint types are allowed.

Customizing and Overriding the defaults

To override the default surveillance management functionality

Step 1: Extend the SurveillanceManagerRepository Class and override all of its methods

//Example repository to use MongoDB instead of MySQL
namespace App;

use Neelkanth\Laravel\Surveillance\Implementations\SurveillanceManagerRepository;
use Illuminate\Support\Carbon;

class SurveillanceManagerMongoDbRepository extends SurveillanceManagerRepository
{
    public function enableSurveillance()
    {
        $surveillance = $this->getRecord();
        if (is_null($surveillance)) {
            $surveillance["type"] = $this->getType();
            $surveillance["value"] = $this->getValue();
        }
        $surveillance["surveillance_enabled"] = 1;
        $surveillance["surveillance_enabled_at"] = Carbon::now()->toDateTimeString();
        $collection = (new \MongoDB\Client)->surveillance->manager;
        $insertOneResult = $collection->insertOne($surveillance);
        return $insertOneResult;
    }
}

Step 2: Provide the custom class in the config/surveillance.php file's manager-repository key

/*
 *  This class is responsible enabling, disabling, blocking and unblocking.
 *  To override the default functionality extend the below class and provide its name here.
 */
"manager-repository" => 'App\SurveillanceManagerMongoDbRepository',

To override the default logging funtionality

Step 1: Extend the SurveillanceLogRepository Class and override all of its methods

//Example repository to write Logs in MongoDB instead of MySQL
namespace App;

use Neelkanth\Laravel\Surveillance\Implementations\SurveillanceLogRepository;

class SurveillanceLogMongoDbRepository extends SurveillanceLogRepository
{
    public function writeLog($dataToLog = null)
    {
        if (!is_null($dataToLog)) {
            $this->setLogToWrite($dataToLog);
        }
        $log = $this->getLogToWrite();
        if (!empty($log) && is_array($log)) {
            $collection = (new \MongoDB\Client)->surveillance->logs;
            $insertOneResult = $collection->insertOne($log);
        }
    }
}

Step 2: Provide the custom class in the config/surveillance.php file's log-repository key

/*
 *  This class is responsible for logging the surveillance enabled requests
 *  To override the default functionality extend the below class and provide its name here.
*/
"log-repository" => 'App\SurveillanceLogMongoDbRepository',

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Security

If you discover any security-related issues, please email [email protected] instead of using the issue tracker.

Credits

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].