From 026bca5078923cdff79eeab3aa75e845af840448 Mon Sep 17 00:00:00 2001 From: Paul Fournet Date: Mon, 4 Apr 2022 12:54:20 +0000 Subject: [PATCH 1/3] add: client MTU settings available from command line --- main.go | 6 +++++- util/config.go | 1 + util/util.go | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 9f2af3c..c62f0b9 100644 --- a/main.go +++ b/main.go @@ -3,10 +3,11 @@ package main import ( "flag" "fmt" - "github.com/labstack/echo/v4" "net/http" "time" + "github.com/labstack/echo/v4" + rice "github.com/GeertJohan/go.rice" "github.com/ngoduykhanh/wireguard-ui/emailer" "github.com/ngoduykhanh/wireguard-ui/handler" @@ -34,6 +35,7 @@ var ( flagEmailFrom string flagEmailFromName string = "WireGuard UI" flagSessionSecret string + flagClientMTU int ) const ( @@ -60,6 +62,7 @@ func init() { 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(&flagSessionSecret, "session-secret", util.LookupEnvOrString("SESSION_SECRET", flagSessionSecret), "The key used to encrypt session cookies.") + flag.IntVar(&flagClientMTU, "client-mtu", util.LookupEnvOrInt("CLIENT_MTU", flagClientMTU), "Client default MTU") flag.Parse() // update runtime config @@ -75,6 +78,7 @@ func init() { util.EmailFrom = flagEmailFrom util.EmailFromName = flagEmailFromName util.SessionSecret = []byte(flagSessionSecret) + util.ClientMTU = flagClientMTU // print app information fmt.Println("Wireguard UI") diff --git a/util/config.go b/util/config.go index 80cbc9c..8910f72 100644 --- a/util/config.go +++ b/util/config.go @@ -16,6 +16,7 @@ var ( EmailSubject string EmailContent string SessionSecret []byte + ClientMTU int ) const ( diff --git a/util/util.go b/util/util.go index 7c347a9..84bbefb 100644 --- a/util/util.go +++ b/util/util.go @@ -27,6 +27,10 @@ func BuildClientConfig(client model.Client, server model.Server, setting model.G if client.UseServerDNS { clientDNS = fmt.Sprintf("DNS = %s\n", strings.Join(setting.DNSServers, ",")) } + clientMTU := "" + if ClientMTU > 0 { + clientMTU = fmt.Sprintf("MTU = %d\n", ClientMTU) + } // Peer section peerPublicKey := fmt.Sprintf("PublicKey = %s\n", server.KeyPair.PublicKey) @@ -60,6 +64,7 @@ func BuildClientConfig(client model.Client, server model.Server, setting model.G clientAddress + clientPrivateKey + clientDNS + + clientMTU + "\n[Peer]\n" + peerPublicKey + peerPresharedKey + From c9a7bdf01899c819bbb4404a73c8a91147cdd033 Mon Sep 17 00:00:00 2001 From: Paul Fournet Date: Mon, 4 Apr 2022 13:44:15 +0000 Subject: [PATCH 2/3] add: default allowed-ips for new clients creations --- handler/routes.go | 2 +- main.go | 3 +++ model/misc.go | 1 + templates/base.html | 2 +- util/config.go | 1 + 5 files changed, 7 insertions(+), 2 deletions(-) diff --git a/handler/routes.go b/handler/routes.go index da7ecd2..c86cfb4 100644 --- a/handler/routes.go +++ b/handler/routes.go @@ -98,7 +98,7 @@ func WireGuardClients(db store.IStore) echo.HandlerFunc { } return c.Render(http.StatusOK, "clients.html", map[string]interface{}{ - "baseData": model.BaseData{Active: "", CurrentUser: currentUser(c)}, + "baseData": model.BaseData{Active: "", CurrentUser: currentUser(c), AllowedIPs: util.AllowedIPs}, "clientDataList": clientDataList, }) } diff --git a/main.go b/main.go index c62f0b9..9c5e3d4 100644 --- a/main.go +++ b/main.go @@ -36,6 +36,7 @@ var ( flagEmailFromName string = "WireGuard UI" flagSessionSecret string flagClientMTU int + flagAllowedIPs string ) const ( @@ -63,6 +64,7 @@ func init() { 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.IntVar(&flagClientMTU, "client-mtu", util.LookupEnvOrInt("CLIENT_MTU", flagClientMTU), "Client default MTU") + flag.StringVar(&flagAllowedIPs, "allowed-ips", util.LookupEnvOrString("ALLOWED_IPS", flagAllowedIPs), "List of default allowed IPs for the client") flag.Parse() // update runtime config @@ -79,6 +81,7 @@ func init() { util.EmailFromName = flagEmailFromName util.SessionSecret = []byte(flagSessionSecret) util.ClientMTU = flagClientMTU + util.AllowedIPs = flagAllowedIPs // print app information fmt.Println("Wireguard UI") diff --git a/model/misc.go b/model/misc.go index 12d6906..2574370 100644 --- a/model/misc.go +++ b/model/misc.go @@ -10,4 +10,5 @@ type Interface struct { type BaseData struct { Active string CurrentUser string + AllowedIPs string } diff --git a/templates/base.html b/templates/base.html index a161891..3adae78 100644 --- a/templates/base.html +++ b/templates/base.html @@ -175,7 +175,7 @@ + value="{{if .baseData.AllowedIPs}} {{.baseData.AllowedIPs}} {{else}} 0.0.0.0/0 {{end}}">
+
+ + +
+
+ + +
@@ -142,7 +152,17 @@ Global Settings const mtu = $("#mtu").val(); const persistent_keepalive = $("#persistent_keepalive").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 email_subject = $("#email_subject").val(); + const email_content = $("#email_content").val(); + const data = { + "endpoint_address": endpoint_address, + "dns_servers": dns_servers, + "mtu": mtu, + "persistent_keepalive": persistent_keepalive, + "config_file_path": config_file_path, + "email_subject": email_subject, + "email_content": email_content + }; $.ajax({ cache: false, @@ -255,4 +275,4 @@ Global Settings }); }); -{{end}} \ No newline at end of file +{{end}}