From a084d26cb2a9226faa39750e32c3fbacf217c16c Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Fri, 4 Apr 2008 15:16:09 +0000 Subject: Creating a expert tab so you can edit the config-files. git-svn-id: svn://svn.alpinelinux.org/acf/tinydns/trunk@945 ab2d0c66-481e-0410-8bed-d214d4d58bed --- tinydns-controller.lua | 73 +++++++++++++++++++++++++++ tinydns-edit-html.lsp | 113 ++++++++++++++++++++++++++++++++++++++++++ tinydns-edit_records-html.lsp | 106 --------------------------------------- tinydns-expert-html.lsp | 69 ++++++++++++++++++++++++++ tinydns-model.lua | 88 ++++++++++++++++++++++++++++++++ tinydns.menu | 1 + 6 files changed, 344 insertions(+), 106 deletions(-) create mode 100644 tinydns-edit-html.lsp delete mode 100644 tinydns-edit_records-html.lsp create mode 100644 tinydns-expert-html.lsp 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-html.lsp b/tinydns-edit-html.lsp new file mode 100644 index 0000000..cf70091 --- /dev/null +++ b/tinydns-edit-html.lsp @@ -0,0 +1,113 @@ + +DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") +--]] +?> + 0) then + val.class = "error" + io.write(" class='error'") + end + io.write(">" .. val.label .. "") + io.write("\n\t\t
") + if (viewtype == "viewonly") then + io.write(val.value) + elseif (val.type == "radio") and (type(val.option) == "table") and (#val.option > 0) then + io.write("") + for k1,v1 in pairs(val.option) do + io.write(tostring(v1.label) .. ":") + io.write("") + end + io.write("") + else + io.write(html.form[val.type](val)) + end + if (val.descr) and (#val.descr > 0) then io.write("\n\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

") end + if (#val.errtxt > 0) then io.write("\n\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

") end + io.write("\n\t\t
\n") + end + end +end +?> + +

SYSTEM INFO

+
+ +
+ + +
+

CONFIGURATION

+

Expert config

+

File details

+
+ +
+ +

FILE CONTENT

+ + +

SAVE AND APPLY ABOVE SETTINGS

+
+ +
+ +
+ +') + io.write('

MANAGEMENT

') + io.write('
') + io.write('
' .. cmdform[tags[1]]["label"] .. '
') + io.write('
') + for k,v in pairs(tags) do + if (cmdform[v]) then + io.write(html.form[cmdform[v].type](cmdform[v])) + end + end + io.write('
') + + if (cmdresult) and (cmdresult.action) and (#cmdresult.action.descr > 0) then + io.write('
' .. cmdresult.label .. '
') + io.write('
' .. cmdresult.action.descr .. '
') + end + io.write('
') +end ?> + +DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") +--]] +?> + diff --git a/tinydns-edit_records-html.lsp b/tinydns-edit_records-html.lsp deleted file mode 100644 index 4241540..0000000 --- a/tinydns-edit_records-html.lsp +++ /dev/null @@ -1,106 +0,0 @@ - -DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] -?> - - 0) then - val.class = "error" - io.write(" class='error'") - end - io.write(">" .. val.label .. "") - io.write("\n\t\t
") - if (viewtype == "viewonly") then - io.write(val.value) - elseif (val.type == "radio") and (type(val.option) == "table") and (#val.option > 0) then - io.write("") - for k1,v1 in pairs(val.option) do - io.write(tostring(v1.label) .. ":") - io.write("") - end - io.write("") - else - io.write(html.form[val.type](val)) - end - if (val.descr) and (#val.descr > 0) then io.write("\n\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

") end - if (#val.errtxt > 0) then io.write("\n\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

") end - io.write("\n\t\t
\n") - end - end -end -?> - - 0) then - v.class = "error" - io.write(" class='error'") - end - io.write(">" .. v.label .. "") - io.write("\n\t\t
") - io.write(html.form[v.type](v)) - if (v.descr) and (#v.descr > 0) then io.write("\n\t\t

" .. string.gsub(v.descr, "\n", "
") .. "

") end - if (#v.errtxt > 0) then io.write("\n\t\t

" .. string.gsub(v.errtxt, "\n", "
") .. "

") end - io.write("\n\t\t
\n") - end - end -end -?> - -
- -

EDIT PROPERTIES

-
- - - - - - -
- -
- -DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] -?> - 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 @@ + +DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") +--]] +?> + +") + for k,v in pairs(tags) do + if (myform[v]) and (myform[v]["value"]) then + local val = myform[v] + io.write("\t 0) then + val.class = "error" + io.write(" class='error'") + end + io.write(">" .. val.label .. "\n") + if (viewonly) then + io.write("\t\t
" .. val.value .. "\n") + else + io.write("\t\t
" .. html.form[val.type](val) .. "\n") + end + if (val.descr) and (#val.descr > 0) then io.write("\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

\n") end + if (#val.errtxt > 0) then io.write("\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

\n") end + io.write("\t\t
\n") + end + end + io.write("") +end +?> + +

SYSTEM INFO

+ + +

CONFIGURATION

+ +

Expert config

+

List of configfiles

+ + + + + + +--]]?> + + + + + + +
File
+ +DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") +--]] +?> 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 -- cgit v1.2.3