Skip to content

Commit a024155

Browse files
author
Bruno Cabral
committed
Colocar os commands
1 parent 70e3897 commit a024155

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed

src/BlockBotsServiceProvider.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Potelo\LaravelBlockBots;
44

55
use Illuminate\Support\ServiceProvider;
6+
use Potelo\LaravelBlockBots\Commands\ListWhitelist;
7+
use Potelo\LaravelBlockBots\Commands\ClearWhitelist;
68

79
class BlockBotsServiceProvider extends ServiceProvider
810
{
@@ -13,6 +15,14 @@ class BlockBotsServiceProvider extends ServiceProvider
1315
*/
1416
public function boot()
1517
{
18+
19+
if ($this->app->runningInConsole()) {
20+
$this->commands([
21+
ListWhitelist::class,
22+
ClearWhitelist::class,
23+
]);
24+
}
25+
1626
$this->publishes([
1727
__DIR__ . '/config/block-bots.php' => config_path('block-bots.php'),
1828
]);
@@ -36,3 +46,5 @@ public function register()
3646
);
3747
}
3848
}
49+
50+

src/Commands/ClearWhitelist.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Potelo\LaravelBlockBots\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\Redis;
7+
8+
class ClearWhitelist extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'block-bots:clear-whitelist';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Clear the White-list';
23+
24+
/**
25+
* Create a new command instance.
26+
*
27+
* @return void
28+
*/
29+
public function __construct()
30+
{
31+
parent::__construct();
32+
}
33+
34+
/**
35+
* Execute the console command.
36+
*
37+
* @return mixed
38+
*/
39+
public function handle()
40+
{
41+
//
42+
$key_whitelist = "block_bot:whitelist";
43+
$whitelist = Redis::del($key_whitelist);
44+
$this->info("Whitelist cleared");
45+
46+
47+
}
48+
}

src/Commands/ListWhitelist.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Potelo\LaravelBlockBots\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\Redis;
7+
8+
class ListWhitelist extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'block-bots:list-whitelist';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Show the list of IPs that are Whitelisted';
23+
24+
/**
25+
* Create a new command instance.
26+
*
27+
* @return void
28+
*/
29+
public function __construct()
30+
{
31+
parent::__construct();
32+
}
33+
34+
/**
35+
* Execute the console command.
36+
*
37+
* @return mixed
38+
*/
39+
public function handle()
40+
{
41+
//
42+
$key_whitelist = "block_bot:whitelist";
43+
$whitelist = Redis::smembers($key_whitelist);
44+
$this->info("List of IPs whitelisted:");
45+
foreach ($whitelist as $ip)
46+
{
47+
$this->info($ip);
48+
}
49+
50+
}
51+
}

0 commit comments

Comments
 (0)