Giter Site home page Giter Site logo

tierpod / dmarc-report-converter Goto Github PK

View Code? Open in Web Editor NEW
219.0 7.0 24.0 1.57 MB

Convert dmarc reports from xml to human-readable formats

License: MIT License

Makefile 2.12% Go 93.03% JavaScript 4.70% Shell 0.15%
dmarc dmarc-reports xml html imap golang dkim spf

dmarc-report-converter's Introduction

dmarc-report-converter

Convert DMARC report files from xml to human-readable formats. Files can be located on a local filesystem or on an IMAP server.

Example of html_static output: html

Support input formats:

  • .xml file: dmarc report in xml format

  • .gz file: gzipped dmarc report in xml format

  • .zip file: zipped dmarc report in xml format

  • .eml file: an electronic mail format or email saved in plain text - dovecot-report-converter tries to extract .xml, .gz or .zip attachments from found eml files to input.dir

Support output formats:

  • html_static output file is a HTML, generated from builtin template htmlStaticTmpl (consts.go). This format uses bootstrap hosted on bootstrapcdn, so you don't need to configure self-hosted bootsrap assets.

  • html output file is a HTML, generated from builtin template htmlTmpl (consts.go ). This format uses self-hosted bootsrap and javascript assets, so you need to configure your web server and output -> assets_path option.

  • txt output file is the plain text, generated from builtin template txtTmpl (consts.go).

  • json output file is the json, represents dmarc.Report struct.

  • external_template output file generated from external template file. Path to this file must be set with output -> external_template option. Builtin template txtTmpl (consts.go) can be used as example.

Installation

  1. Get installation archive. There are two ways: download pre-built archive from github releases page or build from sources

  2. Unpack to destination directory, for example to "/opt":

    sudo tar -xvf dmarc-report-converter*.tar.gz -C /opt
  3. Copy example config file and edit:

    cd /opt/dmarc-report-converter/
    sudo cp config.dist.yaml config.yaml
    sudo nano config.yaml
  4. If you want to use "html" output, you have to configure your web server to serve assets directory and change assets_path in configuration file. Example for nginx:

    sudo cp -r assets /usr/share/nginx/html

    config.yaml:

    output:
      assets_path: "/dmarc/assets"

    location configuration:

    location /dmarc/ {
        root /usr/share/nginx/html;
        autoindex           on;
        autoindex_localtime on;
    }

    and go to the http://your-web-server/dmarc

docker compose

There is a Docker Compose wrapper created by @nielsbom (thanks!):

https://github.com/nielsbom/dmarc_report_viewer

Configuration

Copy config/config.dist.yaml to config.yaml and change parameters:

  • lookup_addr (bool): perform reverse lookup? If enabled, may take some time.

  • lookup_limit (int): limit lookup pool size; must be positive; default = 50

  • merge_reports (bool): merge multiple similar reports to one?

  • merge_key (string): Go template string used to generate a key to merge reports. Only used when merge_reports is enabled. Default is {{ .ReportMetadata.OrgName }}!{{ .ReportMetadata.Email }}!{{ .PolicyPublished.Domain }}.

  • log_debug (bool): print debug log messages?

  • log_datetime (bool): add datetime to log messages?

input section:

  • dir (str): directory with input files

  • delete (bool): delete source files after conversion?

  • imap (optional section): dmarc-report-converter can fetch reports from IMAP server and save them to input -> dir before conversion started. To achieve this, configure this subsection.

    • server, username, password, mailbox (str): IMAP server address, credentials and mailbox name

    • delete (bool): delete email messages from IMAP server if reports are fetched successfully

    • debug (bool): print debug messages during IMAP session?

    • security (str): select encryption between "tls" (default), "starttls" or "plaintext"

output section:

  • file (str): output file, should be string or golang template. If value is empty string "" or "stdout", print result to stdout. Inside golang template any field from dmarc.Report struct can be used, or shortcuts .ID, .TodayID

  • format (str): output format (txt, json, html_static, html, external_template)

  • assets_path (str, optional for html format): path to assets for html output format.

  • external_template (str, mandatory for external_template format): path to external template file

Templates

External templates can reference to dmarc.Report struct as . (dot, see consts.go for example).

Additional functions can be used:

  • now "2006-2-1" returns current date and time, first argument is the golang time format.

Daily reports

If you want to convert reports daily:

  • Set input -> delete: yes and input -> imap -> delete: yes, because all old reports should be deleted from the source

  • Set merge_reports: no (do not merge any reports, use as-is)

  • Execute dmarc-report-converter every day (add daily crontab job or systemd timer):

    sudo cp install/dmarc-report-converter.sh /etc/cron.daily/
  • Use {{ .ID }} or {{ .TodayID }} shortcut in output -> file

Weekly or monthly reports

Many providers send reports to your email address every day. If you want to make weekly or monthly reports:

  • Set input -> delete: yes and input -> imap -> delete: yes, because all old reports should be deleted from the source

  • Set merge_reports: yes, because all similar reports should be merged

  • Execute dmarc-report-converter every week / month (add weekly / monthly crontab job or systemd timer)

  • Use {{ .TodayID }} shortcut in output -> file, if you want to create output file with current date in filename (instead of begin report date).

Building from sources

  1. Install go compiler and building tools:

    # debian/ubuntu
    sudo apt-get install golang-go make git tar
    
    # centos/fedora, enable epel-release repo first
    sudo yum install epel-release
    sudo yum install golang make git tar

    or follow official instruction

  2. Download sources:

    git clone https://github.com/tierpod/dmarc-report-converter.git
  3. Build binary and create installation archive:

    cd dmarc-report-converter
    make release
  4. Installation archive will be places inside dist directory. Also, if you want to test dmarc-report-converter without installation, you can execute:

    ./bin/dmarc-report-converter -config /path/to/config.yaml

Thanks

And we have a lot of contributors!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.