Skip to content

Commit 9c98fd1

Browse files
committed
added bin/dmarc_view_reports
1 parent f19a306 commit 9c98fd1

File tree

5 files changed

+92
-5
lines changed

5 files changed

+92
-5
lines changed

bin/dmarc_view_reports

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/perl
2+
use strict;
3+
use warnings;
4+
5+
use Data::Dumper;
6+
$|++;
7+
8+
use lib 'lib';
9+
use Mail::DMARC::Report::View::CLI;
10+
my $cli = Mail::DMARC::Report::View::CLI->new;
11+
12+
my $reports = $cli->store->retrieve;
13+
printf "%3s %20s %20s %15s\n", qw[ ID Recipient From/Sender Report-Start ];
14+
printf " | -- %3s %32s %13s %7s %7s %20s\n\n", 'Qty','Source IP','Disposition','DKIM','SPF';
15+
16+
foreach my $report ( reverse @$reports) {
17+
#warn Dumper($report);
18+
printf "%3s %20s %20s %15s\n", @$report{qw/ rid rcpt_domain from_domain begin /};
19+
my $rows = $cli->store->backend->get_row( rid => $report->{rid} )->{rows};
20+
foreach my $row ( @$rows ) {
21+
printf " | -- %3s %32s %13s %7s %7s", @$row{qw/ count source_ip disposition dkim spf /};
22+
foreach ( @{ $row->{reasons} } ) {
23+
print ' ' . $_->{type};
24+
print "( $_->{comment} )" if $_->{comment};
25+
};
26+
print "\n";
27+
#print Dumper($row);
28+
}
29+
print "\n";
30+
}
31+
32+
exit;
33+
34+
# PODNAME: dmarc_view_reports
35+
# ABSTRACT: view DMARC reports on the command line
36+
37+
=head1 SYNOPSIS
38+
39+
dmarc_view_reports | less
40+
41+
42+
=head1 DESCRIPTION
43+
44+
Dumps the contents of the DMARC data store to your terminal. The most recent records are show first.
45+
46+
47+
=head1 SAMPLE OUTPUT
48+
49+
50+
ID Recipient From/Sender Report-Start
51+
| -- Qty Source IP Disposition DKIM SPF
52+
53+
570 theartfarm.com simerson.net 2013-05-20 09:40:50
54+
| -- 1 75.126.200.152 quarantine fail fail
55+
56+
568 yeah.net tnpi.net 2013-05-21 09:00:00
57+
| -- 1 111.176.77.138 reject fail fail
58+
59+
567 126.com tnpi.net 2013-05-21 09:00:00
60+
| -- 1 49.73.135.125 reject fail fail
61+
62+
565 google.com mesick.us 2013-05-20 17:00:00
63+
| -- 88 208.75.177.101 none pass pass
64+
65+
564 google.com theartfarm.com 2013-05-20 17:00:00
66+
| -- 3 208.75.177.101 none pass pass
67+
68+
563 google.com lynboyer.com 2013-05-20 17:00:00
69+
| -- 1 2a00:1450:4010:c03::235 none pass fail forwarded
70+
| -- 12 208.75.177.101 none pass pass
71+
| -- 1 209.85.217.174 none pass fail forwarded
72+
73+
561 google.com simerson.net 2013-05-20 17:00:00
74+
| -- 1 208.75.177.101 none pass pass
75+
76+
560 google.com tnpi.net 2013-05-20 17:00:00
77+
| -- 1 208.75.177.101 none pass pass
78+
| -- 1 27.20.110.240 reject fail fail
79+
80+
559 hotmail.com lynboyer.com 2013-05-20 20:00:00
81+
| -- 6 208.75.177.101 none pass pass
82+
83+
=cut
84+

lib/Mail/DMARC.pm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,11 @@ This module can be used...
210210
211211
=over 4
212212
213-
by MTAs and filtering tools such as SpamAssassin to validate that incoming messages are aligned with the purported senders policies.
213+
by MTAs and filtering tools like SpamAssassin to validate that incoming messages are aligned with the purported senders policies.
214214
215-
by an email sender that wishes to receive DMARC reports from other mail servers.
215+
by email senders, to receive DMARC reports from other mail servers and display them via CLI and web interfaces.
216+
217+
by MTA operators to send DMARC reports to DMARC author domains.
216218
217219
=back
218220

lib/Mail/DMARC/Report/Store.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ __END__
4444
4545
=head1 DESCRIPTION
4646
47-
I struggled with choosing between a perl AnyDBM storage backend versus a SQL backend. I deployed with SQL because with a single SQL implementation, the user can choose from the wide availability of DBD drivers, including SQLite, MySQL, DBD (same as AnyDBM) and many others.
47+
I first toyed with perl's AnyDBM storage backend. I chose to deploy with SQL because with a single SQL implementation, the user can choose from the wide availability of DBD drivers, including SQLite, MySQL, DBD (same as AnyDBM) and many others.
4848
49-
Others might like an alternative. This layer of indirection allows someone to write a new Mail::DMARC::Report::Store::MyGreatDB module, update their config file, and not alter the innards of Mail::DMARC.
49+
Others might like an alternative. This layer of indirection allows someone to write a new Mail::DMARC::Report::Store::MyGreatDB module, update their config file, and not alter the innards of Mail::DMARC. Much.
5050
5151
=cut

lib/Mail/DMARC/Report/Store/SQL.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ sub get_row {
269269

270270
my $rows = $self->query($query, \@params);
271271
foreach ( @$rows ) {
272+
$_->{reasons} = $self->query('SELECT type,comment FROM report_record_reason WHERE report_record_id=?', [ $_->{id} ] );
272273
$_->{source_ip} = $self->any_inet_ntop( $_->{source_ip} );
273274
};
274275
return {

lib/Mail/DMARC/Report/View/CLI.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ sub new {
1515
sub list {
1616
my $self = shift;
1717
my $reports = $self->store->retrieve;
18-
foreach my $report (@$reports) {
18+
foreach my $report ( reverse @$reports) {
1919
printf "%3s %20s %20s %15s\n", @$report{qw/ rid rcpt_domain from_domain begin /};
2020
foreach my $row ( @{ $report->{rows} } ) {
2121
printf "\t%15s %6s %6s \n", @$row{qw/ disposition dkim spf /};

0 commit comments

Comments
 (0)