forked from mozilla/blurts-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
script to calculate quickest breach alert
- Loading branch information
1 parent
ce75486
commit 5ba8b19
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"use strict"; | ||
|
||
const HIBP = require("../hibp"); | ||
|
||
// https://stackoverflow.com/a/8528531 | ||
function dhm(t){ | ||
const cd = 24 * 60 * 60 * 1000, | ||
ch = 60 * 60 * 1000, | ||
pad = (n) => { return n < 10 ? "0" + n : n; }; | ||
let d = Math.floor(t / cd), | ||
h = Math.floor( (t - d * cd) / ch), | ||
m = Math.round( (t - d * cd - h * ch) / 60000); | ||
if( m === 60 ){ | ||
h++; | ||
m = 0; | ||
} | ||
if( h === 24 ){ | ||
d++; | ||
h = 0; | ||
} | ||
return [d, pad(h), pad(m)].join(":"); | ||
} | ||
|
||
|
||
(async () => { | ||
const breaches = await HIBP.req("/breaches"); | ||
|
||
let fastestResponseTime = Math.abs(new Date() - new Date(0)); | ||
let fastestResponseBreach = ""; | ||
|
||
for (const breach of breaches.body) { | ||
console.log("checking response time for breach: ", breach.Name); | ||
const responseTime = Math.abs(new Date(breach.BreachDate) - new Date(breach.AddedDate)); | ||
if (responseTime < fastestResponseTime) { | ||
fastestResponseTime = responseTime; | ||
fastestResponseBreach = breach.Name; | ||
} | ||
} | ||
|
||
console.log("fastest breach response time (dd:hh:mm): ", dhm(Math.abs(fastestResponseTime))); | ||
console.log("on breach: ", fastestResponseBreach); | ||
})(); | ||
|