zeevx/superban

添加了禁止客户端在一段时间内完全访问你的应用路由的功能。

1.0.1 2023-12-22 12:12 UTC

This package is auto-updated.

Last update: 2024-09-22 13:40:35 UTC


README

superban

Laravel Superban .

Latest Version on Packagist Total Downloads

添加了禁止客户端在一段时间内完全访问你的应用路由的功能。

安装

您可以通过composer安装此包

composer require zeevx/superban

您可以使用以下命令发布配置文件

php artisan vendor:publish --tag="superban-config"

要使用中间件,请在app/Http/Kernel.php中添加它们

    protected $routeMiddleware = [
        'superban' => \Zeevx\Superban\Middlewares\SuperbanMiddleware::class,
    ];

这是发布配置文件的内容

return [
/**
     * Key used in cache
     * The default is ip_address, you can use either: ip_address or email or user_id
     *
     */
    'key' => 'ip_address',

    /**
     * The cache to be used,
     * The default cache in config/cache.php is used if empty.
     */
    'cache' => 'file',

    /**
     * Specify guard to be used if you are using email or user_id
     * The default guard in config/auth.php is used if empty
     */
    'user_guard' => '',

    /**
     * Enable email notification for when a user is banned
     *
     */
    'enable_email_notification' => true,

    /**
     * Email address to be used for email notification
     *
     */
    'email_address' => '',
];

用法

将中间件应用到以下格式的任何路由

X - 请求次数

Y - 在多长时间内(分钟)

Z - 用户被禁止多长时间(分钟)。

Route::middleware(['superban:X,Y,Z])->group(function () {
   Route::post('/thisroute', function () {
       // ...
   });
 
   Route::post('anotherroute', function () {
       // ...
   });
});

测试

composer test

致谢

许可

MIT许可(MIT)。请参阅许可文件获取更多信息。