summaryrefslogtreecommitdiffstats
path: root/tinydns-model.lua
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 /tinydns-model.lua
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
Diffstat (limited to 'tinydns-model.lua')
-rw-r--r--tinydns-model.lua34
1 files changed, 32 insertions, 2 deletions
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