mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-06-07 00:46:58 +03:00
Add wireguard server key pair generation
This commit is contained in:
parent
febf075f8d
commit
d5ff0cb704
5 changed files with 113 additions and 8 deletions
|
@ -57,21 +57,25 @@ Wireguard Server Settings
|
|||
<div class="form-group">
|
||||
<label for="private_key">Private Key</label>
|
||||
<div class="input-group input-group">
|
||||
<input type="text" class="form-control" id="private_key" placeholder="Private Key">
|
||||
<input type="password" class="form-control" id="private_key" placeholder="Private Key"
|
||||
value="{{ .serverKeyPair.PrivateKey }}" disabled>
|
||||
<span class="input-group-append">
|
||||
<button type="button" class="btn btn-danger btn-flat">Show</button>
|
||||
<button type="button" class="btn btn-danger btn-flat"
|
||||
id="btn_show_private_key">Show</button>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="public_key">Public Key</label>
|
||||
<input type="text" class="form-control" id="public_key" placeholder="Public Key">
|
||||
<input type="text" class="form-control" id="public_key" placeholder="Public Key"
|
||||
value="{{ .serverKeyPair.PublicKey }}" disabled>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.card-body -->
|
||||
|
||||
<div class="card-footer">
|
||||
<button type="submit" class="btn btn-danger">Regenerate</button>
|
||||
<button type="button" class="btn btn-danger" data-toggle="modal"
|
||||
data-target="#modal_keypair_confirmation">Generate</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -81,6 +85,30 @@ Wireguard Server Settings
|
|||
<!-- /.row -->
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="modal fade" id="modal_keypair_confirmation">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content bg-warning">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title">KeyPair Generation</h4>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>Are you sure to generate a new key pair for the Wireguard server?<br/>
|
||||
The existing Clients's peer public key need to be updated to keep the connection working.</p>
|
||||
</div>
|
||||
<div class="modal-footer justify-content-between">
|
||||
<button type="button" class="btn btn-outline-dark" data-dismiss="modal">Cancel</button>
|
||||
<button type="button" class="btn btn-outline-dark" id="btn_generate_confirm">Generate</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.modal-content -->
|
||||
</div>
|
||||
<!-- /.modal-dialog -->
|
||||
</div>
|
||||
<!-- /.modal -->
|
||||
{{end}}
|
||||
|
||||
{{define "bottom_js"}}
|
||||
|
@ -161,5 +189,45 @@ Wireguard Server Settings
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Wireguard Key Pair generation confirmation button
|
||||
$(document).ready(function () {
|
||||
$('#btn_generate_confirm').click(function () {
|
||||
$.ajax({
|
||||
cache: false,
|
||||
method: 'POST',
|
||||
url: '/wg-server/keypair',
|
||||
dataType: 'json',
|
||||
contentType: "application/json",
|
||||
success: function(data) {
|
||||
$('#modal_keypair_confirmation').modal('hide');
|
||||
toastr.success('Generate new key pair successfully');
|
||||
// update the UI
|
||||
$('#private_key').val(data['private_key']);
|
||||
$('#public_key').val(data['public_key']);
|
||||
},
|
||||
error: function(jqXHR, exception) {
|
||||
var responseJson = jQuery.parseJSON(jqXHR.responseText);
|
||||
toastr.error(responseJson['message']);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Show private key button event
|
||||
$(document).ready(function () {
|
||||
$('#btn_show_private_key').click(function () {
|
||||
var privateElement = document.getElementById("private_key");
|
||||
var btnElement = document.getElementById("btn_show_private_key");
|
||||
console.log(privateElement);
|
||||
if (privateElement.type === 'password') {
|
||||
privateElement.type = 'text';
|
||||
btnElement.innerText = 'Hide';
|
||||
} else {
|
||||
privateElement.type = 'password';
|
||||
btnElement.innerText = 'Show';
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{{end}}
|
Loading…
Add table
Add a link
Reference in a new issue