diff options
-rw-r--r-- | alpineversion-controller.lua | 7 | ||||
-rw-r--r-- | alpineversion-model.lua | 6 | ||||
-rw-r--r-- | cron-controller.lua | 22 | ||||
-rw-r--r-- | cron-model.lua | 32 | ||||
-rw-r--r-- | health-controller.lua | 16 | ||||
-rw-r--r-- | health-model.lua | 14 | ||||
-rw-r--r-- | hostname-controller.lua | 10 | ||||
-rw-r--r-- | hostname-model.lua | 12 | ||||
-rw-r--r-- | interfaces-controller.lua | 24 | ||||
-rw-r--r-- | interfaces-definitions.lua | 12 | ||||
-rw-r--r-- | interfaces-model.lua | 40 | ||||
-rw-r--r-- | logfiles-controller.lua | 18 | ||||
-rw-r--r-- | logfiles-model.lua | 20 | ||||
-rw-r--r-- | modules-controller.lua | 12 | ||||
-rw-r--r-- | modules-model.lua | 14 | ||||
-rw-r--r-- | password-controller.lua | 8 | ||||
-rw-r--r-- | password-model.lua | 8 | ||||
-rw-r--r-- | rc-controller.lua | 12 | ||||
-rw-r--r-- | rc-model.lua | 13 | ||||
-rw-r--r-- | syslog-controller.lua | 16 | ||||
-rw-r--r-- | syslog-model.lua | 22 |
21 files changed, 188 insertions, 150 deletions
diff --git a/alpineversion-controller.lua b/alpineversion-controller.lua index 4d785ae..901ea59 100644 --- a/alpineversion-controller.lua +++ b/alpineversion-controller.lua @@ -1,10 +1,11 @@ -- the alpineversion controller -module (..., package.seeall) +local mymodule = {} -default_action = "read" +mymodule.default_action = "read" -read = function (self ) +mymodule.read = function (self ) return self.model.get() end +return mymodule diff --git a/alpineversion-model.lua b/alpineversion-model.lua index b839785..80e38cf 100644 --- a/alpineversion-model.lua +++ b/alpineversion-model.lua @@ -1,12 +1,14 @@ -- alpineversion model methods -module (..., package.seeall) +local mymodule = {} fs = require("acf.fs") -get = function () +mymodule.get = function () local liboutput = fs.read_file("/etc/alpine-release") if (liboutput == nil) or (liboutput == "") then liboutput = "Unknown version" end return cfe({ value=liboutput, label="Alpine version" }) end + +return mymodule diff --git a/cron-controller.lua b/cron-controller.lua index 8c40b13..5d84bd5 100644 --- a/cron-controller.lua +++ b/cron-controller.lua @@ -1,36 +1,38 @@ -- the cron controller -module (..., package.seeall) +local mymodule = {} -default_action = "status" +mymodule.default_action = "status" -function status(self) +function mymodule.status(self) return self.model.getstatus() end -function startstop(self) +function mymodule.startstop(self) return self.handle_form(self, self.model.get_startstop, self.model.startstop_service, self.clientdata) end -function listjobs(self) +function mymodule.listjobs(self) return self.model.listjobs() end -function editjob(self) +function mymodule.editjob(self) return self.handle_form(self, self.model.read_job, self.model.update_job, self.clientdata, "Save", "Edit Job", "Job Saved") end -function deletejob(self) +function mymodule.deletejob(self) return self.handle_form(self, self.model.get_delete_job, self.model.delete_job, self.clientdata, "Delete", "Delete Job", "Job Deleted") end -function movejob(self) +function mymodule.movejob(self) return self.handle_form(self, self.model.get_move_job, self.model.move_job, self.clientdata, "Move", "Move Job", "Job Moved") end -function createjob(self) +function mymodule.createjob(self) return self.handle_form(self, self.model.create_new_job, self.model.create_job, self.clientdata, "Create", "Create New Job", "New Job Created") end -function expert(self) +function mymodule.expert(self) return self.handle_form(self, self.model.read_configfile, self.model.update_configfile, self.clientdata, "Save", "Edit Config File", "Configuration Set") end + +return mymodule diff --git a/cron-model.lua b/cron-model.lua index 46081ac..f34689a 100644 --- a/cron-model.lua +++ b/cron-model.lua @@ -1,4 +1,4 @@ -module (..., package.seeall) +local mymodule = {} posix = require("posix") modelfunctions = require("modelfunctions") @@ -65,37 +65,37 @@ end -- ################################################################################ -- PUBLIC FUNCTIONS -function get_startstop(self, clientdata) +function mymodule.get_startstop(self, clientdata) return modelfunctions.get_startstop(processname) end -function startstop_service(self, startstop, action) +function mymodule.startstop_service(self, startstop, action) return modelfunctions.startstop_service(startstop, action) end -function getstatus() +function mymodule.getstatus() return modelfunctions.getstatus(processname, packagename, "Cron Status") end -function listjobs() +function mymodule.listjobs() return cfe({ type="structure", value=list_jobs(), label="Cron Jobs" }) end -function read_job(self, clientdata) +function mymodule.read_job(self, clientdata) return modelfunctions.getfiledetails(clientdata.name, validate_filename) end -function update_job(self, filedetails) +function mymodule.update_job(self, filedetails) return modelfunctions.setfiledetails(self, filedetails, validate_filename) end -function get_delete_job(self, clientdata) +function mymodule.get_delete_job(self, clientdata) local result = {} result.filename = cfe({ value=clientdata.name or "", label="File Name" }) return cfe({ type="group", value=result, label="Delete Cron Job" }) end -function delete_job(self, deleterequest) +function mymodule.delete_job(self, deleterequest) deleterequest.errtxt = "Invalid File" if validate_filename(deleterequest.value.filename.value) then os.remove(deleterequest.value.filename.value) @@ -104,7 +104,7 @@ function delete_job(self, deleterequest) return deleterequest end -function get_move_job() +function mymodule.get_move_job() local move = {} move.name = cfe({ type="select", label="Name", option=select(2, list_jobs()) }) move.period = cfe({ type="select", label="Period", option=list_periods() }) @@ -113,7 +113,7 @@ function get_move_job() return cfe({ type="group", value=move, label="Move Job" }) end -function move_job(self, move) +function mymodule.move_job(self, move) local success = modelfunctions.validateselect(move.value.name) success = modelfunctions.validateselect(move.value.period) and success @@ -129,7 +129,7 @@ function move_job(self, move) return move end -function create_new_job() +function mymodule.create_new_job() local newjob = {} newjob.name = cfe({ label="Name" }) newjob.period = cfe({ type="select", label="Period", option=list_periods() }) @@ -137,7 +137,7 @@ function create_new_job() return cfe({ type="group", value=newjob, label="Create New Job" }) end -function create_job(self, newjob) +function mymodule.create_job(self, newjob) local success = modelfunctions.validateselect(newjob.value.period) if newjob.value.name.value == "" then @@ -161,12 +161,14 @@ function create_job(self, newjob) return newjob end -function read_configfile() +function mymodule.read_configfile() -- FIXME validate return modelfunctions.getfiledetails(configfile) end -function update_configfile(self, filedetails) +function mymodule.update_configfile(self, filedetails) -- FIXME validate return modelfunctions.setfiledetails(self, filedetails, {configfile}) end + +return mymodule diff --git a/health-controller.lua b/health-controller.lua index f5cc26c..68f895e 100644 --- a/health-controller.lua +++ b/health-controller.lua @@ -1,26 +1,26 @@ -module (..., package.seeall) +local mymodule = {} -default_action = "system" +mymodule.default_action = "system" -- Public methods -system = function (self ) +mymodule.system = function (self ) return self.model:get_system() end -storage = function (self ) +mymodule.storage = function (self ) return self.model:get_storage() end -network = function (self ) +mymodule.network = function (self ) return self.model:get_network() end -proc = function (self ) +mymodule.proc = function (self ) return self.model:get_proc() end -networkstats = function(self) +mymodule.networkstats = function(self) local retval = self.model.get_networkstats() if self.conf.viewtype == "html" then local intf = self:new("alpine-baselayout/interfaces") @@ -34,3 +34,5 @@ networkstats = function(self) end return retval end + +return mymodule diff --git a/health-model.lua b/health-model.lua index 50c61f2..424a0e4 100644 --- a/health-model.lua +++ b/health-model.lua @@ -1,5 +1,5 @@ -- acf model for displaying logfiles recusivly -module (..., package.seeall) +local mymodule = {} fs = require("acf.fs") date = require("acf.date") @@ -52,7 +52,7 @@ end -- ############################################################### -- Public functions -get_system = function (self) +mymodule.get_system = function (self) local system = {} local meminfo = memusage() system.uptime = cfe({ value=querycmd("uptime"), label="Uptime" }) @@ -68,7 +68,7 @@ get_system = function (self) return cfe({ type="group", value=system }) end -get_storage = function (self) +mymodule.get_storage = function (self) local storage = {} local disk = diskfree() .. "\n" local other = {} @@ -108,7 +108,7 @@ get_storage = function (self) return cfe({ type="group", value=storage }) end -get_network = function (self) +mymodule.get_network = function (self) local network = {} network.interfaces = cfe({ value=querycmd("ip addr"), label="Interfaces" }) network.routes = cfe({ value=querycmd("ip route"), label="Routes" }) @@ -116,14 +116,14 @@ get_network = function (self) return cfe({ type="group", value=network }) end -get_proc = function (self) +mymodule.get_proc = function (self) local proc = {} proc.processor = cfe({ value=fs.read_file("/proc/cpuinfo") or "", label="Processor" }) proc.memory = cfe({ value=fs.read_file("/proc/meminfo") or "", label="Memory" }) return cfe({ type="group", value=proc }) end -get_networkstats = function () +mymodule.get_networkstats = function () local stats = cfe({ type="structure", value={}, label="Network Stats", timestamp=os.time() }) local result = fs.read_file("/proc/net/dev") or "" -- parse the result @@ -144,3 +144,5 @@ get_networkstats = function () end return stats end + +return mymodule diff --git a/hostname-controller.lua b/hostname-controller.lua index c68c5c3..255f23c 100644 --- a/hostname-controller.lua +++ b/hostname-controller.lua @@ -1,12 +1,14 @@ -- the hostname controller -module (..., package.seeall) +local mymodule = {} -default_action = "read" +mymodule.default_action = "read" -read = function(self) +mymodule.read = function(self) return self.model.get(true) end -edit = function(self) +mymodule.edit = function(self) return self.handle_form(self, self.model.read_name, self.model.update_name, self.clientdata, "Save", "Edit Hostname", "Hostname Set") end + +return mymodule diff --git a/hostname-model.lua b/hostname-model.lua index 3094393..8e20707 100644 --- a/hostname-model.lua +++ b/hostname-model.lua @@ -1,10 +1,10 @@ -- hostname model methods -module (..., package.seeall) +local mymodule = {} fs = require("acf.fs") modelfunctions = require("modelfunctions") -get = function (fqdn) +mymodule.get = function (fqdn) local n if fqdn then n = modelfunctions.run_executable({"hostname", "-f"}) @@ -20,11 +20,11 @@ get = function (fqdn) end -read_name = function () - return cfe({ type="group", value={hostname=get(false)}, label="Hostname" }) +mymodule.read_name = function () + return cfe({ type="group", value={hostname=mymodule.get(false)}, label="Hostname" }) end -update_name = function(self, name) +mymodule.update_name = function(self, name) local success = true if success then @@ -36,3 +36,5 @@ update_name = function(self, name) return name end + +return mymodule diff --git a/interfaces-controller.lua b/interfaces-controller.lua index 6e72160..592c0b8 100644 --- a/interfaces-controller.lua +++ b/interfaces-controller.lua @@ -1,41 +1,43 @@ -- the interfaces controller -module (..., package.seeall) +local mymodule = {} -default_action = "read" +mymodule.default_action = "read" -status = function (self) +mymodule.status = function (self) return self.model.get_status() end -read = function (self) +mymodule.read = function (self) return self.model.get_all_interfaces() end -update = function(self) +mymodule.update = function(self) return self.handle_form(self, self.model.get_iface_by_name, self.model.update_iface, self.clientdata, "Save", "Update Interface", "Interface updated") end -delete = function(self) +mymodule.delete = function(self) return self.handle_form(self, self.model.get_delete_iface_by_name, self.model.delete_iface_by_name, self.clientdata, "Delete", "Delete Interface") end -ifup = function(self) +mymodule.ifup = function(self) return self.handle_form(self, self.model.get_ifup_by_name, self.model.ifup_by_name, self.clientdata, "ifup", "Interface Up") end -ifdown = function(self) +mymodule.ifdown = function(self) return self.handle_form(self, self.model.get_ifdown_by_name, self.model.ifdown_by_name, self.clientdata, "ifdown", "Interface Down") end -- FIXME: 'Method' select box appeared via JS ... figure out how best to implement that when using the standard view -create = function(self) +mymodule.create = function(self) return self.handle_form(self, self.model.get_iface, self.model.create_iface, self.clientdata, "Create", "Create Interface", "Interface created") end -editintfile = function(self) +mymodule.editintfile = function(self) return self.handle_form(self, self.model.get_file, self.model.write_file, self.clientdata, "Save", "Edit Interfaces file", "File saved") end -restart = function(self) +mymodule.restart = function(self) return self.handle_form(self, self.model.get_restartnetworking, self.model.restartnetworking, self.clientdata, "Restart", "Restart Networking") end + +return mymodule diff --git a/interfaces-definitions.lua b/interfaces-definitions.lua index eaa979f..089e64b 100644 --- a/interfaces-definitions.lua +++ b/interfaces-definitions.lua @@ -1,6 +1,6 @@ -module (..., package.seeall) +local mymodule = {} -- Definitions of interface cfe's / options - required = { + mymodule.required = { comment = {type="longtext", label="Comments", seq=2}, auto = {type="boolean", value=false, label="Auto bring-up", seq=3}, name = {label="Interface Name", seq=1}, @@ -12,12 +12,12 @@ module (..., package.seeall) ['post-down'] = {type="longtext", label="'post-down' actions", seq=103}, other = {type="longtext", label="Other options (unsupported)", seq=104}, } - family_methods = { + mymodule.family_methods = { inet = {"loopback", "static", "manual", "dhcp", "bootp", "ppp", "wvdial"}, ipx = {"static", "dynamic"}, inet6 = {"loopback", "static", "manual", "v4tunnel"}, } - method_options = { + mymodule.method_options = { inet = { static = {"address", "netmask", "broadcast", "network", "metric", "gateway", "pointopoint", "media", "hwaddress", "mtu"}, dhcp = {"hostname", "leasehours", "leasetime", "vendor", "client", "hwaddress"}, @@ -34,7 +34,7 @@ module (..., package.seeall) v4tunnel = {"address", "netmask", "endpoint", "local", "gateway", "ttl"}, }, } - optional = { + mymodule.optional = { address = {label="Address", seq=6}, netmask = {label="Netmask", seq=7}, endpoint = {label="Endpoint address", seq=8}, @@ -60,3 +60,5 @@ module (..., package.seeall) netnum = {label="Network number", seq=28}, ttl = {label="TTL setting", seq=29}, } + +return mymodule diff --git a/interfaces-model.lua b/interfaces-model.lua index 2f108b9..9fee686 100644 --- a/interfaces-model.lua +++ b/interfaces-model.lua @@ -1,6 +1,6 @@ -- acf model for /etc/network/interfaces -- Copyright(c) 2007 N. Angelacos - Licensed under terms of GPL2 -module (..., package.seeall) +local mymodule = {} modelfunctions = require("modelfunctions") fs = require("acf.fs") @@ -232,12 +232,12 @@ end -- Public Methods ------------------------------------------------------------------------------- -get_all_interfaces = function(self, clientdata) +mymodule.get_all_interfaces = function(self, clientdata) unpack_interfaces() return cfe({ type="group", value=array, label="Interfaces" }) end -get_iface_by_name = function(self, clientdata) +mymodule.get_iface_by_name = function(self, clientdata) -- if the name is blank, then return a blank iface with error local ret unpack_interfaces() @@ -253,11 +253,11 @@ get_iface_by_name = function(self, clientdata) return ret end -get_iface = function(self, clientdata) +mymodule.get_iface = function(self, clientdata) return get_blank_iface() end -create_iface = function(self, def) +mymodule.create_iface = function(self, def) unpack_interfaces() local success = validate_interface( def ) @@ -272,7 +272,7 @@ create_iface = function(self, def) return def end -update_iface = function(self, def) +mymodule.update_iface = function(self, def) unpack_interfaces() -- if the def by that name doesn't exist, fail local success @@ -294,14 +294,14 @@ update_iface = function(self, def) return def end -get_delete_iface_by_name = function(self, clientdata) +mymodule.get_delete_iface_by_name = function(self, clientdata) local result = {} result.name = cfe({ type="select", value=clientdata.name or "", label="Interface Name", option=list_interfaces() }) return cfe({ type="group", value=result, label="Interface Name" }) end -delete_iface_by_name = function(self, deleterequest) +mymodule.delete_iface_by_name = function(self, deleterequest) local success = modelfunctions.validateselect(deleterequest.value.name) if success then @@ -321,7 +321,7 @@ delete_iface_by_name = function(self, deleterequest) return deleterequest end -get_status = function () +mymodule.get_status = function () local status = {} status.filename = cfe({ value=filename, label="Interfaces file" }) status.iproute = cfe({ type="longtext", label="ip route" }) @@ -339,16 +339,16 @@ get_status = function () return cfe({ type="group", value=status, label="Status" }) end -get_file = function () +mymodule.get_file = function () return modelfunctions.getfiledetails(filename) end -write_file = function (self, newfile) +mymodule.write_file = function (self, newfile) array = nil return modelfunctions.setfiledetails(self, newfile, {filename}) end -get_interfaces = function() +mymodule.get_interfaces = function() local ipaddr = modelfunctions.run_executable({"ip", "addr"}) -- now parse the result to find the interfaces local retval = {} @@ -361,7 +361,7 @@ get_interfaces = function() return cfe({ type="list", value=retval, label="IP Interfaces" }) end -get_addresses = function() +mymodule.get_addresses = function() local ipaddr = modelfunctions.run_executable({"ip", "addr"}) -- now parse the result to find the interfaces and IP addresses local retval = {} @@ -376,14 +376,14 @@ get_addresses = function() return cfe({ type="structure", value=retval, label="Interface IP Addresses" }) end -get_ifup_by_name = function(self, clientdata) +mymodule.get_ifup_by_name = function(self, clientdata) local result = {} result.name = cfe({ type="select", value=clientdata.name or "", label="Interface Name", option=list_interfaces() }) return cfe({ type="group", value=result, label="Interface Name" }) end -ifup_by_name = function (self, ifuprequest) +mymodule.ifup_by_name = function (self, ifuprequest) local success = modelfunctions.validateselect(ifuprequest.value.name) if success then name = ifuprequest.value.name.value or "" @@ -399,14 +399,14 @@ ifup_by_name = function (self, ifuprequest) return ifuprequest end -get_ifdown_by_name = function(self, clientdata) +mymodule.get_ifdown_by_name = function(self, clientdata) local result = {} result.name = cfe({ type="select", value=clientdata.name or "", label="Interface Name", option=list_interfaces() }) return cfe({ type="group", value=result, label="Interface Name" }) end -ifdown_by_name = function (self, ifdownrequest) +mymodule.ifdown_by_name = function (self, ifdownrequest) local success = modelfunctions.validateselect(ifdownrequest.value.name) if success then name = ifdownrequest.value.name.value or "" @@ -422,7 +422,7 @@ ifdown_by_name = function (self, ifdownrequest) return ifdownrequest end -get_restartnetworking = function(self, clientdata) +mymodule.get_restartnetworking = function(self, clientdata) local actions = {} actions[1] = "restart" local service = cfe({ type="hidden", value=servicename, label="Service Name" }) @@ -431,6 +431,8 @@ get_restartnetworking = function(self, clientdata) return startstop end -restartnetworking = function(self, startstop) +mymodule.restartnetworking = function(self, startstop) return modelfunctions.startstop_service(startstop, "restart") end + +return mymodule diff --git a/logfiles-controller.lua b/logfiles-controller.lua index 3c594f2..10d0a55 100644 --- a/logfiles-controller.lua +++ b/logfiles-controller.lua @@ -1,29 +1,31 @@ -module (..., package.seeall) +local mymodule = {} posix = require("posix") -default_action = "status" +mymodule.default_action = "status" -- Public methods -status = function (self ) +mymodule.status = function (self ) return self.model.get() end -delete = function (self) +mymodule.delete = function (self) return self.handle_form(self, self.model.get_delete, self.model.delete, self.clientdata, "Delete", "Delete File", "File Deleted") end -view = function (self) +mymodule.view = function (self) return self.model.get_filedetails(self.clientdata.filename or "", self.clientdata.grep) end -download = function (self) - local filestatus = view(self) +mymodule.download = function (self) + local filestatus = mymodule.view(self) local filecontent = filestatus.value.filecontent filecontent.label = posix.basename(filestatus.value.filename.value) return filecontent end -tail = function (self) +mymodule.tail = function (self) return self.model.tail(self.clientdata.filename, self.clientdata.offset, self.clientdata.grep) end + +return mymodule diff --git a/logfiles-model.lua b/logfiles-model.lua index a43de6c..95bcb19 100644 --- a/logfiles-model.lua +++ b/logfiles-model.lua @@ -1,5 +1,5 @@ -- acf model for displaying logfiles -module (..., package.seeall) +local mymodule = {} posix = require("posix") modelfunctions = require("modelfunctions") @@ -80,9 +80,9 @@ local do_grep = function(filecontent, grep) end end -get_filedetails = function (path, grep) +mymodule.get_filedetails = function (path, grep) local success = false - local available_files = get() + local available_files = mymodule.get() for i,file in ipairs(available_files.value) do if file.value.filename.value == path then success = true @@ -106,14 +106,14 @@ get_filedetails = function (path, grep) return filedetails end -tail = function(path, offset, grep) +mymodule.tail = function(path, offset, grep) local filename = cfe({ value=path, label="File name", errtxt="File not found" }) local filesize = cfe({ value="0", label="File size" }) local filecontent = cfe({ type="longtext", label="File content" }) local fileoffset = cfe({ value="0", label="File offset" }) local filegrep = cfe({ value=grep or "", label="Grep" }) - local available_files = get() + local available_files = mymodule.get() for i,file in ipairs(available_files.value) do if ( file.value.filename.value == path ) then filename.errtxt = nil @@ -141,15 +141,15 @@ tail = function(path, offset, grep) return cfe({ type="group", value={filename=filename, filecontent=filecontent, filesize=filesize, fileoffset=fileoffset, grep=filegrep}, label="Tail Config file details" }) end -get = function () +mymodule.get = function () -- These folders (and their subfolers) are going to be listed return list_files( "/var/log", "/tmp/squid/log" ) end -get_delete = function() +mymodule.get_delete = function() local filename = cfe({ type="select", label="File name", option={} }) -- Get a list of files that could be deleted - local available_files = get() + local available_files = mymodule.get() for i,file in ipairs(available_files.value) do filename.option[#filename.option+1] = file.value.filename.value end @@ -158,7 +158,7 @@ get_delete = function() end -- Function to check if a file is deletable, and if it is, then delete it. -delete = function (self, filetodelete) +mymodule.delete = function (self, filetodelete) local success = modelfunctions.validateselect(filetodelete.value.filename) if success then @@ -182,9 +182,9 @@ delete = function (self, filetodelete) if not success then filetodelete.errtxt = "Failed to delete file" -self.logevent(filetodelete.value.filename.errtxt) end return filetodelete end +return mymodule diff --git a/modules-controller.lua b/modules-controller.lua index 11774f0..304f303 100644 --- a/modules-controller.lua +++ b/modules-controller.lua @@ -1,16 +1,18 @@ -- the modules controller -module (..., package.seeall) +local mymodule = {} -default_action = "status" +mymodule.default_action = "status" -status = function(self) +mymodule.status = function(self) return self.model.read_modules() end -edit = function(self) +mymodule.edit = function(self) return self.handle_form(self, self.model.read_file, self.model.write_file, self.clientdata, "Save", "Edit Modules file", "File saved") end -reload = function(self) +mymodule.reload = function(self) return self.handle_form(self, self.model.get_reloadmodules, self.model.reloadmodules, self.clientdata, "Reload", "Reload Modules") end + +return mymodule diff --git a/modules-model.lua b/modules-model.lua index 74f8384..0a55140 100644 --- a/modules-model.lua +++ b/modules-model.lua @@ -1,24 +1,24 @@ -module (..., package.seeall) +local mymodule = {} modelfunctions = require("modelfunctions") fs = require("acf.fs") local configfile = "/etc/modules" -function read_modules() +function mymodule.read_modules() local retval = modelfunctions.run_executable({"lsmod"}) return cfe({ type="longtext", value=retval, label="Modules List" }) end -function read_file() +function mymodule.read_file() return modelfunctions.getfiledetails(configfile) end -function write_file(self, filedetails) +function mymodule.write_file(self, filedetails) return modelfunctions.setfiledetails(self, filedetails, {configfile}) end -function get_reloadmodules(self, clientdata) +function mymodule.get_reloadmodules(self, clientdata) local actions = {} actions[1] = "restart" local service = cfe({ type="hidden", value="modules", label="Service Name" }) @@ -27,6 +27,8 @@ function get_reloadmodules(self, clientdata) return startstop end -function reloadmodules(self, startstop) +function mymodule.reloadmodules(self, startstop) return modelfunctions.startstop_service(startstop, "restart") end + +return mymodule diff --git a/password-controller.lua b/password-controller.lua index 9982ada..f5d668c 100644 --- a/password-controller.lua +++ b/password-controller.lua @@ -1,8 +1,10 @@ -- the password controller -module (..., package.seeall) +local mymodule = {} -default_action = "edit" +mymodule.default_action = "edit" -edit = function (self) +mymodule.edit = function (self) return self.handle_form(self, self.model.read_password, self.model.update_password, self.clientdata, "Save", "Set System Password", "Password Set") end + +return mymodule diff --git a/password-model.lua b/password-model.lua index 5c5f801..a91f3db 100644 --- a/password-model.lua +++ b/password-model.lua @@ -1,11 +1,11 @@ -- password model methods -module (..., package.seeall) +local mymodule = {} fs = require("acf.fs") format = require("acf.format") posix = require("posix") -read_password = function() +mymodule.read_password = function() pw = {} pw.user = cfe({ label="User Name", seq=1 }) pw.password = cfe({ type="password", label="Password", seq=2 }) @@ -14,7 +14,7 @@ read_password = function() end --setup so that it will compare password input -update_password = function (self, pw) +mymodule.update_password = function (self, pw) local success = true if pw.value.password.value == "" or pw.value.password.value ~= pw.value.password_confirm.value then pw.value.password.errtxt = "Invalid or non matching password" @@ -44,3 +44,5 @@ update_password = function (self, pw) return pw end + +return mymodule diff --git a/rc-controller.lua b/rc-controller.lua index 63d9a94..4ec40b9 100644 --- a/rc-controller.lua +++ b/rc-controller.lua @@ -1,17 +1,19 @@ -- the rc controller -module (..., package.seeall) +local mymodule = {} -default_action = "status" +mymodule.default_action = "status" -status = function(self) +mymodule.status = function(self) return self.model.status() end -edit = function(self) +mymodule.edit = function(self) return self.handle_form(self, self.model.read_runlevels, self.model.update_runlevels, self.clientdata, "Save", "Edit Service Runlevels", "Runlevels Updated") end -startstop = function(self) +mymodule.startstop = function(self) return self.handle_form(self, self.model.get_startstop, self.model.startstop_service, self.clientdata) end + +return mymodule diff --git a/rc-model.lua b/rc-model.lua index d799cca..3df75a2 100644 --- a/rc-model.lua +++ b/rc-model.lua @@ -1,4 +1,4 @@ -module (..., package.seeall) +local mymodule = {} posix = require("posix") modelfunctions = require("modelfunctions") @@ -16,7 +16,7 @@ table.sort(runlevels) local config -status = function() +mymodule.status = function() if not config then config = processinfo.read_initrunlevels() for i,c in pairs(config) do @@ -30,7 +30,7 @@ status = function() return cfe({ type="structure", value=config, label="Init Runlevels" }) end -read_runlevels = function(self, clientdata) +mymodule.read_runlevels = function(self, clientdata) local servicename = clientdata.servicename local value = {} value.servicename = cfe({ value=servicename or "", label="Service Name", seq=1 }) @@ -49,7 +49,7 @@ read_runlevels = function(self, clientdata) return cfe({ type="group", value=value, label="Service Runlevels"}) end -update_runlevels = function(self, service) +mymodule.update_runlevels = function(self, service) local success = modelfunctions.validatemulti(service.value.runlevels) service.value.servicename.errtxt = "Invalid service" for name in posix.files("/etc/init.d") do @@ -85,11 +85,12 @@ update_runlevels = function(self, service) return service end -function get_startstop(self, clientdata) +function mymodule.get_startstop(self, clientdata) return modelfunctions.get_startstop(clientdata.servicename) end -function startstop_service(self, startstop) +function mymodule.startstop_service(self, startstop) return modelfunctions.startstop_service(startstop, clientdata.action) end +return mymodule diff --git a/syslog-controller.lua b/syslog-controller.lua index 3367a55..ec9cb83 100644 --- a/syslog-controller.lua +++ b/syslog-controller.lua @@ -1,23 +1,25 @@ -module(..., package.seeall) +local mymodule = {} -default_action = "loginfo" +mymodule.default_action = "loginfo" -function loginfo(self) +function mymodule.loginfo(self) return self.model.getlogging() end -function config(self) +function mymodule.config(self) return self.handle_form(self, self.model.getconfig, self.model.updateconfig, self.clientdata, "Save", "Edit config", "Configuration Set") end -function expert(self) +function mymodule.expert(self) return self.handle_form(self, self.model.get_filedetails, self.model.update_filedetails, self.clientdata, "Save", "Edit config", "Configuration Set") end -function startstop(self) +function mymodule.startstop(self) return self.handle_form(self, self.model.get_startstop, self.model.startstop_service, self.clientdata) end -function status(self) +function mymodule.status(self) return self.model.getstatus() end + +return mymodule diff --git a/syslog-model.lua b/syslog-model.lua index 08dacfc..8e3c665 100644 --- a/syslog-model.lua +++ b/syslog-model.lua @@ -1,4 +1,4 @@ -module(..., package.seeall) +local mymodule = {} modelfunctions = require("modelfunctions") fs = require("acf.fs") @@ -145,21 +145,21 @@ end -- ################################################################################ -- PUBLIC FUNCTIONS -function get_startstop(self, clientdata) +function mymodule.get_startstop(self, clientdata) return modelfunctions.get_startstop(processname) end -function startstop_service(self, startstop, action) +function mymodule.startstop_service(self, startstop, action) return modelfunctions.startstop_service(startstop, action) end -function getstatus() +function mymodule.getstatus() return modelfunctions.getstatus(processname, packagename, "Syslog Status") end -function getlogging() +function mymodule.getlogging() local status = {} - local opts = getconfig() + local opts = mymodule.getconfig() if (opts.value.remotelogging.value == "") or (opts.value.localandnetworklog.value) then status.logfile = cfe({ label="Locally logging to", @@ -176,11 +176,11 @@ function getlogging() return cfe({ type="group", value=status }) end -function get_filedetails() +function mymodule.get_filedetails() return modelfunctions.getfiledetails(configfile) end -function getconfig() +function mymodule.getconfig() local config = {} if (fs.is_file(configfile)) then local configcontent = format.opts_to_table(string.sub((format.parse_ini_file(fs.read_file(configfile) or "", "", "SYSLOGD_OPTS") or ""),2,-2)) @@ -193,7 +193,7 @@ function getconfig() return config end -function updateconfig (self, config) +function mymodule.updateconfig (self, config) local success = true success, config = validateconfig(config) @@ -206,6 +206,8 @@ function updateconfig (self, config) return config end -function update_filedetails (self, filedetails) +function mymodule.update_filedetails (self, filedetails) return modelfunctions.setfiledetails(self, filedetails, {configfile}, validate_configfile) end + +return mymodule |