line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package POE::Component::IRC::Plugin::FTP::EasyUpload; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
296637
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.002'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
14
|
use Carp; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
74
|
|
9
|
1
|
|
|
1
|
|
5
|
use POE qw(Component::Net::FTP); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
10
|
1
|
|
|
1
|
|
439
|
use Devel::TakeHashArgs; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
11
|
1
|
|
|
1
|
|
5
|
use POE::Component::IRC::Plugin qw( :ALL ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1461
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
15
|
0
|
0
|
|
|
|
|
get_args_as_hash( \@_, \ my %args, { |
16
|
|
|
|
|
|
|
port => 21, |
17
|
|
|
|
|
|
|
timeout => 30, |
18
|
|
|
|
|
|
|
pub_uri => '', |
19
|
|
|
|
|
|
|
retries => 5, |
20
|
|
|
|
|
|
|
verbose_error => 1, |
21
|
|
|
|
|
|
|
tag => qr//, |
22
|
|
|
|
|
|
|
}, |
23
|
|
|
|
|
|
|
[ qw(host login pass) ], |
24
|
|
|
|
|
|
|
[ |
25
|
|
|
|
|
|
|
qw( host login pass obj_args timeout pub_uri debug |
26
|
|
|
|
|
|
|
retries tag port verbose_error unique |
27
|
|
|
|
|
|
|
) |
28
|
|
|
|
|
|
|
], |
29
|
|
|
|
|
|
|
) or croak $@; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
|
$args{pub_uri} = $args{host} |
33
|
|
|
|
|
|
|
unless defined $args{pub_uri}; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my $self = bless \%args, $class; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
return $self; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub PCI_register { |
41
|
0
|
|
|
0
|
0
|
|
my ($self, $irc) = @_; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
$self->{irc} = $irc; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
$irc->plugin_register( $self, 'USER', qw(privmsg notice) ); |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$self->{session_id} = POE::Session->create( |
48
|
|
|
|
|
|
|
object_states => [ |
49
|
|
|
|
|
|
|
$self => [qw(_start _processed _shutdown)], |
50
|
|
|
|
|
|
|
], |
51
|
|
|
|
|
|
|
)->ID(); |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
return 1; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
0
|
0
|
|
sub U_privmsg { my $self = shift; $self->_process( @_ ); } |
|
0
|
|
|
|
|
|
|
57
|
0
|
|
|
0
|
0
|
|
sub U_notice { my $self = shift; $self->_process( @_ ); } |
|
0
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _process { |
60
|
0
|
|
|
0
|
|
|
my ( $self, $irc, $out_ref ) = @_; |
61
|
0
|
0
|
|
|
|
|
$self->{debug} |
62
|
|
|
|
|
|
|
and carp "OUT: $$out_ref"; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
|
if ( my ( $file, $dir, $prefix ) = $$out_ref =~ /$self->{tag}/ ) { |
66
|
0
|
0
|
|
|
|
|
$prefix = '' |
67
|
|
|
|
|
|
|
unless defined $prefix; |
68
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
$self->{debug} |
70
|
|
|
|
|
|
|
and carp "[ file => $file, dir => $dir, prefix => $prefix ]"; |
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
|
$self->{poco}->process( { |
73
|
|
|
|
|
|
|
event => '_processed', |
74
|
|
|
|
|
|
|
session => $self->{session_id}, |
75
|
|
|
|
|
|
|
_out => $$out_ref, |
76
|
|
|
|
|
|
|
_try => 0, |
77
|
|
|
|
|
|
|
_prefix => $prefix, |
78
|
|
|
|
|
|
|
commands => [ |
79
|
|
|
|
|
|
|
{ new => [ |
80
|
|
|
|
|
|
|
$self->{host}, |
81
|
|
|
|
|
|
|
Timeout => $self->{timeout}, |
82
|
|
|
|
|
|
|
Port => $self->{port}, |
83
|
0
|
0
|
|
|
|
|
@{ $self->{obj_args} || [] }, |
|
|
0
|
|
|
|
|
|
84
|
|
|
|
|
|
|
], |
85
|
|
|
|
|
|
|
}, |
86
|
|
|
|
|
|
|
{ login => [ $self->{login}, $self->{pass} ] }, |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
defined $dir ? ( { cwd => [ $dir ] } ) : (), |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
$self->{unique} ? { put_unique => [ $file ] } |
91
|
|
|
|
|
|
|
: { put => [ $file ] }, |
92
|
|
|
|
|
|
|
], |
93
|
|
|
|
|
|
|
}, |
94
|
|
|
|
|
|
|
); |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
return PCI_EAT_ALL; |
97
|
|
|
|
|
|
|
} |
98
|
0
|
|
|
|
|
|
return PCI_EAT_NONE; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _processed { |
102
|
0
|
|
|
0
|
|
|
my ( $kernel, $self, $in_ref ) = @_[ KERNEL, OBJECT, ARG0 ]; |
103
|
0
|
|
|
|
|
|
my $out_message; |
104
|
0
|
0
|
|
|
|
|
if ( $in_ref->{is_error} ) { |
105
|
0
|
0
|
|
|
|
|
$self->{debug} |
106
|
|
|
|
|
|
|
and carp "FTP error on $in_ref->{error} command: " |
107
|
|
|
|
|
|
|
. $in_ref->{last_error}; |
108
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
|
if ( $self->{retries} < $in_ref->{_try}++ ) { |
110
|
0
|
0
|
|
|
|
|
$self->{debug} |
111
|
|
|
|
|
|
|
and carp "Retring after error [retry # $in_ref->{_try}]"; |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
delete @$in_ref{ qw(error responses) }; |
114
|
0
|
|
|
|
|
|
$self->{poco}->process( $in_ref ); |
115
|
0
|
|
|
|
|
|
return; |
116
|
|
|
|
|
|
|
} |
117
|
0
|
|
|
|
|
|
$in_ref->{last_error} =~ s/\n|\r//g; |
118
|
0
|
0
|
|
|
|
|
$out_message = $self->{verbose_error} |
119
|
|
|
|
|
|
|
? "[FTP Error: $in_ref->{last_error}]" |
120
|
|
|
|
|
|
|
: '[FTP Error]'; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
else { |
123
|
0
|
|
|
|
|
|
$out_message = $self->{pub_uri} |
124
|
|
|
|
|
|
|
. $in_ref->{_prefix} |
125
|
|
|
|
|
|
|
. $in_ref->{responses}[-1][0]; |
126
|
|
|
|
|
|
|
} |
127
|
0
|
|
|
|
|
|
$in_ref->{_out} =~ s/$self->{tag}/$out_message/g; |
128
|
0
|
|
|
|
|
|
$kernel->post( $self->{irc} => quote => $in_ref->{_out} ); |
129
|
0
|
|
|
|
|
|
return; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub PCI_unregister { |
133
|
0
|
|
|
0
|
0
|
|
my ($self, $irc) = @_; |
134
|
0
|
|
|
|
|
|
$poe_kernel->call( $self->{session_id} => '_shutdown' ); |
135
|
0
|
|
|
|
|
|
delete $self->{irc}; |
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
return 1; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub _start { |
141
|
0
|
|
|
0
|
|
|
my ( $kernel, $self ) = @_[KERNEL, OBJECT]; |
142
|
0
|
|
|
|
|
|
$self->{session_id} = $_[SESSION]->ID(); |
143
|
0
|
|
|
|
|
|
$kernel->refcount_increment( $self->{session_id}, __PACKAGE__ ); |
144
|
|
|
|
|
|
|
|
145
|
0
|
0
|
|
|
|
|
$self->{poco} = POE::Component::Net::FTP->spawn( |
146
|
|
|
|
|
|
|
$self->{debug} ? ( debug => $self->{debug} ) : () |
147
|
|
|
|
|
|
|
); |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
return; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub _shutdown { |
153
|
0
|
|
|
0
|
|
|
my ( $kernel, $self ) = @_[KERNEL, OBJECT]; |
154
|
0
|
|
|
|
|
|
$self->{poco}->shutdown; |
155
|
0
|
|
|
|
|
|
$kernel->alarm_remove_all(); |
156
|
0
|
|
|
|
|
|
$kernel->refcount_decrement( $self->{session_id}, __PACKAGE__ ); |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
return; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
1; |
162
|
|
|
|
|
|
|
__END__ |