Skip to content

Commit

Permalink
Add validation to proxy names
Browse files Browse the repository at this point in the history
  • Loading branch information
ghormann committed Jun 27, 2021
1 parent 3192472 commit 46b30f0
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions www/js/fpp.js
Expand Up @@ -6030,3 +6030,48 @@ function PreviewStatistics() {
$('#statsPreviewPopup').fppDialog( "moveToTop" );
$('#statsPreviewDiv').load('api/statistics/usage');
}

function isValidIpAddress(ip)
{
if (ip == "") {
return false;
}
return /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ip);
}


// Source: https://github.com/miguelmota/is-valid-hostname/blob/master/index.js
// License MIT: https://raw.githubusercontent.com/miguelmota/is-valid-hostname/master/LICENSE
function isValidHostname(value) {
if (typeof value !== 'string') return false

const validHostnameChars = /^[a-zA-Z0-9-.]{1,253}\.?$/g
if (!validHostnameChars.test(value)) {
return false
}

if (value.endsWith('.')) {
value = value.slice(0, value.length - 1)
}

if (value.length > 253) {
return false
}

const labels = value.split('.')

const isValid = labels.every(function (label) {
const validLabelChars = /^([a-zA-Z0-9-]+)$/g

const validLabel = (
validLabelChars.test(label) &&
label.length < 64 &&
!label.startsWith('-') &&
!label.endsWith('-')
)

return validLabel
})

return isValid
}

0 comments on commit 46b30f0

Please sign in to comment.