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:
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

View file

@ -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)})

View file

@ -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)))

View file

@ -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
}