0
0
mirror of https://github.com/vx3r/wg-gen-web.git synced 2025-09-11 12:24:27 +00:00

version link commit / download server wg conf

This commit is contained in:
vx3r
2020-03-06 11:43:32 +01:00
parent 8985021065
commit 0e3aef75b8
4 changed files with 71 additions and 30 deletions

View File

@ -6,6 +6,7 @@ import (
"github.com/skip2/go-qrcode"
"gitlab.127-0-0-1.fr/vx3r/wg-gen-web/core"
"gitlab.127-0-0-1.fr/vx3r/wg-gen-web/model"
"gitlab.127-0-0-1.fr/vx3r/wg-gen-web/template"
"gitlab.127-0-0-1.fr/vx3r/wg-gen-web/util"
"net/http"
)
@ -28,6 +29,7 @@ func ApplyRoutes(r *gin.Engine) {
{
server.GET("", readServer)
server.PATCH("", updateServer)
server.GET("/config", configServer)
server.GET("/version", version)
}
}
@ -203,6 +205,39 @@ func updateServer(c *gin.Context) {
c.JSON(http.StatusOK, client)
}
func configServer(c *gin.Context) {
clients, err := core.ReadClients()
if err != nil {
log.WithFields(log.Fields{
"err": err,
}).Error("failed to read clients")
c.AbortWithStatus(http.StatusUnprocessableEntity)
return
}
server, err := core.ReadServer()
if err != nil {
log.WithFields(log.Fields{
"err": err,
}).Error("failed to read server")
c.AbortWithStatus(http.StatusUnprocessableEntity)
return
}
configData, err := template.DumpServerWg(clients, server)
if err != nil {
log.WithFields(log.Fields{
"err": err,
}).Error("failed to dump wg config")
c.AbortWithStatus(http.StatusUnprocessableEntity)
return
}
// return config as txt file
c.Header("Content-Disposition", "attachment; filename=wg0.conf")
c.Data(http.StatusOK, "application/config", configData)
}
func version(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"version": util.Version,