summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tinydns-controller.lua18
-rw-r--r--tinydns-listfiles-html.lsp2
-rw-r--r--tinydns-model.lua70
3 files changed, 58 insertions, 32 deletions
diff --git a/tinydns-controller.lua b/tinydns-controller.lua
index e0e7e2a..1856fa2 100644
--- a/tinydns-controller.lua
+++ b/tinydns-controller.lua
@@ -9,7 +9,7 @@ function status(self)
end
function view(self)
- return self.model.getconfigobjects(self.clientdata.filename)
+ return self.model.getconfigobjects(self.clientdata.filename, sessiondata.userinfo.dnsfiles)
end
function startstop(self)
@@ -21,14 +21,16 @@ function config(self)
end
function newfile(self)
- return controllerfunctions.handle_form(self, self.model.getnewconfigfile, self.model.createconfigfile, self.clientdata, "Create", "Create New Config File", "Config File Created", "listfiles")
+ return controllerfunctions.handle_form(self, self.model.getnewconfigfile, function(value)
+ return self.model.createconfigfile(self, value, sessiondata.userinfo.dnsfiles)
+ end, self.clientdata, "Create", "Create New Config File", "Config File Created", "listfiles")
end
function listfiles(self)
- local configfiles = self.model.getfilelist()
+ local configfiles = self.model.getfilelist(sessiondata.userinfo.dnsfiles)
local config = {}
for k,v in pairs(configfiles.value) do
- local filedetails = self.model.get_filedetails(v)
+ local filedetails = self.model.get_filedetails(v, sessiondata.userinfo.dnsfiles)
table.insert(config,filedetails)
end
@@ -36,7 +38,11 @@ function listfiles(self)
end
function editfile(self)
- config = controllerfunctions.handle_form(self, function() return self.model.get_filedetails(self.clientdata.filename) end, self.model.set_filedetails, self.clientdata, "Save", "Edit Config File", "Config File Saved")
+ config = controllerfunctions.handle_form(self, function()
+ return self.model.get_filedetails(self.clientdata.filename, sessiondata.userinfo.dnsfiles)
+ end, function(value)
+ return self.model.set_filedetails(value, sessiondata.userinfo.dnsfiles)
+ end, self.clientdata, "Save", "Edit Config File", "Config File Saved")
if self.clientdata.linenumber and validator.is_integer(self.clientdata.linenumber) then
config.value.filecontent.linenumber = self.clientdata.linenumber
@@ -45,5 +51,5 @@ function editfile(self)
end
function delete(self)
- return self:redirect_to_referrer(self.model.remove_file(self.clientdata.filename))
+ return self:redirect_to_referrer(self.model.remove_file(self.clientdata.filename, sessiondata.userinfo.dnsfiles))
end
diff --git a/tinydns-listfiles-html.lsp b/tinydns-listfiles-html.lsp
index 1b53187..46753ec 100644
--- a/tinydns-listfiles-html.lsp
+++ b/tinydns-listfiles-html.lsp
@@ -35,7 +35,7 @@ io.write("</span>")
<? end ?>
</TABLE>
-<? if viewlibrary and viewlibrary.dispatch_component then
+<? if viewlibrary and viewlibrary.dispatch_component and session.permissions.tinydns.newfile then
local newfileform = viewlibrary.dispatch_component("newfile", nil, true) ?>
<h2>Create new Domain</h2>
<?
diff --git a/tinydns-model.lua b/tinydns-model.lua
index 7a0f411..9f73000 100644
--- a/tinydns-model.lua
+++ b/tinydns-model.lua
@@ -91,21 +91,27 @@ local function split_config_items(orgitem)
return output
end
--- Feed the configfiles table with list of all availage configfiles
-local function searchforconfigfiles()
+-- Feed the configfiles table with list of all available and allowed configfiles
+local function searchforconfigfiles(allowedlist)
+ if #configfiles > 0 then return configfiles end
local cnffile = {}
recursedir(configdir, cnffile)
- for k,v in pairs(cnffile) do
- local configcontent = get_value_from_file(v)
- if (configcontent) then
- table.insert(configfiles, v)
+ if allowedlist then
+ local reverseallowed = {}
+ for x,name in ipairs(allowedlist) do reverseallowed[name] = x end
+ for k,v in pairs(cnffile) do
+ if reverseallowed[v] then
+ table.insert(configfiles, v)
+ end
end
+ else
+ configfiles = cnffile
end
+ return configfiles
end
-searchforconfigfiles()
local function validfilename(path)
- for k,v in pairs(getfilelist().value) do
+ for k,v in pairs(configfiles) do
if (v == path) then
return true
end
@@ -129,12 +135,6 @@ function getstatus()
value=configdir,
})
- status.value.configfiles = cfe({
- type="list",
- label="Config files",
- value=configfiles,
- })
-
local config = getconfig()
status.value.listen = config.value.listen
@@ -171,7 +171,8 @@ 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(file_name, filter_type)
+function getconfigobjects(file_name, allowedfiles, filter_type)
+ configfiles = searchforconfigfiles(allowedfiles)
local configobjects = {}
--Loop through all available configfiles
for i,filename in pairs(configfiles) do
@@ -228,18 +229,24 @@ function getconfigobjects(file_name, filter_type)
return cfe({ type="structure", value=configobjects, label="DNS Entries", filename=file_name, fieldlabels=descr.fieldlabels })
end
-function getfilelist ()
- local listed_files = {}
- recursedir(configdir, listed_files)
-
- return cfe({ type="list", value=listed_files, label="List of config files" })
+function getfilelist(allowedfiles)
+ configfiles = searchforconfigfiles(allowedfiles)
+ return cfe({ type="list", value=configfiles, label="List of config files" })
end
-function get_filedetails(path)
- return modelfunctions.getfiledetails(path)
+function get_filedetails(path, allowedfiles)
+ configfiles = searchforconfigfiles(allowedfiles)
+ if not validfilename(path) then
+ local result = modelfunctions.getfiledetails("")
+ result.value.filename.value = path
+ return result
+ else
+ return modelfunctions.getfiledetails(path)
+ end
end
-function set_filedetails (filedetails)
+function set_filedetails (filedetails, allowedfiles)
+ configfiles = searchforconfigfiles(allowedfiles)
filedetails.value.filecontent.value = string.gsub(format.dostounix(filedetails.value.filecontent.value), "\n+$", "")
local success, errtxt = validfilename(filedetails.value.filename.value)
if success then
@@ -259,7 +266,7 @@ function getnewconfigfile()
return cfe({ type="group", value=options, label="New config file" })
end
-function createconfigfile(configfile)
+function createconfigfile(self, configfile, allowedfiles)
configfile.errtxt = "Failed to create file"
local path = configfile.value.filename.value
local validfilepath, filepatherror = validator.is_valid_filename(path,configdir)
@@ -270,6 +277,18 @@ function createconfigfile(configfile)
local file = io.open(path, "w")
file:close()
configfile.errtxt = nil
+
+ -- We have to add this file to the allowed list
+ local found = false
+ for i,name in ipairs(allowedfiles) do
+ if name == configfile.value.filename.value then found = true break end
+ end
+ if not found then
+ -- this modifies the session
+ allowedfiles[#allowedfiles + 1] = configfile.value.filename.value
+ require("authenticator")
+ authenticator.change_setting(self, self.sessiondata.userinfo.userid, "dnsfiles", allowedfiles)
+ end
end
else
configfile.value.filename.errtxt = filepatherror
@@ -278,7 +297,8 @@ function createconfigfile(configfile)
return configfile
end
-function remove_file(path)
+function remove_file(path, allowedfiles)
+ configfiles = searchforconfigfiles(allowedfiles)
local success = "Failed to delete file"
local errtxt
if not (fs.is_file(path)) then