From 8b4038c238a4d6f39fe0998033cd380d0f5ff384 Mon Sep 17 00:00:00 2001 From: vx3r Date: Wed, 15 Jul 2020 15:52:16 +0900 Subject: [PATCH] bug issue #47 --- api/v1/server/server.go | 25 +++---------------------- core/server.go | 5 +++++ 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/api/v1/server/server.go b/api/v1/server/server.go index 158deb9..af9773c 100644 --- a/api/v1/server/server.go +++ b/api/v1/server/server.go @@ -6,7 +6,6 @@ import ( "gitlab.127-0-0-1.fr/vx3r/wg-gen-web/auth" "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/version" "golang.org/x/oauth2" "net/http" @@ -74,30 +73,12 @@ func updateServer(c *gin.Context) { } func configServer(c *gin.Context) { - clients, err := core.ReadClients() + configData, err := core.ReadWgConfigFile() 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) + }).Error("failed to read wg config file") + c.AbortWithStatus(http.StatusInternalServerError) return } diff --git a/core/server.go b/core/server.go index c2287f7..e78a2aa 100644 --- a/core/server.go +++ b/core/server.go @@ -168,3 +168,8 @@ func GetAllReservedIps() ([]string, error) { return reserverIps, nil } + +// ReadWgConfigFile return content of wireguard config file +func ReadWgConfigFile() ([]byte, error) { + return util.ReadFile(filepath.Join(os.Getenv("WG_CONF_DIR"), os.Getenv("WG_INTERFACE_NAME"))) +}