File tree Expand file tree Collapse file tree 5 files changed +64
-18
lines changed Expand file tree Collapse file tree 5 files changed +64
-18
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,7 @@ Available middlewares applicable to routes:
81
81
firewall.all
82
82
83
83
firewall.agent
84
+ firewall.bot
84
85
firewall.geo
85
86
firewall.ip
86
87
firewall.lfi
Original file line number Diff line number Diff line change 42
42
'all_middleware ' => [
43
43
'firewall.ip ' ,
44
44
'firewall.agent ' ,
45
+ 'firewall.bot ' ,
45
46
'firewall.geo ' ,
46
47
'firewall.lfi ' ,
47
48
'firewall.php ' ,
94
95
'block ' => [], // i.e. 'AppleWebKit'
95
96
],
96
97
97
- 'allow_robots ' => true ,
98
+ 'auto_block ' => [
99
+ 'attempts ' => 5 ,
100
+ 'frequency ' => 1 * 60 , // 1 minute
101
+ 'period ' => 30 * 60 , // 30 minutes
102
+ ],
103
+ ],
104
+
105
+ 'bot ' => [
106
+ 'methods ' => ['all ' ],
107
+
108
+ 'routes ' => [
109
+ 'only ' => [], // i.e. 'contact'
110
+ 'except ' => [], // i.e. 'admin/*'
111
+ ],
112
+
113
+ // https://github.com/JayBizzle/Crawler-Detect/blob/master/raw/Crawlers.txt
114
+ 'crawlers ' => [
115
+ 'allow ' => [], // i.e. 'GoogleSites', 'GuzzleHttp'
116
+ 'block ' => [], // i.e. 'Holmes'
117
+ ],
98
118
99
119
'auto_block ' => [
100
120
'attempts ' => 5 ,
Original file line number Diff line number Diff line change @@ -36,10 +36,6 @@ public function check($patterns)
36
36
$ status = true ;
37
37
}
38
38
39
- if (!$ status && $ this ->isRobot ()) {
40
- $ status = true ;
41
- }
42
-
43
39
if ($ status ) {
44
40
$ log = $ this ->log ();
45
41
@@ -171,17 +167,4 @@ protected function isProperty()
171
167
172
168
return false ;
173
169
}
174
-
175
- protected function isRobot ()
176
- {
177
- if (config ('firewall.middleware. ' . $ this ->middleware . '.allow_robots ' )) {
178
- return false ;
179
- }
180
-
181
- if ($ this ->parser ->isRobot ()) {
182
- return true ;
183
- }
184
-
185
- return false ;
186
- }
187
170
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Akaunting \Firewall \Middleware ;
4
+
5
+ use Akaunting \Firewall \Abstracts \Middleware ;
6
+ use Akaunting \Firewall \Events \AttackDetected ;
7
+ use Jenssegers \Agent \Agent ;
8
+
9
+ class Bot extends Middleware
10
+ {
11
+ public function check ($ patterns )
12
+ {
13
+ $ agent = new Agent ();
14
+
15
+ if (!$ agent ->isRobot ()) {
16
+ return false ;
17
+ }
18
+
19
+ if (!$ crawlers = config ('firewall.middleware. ' . $ this ->middleware . '.crawlers ' )) {
20
+ return false ;
21
+ }
22
+
23
+ $ status = false ;
24
+
25
+ if (!empty ($ crawlers ['allow ' ]) && !in_array ((string ) $ agent ->robot (), (array ) $ crawlers ['allow ' ])) {
26
+ $ status = true ;
27
+ }
28
+
29
+ if (in_array ((string ) $ agent ->robot (), (array ) $ crawlers ['block ' ])) {
30
+ $ status = true ;
31
+ }
32
+
33
+ if ($ status ) {
34
+ $ log = $ this ->log ();
35
+
36
+ event (new AttackDetected ($ log ));
37
+ }
38
+
39
+ return $ status ;
40
+ }
41
+ }
Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ public function registerMiddleware($router)
59
59
{
60
60
$ router ->middlewareGroup ('firewall.all ' , config ('firewall.all_middleware ' ));
61
61
$ router ->aliasMiddleware ('firewall.agent ' , 'Akaunting\Firewall\Middleware\Agent ' );
62
+ $ router ->aliasMiddleware ('firewall.bot ' , 'Akaunting\Firewall\Middleware\Bot ' );
62
63
$ router ->aliasMiddleware ('firewall.ip ' , 'Akaunting\Firewall\Middleware\Ip ' );
63
64
$ router ->aliasMiddleware ('firewall.geo ' , 'Akaunting\Firewall\Middleware\Geo ' );
64
65
$ router ->aliasMiddleware ('firewall.lfi ' , 'Akaunting\Firewall\Middleware\Lfi ' );
You can’t perform that action at this time.
0 commit comments