summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tinydns-controller.lua73
-rw-r--r--tinydns-edit-html.lsp (renamed from tinydns-edit_records-html.lsp)93
-rw-r--r--tinydns-expert-html.lsp69
-rw-r--r--tinydns-model.lua88
-rw-r--r--tinydns.menu1
5 files changed, 281 insertions, 43 deletions
diff --git a/tinydns-controller.lua b/tinydns-controller.lua
index 8bf4769..f6c5268 100644
--- a/tinydns-controller.lua
+++ b/tinydns-controller.lua
@@ -192,6 +192,79 @@ function status(self)
config=config,
}
end
+function expert(self)
+ local cmdmanagement, cmdmanagementresult
+ if ( self.clientdata.cmdmanagement) then
+ cmdmanagement = cfe({
+ name="cmdmanagement",
+ value=string.lower(self.clientdata.cmdmanagement),
+ })
+ cmdmanagementresult, cmdmanagement = self.model:startstop_service( cmdmanagement )
+ end
+
+ local status = getstatus(self)
+ local config = self.model:getfilelist()
+
+ return {
+ option={ script=ENV["SCRIPT_NAME"],
+ prefix=self.conf.prefix,
+ controller = self.conf.controller,
+ action = "expert",
+ link = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller, },
+ cmdmanagement = cmdmanagement,
+ management = management,
+ config = config,
+ status = status,
+ startstop = startstop,
+ debugclientdata = self.clientdata,
+ }
+
+end
+
+function edit(self)
+ local cmdmanagement, cmdmanagementresult, modifications
+ if ( self.clientdata.cmdmanagement) then
+ cmdmanagement = cfe({
+ name="cmdmanagement",
+ value=string.lower(self.clientdata.cmdmanagement),
+ })
+ cmdmanagementresult, cmdmanagement = self.model:startstop_service( cmdmanagement )
+ end
+
+ -- Save changes
+ if ( self.clientdata.cmdsave) then
+ local filetochange = cfe ({ name=self.clientdata.filename, value=self.clientdata.filecontent, })
+ modifications = self.model:updatefilecontent(filetochange)
+ self.clientdata.name = self.clientdata.filename
+ 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",
+ })
+
+ return {
+ option={ script=ENV["SCRIPT_NAME"],
+ prefix=self.conf.prefix,
+ controller = self.conf.controller,
+ action = "edit",
+ link = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller, },
+ cmdmanagement = cmdmanagement,
+ modifications = modifications,
+ management = management,
+ file = file,
+ status = status,
+ startstop = startstop,
+ debugclientdata = self.clientdata,
+ }
+
+end
--[=[
function edit_records(self,types,record,errormessage)
local recorddetails = {}
diff --git a/tinydns-edit_records-html.lsp b/tinydns-edit-html.lsp
index 4241540..cf70091 100644
--- a/tinydns-edit_records-html.lsp
+++ b/tinydns-edit-html.lsp
@@ -6,7 +6,6 @@ io.write(html.cfe_unpack(form))
io.write("</span>")
--]]
?>
-
<?
function displayinfo(myform,tags,viewtype)
for k,v in pairs(tags) do
@@ -41,63 +40,71 @@ function displayinfo(myform,tags,viewtype)
end
?>
-<?
-function displayinfo_special(myform)
- for i=1,#myform do
- local v = myform[i]
- if (v) and (v["value"]) then
- io.write("\n\t<DT")
- if (#v.errtxt > 0) then
- v.class = "error"
- io.write(" class='error'")
- end
- io.write(">" .. v.label .. "</DT>")
- io.write("\n\t\t<DD>")
- io.write(html.form[v.type](v))
- if (v.descr) and (#v.descr > 0) then io.write("\n\t\t<P CLASS='descr'>" .. string.gsub(v.descr, "\n", "<BR>") .. "</P>") end
- if (#v.errtxt > 0) then io.write("\n\t\t<P CLASS='error'>" .. string.gsub(v.errtxt, "\n", "<BR>") .. "</P>") end
- io.write("\n\t\t</DD>\n")
- end
- end
-end
+<H1>SYSTEM INFO</H1>
+<DL>
+<?
+local myform = form.status
+local tags = { "status", "version", "autostart", }
+displayinfo(myform,tags,"viewonly")
?>
+</DL>
-<form name="cmd" action="<?= form.option.link ?>/<?= form.option.action ?>" method="POST">
-<H1>EDIT PROPERTIES</H1>
+<form name="myform" action="" method="POST">
+<h1>CONFIGURATION</h1>
+<H2>Expert config</H2>
+<h3>File details</h3>
<DL>
<?
-local myform = form.edit
-displayinfo_special(myform)
+local myform = form.file
+local tags = { "filename", "filesize", "mtime", "sumerrors", }
+displayinfo(myform,tags,"viewonly")
?>
+</DL>
-<?
-local tags = {"cmdsave", "cmddelete", }
-local myform = form
-displayinfo(myform,tags)
+<H3>FILE CONTENT</H3>
+<?
+local myform = form.file
+io.write(html.form[myform.filecontent.type](myform.filecontent))
?>
-<? -- Add the field that holds the filename
-local myform = form.edit.filename
-if (type(myform) == "table") then
- io.write(html.form[myform.type](myform))
-end
-local myform = form.edit.orgrecord
-if (type(myform) == "table") then
- io.write(html.form[myform.type](myform))
-end
-local myform = form.edit.actiontype
-if (type(myform) == "table") then
- io.write(html.form[myform.type](myform))
-end
+<H2>SAVE AND APPLY ABOVE SETTINGS</H2>
+<DL>
+<?
+local tags = { "cmdsave", }
+displayinfo(myform,tags)
?>
-
</DL>
</form>
+<? -- MANAGEMENT BUTTONS
+local cmdform = form.management
+local cmdresult = form.cmdmanagement
+local tags = { "start", "stop", "restart" }
+if (cmdform) and (cmdform[tags[1]]) then
+
+ io.write('<form name="management" action="" method="POST">')
+ io.write('<H1>MANAGEMENT</H1>')
+ io.write('<dl>')
+ io.write('<dt>' .. cmdform[tags[1]]["label"] .. '</dt>')
+ io.write('<dd>')
+ for k,v in pairs(tags) do
+ if (cmdform[v]) then
+ io.write(html.form[cmdform[v].type](cmdform[v]))
+ end
+ end
+ io.write('</dd>')
+
+ if (cmdresult) and (cmdresult.action) and (#cmdresult.action.descr > 0) then
+ io.write('<dt>' .. cmdresult.label .. '</dt>')
+ io.write('<dd><pre>' .. cmdresult.action.descr .. '</pre></dd>')
+ end
+ io.write('</dl></form>')
+end ?>
+
<?
----[[ DEBUG INFORMATION
+--[[ DEBUG INFORMATION
io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
io.write(html.cfe_unpack(form))
io.write("</span>")
diff --git a/tinydns-expert-html.lsp b/tinydns-expert-html.lsp
new file mode 100644
index 0000000..1437ad8
--- /dev/null
+++ b/tinydns-expert-html.lsp
@@ -0,0 +1,69 @@
+<? local form = ... ?>
+<?
+--[[ DEBUG INFORMATION
+io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
+io.write(html.cfe_unpack(form))
+io.write("</span>")
+--]]
+?>
+
+<?
+function displayinfo(myform,tags,viewonly)
+ io.write("<DL>")
+ for k,v in pairs(tags) do
+ if (myform[v]) and (myform[v]["value"]) then
+ local val = myform[v]
+ io.write("\t<DT")
+ if (#val.errtxt > 0) then
+ val.class = "error"
+ io.write(" class='error'")
+ end
+ io.write(">" .. val.label .. "</DT>\n")
+ if (viewonly) then
+ io.write("\t\t<DD>" .. val.value .. "\n")
+ else
+ io.write("\t\t<DD>" .. html.form[val.type](val) .. "\n")
+ end
+ if (val.descr) and (#val.descr > 0) then io.write("\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>\n") end
+ if (#val.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>\n") end
+ io.write("\t\t</DD>\n")
+ end
+ end
+ io.write("</DL>")
+end
+?>
+
+<H1>SYSTEM INFO</H1>
+<?
+local myform = form.status
+local tags = { "status", "version", "autostart", }
+displayinfo(myform,tags,"viewonly")
+?>
+
+<h1>CONFIGURATION</h1>
+
+<h2>Expert config</h2>
+<h3>List of configfiles</h3>
+
+<? local myform = form.status.configfiles ?>
+<TABLE>
+<? --[[
+ <TR style="background:#eee;font-weight:bold;">
+ <TD style="padding-right:20px;white-space:nowrap;text-align:left;" class="header">File</TD>
+ </TR>
+--]]?>
+
+<? for k,v in pairs(myform.value) do ?>
+ <TR>
+ <TD style="padding-right:20px;white-space:nowrap;"><?= html.link{value = "edit?name=" .. v , label=v } ?></TD>
+ </TR>
+<? end ?>
+</TABLE>
+
+<?
+--[[ DEBUG INFORMATION
+io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
+io.write(html.cfe_unpack(form))
+io.write("</span>")
+--]]
+?>
diff --git a/tinydns-model.lua b/tinydns-model.lua
index 00918ca..11f1101 100644
--- a/tinydns-model.lua
+++ b/tinydns-model.lua
@@ -12,6 +12,7 @@ local configitems = {}
local processname = "tinydns"
local configfile = "/etc/conf.d/" .. processname
+local baseurl = "/etc/tinydns/"
local initdoptions = getopts.getoptsfromfile_onperline("/etc/init.d/" .. processname)
if (initdoptions) then
configdir = initdoptions.DATADIR
@@ -637,6 +638,22 @@ function getconfigobjects(self,filter_type, filter_levels)
return domains_filtered
end
+-- Function to recursively inserts all filenames in a dir into an array
+local function recursedir(path, filearray)
+ local k,v
+ for k,v in pairs(posix.dir(path) or {}) do
+ -- Ignore files that begins with a '.'
+ if not string.match(v, "^%.") then
+ local f = path .. "/" .. v
+ -- If subfolder exists, list files in this subfolder
+ if (posix.stat(f).type == "directory") then
+ recursedir(f, filearray)
+ else
+ table.insert(filearray, f)
+ end
+ end
+ end
+end
-- ################################################################################
-- DEBUG INFORMATION (Everything below will be deleted in the future)
@@ -698,3 +715,74 @@ function getdebug()
return debug
end
+
+function getfilelist ()
+ local listed_files = {}
+ for k,v in pairs{baseurl} do
+ recursedir(v, listed_files)
+ end
+-- table.sort(listed_files, function (a,b) return (a.name < b.name) end )
+
+ return listed_files
+end
+
+function get_filedetails(self,path)
+-- local path
+-- if (num == "2") then
+-- path = configfile2
+-- else
+-- path = configfile
+-- end
+ local file = {}
+ local filedetails = {}
+ local config = {}
+ local filenameerrtxt
+ if (path) and (fs.is_file(path)) then
+ filedetails = fs.stat(path)
+ config = getconfig(path)
+ else
+ config = {}
+ config.filename = {}
+ config["filename"]["errtxt"]="Config file '".. path .. "' is missing!"
+ end
+
+ file["filename" .. (num or "")] = cfe({
+ name="filename" .. (num or ""),
+ label="File name",
+ value=path,
+ errtxt=filenameerrtxt
+ })
+ file["filesize" .. (num or "")] = cfe({
+ name="filesize" .. (num or ""),
+ label="File size",
+ value=filedetails.size or 0,
+ })
+ file["mtime" .. (num or "")] = cfe({
+ name="mtime" .. (num or ""),
+ label="File date",
+ value=filedetails.mtime or "---",
+ })
+ file["filecontent" .. (num or "")] = cfe({
+ type="longtext",
+ name="filecontent" .. (num or ""),
+ label="File content",
+ value=fs.read_file(path),
+ })
+
+ -- Sum all errors into one cfe
+ local sumerrors = ""
+ for k,v in pairs(config) do
+ if (config[k]) and (config[k]["errtxt"]) and (config[k]["errtxt"] ~= "") then
+ sumerrors = sumerrors .. config[k]["errtxt"] .. "\n"
+ end
+ end
+ if (sumerrors ~= "") then
+ file["sumerrors" .. (num or "")] = cfe ({
+ name="sumerrors" .. (num or ""),
+ label = "Configuration errors",
+ errtxt = string.match(sumerrors, "(.-)\n$"),
+ })
+ end
+
+ return file
+end
diff --git a/tinydns.menu b/tinydns.menu
index de2ee2c..6d2ee02 100644
--- a/tinydns.menu
+++ b/tinydns.menu
@@ -1,3 +1,4 @@
#CAT GROUP/DESC TAB ACTION
Networking 10DNS Status status
#Networking 10DNS Config config
+Networking 10DNS Expert expert