From d6353ee07536b78709d27baf69150eeda81af2ea Mon Sep 17 00:00:00 2001 From: Gilles Darold Date: Mon, 10 Dec 2018 17:21:41 +0100 Subject: [PATCH] Add new configuration directive RELAY_IP_ONLY to only store recipient or sender relay as Ip addresses. Actually when possible sendmailanalyzer extract the fqdn part of the relay not the Ip address. Enable this directive if you just want Ip addresses. --- Makefile.PL | 4 ++++ README | 5 +++++ doc/sendmailanalyzer.pod | 5 +++++ sendmailanalyzer | 17 +++++++++++------ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index 89e32d4..42b3140 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -356,6 +356,10 @@ NO_HOST_DOMAIN 0 # this directive to force sendmailanalyzer to take them as sent. NO_QUEUE_EXCLUSION 0 +# When possible sendmailanalyzer extract the fqdn part of the sender or +# recipient relay. Enable this directive if you just want Ip addresses. +RELAY_IP_ONLY 0 + }; close(OUTCFG); diff --git a/README b/README index 4605b14..cdecfe8 100644 --- a/README +++ b/README @@ -905,6 +905,11 @@ CONFIGURATION will exclude from report all recipient statistics sent to bcc-addr1@domain1.com and bcc-addr2@domain2.com + RELAY_IP_ONLY + When possible sendmailanalyzer extract the fqdn part of the sender + or recipient relay. Enable this directive if you just want Ip + addresses. + Domain / user views options LOW_LIMIT, MEDIUM_LIMIT, HIGH_LIMIT (NO MORE USED) User messaging data limit in megabytes to show/warn the level of diff --git a/doc/sendmailanalyzer.pod b/doc/sendmailanalyzer.pod index 87b7319..5f73aa8 100644 --- a/doc/sendmailanalyzer.pod +++ b/doc/sendmailanalyzer.pod @@ -1070,6 +1070,11 @@ in all destination adresses with $TO =~ /^$EXCLUDE_TO$/. For example: will exclude from report all recipient statistics sent to bcc-addr1@domain1.com and bcc-addr2@domain2.com +=item RELAY_IP_ONLY + +When possible sendmailanalyzer extract the fqdn part of the sender or +recipient relay. Enable this directive if you just want Ip addresses. + =back =head2 Domain / user views options diff --git a/sendmailanalyzer b/sendmailanalyzer index 849f999..d32d9d2 100755 --- a/sendmailanalyzer +++ b/sendmailanalyzer @@ -2290,18 +2290,22 @@ sub clean_relay if ($relay =~ m#\b([a-fA-F0-9\.\:]+) \(may be forged#) { $relay = $1; - } elsif ($relay =~ m#localhost|127\.0\.0\.1#) { + } elsif ($relay =~ m#localhost|127\.0\.0\.1|::1#) { return 'localhost'; } elsif ( $relay =~ s/\[([^\]]+)\]// ) { my $fqdn = $relay; my $ip = $1; - $fqdn =~ s#:.*##; - if (!$fqdn || ($fqdn eq 'unknown')) { - $relay = $ip; - } elsif ($fqdn =~ /[\s,]/) { + if ($CONFIG{RELAY_IP_ONLY}) { $relay = $ip; } else { - $relay = $fqdn; + $fqdn =~ s#:.*##; + if (!$fqdn || ($fqdn eq 'unknown')) { + $relay = $ip; + } elsif ($fqdn =~ /[\s,]/) { + $relay = $ip; + } else { + $relay = $fqdn; + } } } elsif ( $relay =~ s/\(([a-fA-F0-9\.\:]+)\)// ) { $relay = $1; @@ -2964,6 +2968,7 @@ sub read_config $CONFIG{POSTGREY_NAME} ||= 'postgrey|sqlgrey'; $CONFIG{SPAMD_NAME} ||= 'spamd'; $CONFIG{SPF_DKIM_NAME} ||= 'opendmarc|opendkim'; + $CONFIG{RELAY_IP_ONLY} ||= 0; } ####