Add ForwardMark to global settings

This commit is contained in:
Frank Ittermann 2022-03-21 21:50:00 +01:00
parent ad4ca4d9bb
commit f6720d2723
No known key found for this signature in database
GPG key ID: A9215275A11EAAC6
5 changed files with 21 additions and 2 deletions

View file

@ -10,6 +10,7 @@ type GlobalSetting struct {
DNSServers []string `json:"dns_servers"` DNSServers []string `json:"dns_servers"`
MTU int `json:"mtu,string"` MTU int `json:"mtu,string"`
PersistentKeepalive int `json:"persistent_keepalive,string"` PersistentKeepalive int `json:"persistent_keepalive,string"`
ForwardMark string `json:"forward_mark"`
ConfigFilePath string `json:"config_file_path"` ConfigFilePath string `json:"config_file_path"`
UpdatedAt time.Time `json:"updated_at"` UpdatedAt time.Time `json:"updated_at"`
} }

View file

@ -90,6 +90,7 @@ func (o *JsonDB) Init() error {
globalSetting.DNSServers = []string{util.DefaultDNS} globalSetting.DNSServers = []string{util.DefaultDNS}
globalSetting.MTU = util.DefaultMTU globalSetting.MTU = util.DefaultMTU
globalSetting.PersistentKeepalive = util.DefaultPersistentKeepalive globalSetting.PersistentKeepalive = util.DefaultPersistentKeepalive
globalSetting.ForwardMark = util.DefaultForwardMark
globalSetting.ConfigFilePath = util.DefaultConfigFilePath globalSetting.ConfigFilePath = util.DefaultConfigFilePath
globalSetting.UpdatedAt = time.Now().UTC() globalSetting.UpdatedAt = time.Now().UTC()
o.conn.Write("server", "global_settings", globalSetting) o.conn.Write("server", "global_settings", globalSetting)

View file

@ -55,6 +55,12 @@ Global Settings
name="persistent_keepalive" placeholder="Persistent Keepalive" name="persistent_keepalive" placeholder="Persistent Keepalive"
value="{{if .globalSettings.PersistentKeepalive }}{{ .globalSettings.PersistentKeepalive }}{{end}}"> value="{{if .globalSettings.PersistentKeepalive }}{{ .globalSettings.PersistentKeepalive }}{{end}}">
</div> </div>
<div class="form-group">
<label for="forward_mark">Forward Mark</label>
<input type="text" class="form-control" id="forward_mark"
name="forward_mark" placeholder="Forward Mark"
value="{{ .globalSettings.ForwardMark }}">
</div>
<div class="form-group"> <div class="form-group">
<label for="config_file_path">Wireguard Config File Path</label> <label for="config_file_path">Wireguard Config File Path</label>
<input type="text" class="form-control" id="config_file_path" <input type="text" class="form-control" id="config_file_path"
@ -141,8 +147,9 @@ Global Settings
const dns_servers = $("#dns_servers").val().split(","); const dns_servers = $("#dns_servers").val().split(",");
const mtu = $("#mtu").val(); const mtu = $("#mtu").val();
const persistent_keepalive = $("#persistent_keepalive").val(); const persistent_keepalive = $("#persistent_keepalive").val();
const forward_mark = $("#forward_mark").val();
const config_file_path = $("#config_file_path").val(); const config_file_path = $("#config_file_path").val();
const data = {"endpoint_address": endpoint_address, "dns_servers": dns_servers, "mtu": mtu, "persistent_keepalive": persistent_keepalive, "config_file_path": config_file_path}; const data = {"endpoint_address": endpoint_address, "dns_servers": dns_servers, "mtu": mtu, "persistent_keepalive": persistent_keepalive, "forward_mark": forward_mark, "config_file_path": config_file_path};
$.ajax({ $.ajax({
cache: false, cache: false,
@ -211,6 +218,9 @@ Global Settings
}, },
config_file_path: { config_file_path: {
required: true required: true
},
forward_mark: {
required: false
} }
}, },
messages: { messages: {
@ -255,4 +265,4 @@ Global Settings
}); });
}); });
</script> </script>
{{end}} {{end}}

View file

@ -26,6 +26,7 @@ const (
DefaultDNS = "1.1.1.1" DefaultDNS = "1.1.1.1"
DefaultMTU = 1450 DefaultMTU = 1450
DefaultPersistentKeepalive = 15 DefaultPersistentKeepalive = 15
DefaultForwardMark = "0xca6c"
DefaultConfigFilePath = "/etc/wireguard/wg0.conf" DefaultConfigFilePath = "/etc/wireguard/wg0.conf"
UsernameEnvVar = "WGUI_USERNAME" UsernameEnvVar = "WGUI_USERNAME"
PasswordEnvVar = "WGUI_PASSWORD" PasswordEnvVar = "WGUI_PASSWORD"

View file

@ -55,11 +55,17 @@ func BuildClientConfig(client model.Client, server model.Server, setting model.G
peerPersistentKeepalive = fmt.Sprintf("PersistentKeepalive = %d\n", setting.PersistentKeepalive) 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 // build the config as string
strConfig := "[Interface]\n" + strConfig := "[Interface]\n" +
clientAddress + clientAddress +
clientPrivateKey + clientPrivateKey +
clientDNS + clientDNS +
forwardMark +
"\n[Peer]\n" + "\n[Peer]\n" +
peerPublicKey + peerPublicKey +
peerPresharedKey + peerPresharedKey +