diff --git a/certificates.go b/certificates.go index 23354972e..bfa4d11ac 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,116 @@ 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, 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)) 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)