Commit 1c1a470e authored by Ted Trask's avatar Ted Trask

Remove all calls to 'module' in preparation for move to Lua 5.2

Use mymodule parameter for module definition.
This was also helpful in revealing places where the code relied on the global environment.
parent a65ebadc
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 editpap(self)
function mymodule.editpap(self)
return self.handle_form(self, self.model.read_papfiledetails, self.model.update_papfiledetails, self.clientdata, "Save", "Edit Config", "Configuration Set")
end
function editchap(self)
function mymodule.editchap(self)
return self.handle_form(self, self.model.read_chapfiledetails, self.model.update_chapfiledetails, self.clientdata, "Save", "Edit Config", "Configuration Set")
end
function listpeers(self)
function mymodule.listpeers(self)
return self.model.list_peers()
end
function createpeer(self)
function mymodule.createpeer(self)
return self.handle_form(self, self.model.get_newpeer, self.model.create_peer, self.clientdata, "Create", "Create New Peer File", "Peer File Created")
end
function deletepeer(self)
function mymodule.deletepeer(self)
return self.handle_form(self, self.model.get_delete_peer, self.model.delete_peer, self.clientdata, "Delete", "Delete Peer File", "Peer File Deleted")
end
function editpeer(self)
function mymodule.editpeer(self)
return self.handle_form(self, function() return self.model.read_peerfile(self.clientdata.name) end, self.model.update_peerfile, self.clientdata, "Save", "Edit PPP Peer", "Peer Configuration Set")
end
return mymodule
module(..., package.seeall)
local mymodule = {}
-- Load libraries
modelfunctions = require("modelfunctions")
......@@ -21,7 +21,7 @@ local path = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
-- ################################################################################
-- PUBLIC FUNCTIONS
function getstatus()
function mymodule.getstatus()
local status = {}
local value, errtxt = processinfo.package_version(packagename)
......@@ -43,37 +43,37 @@ function getstatus()
return cfe({ type="group", value=status, label="PPP Status" })
end
function read_papfiledetails()
function mymodule.read_papfiledetails()
return modelfunctions.getfiledetails(papfile)
end
function update_papfiledetails(self, filedetails)
function mymodule.update_papfiledetails(self, filedetails)
local retval = modelfunctions.setfiledetails(self, filedetails, {papfile})
posix.chmod(papfile, "rw-------")
return retval
end
function read_chapfiledetails()
function mymodule.read_chapfiledetails()
return modelfunctions.getfiledetails(chapfile)
end
function update_chapfiledetails(self, filedetails)
function mymodule.update_chapfiledetails(self, filedetails)
local retval = modelfunctions.setfiledetails(self, filedetails, {chapfile})
posix.chmod(chapfile, "rw-------")
return retval
end
function list_peers()
function mymodule.list_peers()
return cfe({ type="list", value=fs.find_files_as_array(nil, peerspath), label="Peers" })
end
function get_newpeer()
function mymodule.get_newpeer()
local newpeer = {}
newpeer.name = cfe({ label="Name" })
return cfe({ type="group", value=newpeer, label="New Peer" })
end
function create_peer(self, newpeer)
function mymodule.create_peer(self, newpeer)
newpeer.errtxt = "Failed to create peer"
local path = newpeer.value.name.value
if not string.find(path, "/") then
......@@ -94,13 +94,13 @@ function create_peer(self, newpeer)
return newpeer
end
function get_delete_peer(self, clientdata)
function mymodule.get_delete_peer(self, clientdata)
retval = {}
retval.name = cfe({ value=clientdata.name or "", label="Name" })
return cfe({ type="group", value=retval, label="Delete Peer File" })
end
function delete_peer(self, delpeer)
function mymodule.delete_peer(self, delpeer)
delpeer.errtxt = "Failed to delete peer"
delpeer.value.name.errtxt="Peer not found"
......@@ -116,10 +116,12 @@ function delete_peer(self, delpeer)
return delpeer
end
function read_peerfile(name)
function mymodule.read_peerfile(name)
return modelfunctions.getfiledetails(name, fs.find_files_as_array(nil, peerspath))
end
function update_peerfile(self, filedetails)
function mymodule.update_peerfile(self, filedetails)
return modelfunctions.setfiledetails(self, filedetails, fs.find_files_as_array(nil, peerspath))
end
return mymodule
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment