summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2014-02-03 21:54:10 +0000
committerTed Trask <ttrask01@yahoo.com>2014-02-03 21:54:10 +0000
commit9cf7dbead8f602c77541889bef4bc8e629e76853 (patch)
tree6a74f790d48f3a31fb374506951e3b8c8a7d9d91
parent7b1dcaf9cdf3d5c62167e9b6b86797edb64b7e95 (diff)
downloadacf-shorewall-9cf7dbead8f602c77541889bef4bc8e629e76853.tar.bz2
acf-shorewall-9cf7dbead8f602c77541889bef4bc8e629e76853.tar.xz
Remove dead code
-rw-r--r--shorewall-config-html.lsp184
-rw-r--r--shorewall-controller.lua590
-rw-r--r--shorewall-model.lua223
3 files changed, 0 insertions, 997 deletions
diff --git a/shorewall-config-html.lsp b/shorewall-config-html.lsp
deleted file mode 100644
index 878727a..0000000
--- a/shorewall-config-html.lsp
+++ /dev/null
@@ -1,184 +0,0 @@
-<% local form,viewlibrary = ...
-<% html = require("acf.html") %>
-
-local descr = {
- ['interfaces'] = {
- ['labels'] = { "ZONE", "INTERFACES", "BROADCAST", "OPTIONS" },
- ['width'] = { "100", "100", "100", "*" }
- },
- ['zones'] = {
- ['labels'] = { "ZONE", "INTERFACES", "BROADCAST", "OPTIONS" },
- ['width'] = { "100", "100", "100", "*" }
- },
- ['policy'] = {
- ['labels'] = { "SOURCE", "DEST", "POLICY", "LOG LEVEL", "LIMIT:BURST" },
- ['width'] = { "100", "100", "100", "100" }
- },
- ['rules'] = {
- ['labels'] = { "ACTION", "SOURCE", "DEST", "PROTO", "DEST<BR>PORT", "SOURCE<BR>PORT(S)", "ORIGINAL<BR>DEST", "RATE<BR>LIMIT", "USER/<BR>GROUP", "MARK", },
- ['width'] = { "100", "70", "70", "70", "100", }
- },
- ['masq'] = {
- ['labels'] = { "INTERFACE", "SOURCE", "ADDRESS", "PROTO", "PORT(S)", "IPSEC", "MARK" },
- ['width'] = { "100", "70", "70", "70", "100", }
- },
- }
-%>
-
-<% if viewlibrary and viewlibrary.dispatch_component then
- viewlibrary.dispatch_component("status")
-end %>
-
-<% local myform = form.config %>
-<h1>GUIDED CONFIGURATION</h1>
-
-
-<H3>Defince zones</H3>
-<% local myform = "zones" %>
-<TABLE>
-<TR>
-<% for i=1,#descr[myform]['labels'] do %>
- <TD style="padding-right:10px;text-align:left;" class="header" WIDTH="<% io.write(descr[myform]['width'][i] or "*") %>"><% io.write(descr[myform]['labels'][i] or "") %></TD>
-<% end %>
- <TD class="header" WIDTH="60"><IMG SRC='<%= html.html_escape(page_info.wwwprefix..page_info.staticdir) %>/tango/16x16/actions/list-add.png' width='16' height='16' title="Add item below this record"></TD>
-</TR>
-
-<%
-for i=1, #form.config[myform]['option'] do
-%>
-
-<TR>
- <% for ii=1,#descr[myform]['labels'] do %>
- <TD style="padding-right:10px"><% io.write(form.config[myform]['option'][i][ii] or "") %></TD>
- <% end %>
- <TD style="padding-right:0px;text-align:left;">
-<IMG SRC='<%= html.html_escape(page_info.wwwprefix..page_info.staticdir) %>/tango/16x16/actions/list-add.png' width='16' height='16' title="Add item below this record">
-<IMG SRC='<%= html.html_escape(page_info.wwwprefix..page_info.staticdir) %>/tango/16x16/actions/list-remove.png' width='16' height='16' title="Remove this record">
-<IMG SRC='<%= html.html_escape(page_info.wwwprefix..page_info.staticdir) %>/tango/16x16/actions/document-properties.png' width='16' height='16' title="Edit this record">
-</TD>
- </TR>
-<%
-end
-%>
-</TABLE>
-
-<H3>Interfaces</H3>
-<% local myform = "interfaces" %>
-<TABLE>
-<TR>
-<% for i=1,#descr[myform]['labels'] do %>
- <TD style="padding-right:10px;text-align:left;" class="header" WIDTH="<% io.write(descr[myform]['width'][i] or "*") %>"><% io.write(descr[myform]['labels'][i] or "") %></TD>
-<% end %>
- <TD class="header" WIDTH="60"><IMG SRC='<%= html.html_escape(page_info.wwwprefix..page_info.staticdir) %>/tango/16x16/actions/list-add.png' width='16' height='16' title="Add item below this record"></TD>
-</TR>
-
-<%
-for i=1, #form.config[myform]['option'] do
-%>
-
-<TR>
- <% for ii=1,#descr[myform]['labels'] do %>
- <TD style="padding-right:10px;"><% io.write(form.config[myform]['option'][i][ii] or "") %></TD>
- <% end %>
- <TD style="padding-right:0px;">
-<IMG SRC='<%= html.html_escape(page_info.wwwprefix..page_info.staticdir) %>/tango/16x16/actions/list-add.png' width='16' height='16' title="Add item below this record">
-<IMG SRC='<%= html.html_escape(page_info.wwwprefix..page_info.staticdir) %>/tango/16x16/actions/list-remove.png' width='16' height='16' title="Remove this record">
-<IMG SRC='<%= html.html_escape(page_info.wwwprefix..page_info.staticdir) %>/tango/16x16/actions/document-properties.png' width='16' height='16' title="Edit this record">
-</TD>
- </TR>
-<%
-end
-%>
-</TABLE>
-
-
-<h3>Default policy</h3>
-<% local myform = "policy" %>
-<TABLE>
-<TR>
-<% for i=1,#descr[myform]['labels'] do %>
- <TD style="padding-right:10px;text-align:left;" class="header" WIDTH="<% io.write(descr[myform]['width'][i] or "*") %>"><% io.write(descr[myform]['labels'][i] or "") %></TD>
-<% end %>
- <TD class="header" WIDTH="60"><IMG SRC='<%= html.html_escape(page_info.wwwprefix..page_info.staticdir) %>/tango/16x16/actions/list-add.png' width='16' height='16' title="Add item below this record"></TD>
-</TR>
-
-<%
-for i=1, #form.config[myform]['option'] do
-%>
-
-<TR>
- <% for ii=1,#descr[myform]['labels'] do %>
- <TD style="padding-right:10px;"><% io.write(form.config[myform]['option'][i][ii] or "") %></TD>
- <% end %>
- <TD style="padding-right:0px;text-align:left;">
-<IMG SRC='<%= html.html_escape(page_info.wwwprefix..page_info.staticdir) %>/tango/16x16/actions/list-add.png' width='16' height='16' title="Add item below this record">
-<IMG SRC='<%= html.html_escape(page_info.wwwprefix..page_info.staticdir) %>/tango/16x16/actions/list-remove.png' width='16' height='16' title="Remove this record">
-<IMG SRC='<%= html.html_escape(page_info.wwwprefix..page_info.staticdir) %>/tango/16x16/actions/document-properties.png' width='16' height='16' title="Edit this record">
-</TD>
- </TR>
-<%
-end
-%>
-</TABLE>
-
-<h3>Rules</h3>
-<% local myform = "rules"
-local val = {1,2,3,4,5,6,7,8,10,}
-%>
-<TABLE>
-<TR>
-<% for k,i in pairs(val) do %>
- <TD style="padding-right:10px;text-align:left;" class="header" WIDTH="<% io.write(descr[myform]['width'][i] or "*") %>"><% io.write(descr[myform]['labels'][i] or "") %></TD>
-<% end %>
- <TD class="header" WIDTH="60"><IMG SRC='<%= html.html_escape(page_info.wwwprefix..page_info.staticdir) %>/tango/16x16/actions/list-add.png' width='16' height='16' title="Add item below this record"></TD>
-</TR>
-
-<%
-for i=1, #form.config[myform]['option'] do
-%>
-
-<TR>
- <% for ii,vv in pairs(val) do %>
- <TD style="padding-right:10px;"><% io.write(form.config[myform]['option'][i][ii] or "") %></TD>
- <% end %>
- <TD style="padding-right:0px;text-align:left;">
-<IMG SRC='<%= html.html_escape(page_info.wwwprefix..page_info.staticdir) %>/tango/16x16/actions/list-add.png' width='16' height='16' title="Add item below this record">
-<IMG SRC='<%= html.html_escape(page_info.wwwprefix..page_info.staticdir) %>/tango/16x16/actions/list-remove.png' width='16' height='16' title="Remove this record">
-<IMG SRC='<%= html.html_escape(page_info.wwwprefix..page_info.staticdir) %>/tango/16x16/actions/document-properties.png' width='16' height='16' title="Edit this record">
-</TD>
- </TR>
-<%
-end
-%>
-</TABLE>
-
-<H3>Masq</H3>
-<% local myform = "masq" %>
-<TABLE>
-<TR>
-<% for i=1,#descr[myform]['labels'] do %>
- <TD style="padding-right:10px;text-align:left;" class="header" WIDTH="<% io.write(descr[myform]['width'][i] or "*") %>"><% io.write(descr[myform]['labels'][i] or "") %></TD>
-<% end %>
- <TD class="header" WIDTH="60"><IMG SRC='<%= html.html_escape(page_info.wwwprefix..page_info.staticdir) %>/tango/16x16/actions/list-add.png' width='16' height='16' title="Add item below this record"></TD>
-</TR>
-
-<%
-for i=1, #form.config[myform]['option'] do
-%>
-
-<TR>
- <% for ii=1,#descr[myform]['labels'] do %>
- <TD style="padding-right:10px;"><% io.write(form.config[myform]['option'][i][ii] or "") %></TD>
- <% end %>
- <TD style="padding-right:0px;text-align:left;">
-<IMG SRC='<%= html.html_escape(page_info.wwwprefix..page_info.staticdir) %>/tango/16x16/actions/list-add.png' width='16' height='16' title="Add item below this record">
-<IMG SRC='<%= html.html_escape(page_info.wwwprefix..page_info.staticdir) %>/tango/16x16/actions/list-remove.png' width='16' height='16' title="Remove this record">
-<IMG SRC='<%= html.html_escape(page_info.wwwprefix..page_info.staticdir) %>/tango/16x16/actions/document-properties.png' width='16' height='16' title="Edit this record">
-</TD>
- </TR>
-<%
-end
-%>
-</TABLE>
-
-
diff --git a/shorewall-controller.lua b/shorewall-controller.lua
index 59f6394..732cf5c 100644
--- a/shorewall-controller.lua
+++ b/shorewall-controller.lua
@@ -25,595 +25,5 @@ end
function mymodule.logfile(self)
return self.model.getlogfile()
end
---[[
-function mymodule.editrecords(self,types,record,errormessage)
- local recorddetails = {}
- local edit = {}
- local config=self.model:getconfig()
-
-
- -- Split the record into a table
- local recordtable = {}
- for word in string.gmatch(record, "%S+") do
- table.insert(recordtable, word)
- end
-
- -- Save info on how the original record looked like
- edit.orgrecord = cfe({
- name="orgrecord",
- label="Original record",
- value=record,
- type="hidden",
- })
-
- -- Specify a actiontype (this is then used when we make changes)
- edit.actiontype = cfe({
- name="actiontype",
- label="Type of action [add|delete|modify]",
- type="hidden",
- })
- if (record == newrecordtxt) then
- edit.actiontype.value = "add"
- else
- edit.actiontype.value = "modify"
- end
-
- if (types == "params") then
- table.insert(edit, cfe({
- name=1,
- value=recordtable[1],
- label="Variable name",
- }))
- if (record == newrecordtxt) then
- edit[1]["value"] = "VARIABLE=XXX"
- end
- end
-
- -- Display save button
- local cmdsave = displaycmdsave()
- cmdsave.errtxt = errormessage
-
- -- Display delete button
- cmddelete = cfe({ name="cmddelete",
- label="Delete this record",
- value="Delete",
- type="submit",
- })
-
- if (types == "interfaces") then
-
- -- Fetch the list of existing interfaces
--- local interfaceslist = {}
--- local interfaces, int_w_loaded, int_m_loaded = self:new("alpine-baselayout/interfaces")
--- if (int_m_loaded) then
--- interfaceslist = interfaces.worker.read(interfaces)
--- end
-
- -- Create a cfe-table of the existing records
- local fieldnum = 1
- edit[fieldnum] = cfe({
- label="Zone",
- name=fieldnum,
- value=recordtable[fieldnum],
- type="select",
- option={},
- debug=interfaceslist,
- })
- -- IF user creates '[New]' record... then clean up the output.
- if (record == newrecordtxt) then
- edit[fieldnum]["value"] = "-"
- end
- table.insert(edit[fieldnum]["option"], "-")
- for k,v in pairs(config.zones.option or {}) do
- table.insert(edit[fieldnum]["option"], string.match(v, "^%s*(%S*)"))
- end
- -- IF the value is not one of the existing options, then warn and add this option.
- for k,v in pairs(edit[fieldnum]["option"]) do
- edit[fieldnum]["errtxt"] = "'" .. edit[fieldnum]["value"] .. "' is not a valid option!"
- if (tostring(v) == tostring(edit[fieldnum]["value"])) then
- edit[fieldnum]["errtxt"] = nil
- break
- end
- end
- -- Now add this option to the list (just to show what it was)
- if (edit[fieldnum]["errtxt"]) then
- table.insert(edit[fieldnum]["option"], edit[fieldnum]["value"])
- end
-
- -- Create a cfe-table of the existing records
- local fieldnum = 2
- edit[fieldnum] = cfe({
- label="Interfaces",
- name=fieldnum,
- value=recordtable[fieldnum],
--- descr="Available interfaces are: ",
- })
-
- -- Create a cfe-table of the existing records
- local fieldnum = 3
- edit[fieldnum] = cfe({
- label="Broadcast",
- name=fieldnum,
- value=recordtable[fieldnum],
- })
-
- -- Create a cfe-table of the existing records
- local fieldnum = 4
- edit[fieldnum] = cfe({
- label="Broadcast",
- name=fieldnum,
- value=recordtable[fieldnum],
- })
-
- end
-
- if (types == "zones") then
-
- -- Create a cfe-table of the existing records
- local fieldnum = 1
- edit[fieldnum] = cfe({
- label="Zone",
- name=fieldnum,
- value=recordtable[fieldnum],
- })
-
- -- Create a cfe-table of the existing records
- local fieldnum = 2
- edit[fieldnum] = cfe({
- label="Type",
- name=fieldnum,
- value=recordtable[fieldnum],
- type="select",
- option={"ipv4", "ipsec", "firewall",}
- })
- -- IF user creates '[New]' record... then clean up the output.
- if (record == newrecordtxt) then
- edit[fieldnum]["value"] = "ipv4"
- end
- -- IF the value is not one of the existing options, then warn and add this option.
- for k,v in pairs(edit[fieldnum]["option"]) do
- edit[fieldnum]["errtxt"] = "'" .. edit[fieldnum]["value"] .. "' is not a valid option!"
- if (tostring(v) == tostring(edit[fieldnum]["value"])) then
- edit[fieldnum]["errtxt"] = nil
- break
- end
- end
- -- Now add this option to the list (just to show what it was)
- if (edit[fieldnum]["errtxt"]) then
- table.insert(edit[fieldnum]["option"], edit[fieldnum]["value"])
- end
-
- -- Create a cfe-table of the existing records
- local fieldnum = 3
- edit[fieldnum] = cfe({
- label="Options",
- name=fieldnum,
- value=recordtable[fieldnum],
- })
-
- -- Create a cfe-table of the existing records
- local fieldnum = 4
- edit[fieldnum] = cfe({
- label="IN Options",
- name=fieldnum,
- value=recordtable[fieldnum],
- })
-
- -- Create a cfe-table of the existing records
- local fieldnum = 5
- edit[fieldnum] = cfe({
- label="OUT Options",
- name=fieldnum,
- value=recordtable[fieldnum],
- })
- end
-
- if (types == "policy") then
-
- -- Create a cfe-table of the existing records
- local fieldnum = 1
- edit[fieldnum] = cfe({
- label="Source zone",
- name=fieldnum,
- value=recordtable[fieldnum],
- type="select",
- option=self.model.get_defined_zones(),
- })
- -- IF user creates '[New]' record... then clean up the output.
- if (record == newrecordtxt) then
- edit[fieldnum]["value"] = "all"
- end
- table.insert(edit[fieldnum]["option"], "$FW")
- table.insert(edit[fieldnum]["option"], "all")
- -- IF the value is not one of the existing options, then warn and add this option.
- for k,v in pairs(edit[fieldnum]["option"]) do
- edit[fieldnum]["errtxt"] = "'" .. edit[fieldnum]["value"] .. "' is not a valid option!"
- if (tostring(v) == tostring(edit[fieldnum]["value"])) then
- edit[fieldnum]["errtxt"] = nil
- break
- end
- end
- -- Now add this option to the list (just to show what it was)
- if (edit[fieldnum]["errtxt"]) then
- table.insert(edit[fieldnum]["option"], edit[fieldnum]["value"])
- end
-
-
- -- Create a cfe-table of the existing records
- local fieldnum = 2
- edit[fieldnum] = cfe({
- label="Destination zone",
- name=fieldnum,
- value=recordtable[fieldnum],
- type="select",
- option=self.model.get_defined_zones(),
- })
- -- IF user creates '[New]' record... then clean up the output.
- if (record == newrecordtxt) then
- edit[fieldnum]["value"] = "all"
- end
- table.insert(edit[fieldnum]["option"], "$FW")
- table.insert(edit[fieldnum]["option"], "all")
- -- IF the value is not one of the existing options, then warn and add this option.
- for k,v in pairs(edit[fieldnum]["option"]) do
- edit[fieldnum]["errtxt"] = "'" .. edit[fieldnum]["value"] .. "' is not a valid option!"
- if (tostring(v) == tostring(edit[fieldnum]["value"])) then
- edit[fieldnum]["errtxt"] = nil
- break
- end
- end
- -- Now add this option to the list (just to show what it was)
- if (edit[fieldnum]["errtxt"]) then
- table.insert(edit[fieldnum]["option"], edit[fieldnum]["value"])
- end
-
-
- -- Create a cfe-table of the existing records
- local fieldnum = 3
- edit[fieldnum] = cfe({
- label="Policy",
- name=fieldnum,
- value=recordtable[fieldnum],
- type="select",
- option={"ACCEPT","DROP","REJECT","CONTINUE","QUEUE","NONE"}
- })
- -- IF user creates '[New]' record... then clean up the output.
- if (record == newrecordtxt) then
- edit[fieldnum]["value"] = "DROP"
- end
- -- IF the value is not one of the existing options, then warn and add this option.
- for k,v in pairs(edit[fieldnum]["option"]) do
- edit[fieldnum]["errtxt"] = "'" .. edit[fieldnum]["value"] .. "' is not a valid option!"
- if (tostring(v) == tostring(edit[fieldnum]["value"])) then
- edit[fieldnum]["errtxt"] = nil
- break
- end
- end
- -- Now add this option to the list (just to show what it was)
- if (edit[fieldnum]["errtxt"]) then
- table.insert(edit[fieldnum]["option"], edit[fieldnum]["value"])
- end
-
- -- Create a cfe-table of the existing records
- local fieldnum = 4
- edit[fieldnum] = cfe({
- label="Log level",
- name=fieldnum,
- value=recordtable[fieldnum],
- })
-
- -- Create a cfe-table of the existing records
- local fieldnum = 5
- edit[fieldnum] = cfe({
- label="Burst:Limit",
- name=fieldnum,
- value=recordtable[fieldnum],
- })
- end
-
- if (types == "rules") then
-
- -- Create a cfe-table of the existing records
- local fieldnum = 1
- edit[fieldnum] = cfe({
- label="Action",
- name=fieldnum,
- value=recordtable[fieldnum],
- type="select",
- option={
- "ACCEPT", "ACCEPT+", "ACCEPT!",
- "NONAT",
- "DROP", "DROP!",
- "REJECT", "REJECT!",
- "DNAT", "DNAT-",
- "REDIRECT", "REDIRECT-",
- "CONTINUE", "CONTINUE!",
- "LOG",
- "QUEUE", "QUEUE!",
- "COMMENT",
- },
- })
- -- IF user creates '[New]' record... then clean up the output.
- if (record == newrecordtxt) then
- edit[fieldnum]["value"] = "DROP"
- end
- -- IF the value is not one of the existing options, then warn and add this option.
- for k,v in pairs(edit[fieldnum]["option"]) do
- edit[fieldnum]["errtxt"] = "Attention! '" .. edit[fieldnum]["value"] .. "' could be a invalid option (or is a action defined in 'actions')."
- if (tostring(v) == tostring(edit[fieldnum]["value"])) then
- edit[fieldnum]["errtxt"] = nil
- break
- end
- end
- -- Now add this option to the list (just to show what it was)
- if (edit[fieldnum]["errtxt"]) then
- table.insert(edit[fieldnum]["option"], edit[fieldnum]["value"])
- end
-
-
- -- Create a cfe-table of the existing records
- local fieldnum = 2
- edit[fieldnum] = cfe({
- label="Source",
- name=fieldnum,
- value=recordtable[fieldnum],
- })
-
- -- Create a cfe-table of the existing records
- local fieldnum = 3
- edit[fieldnum] = cfe({
- label="Destination",
- name=fieldnum,
- value=recordtable[fieldnum],
- })
-
- -- Create a cfe-table of the existing records
- local fieldnum = 4
- edit[fieldnum] = cfe({
- label="Proto",
- name=fieldnum,
- value=recordtable[fieldnum],
- })
-
- -- Create a cfe-table of the existing records
- local fieldnum = 5
- edit[fieldnum] = cfe({
- label="Destination port",
- name=fieldnum,
- value=recordtable[fieldnum],
- })
-
- -- Create a cfe-table of the existing records
- local fieldnum = 6
- edit[fieldnum] = cfe({
- label="Source port(s)",
- name=fieldnum,
- value=recordtable[fieldnum],
- })
-
- -- Create a cfe-table of the existing records
- local fieldnum = 7
- edit[fieldnum] = cfe({
- label="Original destination",
- name=fieldnum,
- value=recordtable[fieldnum],
- })
-
- -- Create a cfe-table of the existing records
- local fieldnum = 8
- edit[fieldnum] = cfe({
- label="Rate:Limit",
- name=fieldnum,
- value=recordtable[fieldnum],
- })
-
- -- Create a cfe-table of the existing records
- local fieldnum = 9
- edit[fieldnum] = cfe({
- label="User/Group",
- name=fieldnum,
- value=recordtable[fieldnum],
- })
-
- -- Create a cfe-table of the existing records
- local fieldnum = 9
- edit[fieldnum] = cfe({
- label="Mark",
- name=fieldnum,
- value=recordtable[fieldnum],
- })
-
- end
-
- -- Add a hidden input where we define which config-file should be modified
- edit.filename = cfe({
- label="File to edit",
- name="filename",
- value=types,
- type="hidden",
- })
-
-
- return {
- edit=edit,
- option={ script=self.conf.script,
- prefix=self.conf.prefix,
- controller = self.conf.controller,
- action = "config",
- link = self.conf.script .. self.conf.prefix .. self.conf.controller, },
- cmdsave=cmdsave,
- cmddelete=cmddelete,
- clientdata=clientdata,
- }
-end
-
-function mymodule.config(self)
-
- -- If we made some changes to a recods... then proceed with the modification
- local savesuccess, configmessage
- if (self.clientdata.cmdsave) or (self.clientdata.cmddelete) then
-
- -- Check to see that user has entered accepted values
- local inputfields = {}
- local invalidinputfields
- if (self.clientdata) then
- for i=1,#self.clientdata do
- table.insert(inputfields, self.clientdata[i])
- if (self.clientdata[i+1]) and (#self.clientdata[i+1] > 0 ) and (#self.clientdata[i] == 0) then
- configmessage = cfe({errtxt="Skipped fileds should contain '-'"})
- end
- end
- end
-
- -- What are we going to do with the record...
- local modify_actiontype = self.clientdata.actiontype or "unknown"
- if (self.clientdata.cmddelete) then
- modify_actiontype = "delete"
- end
-
-
-
- if not ((configmessage) and (configmessage.errtxt)) then
- --Actually change the values
- savesuccess, configmessage = self.model:modify_config(modify_actiontype,
- self.clientdata.filename,
- inputfields,
- self.clientdata.orgrecord)
- end
-
- end
- -- If we previously made some changes, report this to user
- if ((self.clientdata.cmdsave) or (self.clientdata.cmddelete)) and not (savesuccess) then
- self.conf.action = "editrecords"
- self.conf.type = "redir"
- return editrecords(self,self.clientdata.filename, self.clientdata.orgrecord,tostring((configmessage.errtxt or "")))
- end
-
- local config=self.model:getconfig()
-
- -- Add a [New] record to the options
- table.insert(config.params.option, newrecordtxt)
-
- -- Add button
- config.params_cmd = cfe ({
- name="params_cmd",
- label="Edit above record",
- value="Edit",
- type="submit",
- })
- config.params_cmd.descr="Mark a item in above list before pressing [" .. config.params_cmd.value .. "]"
-
- -- Add button
- config.interfaces_cmd = cfe ({
- name="interfaces_cmd",
- label="Edit above record",
- value="Edit",
- type="submit",
- })
- config.interfaces_cmd.descr="Mark a item in above list before pressing [" .. config.interfaces_cmd.value .. "]"
-
- -- Add button
- config.zones_cmd = cfe ({
- name="zones_cmd",
- label="Edit above record",
- value="Edit",
- type="submit",
- })
- config.zones_cmd.descr="Mark a item in above list before pressing [" .. config.zones_cmd.value .. "]"
-
- -- Add button
- config.policy_cmd = cfe ({
- name="policy_cmd",
- label="Edit above record",
- value="Edit",
- type="submit",
- })
- config.policy_cmd.descr="Mark a item in above list before pressing [" .. config.policy_cmd.value .. "]"
-
- -- Add button
- config.rules_cmd = cfe ({
- name="rules_cmd",
- label="Edit above record",
- value="Edit",
- type="submit",
- })
- config.rules_cmd.descr="Mark a item in above list before pressing [" .. config.rules_cmd.value .. "]"
-
- -- Add button
- config.check_cmd = cfe ({
- name="check_cmd",
- label="Check if config works",
- descr="After your check, you will be able to start/stop/restart the process.",
- errtxt="Attention! This check could take a long time depending on your configuration.",
- value="Check",
- type="submit",
- })
-
- -- Redirect if button is pressed
- if (self.clientdata.params_cmd) and (self.clientdata.params) then
- self.conf.action = "editrecords"
- self.conf.type = "redir"
- return editrecords(self,"params", self.clientdata.params)
- elseif (self.clientdata.params_cmd) and not (self.clientdata.params) then
- config.params_cmd.errtxt = "You need to specify a record to edit!"
- end
-
- -- Redirect if button is pressed
- if (self.clientdata.interfaces_cmd) and (self.clientdata.interfaces) then
- self.conf.action = "editrecords"
- self.conf.type = "redir"
- return editrecords(self,"interfaces", self.clientdata.interfaces)
- elseif (self.clientdata.interfaces_cmd) and not (self.clientdata.interfaces) then
- config.interfaces_cmd.errtxt = "You need to specify a record to edit!"
- end
-
- -- Redirect if button is pressed
- if (self.clientdata.zones_cmd) and (self.clientdata.zones) then
- self.conf.action = "editrecords"
- self.conf.type = "redir"
- return editrecords(self,"zones", self.clientdata.zones)
- elseif (self.clientdata.zones_cmd) and not (self.clientdata.zones) then
- config.zones_cmd.errtxt = "You need to specify a record to edit!"
- end
-
- -- Redirect if button is pressed
- if (self.clientdata.policy_cmd) and (self.clientdata.policy) then
- self.conf.action = "editrecords"
- self.conf.type = "redir"
- return editrecords(self,"policy", self.clientdata.policy)
- elseif (self.clientdata.policy_cmd) and not (self.clientdata.policy) then
- config.policy_cmd.errtxt = "You need to specify a record to edit!"
- end
-
- -- Redirect if button is pressed
- if (self.clientdata.rules_cmd) and (self.clientdata.rules) then
- self.conf.action = "editrecords"
- self.conf.type = "redir"
- return editrecords(self,"rules", self.clientdata.rules)
- elseif (self.clientdata.rules_cmd) and not (self.clientdata.rules) then
- config.rules_cmd.errtxt = "You need to specify a record to edit!"
- end
-
- -- If we previously made some changes, report this to user
- if ((self.clientdata.cmdsave) or (self.clientdata.cmddelete)) and (savesuccess) and (configmessage) and (configmessage.descr) then
- local reporttobutton = self.clientdata.filename .. "_cmd"
- if (config[reporttobutton]) then
- config[reporttobutton]["descr"] = tostring(configmessage.descr)
- end
- end
-
- return {
- config=config,
- option={ script=self.conf.script,
- prefix=self.conf.prefix,
- controller = self.conf.controller,
- action = "check",
- link = self.conf.script .. self.conf.prefix .. self.conf.controller, },
- clientdata=clientdata,
- savesuccess=savesuccess,
- configmessage=configmessage,
- }
-end
---]]
return mymodule
diff --git a/shorewall-model.lua b/shorewall-model.lua
index 75fccb5..1817199 100644
--- a/shorewall-model.lua
+++ b/shorewall-model.lua
@@ -10,162 +10,6 @@ local configfile = "/etc/shorewall/shorewall.conf"
local processname = "shorewall"
local packagename = "shorewall-shell"
local baseurl = "/etc/shorewall/"
---[[
-local config = {}
-
--- ################################################################################
--- LOCAL FUNCTIONS
-
-local function read_config(file)
- local path = baseurl .. file
- if not (fs.is_file(path)) then
- return {}
- end
- local filecontent = fs.read_file_as_array(path) or {}
- local output = {}
- for k,v in pairs(filecontent) do
- if not string.find ( v, "^[;#].*" ) and not (string.find (v, "^%s*$")) then
- local details = {}
- for v in string.gmatch(v, "%S+") do
- table.insert(details, v)
- end
- table.insert(output, details)
- end
- end
- return output
-end
-
-local function addremove_config( addremove, file, value, orgvalue )
- filepath = baseurl .. file
- local cmdoutput
-
- -- Check if we are about to change a valid filename
- local isvalidfile
- for k,v in pairs(mymodule.getfilelist()) do
- isvalidfile = true
- if (v.value == filepath) then
- break
- end
- isvalidfile = false
- end
- if not (fs.is_file(filepath)) or not (isvalidfile) then
- return false, cfe({
- name="model:addremove_config()",
- errtxt="'" .. filepath .. "' is not a valid file!",
- })
- end
-
- if not (type(value) == "table") then
- return false, cfe({
- name="model:addremove_config()",
- errtxt="Value should come as an array!",
- })
- end
-
- local filecontentarray = fs.read_file_as_array(filepath) or {}
-
- if (addremove == "delete" ) then
- local modifyrow
- local orgrecordtable = {}
- for word in string.gmatch(orgvalue, "%S+") do
- table.insert(orgrecordtable, word)
- end
- for i=1, #filecontentarray do
- local recordtable = {}
- for word in string.gmatch(filecontentarray[i], "%S+") do
- table.insert(recordtable, word)
- end
-
- if (table.concat(recordtable) == table.concat(orgrecordtable)) then
- modifyrow = i
- end
- end
-
- if (tonumber(modifyrow)) then
- table.remove(filecontentarray, modifyrow)
- fs.write_file(filepath, table.concat(filecontentarray, "\n"))
- return true, cfe({
- name="model:addremove_config()",
- descr="* Record was successfully deleted!",
- })
- else
- return false, cfe({
- name="model:addremove_config()",
- errtxt="Record was not deleted!",
- })
- end
-
- elseif (addremove == "add" ) then
- --Check if such record already exists
- for k,v in pairs(filecontentarray) do
- if not string.find ( v, "^[;#].*" ) then
- local recordtable = {}
- for word in string.gmatch(v, "%S+") do
- table.insert(recordtable, word)
- end
- if (table.concat(recordtable) == table.concat(value)) then
- return false, cfe({
- name="model:addremove_config()",
- errtxt="The config already holds this kind of config!",
- })
- end
- end
- end
-
- table.insert(filecontentarray, (#filecontentarray), table.concat(value, "\t"))
- fs.write_file(filepath, table.concat(filecontentarray, "\n"))
- return true, cfe({
- name="model:addremove_config()",
- descr="* Record was successfully added!",
- })
-
- elseif (addremove == "modify" ) then
- local modifyrow
- local orgrecordtable = {}
- for word in string.gmatch(orgvalue, "%S+") do
- table.insert(orgrecordtable, word)
- end
- for i=1, #filecontentarray do
- local recordtable = {}
- for word in string.gmatch(filecontentarray[i], "%S+") do
- table.insert(recordtable, word)
- end
-
- if (table.concat(recordtable) == table.concat(orgrecordtable)) then
- modifyrow = i
- end
- end
-
- if (tonumber(modifyrow)) then
- table.remove(filecontentarray, modifyrow)
- table.insert(filecontentarray, modifyrow, table.concat(value, "\t"))
- fs.write_file(filepath, table.concat(filecontentarray, "\n"))
- return true, cfe({
- name="model:addremove_config()",
- descr="* Record was successfully modified!",
- })
- else
- return false, cfe({
- name="model:addremove_config()",
- errtxt="Record was not modified!",
- })
- end
-
- else
- return false, cfe({
- name="model:addremove_config()",
- errtxt="Wrong usage of this function! Available options are [add|delete|modify]. You chose '" .. addremove .. "'",
- })
- end
-
- return false, cfe({
- name="model:addremove_config()",
- errtxt="Something went wrong!",
- debug=value,
- })
-end
---]]
-
-- ################################################################################
-- PUBLIC FUNCTIONS
@@ -227,71 +71,4 @@ function mymodule.updatefiledetails(self, filedetails)
return modelfunctions.setfiledetails(self, filedetails, is_valid_filename)
end
---[[
-function mymodule.modify_config(self, addremove, file, value, orgvalue )
- return addremove_config(addremove, file, value, orgvalue )
-end
-
-function mymodule.getconfig()
- local config = {}
-
- config.params = cfe({
- name = "params",
- label="List of parameters",
- type="select",
- option={},
- })
- for k,v in pairs(read_config("params")) do
- table.insert(config.params.option, v[1])
- end
- config.params.size=#config.params.option + 1
-
- config.interfaces = cfe({
- name = "interfaces",
- label="List of interfaces",
- type="select",
- option=read_config("interfaces"),
- })
-
- config.zones = cfe({
- name = "zones",
- label="List of zones",
- type="select",
- option=read_config("zones"),
- })
-
- config.policy = cfe({
- name = "policy",
- label="List of policy",
- type="select",
- option=read_config("policy"),
- })
-
- config.rules = cfe({
- name = "rules",
- label="List of rules",
- type="select",
- option=read_config("rules"),
- })
-
- config.masq = cfe({
- name = "masq",
- label="List of rules",
- type="select",
- option=read_config("masq"),
- })
-
- return config
-
-end
-
-function mymodule.get_defined_zones ()
- local output = {}
- for k,v in pairs(read_config("zones")) do
- table.insert(output, string.match(v, "^%s*(%S*)"))
- end
- return output
-end
---]]
-
return mymodule