File tree Expand file tree Collapse file tree 3 files changed +111
-0
lines changed Expand file tree Collapse file tree 3 files changed +111
-0
lines changed Original file line number Diff line number Diff line change 33namespace Potelo \LaravelBlockBots ;
44
55use Illuminate \Support \ServiceProvider ;
6+ use Potelo \LaravelBlockBots \Commands \ListWhitelist ;
7+ use Potelo \LaravelBlockBots \Commands \ClearWhitelist ;
68
79class 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+
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments