mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-04-19 19:59:13 +03:00
Support for notes about clients
This commit is contained in:
parent
a22e807d2a
commit
986404236a
6 changed files with 33 additions and 3 deletions
|
@ -720,6 +720,7 @@ func UpdateClient(db store.IStore) echo.HandlerFunc {
|
||||||
client.PublicKey = _client.PublicKey
|
client.PublicKey = _client.PublicKey
|
||||||
client.PresharedKey = _client.PresharedKey
|
client.PresharedKey = _client.PresharedKey
|
||||||
client.UpdatedAt = time.Now().UTC()
|
client.UpdatedAt = time.Now().UTC()
|
||||||
|
client.AdditionalNotes = strings.ReplaceAll(strings.Trim(_client.AdditionalNotes, "\r\n"), "\r\n", "\n")
|
||||||
|
|
||||||
// write to the database
|
// write to the database
|
||||||
if err := db.SaveClient(client); err != nil {
|
if err := db.SaveClient(client); err != nil {
|
||||||
|
|
|
@ -18,6 +18,7 @@ type Client struct {
|
||||||
AllowedIPs []string `json:"allowed_ips"`
|
AllowedIPs []string `json:"allowed_ips"`
|
||||||
ExtraAllowedIPs []string `json:"extra_allowed_ips"`
|
ExtraAllowedIPs []string `json:"extra_allowed_ips"`
|
||||||
Endpoint string `json:"endpoint"`
|
Endpoint string `json:"endpoint"`
|
||||||
|
AdditionalNotes string `json:"additional_notes"`
|
||||||
UseServerDNS bool `json:"use_server_dns"`
|
UseServerDNS bool `json:"use_server_dns"`
|
||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
|
|
@ -288,6 +288,10 @@
|
||||||
<label for="client_telegram_userid" class="control-label">Telegram userid</label>
|
<label for="client_telegram_userid" class="control-label">Telegram userid</label>
|
||||||
<input type="text" class="form-control" id="client_telegram_userid" name="client_telegram_userid">
|
<input type="text" class="form-control" id="client_telegram_userid" name="client_telegram_userid">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="additional_notes" class="control-label">Notes</label>
|
||||||
|
<textarea class="form-control" style="min-height: 6rem;" id="additional_notes" name="additional_notes" placeholder="Additional notes about this client"></textarea>
|
||||||
|
</div>
|
||||||
</details>
|
</details>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer justify-content-between">
|
<div class="modal-footer justify-content-between">
|
||||||
|
@ -484,9 +488,11 @@
|
||||||
const public_key = $("#client_public_key").val();
|
const public_key = $("#client_public_key").val();
|
||||||
const preshared_key = $("#client_preshared_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, "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,
|
"extra_allowed_ips": extra_allowed_ips, "endpoint": endpoint, "use_server_dns": use_server_dns, "enabled": enabled,
|
||||||
"public_key": public_key, "preshared_key": preshared_key};
|
"public_key": public_key, "preshared_key": preshared_key, "additional_notes": additional_notes};
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
cache: false,
|
cache: false,
|
||||||
|
@ -627,6 +633,7 @@
|
||||||
$("#client_extra_allowed_ips").importTags('');
|
$("#client_extra_allowed_ips").importTags('');
|
||||||
$("#client_endpoint").val('');
|
$("#client_endpoint").val('');
|
||||||
$("#client_telegram_userid").val('');
|
$("#client_telegram_userid").val('');
|
||||||
|
$("#additional_notes").val('');
|
||||||
updateSubnetRangesList("#subnet_ranges");
|
updateSubnetRangesList("#subnet_ranges");
|
||||||
updateIPAllocationSuggestion(true);
|
updateIPAllocationSuggestion(true);
|
||||||
});
|
});
|
||||||
|
|
|
@ -195,6 +195,10 @@ Wireguard Clients
|
||||||
<label for="_client_telegram_userid" class="control-label">Telegram userid</label>
|
<label for="_client_telegram_userid" class="control-label">Telegram userid</label>
|
||||||
<input type="text" class="form-control" id="_client_telegram_userid" name="_client_telegram_userid">
|
<input type="text" class="form-control" id="_client_telegram_userid" name="_client_telegram_userid">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="_additional_notes" class="control-label">Notes</label>
|
||||||
|
<textarea class="form-control" style="min-height: 6rem;" id="_additional_notes" name="_additional_notes" placeholder="Additional notes about this client"></textarea>
|
||||||
|
</div>
|
||||||
</details>
|
</details>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer justify-content-between">
|
<div class="modal-footer justify-content-between">
|
||||||
|
@ -649,6 +653,8 @@ Wireguard Clients
|
||||||
modal.find("#_client_public_key").val(client.public_key);
|
modal.find("#_client_public_key").val(client.public_key);
|
||||||
modal.find("#_client_preshared_key").val(client.preshared_key);
|
modal.find("#_client_preshared_key").val(client.preshared_key);
|
||||||
|
|
||||||
|
modal.find("#_additional_notes").val(client.additional_notes);
|
||||||
|
|
||||||
// handle subnet range select
|
// handle subnet range select
|
||||||
$('#_subnet_ranges').on('select2:select', function (e) {
|
$('#_subnet_ranges').on('select2:select', function (e) {
|
||||||
updateIPAllocationSuggestionExisting();
|
updateIPAllocationSuggestionExisting();
|
||||||
|
@ -769,9 +775,11 @@ Wireguard Clients
|
||||||
enabled = true;
|
enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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, "email": email, "telegram_userid": telegram_userid, "allocated_ips": allocated_ips,
|
||||||
"allowed_ips": allowed_ips, "extra_allowed_ips": extra_allowed_ips, "endpoint": endpoint,
|
"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};
|
"use_server_dns": use_server_dns, "enabled": enabled, "public_key": public_key, "preshared_key": preshared_key, "additional_notes": additional_notes};
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
cache: false,
|
cache: false,
|
||||||
|
|
|
@ -20,6 +20,10 @@ Table = {{ .globalSettings.Table }}
|
||||||
# Telegram: {{ .Client.TgUserid }}
|
# Telegram: {{ .Client.TgUserid }}
|
||||||
# Created at: {{ .Client.CreatedAt }}
|
# Created at: {{ .Client.CreatedAt }}
|
||||||
# Update at: {{ .Client.UpdatedAt }}
|
# Update at: {{ .Client.UpdatedAt }}
|
||||||
|
{{- if .Client.AdditionalNotes}}
|
||||||
|
|
||||||
|
# Notes:
|
||||||
|
# {{ .Client.AdditionalNotes }}{{end}}
|
||||||
[Peer]
|
[Peer]
|
||||||
PublicKey = {{ .Client.PublicKey }}
|
PublicKey = {{ .Client.PublicKey }}
|
||||||
{{if .Client.PresharedKey}}PresharedKey = {{ .Client.PresharedKey }}{{end}}
|
{{if .Client.PresharedKey}}PresharedKey = {{ .Client.PresharedKey }}{{end}}
|
||||||
|
|
11
util/util.go
11
util/util.go
|
@ -560,6 +560,15 @@ func WriteWireGuardServerConfig(tmplDir fs.FS, serverConfig model.Server, client
|
||||||
tmplWireguardConf = fileContent
|
tmplWireguardConf = fileContent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// escape multiline notes
|
||||||
|
escapedClientDataList := []model.ClientData{}
|
||||||
|
for _, cd := range clientDataList {
|
||||||
|
if cd.Client.AdditionalNotes != "" {
|
||||||
|
cd.Client.AdditionalNotes = strings.ReplaceAll(cd.Client.AdditionalNotes, "\n", "\n# ")
|
||||||
|
}
|
||||||
|
escapedClientDataList = append(escapedClientDataList, cd)
|
||||||
|
}
|
||||||
|
|
||||||
// parse the template
|
// parse the template
|
||||||
t, err := template.New("wg_config").Parse(tmplWireguardConf)
|
t, err := template.New("wg_config").Parse(tmplWireguardConf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -574,7 +583,7 @@ func WriteWireGuardServerConfig(tmplDir fs.FS, serverConfig model.Server, client
|
||||||
|
|
||||||
config := map[string]interface{}{
|
config := map[string]interface{}{
|
||||||
"serverConfig": serverConfig,
|
"serverConfig": serverConfig,
|
||||||
"clientDataList": clientDataList,
|
"clientDataList": escapedClientDataList,
|
||||||
"globalSettings": globalSettings,
|
"globalSettings": globalSettings,
|
||||||
"usersList": usersList,
|
"usersList": usersList,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue