diff --git a/custom/js/helper.js b/custom/js/helper.js index 42bc17a..ad7d921 100644 --- a/custom/js/helper.js +++ b/custom/js/helper.js @@ -18,6 +18,12 @@ function renderClientList(data) { allowedIpsHtml += `${obj} `; }) + // render client private subnets + let privateSubnetsHtml = ""; + $.each(obj.Client.private_subnets, function(index, obj) { + privateSubnetsHtml += `${obj} `; + }) + // render client html content let html = `
@@ -50,6 +56,8 @@ function renderClientList(data) { + allocatedIpsHtml + `Allowed IPs` + allowedIpsHtml + + `Private Subnets` + + privateSubnetsHtml +`
` diff --git a/model/client.go b/model/client.go index 2d610a6..3da74f0 100644 --- a/model/client.go +++ b/model/client.go @@ -6,17 +6,18 @@ import ( // Client model type Client struct { - ID string `json:"id"` - PrivateKey string `json:"private_key"` - PublicKey string `json:"public_key"` - PresharedKey string `json:"preshared_key"` - Name string `json:"name"` - Email string `json:"email"` - AllocatedIPs []string `json:"allocated_ips"` - AllowedIPs []string `json:"allowed_ips"` - Enabled bool `json:"enabled"` - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"updated_at"` + ID string `json:"id"` + PrivateKey string `json:"private_key"` + PublicKey string `json:"public_key"` + PresharedKey string `json:"preshared_key"` + Name string `json:"name"` + Email string `json:"email"` + AllocatedIPs []string `json:"allocated_ips"` + AllowedIPs []string `json:"allowed_ips"` + PrivateSubnets []string `json:"private_subnets"` + Enabled bool `json:"enabled"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` } // ClientData includes the Client and extra data diff --git a/templates/base.html b/templates/base.html index 0e04f31..67f89fb 100644 --- a/templates/base.html +++ b/templates/base.html @@ -153,6 +153,10 @@ +
+ + +
@@ -274,13 +278,14 @@ const email = $("#client_email").val(); const allocated_ips = $("#client_allocated_ips").val().split(","); const allowed_ips = $("#client_allowed_ips").val().split(","); + const private_subnets = $("#client_private_subnets").val().split(","); let enabled = false; if ($("#enabled").is(':checked')){ enabled = true; } - const data = {"name": name, "email": email, "allocated_ips": allocated_ips, "allowed_ips": allowed_ips, + const data = {"name": name, "email": email, "allocated_ips": allocated_ips, "allowed_ips": allowed_ips, "private_subnets": private_subnets, "enabled": enabled}; $.ajax({ @@ -354,6 +359,18 @@ 'placeholderColor': '#666666' }); + // PrivateSubnets tag input + $("#client_private_subnets").tagsInput({ + 'width': '100%', + 'height': '75%', + 'interactive': true, + 'defaultText': 'Add More', + 'removeWithBackspace': true, + 'minChars': 0, + 'maxChars': 18, + 'placeholderColor': '#666666' + }); + // New client form validation $(document).ready(function () { $.validator.setDefaults({ diff --git a/templates/clients.html b/templates/clients.html index 689d5d2..c095fc5 100644 --- a/templates/clients.html +++ b/templates/clients.html @@ -58,6 +58,10 @@ Wireguard Clients
+
+ + +
@@ -266,6 +270,18 @@ Wireguard Clients 'placeholderColor': '#666666' }); + // PrivateSubnet tag input + modal.find("#_client_private_subnets").tagsInput({ + 'width': '100%', + 'height': '75%', + 'interactive': true, + 'defaultText': 'Add More', + 'removeWithBackspace': true, + 'minChars': 0, + 'maxChars': 18, + 'placeholderColor': '#666666' + }); + // update client modal data $.ajax({ cache: false, @@ -291,6 +307,11 @@ Wireguard Clients modal.find("#_client_allowed_ips").addTag(obj); }); + modal.find("#_client_private_subnets").importTags(''); + client.private_subnets.forEach(function (obj) { + modal.find("#_client_private_subnets").addTag(obj); + }); + modal.find("#_enabled").prop("checked", client.enabled); }, error: function (jqXHR, exception) { @@ -306,15 +327,16 @@ Wireguard Clients const client_id = $("#_client_id").val(); const name = $("#_client_name").val(); const email = $("#_client_email").val(); - const allocated_ips = $("#_client_allocated_ips").val().split(","); + const allocated_ips = $("#1").val().split(","); const allowed_ips = $("#_client_allowed_ips").val().split(","); + const private_subnets = $("#_client_private_subnets").val().split(","); let enabled = false; if ($("#_enabled").is(':checked')){ enabled = true; } - const data = {"id": client_id, "name": name, "email": email, "allocated_ips": allocated_ips, + const data = {"id": client_id, "name": name, "email": email, "allocated_ips": allocated_ips, "private_subnets": private_subnets, "allowed_ips": allowed_ips, "enabled": enabled}; $.ajax({ diff --git a/templates/wg.conf b/templates/wg.conf index f4b1981..e63c8cc 100644 --- a/templates/wg.conf +++ b/templates/wg.conf @@ -20,5 +20,5 @@ PostDown = {{ .serverConfig.Interface.PostDown }} [Peer] PublicKey = {{ .Client.PublicKey }} PresharedKey = {{ .Client.PresharedKey }} -AllowedIPs = {{$first :=true}}{{range .Client.AllocatedIPs }}{{if $first}}{{$first = false}}{{else}},{{end}}{{.}}{{end}} +AllowedIPs = {{$first :=true}}{{range .Client.AllocatedIPs }}{{if $first}}{{$first = false}}{{else}},{{end}}{{.}}{{end}}{{if .Client.PrivateSubnets}},{{end}}{{$first :=true}}{{range .Client.PrivateSubnets }}{{if $first}}{{$first = false}}{{else}},{{end}}{{.}}{{end}} {{end}}{{end}}