diff options
Diffstat (limited to 'modules/private/websites/tools/tools/dmarc_reports/app.js')
-rw-r--r-- | modules/private/websites/tools/tools/dmarc_reports/app.js | 103 |
1 files changed, 0 insertions, 103 deletions
diff --git a/modules/private/websites/tools/tools/dmarc_reports/app.js b/modules/private/websites/tools/tools/dmarc_reports/app.js deleted file mode 100644 index 8e8a6c4..0000000 --- a/modules/private/websites/tools/tools/dmarc_reports/app.js +++ /dev/null | |||
@@ -1,103 +0,0 @@ | |||
1 | const app = new Vue({ | ||
2 | el: '#app', | ||
3 | data: { | ||
4 | info: null, | ||
5 | summaries: null, | ||
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 | anonymous: true, | ||
14 | }, | ||
15 | created: async function () { | ||
16 | let that = this; | ||
17 | |||
18 | if ('anonymous' in localStorage) { | ||
19 | this.anonymous = JSON.parse(localStorage.anonymous); | ||
20 | } | ||
21 | this.fetchAll(); | ||
22 | }, | ||
23 | methods: { | ||
24 | fetchAll: async function() { | ||
25 | try { | ||
26 | this.info = await this.getInfo(); | ||
27 | this.summaries = this.info.summaries; | ||
28 | } catch (error) { | ||
29 | this.info = null; | ||
30 | this.summaries = null; | ||
31 | } | ||
32 | }, | ||
33 | toggleAnonymous: function() { | ||
34 | this.anonymous = !this.anonymous; | ||
35 | localStorage.anonymous = this.anonymous; | ||
36 | this.fetchAll(); | ||
37 | }, | ||
38 | filtered: function () { | ||
39 | let that = this; | ||
40 | let filtered = this.summaries.filter(function (summary) { | ||
41 | return (!that.filterGreen || that.getColor(summary) !== "lime") | ||
42 | && (!that.filterDomain || summary.domain === that.filterDomain) | ||
43 | && (!that.filterOrg || summary.org === that.filterOrg) | ||
44 | && (!that.filterDate || that.inDates(summary)); | ||
45 | }); | ||
46 | if (this.reverse) { | ||
47 | return filtered.reverse(); | ||
48 | } else { | ||
49 | return filtered; | ||
50 | } | ||
51 | }, | ||
52 | toggle: async function(summary) { | ||
53 | if (this.selectedSummary && this.selectedSummary.serial === summary.serial) { | ||
54 | this.selectedSummary = null; | ||
55 | } else { | ||
56 | if (!summary.details) { | ||
57 | summary.details = await this.getDetails(summary.serial); | ||
58 | } | ||
59 | this.selectedSummary = summary; | ||
60 | } | ||
61 | }, | ||
62 | inDates: function(summary) { | ||
63 | if (!this.filterDate) { return true; } | ||
64 | |||
65 | let mindate = (new Date(summary.mindate)).toISOString().substring(0, 7); | ||
66 | let maxdate = (new Date(summary.maxdate)).toISOString().substring(0, 7); | ||
67 | |||
68 | return mindate === this.filterDate || maxdate === this.filterDate; | ||
69 | }, | ||
70 | printDate: function (date) { | ||
71 | return (new Date(date)).toISOString().replace("T", " ").replace(/\..*Z$/, " UTC"); | ||
72 | }, | ||
73 | getColor: function (element) { | ||
74 | if (element.dkimresult === "fail" && element.spfresult === "fail") { | ||
75 | return "red"; | ||
76 | } else if (element.dkimresult === "fail" || element.spfresult === "fail") { | ||
77 | return "orange"; | ||
78 | } else if (element.dkimresult === "pass" && element.spfresult === "pass") { | ||
79 | return "lime"; | ||
80 | } else { | ||
81 | return "yellow"; | ||
82 | } | ||
83 | }, | ||
84 | getInfo: function (event) { | ||
85 | let anonymous = this.anonymous ? "anonymous=1" : ""; | ||
86 | return fetch(`api.php?${anonymous}`).then(function (response) { | ||
87 | if (response.status != 200) { return; } | ||
88 | return response.text().then(function (body) { | ||
89 | return JSON.parse(body); | ||
90 | }); | ||
91 | }); | ||
92 | }, | ||
93 | getDetails: function (serial) { | ||
94 | let anonymous = this.anonymous ? "&anonymous=1" : ""; | ||
95 | return fetch(`api.php?serial=${serial}${anonymous}`).then(function (response) { | ||
96 | if (response.status != 200) { return; } | ||
97 | return response.text().then(function (body) { | ||
98 | return JSON.parse(body); | ||
99 | }); | ||
100 | }); | ||
101 | } | ||
102 | } | ||
103 | }); | ||