line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::Milter::Authentication::Handler::AbusixDataFeed; |
2
|
2
|
|
|
2
|
|
1701
|
use 5.20.0; |
|
2
|
|
|
|
|
12
|
|
3
|
2
|
|
|
2
|
|
19
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
46
|
|
4
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
15
|
|
|
2
|
|
|
|
|
72
|
|
5
|
2
|
|
|
2
|
|
12
|
use Mail::Milter::Authentication::Pragmas; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
17
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Handler class for sending data to Abusix |
7
|
|
|
|
|
|
|
our $VERSION = '3.20230911'; # VERSION |
8
|
2
|
|
|
2
|
|
439
|
use base 'Mail::Milter::Authentication::Handler'; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
167
|
|
9
|
2
|
|
|
2
|
|
902
|
use Mail::DataFeed::Abusix 1.20200617.1; |
|
2
|
|
|
|
|
48125
|
|
|
2
|
|
|
|
|
2066
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub default_config { |
12
|
|
|
|
|
|
|
return { |
13
|
1
|
|
|
1
|
0
|
1341
|
'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
|
10
|
my ( $self, $helo_host ) = @_; |
22
|
6
|
|
|
|
|
29
|
$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
|
25
|
my ($self, $from) = @_; |
50
|
6
|
|
|
|
|
24
|
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
|
|
|
|
|
32
|
port => $config->{ 'listening_port' }, |
59
|
|
|
|
|
|
|
ip_address => $self->ip_address(), |
60
|
|
|
|
|
|
|
time => time(), |
61
|
|
|
|
|
|
|
}; |
62
|
|
|
|
|
|
|
|
63
|
6
|
|
|
|
|
73
|
delete $self->{ 'first_received' }; |
64
|
|
|
|
|
|
|
|
65
|
6
|
|
|
|
|
19
|
my $resolver = $self->get_object('resolver'); |
66
|
6
|
|
|
|
|
12
|
my @rdns; |
67
|
6
|
|
|
|
|
19
|
my $packet = $resolver->query( $self->ip_address(), 'PTR' ); |
68
|
6
|
100
|
|
|
|
1374
|
if ($packet) { |
69
|
1
|
|
|
|
|
5
|
foreach my $rr ( $packet->answer ) { |
70
|
|
|
|
|
|
|
# We do not consider CNAMES here |
71
|
1
|
50
|
|
|
|
13
|
if ( $rr->type eq "PTR" ) { |
72
|
1
|
|
|
|
|
27
|
my $rdstring = $rr->rdatastr; |
73
|
1
|
|
|
|
|
474
|
$rdstring =~ s/\r//g; |
74
|
1
|
|
|
|
|
2
|
$rdstring =~ s/\n//g; |
75
|
1
|
|
|
|
|
3
|
push @rdns, $rdstring; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
6
|
|
|
|
|
32
|
$self->{ 'abusix_feed' }->{'reverse_dns'} = join( ',', @rdns ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub header_callback { |
84
|
22
|
|
|
22
|
0
|
50
|
my ( $self, $header, $value ) = @_; |
85
|
22
|
100
|
|
|
|
57
|
return if defined $self->{ 'first_received' }; |
86
|
10
|
100
|
|
|
|
37
|
return if lc $header ne 'received'; |
87
|
4
|
|
|
|
|
14
|
my $protocol = Mail::Milter::Authentication::Config::get_config()->{'protocol'}; |
88
|
4
|
50
|
|
|
|
12
|
return if $protocol ne 'smtp'; |
89
|
|
|
|
|
|
|
|
90
|
4
|
|
|
|
|
10
|
$self->{ 'first_received' } = $value; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub eoh_callback { |
94
|
6
|
|
|
6
|
0
|
14
|
my ( $self ) = @_; |
95
|
6
|
100
|
|
|
|
17
|
if ( $self->is_handler_loaded('TLS') ) { |
96
|
4
|
|
100
|
|
|
13
|
$self->{ 'abusix_feed' }->{'used_tls'} = $self->is_encrypted() || 0; # Explicit 0 over undef if TLS handler is loaded |
97
|
|
|
|
|
|
|
} |
98
|
6
|
|
|
|
|
22
|
$self->{ 'abusix_feed' }->{'used_auth'} = $self->is_authenticated(); |
99
|
6
|
100
|
|
|
|
22
|
if ( defined $self->{ 'first_received' } ) { |
100
|
4
|
|
|
|
|
13
|
my $used_smtp = $self->{ 'first_received' } =~ / with SMTP/; |
101
|
4
|
|
|
|
|
16
|
my $used_esmtp = $self->{ 'first_received' } =~ / with ESMTP/; |
102
|
4
|
50
|
50
|
|
|
16
|
if ( $used_smtp xor $used_esmtp ) { |
103
|
|
|
|
|
|
|
# Filters line noise! |
104
|
4
|
100
|
|
|
|
18
|
$self->{ 'abusix_feed' }->{'used_esmtp'} = 1 if $used_esmtp; |
105
|
4
|
100
|
|
|
|
11
|
$self->{ 'abusix_feed' }->{'used_esmtp'} = 0 if $used_smtp; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
6
|
|
|
|
|
25
|
$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.20230911 |
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 |