Return CA certificate on /cacert GET request

This commit is contained in:
raul 2024-05-22 16:10:38 +02:00
parent 1116cd3e51
commit 47ebd58e4e
1 changed files with 13 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import (
"embed" "embed"
"fmt" "fmt"
"net/http" "net/http"
"os"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/spf13/viper" "github.com/spf13/viper"
@ -26,16 +27,27 @@ func server() {
listenPort = lPort listenPort = lPort
} }
r := gin.Default() r := gin.Default()
r.Static("/css", "./cmd/templates/css")
LoadHTMLFromEmbedFS(r, templateFolder, "templates/*.html") LoadHTMLFromEmbedFS(r, templateFolder, "templates/*.html")
r.Static("/css", "./cmd/templates/css")
r.GET("/", returnIndex) r.GET("/", returnIndex)
r.GET("/cacert", returnCacert)
r.POST("/api/upload", getCert) r.POST("/api/upload", getCert)
fmt.Printf("Listening on port %v...\n", listenPort) fmt.Printf("Listening on port %v...\n", listenPort)
r.Run(":" + 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) { func returnIndex(c *gin.Context) {
c.HTML(http.StatusOK, "templates/index.html", gin.H{ c.HTML(http.StatusOK, "templates/index.html", gin.H{
"UserAgent": c.Request.UserAgent(), "UserAgent": c.Request.UserAgent(),