From ca8952c1a3f5107563020604585ada9f6b088860 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Mon, 22 Sep 2008 20:58:06 +0000 Subject: Rewrite of shorewall to use new libraries, ... Moved statusbasic to status, status to details, expert to listfiles. Changed check to not have a page. Used links for status, edit, startstop. Didn't change config, so it still doesn't work. git-svn-id: svn://svn.alpinelinux.org/acf/shorewall/trunk@1480 ab2d0c66-481e-0410-8bed-d214d4d58bed --- shorewall-check-html.lsp | 38 ------ shorewall-config-html.lsp | 2 +- shorewall-controller.lua | 149 +++++------------------ shorewall-details-html.lsp | 19 +++ shorewall-edit-html.lsp | 53 +-------- shorewall-expert-html.lsp | 35 ------ shorewall-listfiles-html.lsp | 45 +++++++ shorewall-logfile-html.lsp | 21 +--- shorewall-model.lua | 261 ++++++++++++----------------------------- shorewall-startstop-html.lsp | 27 +---- shorewall-status-html.lsp | 24 +--- shorewall-statusbasic-html.lsp | 17 --- shorewall.menu | 5 +- shorewall.roles | 4 +- 14 files changed, 183 insertions(+), 517 deletions(-) delete mode 100644 shorewall-check-html.lsp create mode 100644 shorewall-details-html.lsp mode change 100644 => 120000 shorewall-edit-html.lsp delete mode 100644 shorewall-expert-html.lsp create mode 100644 shorewall-listfiles-html.lsp mode change 100644 => 120000 shorewall-startstop-html.lsp mode change 100644 => 120000 shorewall-status-html.lsp delete mode 100644 shorewall-statusbasic-html.lsp diff --git a/shorewall-check-html.lsp b/shorewall-check-html.lsp deleted file mode 100644 index 6e39399..0000000 --- a/shorewall-check-html.lsp +++ /dev/null @@ -1,38 +0,0 @@ -<% local form, viewlibrary = ... -require("viewfunctions") ---[[ DEBUG INFORMATION -io.write("

DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(view)) -io.write("
") ---]] -%> - -<% if viewlibrary and viewlibrary.dispatch_component then - viewlibrary.dispatch_component("statusbasic") -end %> - -

CONFIGURATION

-<% local myform = form.config %> - -

CHECK CONFIGURATION

-<% -io.write(html.form[form.config.checkresult.type](form.config.checkresult)) -%> - -
-<% --- Management buttons -local myform = form.management -local tags = { "restart" } -if (myform) then - io.write("

MANAGEMENT

\n
") - displaymanagement(myform,tags) - io.write("
") -end -%> -
- -<% if viewlibrary and viewlibrary.dispatch_component then - viewlibrary.dispatch_component("startstop") -end %> - diff --git a/shorewall-config-html.lsp b/shorewall-config-html.lsp index 5704df8..c14d453 100644 --- a/shorewall-config-html.lsp +++ b/shorewall-config-html.lsp @@ -31,7 +31,7 @@ local descr = { %> <% if viewlibrary and viewlibrary.dispatch_component then - viewlibrary.dispatch_component("statusbasic") + viewlibrary.dispatch_component("status") end %> <% local myform = form.config %> diff --git a/shorewall-controller.lua b/shorewall-controller.lua index 967c4d6..da88e40 100644 --- a/shorewall-controller.lua +++ b/shorewall-controller.lua @@ -1,9 +1,7 @@ module(..., package.seeall) --- This is the object/text used when we want to add a new record - -require("format") - +require("controllerfunctions") +--[[ local newrecordtxt = "[New]" -- ################################################################################ @@ -18,12 +16,40 @@ local function displaycmdsave(self) }) return cmdsave end - +--]] -- ################################################################################ -- PUBLIC FUNCTIONS default_action = "status" +function status(self) + return self.model.getstatus() +end + +function details(self) + return self.model.getstatusdetails() +end + +function startstop(self) + return controllerfunctions.handle_startstop(self, self.model.startstop_service, self.model.getstatus, self.clientdata) +end + +function listfiles(self) + return self.model.getfilelist() +end + +function edit(self) + return controllerfunctions.handle_form(self, function() return self.model.getfiledetails(self.clientdata.filename) end, self.model.updatefiledetails, self.clientdata, "Save", "Edit File", "File Saved") +end + +function check(self) + return self:redirect_to_referrer(self.model.configcheck()) +end + +function logfile(self) + return self.model.getlogfile() +end +--[[ function editrecords(self,types,record,errormessage) local recorddetails = {} local edit = {} @@ -445,17 +471,6 @@ function editrecords(self,types,record,errormessage) } end -function status(self) - return { status=self.model.getstatusdetails() } -end -function statusbasic(self) - return { - status=self.model.getstatus(), - version=self.model.getversion(), - autostart=self.model.getautostart(), - } -end - function config(self) -- If we made some changes to a recods... then proceed with the modification @@ -623,104 +638,4 @@ function config(self) configmessage=configmessage, } end - -function check(self) - - local config = self.model:configcheck() - - return { - option={ script=self.conf.script, - prefix=self.conf.prefix, - controller = self.conf.controller, - action = "expert", - link = self.conf.script .. self.conf.prefix .. self.conf.controller, }, - config = config, - startstop = startstop, - debugclientdata = self.clientdata, - } - -end - -function logfile(self) - - local config = self.model:getlogfile() - - return { - option={ script=self.conf.script, - prefix=self.conf.prefix, - controller = self.conf.controller, - action = "expert", - link = self.conf.script .. self.conf.prefix .. self.conf.controller, }, - config = config, - startstop = startstop, - debugclientdata = self.clientdata, - } - -end - -function expert(self) - return { - option={ script=self.conf.script, - prefix=self.conf.prefix, - controller = self.conf.controller, - action = "expert", - link = self.conf.script .. self.conf.prefix .. self.conf.controller, }, - config = self.model:getfilelist(), - startstop = startstop, - debugclientdata = self.clientdata, - } -end - -function edit(self) - - -- Save changes - local cmdsaveresult, cmdsaveerror - if ( self.clientdata.cmdsave) then - local filetochange = cfe ({ name=self.clientdata.filename, value=self.clientdata.filecontent, }) - cmdsaveresult, cmdsaveerror = self.model:updatefilecontent(filetochange) - self.clientdata.name = self.clientdata.filename - end - - local config = self.model:getfiledetails(cfe({ - name="editfile", - value=self.clientdata.name, - })) - - -- Display save button - config.cmdsave = displaycmdsave() - if (cmdsaveresult) then - config.cmdsave.descr="* Changes has been saved!" - redirect(self,"expert") - end - - return { - option={ script=self.conf.script, - prefix=self.conf.prefix, - controller = self.conf.controller, - action = "edit", - link = self.conf.script .. self.conf.prefix .. self.conf.controller, }, - modifications = modifications, - config = config, - startstop = startstop, - debugclientdata = self.clientdata, - } - -end - -function startstop(self) - local result - if self.clientdata.action then - result = self.model:startstop_service(self.clientdata.action) - self.sessiondata.syslogstartstopresult = result - self.redirect_to_referrer(self) - end - - local status = self.model.getstatus() - if self.sessiondata.syslogstartstopresult then - result = self.sessiondata.syslogstartstopresult - self.sessiondata.syslogstartstopresult = nil - end - - return cfe({ type="group", value={status=status, result=result} }) -end - +--]] diff --git a/shorewall-details-html.lsp b/shorewall-details-html.lsp new file mode 100644 index 0000000..d5a65ec --- /dev/null +++ b/shorewall-details-html.lsp @@ -0,0 +1,19 @@ +<% local data, viewlibrary = ... +require("viewfunctions") +--[[ DEBUG INFORMATION +io.write("

DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(viewlibrary)) +io.write("----------") +io.write(html.cfe_unpack(data)) +io.write("
") +--]] +%> + +<% if viewlibrary and viewlibrary.dispatch_component then + viewlibrary.dispatch_component("status") +end %> + +

<%= data.label %>

+
+<%= data.value %>
+
diff --git a/shorewall-edit-html.lsp b/shorewall-edit-html.lsp deleted file mode 100644 index f808a72..0000000 --- a/shorewall-edit-html.lsp +++ /dev/null @@ -1,52 +0,0 @@ -<% local form, viewlibrary = ... -require("viewfunctions") -%> - -<% if viewlibrary and viewlibrary.dispatch_component then - viewlibrary.dispatch_component("statusbasic") -end %> - -

CONFIGURATION

-<% local myform = form.config %> -
" method="POST"> - -

EXPERT CONFIGURATION

-

FILE DETAILS

-
-<% -local tags = { "filename","filesize", "mtime", "sumerrors" } -displayinfo(myform,tags,"viewonly") -%> -
- -<% if (form.config.filecontent) then %> - -

FILE CONTENT

- -<% -io.write(html.form[form.config.filecontent.type](form.config.filecontent)) -%> - -

SAVE AND APPLY ABOVE SETTINGS

-
-<% -local tags = { "cmdsave", } -displayinfo(myform,tags) -%> -
- -<% end %> - -<% --- Management buttons -local myform = form.management -local tags = { "start", "stop", "restart" } -if (myform) then - io.write("

MANAGEMENT

\n
") - displaymanagement(myform,tags) - io.write("
") -end -%> -
- diff --git a/shorewall-edit-html.lsp b/shorewall-edit-html.lsp new file mode 120000 index 0000000..15b1930 --- /dev/null +++ b/shorewall-edit-html.lsp @@ -0,0 +1 @@ +../filedetails-html.lsp \ No newline at end of file diff --git a/shorewall-expert-html.lsp b/shorewall-expert-html.lsp deleted file mode 100644 index 61ad046..0000000 --- a/shorewall-expert-html.lsp +++ /dev/null @@ -1,35 +0,0 @@ -<% local form, viewlibrary = ... -require("viewfunctions") -%> -<% ---[[ DEBUG INFORMATION -io.write("

DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] -%> - -<% if viewlibrary and viewlibrary.dispatch_component then - viewlibrary.dispatch_component("statusbasic") -end %> - -

EXPERT CONFIGURATION

- -<% local myform = form.config %> - - - - - - - - -<% for i = 1, table.maxn(myform) do %> - - - - - -<% end %> -
FileSizeLast Modified
<%= html.link{value = "edit?name=" .. myform[i].value , label=myform[i].value } %><%= myform[i].size %><%= myform[i].mtime %>
- diff --git a/shorewall-listfiles-html.lsp b/shorewall-listfiles-html.lsp new file mode 100644 index 0000000..df002b2 --- /dev/null +++ b/shorewall-listfiles-html.lsp @@ -0,0 +1,45 @@ +<% local data, viewlibrary, page_info, session = ... +require("viewfunctions") +%> +<% +--[[ DEBUG INFORMATION +io.write("

DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(data)) +io.write("
") +--]] +%> + +<% displaycommandresults({"check"}, session) %> + +<% if viewlibrary and viewlibrary.dispatch_component then + viewlibrary.dispatch_component("status") +end %> + +

<%= data.label %>

+ + + + + + + + + +<% for i,file in ipairs(data.value) do %> + + + + + +<% end %> +
FileSizeLast Modified
<%= html.link{value = "edit?filename=" .. file.filename, label=file.filename} %><%= file.filesize %><%= file.mtime %>
+
+
"> +
Check Configuration
+
+
+
+ +<% if viewlibrary and viewlibrary.dispatch_component then + viewlibrary.dispatch_component("startstop") +end %> diff --git a/shorewall-logfile-html.lsp b/shorewall-logfile-html.lsp index d3343b7..e939464 100644 --- a/shorewall-logfile-html.lsp +++ b/shorewall-logfile-html.lsp @@ -1,27 +1,12 @@ -<% local form, viewlibrary = ... +<% local data, viewlibrary = ... require("viewfunctions") --[[ DEBUG INFORMATION io.write("

DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(view)) +io.write(html.cfe_unpack(data)) io.write("
") --]] %> <% if viewlibrary and viewlibrary.dispatch_component then - viewlibrary.dispatch_component("statusbasic") + viewlibrary.dispatch_component("alpine-baselayout/logfiles/view", {name=data.value, grep="Shorewall"}) end %> - -

LOGIFLES

-

DETAILS

-<% local myform = form.config %> -

FILE DETAILS

-
-<% -local tags = { "filename", "filesize", "mtime", "sumerrors" } -displayinfo(myform,tags,"viewonly") -%> -
- -

FILE CONTENT

<% -io.write(html.form[form.config.checkresult.type](form.config.checkresult)) -%> diff --git a/shorewall-model.lua b/shorewall-model.lua index a8627c7..53e56d7 100644 --- a/shorewall-model.lua +++ b/shorewall-model.lua @@ -1,45 +1,21 @@ module(..., package.seeall) -- Load libraries +require("modelfunctions") require("fs") -require("procps") require("getopts") -require("format") -require("daemoncontrol") -require("validator") -require("processinfo") -- Set variables local configfile = "/etc/shorewall/shorewall.conf" local processname = "shorewall" local packagename = "shorewall" local baseurl = "/etc/shorewall/" +--[[ local config = {} -- ################################################################################ -- LOCAL FUNCTIONS -local function getloglevels() - local loglevels = {} - for i=1,8 do - table.insert(loglevels,i) - end - return loglevels -end - -local function getdetails() - local f,error = io.popen("/sbin/shorewall status") - local fake = f:read("*l") - local fake = f:read("*l") - local programstatus = f:read("*l") or "" - local programstate = f:read("*l") or "" - f:close() - local f,error = io.popen("/sbin/shorewall version") - local programversion = "shorewall-" .. f:read("*l") - f:close() - return programversion,programstatus,programstate -end - local function read_config(file) local path = baseurl .. file if not (fs.is_file(path)) then @@ -59,7 +35,6 @@ local function read_config(file) return output end ----[[ local function addremove_config( addremove, file, value, orgvalue ) filepath = baseurl .. file local cmdoutput @@ -195,13 +170,81 @@ end -- ################################################################################ -- PUBLIC FUNCTIONS -function modify_config(self, addremove, file, value, orgvalue ) - return addremove_config(addremove, file, value, orgvalue ) +function getstatus() + local status = modelfunctions.getstatus(processname, packagename, "Shorewall Status") + local details = getstatusdetails() + if string.match(details.value, "Shorewall is running") then + status.value.status.value = "Enabled" + end + return status +end + +function getstatusdetails() + local f = io.popen("/sbin/shorewall status") + local programstate = f:read("*a") or "" + f:close() + return cfe({ value=programstate, label="Shorewall status report" }) +end + +function startstop_service(action) + return modelfunctions.startstop_service(processname, action) +end + +function configcheck () + local f = io.popen("/bin/echo -n '>> Check starts at: ';/bin/date; /bin/echo; /etc/init.d/shorewall check; /bin/echo; /bin/echo -n '>> Check stops at: '; /bin/date;") + local checkresult = f:read("*a") + f:close() + return cfe({ type="longtext", value=checkresult, label="Result of checking config" }) +end + +function getlogfile () + local logfilepath = getopts.getoptsfromfile(configfile,"","LOGFILE") or "" + return cfe({ value=logfilepath, label="Shorewall logfile" }) +end + +function getfilelist () + local listed_files = {} + + 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 + + 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 + +function getfiledetails(filename) + --Validate filename + local available_files = getfilelist() + for i,file in ipairs(available_files.value) do + if file.filename == filename then + return modelfunctions.getfiledetails(filename) + end + end + local retval = modelfunctions.getfiledetails("") + retval.value.filename.value = filename + return retval end -function startstop_service ( self, action ) - local cmdresult,cmdmessage,cmderror,cmdaction = daemoncontrol.daemoncontrol(processname, action) - return cfe({ type="boolean", value=cmdresult, descr=cmdmessage, errtxt=cmderror, label=action.." result" }) +function updatefiledetails (filedetails) + local available_files = getfilelist() + for i,file in ipairs(available_files.value) do + if file.filename == filedetails.value.filename.value then + return modelfunctions.setfiledetails(filedetails) + end + end + filedetails.value.filename.errtxt = "Invalid Filename" + filedetails.errtxt = "Failed to save file" + return filedetails +end + +--[[ +function modify_config(self, addremove, file, value, orgvalue ) + return addremove_config(addremove, file, value, orgvalue ) end function getconfig() @@ -257,57 +300,6 @@ function getconfig() end -function getversion() - local value, errtxt = processinfo.package_version(packagename) - local version = cfe({ name = "version", - label="Program version", - value=value, - errtxt=errtxt, - }) - return version -end -function getautostart() - local autostart_sequense, autostart_errtxt = processinfo.process_botsequence(processname) - local autostart = cfe({ name="autostart", - label="Autostart sequence", - value=autostart_sequense, - errtxt=autostart_errtxt, - }) - return autostart -end - -function getstatus() - local programversion,programstatus,programstate = getdetails() - local status = cfe({ name="status", - label="Program status", - value=programstatus, - }) - return status -end -function getstatusdetails() - local details = {} - local programversion,programstatus,programstate = getdetails() - details.state = cfe({ name="state", - label="Program reports", - value=programstate, - }) - return details -end - - -function configcheck () - local check = {} - local f,err = io.popen("/bin/echo -n '>> Check starts at: ';/bin/date; /bin/echo; /etc/init.d/shorewall check; /bin/echo; /bin/echo -n '>> Check stops at: '; /bin/date;") - local checkresult = f:read("*a") - f:close() - check.checkresult = cfe({ name = "checkresult", - type="longtext", - label="Result of checking config", - value=checkresult, - }) - return check -end - function get_defined_zones () local output = {} for k,v in pairs(read_config("zones")) do @@ -315,105 +307,4 @@ function get_defined_zones () end return output end - -function getlogfile () - local logfile = {} - local logfilepath = getopts.getoptsfromfile(configfile,"","LOGFILE") or "" - local cmdaction = "grep Shorewall " .. logfilepath - local f, error = io.popen(cmdaction ,r) - local checkresult = f:read("*a") - f:close() - logfile.checkresult = cfe({ name = "checkresult", - type="longtext", - label="Result of logfiles", - value=checkresult, - }) - logfile.filename = cfe({ - name="filename", - label="File name", - value=cmdaction, - }) - return logfile -end - -function getfilelist () - local filepath = baseurl - local listed_files = {} - - local k,v - for name in posix.files(filepath) do - if not string.match(name, "^%.") and not string.match(name, "^Makefile") then - local filedetails = fs.stat(filepath .. name) - table.insert ( listed_files , cfe({name=name, value=filepath .. name, mtime=filedetails.mtime, size=filedetails.size,}) ) - end - end - - table.sort(listed_files, function (a,b) return (a.name < b.name) end ) - - return listed_files -end - -function getfiledetails(self,search) - local file = {} - local path = nil - --Validate filename - local available_files = getfilelist() - for k,v in pairs(available_files) do - if ( tostring(available_files[k]["value"]) == tostring(search.value) ) then - path = tostring(search.value) - end - end - if not (path) or (path == "") then - file["filename"] = search - file["filename"]["label"] = "File name" - file["filename"]["errtxt"] = "Invalid path!" - return file - end - - local filedetails = fs.stat(path) - file["filename"] = cfe({ - name="filename", - label="File name", - value=path, - }) - file["filesize"] = cfe({ - name="filesize", - label="File size", - value=filedetails.size, - }) - file["mtime"] = cfe({ - name="mtime", - label="File name", - value=filedetails.mtime, - }) - file["filecontent"] = cfe({ - type="longtext", - name="filecontent", - label="File content", - value=fs.read_file(path), - }) - - return file -end - --- modifications should be a CFE -function updatefilecontent (self, filetochange) - local path = nil - --Validate filename - local available_files = getfilelist() - for k,v in pairs(available_files) do - if ( tostring(available_files[k]["value"]) == tostring(filetochange.name) ) then - path = tostring(filetochange.name) - end - end - if not (path) then - filetochange.errtxt = "Invalid path!" - return false, filetochange - end - - local file_result,err = fs.write_file(path, format.dostounix(filetochange.value)) - return true -end - - - +--]] diff --git a/shorewall-startstop-html.lsp b/shorewall-startstop-html.lsp deleted file mode 100644 index 3b706a9..0000000 --- a/shorewall-startstop-html.lsp +++ /dev/null @@ -1,26 +0,0 @@ -<% local data = ... %> -<% --[[ -io.write(html.cfe_unpack(data)) ---]] %> - -

MANAGEMENT

-
-
-
Program control-panel
-
-> -> -> -
-
- -<% if data.value.result then %> -
Previous action result
-
-<% if data.value.result.descr then %> -

<%= string.gsub(data.value.result.descr, "\n", "
") %>

-<% end if data.value.result.errtxt then %> -

<%= string.gsub(data.value.result.errtxt, "\n", "
") %>

-<% end end %> -
-
diff --git a/shorewall-startstop-html.lsp b/shorewall-startstop-html.lsp new file mode 120000 index 0000000..0ea2627 --- /dev/null +++ b/shorewall-startstop-html.lsp @@ -0,0 +1 @@ +../startstop-html.lsp \ No newline at end of file diff --git a/shorewall-status-html.lsp b/shorewall-status-html.lsp deleted file mode 100644 index f1a2d56..0000000 --- a/shorewall-status-html.lsp +++ /dev/null @@ -1,23 +0,0 @@ -<% local form, viewlibrary = ... -require("viewfunctions") ---[[ DEBUG INFORMATION -io.write("

DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(viewlibrary)) -io.write("----------") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] -%> - -<% if viewlibrary and viewlibrary.dispatch_component then - viewlibrary.dispatch_component("statusbasic") -end %> - -

PROGRAM SPECIFIC OPTIONS/INFORMATION

-
-<% -local myform = form.status -local tags = { "state", } -displayinfo(myform,tags,"viewonly") -%> -
diff --git a/shorewall-status-html.lsp b/shorewall-status-html.lsp new file mode 120000 index 0000000..b2f8480 --- /dev/null +++ b/shorewall-status-html.lsp @@ -0,0 +1 @@ +../status-html.lsp \ No newline at end of file diff --git a/shorewall-statusbasic-html.lsp b/shorewall-statusbasic-html.lsp deleted file mode 100644 index 99e7895..0000000 --- a/shorewall-statusbasic-html.lsp +++ /dev/null @@ -1,17 +0,0 @@ -<% local form = ... -require("viewfunctions") ---[[ DEBUG INFORMATION -io.write("

DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] -%> - -

SYSTEM INFO

-
-<% -local myform = form -local tags = { "status", "version", "autostart", } -displayinfo(myform,tags,"viewonly") -%> -
diff --git a/shorewall.menu b/shorewall.menu index 6ea1c18..8783eba 100644 --- a/shorewall.menu +++ b/shorewall.menu @@ -1,7 +1,6 @@ #CAT GROUP/DESC TAB ACTION -Networking 40Firewall Status status +Networking 40Firewall Status details #Networking 40Firewall Config config -Networking 40Firewall Expert expert -Networking 40Firewall Check/Start/Stop/Restart check +Networking 40Firewall Expert listfiles Networking 40Firewall Logfile logfile diff --git a/shorewall.roles b/shorewall.roles index 270dea4..cd638fb 100644 --- a/shorewall.roles +++ b/shorewall.roles @@ -1,2 +1,2 @@ -READ=shorewall:status,shorewall:statusbasic,shorewall:logfile -UPDATE=shorewall:editrecords,shorewall:config,shorewall:check,shorewall:expert,shorewall:edit,shorewall:startstop +READ=shorewall:status,shorewall:details,shorewall:logfile +UPDATE=shorewall:editrecords,shorewall:config,shorewall:check,shorewall:listfiles,shorewall:edit,shorewall:startstop -- cgit v1.2.3