File tree Expand file tree Collapse file tree 6 files changed +160
-4
lines changed Expand file tree Collapse file tree 6 files changed +160
-4
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 ;
76use  Potelo \LaravelBlockBots \Commands \ClearWhitelist ;
7+ use  Potelo \LaravelBlockBots \Commands \ListWhitelist ;
8+ use  Potelo \LaravelBlockBots \Commands \ListHits ;
9+ use  Potelo \LaravelBlockBots \Commands \ListNotified ;
810
911class  BlockBotsServiceProvider extends  ServiceProvider
1012{
@@ -18,8 +20,10 @@ public function boot()
1820
1921        if  ($ this app ->runningInConsole ()) {
2022            $ this commands ([
21-                 ListWhitelist::class,
2223                ClearWhitelist::class,
24+                 ListWhitelist::class,
25+                 ListHits::class,
26+                 ListNotified::class,
2327            ]);
2428        }
2529
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+ use  Potelo \LaravelBlockBots \Contracts \Configuration ;
8+ 
9+ class  ListHits extends  Command
10+ {
11+     /** 
12+      * The name and signature of the console command. 
13+      * 
14+      * @var string 
15+      */ 
16+     protected  $ signature'block-bots:list-hits ' ;
17+ 
18+     /** 
19+      * The console command description. 
20+      * 
21+      * @var string 
22+      */ 
23+     protected  $ description'Show the list of IPs with hits count ' ;
24+ 
25+     /** 
26+      * @var \Potelo\LaravelBlockBots\Contracts\Configuration 
27+      */ 
28+     private  $ options
29+ 
30+     /** 
31+      * Create a new command instance. 
32+      * 
33+      * @return void 
34+      */ 
35+     public  function  __construct ()
36+     {
37+         parent ::__construct ();
38+         $ this options  = new  Configuration ();
39+     }
40+ 
41+     /** 
42+      * Execute the console command. 
43+      * 
44+      * @return void 
45+      */ 
46+     public  function  handle ()
47+     {
48+         $ this info ("List of IPs hits: " );
49+         
50+         $ keyskeys ('block_bot:hits* ' );
51+         
52+         foreach  ($ keysas  $ key
53+             $ keystr ($ keyafterLast (': ' );
54+             $ this info ($ key" :  "  . Redis::get ("block_bot:hits: {$ key ));
55+         }
56+     }
57+ }
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+ use  Potelo \LaravelBlockBots \Contracts \Configuration ;
8+ 
9+ class  ListNotified extends  Command
10+ {
11+     /** 
12+      * The name and signature of the console command. 
13+      * 
14+      * @var string 
15+      */ 
16+     protected  $ signature'block-bots:list-notified ' ;
17+ 
18+     /** 
19+      * The console command description. 
20+      * 
21+      * @var string 
22+      */ 
23+     protected  $ description'Show the list of notified IPs with notified count ' ;
24+ 
25+     /** 
26+      * @var \Potelo\LaravelBlockBots\Contracts\Configuration 
27+      */ 
28+     private  $ options
29+ 
30+     /** 
31+      * Create a new command instance. 
32+      * 
33+      * @return void 
34+      */ 
35+     public  function  __construct ()
36+     {
37+         parent ::__construct ();
38+         $ this options  = new  Configuration ();
39+     }
40+ 
41+     /** 
42+      * Execute the console command. 
43+      * 
44+      * @return void 
45+      */ 
46+     public  function  handle ()
47+     {
48+         $ this info ("List of notified IPs with notified count: " );
49+         
50+         $ keyskeys ('block_bot:notified* ' );
51+         
52+         foreach  ($ keysas  $ key
53+             $ keystr ($ keyafterLast (': ' );
54+             $ this info ($ key" :  "  . Redis::get ("block_bot:notified: {$ key ));
55+         }
56+     }
57+ }
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ public function __construct($request)
2626        $ this ip  = $ requestgetClientIp ();
2727        $ this id  = Auth::check () ? Auth::id () : $ this ip ;
2828        $ this userAgent  = $ requestheader ('User-Agent ' );
29-         $ this key  = "block_bot: {$ this id }" ;
29+         $ this key  = "block_bot:hits:  {$ this id }" ;
3030        $ this logKey  = "block_bot:notified: {$ this ip }" ;
3131        $ this url  = substr ($ requestfullUrl (), strlen ($ requestgetScheme () . ":// " ));
3232        $ this options  = new  Configuration ();
Original file line number Diff line number Diff line change 1+ <?php 
2+ 
3+ namespace  Potelo \LaravelBlockBots \Events ;
4+ 
5+ use  Carbon \Carbon ;
6+ use  Illuminate \Queue \SerializesModels ;
7+ 
8+ class  BotBlockedEvent
9+ {
10+     use  SerializesModels;
11+ 
12+     public  $ ip
13+ 
14+     /** @var integer */ 
15+     public  $ number_of_hits
16+ 
17+     /** @var Carbon */ 
18+     public  $ block_date
19+ 
20+     /** 
21+      * Create a new event instance. 
22+      * 
23+      * @param $ip 
24+      * @param  integer  $number_of_hits 
25+      * @param  Carbon  $block_date 
26+      * 
27+      * @return void 
28+      */ 
29+     public  function  __construct ($ ip$ number_of_hits$ block_date
30+     {
31+         $ this ip  = $ ip
32+         $ this number_of_hits  = $ number_of_hits
33+         $ this block_date  = $ block_date
34+     }
35+ }
Original file line number Diff line number Diff line change 1111use  Potelo \LaravelBlockBots \Events \UserBlockedEvent ;
1212use  Potelo \LaravelBlockBots \Jobs \ProcessLogWithIpInfo ;
1313use  Potelo \LaravelBlockBots \Abstracts \AbstractBlockBots ;
14- 
14+ use   Potelo \ LaravelBlockBots \ Events \ BotBlockedEvent ; 
1515
1616class  BlockBots extends  AbstractBlockBots
1717{
@@ -56,6 +56,9 @@ protected function notAllowed()
5656            event (new  UserBlockedEvent (Auth::user (), $ this hits , Carbon::now ()));
5757        }
5858
59+         if  (Auth::guest () && $ this isTheFirstOverflow ()) {
60+             event (new  BotBlockedEvent ($ this client ->ip , $ this hits , Carbon::now ()));
61+         }
5962
6063        if  ($ this request ->expectsJson ()) {
6164            return  response ()->json ($ this options ->json_response , 429 );
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments