diff --git a/app/js/custom.js b/app/js/custom.js index 53ea7ae3..c33a5d5a 100644 --- a/app/js/custom.js +++ b/app/js/custom.js @@ -623,18 +623,18 @@ function clearBlocklistStatus() { $('#cbxblocklist-status').removeClass('check-updated').addClass('check-hidden'); } -// Handler for the wireguard generate key button +// Handler for the WireGuard generate key button $('.wg-keygen').click(function(){ - var entity_pub = $(this).parent('div').prev('input[type="text"]'); - var entity_priv = $(this).parent('div').next('input[type="hidden"]'); + var parentGroup = $(this).closest('.input-group'); + var entity_pub = parentGroup.find('input[type="text"]'); var updated = entity_pub.attr('name')+"-pubkey-status"; - var csrfToken = $('meta[name=csrf_token]').attr('content'); + var csrfToken = $('meta[name="csrf_token"]').attr('content'); $.post('ajax/networking/get_wgkey.php',{'entity':entity_pub.attr('name'), 'csrf_token': csrfToken},function(data){ var jsonData = JSON.parse(data); entity_pub.val(jsonData.pubkey); $('#' + updated).removeClass('check-hidden').addClass('check-updated').delay(500).animate({ opacity: 1 }, 700); - }) -}) + }); +}); // Handler for wireguard client.conf download $('.wg-client-dl').click(function(){ diff --git a/includes/wireguard.php b/includes/wireguard.php index ed47a6e1..2cca31db 100755 --- a/includes/wireguard.php +++ b/includes/wireguard.php @@ -207,7 +207,10 @@ function SaveWireGuardConfig($status) } if (isset($_POST['wg_pendpoint']) && strlen(trim($_POST['wg_pendpoint']) >0 )) { $wg_pendpoint_seg = substr($_POST['wg_pendpoint'],0,strpos($_POST['wg_pendpoint'],':')); - if (!filter_var($wg_pendpoint_seg,FILTER_VALIDATE_IP)) { + $host_port = explode(':', $wg_pendpoint_seg); + $hostname = $host_port[0]; + if (!filter_var($hostname, FILTER_VALIDATE_IP) && + !filter_var($hostname, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)) { $status->addMessage('Invalid value for endpoint address', 'danger'); $good_input = false; } diff --git a/templates/wg/peers.php b/templates/wg/peers.php index fad228c4..a625b4c9 100644 --- a/templates/wg/peers.php +++ b/templates/wg/peers.php @@ -21,10 +21,8 @@