#!/usr/bin/perl 
use strict;
use warnings;

use Mail::DMARC;
use Mail::DMARC::HTTP;

my $dmarc = Mail::DMARC->new();
$dmarc->is_public_suffix('tnpi.net');
my $report = $dmarc->report;
my $http = Mail::DMARC::HTTP->new;
$http->dmarc_httpd($report);
exit;

__END__

=pod

=head1 NAME

dmarc_httpd: a web server for DMARC validation and report viewing

=head1 SYNOPSIS

A HTTP interface for:

=over 4

=item * local DMARC reports

=item * DMARC validator service

=back

Start the HTTP server:

    dmarc_httpd

Connect with a web browser to L<http://localhost:8080|http://localhost:8080/>.

=head1 DESCRIPTION

The HTTP server handles 4 types of requests:

=over 4

=item * /

Serves files stored in the perl share directory of the Mail::DMARC module.
This presently entails one HTML file and a handful of CSS and JS files for
the report viewing feature.

=item * /dmarc/json/validate - DMARC validation requests

Accepts a JSON encoded HTTP POST request. Validates the request, performs a
DMARC validation and returns a JSON encoded result object. This is the API
for non-perl applications to utilize Mail::DMARC.

See the dmarc_http_client app for a usage example.

=item * /dmarc/json/report

Accepts AJAX requests from the browser and returns JSON encoded DMARC reports.

=item * /dmarc/json/row

Accepts AJAX requests from the browser and returns JSON encoded DMARC report rows.

=back

An implementation that uses the http validation service is the included <dmarc_http_client> and another is the dmarc plugin in the <Haraka mail server|http://haraka.github.io>.

A L<Sample Report|http://search.cpan.org/dist/Mail-DMARC/example/report_cgi.png> is available which shows the web interface. It is implemented almost entirely in JavaScript, using jQuery, jQueryUI, and jqGrid.

Web server settings are in the [http] and [https] sections of mail-dmarc.ini.

=head1 THANKS

jQuery - http://www.jquery.com/

jqGrid - http://www.trirand.com/blog/

=head1 AUTHORS

=over 4

=item *

Matt Simerson <msimerson@cpan.org>

=item *

Davide Migliavacca <shari@cpan.org>

=item *

Marc Bradshaw <marc@marcbradshaw.net>

=back

=cut
