]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/websites/tools/tools/dmarc_reports/app.js
Add dmarc reports
[perso/Immae/Config/Nix.git] / modules / private / websites / tools / tools / dmarc_reports / app.js
1 const app = new Vue({
2 el: '#app',
3 data: {
4 info: null,
5 summaries: [],
6 selectedSummary: null,
7 filterGreen: true,
8 filterDomain: null,
9 filterOrg: null,
10 //filterDate: (new Date()).toISOString().substring(0, 7),
11 filterDate: null,
12 reverse: true,
13 },
14 created: async function () {
15 let that = this;
16
17 try {
18 this.info = await this.getInfo();
19 this.summaries = this.info.summaries;
20 } catch (error) {}
21 },
22 methods: {
23 filtered: function () {
24 let that = this;
25 let filtered = this.summaries.filter(function (summary) {
26 return (!that.filterGreen || that.getColor(summary) !== "lime")
27 && (!that.filterDomain || summary.domain === that.filterDomain)
28 && (!that.filterOrg || summary.org === that.filterOrg)
29 && (!that.filterDate || that.inDates(summary));
30 });
31 if (this.reverse) {
32 return filtered.reverse();
33 } else {
34 return filtered;
35 }
36 },
37 toggle: async function(summary) {
38 if (this.selectedSummary && this.selectedSummary.serial === summary.serial) {
39 this.selectedSummary = null;
40 } else {
41 if (!summary.details) {
42 summary.details = await this.getDetails(summary.serial);
43 }
44 this.selectedSummary = summary;
45 }
46 },
47 inDates: function(summary) {
48 if (!this.filterDate) { return true; }
49
50 let mindate = (new Date(summary.mindate)).toISOString().substring(0, 7);
51 let maxdate = (new Date(summary.maxdate)).toISOString().substring(0, 7);
52
53 return mindate === this.filterDate || maxdate === this.filterDate;
54 },
55 printDate: function (date) {
56 return (new Date(date)).toISOString();
57 },
58 getColor: function (element) {
59 if (element.dkimresult === "fail" && element.spfresult === "fail") {
60 return "red";
61 } else if (element.dkimresult === "fail" || element.spfresult === "fail") {
62 return "orange";
63 } else if (element.dkimresult === "pass" && element.spfresult === "pass") {
64 return "lime";
65 } else {
66 return "yellow";
67 }
68 },
69 getInfo: function (event) {
70 return fetch('api.php').then(function (response) {
71 if (response.status != 200) { return; }
72 return response.text().then(function (body) {
73 return JSON.parse(body);
74 });
75 });
76 },
77 getDetails: function (serial) {
78 return fetch(`api.php?serial=${serial}`).then(function (response) {
79 if (response.status != 200) { return; }
80 return response.text().then(function (body) {
81 return JSON.parse(body);
82 });
83 });
84 }
85 }
86 });