summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-pbx/luasrc/model/cbi/pbx-google.lua
blob: 128c7a3071582bb96ec7039fc11c65d5df0f1074 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
--[[
    Copyright 2011 Iordan Iordanov <iiordanov (AT) gmail.com>

    This file is part of luci-pbx.

    luci-pbx is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    luci-pbx is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with luci-pbx.  If not, see <http://www.gnu.org/licenses/>.
]]--

if     nixio.fs.access("/etc/init.d/asterisk")   then
   server = "asterisk"
elseif nixio.fs.access("/etc/init.d/freeswitch") then
   server = "freeswitch"
else
   server = ""
end

modulename           = "pbx-google"
googlemodulename     = "pbx-google"
defaultstatus        = "dnd"
defaultstatusmessage = "PBX online, may lose messages"

m = Map (modulename, translate("Google Accounts"),
	 translate("This is where you set up your Google (Talk and Voice) Accounts, in order to start\
		using them for dialing and receiving calls (voice chat and real phone calls). Click \"Add\"\
		to add as many accounts as you wish."))

-- Recreate the config, and restart services after changes are commited to the configuration.
function m.on_after_commit(self)
   -- Create a field "name" for each account which identifies the account in the backend.
   commit = false
   m.uci:foreach(modulename, "gtalk_jabber", 
		 function(s1)
		    if s1.username ~= nil then
		       name=string.gsub(s1.username, "%W", "_")
		       if s1.name ~= name then
			  m.uci:set(modulename, s1['.name'], "name", name)
			  commit = true
		       end
		    end
		 end)
   if commit == true then  m.uci:commit(modulename) end
   
   luci.sys.call("/etc/init.d/pbx-" .. server .. " restart 1\>/dev/null 2\>/dev/null")
   luci.sys.call("/etc/init.d/asterisk             restart 1\>/dev/null 2\>/dev/null")
end

-----------------------------------------------------------------------------
s = m:section(TypedSection, "gtalk_jabber", translate("Google Voice/Talk Accounts"))
s.anonymous = true
s.addremove = true

s:option(Value, "username",     translate("Email"))

pwd = s:option(Value, "secret", translate("Password"),
	       translate("When your password is saved, it disappears from this field and is not displayed\
			 for your protection. The previously saved password will be changed only when you\
			 enter a value different from the saved one."))
pwd.password = true
pwd.rmempty = false

-- We skip reading off the saved value and return nothing.
function pwd.cfgvalue(self, section)
    return "" 
end

-- We check the entered value against the saved one, and only write if the entered value is
-- something other than the empty string, and it differes from the saved value.
function pwd.write(self, section, value)
    local orig_pwd = m:get(section, self.option)
    if value and #value > 0 and orig_pwd ~= value then
        Value.write(self, section, value)
    end
end


p = s:option(ListValue, "register",
	     translate("Enable Incoming Calls (See Status, Message below)"),
	     translate("When somebody starts voice chat with your GTalk account or calls the GVoice,\
		       number (if you have Google Voice), the call will be forwarded to any users\
			that are online (registered using a SIP device or softphone) and permitted to\
			receive the call. If you have Google Voice, you must go to your GVoice settings and\
			forward calls to Google chat in order to actually receive calls made to your\
			GVoice number. If you have trouble receiving calls from GVoice, experiment\
			with the Call Screening option in your GVoice Settings. Finally, make sure no other\
			client is online with this account (browser in gmail, mobile/desktop Google Talk\
			App) as it may interfere."))
p:value("yes", translate("Yes"))
p:value("no",  translate("No"))
p.default = "yes"

p = s:option(ListValue, "make_outgoing_calls", translate("Enable Outgoing Calls"),
	     translate("Use this account to make outgoing calls as configured in the \"Call Routing\" section."))
p:value("yes", translate("Yes"))
p:value("no",  translate("No"))
p.default = "yes"

st = s:option(ListValue, "status", translate("Account Status"))
st:depends("register", "yes")
st:value("dnd", translate("Do Not Disturb"))
st:value("away",  translate("Away"))
st:value("available",  translate("Available"))
st.default = defaultstatus

stm = s:option(Value, "statusmessage", translate("Account Status Message"),
	     translate("Avoid using anything but alpha-numeric characters, space, comma, and period."))
stm:depends("register", "yes")
stm.default = defaultstatusmessage

return m