Merge pull request #1571 from user7887/luci-ru
[project/luci.git] / applications / luci-app-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). Please \
36                 make at least one voice call using the Google Talk plugin installable through the \
37                 GMail interface, and then log out from your account everywhere. Click \"Add\" \
38                 to add as many accounts as you wish."))
39
40 -- Recreate the config, and restart services after changes are commited to the configuration.
41 function m.on_after_commit(self)
42    -- Create a field "name" for each account that identifies the account in the backend.
43    commit = false
44    m.uci:foreach(modulename, "gtalk_jabber", 
45                  function(s1)
46                     if s1.username ~= nil then
47                        name=string.gsub(s1.username, "%W", "_")
48                        if s1.name ~= name then
49                           m.uci:set(modulename, s1['.name'], "name", name)
50                           commit = true
51                        end
52                     end
53                  end)
54    if commit == true then  m.uci:commit(modulename) end
55    
56    luci.sys.call("/etc/init.d/pbx-" .. server .. " restart 1\>/dev/null 2\>/dev/null")
57    luci.sys.call("/etc/init.d/asterisk             restart 1\>/dev/null 2\>/dev/null")
58 end
59
60 -----------------------------------------------------------------------------
61 s = m:section(TypedSection, "gtalk_jabber", translate("Google Voice/Talk Accounts"))
62 s.anonymous = true
63 s.addremove = true
64
65 s:option(Value, "username",     translate("Email"))
66
67 pwd = s:option(Value, "secret", translate("Password"),
68                translate("When your password is saved, it disappears from this field and is not displayed \
69                          for your protection. The previously saved password will be changed only when you \
70                          enter a value different from the saved one."))
71 pwd.password = true
72 pwd.rmempty = false
73
74 -- We skip reading off the saved value and return nothing.
75 function pwd.cfgvalue(self, section)
76     return "" 
77 end
78
79 -- We check the entered value against the saved one, and only write if the entered value is
80 -- something other than the empty string, and it differes from the saved value.
81 function pwd.write(self, section, value)
82     local orig_pwd = m:get(section, self.option)
83     if value and #value > 0 and orig_pwd ~= value then
84         Value.write(self, section, value)
85     end
86 end
87
88
89 p = s:option(ListValue, "register",
90              translate("Enable Incoming Calls (set Status below)"),
91              translate("When somebody starts voice chat with your GTalk account or calls the GVoice, \
92                        number (if you have Google Voice), the call will be forwarded to any users \
93                         that are online (registered using a SIP device or softphone) and permitted to \
94                         receive the call. If you have Google Voice, you must go to your GVoice settings and \
95                         forward calls to Google chat in order to actually receive calls made to your \
96                         GVoice number. If you have trouble receiving calls from GVoice, experiment \
97                         with the Call Screening option in your GVoice Settings. Finally, make sure no other \
98                         client is online with this account (browser in gmail, mobile/desktop Google Talk \
99                         App) as it may interfere."))
100 p:value("yes", translate("Yes"))
101 p:value("no",  translate("No"))
102 p.default = "yes"
103
104 p = s:option(ListValue, "make_outgoing_calls", translate("Enable Outgoing Calls"),
105       translate("Use this account to make outgoing calls as configured in the \"Call Routing\" section."))
106 p:value("yes", translate("Yes"))
107 p:value("no",  translate("No"))
108 p.default = "yes"
109
110 st = s:option(ListValue, "status", translate("Google Talk Status"))
111 st:depends("register", "yes")
112 st:value("dnd", translate("Do Not Disturb"))
113 st:value("away",  translate("Away"))
114 st:value("available",  translate("Available"))
115 st.default = defaultstatus
116
117 stm = s:option(Value, "statusmessage", translate("Google Talk Status Message"),
118              translate("Avoid using anything but alpha-numeric characters, space, comma, and period."))
119 stm:depends("register", "yes")
120 stm.default = defaultstatusmessage
121
122 return m