diff --git a/custom/js/helper.js b/custom/js/helper.js index 39bc1fa..4f21c1c 100644 --- a/custom/js/helper.js +++ b/custom/js/helper.js @@ -18,6 +18,11 @@ function renderClientList(data) { allowedIpsHtml += `${obj} `; }) + let subnetRangesString = ""; + if (obj.Client.subnet_ranges && obj.Client.subnet_ranges.length > 0) { + subnetRangesString = obj.Client.subnet_ranges.join(',') + } + // render client html content let html = `
@@ -59,6 +64,7 @@ function renderClientList(data) {
${obj.Client.name} + ${obj.Client.email} ${prettyDateTime(obj.Client.created_at)} diff --git a/handler/routes.go b/handler/routes.go index 780d463..6f555d0 100644 --- a/handler/routes.go +++ b/handler/routes.go @@ -366,6 +366,10 @@ func GetClients(db store.IStore) echo.HandlerFunc { }) } + for i, clientData := range clientDataList { + clientDataList[i] = util.FillClientSubnetRange(clientData) + } + return c.JSON(http.StatusOK, clientDataList) } } @@ -391,7 +395,7 @@ func GetClient(db store.IStore) echo.HandlerFunc { return c.JSON(http.StatusNotFound, jsonHTTPResponse{false, "Client not found"}) } - return c.JSON(http.StatusOK, clientData) + return c.JSON(http.StatusOK, util.FillClientSubnetRange(clientData)) } } diff --git a/model/client.go b/model/client.go index 95342f0..6199123 100644 --- a/model/client.go +++ b/model/client.go @@ -12,6 +12,7 @@ type Client struct { PresharedKey string `json:"preshared_key"` Name string `json:"name"` Email string `json:"email"` + SubnetRanges []string `json:"subnet_ranges,omitempty"` AllocatedIPs []string `json:"allocated_ips"` AllowedIPs []string `json:"allowed_ips"` ExtraAllowedIPs []string `json:"extra_allowed_ips"` @@ -29,7 +30,7 @@ type ClientData struct { } type QRCodeSettings struct { - Enabled bool - IncludeDNS bool - IncludeMTU bool + Enabled bool + IncludeDNS bool + IncludeMTU bool } diff --git a/templates/base.html b/templates/base.html index bca6ee6..5821cc6 100644 --- a/templates/base.html +++ b/templates/base.html @@ -58,11 +58,13 @@
@@ -210,7 +212,7 @@
- + @@ -374,7 +376,6 @@ $(document).ready(function () { - addGlobalStyle(` .toast-top-right-fix { top: 67px; @@ -387,6 +388,8 @@ toastr.options.positionClass = 'toast-top-right-fix'; updateApplyConfigVisibility() + // from clients.html + updateSearchList() }); diff --git a/templates/clients.html b/templates/clients.html index c7a6c96..570b0aa 100644 --- a/templates/clients.html +++ b/templates/clients.html @@ -279,6 +279,36 @@ Wireguard Clients }); }); } + + function updateSearchList() { + $.getJSON("{{.basePath}}/api/subnet-ranges", null, function(data) { + $("#status-selector option").remove(); + $("#status-selector").append( + $("") + .text("All") + .val("All"), + $("") + .text("Enabled") + .val("Enabled"), + $("") + .text("Disabled") + .val("Disabled"), + $("") + .text("Connected") + .val("Connected"), + $("") + .text("Disconnected") + .val("Disconnected") + ); + $.each(data, function(index, item) { + $("#status-selector").append( + $("") + .text(item) + .val(item) + ); + }); + }); +}