line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::CurlLog; |
2
|
1
|
|
|
1
|
|
56558
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
872
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = "0.03"; |
6
|
|
|
|
|
|
|
our %opts = ( |
7
|
|
|
|
|
|
|
file => undef, |
8
|
|
|
|
|
|
|
response => 1, |
9
|
|
|
|
|
|
|
options => "-k", |
10
|
|
|
|
|
|
|
timing => 0, |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub import { |
14
|
1
|
|
|
1
|
|
8
|
my ($package, %args) = @_; |
15
|
1
|
|
|
|
|
3
|
for my $key (keys %args) { |
16
|
2
|
|
|
|
|
3
|
$opts{$key} = $args{$key}; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
1
|
50
|
|
|
|
4
|
if (!$opts{file}) { |
20
|
0
|
|
|
|
|
0
|
$opts{fh} = \*STDERR; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
else { |
23
|
1
|
|
|
|
|
2
|
my $file2 = $opts{file}; |
24
|
1
|
50
|
|
|
|
3
|
if ($file2 =~ m{^~/}) { |
25
|
0
|
|
0
|
|
|
0
|
my $home = $ENV{HOME} || (getpwuid($<))[7]; |
26
|
0
|
|
|
|
|
0
|
$file2 =~ s{^~/}{$home/}; |
27
|
|
|
|
|
|
|
} |
28
|
1
|
50
|
|
|
|
82
|
open $opts{fh}, ">>", $file2 or die "Can't open $opts{file}: $!"; |
29
|
|
|
|
|
|
|
} |
30
|
1
|
|
|
|
|
6
|
select($opts{fh}); |
31
|
1
|
|
|
|
|
3
|
$| = 1; |
32
|
1
|
|
|
|
|
1
|
select(STDOUT); |
33
|
|
|
|
|
|
|
|
34
|
1
|
50
|
|
|
|
2
|
if (!$ENV{"GATEWAY_INTERFACE"}) { |
35
|
0
|
|
|
|
|
0
|
return 1; |
36
|
|
|
|
|
|
|
} |
37
|
1
|
|
|
|
|
2
|
my $cmd = "curl "; |
38
|
1
|
50
|
|
|
|
4
|
my $url = $ENV{"HTTPS"} ? "https://" : "http://"; |
39
|
1
|
|
0
|
|
|
3
|
$url .= $ENV{"HTTP_HOST"} || $ENV{"SERVER_NAME"} || $ENV{"SERVER_ADDR"}; |
40
|
1
|
|
|
|
|
2
|
$url .= $ENV{"REQUEST_URI"}; |
41
|
1
|
50
|
|
|
|
4
|
if ($url =~ /[=&;?]/) { |
42
|
1
|
|
|
|
|
2
|
$cmd .= "\"$url\" "; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else { |
45
|
0
|
|
|
|
|
0
|
$cmd .= "$url "; |
46
|
|
|
|
|
|
|
} |
47
|
1
|
50
|
|
|
|
2
|
if ($opts{options}) { |
48
|
1
|
|
|
|
|
7
|
$cmd .= "$opts{options} "; |
49
|
|
|
|
|
|
|
} |
50
|
1
|
50
|
|
|
|
2
|
if ($ENV{"REQUEST_METHOD"}) { |
51
|
0
|
0
|
0
|
|
|
0
|
if ($ENV{"REQUEST_METHOD"} ne "GET" || $ENV{"CONTENT_LENGTH"}) { |
52
|
0
|
|
|
|
|
0
|
$cmd .= "-X $ENV{REQUEST_METHOD} "; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
1
|
50
|
|
|
|
1
|
if ($ENV{"CONTENT_TYPE"}) { |
56
|
0
|
|
|
|
|
0
|
$cmd .= "-H \"Content-Type: $ENV{CONTENT_TYPE}\" "; |
57
|
|
|
|
|
|
|
} |
58
|
1
|
50
|
|
|
|
3
|
if ($ENV{"HTTP_ACCEPT"}) { |
59
|
0
|
|
|
|
|
0
|
$cmd .= "-H \"Accept: $ENV{HTTP_ACCEPT}\" "; |
60
|
|
|
|
|
|
|
} |
61
|
1
|
50
|
|
|
|
1
|
if ($ENV{"HTTP_AUTHORIZATION"}) { |
62
|
0
|
|
|
|
|
0
|
$cmd .= "-H \"Authorization: $ENV{HTTP_AUTHORIZATION}\" "; |
63
|
|
|
|
|
|
|
} |
64
|
1
|
50
|
|
|
|
2
|
if ($ENV{"HTTP_COOKIE"}) { |
65
|
0
|
|
|
|
|
0
|
$cmd .= "-H \"Cookie: $ENV{HTTP_COOKIE}\" "; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
# if ($ENV{"HTTP_USER_AGENT"}) { |
68
|
|
|
|
|
|
|
# $cmd .= "-H \"UserAgent: $ENV{HTTP_USER_AGENT}\" "; |
69
|
|
|
|
|
|
|
# } |
70
|
1
|
50
|
|
|
|
2
|
if ($ENV{"CONTENT_LENGTH"}) { |
71
|
0
|
|
|
|
|
0
|
my $input = do {local $/; }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
72
|
0
|
|
|
|
|
0
|
close STDIN; |
73
|
0
|
|
|
|
|
0
|
open STDIN, "<", \$input; |
74
|
0
|
|
|
|
|
0
|
my $input2 = $input; |
75
|
0
|
|
|
|
|
0
|
$input2 =~ s{([\\\$"])}{\\$1}g; |
76
|
0
|
|
|
|
|
0
|
$cmd .= "-d \"$input2\" "; |
77
|
|
|
|
|
|
|
} |
78
|
1
|
|
|
|
|
9
|
$cmd =~ s/\s*$//; |
79
|
|
|
|
|
|
|
|
80
|
1
|
|
|
|
|
1
|
print {$opts{fh}} "# " . localtime() . " request from $ENV{REMOTE_ADDR}\n"; |
|
1
|
|
|
|
|
89
|
|
81
|
1
|
|
|
|
|
3
|
print {$opts{fh}} "$cmd\n"; |
|
1
|
|
|
|
|
11
|
|
82
|
|
|
|
|
|
|
|
83
|
1
|
|
|
|
|
2
|
$opts{response2} = ""; |
84
|
1
|
50
|
|
|
|
3
|
if ($opts{response}) { |
85
|
0
|
|
|
|
|
0
|
open $opts{stdout}, ">&", STDOUT; |
86
|
0
|
|
|
|
|
0
|
close STDOUT; |
87
|
0
|
|
|
|
|
0
|
open STDOUT, ">", \$opts{response2}; |
88
|
|
|
|
|
|
|
} |
89
|
1
|
|
|
|
|
1086
|
$opts{time1} = time(); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
END { |
93
|
1
|
50
|
|
1
|
|
4132
|
if ($opts{response}) { |
94
|
0
|
|
|
|
|
0
|
open STDOUT, ">&", $opts{stdout}; |
95
|
0
|
|
|
|
|
0
|
print $opts{response2}; |
96
|
0
|
|
|
|
|
0
|
$opts{response2} =~ s/\r//g; |
97
|
0
|
|
|
|
|
0
|
$opts{response2} =~ s/\s*$//g; |
98
|
0
|
|
|
|
|
0
|
print {$opts{fh}} "# " . localtime() . " response\n"; |
|
0
|
|
|
|
|
0
|
|
99
|
0
|
|
|
|
|
0
|
print {$opts{fh}} $opts{response2} . "\n"; |
|
0
|
|
|
|
|
0
|
|
100
|
|
|
|
|
|
|
} |
101
|
1
|
50
|
|
|
|
11
|
if ($opts{timing}) { |
102
|
0
|
|
|
|
|
0
|
$opts{time2} = time(); |
103
|
0
|
|
|
|
|
0
|
my $diff = $opts{time2} - $opts{time1}; |
104
|
0
|
|
|
|
|
0
|
print {$opts{fh}} "# ${diff}s\n"; |
|
0
|
|
|
|
|
0
|
|
105
|
|
|
|
|
|
|
} |
106
|
1
|
|
|
|
|
2
|
print {$opts{fh}} "\n"; |
|
1
|
|
|
|
|
45
|
|
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__END__ |