line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Web::Detect; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
37075
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
62
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.04'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub import { |
9
|
3
|
100
|
|
3
|
|
3119
|
if ( @_ > 1 ) { |
10
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
617
|
|
11
|
2
|
100
|
|
|
|
14
|
if ( grep /^detect_web$/, @_ ) { |
12
|
1
|
|
|
|
|
3
|
*{ caller() . '::detect_web' } = \&detect_web; |
|
1
|
|
|
|
|
6
|
|
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
2
|
100
|
|
|
|
15
|
if ( grep /^detect_web_fast$/, @_ ) { |
16
|
1
|
|
|
|
|
3
|
*{ caller() . '::detect_web_fast' } = \&detect_web_fast; |
|
1
|
|
|
|
|
5
|
|
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub detect_web { |
22
|
13
|
|
|
13
|
1
|
738
|
my ($first) = @_; |
23
|
13
|
|
|
|
|
14
|
my %res; |
24
|
|
|
|
|
|
|
|
25
|
13
|
50
|
|
|
|
33
|
if ( $ENV{MOD_PERL} ) { # verified on mod_perl 1.3 and mod_perl 2.0 |
26
|
0
|
|
|
|
|
0
|
$res{mod_perl} = 1; |
27
|
0
|
0
|
|
|
|
0
|
return \%res if $first; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
13
|
50
|
|
|
|
21
|
if ( $ENV{PLACK_ENV} ) { |
31
|
0
|
|
|
|
|
0
|
$res{plack} = 1; |
32
|
0
|
|
|
|
|
0
|
$res{psgi} = 1; |
33
|
0
|
0
|
|
|
|
0
|
return \%res if $first; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
13
|
100
|
|
|
|
27
|
if ( $ENV{'PANGEA'} ) { |
37
|
7
|
|
|
|
|
12
|
$res{'pangea'} = 1; |
38
|
7
|
|
|
|
|
8
|
$res{'psgi'} = 1; |
39
|
7
|
100
|
|
|
|
26
|
return \%res if $first; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
11
|
50
|
33
|
|
|
52
|
if ( $ENV{'CPANEL'} || $ENV{'WHM50'} ) { |
43
|
0
|
|
|
|
|
0
|
$res{'cpanel'} = 1; |
44
|
0
|
0
|
|
|
|
0
|
return \%res if $first; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
11
|
50
|
|
|
|
22
|
if ( $ENV{'CATALYST_SCRIPT_GEN'} ) { |
48
|
0
|
|
|
|
|
0
|
$res{'catalyst'} = 1; |
49
|
0
|
0
|
|
|
|
0
|
return \%res if $first; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
11
|
50
|
|
|
|
23
|
if ( $ENV{'DANCER_APPDIR'} ) { |
53
|
0
|
|
|
|
|
0
|
$res{'dancer'} = 1; |
54
|
0
|
0
|
|
|
|
0
|
return \%res if $first; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
11
|
50
|
|
|
|
20
|
if ( $ENV{'MOJO_EXE'} ) { |
58
|
0
|
|
|
|
|
0
|
$res{'mojo'} = 1; |
59
|
0
|
0
|
|
|
|
0
|
return \%res if $first; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
11
|
50
|
|
|
|
20
|
if ( $ENV{'FCGI_ROLE'} ) { |
63
|
0
|
|
|
|
|
0
|
$res{'FCGI.pm'} = 1; |
64
|
0
|
0
|
|
|
|
0
|
return \%res if $first; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
11
|
50
|
|
|
|
20
|
if ( $ENV{'INSTANCE_ID'} ) { |
68
|
0
|
|
|
|
|
0
|
$res{'IIS'} = 1; |
69
|
0
|
0
|
|
|
|
0
|
return \%res if $first; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# now, do more generic checks after specific server checks: |
73
|
11
|
100
|
66
|
|
|
70
|
if ( defined $ENV{GATEWAY_INTERFACE} && $ENV{GATEWAY_INTERFACE} =~ m/^CGI/ ) { |
74
|
9
|
|
|
|
|
18
|
$res{cgi} = 1; |
75
|
9
|
100
|
|
|
|
23
|
return \%res if $first; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# General server vars: |
79
|
9
|
50
|
66
|
|
|
122
|
if ( $ENV{'SCRIPT_NAME'} || $ENV{'SCRIPT_FILENAME'} || $ENV{'REMOTE_ADDR'} || $ENV{'HTTPS'} || $ENV{'QUERY_STRING'} || $ENV{'DOCUMENT_ROOT'} ) { |
|
|
|
66
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
80
|
2
|
|
|
|
|
2
|
$res{'general'} = 1; |
81
|
2
|
50
|
|
|
|
6
|
return \%res if $first; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# still nothing? yikes ... |
85
|
9
|
|
|
|
|
26
|
for my $k ( keys %ENV ) { |
86
|
16
|
100
|
|
|
|
52
|
if ( $k =~ m/^(?:HTTP|SERVER|REQUEST)_/ ) { |
87
|
2
|
|
|
|
|
19
|
$res{'general'} += 2; |
88
|
2
|
50
|
|
|
|
10
|
return \%res if $first; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# the way scripts are run in some web servers they are still technically |
93
|
|
|
|
|
|
|
# "interactive", so interactivity is only reliable for this if it is false |
94
|
|
|
|
|
|
|
# (IO::Interactive::Tiny) |
95
|
|
|
|
|
|
|
# |
96
|
|
|
|
|
|
|
# ditto +/- for term detection (Term::Detect) |
97
|
|
|
|
|
|
|
|
98
|
9
|
100
|
|
|
|
30
|
return unless %res; |
99
|
7
|
|
|
|
|
53
|
return \%res; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub detect_web_fast { |
103
|
5
|
|
|
5
|
1
|
11
|
@_ = (1); |
104
|
5
|
|
|
|
|
14
|
goto &detect_web; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
#ABSTRACT: Detect if program is running under some web environment |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__END__ |