diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-11-21 11:33:09 -0500 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-11-21 11:33:09 -0500 |
commit | b772eb66f2862fbecd6c9fd024381299baaabb66 (patch) | |
tree | c488de3394d11236a988fec484f664ea31bff9d2 | |
parent | ccb418c3a26fd687bfcd01cb42151f9507fcbe66 (diff) |
better time formatting/markup
-rw-r--r-- | crtsh-pem2html.go | 25 | ||||
-rw-r--r-- | tls-pem2html.go | 23 |
2 files changed, 37 insertions, 11 deletions
diff --git a/crtsh-pem2html.go b/crtsh-pem2html.go index 63249c3..f856ffb 100644 --- a/crtsh-pem2html.go +++ b/crtsh-pem2html.go @@ -28,8 +28,10 @@ func handleBool(ok bool, str string, a ...interface{}) { var tmpl = template.Must(template.New("pem2html"). Funcs(template.FuncMap{ - "red": red, - "green": green, + "red": red, + "green": green, + "time": fTime, + "datetime": fDateTime, }).Parse(`<!DOCTYPE html> <html lang="en"> <head> @@ -74,6 +76,9 @@ var tmpl = template.Must(template.New("pem2html"). height: 100%; color: black; } + time .time { + display: none + } </style> <script src="sorttable.js"></script> <base target="_parent" /> @@ -81,7 +86,7 @@ var tmpl = template.Must(template.New("pem2html"). <body> <table class=sortable> <caption> - <p>CT log (Updated {{.now.Local.Format "2006-01-02 15:04:05"}})</p> + <p>CT log (Updated {{.now | datetime}})</p> </caption> <tr> <th>Logged</th> @@ -92,9 +97,9 @@ var tmpl = template.Must(template.New("pem2html"). </tr> {{range $cert := .certs}} <tr> - <td style="background-color: {{$cert.Updated | green}}"><a target="_blank" href="{{$cert.Url}}">{{$cert.Updated.Local.Format "2006-01-02 15:04:05"}}</a></td> - <td><a target="_blank" href="{{$cert.Url}}">{{$cert.X509.NotBefore.Local.Format "2006-01-02"}}</a></td> - <td style="background-color: {{$cert.X509.NotAfter | red}}"><a target="_blank" href="{{$cert.Url}}">{{$cert.X509.NotAfter.Local.Format "2006-01-02"}}</a></td> + <td style="background-color: {{$cert.Updated | green}}"><a target="_blank" href="{{$cert.Url}}">{{$cert.Updated | datetime}}</a></td> + <td><a target="_blank" href="{{$cert.Url}}">{{$cert.X509.NotBefore | time}}</a></td> + <td style="background-color: {{$cert.X509.NotAfter | red}}"><a target="_blank" href="{{$cert.Url}}">{{$cert.X509.NotAfter | time}}</a></td> <td><a target="_blank" href="{{$cert.Url}}">{{$cert.X509.Subject.CommonName}}</a></td> <td><a target="_blank" href="{{$cert.Url}}">{{$cert.X509.Issuer.Organization}}</a></td> </tr> @@ -104,6 +109,14 @@ var tmpl = template.Must(template.New("pem2html"). </html> `)) +func fTime(t time.Time) template.HTML { + return template.HTML(t.Local().Format("<time datetime=\"2006-01-02 15:04:05\" title=\"2006-01-02 15:04:05\">2006-01-02 <span class=time>15:04:05</span></time>")) +} + +func fDateTime(t time.Time) template.HTML { + return template.HTML(t.Local().Format("<time datetime=\"2006-01-02 15:04:05\">2006-01-02 15:04:05</time>")) +} + func getNow() time.Time { stat, err := os.Stdin.Stat() if err == nil { diff --git a/tls-pem2html.go b/tls-pem2html.go index be93b44..6cecbf6 100644 --- a/tls-pem2html.go +++ b/tls-pem2html.go @@ -28,8 +28,10 @@ func handleBool(ok bool, str string, a ...interface{}) { var tmpl = template.Must(template.New("pem2html"). Funcs(template.FuncMap{ - "red": red, - "green": green, + "red": red, + "green": green, + "time": fTime, + "datetime": fDateTime, }).Parse(`<!DOCTYPE html> <html lang="en"> <head> @@ -77,6 +79,9 @@ var tmpl = template.Must(template.New("pem2html"). height: 100%; color: black; } + time .time { + display: none + } </style> <script src="sorttable.js"></script> <base target="_parent" /> @@ -84,7 +89,7 @@ var tmpl = template.Must(template.New("pem2html"). <body> <table class=sortable> <caption> - <p>Live Certs (Updated {{.now.Local.Format "2006-01-02 15:04:05"}})</p> + <p>Live Certs (Updated {{.now | datetime}})</p> </caption> <tr> <th>NotBefore</th> @@ -94,8 +99,8 @@ var tmpl = template.Must(template.New("pem2html"). </tr> {{range $cert := .certs}} <tr class="{{$cert.Class}}"> - <td style="background-color: {{$cert.X509.NotBefore | green}}"><a href="{{$cert.Url}}" title="{{$cert.Error}}">{{$cert.X509.NotBefore.Local.Format "2006-01-02"}}</a></td> - <td style="background-color: {{$cert.X509.NotAfter | red }}"><a href="{{$cert.Url}}" title="{{$cert.Error}}">{{$cert.X509.NotAfter.Local.Format "2006-01-02"}}</a></td> + <td style="background-color: {{$cert.X509.NotBefore | green}}"><a href="{{$cert.Url}}" title="{{$cert.Error}}">{{$cert.X509.NotBefore | time}}</a></td> + <td style="background-color: {{$cert.X509.NotAfter | red }}"><a href="{{$cert.Url}}" title="{{$cert.Error}}">{{$cert.X509.NotAfter | time}}</a></td> <td><a href="{{$cert.Url}}" title="{{$cert.Error}}">{{$cert.X509.Subject.CommonName | html}}</a></td> <td><a href="{{$cert.Url}}" title="{{$cert.Error}}">{{$cert.Socket | html}}</a></td> </tr> @@ -105,6 +110,14 @@ var tmpl = template.Must(template.New("pem2html"). </html> `)) +func fTime(t time.Time) template.HTML { + return template.HTML(t.Local().Format("<time datetime=\"2006-01-02 15:04:05\" title=\"2006-01-02 15:04:05\">2006-01-02 <span class=time>15:04:05</span></time>")) +} + +func fDateTime(t time.Time) template.HTML { + return template.HTML(t.Local().Format("<time datetime=\"2006-01-02 15:04:05\">2006-01-02 15:04:05</time>")) +} + func getNow() time.Time { stat, err := os.Stdin.Stat() if err == nil { |