Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Friendly name param #644

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Build container images

on:
workflow_dispatch:
push:
branches:
- "master"
Expand Down Expand Up @@ -44,7 +45,7 @@ jobs:
${base}:${github_tag}
END_HEREDOC
)

## Set 'latest' image tag if 'main' or 'master'
## branch is pushed
##
Expand All @@ -58,13 +59,13 @@ jobs:
## Print tags for debugging purpose
##
echo "[INFO] container_images: ${container_images}"

## Set container_images output
##
echo "container_images<<EOF" >> $GITHUB_OUTPUT
echo "$container_images" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

## Set APP_VERSION env
#
echo "APP_VERSION=${app_version}" >> $GITHUB_ENV
Expand Down
6 changes: 6 additions & 0 deletions handler/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -919,6 +923,7 @@ func Status(db store.IStore) echo.HandlerFunc {
Connected bool
AllocatedIP string
Endpoint string
FriendlyName string
}

type DeviceVM struct {
Expand Down Expand Up @@ -989,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)
}
Expand Down
1 change: 1 addition & 0 deletions model/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ <h4 class="modal-title">New Wireguard Client</h4>
<label for="client_name" class="control-label">Name</label>
<input type="text" class="form-control" id="client_name" name="client_name">
</div>
<div class="form-group">
<label for="client_friendly_name" class="control-label">Friendly Name</label>
<input type="text" class="form-control" id="client_friendly_name" name="client_friendly_name">
</div>
<div class="form-group">
<label for="client_email" class="control-label">Email</label>
<input type="text" class="form-control" id="client_email" name="client_email">
Expand Down Expand Up @@ -437,7 +441,7 @@ <h1>{{template "page_title" .}}</h1>
}
});
}

// populateClient function for render new client info
// on the client page.
function populateClient(client_id) {
Expand All @@ -460,6 +464,7 @@ <h1>{{template "page_title" .}}</h1>
// 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(",");
Expand All @@ -484,10 +489,10 @@ <h1>{{template "page_title" .}}</h1>
}
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};

Expand Down Expand Up @@ -623,6 +628,7 @@ <h1>{{template "page_title" .}}</h1>
$(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("");
Expand Down
14 changes: 10 additions & 4 deletions templates/clients.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ <h4 class="modal-title">Edit Client</h4>
<label for="_client_name" class="control-label">Name</label>
<input type="text" class="form-control" id="_client_name" name="_client_name">
</div>
<div class="form-group">
<label for="_client_friendly_name" class="control-label">Name</label>
<input type="text" class="form-control" id="_client_friendly_name" name="_client_friendly_name">
</div>
<div class="form-group">
<label for="_client_email" class="control-label">Email</label>
<input type="text" class="form-control" id="_client_email" name="client_email">
Expand Down Expand Up @@ -505,7 +509,7 @@ <h4 class="modal-title">Remove</h4>
if (sr === selectedSR) {
$(this).closest('.col-lg-4').show();
break
}
}
}
})
// $('.col-lg-4').show();
Expand Down Expand Up @@ -628,6 +632,7 @@ <h4 class="modal-title">Remove</h4>
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
Expand Down Expand Up @@ -659,7 +664,7 @@ <h4 class="modal-title">Remove</h4>

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
Expand Down Expand Up @@ -757,6 +762,7 @@ <h4 class="modal-title">Remove</h4>
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(",");
Expand Down Expand Up @@ -784,7 +790,7 @@ <h4 class="modal-title">Remove</h4>

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};

Expand Down Expand Up @@ -958,7 +964,7 @@ <h4 class="modal-title">Remove</h4>
$(element).removeClass('is-invalid');
}
});
//
//
});
</script>
{{end}}
2 changes: 2 additions & 0 deletions templates/status.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Friendly Name</th>
<th scope="col">Email</th>
<th scope="col">Allocated IPs</th>
<th scope="col">Endpoint</th>
Expand All @@ -55,6 +56,7 @@
<tr {{ if $peer.Connected }} class="table-success" {{ end }}>
<th scope="row">{{ $idx }}</th>
<td>{{ $peer.Name }}</td>
<td>{{ $peer.FriendlyName }}</td>
<td>{{ $peer.Email }}</td>
<td>{{ $peer.AllocatedIP }}</td>
<td>{{ $peer.Endpoint }}</td>
Expand Down
1 change: 1 addition & 0 deletions templates/wg.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down