diff --git a/handler/routes.go b/handler/routes.go index 2d3509a..a2424d1 100644 --- a/handler/routes.go +++ b/handler/routes.go @@ -3,11 +3,12 @@ package handler import ( "encoding/json" "fmt" - rice "github.com/GeertJohan/go.rice" "net/http" "strings" "time" + rice "github.com/GeertJohan/go.rice" + "github.com/gorilla/sessions" "github.com/labstack/echo-contrib/session" "github.com/labstack/echo/v4" @@ -192,7 +193,6 @@ func NewClient() echo.HandlerFunc { client.HasPrivateSubnet = true } } - // write client to the database db.Write("clients", client.ID, client) @@ -256,6 +256,8 @@ func UpdateClient() echo.HandlerFunc { client.AllocatedIPs = _client.AllocatedIPs client.AllowedIPs = _client.AllowedIPs client.PrivateSubnets = _client.PrivateSubnets + client.PostUp = _client.PostUp + client.PostDown = _client.PostDown client.UpdatedAt = time.Now().UTC() client.HasPrivateSubnet = false diff --git a/model/client.go b/model/client.go index 923914a..afbeaaa 100644 --- a/model/client.go +++ b/model/client.go @@ -19,6 +19,8 @@ type Client struct { Enabled bool `json:"enabled"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` + PostUp string `json:"post_up"` + PostDown string `json:"post_down"` } // ClientData includes the Client and extra data diff --git a/templates/base.html b/templates/base.html index de8e298..07f9b15 100644 --- a/templates/base.html +++ b/templates/base.html @@ -157,6 +157,16 @@ +
+ + +
+
+ + +
@@ -279,6 +289,8 @@ const allocated_ips = $("#client_allocated_ips").val().split(","); const allowed_ips = $("#client_allowed_ips").val().split(","); const private_subnets = $("#client_private_subnets").val().split(","); + const post_up = $("#client_post_up").val(); + const post_down = $("#client_post_down").val(); let enabled = false; if ($("#enabled").is(':checked')){ @@ -286,7 +298,7 @@ } const data = {"name": name, "email": email, "allocated_ips": allocated_ips, "allowed_ips": allowed_ips, "private_subnets": private_subnets, - "enabled": enabled}; + "post_up": post_up, "post_down": post_down, "enabled": enabled}; $.ajax({ cache: false, diff --git a/templates/clients.html b/templates/clients.html index 8c8d526..ae80039 100644 --- a/templates/clients.html +++ b/templates/clients.html @@ -62,6 +62,14 @@ Wireguard Clients
+
+ + +
+
+ + +
@@ -312,6 +320,8 @@ Wireguard Clients modal.find("#_client_private_subnets").addTag(obj); }); + modal.find("#_client_post_up").val(client.post_up); + modal.find("#_client_post_down").val(client.post_down); modal.find("#_enabled").prop("checked", client.enabled); }, error: function (jqXHR, exception) { @@ -330,6 +340,8 @@ Wireguard Clients const allocated_ips = $("#_client_allocated_ips").val().split(","); const allowed_ips = $("#_client_allowed_ips").val().split(","); const private_subnets = $("#_client_private_subnets").val().split(","); + const post_up = $("#_client_post_up").val(); + const post_down = $("#_client_post_down").val(); let enabled = false; if ($("#_enabled").is(':checked')){ @@ -337,7 +349,7 @@ Wireguard Clients } const data = {"id": client_id, "name": name, "email": email, "allocated_ips": allocated_ips, "private_subnets": private_subnets, - "allowed_ips": allowed_ips, "enabled": enabled}; + "allowed_ips": allowed_ips, "post_up": post_up, "post_down": post_down, "enabled": enabled}; $.ajax({ cache: false, diff --git a/util/util.go b/util/util.go index 027e0fa..230ca79 100644 --- a/util/util.go +++ b/util/util.go @@ -22,6 +22,8 @@ func BuildClientConfig(client model.Client, server model.Server, setting model.G clientAddress := fmt.Sprintf("Address = %s", strings.Join(client.AllocatedIPs, ",")) clientPrivateKey := fmt.Sprintf("PrivateKey = %s", client.PrivateKey) clientDNS := fmt.Sprintf("DNS = %s", strings.Join(setting.DNSServers, ",")) + clientPostUp := fmt.Sprintf("PostUp = %s", client.PostUp) + clientPostDown := fmt.Sprintf("PostDown = %s", client.PostDown) // Peer section peerPublicKey := fmt.Sprintf("PublicKey = %s", server.KeyPair.PublicKey) @@ -34,7 +36,9 @@ func BuildClientConfig(client model.Client, server model.Server, setting model.G strConfig := "[Interface]\n" + clientAddress + "\n" + clientPrivateKey + "\n" + - clientDNS + "\n\n" + + clientDNS + "\n" + + clientPostUp + "\n" + + clientPostDown + "\n\n" + "[Peer]" + "\n" + peerPublicKey + "\n" + peerPresharedKey + "\n" +