From e45ff32aca748b05e0f000daa7536b058d2da089 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 6 Feb 2017 18:02:11 -0500 Subject: Colorize the last-updated timestamps with JS. --- colordate.js | 40 ++++++++++++++++++++++++++++++++++++++++ crtsh-pem2html.go | 7 ++++++- index.html.gen | 1 + tls-pem2html.go | 7 ++++++- 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 colordate.js diff --git a/colordate.js b/colordate.js new file mode 100644 index 0000000..a228eb5 --- /dev/null +++ b/colordate.js @@ -0,0 +1,40 @@ +(function() { + // in milliseconds + var now = Date.now(); + var oneday = 1000*60*60*24; + + var mapTo = function(iRange, oRange, iPoint) { + var pct = (iPoint - iRange[0])/(iRange[1]-iRange[0]); + if (pct < 0) { + pct = 0; + } else if (pct > 1) { + pct = 1; + } + var oPoint = oRange[0] + (pct * (oRange[1]-oRange[0])); + return oPoint; + } + + + var rgb = function(r, g, b) { + return "rgb(" + Math.trunc(r) + "," + Math.trunc(g) + "," + Math.trunc(b) + ")"; + }; + + var date2color = function(t) { + var max = 0xF3; + var red = mapTo([now-oneday, now-(oneday/2)], + [max, 0], + t); + var green = mapTo([now-(oneday/2), now], + [0, max], + t); + return rgb(max-green, max-red, max-green-red); + }; + + var main = function() { + document.querySelectorAll('time.colordate').forEach(function(time) { + time.style.backgroundColor = date2color(Date.parse(time.dateTime)); + }); + }; + + document.addEventListener("DOMContentLoaded", main, false); +})(); diff --git a/crtsh-pem2html.go b/crtsh-pem2html.go index 0a64848..66961b1 100644 --- a/crtsh-pem2html.go +++ b/crtsh-pem2html.go @@ -32,9 +32,10 @@ var tmpl = template.Must(template.New("pem2html"). "green": green, "date": fDate, "datetime": fDateTime, + "colorDatetime": cDateTime, }).Parse(` @@ -65,6 +66,10 @@ func fDateTime(t time.Time) template.HTML { return template.HTML(t.Local().Format("")) } +func cDateTime(t time.Time) template.HTML { + return template.HTML(t.Local().Format("")) +} + func getNow() time.Time { stat, err := os.Stdin.Stat() if err == nil { diff --git a/index.html.gen b/index.html.gen index da0eae2..da0a0a7 100755 --- a/index.html.gen +++ b/index.html.gen @@ -7,6 +7,7 @@ echo 'Dashboard + diff --git a/tls-pem2html.go b/tls-pem2html.go index 8eb438c..5a9101e 100644 --- a/tls-pem2html.go +++ b/tls-pem2html.go @@ -32,9 +32,10 @@ var tmpl = template.Must(template.New("pem2html"). "green": green, "date": fDate, "datetime": fDateTime, + "colorDatetime": cDateTime, }).Parse(`
-

CT log (Updated {{.now | datetime}})

+

CT log (Updated {{.now | colorDatetime}})

Logged
@@ -61,6 +62,10 @@ func fDateTime(t time.Time) template.HTML { return template.HTML(t.Local().Format("")) } +func cDateTime(t time.Time) template.HTML { + return template.HTML(t.Local().Format("")) +} + func getNow() time.Time { stat, err := os.Stdin.Stat() if err == nil { -- cgit v1.2.3-2-g168b
-

Live Certs (Updated {{.now | datetime}})

+

Live Certs (Updated {{.now | colorDatetime}})

NotBefore