1) Made spacing with \ syntax consistent across the board.
[project/luci.git] / applications / luci-pbx / luasrc / model / cbi / pbx-google.lua
1 --[[
2     Copyright 2011 Iordan Iordanov <iiordanov (AT) gmail.com>
3
4     This file is part of luci-pbx.
5
6     luci-pbx is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10
11     luci-pbx is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with luci-pbx.  If not, see <http://www.gnu.org/licenses/>.
18 ]]--
19
20 if     nixio.fs.access("/etc/init.d/asterisk")   then
21    server = "asterisk"
22 elseif nixio.fs.access("/etc/init.d/freeswitch") then
23    server = "freeswitch"
24 else
25    server = ""
26 end
27
28 modulename           = "pbx-google"
29 googlemodulename     = "pbx-google"
30 defaultstatus        = "dnd"
31 defaultstatusmessage = "PBX online, may lose messages"
32
33 m = Map (modulename, translate("Google Accounts"),
34          translate("This is where you set up your Google (Talk and Voice) Accounts, in order to start \
35                 using them for dialing and receiving calls (voice chat and real phone calls). Click \"Add\" \
36                 to add as many accounts as you wish."))
37
38 -- Recreate the config, and restart services after changes are commited to the configuration.
39 function m.on_after_commit(self)
40    -- Create a field "name" for each account which identifies the account in the backend.
41    commit = false
42    m.uci:foreach(modulename, "gtalk_jabber", 
43                  function(s1)
44                     if s1.username ~= nil then
45                        name=string.gsub(s1.username, "%W", "_")
46                        if s1.name ~= name then
47                           m.uci:set(modulename, s1['.name'], "name", name)
48                           commit = true
49                        end
50                     end
51                  end)
52    if commit == true then  m.uci:commit(modulename) end
53    
54    luci.sys.call("/etc/init.d/pbx-" .. server .. " restart 1\>/dev/null 2\>/dev/null")
55    luci.sys.call("/etc/init.d/asterisk             restart 1\>/dev/null 2\>/dev/null")
56 end
57
58 -----------------------------------------------------------------------------
59 s = m:section(TypedSection, "gtalk_jabber", translate("Google Voice/Talk Accounts"))
60 s.anonymous = true
61 s.addremove = true
62
63 s:option(Value, "username",     translate("Email"))
64
65 pwd = s:option(Value, "secret", translate("Password"),
66                translate("When your password is saved, it disappears from this field and is not displayed \
67                          for your protection. The previously saved password will be changed only when you \
68                          enter a value different from the saved one."))
69 pwd.password = true
70 pwd.rmempty = false
71
72 -- We skip reading off the saved value and return nothing.
73 function pwd.cfgvalue(self, section)
74     return "" 
75 end
76
77 -- We check the entered value against the saved one, and only write if the entered value is
78 -- something other than the empty string, and it differes from the saved value.
79 function pwd.write(self, section, value)
80     local orig_pwd = m:get(section, self.option)
81     if value and #value > 0 and orig_pwd ~= value then
82         Value.write(self, section, value)
83     end
84 end
85
86
87 p = s:option(ListValue, "register",
88              translate("Enable Incoming Calls (See Status, Message below)"),
89              translate("When somebody starts voice chat with your GTalk account or calls the GVoice, \
90                        number (if you have Google Voice), the call will be forwarded to any users \
91                         that are online (registered using a SIP device or softphone) and permitted to \
92                         receive the call. If you have Google Voice, you must go to your GVoice settings and \
93                         forward calls to Google chat in order to actually receive calls made to your \
94                         GVoice number. If you have trouble receiving calls from GVoice, experiment \
95                         with the Call Screening option in your GVoice Settings. Finally, make sure no other \
96                         client is online with this account (browser in gmail, mobile/desktop Google Talk \
97                         App) as it may interfere."))
98 p:value("yes", translate("Yes"))
99 p:value("no",  translate("No"))
100 p.default = "yes"
101
102 p = s:option(ListValue, "make_outgoing_calls", translate("Enable Outgoing Calls"),
103       translate("Use this account to make outgoing calls as configured in the \"Call Routing\" section."))
104 p:value("yes", translate("Yes"))
105 p:value("no",  translate("No"))
106 p.default = "yes"
107
108 st = s:option(ListValue, "status", translate("Account Status"))
109 st:depends("register", "yes")
110 st:value("dnd", translate("Do Not Disturb"))
111 st:value("away",  translate("Away"))
112 st:value("available",  translate("Available"))
113 st.default = defaultstatus
114
115 stm = s:option(Value, "statusmessage", translate("Account Status Message"),
116              translate("Avoid using anything but alpha-numeric characters, space, comma, and period."))
117 stm:depends("register", "yes")
118 stm.default = defaultstatusmessage
119
120 return m