From 2c881d8091c28152799464ed43004e6ba9066e31 Mon Sep 17 00:00:00 2001 From: Matteo Suppo Date: Mon, 11 Jan 2016 15:48:34 +0100 Subject: [PATCH 1/3] Add template for other browsers than firefox --- certificates.go | 19 +++++++++++++++++++ main.go | 7 ++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/certificates.go b/certificates.go index 23354972e..a6d0e09f2 100644 --- a/certificates.go +++ b/certificates.go @@ -21,9 +21,11 @@ import ( "net" "os" "strings" + "text/template" "time" log "github.com/Sirupsen/logrus" + "github.com/gin-gonic/gin" ) var ( @@ -215,3 +217,20 @@ func generateCertificates() { log.Print("written cert.cer") } + +func certHandler(c *gin.Context) { + if strings.Contains(c.Request.UserAgent(), "Firefox") { + c.Header("content-type", "application/x-x509-ca-cert") + c.File("ca.cert.cer") + return + } + noFirefoxTemplate.Execute(c.Writer, c.Request.Host) +} + +const noFirefoxTemplateHTML = ` + + + +` + +var noFirefoxTemplate = template.Must(template.New("home").Parse(noFirefoxTemplateHTML)) diff --git a/main.go b/main.go index e042ab288..e04ba5477 100755 --- a/main.go +++ b/main.go @@ -75,11 +75,6 @@ func launchSelfLater() { log.Println("Done waiting 2 secs. Now launching...") } -func certHandler(c *gin.Context) { - c.Header("content-type", "application/x-x509-ca-cert") - c.File("cert.cer") -} - func main() { flag.Parse() @@ -236,6 +231,8 @@ func main() { ValidateHeaders: false, })) + r.LoadHTMLFiles("templates/nofirefox.html") + r.GET("/", homeHandler) r.GET("/certificate.crt", certHandler) r.POST("/upload", uploadHandler) From c0647b9d96217dc4ee5f31910ea421b8a968d0f7 Mon Sep 17 00:00:00 2001 From: Matteo Suppo Date: Mon, 11 Jan 2016 17:24:45 +0100 Subject: [PATCH 2/3] Add page for wrong browser --- certificates.go | 100 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 2 deletions(-) diff --git a/certificates.go b/certificates.go index a6d0e09f2..15b5af94e 100644 --- a/certificates.go +++ b/certificates.go @@ -224,13 +224,109 @@ func certHandler(c *gin.Context) { c.File("ca.cert.cer") return } - noFirefoxTemplate.Execute(c.Writer, c.Request.Host) + noFirefoxTemplate.Execute(c.Writer, gin.H{ + "url": "http://" + c.Request.Host + c.Request.URL.String(), + }) } const noFirefoxTemplateHTML = ` + + + + + + +
+

Oops, this is not Firefox

+
+ +
+

You need to open this link in Firefox to trust this certificate: {{.host}}{{.url}}

+
+ + +` var noFirefoxTemplate = template.Must(template.New("home").Parse(noFirefoxTemplateHTML)) From 62d461f8595cebe6d684f600dc9d186baadd5db8 Mon Sep 17 00:00:00 2001 From: Matteo Suppo Date: Mon, 11 Jan 2016 17:26:49 +0100 Subject: [PATCH 3/3] Change padding --- certificates.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/certificates.go b/certificates.go index 15b5af94e..bfa4d11ac 100644 --- a/certificates.go +++ b/certificates.go @@ -260,7 +260,7 @@ body { height: auto; margin: 0 auto; min-width: 600px; - padding: 0 4%; + padding: 2% 4%; position: relative; width: 65%; box-shadow: 0 0 10px 0 rgba(21,110,114,.8);