summaryrefslogtreecommitdiffstats
path: root/authenticator-freeswitch-vmail.lua
blob: 92aa29d4baaaf922b704c531e30fe20199973470 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
-- Copy of authenticator-plaintext, plus added authentication from voicemail DB
module (..., package.seeall)

require("md5")
a = require("authenticator-plaintext")

list_fields = function(self, tabl)
	result = a.list_fields(self, tabl)
	return result
end

read_field = function(self, tabl, field)
	result = a.read_field(self, tabl, field)
	if tabl == authenticator.usertable and field == "" then
		-- authenticator is reading all users
		local vmcontroller = self:new("freeswitch-vmail/vmail")
		local users = vmcontroller.model.list_passwords()
		for i,val in ipairs(users.value) do
			local string = md5.sumhexa(val.password)..":Voicemail User:/freeswitch-vmail/vmail/USER"
			result[#result+1] = { id=val.username, entry=string }
		end
		vmcontroller:destroy()
	end
	return result
end

delete_field = function(self, tabl, field)
	result = a.delete_field(self, tabl, field)
	return result
end

write_entry = function(self, tabl, field, id, entry)
	result = a.write_entry(self, tabl, field, id, entry)
	return result
end

read_entry = function(self, tabl, field, id)
	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
			result = md5.sumhexa(users.value[1].password)..":Voicemail User:/freeswitch-vmail/vmail/USER"
		end
		vmcontroller:destroy()
	end
	if not result then
		result = a.read_entry(self, tabl, field, id)
	end
	return result
end

delete_entry = function (self, tabl, field, id)
	result = a.delete_entry(self, tabl, field, id)
	return result
end