PHP code example of ramir1 / laravel-bot2ban

1. Go to this page and download the library: Download ramir1/laravel-bot2ban 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/ */

    

ramir1 / laravel-bot2ban example snippets


return [
    'signatures' => \Ramir1\LaravelBot2Ban\Signatures\CoreSignatures::definitions() + [
        'project.internal-tool' => [
            'target' => 'uri',
            'type' => 'startswith',
            'patterns' => ['/internal-ops'],
            'level' => 'block',
        ],
    ],
];

use Ramir1\LaravelBot2Ban\Facades\Bot2Ban;
use Ramir1\LaravelBot2Ban\Signatures\{Signature, SignatureTarget, MatchType, Severity};

Bot2Ban::register(new Signature(
    id: 'project.internal-tool',
    target: SignatureTarget::Uri,
    type: MatchType::StartsWith,
    patterns: ['/internal-ops'],
    level: Severity::Block,
));

'signatures' => [
    'default_new_signature_policy' => 'disabled',
    'decisions' => [
        'core.wordpress-and-xmlrpc-paths' => 'rejected',  // this site legitimately uses /wp-admin
        'core.generic-admin-path-words'   => 'approved',
    ],
],
bash
php artisan vendor:publish --tag=bot2ban-config       # main config
php artisan vendor:publish --tag=bot2ban-signatures   # signature definitions
php artisan vendor:publish --tag=bot2ban-fail2ban      # fail2ban templates
php artisan vendor:publish --tag=bot2ban              # everything at once
bash
php artisan vendor:publish --tag=bot2ban-nginx
bash
php artisan vendor:publish --tag=bot2ban-fail2ban
bash
docker compose build
docker compose run --rm php composer install
docker compose run --rm php vendor/bin/pest
docker compose run --rm php vendor/bin/pint --test
docker compose run --rm php vendor/bin/phpstan analyse