diff options
Diffstat (limited to 'tinydns-model.lua')
-rw-r--r-- | tinydns-model.lua | 73 |
1 files changed, 39 insertions, 34 deletions
diff --git a/tinydns-model.lua b/tinydns-model.lua index e75f937..43bf8ea 100644 --- a/tinydns-model.lua +++ b/tinydns-model.lua @@ -89,7 +89,7 @@ local function split_config_items(orgitem) local output = {} output = format.string_to_table(string.sub(orgitem,2),delimiter) output.type = string.sub(orgitem,1,1) - output.label = descr['prefix'][output.type] or "unknown" + output.label = descr['prefix'][output.type] return output end @@ -199,42 +199,47 @@ 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) +function getconfigobjects(file_name, filter_type) local configobjects = {} --Loop through all available configfiles for i,filename in pairs(configfiles) do - local filecontent, fileresult - fileresult, filecontent = get_value_from_file(filename) - for j,configline in pairs(filecontent) do - local domaindetails = {} - local filecontent_table = split_config_items(configline) - filecontent_table.configline = configline - - -- Use only configs that has a valid prefix - -- 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.type)) ) - and (filecontent_table.label) - then - local entry = {} - for i,value in ipairs(filecontent_table) do - entry[i] = value + if not file_name or file_name == filename then + local filecontent = fs.read_file_as_array(filename) + for linenumber,configline in ipairs(filecontent) do + local domaindetails = {} + local filecontent_table = split_config_items(configline) + filecontent_table.configline = configline + + -- Use only configs that has a valid prefix + -- 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.type)) ) + and (filecontent_table.label) + then + local entry = {} + for i,value in ipairs(filecontent_table) do + entry[i] = value + end + -- add in the filename and line number + entry.filename = filename + entry.linenumber = linenumber + + -- we're gonna add a reverse domain name to make it easier to sort + local domain = {} + for mt in string.gmatch(entry[1], "([^.]+)") do + table.insert(domain, mt) + end + local reversedomain = {} + for i=#domain,1,-1 do + table.insert(reversedomain, domain[i]) + end + entry.sort = table.concat(reversedomain, ".") + + -- add it to the table + if not configobjects[filecontent_table.type] then + configobjects[filecontent_table.type] = {label=filecontent_table.label, fieldlabels=descr.fieldlabels[filecontent_table.type]} + end + table.insert(configobjects[filecontent_table.type], entry) end - -- we're gonna add a reverse domain name to make it easier to sort - local domain = {} - for mt in string.gmatch(entry[1], "([^.]+)") do - table.insert(domain, mt) - end - local reversedomain = {} - for i=#domain,1,-1 do - table.insert(reversedomain, domain[i]) - end - entry.sort = table.concat(reversedomain, ".") - - -- add it to the table - if not configobjects[filecontent_table.type] then - configobjects[filecontent_table.type] = {label=filecontent_table.label, fieldlabels=descr.fieldlabels[filecontent_table.type]} - end - table.insert(configobjects[filecontent_table.type], entry) end end end @@ -261,7 +266,7 @@ function getconfigobjects(self, filter_type) end end - return configobjects + return cfe({ type="structure", value=configobjects, label="DNS Entries", filename=file_name }) end function getfilelist () |