diff options
-rw-r--r-- | openssh-controller.lua | 24 | ||||
-rw-r--r-- | openssh-model.lua | 34 |
2 files changed, 31 insertions, 27 deletions
diff --git a/openssh-controller.lua b/openssh-controller.lua index 47c6766..134a628 100644 --- a/openssh-controller.lua +++ b/openssh-controller.lua @@ -1,39 +1,41 @@ -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 config(self) +function mymodule.config(self) return self.handle_form(self, self.model.read_config, self.model.update_config, self.clientdata, "Save", "Edit Config", "Configuration Saved") 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 expert(self) +function mymodule.expert(self) return self.handle_form(self, self.model.getconfigfile, self.model.setconfigfile, self.clientdata, "Save", "Edit Config", "Configuration Saved") end -function connectedpeers(self) +function mymodule.connectedpeers(self) return self.model.list_conn_peers() end -function listusers(self) +function mymodule.listusers(self) return self.model.list_users() end -function listauth(self) +function mymodule.listauth(self) return self.model.list_auths(self.clientdata.user) end -function deleteauth(self) +function mymodule.deleteauth(self) return self.handle_form(self, self.model.get_delete_auth, self.model.delete_auth, self.clientdata, "Delete", "Delete Authorized Key", "Key Deleted") end -function addauth(self) +function mymodule.addauth(self) return self.handle_form(self, function() return self.model.get_auth(self.clientdata.user) end, self.model.create_auth, self.clientdata, "Add", "Add New Authorized Key", "Key Added") end + +return mymodule diff --git a/openssh-model.lua b/openssh-model.lua index 4c81417..8eb946b 100644 --- a/openssh-model.lua +++ b/openssh-model.lua @@ -1,4 +1,4 @@ -module(..., package.seeall) +local mymodule = {} -- Load libraries modelfunctions = require("modelfunctions") @@ -46,27 +46,27 @@ 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, header .. " status") end -function getconfigfile() +function mymodule.getconfigfile() return modelfunctions.getfiledetails(configfile) end -function setconfigfile(self, filedetails) +function mymodule.setconfigfile(self, filedetails) return modelfunctions.setfiledetails(self, filedetails, {configfile}) end -function read_config() +function mymodule.read_config() local output = {} output.Port = cfe({ value=22, label="Port", seq=1 }) output.ListenAddress = cfe({ value="0.0.0.0", label="Listen address", seq=2 }) @@ -86,7 +86,7 @@ function read_config() return cfe({ type="group", value=output, label="OpenSSH Config" }) end -function update_config(self, config) +function mymodule.update_config(self, config) local success, config = validate_config(config) if success then @@ -123,12 +123,12 @@ function update_config(self, config) return config end -function list_conn_peers() +function mymodule.list_conn_peers() local output = {} local netstat = {} local ps = {} local who = {} - config = read_config() + config = mymodule.read_config() local f = modelfunctions.run_executable({"netstat", "-lnaW"}) local flines = format.search_for_lines(f, "ESTABLISHED") local g = modelfunctions.run_executable({"netstat", "-laW"}) @@ -179,7 +179,7 @@ function list_conn_peers() return output end -function list_users() +function mymodule.list_users() local users = {"root"} -- The only users we're going to worry about in this ACF are root and ones with home directories for user in posix.files("/home") do @@ -206,7 +206,7 @@ local function parseauthline(line) return retval end -function list_auths(user) +function mymodule.list_auths(user) user = user or "root" local cmdresult = cfe({ type="group", value={}, label="Authorized Key List" }) cmdresult.value.user = cfe({ value=user, label="User" }) @@ -225,14 +225,14 @@ function list_auths(user) return cmdresult end -function get_delete_auth(self, clientdata) +function mymodule.get_delete_auth(self, clientdata) local retval = {} retval.user = cfe({ value=clientdata.user or "root", label="User" }) retval.auth = cfe({ value=clientdata.auth or "", label="Authorized Key" }) return cfe({ type="group", value=retval, label="Delete Authorized Key" }) end -function delete_auth(self, delauth) +function mymodule.delete_auth(self, delauth) local user = delauth.value.user.value delauth.value.user.errtxt = "User not found" delauth.errtxt = "Failed to delete key" @@ -262,7 +262,7 @@ function delete_auth(self, delauth) return delauth end -function get_auth(user) +function mymodule.get_auth(user) local cmdresult = cfe({ type="group", value={}, label="Authorized Key List" }) cmdresult.value.user = cfe({ value=user or "root", label="User", seq=1 }) if user then @@ -272,7 +272,7 @@ function get_auth(user) return cmdresult end -function create_auth(self, authstr) +function mymodule.create_auth(self, authstr) authstr.value.user.value = authstr.value.user.value or "root" local success = true if not authstr.value.user.value == "root" and (string.find(authstr.value.user.value, "/") or not fs.is_dir("/home/"..authstr.value.user.value)) then @@ -334,3 +334,5 @@ function create_auth(self, authstr) end return authstr end + +return mymodule |