summaryrefslogtreecommitdiffstats
path: root/tinydns-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tinydns-model.lua')
-rw-r--r--tinydns-model.lua445
1 files changed, 270 insertions, 175 deletions
diff --git a/tinydns-model.lua b/tinydns-model.lua
index a466f6b..286689f 100644
--- a/tinydns-model.lua
+++ b/tinydns-model.lua
@@ -21,6 +21,8 @@ else
datafile = "/var/cache/data"
end
+--configdir = "hidden for the moment - This row is here only for debug purpose"
+
-- ################################################################################
-- LOCAL FUNCTIONS
@@ -38,26 +40,6 @@ local function get_version()
return cmd_output_result,cmd_output_error
end
--- This function could be used to check that valid parameters are used in different places
-local function check_signs(sign)
- local output = {}
- local output = {prefix={
- ['.']="Name server for your domain",
- ['&']="Name server",
- ['=']="Host",
- ['+']="Alias",
- ['@']="Mail exchanger",
- ['=']="Host",
- ['^']="PTR record",
- ['C']="Canonical Name",
- ['Z']="SOA record",
- [':']="Generic record",
- ['%']="Client location",
- }}
- output = output[sign]
- return output
-end
-
-- Return a table with the config-content of a file
-- Commented/Blank lines are ignored
local function get_value_from_file(file)
@@ -101,12 +83,6 @@ local function split_config_items(orgitem)
output = format.string_to_table(string.sub(orgitem,1,1) .. ":" .. string.sub(orgitem,2),delimiter)
output.type = check_signs("prefix")
output.type = output.type[string.sub(orgitem,1,1)] or "unknown"
--- for k,v in pairs(cnffile) do
--- local configcontent = get_value_from_file(v)
--- if (configcontent) then
--- table.insert(configfiles, v)
--- end
--- end
return output
end
@@ -122,7 +98,7 @@ local function searchforconfigfiles()
end
-- Debug option (adds the sampleconfig content)
--- table.insert(configfiles, "/usr/share/acf/app/tinydns/sampleconfig.conf")
+ table.insert(configfiles, "/usr/share/acf/app/tinydns/sampleconfig.conf")
end
searchforconfigfiles()
@@ -147,17 +123,9 @@ end
local function recursedomains(t,array,maxn,currnum)
if not (currnum) then currnum = maxn + 1 end
currnum = currnum - 1
- -- FIXME: The current level should hold information on previous level too!
if not (currnum == 0) then
--- if (array) and (type(array[t[currnum]]) == "table") then
--- local k,v = pairs(array[t[currnum]]) do
--- end
--- end
-
if not (array[t[currnum]]) then
--- if not (array[(table.concat(t,"."))]) then
--- array[t[currnum]] = {}
array[t[currnum]] = {}
end
recursedomains(t,array[t[currnum]],maxn,currnum)
@@ -214,11 +182,30 @@ end
-- ################################################################################
-- PUBLIC FUNCTIONS
+-- This function could be used to check that valid parameters are used in different places
+function check_signs(sign)
+ local output = {}
+ local output = {prefix={
+ ['.']="Name server for your domain",
+ ['&']="Name server",
+ ['=']="Host",
+ ['+']="Alias",
+ ['@']="Mail exchanger",
+ ['=']="Host",
+ ['^']="PTR record",
+ ['C']="Canonical Name",
+ ['Z']="SOA record",
+ [':']="Generic record",
+ ['%']="Client location",
+ }}
+ output = output[sign]
+ return output
+end
+
-- Present some general status
function getstatus()
local status = {}
local version,versionerrtxt = get_version()
- local config = getconfig()
status.version = cfe({ name = "version",
label="Program version",
value=version,
@@ -229,29 +216,20 @@ function getstatus()
value=procps.pidof(processname),
})
- status.locations = config.locations
- status.domains = config.domains
-
return status
end
-- Return config-information
-function getconfig()
+function getlocations(self,filter_type)
local config = {}
local configobjects = {}
local locations = {}
- local domains = {}
local debug
local version,versionerrtxt = get_version()
local listenaddr = getopts.getoptsfromfile_onperline(configfile,"IP") or {}
- config.listen = cfe({
- name = "listen",
- label="IP address to listen on",
- value=listenaddr.IP or "",
- })
- --Loop through all available configfiles
+ -- Loop through all available configfiles
for k,v in pairs(configfiles) do
local filecontent, fileresult
fileresult, filecontent = get_value_from_file(v)
@@ -275,14 +253,52 @@ function getconfig()
end
table.insert(locations[filecontent_table[2]], filecontent_table[3])
end
+ end
+ end
+
+ return locations
+end
+
+function getconfig(self,filter_type)
+ local config = {}
+ local listenaddr = getopts.getoptsfromfile_onperline(configfile,"IP") or {}
+
+ config.listen = cfe({
+ name = "listen",
+ label="IP address to listen on",
+ value=listenaddr.IP or "",
+ })
+
+ return config
+end
+
+-- If you enter 'filter_type' (this should be one of the options found in local function check_signs() ) then
+-- the output will be filtered to only contain this type of data.
+function getconfigobjects(self,filter_type)
+ local domains = {}
+
+ --Loop through all available configfiles
+ for k,v in pairs(configfiles) do
+ local filecontent, fileresult
+ fileresult, filecontent = get_value_from_file(v)
+ for kk,vv in pairs(filecontent) do
+ local domaindetails = {}
+ local filecontent_table = split_config_items(vv)
-- Create domain information tables
local domain, level1, level2, level3, level4, level5, level6, levels
- if (filecontent_table[1] == "&") then
- local descr=check_signs("prefix")
- domain = format.string_to_table(filecontent_table[2], "%.")
- if (domain[#domain] ~= "arpa") then
+ -- * START * COMMONT SETTINGS ***************************************************************************************
+ local descr=check_signs("prefix")
+ -- Use only configs that has a valid prefix
+ -- We filter away location-definitions
+ -- If function is called with some filter options... then show only the filtered values
+ if ( not (filter_type) or
+ ( (filter_type) and (filter_type == filecontent_table[1]))) and
+ (descr[filecontent_table[1]]) and not
+ (filecontent_table[1] == "%") then
+
+ domain = format.string_to_table(filecontent_table[2], "%.")
-- We rebuild the table and add previous level-information to the current level
for i = table.maxn(domain),2,-1 do
domain[i-1] = domain[i-1] .. "." .. domain[i]
@@ -290,156 +306,235 @@ function getconfig()
-- This is the main information on each object
domaindetails = cfe ({
- name=filecontent_table[4],
- label=filecontent_table[4],
+ name=filecontent_table[2],
+ label=filecontent_table[2],
})
+
-- Add details to the previous object
table.insert(domaindetails, cfe ({
- name=type,
- label="Type:",
+ name="type",
+ label="Type",
value=descr[filecontent_table[1]],
}))
- table.insert(domaindetails, cfe ({
- name=domain,
- label="Domain:",
- value=filecontent_table[2],
- }))
- table.insert(domaindetails, cfe ({
- name=ip,
- label="IP address:",
- value=filecontent_table[3],
- }))
- table.insert(domaindetails, cfe ({
- name=ns,
- label="Name server:",
- value=filecontent_table[4],
- }))
- table.insert(domaindetails, cfe ({
- name=ttl,
- label="TimeToLive:",
- value=filecontent_table[5],
- }))
-
- table.insert(domaindetails, cfe ({
- name=debug,
- label="Debug:",
- value=table.concat(filecontent_table,":"),
- }))
+ -- Set values and labels for field #3
+ local name = "ip"
+ local label = "IP address"
+ -- Some configs uses third column in some other way
+ if (filecontent_table[1] == "^") or (filecontent_table[1] == "C") then
+ name = "pointdomain"
+ label = "Domain"
+ end
+ if (filecontent_table[1] == "Z") then
+ name = "mname"
+ label = "Primary nameserver"
+ end
+ if (filecontent_table[1] == ":") then
+ name = "rectype"
+ label = "Type of record"
+ end
+ if (filecontent_table[3]) and (#filecontent_table[3]> 0) and (name) then
+ table.insert(domaindetails, cfe ({
+ name=name,
+ label=label,
+ value=filecontent_table[3],
+ }))
end
- end
+ -- Set values and labels for field #4
+ local name = "nameserver"
+ local label = "Name server"
+ -- Some configs uses third column in some other way
+ if (filecontent_table[1] == "=") or (filecontent_table[1] == "+") then
+ name = "ttl"
+ label = "Time to live"
+ end
+ if (filecontent_table[1] == "@") then
+ name = "mx"
+ label = "Mail exchanger"
+ end
+ if (filecontent_table[4]) and (#filecontent_table[4]> 0) and (name) then
+ table.insert(domaindetails, cfe ({
+ name=name,
+ label=label,
+ value=filecontent_table[4],
+ }))
+ end
- local value = filecontent_table[2]
- local currenttable
- if (type(domain) == "table") then
- currenttable = recursedomains(domain, domains, table.maxn(domain))
- end
+ -- Set values and labels for field #5
+ local name = nil
+ local label = nil
+ -- Some configs uses third column in some other way
+ if (filecontent_table[1] == ".") or (filecontent_table[1] == "&") then
+ name = "ttl"
+ label = "Time to live"
+ end
+ if (filecontent_table[1] == "=") or (filecontent_table[1] == "+") then
+ name = "timestamp"
+ label = "Time stamp"
+ end
+ if (filecontent_table[1] == "@") then
+ name = "dist"
+ label = "Distance"
+ end
+ if (filecontent_table[5]) and (#filecontent_table[5]> 0) and (name) then
+ table.insert(domaindetails, cfe ({
+ name=name,
+ label=label,
+ value=filecontent_table[5],
+ }))
+ end
- -- FIXME: This is where we should put the information into the table!
- if (domaindetails.value) then
- table.insert (currenttable , domaindetails)
- end
+ -- Set values and labels for field #6
+ local name = nil
+ local label = nil
+ -- Some configs uses third column in some other way
+ if (filecontent_table[1] == ".") or (filecontent_table[1] == "&") then
+ name = "ttl"
+ label = "Time to live"
+ end
+ if (filecontent_table[1] == "=") or (filecontent_table[1] == "+") then
+ name = "timestamp"
+ label = "Time stamp"
+ end
+ if (filecontent_table[1] == "@") then
+ name = "dist"
+ label = "Distance"
+ end
+ if (filecontent_table[1] == "Z") then
+ name = "ser"
+ label = "Serial number"
+ end
---[[
- if (type(domain) == "table") then
- levels = table.maxn(domain)
- level1 = domain[levels]
-
+ if (filecontent_table[6]) and (#filecontent_table[6]> 0) and (name) then
+ table.insert(domaindetails, cfe ({
+ name=name,
+ label=label,
+ value=filecontent_table[6],
+ }))
+ end
- if (level1) then
- level2 = (domain[levels-1] or "unknown") .. "."
+ -- Set values and labels for field #7
+ local name = nil
+ local label = nil
+ -- Some configs uses third column in some other way
+ if (filecontent_table[1] == ".") or (filecontent_table[1] == "&") then
+ name = "timestamp"
+ label = "Time stamp"
end
- if (level2) and (domain[levels-2]) then
- level3 = domain[levels-2] .. "." .. level2
+ if (filecontent_table[1] == "=") or (filecontent_table[1] == "+") or
+ (filecontent_table[1] == "-") or (filecontent_table[1] == "^") or
+ (filecontent_table[1] == "C") then
+ name = "location"
+ label = "Location"
end
- if (level3) and (domain[levels-3]) then
- level4 = domain[levels-3] .. "." .. level3
+ if (filecontent_table[1] == "@") then
+ name = "ttl"
+ label = "Time to live"
end
- if (level4) and (domain[levels-4]) then
- level5 = domain[levels-4] .. "." .. level4
+ if (filecontent_table[1] == "Z") then
+ name = "ref"
+ label = "Refresh time"
end
- if (level5) and (domain[levels-5]) then
- level6 = domain[levels-5] .. "." .. level5
+ if (filecontent_table[7]) and (#filecontent_table[7]> 0) and (name) then
+ table.insert(domaindetails, cfe ({
+ name=name,
+ label=label,
+ value=filecontent_table[7],
+ }))
end
- if (level6) and (domain[levels-6]) then
- level7 = domain[(levels-6)] .. "." .. level6
+
+ -- Set values and labels for field #8
+ local name = nil
+ local label = nil
+ -- Some configs uses third column in some other way
+ if (filecontent_table[1] == ".") or (filecontent_table[1] == "&") then
+ name = "timestamp"
+ label = "Time stamp"
end
- end
- if (level1 ) and (#level1 > 0) and not (domain[levels] == "arpa") then
- if not (domains[level1]) then
- domains[level1] = {}
+ if (filecontent_table[1] == "=") or (filecontent_table[1] == "+") or
+ (filecontent_table[1] == "-") or (filecontent_table[1] == "^") or
+ (filecontent_table[1] == "C") then
+ name = "location"
+ label = "Location"
+ end
+ if (filecontent_table[1] == "@") then
+ name = "ttl"
+ label = "Time to live"
+ end
+ if (filecontent_table[1] == "Z") then
+ name = "ref"
+ label = "Refresh time"
end
- if (level2) and (#level2 > 0) then
- if not (domains[level1][level2]) then
- domains[level1][level2] = {}
+ if (filecontent_table[8]) and (#filecontent_table[8]> 0) and (name) then
+ table.insert(domaindetails, cfe ({
+ name=name,
+ label=label,
+ value=filecontent_table[8],
+ }))
+ end
+
+ -- Set values and labels for field #9-12
+ if (filecontent_table[1] == "Z") then
+ if (filecontent_table[9]) and (#filecontent_table[9]> 0) then
+ table.insert(domaindetails, cfe ({
+ name="min",
+ label="Minimum time",
+ value=filecontent_table[9],
+ }))
+ end
+ if (filecontent_table[10]) and (#filecontent_table[10]> 0) then
+ table.insert(domaindetails, cfe ({
+ name="ttl",
+ label="Time to live",
+ value=filecontent_table[10],
+ }))
+ end
+ if (filecontent_table[11]) and (#filecontent_table[11]> 0) then
+ table.insert(domaindetails, cfe ({
+ name="timestamp",
+ label="Time stamp",
+ value=filecontent_table[11],
+ }))
+ end
+ if (filecontent_table[12]) and (#filecontent_table[12]> 0) then
+ table.insert(domaindetails, cfe ({
+ name="location",
+ label="Location",
+ value=filecontent_table[12],
+ }))
end
- if (level3) and (#level3 > 0) then
- if not (domains[level1][level2][level3]) then
- domains[level1][level2][level3] = {}
- end
- if (level4) and (#level4 > 0) then
- if not (domains[level1][level2][level3][level4]) then
- domains[level1][level2][level3][level4] = {}
- end
- if (level5) and (#level5 > 0) then
- if not (domains[level1][level2][level3][level4][level5]) then
- domains[level1][level2][level3][level4][level5] = {}
- end
- if (level6) and (#level6 > 0) then
- if not (domains[level1][level2][level3][level4][level5][level6]) then
- domains[level1][level2][level3][level4][level5][level6] = {}
- end
- if (level7) and (#level7 > 0) then
- if not (domains[level1][level2][level3][level4][level5][level6][level7]) then
- domains[level1][level2][level3][level4][level5][level6][level7] = {}
- domains[level1][level2][level3][level4][level5][level6][level7] = {}
- end
- else
- table.insert(domains[level1][level2][level3][level4][level5][level6], filecontent_table[4])
- end --level7
- else
- table.insert(domains[level1][level2][level3][level4][level5], filecontent_table[4])
- end --level6
- else
- table.insert(domains[level1][level2][level3][level4], filecontent_table[4])
- end --level5
- else
- table.insert(domains[level1][level2][level3], filecontent_table[4])
- end --level4
- else
- table.insert(domains[level1][level2], filecontent_table[4])
- end --level3
- else
- table.insert(domains[level1], filecontent_table[4])
- end --level2
- end --level1
+ end
+
+
+--[[
+ table.insert(domaindetails, cfe ({
+ name="debug",
+ label="Debug",
+ value=filter_type,
+ }))
--]]
+ end
+ -- * END * COMMONT SETTINGS ***************************************************************************************
+
+ -- Inject the previous data into the right table
+ local value = filecontent_table[2]
+ local currenttable
+ if (type(domain) == "table") then
+ currenttable = recursedomains(domain, domains, table.maxn(domain))
+ end
+
+ if (domaindetails.value) then
+ table.insert (currenttable , domaindetails)
+ end
end
end
- config.locations = cfe({
- name="locations",
- label="Locations",
- value=locations,
- })
-
- config.domains = cfe({
- name="domains",
- label="Domains",
- value=domains,
- })
--- config.domains = debug
----[[
- config.configitems = cfe({
- name = "configitems",
- label="Config items",
- value=configobjects,
- })
---]]
- return config
+ -- TODO: Sort the domains table!
+
+ return domains
end