From dd8f4742e7cdaba36cb717295bde95c5d6a5f6e1 Mon Sep 17 00:00:00 2001 From: kadet77rus Date: Fri, 27 Sep 2024 19:41:58 +0300 Subject: [PATCH 1/5] add friendly_name param --- handler/routes.go | 4 ++++ model/client.go | 1 + templates/base.html | 12 +++++++++--- templates/clients.html | 14 ++++++++++---- templates/status.html | 2 ++ templates/wg.conf | 1 + 6 files changed, 27 insertions(+), 7 deletions(-) diff --git a/handler/routes.go b/handler/routes.go index ede3654..1302e6b 100644 --- a/handler/routes.go +++ b/handler/routes.go @@ -481,6 +481,10 @@ func NewClient(db store.IStore) echo.HandlerFunc { } } + if client.FriendlyName == "" { + client.FriendlyName = client.Name + "-" + client.ID + } + if client.PresharedKey == "" { presharedKey, err := wgtypes.GenerateKey() if err != nil { diff --git a/model/client.go b/model/client.go index d835124..0f48375 100644 --- a/model/client.go +++ b/model/client.go @@ -23,6 +23,7 @@ type Client struct { Enabled bool `json:"enabled"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` + FriendlyName string `json:"friendly_name"` } // ClientData includes the Client and extra data diff --git a/templates/base.html b/templates/base.html index 3640699..3992183 100644 --- a/templates/base.html +++ b/templates/base.html @@ -207,6 +207,10 @@ +
+ + +
@@ -437,7 +441,7 @@ } }); } - + // populateClient function for render new client info // on the client page. function populateClient(client_id) { @@ -460,6 +464,7 @@ // submitNewClient function for new client form submission function submitNewClient() { const name = $("#client_name").val(); + const friendly_name = $("#client_friendly_name").val(); const email = $("#client_email").val(); const telegram_userid = $("#client_telegram_userid").val(); const allocated_ips = $("#client_allocated_ips").val().split(","); @@ -484,10 +489,10 @@ } const public_key = $("#client_public_key").val(); const preshared_key = $("#client_preshared_key").val(); - + const additional_notes = $("#additional_notes").val(); - const data = {"name": name, "email": email, "telegram_userid": telegram_userid, "allocated_ips": allocated_ips, "allowed_ips": allowed_ips, + const data = {"name": name, "friendly_name": friendly_name, "email": email, "telegram_userid": telegram_userid, "allocated_ips": allocated_ips, "allowed_ips": allowed_ips, "extra_allowed_ips": extra_allowed_ips, "endpoint": endpoint, "use_server_dns": use_server_dns, "enabled": enabled, "public_key": public_key, "preshared_key": preshared_key, "additional_notes": additional_notes}; @@ -623,6 +628,7 @@ $(document).ready(function () { $("#modal_new_client").on('shown.bs.modal', function (e) { $("#client_name").val(""); + $("#client_friendly_name").val(""); $("#client_email").val(""); $("#client_public_key").val(""); $("#client_preshared_key").val(""); diff --git a/templates/clients.html b/templates/clients.html index 0ab8733..326b9ac 100644 --- a/templates/clients.html +++ b/templates/clients.html @@ -125,6 +125,10 @@ Wireguard Clients
+
+ + +
@@ -505,7 +509,7 @@ Wireguard Clients if (sr === selectedSR) { $(this).closest('.col-lg-4').show(); break - } + } } }) // $('.col-lg-4').show(); @@ -628,6 +632,7 @@ Wireguard Clients modal.find("#_client_id").val(client.id); modal.find("#_client_telegram_userid").val(client.telegram_userid); modal.find("#_client_name").val(client.name); + modal.find("#_client_friendly_name").val(client.name); modal.find("#_client_email").val(client.email); let preselectedEl @@ -659,7 +664,7 @@ Wireguard Clients modal.find("#_client_public_key").val(client.public_key); modal.find("#_client_preshared_key").val(client.preshared_key); - + modal.find("#_additional_notes").val(client.additional_notes); // handle subnet range select @@ -757,6 +762,7 @@ Wireguard Clients function submitEditClient() { const client_id = $("#_client_id").val(); const name = $("#_client_name").val(); + const friendly_name = $("#_client_friendly_name").val(); const email = $("#_client_email").val(); const telegram_userid = $("#_client_telegram_userid").val(); const allocated_ips = $("#_client_allocated_ips").val().split(","); @@ -784,7 +790,7 @@ Wireguard Clients const additional_notes = $("#_additional_notes").val(); - const data = {"id": client_id, "name": name, "email": email, "telegram_userid": telegram_userid, "allocated_ips": allocated_ips, + const data = {"id": client_id, "name": name, "friendly_name": friendly_name, "email": email, "telegram_userid": telegram_userid, "allocated_ips": allocated_ips, "allowed_ips": allowed_ips, "extra_allowed_ips": extra_allowed_ips, "endpoint": endpoint, "use_server_dns": use_server_dns, "enabled": enabled, "public_key": public_key, "preshared_key": preshared_key, "additional_notes": additional_notes}; @@ -958,7 +964,7 @@ Wireguard Clients $(element).removeClass('is-invalid'); } }); - // + // }); {{end}} diff --git a/templates/status.html b/templates/status.html index a9b770b..0012b4a 100644 --- a/templates/status.html +++ b/templates/status.html @@ -40,6 +40,7 @@ Connected Peers # Name + Friendly Name Email Allocated IPs Endpoint @@ -55,6 +56,7 @@ Connected Peers {{ $idx }} {{ $peer.Name }} + {{ $peer.FriendlyName }} {{ $peer.Email }} {{ $peer.AllocatedIP }} {{ $peer.Endpoint }} diff --git a/templates/wg.conf b/templates/wg.conf index 34891f0..f59fe0f 100644 --- a/templates/wg.conf +++ b/templates/wg.conf @@ -25,6 +25,7 @@ Table = {{ .globalSettings.Table }} # Notes: # {{ .Client.AdditionalNotes }}{{end}} [Peer] +# friendly_name = {{ .Client.FriendlyName }} PublicKey = {{ .Client.PublicKey }} {{if .Client.PresharedKey}}PresharedKey = {{ .Client.PresharedKey }}{{end}} AllowedIPs = {{$first :=true}}{{range .Client.AllocatedIPs }}{{if $first}}{{$first = false}}{{else}},{{end}}{{.}}{{end}}{{range .Client.ExtraAllowedIPs }},{{.}}{{end}} From 1fb54d097248dbe75e78d01c13e5f4e6228ec5a3 Mon Sep 17 00:00:00 2001 From: kadet77rus Date: Fri, 27 Sep 2024 19:46:19 +0300 Subject: [PATCH 2/5] use my dockerhub --- .github/workflows/docker-build.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 8960a48..589f2c1 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -26,7 +26,8 @@ jobs: - name: Prepare image tags id: image-tags run: | - base=ngoduykhanh/wireguard-ui + # base=ngoduykhanh/wireguard-ui + base=kadet77rus/wireguard-ui app_version=dev ## Set git tag as image tag @@ -44,7 +45,7 @@ jobs: ${base}:${github_tag} END_HEREDOC ) - + ## Set 'latest' image tag if 'main' or 'master' ## branch is pushed ## @@ -58,13 +59,13 @@ jobs: ## Print tags for debugging purpose ## echo "[INFO] container_images: ${container_images}" - + ## Set container_images output ## echo "container_images<> $GITHUB_OUTPUT echo "$container_images" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT - + ## Set APP_VERSION env # echo "APP_VERSION=${app_version}" >> $GITHUB_ENV From 8c8e1c545189984a4c0ba49488ef2293a44bb89f Mon Sep 17 00:00:00 2001 From: kadet77rus Date: Fri, 27 Sep 2024 19:52:00 +0300 Subject: [PATCH 3/5] add manually run build --- .github/workflows/docker-build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 589f2c1..ece8039 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -1,6 +1,7 @@ name: Build container images on: + workflow_dispatch: push: branches: - "master" From c840f2bd5f86a0cea6792783b8efc4ddf8a5c2f7 Mon Sep 17 00:00:00 2001 From: kadet77rus Date: Mon, 28 Oct 2024 13:07:40 +0300 Subject: [PATCH 4/5] fix friendly name --- handler/routes.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/handler/routes.go b/handler/routes.go index 1302e6b..01b023a 100644 --- a/handler/routes.go +++ b/handler/routes.go @@ -923,6 +923,7 @@ func Status(db store.IStore) echo.HandlerFunc { Connected bool AllocatedIP string Endpoint string + FriendlyName string } type DeviceVM struct { @@ -993,6 +994,7 @@ func Status(db store.IStore) echo.HandlerFunc { if _client, ok := m[pVm.PublicKey]; ok { pVm.Name = _client.Name pVm.Email = _client.Email + pVm.FriendlyName = _client.FriendlyName } devVm.Peers = append(devVm.Peers, pVm) } From f1192d6c0ba747568a79c3e7d046b74435942a6d Mon Sep 17 00:00:00 2001 From: kadet77rus <53903372+kadet77rus@users.noreply.github.com> Date: Tue, 29 Oct 2024 17:57:22 +0300 Subject: [PATCH 5/5] Update docker-build.yml --- .github/workflows/docker-build.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index ece8039..6167d2b 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -27,8 +27,7 @@ jobs: - name: Prepare image tags id: image-tags run: | - # base=ngoduykhanh/wireguard-ui - base=kadet77rus/wireguard-ui + base=ngoduykhanh/wireguard-ui app_version=dev ## Set git tag as image tag