diff options
Diffstat (limited to 'shorewall-controller.lua')
-rw-r--r-- | shorewall-controller.lua | 161 |
1 files changed, 99 insertions, 62 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, |