From 0ab11b9ff3aedaa2b1ed23bdd407588bde2576cf Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Tue, 4 Dec 2007 15:28:15 +0000 Subject: Starting up openntpd git-svn-id: svn://svn.alpinelinux.org/acf/openntpd/trunk@403 ab2d0c66-481e-0410-8bed-d214d4d58bed --- Makefile | 43 +++++++++++++++++ config.mk | 10 ++++ openntpd-advanced-html.lsp | 39 +++++++++++++++ openntpd-controller.lua | 34 +++++++++++++ openntpd-model.lua | 118 +++++++++++++++++++++++++++++++++++++++++++++ openntpd-read-html.lsp | 69 ++++++++++++++++++++++++++ openntpd.menu | 2 + 7 files changed, 315 insertions(+) create mode 100644 Makefile create mode 100644 config.mk create mode 100644 openntpd-advanced-html.lsp create mode 100644 openntpd-controller.lua create mode 100644 openntpd-model.lua create mode 100644 openntpd-read-html.lsp create mode 100644 openntpd.menu diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..eff3741 --- /dev/null +++ b/Makefile @@ -0,0 +1,43 @@ +APP_NAME=openntpd +PACKAGE=acf-$(APP_NAME) +VERSION=1.0_alpha1 + +APP_DIST=openntpd.menu + + +EXTRA_DIST=README Makefile config.mk + +DISTFILES=$(APP_DIST) $(EXTRA_DIST) + +TAR=tar + +P=$(PACKAGE)-$(VERSION) +tarball=$(P).tar.bz2 +install_dir=$(DESTDIR)/$(appdir)/$(APP_NAME) + +all: +clean: + rm -rf $(tarball) $(P) + +dist: $(tarball) + +install: + mkdir -p "$(install_dir)" + cp -a $(APP_DIST) "$(install_dir)" + +$(tarball): $(DISTFILES) + rm -rf $(P) + mkdir -p $(P) + cp $(DISTFILES) $(P) + $(TAR) -jcf $@ $(P) + rm -rf $(P) + +# target that creates a tar package, unpacks is and install from package +dist-install: $(tarball) + $(TAR) -jxf $(tarball) + $(MAKE) -C $(P) install DESTDIR=$(DESTDIR) + rm -rf $(P) + +include config.mk + +.PHONY: all clean dist install dist-install diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..45f4d21 --- /dev/null +++ b/config.mk @@ -0,0 +1,10 @@ +prefix=/usr +datadir=${prefix}/share +sysconfdir=${prefix}/etc +localstatedir=${prefix}/var +acfdir=${datadir}/acf +wwwdir=${acfdir}/www +cgibindir=${acfdir}/cgi-bin +appdir=${acfdir}/app +acflibdir=${acfdir}/lib +sessionsdir=${localstatedir}/lib/acf/sessions diff --git a/openntpd-advanced-html.lsp b/openntpd-advanced-html.lsp new file mode 100644 index 0000000..5cb8104 --- /dev/null +++ b/openntpd-advanced-html.lsp @@ -0,0 +1,39 @@ + + + + +

System time

+ +

MENU

+ +
+
Go back to start page
+ +

Details

+ +
File name
+
+ +
File size
+
+ +
Last modified
+
+ + +
Error message
+
+ + +

Content

+
+ + + +
+ diff --git a/openntpd-controller.lua b/openntpd-controller.lua new file mode 100644 index 0000000..d298b1d --- /dev/null +++ b/openntpd-controller.lua @@ -0,0 +1,34 @@ +module (..., package.seeall) + +-- Cause an http redirect to our "read" action +-- We use the self.conf table because it already has prefix,controller,etc +-- The redir code is defined in the application error handler (acf-controller) +local list_redir = function (self) + self.conf.action = "read" + self.conf.type = "redir" + error (self.conf) +end + +mvc={} +mvc.on_load = function(self, parent) + if (self.worker[self.conf.action] == nil ) or ( self.conf.action == "init" ) then + self.worker[self.conf.action] = list_redir(self) + end +end + + +read = function (self) + return ( {filecontent = self.model:get(), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } ) +end + +advanced = function (self) + local filecontent = self.clientdata.modifications or "" + if ( filecontent ~= "") then + local me = ( {filecontent = self.model:update_filecontent(filecontent), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } ) + list_redir(self) + else + local me = ( {filecontent = self.model:get_filecontent(), url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller } ) + return me + end +end + diff --git a/openntpd-model.lua b/openntpd-model.lua new file mode 100644 index 0000000..742c64a --- /dev/null +++ b/openntpd-model.lua @@ -0,0 +1,118 @@ +module (..., package.seeall) + +require("format") +require("fs") + +local ntpdconfig = "/etc/ntpd.conf" +local progname = "openntpd" + +local function config_content( f ) + local config = {} + config.name = f + local conf_file = fs.read_file_as_array ( config.name ) + for i=1,table.maxn(conf_file) do + local l = conf_file[i] + -- Filter out commented lines + if not string.find ( l, "^[;#].*" ) then + local a,b,c = string.match ( l, "^%s*(%S+)%s*(%S*)%s*(%S*).*$" ) + if (a) then + if not (config[string.lower(a)]) then + config[string.lower(a)] = {} + end + if (string.lower(a) == "listen") then + table.insert (config[string.lower(a)], {value=c} ) + else + table.insert (config[string.lower(a)], {value=b} ) + end + end + end + end + return config +end + +local function file_info ( path ) + require("posix") + local filedetails = posix.stat(path) + filedetails["owner"]=rawget((posix.getpasswd(filedetails["uid"])),"name") + filedetails["group"]=rawget((posix.getgroup(filedetails["gid"])),"name") + filedetails["atimelong"]=os.date("%c", filedetails["atime"]) + filedetails["mtimelong"]=os.date("%c", filedetails["mtime"]) + filedetails["longname"]=path + filedetails["name"]=basename(path) + + if ( filedetails["size"] > 1073741824 ) then + filedetails["size"]=((filedetails["size"]/1073741824) - (filedetails["size"]/1073741824%0.1)) .. "G" + elseif ( filedetails["size"] > 1048576 ) then + filedetails["size"]=((filedetails["size"]/1048576) - (filedetails["size"]/1048576%0.1)) .. "M" + elseif ( filedetails["size"] > 1024 ) then + filedetails["size"]=((filedetails["size"]/1024) - (filedetails["size"]/1024%0.1)) .. "k" + else + filedetails["size"]=filedetails["size"] + end + return filedetails +end + +local function get_version () + local f,error = io.popen("/sbin/apk_version -v -s openntpd") + local programversion = f:read("*a") + f:close() + return programversion +end + + +-- ################################################################################ +-- PUBLIC FUNCTIONS +--[[ +function restart_service () + local f,err = io.popen("/etc/init.d/shorewall restart") + local restart = f:read("*a") + f:close() + local status = get_status() + status.restart = restart + return status +end +--]] +--[[ +function get_status () + local f,error = io.popen("/sbin/shorewall status") + local fake = f:read("*l") + local fake = f:read("*l") + local programstatus = f:read("*l") + local programstate = f:read("*l") + f:close() + local f,error = io.popen("/sbin/shorewall version") + local programversion = f:read("*l") + f:close() + return {programversion=programversion,programstatus=programstatus,programstate=programstate} +end +--]] + +function get () + local path = ntpdconfig + config = config_content ( path ) + config["version"] = get_version() + return config +end + +function get_filecontent (self) + local path = ntpdconfig + file_content = nil + if (fs.is_file(path)) then + local filedetails = file_info(path) + local file = io.open( path ) + local file_result = file:read("*a") or "unknown" + file:close() + file_content = {name=name, value=file_result, filedetails=filedetails} + else + file_content = {value="", errtxt="File is missing, but will be created when you save your new settings",filedetails={longname=path, size="0", mtimelong=""}} + end + return file_content +end + +function update_filecontent (self, modifications) + local path = ntpdconfig + local file_result,err = fs.write_file(path, format.dostounix(modifications)) + file_content = get_filecontent() + return file_content +end + diff --git a/openntpd-read-html.lsp b/openntpd-read-html.lsp new file mode 100644 index 0000000..5beee8e --- /dev/null +++ b/openntpd-read-html.lsp @@ -0,0 +1,69 @@ + + +

System time

+ +

SYSTEM INFO

+ +
Program version
+
xxx
+ +
Process running or not
+
xxx
+ +
Current time
+
yyy-mm-dd hh:mm:ss
+ +
TimeZone
+
xxx
+ +

NTPD SETTINGS

+ +
Set time immediately at startup
+
+ +

'SET TIME' OPTIONS

+
Timeserver hosts...
+
+
+In most cases you could use pool.ntp.org or [countryname].pool.ntp.org (if listed in http://www.pool.ntp.org/). +
+ +
Delete selected host
+
(see above)
+ +
Add new host
+
+ +

'PRESENT TIME' OPTIONS (ACT AS TIME SERVER)

+
Listen on address...
+
+
Empty list = Not listening or acting as server; "*" = All local addresses +
+ +
Delete selected address
+
(see above)
+ + +
Add new listen address
+
+ + + + + + diff --git a/openntpd.menu b/openntpd.menu new file mode 100644 index 0000000..14edaa1 --- /dev/null +++ b/openntpd.menu @@ -0,0 +1,2 @@ +#CAT GROUP/DESC TAB ACTION +Setup openNTPD openNTPD read -- cgit v1.2.3