|  line  | 
 stmt  | 
 bran  | 
 cond  | 
 sub  | 
 pod  | 
 time  | 
 code  | 
| 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package Plack::Middleware::Antibot::Static;  | 
| 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
3
 | 
2
 | 
 
 | 
 
 | 
  
2
  
 | 
 
 | 
52485
 | 
 use strict;  | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2
 | 
    | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
64
 | 
    | 
| 
4
 | 
2
 | 
 
 | 
 
 | 
  
2
  
 | 
 
 | 
10
 | 
 use warnings;  | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3
 | 
    | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
45
 | 
    | 
| 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
6
 | 
2
 | 
 
 | 
 
 | 
  
2
  
 | 
 
 | 
7
 | 
 use parent 'Plack::Middleware::Antibot::FilterBase';  | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2
 | 
    | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
9
 | 
    | 
| 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
8
 | 
2
 | 
 
 | 
 
 | 
  
2
  
 | 
 
 | 
881
 | 
 use Plack::Session;  | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1287
 | 
    | 
| 
 
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
457
 | 
    | 
| 
9
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
10
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub new {  | 
| 
11
 | 
9
 | 
 
 | 
 
 | 
  
9
  
 | 
  
1
  
 | 
8990
 | 
     my $self = shift->SUPER::new(@_);  | 
| 
12
 | 
9
 | 
 
 | 
 
 | 
 
 | 
 
 | 
24
 | 
     my (%params) = @_;  | 
| 
13
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
14
 | 
9
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
67
 | 
     $self->{path}         = $params{path}         || '/antibot.gif';  | 
| 
15
 | 
9
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
43
 | 
     $self->{session_name} = $params{session_name} || 'antibot_static';  | 
| 
16
 | 
9
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
44
 | 
     $self->{timeout}      = $params{timeout}      || 60 * 15;  | 
| 
17
 | 
9
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
36
 | 
     $self->{score}        = $params{score}        || 0.9;  | 
| 
18
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
19
 | 
9
 | 
 
 | 
 
 | 
 
 | 
 
 | 
42
 | 
     return $self;  | 
| 
20
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
21
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
22
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub execute {  | 
| 
23
 | 
9
 | 
 
 | 
 
 | 
  
9
  
 | 
  
1
  
 | 
11487
 | 
     my $self = shift;  | 
| 
24
 | 
9
 | 
 
 | 
 
 | 
 
 | 
 
 | 
11
 | 
     my ($env) = @_;  | 
| 
25
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
26
 | 
9
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
39
 | 
     if ($env->{REQUEST_METHOD} eq 'GET') {  | 
| 
 
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
27
 | 
5
 | 
 
 | 
 
 | 
 
 | 
 
 | 
7
 | 
         my $path_info = $env->{PATH_INFO};  | 
| 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
29
 | 
5
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
14
 | 
         if ($path_info eq $self->{path}) {  | 
| 
30
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
8
 | 
             my $session = Plack::Session->new($env);  | 
| 
31
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
23
 | 
             $session->set($self->{session_name} => time);  | 
| 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
33
 | 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
35
 | 
             return [200, [], ['']];  | 
| 
34
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
36
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
6
 | 
         $env->{'plack.antibot.static.path'} = $self->{path};  | 
| 
37
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
10
 | 
         $env->{'plack.antibot.static.html'} = qq{ 
 | 
| 
38
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
           . qq{width="1" height="1" style="display:none" />};  | 
| 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
40
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     elsif ($env->{REQUEST_METHOD} eq 'POST') {  | 
| 
41
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
18
 | 
         my $session = Plack::Session->new($env);  | 
| 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
43
 | 
4
 | 
 
 | 
 
 | 
 
 | 
 
 | 
29
 | 
         my $static_fetched = $session->get($self->{session_name});  | 
| 
44
 | 
4
 | 
  
100
  
 | 
  
100
  
 | 
 
 | 
 
 | 
51
 | 
         unless ($static_fetched && time - $static_fetched < $self->{timeout}) {  | 
| 
45
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
14
 | 
             $env->{'plack.antibot.static.detected'}++;  | 
| 
46
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         }  | 
| 
47
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
48
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
49
 | 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
13
 | 
     return;  | 
| 
50
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
51
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
52
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 1;  | 
| 
53
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 __END__  |