authenticator-freeswitch-vmail.lua 1.72 KB
Newer Older
1
-- Authentication from voicemail DB
2
local mymodule = {}
3

4
authenticator = require("authenticator")
5
md5 = require("md5")
6

7 8 9 10 11
-- We will not list entries from the voicemail database, as you must use the freeswitch-vmail controller
-- to list/view/edit entries. Similarly, we will not allow deletion. We will only allow reading single
-- entries, as is done during authentication. These entries will be specified for table=authenticator.usertable
-- and field="". Roles and home page are hardcoded below.

12
mymodule.list_fields = function(self, tabl)
13 14 15 16 17
	if tabl==authenticator.usertable then
		return {""}
	else
		return {}
	end
18 19
end

20
-- Do not list entries from vmail, must use vmail controller to view/edit
21
mymodule.read_field = function(self, tabl, field)
22
	return {}
23 24
end

25
-- We do not allow deletion
26
mymodule.delete_field = function(self, tabl, field)
27
	return false
28 29
end

30
-- We do not allow writing
31
mymodule.write_entry = function(self, tabl, field, id, entry)
32
	return false
33 34
end

35
mymodule.read_entry = function(self, tabl, field, id)
36 37 38 39 40 41
	local result
	if tabl == authenticator.usertable and field == "" then
		-- authenticator is reading one user
		local vmcontroller = self:new("freeswitch-vmail/vmail")
		local users = vmcontroller.model.list_passwords(id)
		if users and users.value and users.value[1] and users.value[1].password then
Ted Trask's avatar
Ted Trask committed
42
-- TODO can change this from md5 to password hash, not that it really matters much as the result isn't stored anywhere
43
			result = md5.sumhexa(users.value[1].password)..":Voicemail User:/freeswitch-vmail/vmail/USER::/freeswitch-vmail/vmail/listmymessages"
44 45 46
		end
		vmcontroller:destroy()
	end
47 48 49
	return result
end

50
-- We do not allow deletion
51
mymodule.delete_entry = function (self, tabl, field, id)
52
	return false
53
end
54 55

return mymodule