pbx-google.lua 5.4 KB

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