| 1 | package Mail::Milter::Authentication::Handler::AbusixDataFeed; | |||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | |||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | |||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Mail::Milter::Authentication 2.201811; | |||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use base 'Mail::Milter::Authentication::Handler'; | |||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||
| 6 | # ABSTRACT: Send data to Abusix | |||||||||||||||||||||||||||||||||
| 7 | 1 | our $VERSION = '2.20181203'; ## VERSION | ||||||||||||||||||||||||||||||||
| 8 | ||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use English qw{ -no_match_vars }; | |||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Sys::Syslog qw{:standard :macros}; | |||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Mail::DataFeed::Abusix; | |||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||
| 12 | ||||||||||||||||||||||||||||||||||
| 13 | sub default_config { | |||||||||||||||||||||||||||||||||
| 14 | return { | |||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | 'feed_name' => 'name_of_feed', | |||||||||||||||||||||||||||||||
|
Subroutine
default_config: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||
| 16 | 'feed_dest' => 'server:port', | |||||||||||||||||||||||||||||||||
| 17 | 'feed_key' => 'this_is_a_secret', | |||||||||||||||||||||||||||||||||
| 18 | 'listening_port' => '25', | |||||||||||||||||||||||||||||||||
| 19 | }; | |||||||||||||||||||||||||||||||||
| 20 | } | |||||||||||||||||||||||||||||||||
| 21 | ||||||||||||||||||||||||||||||||||
| 22 | sub helo_callback { | |||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | my ( $self, $helo_host ) = @_; | |||||||||||||||||||||||||||||||
|
Subroutine
helo_callback: called CC=1 SCAR=0.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||
| 24 | 1 | $self->{'helo_name'} = $helo_host; | ||||||||||||||||||||||||||||||||
| 25 | 1 | return; | ||||||||||||||||||||||||||||||||
| 26 | } | |||||||||||||||||||||||||||||||||
| 27 | ||||||||||||||||||||||||||||||||||
| 28 | sub envfrom_callback { | |||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | my ($self, $from) = @_; | |||||||||||||||||||||||||||||||
|
Subroutine
envfrom_callback: called CC=4 SCAR=13.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||
| 30 | 1 | my $config = $self->handler_config(); | ||||||||||||||||||||||||||||||||
| 31 | ||||||||||||||||||||||||||||||||||
| 32 | $self->{ 'abusix_feed' } = Mail::DataFeed::Abusix->new( | |||||||||||||||||||||||||||||||||
| 33 | 'feed_name' => $config->{ 'feed_name' }, | |||||||||||||||||||||||||||||||||
| 34 | 'feed_dest' => $config->{ 'feed_dest' }, | |||||||||||||||||||||||||||||||||
| 35 | 1 | 'feed_key' => $config->{ 'feed_key' }, | ||||||||||||||||||||||||||||||||
| 36 | ); | |||||||||||||||||||||||||||||||||
| 37 | 1 | $self->{ 'abusix_feed' }->mail_from_domain( $self->get_domain_from( $from ) ); | ||||||||||||||||||||||||||||||||
| 38 | 1 | $self->{ 'abusix_feed' }->helo( $self->{ 'helo_name' } ); | ||||||||||||||||||||||||||||||||
| 39 | 1 | $self->{ 'abusix_feed' }->port( $config->{ 'listening_port' } ); | ||||||||||||||||||||||||||||||||
| 40 | 1 | $self->{ 'abusix_feed' }->ip_address( $self->ip_address() ); | ||||||||||||||||||||||||||||||||
| 41 | ||||||||||||||||||||||||||||||||||
| 42 | 1 | delete $self->{ 'first_received' }; | ||||||||||||||||||||||||||||||||
| 43 | ||||||||||||||||||||||||||||||||||
| 44 | 1 | my $resolver = $self->get_object('resolver'); | ||||||||||||||||||||||||||||||||
| 45 | 1 | my @rdns; | ||||||||||||||||||||||||||||||||
| 46 | 1 | my $packet = $resolver->query( $self->ip_address(), 'PTR' ); | ||||||||||||||||||||||||||||||||
| 47 | 1 | ▶ | if ($packet) { | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||
| 48 | 1 | foreach my $rr ( $packet->answer ) { | ||||||||||||||||||||||||||||||||
| 49 | # We do not consider CNAMES here | |||||||||||||||||||||||||||||||||
| 50 | 1 | ▶ | if ( $rr->type eq "PTR" ) { | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||
| 51 | 1 | my $rdatastr = $rr->rdatastr; | ||||||||||||||||||||||||||||||||
| 52 | 1 | $rdatastr =~ s/\r//g; | ||||||||||||||||||||||||||||||||
| 53 | 1 | $rdatastr =~ s/\n//g; | ||||||||||||||||||||||||||||||||
| 54 | 1 | push @rdns, $rdatastr; | ||||||||||||||||||||||||||||||||
| 55 | } | |||||||||||||||||||||||||||||||||
| 56 | } | |||||||||||||||||||||||||||||||||
| 57 | } | |||||||||||||||||||||||||||||||||
| 58 | 1 | $self->{ 'abusix_feed' }->reverse_dns( join( ',', @rdns ) ); | ||||||||||||||||||||||||||||||||
| 59 | ||||||||||||||||||||||||||||||||||
| 60 | 1 | return; | ||||||||||||||||||||||||||||||||
| 61 | } | |||||||||||||||||||||||||||||||||
| 62 | ||||||||||||||||||||||||||||||||||
| 63 | sub header_callback { | |||||||||||||||||||||||||||||||||
| 64 | 3 | ▶ | my ( $self, $header, $value ) = @_; | |||||||||||||||||||||||||||||||
|
Subroutine
header_callback: called CC=4 SCAR=20.4
Pod
undocumented
| ||||||||||||||||||||||||||||||||||
| 65 | 3 | ▶ | return if defined $self->{ 'first_received' }; | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||
| 66 | 3 | ▶ | return if lc $header ne 'received'; | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||
| 67 | 0 | my $protocol = Mail::Milter::Authentication::Config::get_config()->{'protocol'}; | ||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | return if $protocol ne 'smtp'; | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||
| 69 | ||||||||||||||||||||||||||||||||||
| 70 | 0 | $self->{ 'first_received' } = $value; | ||||||||||||||||||||||||||||||||
| 71 | 0 | return; | ||||||||||||||||||||||||||||||||
| 72 | } | |||||||||||||||||||||||||||||||||
| 73 | ||||||||||||||||||||||||||||||||||
| 74 | sub eoh_callback { | |||||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | my ( $self ) = @_; | |||||||||||||||||||||||||||||||
|
Subroutine
eoh_callback: called CC=6 SCAR=29.3
Pod
undocumented
| ||||||||||||||||||||||||||||||||||
| 76 | 1 | $self->{ 'abusix_feed' }->used_tls( $self->is_encrypted() ); | ||||||||||||||||||||||||||||||||
| 77 | 1 | $self->{ 'abusix_feed' }->used_auth( $self->is_authenticated() ); | ||||||||||||||||||||||||||||||||
| 78 | 1 | ▶ | if ( defined $self->{ 'first_received' } ) { | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||
| 79 | 0 | my $used_smtp = $self->{ 'first_received' } =~ / with SMTP/; | ||||||||||||||||||||||||||||||||
| 80 | 0 | my $used_esmtp = $self->{ 'first_received' } =~ / with ESMTP/; | ||||||||||||||||||||||||||||||||
| 81 | 0 | warn " VALUES SMTP $used_smtp ESMTP $used_esmtp"; | ||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if ( $used_smtp xor $used_esmtp ) { | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/4
$used_smtp xor $used_esmtp
MC/DC0%0/2
$used_smtp xor $used_esmtp
$used_smtp
$used_esmtp
Truth table0%0/4
A xor B
A= $used_smtpB= $used_esmtp
| ||||||||||||||||||||||||||||||||||
| 83 | # Filters line noise! | |||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | $self->{ 'abusix_feed' }->used_esmtp( 1 ) if $used_esmtp; | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | $self->{ 'abusix_feed' }->used_esmtp( 0 ) if $used_smtp; | |||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||
| 86 | } | |||||||||||||||||||||||||||||||||
| 87 | } | |||||||||||||||||||||||||||||||||
| 88 | 1 | $self->{ 'abusix_feed' }->send(); | ||||||||||||||||||||||||||||||||
| 89 | 1 | return; | ||||||||||||||||||||||||||||||||
| 90 | } | |||||||||||||||||||||||||||||||||
| 91 | ||||||||||||||||||||||||||||||||||
| 92 | ||||||||||||||||||||||||||||||||||
| 93 | sub close_callback { | |||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | my ( $self ) = @_; | |||||||||||||||||||||||||||||||
|
Subroutine
close_callback: not called CC=1 SCAR=6.9
Pod
undocumented
| ||||||||||||||||||||||||||||||||||
| 95 | ||||||||||||||||||||||||||||||||||
| 96 | 0 | delete $self->{'helo_name'}; | ||||||||||||||||||||||||||||||||
| 97 | 0 | delete $self->{'abusix_feed'}; | ||||||||||||||||||||||||||||||||
| 98 | 0 | delete $self->{ 'first_received' }; | ||||||||||||||||||||||||||||||||
| 99 | 0 | return; | ||||||||||||||||||||||||||||||||
| 100 | } | |||||||||||||||||||||||||||||||||
| 101 | ||||||||||||||||||||||||||||||||||
| 102 | 1 | 1; | ||||||||||||||||||||||||||||||||
| 103 | ||||||||||||||||||||||||||||||||||
| 104 | __END__ | |||||||||||||||||||||||||||||||||
| 105 | ||||||||||||||||||||||||||||||||||
| 106 | =head1 NAME | |||||||||||||||||||||||||||||||||
| 107 | ||||||||||||||||||||||||||||||||||
| 108 | Authentication Milter - AbusixDataFeed Module | |||||||||||||||||||||||||||||||||
| 109 | ||||||||||||||||||||||||||||||||||
| 110 | =head1 DESCRIPTION | |||||||||||||||||||||||||||||||||
| 111 | ||||||||||||||||||||||||||||||||||
| 112 | Send data back to Abusix | |||||||||||||||||||||||||||||||||
| 113 | ||||||||||||||||||||||||||||||||||
| 114 | =head1 CONFIGURATION | |||||||||||||||||||||||||||||||||
| 115 | ||||||||||||||||||||||||||||||||||
| 116 | "AbusixDataFeed" : { | |||||||||||||||||||||||||||||||||
| 117 | "feed_name" : "id", | |||||||||||||||||||||||||||||||||
| 118 | "feed_dest" : "server:port", | |||||||||||||||||||||||||||||||||
| 119 | "feed_key" : "secret", | |||||||||||||||||||||||||||||||||
| 120 | "listening_port" : "25" | |||||||||||||||||||||||||||||||||
| 121 | }, | |||||||||||||||||||||||||||||||||
| 122 | ||||||||||||||||||||||||||||||||||
| 123 | =head1 SYNOPSIS | |||||||||||||||||||||||||||||||||
| 124 | ||||||||||||||||||||||||||||||||||
| 125 | =head1 AUTHORS | |||||||||||||||||||||||||||||||||
| 126 | ||||||||||||||||||||||||||||||||||
| 127 | Marc Bradshaw E<lt>marc@marcbradshaw.netE<gt> | |||||||||||||||||||||||||||||||||
| 128 | ||||||||||||||||||||||||||||||||||
| 129 | =head1 COPYRIGHT | |||||||||||||||||||||||||||||||||
| 130 | ||||||||||||||||||||||||||||||||||
| 131 | Copyright 2018 | |||||||||||||||||||||||||||||||||
| 132 | ||||||||||||||||||||||||||||||||||
| 133 | This library is free software; you may redistribute it and/or | |||||||||||||||||||||||||||||||||
| 134 | modify it under the same terms as Perl itself. | |||||||||||||||||||||||||||||||||
| 135 | ||||||||||||||||||||||||||||||||||
| 136 | ||||||||||||||||||||||||||||||||||
| 137 | ||||||||||||||||||||||||||||||||||