line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Interface::File::HTTP; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
14
|
use v5.12.5; |
|
1
|
|
|
|
|
5
|
|
8
|
1
|
|
|
1
|
|
9
|
use warnings; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
41
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.2.2'; # TRIAL VERSION |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
6
|
use Data::Dumper; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
63
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
BEGIN { |
15
|
1
|
|
|
1
|
|
7
|
use Rex::Require; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
8
|
|
16
|
1
|
|
|
1
|
|
55
|
MIME::Base64->use; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
8
|
use Rex::Commands; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
20
|
1
|
|
|
1
|
|
8
|
use Rex::Interface::Fs; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
5
|
|
21
|
1
|
|
|
1
|
|
50
|
use Rex::Interface::File::Base; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
12
|
|
22
|
1
|
|
|
1
|
|
32
|
use base qw(Rex::Interface::File::Base); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
615
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub new { |
25
|
0
|
|
|
0
|
0
|
|
my $that = shift; |
26
|
0
|
|
0
|
|
|
|
my $proto = ref($that) || $that; |
27
|
0
|
|
|
|
|
|
my $self = $proto->SUPER::new(@_); |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
bless( $self, $proto ); |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
return $self; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub open { |
35
|
0
|
|
|
0
|
0
|
|
my ( $self, $mode, $file ) = @_; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
$self->{__file} = $file; |
38
|
0
|
|
|
|
|
|
$self->{__current_pos} = 0; |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
if ( $mode eq ">>" ) { |
41
|
0
|
|
|
|
|
|
my $fs = Rex::Interface::Fs->create; |
42
|
0
|
|
|
|
|
|
eval { |
43
|
0
|
|
|
|
|
|
my %stat = $fs->stat($file); |
44
|
0
|
|
|
|
|
|
$self->{__current_pos} = $stat{size}; |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
Rex::Logger::debug("Opening $file with mode: $mode"); |
49
|
0
|
|
|
|
|
|
my $resp = connection->post( "/file/open", { path => $file, mode => $mode } ); |
50
|
0
|
|
|
|
|
|
return $resp->{ok}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub read { |
54
|
0
|
|
|
0
|
0
|
|
my ( $self, $len ) = @_; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $resp = connection->post( |
57
|
|
|
|
|
|
|
"/file/read", |
58
|
|
|
|
|
|
|
{ |
59
|
|
|
|
|
|
|
path => $self->{__file}, |
60
|
|
|
|
|
|
|
start => $self->{__current_pos}, |
61
|
0
|
|
|
|
|
|
len => $len, |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
|
if ( $resp->{ok} ) { |
66
|
0
|
|
|
|
|
|
my $buf = decode_base64( $resp->{buf} ); |
67
|
0
|
|
|
|
|
|
$self->{__current_pos} += length($buf); |
68
|
0
|
|
|
|
|
|
return $buf; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
return; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub write { |
75
|
0
|
|
|
0
|
0
|
|
my ( $self, $buf ) = @_; |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
0
|
|
|
|
utf8::encode($buf) |
78
|
|
|
|
|
|
|
if Rex::Config->get_write_utf8_files && utf8::is_utf8($buf); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my $resp = connection->post( |
81
|
|
|
|
|
|
|
"/file/write_fh", |
82
|
|
|
|
|
|
|
{ |
83
|
|
|
|
|
|
|
path => $self->{__file}, |
84
|
|
|
|
|
|
|
start => $self->{__current_pos}, |
85
|
0
|
|
|
|
|
|
buf => encode_base64($buf), |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
if ( $resp->{ok} ) { |
90
|
0
|
|
|
|
|
|
$self->{__current_pos} += length($buf); |
91
|
0
|
|
|
|
|
|
return length($buf); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
return; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub seek { |
98
|
0
|
|
|
0
|
0
|
|
my ( $self, $pos ) = @_; |
99
|
0
|
|
|
|
|
|
$self->{__current_pos} = $pos; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub close { |
103
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
delete $self->{__current_pos}; |
106
|
0
|
|
|
|
|
|
delete $self->{__file}; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |