| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Plack::Middleware::Antibot::TooFast; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
16932
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
56
|
|
|
4
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
41
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
721
|
use parent 'Plack::Middleware::Antibot::FilterBase'; |
|
|
1
|
|
|
|
|
402
|
|
|
|
1
|
|
|
|
|
6
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
979
|
use Plack::Session; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
|
11
|
|
|
|
|
|
|
my $self = shift->SUPER::new(@_); |
|
12
|
|
|
|
|
|
|
my (%params) = @_; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$self->{session_name} = $params{session_name} || 'antibot_toofast'; |
|
15
|
|
|
|
|
|
|
$self->{timeout} = $params{timeout} || 1; |
|
16
|
|
|
|
|
|
|
$self->{score} = $params{score} || 0.9; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
return $self; |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub execute { |
|
22
|
|
|
|
|
|
|
my $self = shift; |
|
23
|
|
|
|
|
|
|
my ($env) = @_; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
if ($env->{REQUEST_METHOD} eq 'GET') { |
|
26
|
|
|
|
|
|
|
my $session = Plack::Session->new($env); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$session->set($self->{session_name}, time); |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
elsif ($env->{REQUEST_METHOD} eq 'POST') { |
|
31
|
|
|
|
|
|
|
my $session = Plack::Session->new($env); |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $too_fast = $session->get($self->{session_name}); |
|
34
|
|
|
|
|
|
|
unless ($too_fast && time - $too_fast > $self->{timeout}) { |
|
35
|
|
|
|
|
|
|
$env->{'plack.antibot.toofast.detected'}++; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
return; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
|
43
|
|
|
|
|
|
|
__END__ |