mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-05-23 00:15:19 +03:00
Custom wg conf template (#179)
This commit is contained in:
parent
ad4ca4d9bb
commit
100c4ee1f4
5 changed files with 25 additions and 4 deletions
|
@ -16,6 +16,7 @@ var (
|
|||
EmailSubject string
|
||||
EmailContent string
|
||||
SessionSecret []byte
|
||||
WgConfTemplate string
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
21
util/util.go
21
util/util.go
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
|
@ -359,10 +360,22 @@ func ValidateIPAllocation(serverAddresses []string, ipAllocatedList []string, ip
|
|||
|
||||
// WriteWireGuardServerConfig to write Wireguard server config. e.g. wg0.conf
|
||||
func WriteWireGuardServerConfig(tmplBox *rice.Box, serverConfig model.Server, clientDataList []model.ClientData, globalSettings model.GlobalSetting) error {
|
||||
// read wg.conf template file to string
|
||||
tmplWireguardConf, err := tmplBox.String("wg.conf")
|
||||
if err != nil {
|
||||
return err
|
||||
var tmplWireguardConf string
|
||||
|
||||
// if set, read wg.conf template from WgConfTemplate
|
||||
if len(WgConfTemplate) > 0 {
|
||||
fileContentBytes, err := ioutil.ReadFile(WgConfTemplate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tmplWireguardConf = string(fileContentBytes)
|
||||
} else {
|
||||
// read default wg.conf template file to string
|
||||
fileContent, err := tmplBox.String("wg.conf")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tmplWireguardConf = fileContent
|
||||
}
|
||||
|
||||
// parse the template
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue