local mymodule = {} -- Load libraries modelfunctions = require("modelfunctions") fs = require("acf.fs") format = require("acf.format") -- Set variables local configfile = "/etc/shorewall/shorewall.conf" local processname = "shorewall" local packagename = "shorewall-shell" local baseurl = "/etc/shorewall/" -- ################################################################################ -- PUBLIC FUNCTIONS function mymodule.getstatus() return modelfunctions.getstatus(processname, packagename, "Shorewall Status") end function mymodule.getstatusdetails() local programstate, errtxt = modelfunctions.run_executable({"shorewall", "status"}, true) return cfe({ value=programstate, label="Shorewall status report", errtxt=errtxt }) end function mymodule.get_startstop(self, clientdata) return modelfunctions.get_startstop(processname) end function mymodule.startstop_service(self, startstop, action) return modelfunctions.startstop_service(startstop, action) end function mymodule.getlogfile () local logfilepath = format.parse_ini_file(fs.read_file(configfile) or "","","LOGFILE") or "" return cfe({ value=logfilepath, label="Shorewall logfile" }) end function mymodule.getfilelist () local listed_files = {} if fs.is_dir(baseurl) then for name in posix.files(baseurl) do if not string.match(name, "^%.") and not string.match(name, "^Makefile") then local filedetails = fs.stat(baseurl .. name) table.insert ( listed_files , {filename=baseurl..name, mtime=filedetails.mtime, filesize=filedetails.size} ) end end end table.sort(listed_files, function (a,b) return (a.filename < b.filename) end ) return cfe({ type="list", value=listed_files, label="Shorewall File List" }) end local function is_valid_filename(filename) local available_files = mymodule.getfilelist() for i,file in ipairs(available_files.value) do if file.filename == filename then return true end end return false end function mymodule.getfiledetails(filename) return modelfunctions.getfiledetails(filename, is_valid_filename) end function mymodule.updatefiledetails(self, filedetails) return modelfunctions.setfiledetails(self, filedetails, is_valid_filename) end return mymodule