summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-04-04 20:25:46 +0000
committerMika Havela <mika.havela@gmail.com>2008-04-04 20:25:46 +0000
commitea416afe39d2b4d796ccbfe0a7819968ef2d6f63 (patch)
tree8293e068021a298b6d3b28494a4298583e71470c
parenta084d26cb2a9226faa39750e32c3fbacf217c16c (diff)
downloadacf-tinydns-ea416afe39d2b4d796ccbfe0a7819968ef2d6f63.tar.bz2
acf-tinydns-ea416afe39d2b4d796ccbfe0a7819968ef2d6f63.tar.xz
Now you can view/edit all files in /etc/tinydns/.
You shouldn't be able to view/edit other files than in /etc/tinydns (and it's subfolders). git-svn-id: svn://svn.alpinelinux.org/acf/tinydns/trunk@948 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--tinydns-controller.lua19
-rw-r--r--tinydns-edit-html.lsp1
-rw-r--r--tinydns-expert-html.lsp2
-rw-r--r--tinydns-model.lua34
4 files changed, 50 insertions, 6 deletions
diff --git a/tinydns-controller.lua b/tinydns-controller.lua
index f6c5268..502af03 100644
--- a/tinydns-controller.lua
+++ b/tinydns-controller.lua
@@ -233,21 +233,34 @@ function edit(self)
-- Save changes
if ( self.clientdata.cmdsave) then
- local filetochange = cfe ({ name=self.clientdata.filename, value=self.clientdata.filecontent, })
+ local filetochange = cfe ({ name=self.clientdata.name, value=self.clientdata.filecontent, })
modifications = self.model:updatefilecontent(filetochange)
- self.clientdata.name = self.clientdata.filename
+-- if not (modifications) then
+-- self.conf.action = "status"
+-- self.conf.type = "redir"
+-- error (self.conf)
+-- end
+ end
+
+ if not (self.model:valid_filename(self.clientdata.name)) then
+ self.conf.action = "status"
+ self.conf.type = "redir"
+ error (self.conf)
end
local status = getstatus(self)
local file = self.model:get_filedetails(self.clientdata.name)
+
-- Add a cmd button to the view
file.cmdsave = cfe({ name="cmdsave",
label="Save/Apply above settings",
value="Save",
type="submit",
- disabled="yes",
})
+ if (modifications) then
+ file.cmdsave.descr="* Changes has been saved!"
+ end
return {
option={ script=ENV["SCRIPT_NAME"],
diff --git a/tinydns-edit-html.lsp b/tinydns-edit-html.lsp
index cf70091..e5bb6ba 100644
--- a/tinydns-edit-html.lsp
+++ b/tinydns-edit-html.lsp
@@ -65,6 +65,7 @@ displayinfo(myform,tags,"viewonly")
<H3>FILE CONTENT</H3>
<?
local myform = form.file
+io.write('<input type="hidden" value="' .. myform.filename.value .. '" name="name">')
io.write(html.form[myform.filecontent.type](myform.filecontent))
?>
diff --git a/tinydns-expert-html.lsp b/tinydns-expert-html.lsp
index 1437ad8..7744934 100644
--- a/tinydns-expert-html.lsp
+++ b/tinydns-expert-html.lsp
@@ -43,7 +43,7 @@ displayinfo(myform,tags,"viewonly")
<h1>CONFIGURATION</h1>
<h2>Expert config</h2>
-<h3>List of configfiles</h3>
+<h3>List of files</h3>
<? local myform = form.status.configfiles ?>
<TABLE>
diff --git a/tinydns-model.lua b/tinydns-model.lua
index 11f1101..24e0437 100644
--- a/tinydns-model.lua
+++ b/tinydns-model.lua
@@ -12,7 +12,7 @@ local configitems = {}
local processname = "tinydns"
local configfile = "/etc/conf.d/" .. processname
-local baseurl = "/etc/tinydns/"
+local baseurl = "/etc/tinydns"
local initdoptions = getopts.getoptsfromfile_onperline("/etc/init.d/" .. processname)
if (initdoptions) then
configdir = initdoptions.DATADIR
@@ -194,9 +194,22 @@ local function recursedomains(t,array,maxn,currnum)
end
end
+local function validfilename(path)
+ for k,v in pairs(getfilelist()) do
+ if (v == path) then
+ return true
+ end
+ end
+ return false, "Not a valid filename!"
+end
+
-- ################################################################################
-- PUBLIC FUNCTIONS
+function valid_filename(self,path)
+ return validfilename(path)
+end
+
-- This function could be used to check that valid parameters are used in different places
function check_signs(sign)
local output = {}
@@ -733,6 +746,9 @@ function get_filedetails(self,path)
-- else
-- path = configfile
-- end
+ if not (validfilename(path)) then
+ return false, "Not a valid filename!"
+ end
local file = {}
local filedetails = {}
local config = {}
@@ -743,7 +759,7 @@ function get_filedetails(self,path)
else
config = {}
config.filename = {}
- config["filename"]["errtxt"]="Config file '".. path .. "' is missing!"
+ config["filename"]["errtxt"]="Config file '".. tostring(path) .. "' is missing!"
end
file["filename" .. (num or "")] = cfe({
@@ -786,3 +802,17 @@ function get_filedetails(self,path)
return file
end
+function updatefilecontent (self, filetochange)
+ local path = filetochange.name
+ local modifications = filetochange.value
+ if not (fs.is_file(path)) then
+ return false, "Not a filename"
+ end
+ if (validfilename(path)) then
+ fs.write_file(path, format.dostounix(modifications))
+ return true
+ else
+ return false, "Not a valid filename!"
+ end
+ return false, "Something went wrong!"
+end