summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-03-05 16:05:29 +0000
committerMika Havela <mika.havela@gmail.com>2008-03-05 16:05:29 +0000
commit04d24d79929167c44875b3291849293b359ee480 (patch)
tree7944a49e3b5309e0d42262824c8e31f7913e5a79
parent1e43af128e100168a0214dde757b7c5ccb21e7f6 (diff)
downloadacf-shorewall-04d24d79929167c44875b3291849293b359ee480.tar.bz2
acf-shorewall-04d24d79929167c44875b3291849293b359ee480.tar.xz
Saving work for today. Editing a record still doesn't work... but we are getting there.
git-svn-id: svn://svn.alpinelinux.org/acf/shorewall/trunk@822 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--shorewall-controller.lua161
-rw-r--r--shorewall-html.lsp16
2 files changed, 112 insertions, 65 deletions
diff --git a/shorewall-controller.lua b/shorewall-controller.lua
index 3f91b63..b358e67 100644
--- a/shorewall-controller.lua
+++ b/shorewall-controller.lua
@@ -61,6 +61,18 @@ end
-- ################################################################################
-- PUBLIC FUNCTIONS
+function save_records(self)
+ return {
+ edit={},
+ option={ script=ENV["SCRIPT_NAME"],
+ prefix=self.conf.prefix,
+ controller = self.conf.controller,
+ action = "save_records",
+ link = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller, },
+ clientdata=self.clientdata,
+ }
+end
+
function edit_records(self,types,record)
local recorddetails = {}
local edit = {}
@@ -74,7 +86,7 @@ function edit_records(self,types,record)
if (types == "params") then
table.insert(edit, cfe({
- name="field1",
+ name=1,
value=recordtable[1],
label="Variable name",
}))
@@ -85,8 +97,8 @@ function edit_records(self,types,record)
-- Display save button
local cmdsave = displaycmdsave()
- cmdsave.disabled="yes" -- DEBUGGING
- cmdsave.descr="This button is not yet programmed to work" -- DEBUGGING
+-- cmdsave.disabled="yes" -- DEBUGGING
+-- cmdsave.descr="This button is not yet programmed to work" -- DEBUGGING
-- Display delete button
cmddelete = cfe({ name="cmddelete",
@@ -111,7 +123,7 @@ function edit_records(self,types,record)
local fieldnum = 1
edit[fieldnum] = cfe({
label="Zone",
- name="field".. fieldnum,
+ name=fieldnum,
value=recordtable[fieldnum],
type="select",
option={},
@@ -142,7 +154,7 @@ function edit_records(self,types,record)
local fieldnum = 2
edit[fieldnum] = cfe({
label="Interfaces",
- name="field".. fieldnum,
+ name=fieldnum,
value=recordtable[fieldnum],
-- descr="Available interfaces are: ",
})
@@ -151,7 +163,7 @@ function edit_records(self,types,record)
local fieldnum = 3
edit[fieldnum] = cfe({
label="Broadcast",
- name="field".. fieldnum,
+ name=fieldnum,
value=recordtable[fieldnum],
})
@@ -159,7 +171,7 @@ function edit_records(self,types,record)
local fieldnum = 4
edit[fieldnum] = cfe({
label="Broadcast",
- name="field".. fieldnum,
+ name=fieldnum,
value=recordtable[fieldnum],
})
@@ -171,7 +183,7 @@ function edit_records(self,types,record)
local fieldnum = 1
edit[fieldnum] = cfe({
label="Zone",
- name="field".. fieldnum,
+ name=fieldnum,
value=recordtable[fieldnum],
})
@@ -179,7 +191,7 @@ function edit_records(self,types,record)
local fieldnum = 2
edit[fieldnum] = cfe({
label="Type",
- name="field".. fieldnum,
+ name=fieldnum,
value=recordtable[fieldnum],
type="select",
option={"ipv4", "ipsec", "firewall",}
@@ -205,7 +217,7 @@ function edit_records(self,types,record)
local fieldnum = 3
edit[fieldnum] = cfe({
label="Options",
- name="field".. fieldnum,
+ name=fieldnum,
value=recordtable[fieldnum],
})
@@ -213,7 +225,7 @@ function edit_records(self,types,record)
local fieldnum = 4
edit[fieldnum] = cfe({
label="IN Options",
- name="field".. fieldnum,
+ name=fieldnum,
value=recordtable[fieldnum],
})
@@ -221,7 +233,7 @@ function edit_records(self,types,record)
local fieldnum = 5
edit[fieldnum] = cfe({
label="OUT Options",
- name="field".. fieldnum,
+ name=fieldnum,
value=recordtable[fieldnum],
})
end
@@ -232,7 +244,7 @@ function edit_records(self,types,record)
local fieldnum = 1
edit[fieldnum] = cfe({
label="Source zone",
- name="field".. fieldnum,
+ name=fieldnum,
value=recordtable[fieldnum],
type="select",
option=self.model.get_defined_zones(),
@@ -261,7 +273,7 @@ function edit_records(self,types,record)
local fieldnum = 2
edit[fieldnum] = cfe({
label="Destination zone",
- name="field".. fieldnum,
+ name=fieldnum,
value=recordtable[fieldnum],
type="select",
option=self.model.get_defined_zones(),
@@ -290,7 +302,7 @@ function edit_records(self,types,record)
local fieldnum = 3
edit[fieldnum] = cfe({
label="Policy",
- name="field".. fieldnum,
+ name=fieldnum,
value=recordtable[fieldnum],
type="select",
option={"ACCEPT","DROP","REJECT","CONTINUE","QUEUE","NONE"}
@@ -316,7 +328,7 @@ function edit_records(self,types,record)
local fieldnum = 4
edit[fieldnum] = cfe({
label="Log level",
- name="field".. fieldnum,
+ name=fieldnum,
value=recordtable[fieldnum],
})
@@ -324,7 +336,7 @@ function edit_records(self,types,record)
local fieldnum = 5
edit[fieldnum] = cfe({
label="Burst:Limit",
- name="field".. fieldnum,
+ name=fieldnum,
value=recordtable[fieldnum],
})
end
@@ -335,7 +347,7 @@ function edit_records(self,types,record)
local fieldnum = 1
edit[fieldnum] = cfe({
label="Action",
- name="field".. fieldnum,
+ name=fieldnum,
value=recordtable[fieldnum],
type="select",
option={
@@ -373,7 +385,7 @@ function edit_records(self,types,record)
local fieldnum = 2
edit[fieldnum] = cfe({
label="Source",
- name="field".. fieldnum,
+ name=fieldnum,
value=recordtable[fieldnum],
})
@@ -381,7 +393,7 @@ function edit_records(self,types,record)
local fieldnum = 3
edit[fieldnum] = cfe({
label="Destination",
- name="field".. fieldnum,
+ name=fieldnum,
value=recordtable[fieldnum],
})
@@ -389,7 +401,7 @@ function edit_records(self,types,record)
local fieldnum = 4
edit[fieldnum] = cfe({
label="Proto",
- name="field".. fieldnum,
+ name=fieldnum,
value=recordtable[fieldnum],
})
@@ -397,7 +409,7 @@ function edit_records(self,types,record)
local fieldnum = 5
edit[fieldnum] = cfe({
label="Destination port",
- name="field".. fieldnum,
+ name=fieldnum,
value=recordtable[fieldnum],
})
@@ -405,7 +417,7 @@ function edit_records(self,types,record)
local fieldnum = 6
edit[fieldnum] = cfe({
label="Source port(s)",
- name="field".. fieldnum,
+ name=fieldnum,
value=recordtable[fieldnum],
})
@@ -413,7 +425,7 @@ function edit_records(self,types,record)
local fieldnum = 7
edit[fieldnum] = cfe({
label="Original destination",
- name="field".. fieldnum,
+ name=fieldnum,
value=recordtable[fieldnum],
})
@@ -421,7 +433,7 @@ function edit_records(self,types,record)
local fieldnum = 8
edit[fieldnum] = cfe({
label="Rate:Limit",
- name="field".. fieldnum,
+ name=fieldnum,
value=recordtable[fieldnum],
})
@@ -429,7 +441,7 @@ function edit_records(self,types,record)
local fieldnum = 9
edit[fieldnum] = cfe({
label="User/Group",
- name="field".. fieldnum,
+ name=fieldnum,
value=recordtable[fieldnum],
})
@@ -437,13 +449,28 @@ function edit_records(self,types,record)
local fieldnum = 9
edit[fieldnum] = cfe({
label="Mark",
- name="field".. fieldnum,
+ name=fieldnum,
value=recordtable[fieldnum],
})
end
+
+ -- Add a hidden input where we define which config-file should be modified
+ edit.file = cfe({
+ label="File to edit",
+ name="filename",
+ value=types,
+ type="hidden",
+ })
+
+
return {
edit=edit,
+ option={ script=ENV["SCRIPT_NAME"],
+ prefix=self.conf.prefix,
+ controller = self.conf.controller,
+ action = "save_records",
+ link = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller, },
cmdsave=cmdsave,
cmddelete=cmddelete,
clientdata=clientdata,
@@ -458,41 +485,6 @@ function config(self)
local config=self.model:getconfig()
local status=self.model.getstatus()
- -- Redirect if button is pressed
- if (self.clientdata.params_list_cmd) then
- self.conf.action = "edit_records"
- self.conf.type = "redir"
- return edit_records(self,"params", self.clientdata.params_list)
- end
-
- -- Redirect if button is pressed
- if (self.clientdata.interfaces_list_cmd) then
- self.conf.action = "edit_records"
- self.conf.type = "redir"
- return edit_records(self,"interfaces", self.clientdata.interfaces_list)
- end
-
- -- Redirect if button is pressed
- if (self.clientdata.zones_list_cmd) then
- self.conf.action = "edit_records"
- self.conf.type = "redir"
- return edit_records(self,"zones", self.clientdata.zones_list)
- end
-
- -- Redirect if button is pressed
- if (self.clientdata.policies_list_cmd) then
- self.conf.action = "edit_records"
- self.conf.type = "redir"
- return edit_records(self,"policy", self.clientdata.policies_list)
- end
-
- -- Redirect if button is pressed
- if (self.clientdata.rules_list_cmd) then
- self.conf.action = "edit_records"
- self.conf.type = "redir"
- return edit_records(self,"rules", self.clientdata.rules_list)
- end
-
-- Add a [New] record to the options
table.insert(config.interfaces_list.option, newrecordtxt)
table.insert(config.zones_list.option, newrecordtxt)
@@ -555,6 +547,51 @@ function config(self)
-- Display management buttons
local management = displaycmdmanagement(disablestart,disablestop,disablerestart)
+ -- Redirect if button is pressed
+ if (self.clientdata.params_list_cmd) and (self.clientdata.params_list) then
+ self.conf.action = "edit_records"
+ self.conf.type = "redir"
+ return edit_records(self,"params", self.clientdata.params_list)
+ elseif (self.clientdata.params_list_cmd) and not (self.clientdata.params_list) then
+ config.params_list_cmd.errtxt = "You need to specify a record to edit!"
+ end
+
+ -- Redirect if button is pressed
+ if (self.clientdata.interfaces_list_cmd) and (self.clientdata.interfaces_list) then
+ self.conf.action = "edit_records"
+ self.conf.type = "redir"
+ return edit_records(self,"interfaces", self.clientdata.interfaces_list)
+ elseif (self.clientdata.interfaces_list_cmd) and not (self.clientdata.interfaces_list) then
+ config.interfaces_list_cmd.errtxt = "You need to specify a record to edit!"
+ end
+
+ -- Redirect if button is pressed
+ if (self.clientdata.zones_list_cmd) and (self.clientdata.zones_list) then
+ self.conf.action = "edit_records"
+ self.conf.type = "redir"
+ return edit_records(self,"zones", self.clientdata.zones_list)
+ elseif (self.clientdata.zones_list_cmd) and not (self.clientdata.zones_list) then
+ config.zones_list_cmd.errtxt = "You need to specify a record to edit!"
+ end
+
+ -- Redirect if button is pressed
+ if (self.clientdata.policies_list_cmd) and (self.clientdata.policies_list) then
+ self.conf.action = "edit_records"
+ self.conf.type = "redir"
+ return edit_records(self,"policy", self.clientdata.policies_list)
+ elseif (self.clientdata.policies_list_cmd) and not (self.clientdata.policies_list) then
+ config.policies_list_cmd.errtxt = "You need to specify a record to edit!"
+ end
+
+ -- Redirect if button is pressed
+ if (self.clientdata.rules_list_cmd) and (self.clientdata.rules_list) then
+ self.conf.action = "edit_records"
+ self.conf.type = "redir"
+ return edit_records(self,"rules", self.clientdata.rules_list)
+ elseif (self.clientdata.rules_list_cmd) and not (self.clientdata.rules_list) then
+ config.rules_list_cmd.errtxt = "You need to specify a record to edit!"
+ end
+
return {
status=status,
config=config,
diff --git a/shorewall-html.lsp b/shorewall-html.lsp
index 878e7ac..1672808 100644
--- a/shorewall-html.lsp
+++ b/shorewall-html.lsp
@@ -43,7 +43,8 @@ end
<?
function displayinfo_special(myform)
- for k,v in pairs(myform) do
+ for i=1,#myform do
+ local v = myform[i]
if (v) and (v["value"]) then
io.write("\n\t<DT")
if (#v.errtxt > 0) then
@@ -61,6 +62,7 @@ function displayinfo_special(myform)
end
?>
+<form name="cmd" action="<?= form.option.link ?>/<?= form.option.action ?>" method="POST">
<H1>EDIT PROPERTIES</H1>
<DL>
@@ -70,16 +72,24 @@ displayinfo_special(myform)
?>
<?
-
local tags = {"cmdsave", "cmddelete", }
local myform = form
displayinfo(myform,tags)
?>
+<? -- Add the field that holds the filename
+local myform = form.edit.file
+if (type(myform) == "table") then
+ io.write(html.form[myform.type](myform))
+end
+?>
+
</DL>
+</form>
+
<?
---[[ DEBUG INFORMATION
+---[[ DEBUG INFORMATION
io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
io.write(html.cfe_unpack(form))
io.write("</span>")