mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-04-19 19:59:13 +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
|
@ -33,6 +33,8 @@ wireguard interface stats. See the `cap_add` and `network_mode` options on the d
|
||||||
|
|
||||||
Set the `SESSION_SECRET` environment variable to a random value.
|
Set the `SESSION_SECRET` environment variable to a random value.
|
||||||
|
|
||||||
|
To use custom `wg.conf` template set the `WG_CONF_TEMPLATE` environment variable to a path to such file. Make sure `wireguard-ui` will be able to work with it - use [default template](templates/wg.conf) for reference.
|
||||||
|
|
||||||
In order to sent the wireguard configuration to clients via email, set the following environment variables:
|
In order to sent the wireguard configuration to clients via email, set the following environment variables:
|
||||||
|
|
||||||
- using SendGrid API
|
- using SendGrid API
|
||||||
|
|
|
@ -15,6 +15,7 @@ services:
|
||||||
- SESSION_SECRET
|
- SESSION_SECRET
|
||||||
- WGUI_USERNAME=alpha
|
- WGUI_USERNAME=alpha
|
||||||
- WGUI_PASSWORD=this-unusual-password
|
- WGUI_PASSWORD=this-unusual-password
|
||||||
|
- WG_CONF_TEMPLATE
|
||||||
logging:
|
logging:
|
||||||
driver: json-file
|
driver: json-file
|
||||||
options:
|
options:
|
||||||
|
|
4
main.go
4
main.go
|
@ -34,6 +34,7 @@ var (
|
||||||
flagEmailFrom string
|
flagEmailFrom string
|
||||||
flagEmailFromName string = "WireGuard UI"
|
flagEmailFromName string = "WireGuard UI"
|
||||||
flagSessionSecret string
|
flagSessionSecret string
|
||||||
|
flagWgConfTemplate string
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -60,6 +61,7 @@ func init() {
|
||||||
flag.StringVar(&flagEmailFrom, "email-from", util.LookupEnvOrString("EMAIL_FROM_ADDRESS", flagEmailFrom), "'From' email address.")
|
flag.StringVar(&flagEmailFrom, "email-from", util.LookupEnvOrString("EMAIL_FROM_ADDRESS", flagEmailFrom), "'From' email address.")
|
||||||
flag.StringVar(&flagEmailFromName, "email-from-name", util.LookupEnvOrString("EMAIL_FROM_NAME", flagEmailFromName), "'From' email name.")
|
flag.StringVar(&flagEmailFromName, "email-from-name", util.LookupEnvOrString("EMAIL_FROM_NAME", flagEmailFromName), "'From' email name.")
|
||||||
flag.StringVar(&flagSessionSecret, "session-secret", util.LookupEnvOrString("SESSION_SECRET", flagSessionSecret), "The key used to encrypt session cookies.")
|
flag.StringVar(&flagSessionSecret, "session-secret", util.LookupEnvOrString("SESSION_SECRET", flagSessionSecret), "The key used to encrypt session cookies.")
|
||||||
|
flag.StringVar(&flagWgConfTemplate, "wg-conf-template", util.LookupEnvOrString("WG_CONF_TEMPLATE", flagWgConfTemplate), "Path to custom wg.conf template.")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// update runtime config
|
// update runtime config
|
||||||
|
@ -75,6 +77,7 @@ func init() {
|
||||||
util.EmailFrom = flagEmailFrom
|
util.EmailFrom = flagEmailFrom
|
||||||
util.EmailFromName = flagEmailFromName
|
util.EmailFromName = flagEmailFromName
|
||||||
util.SessionSecret = []byte(flagSessionSecret)
|
util.SessionSecret = []byte(flagSessionSecret)
|
||||||
|
util.WgConfTemplate = flagWgConfTemplate
|
||||||
|
|
||||||
// print app information
|
// print app information
|
||||||
fmt.Println("Wireguard UI")
|
fmt.Println("Wireguard UI")
|
||||||
|
@ -89,6 +92,7 @@ func init() {
|
||||||
fmt.Println("Email from\t:", util.EmailFrom)
|
fmt.Println("Email from\t:", util.EmailFrom)
|
||||||
fmt.Println("Email from name\t:", util.EmailFromName)
|
fmt.Println("Email from name\t:", util.EmailFromName)
|
||||||
//fmt.Println("Session secret\t:", util.SessionSecret)
|
//fmt.Println("Session secret\t:", util.SessionSecret)
|
||||||
|
fmt.Println("Custom wg.conf\t:", util.WgConfTemplate)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ var (
|
||||||
EmailSubject string
|
EmailSubject string
|
||||||
EmailContent string
|
EmailContent string
|
||||||
SessionSecret []byte
|
SessionSecret []byte
|
||||||
|
WgConfTemplate string
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
17
util/util.go
17
util/util.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -359,11 +360,23 @@ 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(tmplBox *rice.Box, 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 {
|
||||||
// read wg.conf template file to string
|
var tmplWireguardConf string
|
||||||
tmplWireguardConf, err := tmplBox.String("wg.conf")
|
|
||||||
|
// if set, read wg.conf template from WgConfTemplate
|
||||||
|
if len(WgConfTemplate) > 0 {
|
||||||
|
fileContentBytes, err := ioutil.ReadFile(WgConfTemplate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
// parse the template
|
||||||
t, err := template.New("wg_config").Parse(tmplWireguardConf)
|
t, err := template.New("wg_config").Parse(tmplWireguardConf)
|
||||||
|
|
Loading…
Add table
Reference in a new issue