diff options
-rw-r--r-- | ipsectools-controller.lua | 19 | ||||
-rw-r--r-- | ipsectools-expert-html.lsp | 19 | ||||
-rw-r--r-- | ipsectools-model.lua | 81 |
3 files changed, 53 insertions, 66 deletions
diff --git a/ipsectools-controller.lua b/ipsectools-controller.lua index 6d3fb3c..ba0f667 100644 --- a/ipsectools-controller.lua +++ b/ipsectools-controller.lua @@ -52,12 +52,9 @@ end expert = function (self) local modifications = self.clientdata.filecontent or "" + local modifications2 = self.clientdata.filecontent2 or "" if ( self.clientdata.cmdsave ) then modifications = self.model:update_filecontent(modifications) - end - - local modifications2 = self.clientdata.filecontent2 or "" - if ( self.clientdata.cmdsave2 ) then modifications2 = self.model:update_filecontent2(modifications2) end @@ -79,6 +76,7 @@ expert = function (self) local status=self.model.getstatus() local file = self.model:get_filedetails() + local file2 = self.model:get_filedetails("2") -- Add buttons file.cmdsave = cfe ({ @@ -91,18 +89,6 @@ expert = function (self) file.cmdsave.descr="* Changes has been saved!" end - -- Add buttons - file.cmdsave2 = cfe ({ - name="cmdsave2", - label="Apply settings", - value="Apply", - type="submit", - }) - if (self.clientdata.cmdsave2) then - file.cmdsave2.descr="* Changes has been saved!" - end - - -- Management buttons local disablestart,disablestop,disablerestart -- Disable management buttons based on if the process is running or not @@ -117,6 +103,7 @@ expert = function (self) return ( { status = status, file = file, + file2 = file2, modifications = modifications, management = management, cmdmanagement = cmdmanagement, diff --git a/ipsectools-expert-html.lsp b/ipsectools-expert-html.lsp index 604a276..39c45cd 100644 --- a/ipsectools-expert-html.lsp +++ b/ipsectools-expert-html.lsp @@ -68,22 +68,11 @@ local myform = form.file io.write(html.form[myform.filecontent.type](myform.filecontent)) ?> -<H3>SAVE AND APPLY ABOVE SETTINGS</H3> -<DL> -<? -local tags = { "cmdsave", } -displayinfo(myform,tags) -?> -</DL> - -</form> - -<form name="myform" action="" method="POST"> <H2>Expert config - Policy</H2> <h3>File details</h3> <DL> <? -local myform = form.file +local myform = form.file2 local tags = { "filename2", "filesize2", "mtime2", "sumerrors2", } displayinfo(myform,tags,"viewonly") ?> @@ -91,14 +80,14 @@ displayinfo(myform,tags,"viewonly") <H3>FILE CONTENT</H3> <? -local myform = form.file io.write(html.form[myform.filecontent2.type](myform.filecontent2)) ?> -<H3>SAVE AND APPLY ABOVE SETTINGS</H3> +<H2>SAVE AND APPLY ABOVE SETTINGS</H2> <DL> <? -local tags = { "cmdsave2", } +local myform = form.file +local tags = { "cmdsave", } displayinfo(myform,tags) ?> </DL> diff --git a/ipsectools-model.lua b/ipsectools-model.lua index 4b91fdf..d46f476 100644 --- a/ipsectools-model.lua +++ b/ipsectools-model.lua @@ -190,57 +190,68 @@ function getstatus() return status end -function get_filedetails() - local path = configfile - local filedetails = fs.stat(path) - local file = {} +function getconfig() + local config = {} + return config +end - file["filename"] = cfe({ - name="filename", - label="File name", - value=path, - }) - file["filesize"] = cfe({ - name="filesize", - label="File size", - value=filedetails.size or 0, - }) - file["mtime"] = cfe({ - name="mtime", - label="File date", - value=filedetails.mtime or "---", - }) - file["filecontent"] = cfe({ - type="longtext", - name="filecontent", - label="File content", - value=fs.read_file(path), - }) +function get_filedetails(self,num) + 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 - path = configfile2 - filedetails = fs.stat(path) - file["filename2"] = cfe({ - name="filename2", + file["filename" .. (num or "")] = cfe({ + name="filename" .. (num or ""), label="File name", value=path, + errtxt=filenameerrtxt }) - file["filesize2"] = cfe({ - name="filesize2", + file["filesize" .. (num or "")] = cfe({ + name="filesize" .. (num or ""), label="File size", value=filedetails.size or 0, }) - file["mtime2"] = cfe({ - name="mtime2", + file["mtime" .. (num or "")] = cfe({ + name="mtime" .. (num or ""), label="File date", value=filedetails.mtime or "---", }) - file["filecontent2"] = cfe({ + file["filecontent" .. (num or "")] = cfe({ type="longtext", - name="filecontent2", + 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 |