diff --git a/docker-compose.yaml b/docker-compose.yaml index 72da096..d8ba0a1 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -2,7 +2,8 @@ version: '3' services: wg: - image: ngoduykhanh/wireguard-ui:latest + #image: ngoduykhanh/wireguard-ui:latest + image: wgui:latest container_name: wgui ports: - 5000:5000 @@ -12,4 +13,4 @@ services: max-size: 50m volumes: - ./db:/app/db - - /etc/wireguard:/etc/wireguard +# - /etc/wireguard:/etc/wireguard diff --git a/handler/routes.go b/handler/routes.go index 7b0d689..274de90 100644 --- a/handler/routes.go +++ b/handler/routes.go @@ -3,6 +3,7 @@ package handler import ( "encoding/json" "fmt" + rice "github.com/GeertJohan/go.rice" "net/http" "strings" "time" @@ -429,7 +430,7 @@ func SuggestIPAllocation() echo.HandlerFunc { } // ApplyServerConfig handler to write config file and restart Wireguard server -func ApplyServerConfig() echo.HandlerFunc { +func ApplyServerConfig(tmplBox *rice.Box) echo.HandlerFunc { return func(c echo.Context) error { // access validation validSession(c) @@ -453,7 +454,7 @@ func ApplyServerConfig() echo.HandlerFunc { } // Write config file - err = util.WriteWireGuardServerConfig(server, clients, settings) + err = util.WriteWireGuardServerConfig(tmplBox, server, clients, settings) if err != nil { log.Error("Cannot apply server config: ", err) return c.JSON(http.StatusInternalServerError, jsonHTTPResponse{false, fmt.Sprintf("Cannot apply server config: %v", err)}) diff --git a/main.go b/main.go index 1004239..0d63700 100644 --- a/main.go +++ b/main.go @@ -41,7 +41,7 @@ func main() { app.POST("/global-settings", handler.GlobalSettingSubmit()) app.GET("/api/machine-ips", handler.MachineIPAddresses()) app.GET("/api/suggest-client-ips", handler.SuggestIPAllocation()) - app.GET("/api/apply-wg-config", handler.ApplyServerConfig()) + app.GET("/api/apply-wg-config", handler.ApplyServerConfig(tmplBox)) // servers other static files app.GET("/static/*", echo.WrapHandler(http.StripPrefix("/static/", assetHandler))) diff --git a/util/util.go b/util/util.go index 66142b6..7685ad5 100644 --- a/util/util.go +++ b/util/util.go @@ -313,15 +313,9 @@ func ValidateIPAllocation(serverAddresses []string, ipAllocatedList []string, ip } // WriteWireGuardServerConfig to write Wireguard server config. e.g. wg0.conf -func WriteWireGuardServerConfig(serverConfig model.Server, clientDataList []model.ClientData, globalSettings model.GlobalSetting) error { - // create go rice box for wireguard config - templateBox, err := rice.FindBox("../templates") - if err != nil { - return err - } - +func WriteWireGuardServerConfig(tmplBox *rice.Box, serverConfig model.Server, clientDataList []model.ClientData, globalSettings model.GlobalSetting) error { // read wg.conf template file to string - tmplWireguardConf, err := templateBox.String("wg.conf") + tmplWireguardConf, err := tmplBox.String("wg.conf") if err != nil { return err }