From 3fa9ff2b198333dcb93d80b007d8261a0caee62f Mon Sep 17 00:00:00 2001 From: Khanh Ngo Date: Sat, 20 Nov 2021 21:01:16 +0100 Subject: [PATCH] Make MTU and PersistentKeepalive optional --- templates/base.html | 22 +++++++++---------- templates/global_settings.html | 39 ++++++++++++++++++++++++++++------ templates/wg.conf | 2 +- util/util.go | 7 ++++-- 4 files changed, 50 insertions(+), 20 deletions(-) diff --git a/templates/base.html b/templates/base.html index 48fbf69..1202dab 100644 --- a/templates/base.html +++ b/templates/base.html @@ -44,17 +44,17 @@ -
-
- -
- -
-
-
+ + + + + + + + + + + +
+
+
+

Help

+
+ +
+
+
1. Endpoint Address
+
The public IP address of your Wireguard server that the client will connect to. Click on + Suggest button to auto detect the public IP address of your server.
+
2. DNS Servers
+
The DNS servers will be set to client config.
+
3. MTU
+
The MTU will be set to server config. By default it is 1420. You might want + to adjust the MTU size if your connection (e.g PPPoE, 3G, satellite network, etc) has a low MTU.
+
Leave blank to omit this setting in the Server config.
+
4. Persistent Keepalive
+
By default, WireGuard peers remain silent while they do not need to communicate, + so peers located behind a NAT and/or firewall may be unreachable from other peers + until they reach out to other peers themselves. Adding PersistentKeepalive + can ensure that the connection remains open.
+
Leave blank to omit this setting in the Client config.
+
5. Wireguard Config File Path
+
The path of your Wireguard server config file. Please make sure the parent directory + exists and is writable.
+
+
+
+ +
@@ -172,12 +203,10 @@ Global Settings $("#frm_global_settings").validate({ rules: { mtu: { - required: true, digits: true, range: [68, 65535] }, persistent_keepalive: { - required: true, digits: true }, config_file_path: { @@ -186,12 +215,10 @@ Global Settings }, messages: { mtu: { - required: "Please enter a MTU value", digits: "MTU must be an integer", range: "MTU must be in range 68..65535" }, persistent_keepalive: { - required: "Please enter a Persistent Keepalive value", digits: "Persistent keepalive must be an integer" }, config_file_path: { diff --git a/templates/wg.conf b/templates/wg.conf index 1e240b9..c3cc7c9 100644 --- a/templates/wg.conf +++ b/templates/wg.conf @@ -7,7 +7,7 @@ Address = {{$first :=true}}{{range .serverConfig.Interface.Addresses }}{{if $first}}{{$first = false}}{{else}},{{end}}{{.}}{{end}} ListenPort = {{ .serverConfig.Interface.ListenPort }} PrivateKey = {{ .serverConfig.KeyPair.PrivateKey }} -MTU = {{ .globalSettings.MTU }} +{{if .globalSettings.MTU}}MTU = {{ .globalSettings.MTU }}{{end}} PostUp = {{ .serverConfig.Interface.PostUp }} PostDown = {{ .serverConfig.Interface.PostDown }} diff --git a/util/util.go b/util/util.go index 1cde7ed..2269537 100644 --- a/util/util.go +++ b/util/util.go @@ -41,12 +41,15 @@ func BuildClientConfig(client model.Client, server model.Server, setting model.G if n, err := strconv.Atoi(split[1]); err == nil { desiredPort = n } else { - log.Error("Endpoint appears to be incorrectly formated: ", err) + log.Error("Endpoint appears to be incorrectly formatted: ", err) } } peerEndpoint := fmt.Sprintf("Endpoint = %s:%d", desiredHost, desiredPort) - peerPersistentKeepalive := fmt.Sprintf("PersistentKeepalive = %d", setting.PersistentKeepalive) + peerPersistentKeepalive := "" + if setting.PersistentKeepalive > 0 { + peerPersistentKeepalive = fmt.Sprintf("PersistentKeepalive = %d", setting.PersistentKeepalive) + } // build the config as string strConfig := "[Interface]\n" +