|
@ -2,39 +2,39 @@ var validator = require('validator') |
|
|
// Using Validator
|
|
|
// Using Validator
|
|
|
var isDomain = validator.isFQDN |
|
|
var isDomain = validator.isFQDN |
|
|
|
|
|
|
|
|
function validate(domain, inPort = undefined, outPort = undefined) { |
|
|
function validate(domain, inPort = undefined, outPort = "80") { |
|
|
var domainInvalidMsg = "\nDomain is not valid. Please use a valid domain name." |
|
|
var domainInvalidMsg = "\nDomain is not valid. Please use a valid domain name." |
|
|
var portInvalidMsg = ["\nPort should be a number.", "\nPort should be a number from 1 and 65535."] |
|
|
var portInvalidMsg = ["\nPort should be a number.", "\nPort should be a number from 1 and 65535."] |
|
|
var validInPort = /^\d+$/.exec(inPort) |
|
|
//var validInPort = /^\d+$/.exec(inPort)[0]
|
|
|
var validOutPort = /^\d+$/.exec(outPort) |
|
|
//var validOutPort = /^\d+$/.exec(outPort)[0]
|
|
|
var isTrue = true |
|
|
|
|
|
|
|
|
var isValid = true |
|
|
if (!isDomain(domain)) { |
|
|
if (!isDomain(domain)) { |
|
|
console.log(domainInvalidMsg) |
|
|
console.log(domainInvalidMsg) |
|
|
return isTrue = false |
|
|
return isValid = false |
|
|
} |
|
|
} |
|
|
if (typeof inPort == undefined) { |
|
|
if (typeof inPort == undefined) { |
|
|
if (!validOutPort) { |
|
|
if (!validOutPort) { |
|
|
console.log(portInvalidMsg[0]) |
|
|
console.log(portInvalidMsg[0]) |
|
|
return isTrue = false |
|
|
return isValid = false |
|
|
} |
|
|
} |
|
|
if (!(validOutPort > 0 && validOutPort <= 65535)) { |
|
|
if (!(validOutPort > 0 && validOutPort <= 65535)) { |
|
|
console.log(portInvalidMsg[1]) |
|
|
console.log(portInvalidMsg[1]) |
|
|
return isTrue = false |
|
|
return isValid = false |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (typeof inPort !== undefined) { |
|
|
if (typeof inPort !== undefined) { |
|
|
if (!validInPort || !validOutPort) { |
|
|
if (!validInPort || !validOutPort) { |
|
|
console.log(portInvalidMsg[0]) |
|
|
console.log(portInvalidMsg[0]) |
|
|
return isTrue = false |
|
|
return isValid = false |
|
|
} |
|
|
} |
|
|
if (typeof outPort !== undefined) { |
|
|
if (typeof outPort !== undefined) { |
|
|
console.log(validInPort) |
|
|
|
|
|
if (!((validInPort > 0 && validInPort <= 65535) && (validOutPort > 0 && validOutPort <= 65535))) { |
|
|
if (!((validInPort > 0 && validInPort <= 65535) && (validOutPort > 0 && validOutPort <= 65535))) { |
|
|
console.log(portInvalidMsg[1]) |
|
|
console.log(portInvalidMsg[1]) |
|
|
return isTrue = false |
|
|
return isValid = false |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return isTrue |
|
|
return isValid |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|