Commit b4faf111 authored by Ted Trask's avatar Ted Trask
Browse files

Better validation of config interfaces

parent d7982d62
......@@ -138,7 +138,7 @@ local function parse_file (file)
return opts
end
local function validateconfig(config)
local function validateconfig(self, config)
local success = true
function testlist(param, test, errtxt)
......@@ -159,12 +159,20 @@ local function validateconfig(config)
success = false
end
end
local interfaces = {}
local interfacescontroller = self:new("alpine-baselayout/interfaces")
local ints = interfacescontroller.model.get_interfaces()
interfacescontroller:destroy()
for i,v in ipairs(ints.value) do
interfaces[v] = i
end
testlist(config.value.domain, function(v) return string.find(v, "%s") end, "Cannot contain spaces")
testlist(config.value.interface, function(v) return string.find(v, "%W") end, "Illegal character")
testlist(config.value.interface, function(v) return not interfaces[v] end, "Invalid interface")
testlist(config.value.listen_address, function(v) return not validator.is_ipv4(v) end, "Invalid IP Address")
testlist(config.value.dhcp_range, function(v) return string.find(v, "%s") end, "Cannot contain spaces")
testlist(config.value.no_dhcp_interface, function(v) return string.find(v, "%W") end, "Illegal character")
testlist(config.value.no_dhcp_interface, function(v) return not interfaces[v] end, "Invalid interface")
testlist(config.value.dhcp_host, function(v) return string.find(v, "%s") end, "Cannot contain spaces")
testlist(config.value.dhcp_option, function(v) return string.find(v, "%s") end, "Cannot contain spaces")
testlist(config.value.mx_host, function(v) return string.find(v, "%s") end, "Cannot contain spaces")
......@@ -296,7 +304,7 @@ function getconfig()
end
function setconfig(self, config)
local success, config = validateconfig(config)
local success, config = validateconfig(self, config)
if success then
local file = fs.read_file(configfile) or ""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment