Browse Source

Working on port validation

pull/1/head
Muthu Kumar 7 years ago
parent
commit
9de4036c4a
  1. 5
      util/nginxPath.js
  2. 22
      util/validate.js

5
util/nginxPath.js

@ -8,10 +8,5 @@ function enabledSites() {
return enabledSites return enabledSites
} }
function conf(path, domain) {
return (path + domain + ".conf")
}
module.exports.conf = conf
module.exports.availableSites = availableSites module.exports.availableSites = availableSites
module.exports.enabledSites = enabledSites module.exports.enabledSites = enabledSites

22
util/validate.js

@ -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
} }
} }

Loading…
Cancel
Save