line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::Milter::Authentication::Handler::AbusixDataFeed; |
2
|
2
|
|
|
2
|
|
1755
|
use 5.20.0; |
|
2
|
|
|
|
|
11
|
|
3
|
2
|
|
|
2
|
|
14
|
use strict; |
|
2
|
|
|
|
|
17
|
|
|
2
|
|
|
|
|
41
|
|
4
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
50
|
|
5
|
2
|
|
|
2
|
|
14
|
use Mail::Milter::Authentication::Pragmas; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
19
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Handler class for sending data to Abusix |
7
|
|
|
|
|
|
|
our $VERSION = '3.20230629'; # VERSION |
8
|
2
|
|
|
2
|
|
506
|
use base 'Mail::Milter::Authentication::Handler'; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
215
|
|
9
|
2
|
|
|
2
|
|
1012
|
use Mail::DataFeed::Abusix 1.20200617.1; |
|
2
|
|
|
|
|
48449
|
|
|
2
|
|
|
|
|
2496
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub default_config { |
12
|
|
|
|
|
|
|
return { |
13
|
1
|
|
|
1
|
0
|
1629
|
'feed_name' => 'name_of_feed', |
14
|
|
|
|
|
|
|
'feed_dest' => 'server:port', |
15
|
|
|
|
|
|
|
'feed_key' => 'this_is_a_secret', |
16
|
|
|
|
|
|
|
'listening_port' => '25', |
17
|
|
|
|
|
|
|
}; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub helo_callback { |
21
|
6
|
|
|
6
|
0
|
31
|
my ( $self, $helo_host ) = @_; |
22
|
6
|
|
|
|
|
27
|
$self->{'helo_name'} = $helo_host; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub dequeue_callback { |
26
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
27
|
0
|
|
|
|
|
0
|
my $config = $self->handler_config(); |
28
|
0
|
|
|
|
|
0
|
my $dequeue_list = $self->get_dequeue_list('abusix_datafeed'); |
29
|
0
|
|
|
|
|
0
|
foreach my $id ( $dequeue_list->@* ) { |
30
|
0
|
|
|
|
|
0
|
eval { |
31
|
0
|
|
|
|
|
0
|
my $feed = $self->get_dequeue($id); |
32
|
0
|
0
|
|
|
|
0
|
if ( $feed ) { |
33
|
0
|
|
|
|
|
0
|
my $api = Mail::DataFeed::Abusix->new( $feed->%* ); |
34
|
0
|
|
|
|
|
0
|
$api->send; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
else { |
37
|
0
|
|
|
|
|
0
|
$self->log_error("AbusixDataFeed Report dequeue failed for $id"); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
}; |
40
|
0
|
0
|
|
|
|
0
|
if ( my $Error = $@ ) { |
41
|
0
|
|
|
|
|
0
|
$self->handle_exception( $Error ); |
42
|
0
|
|
|
|
|
0
|
$self->log_error( 'AbusixDataFeed Sending Error ' . $Error ); |
43
|
|
|
|
|
|
|
} |
44
|
0
|
|
|
|
|
0
|
$self->delete_dequeue($id); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub envfrom_callback { |
49
|
6
|
|
|
6
|
0
|
33
|
my ($self, $from) = @_; |
50
|
6
|
|
|
|
|
41
|
my $config = $self->handler_config(); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$self->{ 'abusix_feed' } = { |
53
|
|
|
|
|
|
|
feed_name => $config->{ 'feed_name' }, |
54
|
|
|
|
|
|
|
feed_dest => $config->{ 'feed_dest' }, |
55
|
|
|
|
|
|
|
feed_key => $config->{ 'feed_key' }, |
56
|
|
|
|
|
|
|
mail_from_domain => $self->get_domain_from( $from ), |
57
|
|
|
|
|
|
|
helo => $self->{ 'helo_name' }, |
58
|
6
|
|
|
|
|
50
|
port => $config->{ 'listening_port' }, |
59
|
|
|
|
|
|
|
ip_address => $self->ip_address(), |
60
|
|
|
|
|
|
|
time => time(), |
61
|
|
|
|
|
|
|
}; |
62
|
|
|
|
|
|
|
|
63
|
6
|
|
|
|
|
86
|
delete $self->{ 'first_received' }; |
64
|
|
|
|
|
|
|
|
65
|
6
|
|
|
|
|
32
|
my $resolver = $self->get_object('resolver'); |
66
|
6
|
|
|
|
|
15
|
my @rdns; |
67
|
6
|
|
|
|
|
28
|
my $packet = $resolver->query( $self->ip_address(), 'PTR' ); |
68
|
6
|
100
|
|
|
|
2094
|
if ($packet) { |
69
|
1
|
|
|
|
|
8
|
foreach my $rr ( $packet->answer ) { |
70
|
|
|
|
|
|
|
# We do not consider CNAMES here |
71
|
1
|
50
|
|
|
|
14
|
if ( $rr->type eq "PTR" ) { |
72
|
1
|
|
|
|
|
30
|
my $rdatastr = $rr->rdatastr; |
73
|
1
|
|
|
|
|
601
|
$rdatastr =~ s/\r//g; |
74
|
1
|
|
|
|
|
2
|
$rdatastr =~ s/\n//g; |
75
|
1
|
|
|
|
|
4
|
push @rdns, $rdatastr; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
6
|
|
|
|
|
55
|
$self->{ 'abusix_feed' }->{'reverse_dns'} = join( ',', @rdns ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub header_callback { |
84
|
22
|
|
|
22
|
0
|
402
|
my ( $self, $header, $value ) = @_; |
85
|
22
|
100
|
|
|
|
74
|
return if defined $self->{ 'first_received' }; |
86
|
10
|
100
|
|
|
|
65
|
return if lc $header ne 'received'; |
87
|
4
|
|
|
|
|
18
|
my $protocol = Mail::Milter::Authentication::Config::get_config()->{'protocol'}; |
88
|
4
|
50
|
|
|
|
19
|
return if $protocol ne 'smtp'; |
89
|
|
|
|
|
|
|
|
90
|
4
|
|
|
|
|
19
|
$self->{ 'first_received' } = $value; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub eoh_callback { |
94
|
6
|
|
|
6
|
0
|
18
|
my ( $self ) = @_; |
95
|
6
|
100
|
|
|
|
33
|
if ( $self->is_handler_loaded('TLS') ) { |
96
|
4
|
|
100
|
|
|
48
|
$self->{ 'abusix_feed' }->{'used_tls'} = $self->is_encrypted() || 0; # Explicit 0 over undef if TLS handler is loaded |
97
|
|
|
|
|
|
|
} |
98
|
6
|
|
|
|
|
38
|
$self->{ 'abusix_feed' }->{'used_auth'} = $self->is_authenticated(); |
99
|
6
|
100
|
|
|
|
29
|
if ( defined $self->{ 'first_received' } ) { |
100
|
4
|
|
|
|
|
18
|
my $used_smtp = $self->{ 'first_received' } =~ / with SMTP/; |
101
|
4
|
|
|
|
|
21
|
my $used_esmtp = $self->{ 'first_received' } =~ / with ESMTP/; |
102
|
4
|
50
|
50
|
|
|
22
|
if ( $used_smtp xor $used_esmtp ) { |
103
|
|
|
|
|
|
|
# Filters line noise! |
104
|
4
|
100
|
|
|
|
22
|
$self->{ 'abusix_feed' }->{'used_esmtp'} = 1 if $used_esmtp; |
105
|
4
|
100
|
|
|
|
15
|
$self->{ 'abusix_feed' }->{'used_esmtp'} = 0 if $used_smtp; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
6
|
|
|
|
|
39
|
$self->add_dequeue('abusix_datafeed',$self->{'abusix_feed'}); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub close_callback { |
113
|
0
|
|
|
0
|
0
|
|
my ( $self ) = @_; |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
delete $self->{'helo_name'}; |
116
|
0
|
|
|
|
|
|
delete $self->{'abusix_feed'}; |
117
|
0
|
|
|
|
|
|
delete $self->{ 'first_received' }; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
__END__ |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=pod |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=encoding UTF-8 |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 NAME |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Mail::Milter::Authentication::Handler::AbusixDataFeed - Handler class for sending data to Abusix |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 VERSION |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
version 3.20230629 |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 SYNOPSIS |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 DESCRIPTION |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Send data back to Abusix |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 NAME |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Authentication Milter - AbusixDataFeed Module |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 CONFIGURATION |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
"AbusixDataFeed" : { |
149
|
|
|
|
|
|
|
"feed_name" : "id", |
150
|
|
|
|
|
|
|
"feed_dest" : "server:port", |
151
|
|
|
|
|
|
|
"feed_key" : "secret", |
152
|
|
|
|
|
|
|
"listening_port" : "25" |
153
|
|
|
|
|
|
|
}, |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 AUTHORS |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Marc Bradshaw E<lt>marc@marcbradshaw.netE<gt> |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 COPYRIGHT |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Copyright 2018 |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
This library is free software; you may redistribute it and/or |
164
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 AUTHOR |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Marc Bradshaw <marc@marcbradshaw.net> |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
This software is copyright (c) 2020 by Marc Bradshaw. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
175
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=cut |