diff --git a/model/setting.go b/model/setting.go index a316172..e871591 100644 --- a/model/setting.go +++ b/model/setting.go @@ -10,6 +10,7 @@ type GlobalSetting struct { DNSServers []string `json:"dns_servers"` MTU int `json:"mtu,string"` PersistentKeepalive int `json:"persistent_keepalive,string"` + ForwardMark string `json:"forward_mark"` ConfigFilePath string `json:"config_file_path"` UpdatedAt time.Time `json:"updated_at"` } diff --git a/store/jsondb/jsondb.go b/store/jsondb/jsondb.go index 9088f54..643e5e5 100644 --- a/store/jsondb/jsondb.go +++ b/store/jsondb/jsondb.go @@ -90,6 +90,7 @@ func (o *JsonDB) Init() error { globalSetting.DNSServers = []string{util.DefaultDNS} globalSetting.MTU = util.DefaultMTU globalSetting.PersistentKeepalive = util.DefaultPersistentKeepalive + globalSetting.ForwardMark = util.DefaultForwardMark globalSetting.ConfigFilePath = util.DefaultConfigFilePath globalSetting.UpdatedAt = time.Now().UTC() o.conn.Write("server", "global_settings", globalSetting) diff --git a/templates/global_settings.html b/templates/global_settings.html index 81454dc..d3da9da 100644 --- a/templates/global_settings.html +++ b/templates/global_settings.html @@ -55,6 +55,12 @@ Global Settings name="persistent_keepalive" placeholder="Persistent Keepalive" value="{{if .globalSettings.PersistentKeepalive }}{{ .globalSettings.PersistentKeepalive }}{{end}}"> +
+ + +
-{{end}} \ No newline at end of file +{{end}} diff --git a/util/config.go b/util/config.go index 80cbc9c..4d2c05e 100644 --- a/util/config.go +++ b/util/config.go @@ -26,6 +26,7 @@ const ( DefaultDNS = "1.1.1.1" DefaultMTU = 1450 DefaultPersistentKeepalive = 15 + DefaultForwardMark = "0xca6c" DefaultConfigFilePath = "/etc/wireguard/wg0.conf" UsernameEnvVar = "WGUI_USERNAME" PasswordEnvVar = "WGUI_PASSWORD" diff --git a/util/util.go b/util/util.go index 7c347a9..3fe986d 100644 --- a/util/util.go +++ b/util/util.go @@ -55,11 +55,17 @@ func BuildClientConfig(client model.Client, server model.Server, setting model.G peerPersistentKeepalive = fmt.Sprintf("PersistentKeepalive = %d\n", setting.PersistentKeepalive) } + forwardMark := "" + if setting.ForwardMark != DefaultForwardMark { + forwardMark = fmt.Sprintf("FwMark = %s\n", setting.ForwardMark) + } + // build the config as string strConfig := "[Interface]\n" + clientAddress + clientPrivateKey + clientDNS + + forwardMark + "\n[Peer]\n" + peerPublicKey + peerPresharedKey +