diff --git a/handler/routes.go b/handler/routes.go index 2fd146f..6b85e5b 100644 --- a/handler/routes.go +++ b/handler/routes.go @@ -331,6 +331,8 @@ func UpdateClient(db store.IStore) echo.HandlerFunc { client.AllocatedIPs = _client.AllocatedIPs client.AllowedIPs = _client.AllowedIPs client.ExtraAllowedIPs = _client.ExtraAllowedIPs + client.PostUp = _client.PostUp + client.PostDown = _client.PostDown client.UpdatedAt = time.Now().UTC() // write to the database diff --git a/model/client.go b/model/client.go index c1c7487..9609265 100644 --- a/model/client.go +++ b/model/client.go @@ -17,6 +17,8 @@ type Client struct { ExtraAllowedIPs []string `json:"extra_allowed_ips"` UseServerDNS bool `json:"use_server_dns"` Enabled bool `json:"enabled"` + PostUp string `json:"post_up"` + PostDown string `json:"post_down"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } diff --git a/templates/base.html b/templates/base.html index cf31d4d..28f5e84 100644 --- a/templates/base.html +++ b/templates/base.html @@ -186,6 +186,14 @@ +
+ + +
+
+ + +
@@ -343,6 +351,8 @@ const allowed_ips = $("#client_allowed_ips").val().split(","); let use_server_dns = false; let extra_allowed_ips = []; + const post_up = $("#client_post_up").val(); + const post_down = $("#client_post_down").val(); if ($("#client_extra_allowed_ips").val() !== "") { extra_allowed_ips = $("#client_extra_allowed_ips").val().split(","); @@ -362,8 +372,8 @@ const preshared_key = $("#client_preshared_key").val(); const data = {"name": name, "email": email, "allocated_ips": allocated_ips, "allowed_ips": allowed_ips, - "extra_allowed_ips": extra_allowed_ips, "use_server_dns": use_server_dns, "enabled": enabled, - "public_key": public_key, "preshared_key": preshared_key}; + "extra_allowed_ips": extra_allowed_ips, "post_up": post_up, "post_down": post_down, "use_server_dns": use_server_dns, + "enabled": enabled, "public_key": public_key, "preshared_key": preshared_key}; $.ajax({ cache: false, @@ -485,6 +495,8 @@ $("#client_preshared_key").val(""); $("#client_allocated_ips").importTags(''); $("#client_extra_allowed_ips").importTags(''); + $("#client_post_up").val(""); + $("#client_post_down").val(""); updateIPAllocationSuggestion(); }); }); diff --git a/templates/clients.html b/templates/clients.html index f7f3a1a..538782b 100644 --- a/templates/clients.html +++ b/templates/clients.html @@ -109,6 +109,14 @@ Wireguard Clients
+
+ + +
+
+ + +
@@ -365,6 +373,9 @@ Wireguard Clients modal.find("#_client_extra_allowed_ips").addTag(obj); }); + modal.find("#_client_post_up").val(client.post_up); + modal.find("#_client_post_down").val(client.post_down); + modal.find("#_use_server_dns").prop("checked", client.use_server_dns); modal.find("#_enabled").prop("checked", client.enabled); }, @@ -408,6 +419,8 @@ Wireguard Clients const email = $("#_client_email").val(); const allocated_ips = $("#_client_allocated_ips").val().split(","); const allowed_ips = $("#_client_allowed_ips").val().split(","); + const post_up = $("#_client_post_up").val(); + const post_down = $("#_client_post_down").val(); let use_server_dns = false; let extra_allowed_ips = []; @@ -426,7 +439,8 @@ Wireguard Clients } const data = {"id": client_id, "name": name, "email": email, "allocated_ips": allocated_ips, - "allowed_ips": allowed_ips, "extra_allowed_ips": extra_allowed_ips, "use_server_dns": use_server_dns, "enabled": enabled}; + "allowed_ips": allowed_ips, "extra_allowed_ips": extra_allowed_ips, "post_up": post_up, "post_down": post_down, + "use_server_dns": use_server_dns, "enabled": enabled}; $.ajax({ cache: false, diff --git a/util/util.go b/util/util.go index ea97fcc..9e67f9e 100644 --- a/util/util.go +++ b/util/util.go @@ -28,6 +28,14 @@ func BuildClientConfig(client model.Client, server model.Server, setting model.G if client.UseServerDNS { clientDNS = fmt.Sprintf("DNS = %s\n", strings.Join(setting.DNSServers, ",")) } + clientPostUp := "" + if strings.TrimSpace(client.PostUp) != "" { + clientPostUp = fmt.Sprintf("PostUp = %s\n", client.PostUp) + } + clientPostDown := "" + if strings.TrimSpace(client.PostDown) != "" { + clientPostDown = fmt.Sprintf("PostDown = %s\n", client.PostDown) + } // Peer section peerPublicKey := fmt.Sprintf("PublicKey = %s\n", server.KeyPair.PublicKey) @@ -67,6 +75,8 @@ func BuildClientConfig(client model.Client, server model.Server, setting model.G clientPrivateKey + clientDNS + forwardMark + + clientPostUp + + clientPostDown + "\n[Peer]\n" + peerPublicKey + peerPresharedKey +