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 | |
| 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
| -rw-r--r-- | README | 4 | ||||
| -rw-r--r-- | chrony-config-html.lsp | 26 | ||||
| -rw-r--r-- | chrony-controller.lua | 4 | ||||
| -rw-r--r-- | chrony-model.lua | 64 | ||||
| -rw-r--r-- | chrony.menu | 1 | ||||
| -rw-r--r-- | chrony.roles | 3 | 
6 files changed, 101 insertions, 1 deletions
| @@ -0,0 +1,4 @@ +Validation +Add more options +Add more than one server line... + diff --git a/chrony-config-html.lsp b/chrony-config-html.lsp new file mode 100644 index 0000000..9272f40 --- /dev/null +++ b/chrony-config-html.lsp @@ -0,0 +1,26 @@ +<% local form, viewlibrary, page_info, session = ...  +require("viewfunctions") +%> +<% +--[[ DEBUG INFORMATION +io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>") +io.write(html.cfe_unpack(form)) +io.write("</span>") +--]] +%> + +<% displaycommandresults({"startstop"}, session) %> + +<% if viewlibrary and viewlibrary.dispatch_component then +	viewlibrary.dispatch_component("status") +end %> + +<H1>Config</H1> +<% +	form.action = page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action +	displayform(form) +%> + +<% if viewlibrary and viewlibrary.dispatch_component then +	viewlibrary.dispatch_component("startstop") +end %> diff --git a/chrony-controller.lua b/chrony-controller.lua index 5cc1b1b..4b02a8d 100644 --- a/chrony-controller.lua +++ b/chrony-controller.lua @@ -12,6 +12,10 @@ function startstop(self)  	return controllerfunctions.handle_startstop(self, self.model.startstop_service, self.model.getstatus, self.clientdata)  end +function config(self) +	return controllerfunctions.handle_form(self, self.model.getconfig, self.model.setconfig, self.clientdata, "Save", "Edit Config", "Configuration Set") +end +  function expert(self)  	return controllerfunctions.handle_form(self, self.model.get_filedetails, self.model.update_filedetails, self.clientdata, "Save", "Edit Config File", "Configuration Set")  end 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 diff --git a/chrony.menu b/chrony.menu index 56a9f5f..9a63b6d 100644 --- a/chrony.menu +++ b/chrony.menu @@ -1,5 +1,6 @@  #CAT  		GROUP/DESC		TAB		ACTION  Networking 	20NTP(chrony)		Status		time +Networking	46NTP(chrony)		Config		config  Networking 	46NTP(chrony)		Expert		expert  Networking 	46NTP(chrony)		Logfile		logfile diff --git a/chrony.roles b/chrony.roles index 55dcc4b..c217729 100644 --- a/chrony.roles +++ b/chrony.roles @@ -1,3 +1,4 @@  USER=chrony:status,chrony:logfile,chrony:time,chrony:startstop +EDITOR=chrony:config  EXPERT=chrony:expert -ADMIN=chrony:status,chrony:logfile,chrony:time,chrony:startstop,chrony:expert +ADMIN=chrony:status,chrony:config,chrony:logfile,chrony:time,chrony:startstop,chrony:expert | 
