diff options
author | Mika Havela <mika.havela@gmail.com> | 2008-03-06 16:36:19 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2008-03-06 16:36:19 +0000 |
commit | 41d13da850347a5c2691af7e4d4389fec227188a (patch) | |
tree | d97d6dad8c0b41166ddeb7b0877c195cb9fd3afd /shorewall-controller.lua | |
parent | 04d24d79929167c44875b3291849293b359ee480 (diff) | |
download | acf-shorewall-41d13da850347a5c2691af7e4d4389fec227188a.tar.bz2 acf-shorewall-41d13da850347a5c2691af7e4d4389fec227188a.tar.xz |
Now the config-tab works just find (as I can see).
git-svn-id: svn://svn.alpinelinux.org/acf/shorewall/trunk@823 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'shorewall-controller.lua')
-rw-r--r-- | shorewall-controller.lua | 179 |
1 files changed, 117 insertions, 62 deletions
diff --git a/shorewall-controller.lua b/shorewall-controller.lua index b358e67..dd64ae2 100644 --- a/shorewall-controller.lua +++ b/shorewall-controller.lua @@ -61,29 +61,38 @@ 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) +function edit_records(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, @@ -97,8 +106,7 @@ 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.errtxt=errormessage or "" -- Display delete button cmddelete = cfe({ name="cmddelete", @@ -106,9 +114,6 @@ function edit_records(self,types,record) value="Delete", type="submit", }) - cmddelete.disabled="yes" -- DEBUGGING - cmddelete.descr="This button is not yet programmed to work" -- DEBUGGING - if (types == "interfaces") then @@ -134,7 +139,7 @@ function edit_records(self,types,record) edit[fieldnum]["value"] = "-" end table.insert(edit[fieldnum]["option"], "-") - for k,v in pairs(config.zones_list.option or {}) do + 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. @@ -456,7 +461,7 @@ function edit_records(self,types,record) end -- Add a hidden input where we define which config-file should be modified - edit.file = cfe({ + edit.filename = cfe({ label="File to edit", name="filename", value=types, @@ -469,7 +474,7 @@ function edit_records(self,types,record) option={ script=ENV["SCRIPT_NAME"], prefix=self.conf.prefix, controller = self.conf.controller, - action = "save_records", + action = "config", link = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller, }, cmdsave=cmdsave, cmddelete=cmddelete, @@ -482,114 +487,163 @@ function status(self) end function 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 > 0)) 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 = "edit_records" + self.conf.type = "redir" + return edit_records(self,self.clientdata.filename, self.clientdata.orgrecord,tostring((configmessage.errtxt or ""))) + end + local config=self.model:getconfig() local status=self.model.getstatus() -- Add a [New] record to the options - table.insert(config.interfaces_list.option, newrecordtxt) - table.insert(config.zones_list.option, newrecordtxt) - table.insert(config.policies_list.option, newrecordtxt) - table.insert(config.rules_list.option, newrecordtxt) - table.insert(config.params_list.option, newrecordtxt) + table.insert(config.interfaces.option, newrecordtxt) + table.insert(config.zones.option, newrecordtxt) + table.insert(config.policy.option, newrecordtxt) + table.insert(config.rules.option, newrecordtxt) + table.insert(config.params.option, newrecordtxt) -- Add button - config.params_list_cmd = cfe ({ - name="params_list_cmd", + config.params_cmd = cfe ({ + name="params_cmd", label="Edit above record", value="Edit", type="submit", -- disabled="yes", }) - config.params_list_cmd.descr="Mark a item in above list before pressing [" .. config.params_list_cmd.value .. "]" + config.params_cmd.descr="Mark a item in above list before pressing [" .. config.params_cmd.value .. "]" -- Add button - config.interfaces_list_cmd = cfe ({ - name="interfaces_list_cmd", + config.interfaces_cmd = cfe ({ + name="interfaces_cmd", label="Edit above record", value="Edit", type="submit", -- disabled="yes", }) - config.interfaces_list_cmd.descr="Mark a item in above list before pressing [" .. config.interfaces_list_cmd.value .. "]" + config.interfaces_cmd.descr="Mark a item in above list before pressing [" .. config.interfaces_cmd.value .. "]" -- Add button - config.zones_list_cmd = cfe ({ - name="zones_list_cmd", + config.zones_cmd = cfe ({ + name="zones_cmd", label="Edit above record", value="Edit", type="submit", -- disabled="yes", }) - config.zones_list_cmd.descr="Mark a item in above list before pressing [" .. config.zones_list_cmd.value .. "]" + config.zones_cmd.descr="Mark a item in above list before pressing [" .. config.zones_cmd.value .. "]" -- Add button - config.policies_list_cmd = cfe ({ - name="policies_list_cmd", + config.policy_cmd = cfe ({ + name="policy_cmd", label="Edit above record", value="Edit", type="submit", -- disabled="yes", }) - config.policies_list_cmd.descr="Mark a item in above list before pressing [" .. config.policies_list_cmd.value .. "]" + config.policy_cmd.descr="Mark a item in above list before pressing [" .. config.policy_cmd.value .. "]" -- Add button - config.rules_list_cmd = cfe ({ - name="rules_list_cmd", + config.rules_cmd = cfe ({ + name="rules_cmd", label="Edit above record", value="Edit", type="submit", -- disabled="yes", -- errtxt="This button is not yet programmed!", }) - config.rules_list_cmd.descr="Mark a item in above list before pressing [" .. config.rules_list_cmd.value .. "]" + config.rules_cmd.descr="Mark a item in above list before pressing [" .. config.rules_cmd.value .. "]" -- Management buttons -- 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 + if (self.clientdata.params_cmd) and (self.clientdata.params) 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!" + return edit_records(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_list_cmd) and (self.clientdata.interfaces_list) then + if (self.clientdata.interfaces_cmd) and (self.clientdata.interfaces) 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!" + return edit_records(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_list_cmd) and (self.clientdata.zones_list) then + if (self.clientdata.zones_cmd) and (self.clientdata.zones) 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!" + return edit_records(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.policies_list_cmd) and (self.clientdata.policies_list) then + if (self.clientdata.policy_cmd) and (self.clientdata.policy) 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!" + return edit_records(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_list_cmd) and (self.clientdata.rules_list) then + if (self.clientdata.rules_cmd) and (self.clientdata.rules) 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!" + return edit_records(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 { @@ -602,7 +656,8 @@ function config(self) action = "expert", link = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller, }, clientdata=clientdata, - + savesuccess=savesuccess, + configmessage=configmessage, } end |