Return CA certificate on /cacert GET request
This commit is contained in:
parent
1116cd3e51
commit
47ebd58e4e
|
@ -8,6 +8,7 @@ import (
|
|||
"embed"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/spf13/viper"
|
||||
|
@ -26,16 +27,27 @@ func server() {
|
|||
listenPort = lPort
|
||||
}
|
||||
r := gin.Default()
|
||||
r.Static("/css", "./cmd/templates/css")
|
||||
LoadHTMLFromEmbedFS(r, templateFolder, "templates/*.html")
|
||||
r.Static("/css", "./cmd/templates/css")
|
||||
|
||||
r.GET("/", returnIndex)
|
||||
r.GET("/cacert", returnCacert)
|
||||
r.POST("/api/upload", getCert)
|
||||
|
||||
fmt.Printf("Listening on port %v...\n", listenPort)
|
||||
r.Run(":" + listenPort)
|
||||
}
|
||||
|
||||
func returnCacert(c *gin.Context) {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
e := fmt.Sprintf("Error happened fetching: %v\n", err)
|
||||
c.String(http.StatusInternalServerError, e)
|
||||
return
|
||||
}
|
||||
c.File(home + "/.config/cert400/ca.crt")
|
||||
}
|
||||
|
||||
func returnIndex(c *gin.Context) {
|
||||
c.HTML(http.StatusOK, "templates/index.html", gin.H{
|
||||
"UserAgent": c.Request.UserAgent(),
|
||||
|
|
Loading…
Reference in New Issue