Skip to content

Commit

Permalink
Close #12: add html_static template
Browse files Browse the repository at this point in the history
  • Loading branch information
tierpod committed Apr 8, 2019
1 parent b41a7b3 commit 459953b
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Support output formats:

* **html** output file is the html, generated from template templates/html.gotmpl

* **html_static** output file is the html, generated from template templates/html_static.gotmpl

* **txt** output file is the plain text, generated from template templates/txt.gotmpl

* **json** output file is the json
Expand Down
4 changes: 2 additions & 2 deletions cmd/dmarc-report-converter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ func loadConfig(path string) (*config, error) {

// load and parse output file template
switch c.Output.Format {
case "txt", "html":
case "txt", "html", "html_static":
t := loadTemplate("./templates/" + c.Output.Format + ".gotmpl")
c.Output.template = t
case "json":
default:
return nil, fmt.Errorf("unknown template for format %v", c.Output.Format)
return nil, fmt.Errorf("unable to found template for format '%v' in templates folder", c.Output.Format)
}

if !c.Output.isStdout() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/dmarc-report-converter/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (o *output) do(d dmarc.Report) error {
switch o.cfg.Output.Format {
case "txt":
err = o.template(d)
case "html":
case "html", "html_static":
err = o.templateHTML(d)
case "json":
err = o.json(d)
Expand Down
140 changes: 140 additions & 0 deletions templates/html_static.gotmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap core CSS -->
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<style>
td.left-border, th.left-border
{
border-left: 1px solid #dee2e6;
}

.borderless td, .borderless th
{
border: none;
}

table.table.bottomless
{
margin-bottom: 0rem;
}
</style>
</head>

<body>
<p></p>
<div class="container">
<div class="row">
<div class="col">
<div class="card">
<div class="card-header">
DMARC Report, id {{.Report.ReportMetadata.ReportID}}
</div>
<div class="card-body">
<table class="table table-sm borderless bottomless">
<tbody>
<tr>
<td>Organization</td>
<td><a href="{{.Report.ReportMetadata.ExtraContactInfo}}">{{.Report.ReportMetadata.OrgName}}</a> ({{.Report.ReportMetadata.Email}})</td>
</tr>
<tr>
<td>Date range</td>
<td>since {{.Report.ReportMetadata.DateRange.Begin.UTC}} until {{.Report.ReportMetadata.DateRange.End.UTC}}</td>
</tr>
<tr>
<td>Policy published</td>
<td>{{.Report.PolicyPublished.Domain}}: p={{.Report.PolicyPublished.Policy}} sp={{.Report.PolicyPublished.SPolicy}} pct={{.Report.PolicyPublished.Pct}} adkim={{.Report.PolicyPublished.ADKIM}} aspf={{.Report.PolicyPublished.ASPF}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<p></p>
<div class="row">
<div class="col">
<center><span class="badge badge-success">passed {{ .Report.TotalPassed }}</span> <span class="badge badge-danger">failed {{ .Report.TotalFailed }}</span> <span class="badge">total {{ .Report.Total }}</span></center>
</div>
</div>
<p></p>
<div class="row">
<div class="col">
<table class="table table-bordered table-sm" id="items-table">
<thead>
<tr>
<th scope="col" colspan="3"></th>
<th scope="col" colspan="3" class="left-border">policy evaluated</th>
<th scope="col" colspan="4" class="left-border">auth results</th>
</tr>
<tr>
<th scope="col">ip</th>
<th scope="col" data-toggle="tooltip" title="ptr records">hostname</th>
<th scope="col" data-toggle="tooltip" title="messages count">msgs</th>
<th scope="col" class="left-border">disposition</th>
<th scope="col">DKIM</th>
<th scope="col">SPF</th>
<th scope="col" class="left-border">DKIM domain</th>
<th scope="col">result</th>
<th scope="col">SPF domain</th>
<th scope="col">result</th>
</tr>
</thead>
<tbody id="items-table">
{{- range .Report.Record }}
{{- if .IsPass }}
<tr class="policy-evaluated-result-pass table-success">
{{- else }}
<tr class="policy-evaluated-result-fail">
{{- end }}
<td id="ip">{{.Row.SourceIP}}</td>
<td id="hostname">{{.Row.SourceHostname}}</td>
<td id="msgc">{{.Row.Count}}</td>
<td class="left-border" title="identifiers&#13;header_from: {{.Identifiers.HeaderFrom}}&#13;envelope_from: {{.Identifiers.EnvelopeFrom}}">{{.Row.PolicyEvaluated.Disposition}}</td>
<td>
{{- if eq .Row.PolicyEvaluated.DKIM "fail" }}
<span class="badge badge-danger">{{.Row.PolicyEvaluated.DKIM}}</span>
{{- else }}
<span class="badge badge-success">{{.Row.PolicyEvaluated.DKIM}}</span>
{{- end}}
</td>
<td>
{{- if eq .Row.PolicyEvaluated.SPF "fail" }}
<span class="badge badge-danger">{{.Row.PolicyEvaluated.SPF}}</span>
{{- else }}
<span class="badge badge-success">{{.Row.PolicyEvaluated.SPF}}</span>
{{- end }}
</td>
<td class="left-border">{{.AuthResults.DKIM.Domain}}</td>
<td title="selector: {{.AuthResults.DKIM.Selector}}">
{{- if eq .AuthResults.DKIM.Result "pass"}}
<span class="badge badge-success">{{.AuthResults.DKIM.Result}}</span>
{{- else if eq .AuthResults.DKIM.Result "fail"}}
<span class="badge badge-danger">{{.AuthResults.DKIM.Result}}</span>
{{- else}}
<span class="badge badge-warning">{{.AuthResults.DKIM.Result}}</span>
{{- end}}
</td>
<td>{{.AuthResults.SPF.Domain}}</td>
<td title="scope: {{.AuthResults.SPF.Scope}}">
{{- if eq .AuthResults.SPF.Result "pass"}}
<span class="badge badge-success">{{.AuthResults.SPF.Result}}</span>
{{- else if eq .AuthResults.SPF.Result "fail"}}
<span class="badge badge-danger">{{.AuthResults.SPF.Result}}</span>
{{- else}}
<span class="badge badge-warning">{{.AuthResults.SPF.Result}}</span>
{{- end}}
</td>
</tr>
{{- end }}
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>

0 comments on commit 459953b

Please sign in to comment.