diff options
author | Mika Havela <mika.havela@gmail.com> | 2007-12-07 10:36:41 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2007-12-07 10:36:41 +0000 |
commit | 6f8bd836d7be61dd04b3521a2ffefe7e927de18d (patch) | |
tree | 1e37c12a367e8541978ee8c992dc282fe260d3d8 /openntpd-controller.lua | |
parent | 95f699fa380368841157fdd7043ff7730bcae50e (diff) | |
download | acf-openntpd-6f8bd836d7be61dd04b3521a2ffefe7e927de18d.tar.bz2 acf-openntpd-6f8bd836d7be61dd04b3521a2ffefe7e927de18d.tar.xz |
Cleaning up code. Adding functionallity to add/remove listen address. Error message displayed when something is missing for the desired action. The controller keeps track of things needed before asking the model.
git-svn-id: svn://svn.alpinelinux.org/acf/openntpd/trunk@418 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'openntpd-controller.lua')
-rw-r--r-- | openntpd-controller.lua | 92 |
1 files changed, 67 insertions, 25 deletions
diff --git a/openntpd-controller.lua b/openntpd-controller.lua index 4a74fca..6a22744 100644 --- a/openntpd-controller.lua +++ b/openntpd-controller.lua @@ -21,39 +21,72 @@ end settings = function (self) local cmd = self.clientdata.cmd - errors = {} + local errors = {} + local modify_opts = nil local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller - if (self.clientdata.settings_cmd ~= nil) then + local hosts_cmd = tostring(self.clientdata.hosts_cmd) + local hosts_cmd = string.lower(hosts_cmd) + local listen_cmd = tostring(self.clientdata.listen_cmd) + local listen_cmd = string.lower(listen_cmd) + local settings_cmd = tostring(self.clientdata.settings_cmd) + local settings_cmd = string.lower(settings_cmd) + + -- SECTION WHERE YOU SAVE NEW SETTINGS + if ( hosts_cmd == "delete") then + if not (self.clientdata.hosts_list) then + errors["hosts_list"]="You need to choose something in the list to delete" + end + if (self.clientdata.hosts_list) then + modify_opts = self.model:modify_config(hosts_cmd, nil, self.clientdata.hosts_list) + end + elseif (hosts_cmd == "add") then + if (self.clientdata.hosts_add == "") then + errors["hosts_add"]="You need to enter a server/IP" + end + if (self.clientdata.hosts_type == nil) then + errors["hosts_type"]="You need to choose type of server" + end + if (self.clientdata.hosts_add ~= "") and (self.clientdata.hosts_type ~= nil) then + modify_opts = self.model:modify_config(hosts_cmd, nil, self.clientdata.hosts_type .. " " .. self.clientdata.hosts_add) + end + elseif (listen_cmd == "add") then + if (self.clientdata.listen_add == "") then + errors["listen_add"]="You need to enter what you want to listen at" + end + if (self.clientdata.listen_add ~= "") then + modify_opts = self.model:modify_config(listen_cmd, nil, "listen on " .. self.clientdata.listen_add) + end + elseif (listen_cmd == "delete") then + if not (self.clientdata.listen_list) then + errors["listen_list"]="You need to choose something in the list to delete" + end + if (self.clientdata.listen_list) then + modify_opts = self.model:modify_config(listen_cmd, nil, self.clientdata.listen_list) + end + elseif (settings_cmd == "save") then if (self.clientdata.settings_startup) then modify_opts = self.model:modify_opts("add", "/etc/conf.d/ntpd", "NTPD_OPTS", "-s") else modify_opts = self.model:modify_opts("remove", "/etc/conf.d/ntpd", "NTPD_OPTS", "-s") end end - if (self.clientdata.hosts_cmd) then - if (string.lower(self.clientdata.hosts_cmd) == "delete") then - modify_opts = self.model:modify_config(self.clientdata.hosts_cmd, nil, self.clientdata.hosts_list) - elseif (string.lower(self.clientdata.hosts_cmd) == "add") then - if (self.clientdata.hosts_add == "") then - errors = {hosts_add = "You need to enter a server/IP" } - end - if (self.clientdata.hosts_type == nil) then - errors = {hosts_type = "You need to choose type of server" } - end - if (self.clientdata.hosts_add ~= "") and (self.clientdata.hosts_type ~= nil) then - modify_opts = self.model:modify_config(self.clientdata.hosts_cmd, nil, - self.clientdata.hosts_type .. " " .. self.clientdata.hosts_add) - end - end - end --- DEBUG INFO --- modify_opts = self.clientdata.hosts_cmd + + DEBUGMODEL = modify_opts -- <<< DEBUG INFO >>> + DEBUGCLIENTDATA = self.clientdata -- <<< DEBUG INFO >>> if ( cmd ~= nil ) then local startstop = self.model:startstop_service( cmd ) posix.sleep(1) -- Wait for the process to start|stop - return ( {statusinfo = self.model:get(), startstop = "", modify_opts=modify_opts, url = url } ) + return ( {statusinfo = self.model:get(), + startstop = "", + modify_opts=modify_opts, + url = url } ) else - return ( {statusinfo = self.model:get(), startstop = "", errors = errors, modify_opts=modify_opts, url = url, DEBUG=test } ) + return ( {statusinfo = self.model:get(), startstop = "", + errors = errors, + modify_opts=modify_opts, + url = url, + DEBUGMODEL=DEBUGMODEL, + DEBUGCLIENTDATA=DEBUGCLIENTDATA } ) end end @@ -74,14 +107,23 @@ advanced = function (self) if ( filecontent ~= "") then local me = ( {filecontent = self.model:update_filecontent(filecontent), url = url } ) - return ( {startstop = "", statusinfo = self.model:get(), filecontent = self.model:get_filecontent(), url = url } ) + return ( {startstop = "", + statusinfo = self.model:get(), + filecontent = self.model:get_filecontent(), + url = url } ) else if ( cmd ~= nil ) then local startstop = self.model:startstop_service( cmd ) posix.sleep(1) -- Wait for the process to start|stop - return ( {startstop = startstop, statusinfo = self.model:get(), filecontent = self.model:get_filecontent(), url = url } ) + return ( {startstop = startstop, + statusinfo = self.model:get(), + filecontent = self.model:get_filecontent(), + url = url } ) else - return ( {startstop = "", statusinfo = self.model:get(), filecontent = self.model:get_filecontent(), url = url } ) + return ( {startstop = "", + statusinfo = self.model:get(), + filecontent = self.model:get_filecontent(), + url = url } ) end end end |