diff options
author | Ted Trask <ttrask01@yahoo.com> | 2013-10-18 20:06:41 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2013-10-18 20:06:41 +0000 |
commit | 4e011f1966925211d9c319901bafa0daf20b1a17 (patch) | |
tree | e27ba22ca0a2e79278580fa1406cff0b70b0c089 /chrony-model.lua | |
parent | f6b8fb0c19cdaf8cd0263b36d0aa615175cf863f (diff) | |
download | acf-chrony-4e011f1966925211d9c319901bafa0daf20b1a17.tar.bz2 acf-chrony-4e011f1966925211d9c319901bafa0daf20b1a17.tar.xz |
Remove all calls to 'module' in preparation for move to Lua 5.2
Use mymodule parameter for module definition.
This was also helpful in revealing places where the code relied on the global environment.
Diffstat (limited to 'chrony-model.lua')
-rw-r--r-- | chrony-model.lua | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/chrony-model.lua b/chrony-model.lua index b2ee1ae..a1b937f 100644 --- a/chrony-model.lua +++ b/chrony-model.lua @@ -1,4 +1,4 @@ -module(..., package.seeall) +local mymodule = {} -- Load libraries modelfunctions = require("modelfunctions") @@ -17,7 +17,7 @@ local keyfile = "/etc/chrony/chrony.keys" -- ################################################################################ -- LOCAL FUNCTIONS -function validate_config(config) +local function validate_config(config) local success = true for i,val in ipairs(config.value.server.value) do if string.find(val, "[^%w%s.-]") then @@ -54,7 +54,7 @@ local function get_keyfilestatus(filedetails) -- check to see if the file is being used filedetails.value.status = cfe({ value="Key file in use", label="Key file status" }) - local config = get_config() + local config = mymodule.get_config() if config.value.keyfile.value ~= keyfile then filedetails.value.status.value = "" filedetails.value.status.errtxt = "Key file is not in use" @@ -66,18 +66,18 @@ end -- ################################################################################ -- PUBLIC FUNCTIONS -function get_startstop(self, clientdata) +function mymodule.get_startstop(self, clientdata) local retval = modelfunctions.get_startstop(processname) retval.option[#retval.option+1] = "Online" retval.option[#retval.option+1] = "Offline" return retval end -function startstop_service(self, startstop, action) +function mymodule.startstop_service(self, startstop, action) local lower = action:lower() if lower == "online" or lower == "offline" then -- try to find the password - local config = get_config() + local config = mymodule.get_config() if config.value.keyfile.value == "" then startstop.errtxt = "No key file defined" elseif config.value.commandkey.value == "" then @@ -97,11 +97,11 @@ function startstop_service(self, startstop, action) return startstop end -function getstatus() +function mymodule.getstatus() return modelfunctions.getstatus(processname, packagename, "Chrony Status") end -function getdetails() +function mymodule.getdetails() local details = {} details.time = cfe({ value=os.date(), label="Current Time" }) details.sources = cfe({ type="longtext", value="Unavailable", label="Sources" }) @@ -118,7 +118,7 @@ function getdetails() return cfe({ type="group", value=details, label="Chrony Status Details" }) end -function get_config() +function mymodule.get_config() local output = {} output.server = cfe({ type="list", value={}, label="Servers", descr="List of NTP servers by name or IP (ie. 0.pool.ntp.org). If infrequent Internet connection, follow name/IP with 'offline'.", seq=1 }) output.allow = cfe({ type="list", value={}, label="Allow", descr="List of allowed clients by name/subnet/IP or 'all'.", seq=2 }) @@ -142,7 +142,7 @@ function get_config() return cfe({ type="group", value=output, label="Chrony Config" }) end -function update_config(self, config) +function mymodule.update_config(self, config) local success, config = validate_config(config) if success then @@ -192,23 +192,23 @@ function update_config(self, config) return config end -function get_keyfiledetails() +function mymodule.get_keyfiledetails() return get_keyfilestatus(modelfunctions.getfiledetails(keyfile)) end -function update_keyfiledetails(self, filedetails) +function mymodule.update_keyfiledetails(self, filedetails) return get_keyfilestatus(modelfunctions.setfiledetails(self, filedetails, {keyfile})) end -function get_enable_keyfile() +function mymodule.get_enable_keyfile() local result = {} return cfe({ type="group", value=result, label="Enable Key File" }) end -function enable_keyfile(self, enablerequest) - local config = get_config() +function mymodule.enable_keyfile(self, enablerequest) + local config = mymodule.get_config() config.value.keyfile.value = keyfile - config = update_config(self, config) + config = mymodule.update_config(self, config) if config.errtxt then enablerequest.errtxt = {config.errtxt} for name,val in pairs(config.value) do @@ -221,13 +221,14 @@ function enable_keyfile(self, enablerequest) return enablerequest end -function get_filedetails() +function mymodule.get_filedetails() -- FIXME validate return modelfunctions.getfiledetails(configfile) end -function update_filedetails(self, filedetails) +function mymodule.update_filedetails(self, filedetails) -- FIXME validate return modelfunctions.setfiledetails(self, filedetails, {configfile}) end +return mymodule |