diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index ff33b6d..73df196 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -7,7 +7,7 @@ build-back:
stage: build artifacts
image: golang:latest
script:
- - GOOS=linux GOARCH=amd64 go build -ldflags="-X 'gitlab.127-0-0-1.fr/vx3r/wg-gen-web/util.Version=${CI_COMMIT_SHORT_SHA}'" -o ${CI_PROJECT_NAME}-linux-amd64
+ - GOOS=linux GOARCH=amd64 go build -ldflags="-X 'gitlab.127-0-0-1.fr/vx3r/wg-gen-web/util.Version=${CI_COMMIT_SHA}'" -o ${CI_PROJECT_NAME}-linux-amd64
artifacts:
paths:
- ${CI_PROJECT_NAME}-linux-amd64
@@ -29,7 +29,7 @@ build:
image: docker:latest
script:
- docker info
- - docker build --build-arg COMMIT=${CI_COMMIT_SHORT_SHA} --network br_docker --tag ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA} .
+ - docker build --build-arg COMMIT=${CI_COMMIT_SHA} --network br_docker --tag ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA} .
push:
stage: push docker hub
diff --git a/api/api.go b/api/api.go
index b527996..faa3648 100644
--- a/api/api.go
+++ b/api/api.go
@@ -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,
diff --git a/ui/src/App.vue b/ui/src/App.vue
index 86b54f8..2e2c620 100644
--- a/ui/src/App.vue
+++ b/ui/src/App.vue
@@ -28,7 +28,17 @@