PHP code example of manggala / sentinel

1. Go to this page and download the library: Download manggala/sentinel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

manggala / sentinel example snippets


use Manggala\Sentinel\Http\Middleware\SentinelGuardMiddleware;
use Manggala\Sentinel\Http\Middleware\SentinelBruteForceMiddleware;

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        commands: __DIR__.'/../routes/console.php',
        health: '/up',
    )
    ->withMiddleware(function (Middleware $middleware) {
        // Daftarkan WAF guard global
        $middleware->append(SentinelGuardMiddleware::class);
        
        // Daftarkan Brute Force guard pada endpoint auth
        $middleware->alias([
            'sentinel.bruteforce' => SentinelBruteForceMiddleware::class,
        ]);
    })
    ->create();

protected $middleware = [
    // ...
    \Manggala\Sentinel\Http\Middleware\SentinelGuardMiddleware::class,
];

protected $routeMiddleware = [
    // ...
    'sentinel.bruteforce' => \Manggala\Sentinel\Http\Middleware\SentinelBruteForceMiddleware::class,
];

Route::post('/login', [AuthController::class, 'store'])
    ->middleware('sentinel.bruteforce');

return [
    /*
    |--------------------------------------------------------------------------
    | Status Keaktifan WAF
    |--------------------------------------------------------------------------
    */
    'enabled' => env('SENTINEL_ENABLED', true),

    /*
    |--------------------------------------------------------------------------
    | Anomaly Threat Threshold
    |--------------------------------------------------------------------------
    | Request dengan total skor ancaman >= threshold akan otomatis diblokir (403).
    */
    'threshold' => env('SENTINEL_THRESHOLD', 5),

    /*
    |--------------------------------------------------------------------------
    | Proteksi Login & Brute Force
    |--------------------------------------------------------------------------
    */
    'brute_force' => [
        'max_attempts' => 5,
        'decay_seconds' => 60,
        'captcha_after' => 3,
    ],

    /*
    |--------------------------------------------------------------------------
    | IP Whitelist & Blacklist
    |--------------------------------------------------------------------------
    */
    'whitelist_ips' => [
        '127.0.0.1',
        '::1',
    ],

    /*
    |--------------------------------------------------------------------------
    | Route Exclusions (Pengecualian)
    |--------------------------------------------------------------------------
    */
    'excluded_routes' => [
        'admin/page-builder/*',
        'api/webhooks/*',
    ],
];

use Manggala\Sentinel\Facades\Sentinel;

// Memeriksa apakah IP diblokir
if (Sentinel::isIpBlocked('192.168.1.50')) {
    // IP sedang diblokir
}

// Memblokir IP secara manual
Sentinel::blockIp('192.168.1.50', 'Aktivitas peretasan mencurigakan');

// Membuka blokir IP
Sentinel::unbanIp('192.168.1.50');

// Mendapatkan ringkasan statistik keamanan
$stats = Sentinel::getMetrics();
bash
php artisan sentinel:install
bash
php artisan migrate
bash
php artisan sentinel:install
bash
php artisan sentinel:unban 192.168.1.100
bash
php artisan sentinel:whitelist 10.0.0.1
bash
php artisan sentinel:clear-logs --days=30
bash
php artisan sentinel:stats