Fix wg config template

This commit is contained in:
Khanh Ngo 2020-05-21 15:48:47 +07:00
parent 58f1bd65bb
commit d00d7bd8fe
No known key found for this signature in database
GPG key ID: D5FAA6A16150E49E
4 changed files with 9 additions and 13 deletions

View file

@ -2,7 +2,8 @@ version: '3'
services: services:
wg: wg:
image: ngoduykhanh/wireguard-ui:latest #image: ngoduykhanh/wireguard-ui:latest
image: wgui:latest
container_name: wgui container_name: wgui
ports: ports:
- 5000:5000 - 5000:5000
@ -12,4 +13,4 @@ services:
max-size: 50m max-size: 50m
volumes: volumes:
- ./db:/app/db - ./db:/app/db
- /etc/wireguard:/etc/wireguard # - /etc/wireguard:/etc/wireguard

View file

@ -3,6 +3,7 @@ package handler
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
rice "github.com/GeertJohan/go.rice"
"net/http" "net/http"
"strings" "strings"
"time" "time"
@ -429,7 +430,7 @@ func SuggestIPAllocation() echo.HandlerFunc {
} }
// ApplyServerConfig handler to write config file and restart Wireguard server // 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 { return func(c echo.Context) error {
// access validation // access validation
validSession(c) validSession(c)
@ -453,7 +454,7 @@ func ApplyServerConfig() echo.HandlerFunc {
} }
// Write config file // Write config file
err = util.WriteWireGuardServerConfig(server, clients, settings) err = util.WriteWireGuardServerConfig(tmplBox, server, clients, settings)
if err != nil { if err != nil {
log.Error("Cannot apply server config: ", err) log.Error("Cannot apply server config: ", err)
return c.JSON(http.StatusInternalServerError, jsonHTTPResponse{false, fmt.Sprintf("Cannot apply server config: %v", err)}) return c.JSON(http.StatusInternalServerError, jsonHTTPResponse{false, fmt.Sprintf("Cannot apply server config: %v", err)})

View file

@ -41,7 +41,7 @@ func main() {
app.POST("/global-settings", handler.GlobalSettingSubmit()) app.POST("/global-settings", handler.GlobalSettingSubmit())
app.GET("/api/machine-ips", handler.MachineIPAddresses()) app.GET("/api/machine-ips", handler.MachineIPAddresses())
app.GET("/api/suggest-client-ips", handler.SuggestIPAllocation()) 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 // servers other static files
app.GET("/static/*", echo.WrapHandler(http.StripPrefix("/static/", assetHandler))) app.GET("/static/*", echo.WrapHandler(http.StripPrefix("/static/", assetHandler)))

View file

@ -313,15 +313,9 @@ func ValidateIPAllocation(serverAddresses []string, ipAllocatedList []string, ip
} }
// WriteWireGuardServerConfig to write Wireguard server config. e.g. wg0.conf // WriteWireGuardServerConfig to write Wireguard server config. e.g. wg0.conf
func WriteWireGuardServerConfig(serverConfig model.Server, clientDataList []model.ClientData, globalSettings model.GlobalSetting) error { func WriteWireGuardServerConfig(tmplBox *rice.Box, 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
}
// read wg.conf template file to string // read wg.conf template file to string
tmplWireguardConf, err := templateBox.String("wg.conf") tmplWireguardConf, err := tmplBox.String("wg.conf")
if err != nil { if err != nil {
return err return err
} }