line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
Slaughter::Transport::http - HTTP transport class. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 SYNOPSIS |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
This transport copes with fetching files and policies from a remote server |
9
|
|
|
|
|
|
|
using HTTP or HTTPS as a transport. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
This transport is slightly different to the others, as each file is fetched |
16
|
|
|
|
|
|
|
on-demand, with no local filesystem access and no caching. |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
If HTTP Basic-Auth is required the appropriate details should be passed to |
19
|
|
|
|
|
|
|
slaughter with the "C<--username>" & "C<--password>" flags. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
848
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
26
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
400
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
package Slaughter::Transport::http; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
our $VERSION = "3.0.5"; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 new |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Create a new instance of this object. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub new |
47
|
|
|
|
|
|
|
{ |
48
|
1
|
|
|
1
|
1
|
434
|
my ( $proto, %supplied ) = (@_); |
49
|
1
|
|
33
|
|
|
5
|
my $class = ref($proto) || $proto; |
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
|
|
1
|
my $self = {}; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
3
|
foreach my $key ( keys %supplied ) |
57
|
|
|
|
|
|
|
{ |
58
|
0
|
|
|
|
|
0
|
$self->{ lc $key } = $supplied{ $key }; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
2
|
$self->{ 'error' } = undef; |
65
|
|
|
|
|
|
|
|
66
|
1
|
|
|
|
|
1
|
bless( $self, $class ); |
67
|
1
|
|
|
|
|
3
|
return $self; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 name |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Return the name of this transport. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub name |
79
|
|
|
|
|
|
|
{ |
80
|
1
|
|
|
1
|
1
|
1145
|
return ("http"); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 isAvailable |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Return whether this transport is available. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
As we're pure-perl it should be always available if the C<LWP::UserAgent> module is available. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub isAvailable |
94
|
|
|
|
|
|
|
{ |
95
|
0
|
|
|
0
|
1
|
|
my ($self) = (@_); |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
my $lwp = "use LWP::UserAgent;"; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
eval($lwp); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
0
|
0
|
|
|
|
|
if ($@) |
104
|
|
|
|
|
|
|
{ |
105
|
0
|
|
|
|
|
|
$self->{ 'error' } = "LWP::UserAgent module not available."; |
106
|
0
|
|
|
|
|
|
return 0; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
return 1; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 error |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Return the last error from the transport. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
This is only set in L</isAvailable>. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub error |
126
|
|
|
|
|
|
|
{ |
127
|
0
|
|
|
0
|
1
|
|
my ($self) = (@_); |
128
|
0
|
|
|
|
|
|
return ( $self->{ 'error' } ); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 fetchContents |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Fetch the contents of a remote URL, using HTTP basic-auth if we should |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub fetchContents |
140
|
|
|
|
|
|
|
{ |
141
|
0
|
|
|
0
|
1
|
|
my ( $self, %args ) = (@_); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
my $pref = $args{ 'prefix' }; |
147
|
0
|
|
|
|
|
|
my $url = $args{ 'file' }; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
0
|
0
|
|
|
|
|
if ( $url !~ /^http/i ) |
153
|
|
|
|
|
|
|
{ |
154
|
0
|
|
|
|
|
|
$url = "$self->{'prefix'}/$pref/$url"; |
155
|
|
|
|
|
|
|
|
156
|
0
|
0
|
|
|
|
|
$self->{ 'verbose' } && |
157
|
|
|
|
|
|
|
print "\tExpanded to: $url \n"; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
my $ua; |
162
|
|
|
|
|
|
|
|
163
|
0
|
0
|
|
|
|
|
if ( $LWP::UserAgent::VERSION < 6.00 ) |
164
|
|
|
|
|
|
|
{ |
165
|
0
|
|
|
|
|
|
$ua = LWP::UserAgent->new(); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
else |
168
|
|
|
|
|
|
|
{ |
169
|
0
|
|
|
|
|
|
$ua = LWP::UserAgent->new( ssl_opts => { verify_hostname => 1 } ); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
175
|
0
|
|
|
|
|
|
$ua->env_proxy(); |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
my $req = HTTP::Request->new( GET => $url ); |
181
|
0
|
0
|
0
|
|
|
|
if ( $self->{ 'username' } && $self->{ 'password' } ) |
182
|
|
|
|
|
|
|
{ |
183
|
0
|
|
|
|
|
|
$req->authorization_basic( $self->{ 'username' }, |
184
|
|
|
|
|
|
|
$self->{ 'password' } ); |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
0
|
|
|
|
|
|
my $response = $ua->request($req); |
191
|
0
|
0
|
|
|
|
|
if ( $response->is_success() ) |
192
|
|
|
|
|
|
|
{ |
193
|
0
|
0
|
|
|
|
|
$self->{ 'verbose' } && |
194
|
|
|
|
|
|
|
print "\tOK\n"; |
195
|
0
|
|
|
|
|
|
return ( $response->decoded_content() ); |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
|
201
|
0
|
0
|
|
|
|
|
$self->{ 'verbose' } && |
202
|
|
|
|
|
|
|
print "\tFailed to fetch: $url - " . $response->status_line . "\n"; |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
|
207
|
0
|
|
|
|
|
|
my $res = undef; |
208
|
0
|
|
|
|
|
|
return ($res); |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
1; |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 AUTHOR |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Steve Kemp <steve@steve.org.uk> |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=cut |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head1 LICENSE |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Copyright (c) 2010-2015 by Steve Kemp. All rights reserved. |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
This module is free software; |
226
|
|
|
|
|
|
|
you can redistribute it and/or modify it under |
227
|
|
|
|
|
|
|
the same terms as Perl itself. |
228
|
|
|
|
|
|
|
The LICENSE file contains the full text of the license. |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=cut |
231
|
|
|
|
|
|
|
|