Skip to content

Commit

Permalink
script to calculate quickest breach alert
Browse files Browse the repository at this point in the history
  • Loading branch information
groovecoder committed Oct 8, 2018
1 parent ce75486 commit 5ba8b19
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions scripts/quickest-breach-alerts.js
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);
})();

0 comments on commit 5ba8b19

Please sign in to comment.