diff options
author | Mike Mason <ms13sp@gmail.com> | 2008-11-05 21:29:48 +0000 |
---|---|---|
committer | Mike Mason <ms13sp@gmail.com> | 2008-11-05 21:29:48 +0000 |
commit | ca8fdaf2abd1e3d74d94e03d792940cac02d7c04 (patch) | |
tree | d26f47ada90c2d49d02618efba43141148b664a3 /chrony-model.lua | |
parent | 2cbade4ec6f2175ce1291ae9a49d5098b6477029 (diff) | |
download | acf-chrony-ca8fdaf2abd1e3d74d94e03d792940cac02d7c04.tar.bz2 acf-chrony-ca8fdaf2abd1e3d74d94e03d792940cac02d7c04.tar.xz |
End of day commit. Still need some work. Updating to have more viewed options
git-svn-id: svn://svn.alpinelinux.org/acf/chrony/trunk@1580 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'chrony-model.lua')
-rw-r--r-- | chrony-model.lua | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/chrony-model.lua b/chrony-model.lua index 7dbf994..f2be0b1 100644 --- a/chrony-model.lua +++ b/chrony-model.lua @@ -2,11 +2,14 @@ module(..., package.seeall) -- Load libraries require("modelfunctions") +require("format") +require("fs") -- Set variables local configfile = "/etc/chrony/chrony.conf" local processname = "chronyd" local packagename = "chrony" +local keyfile = "/etc/chrony/chrony.keys" -- ################################################################################ -- LOCAL FUNCTIONS @@ -18,6 +21,67 @@ function startstop_service(action) return modelfunctions.startstop_service(processname, action) end +function getconfig() + local output = {} + output.SERVER = cfe({ value="0.pool.ntp.org", label="server" }) + output.ALLOW = cfe({ value="all", label="allow" }) + output.DRIFTFILE = cfe({ value="/var/log/chrony/chrony.drift", label="driftfile"}) + output.KEYFILE = cfe({value="/etc/chrony/chrony.keys", label="keyfile"}) + output.LOGDIR = cfe({value="/var/log/chrony", label="logdir"}) + +--require ("html") + + local config = format.parse_configfile(fs.read_file(configfile)) + if config then + output.SERVER.value = config.server or output.SERVER.value + output.ALLOW.value = config.allow or output.ALLOW.value + output.DRIFTFILE.value = config.driftfile or output.DRIFTFILE.value + output.KEYFILE.value = config.keyfile or output.KEYFILE.value + output.LOGDIR.value = config.logdir or output.LOGDIR.value + end +--APP.logevent(html.cfe_unpack(output)) +--APP.logevent(html.cfe_unpack(config)) +return cfe({ type="group", value=output, label="Chrony Config" }) +end + + +function update_config(config) + local success, config = validate_config(config) + + if success then + for name,val in pairs(config.value) do + val.line = name.." "..config_value(val.value) + end + + local lines = {} + for line in string.gmatch(fs.read_file(configfile) or "", "([^\n]*)\n?") do + for name,val in pairs(config.value) do + if val.line and string.find(line, "^%s*#?%s*"..name) then + if string.find(line, "^%s*#") then + lines[#lines+1] = val.line + else + line = val.line + end + val.line = nil + end + end + lines[#lines+1] = line + end + + for name,val in pairs(config.value) do + if val.line then + lines[#lines+1] = val.line + val.line = nil + end + end + fs.write_file(configfile, string.gsub(table.concat(lines, "\n"), "\n+$", "")) + else + config.errtxt = "Failed to save config" + end + + return config +end + function getstatus() return modelfunctions.getstatus(processname, packagename, "Chrony Status") end |