1
0

pbx-voip.lua 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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-voip"
  23. m = Map (modulename, translate("SIP Accounts"),
  24. translate("This is where you set up your SIP (VoIP) accounts ts like Sipgate, SipSorcery, \
  25. the popular Betamax providers, and any other providers with SIP settings in order to start \
  26. using them for dialing and receiving calls (SIP uri and real phone calls). Click \"Add\" to \
  27. add as many accounts as you wish."))
  28. -- Recreate the config, and restart services after changes are commited to the configuration.
  29. function m.on_after_commit(self)
  30. commit = false
  31. -- Create a field "name" for each account that identifies the account in the backend.
  32. m.uci:foreach(modulename, "voip_provider",
  33. function(s1)
  34. if s1.defaultuser ~= nil and s1.host ~= nil then
  35. name=string.gsub(s1.defaultuser.."_"..s1.host, "%W", "_")
  36. if s1.name ~= name then
  37. m.uci:set(modulename, s1['.name'], "name", name)
  38. commit = true
  39. end
  40. end
  41. end)
  42. if commit == true then m.uci:commit(modulename) end
  43. luci.sys.call("/etc/init.d/pbx-" .. server .. " restart 1\>/dev/null 2\>/dev/null")
  44. luci.sys.call("/etc/init.d/" .. server .. " restart 1\>/dev/null 2\>/dev/null")
  45. end
  46. -----------------------------------------------------------------------------
  47. s = m:section(TypedSection, "voip_provider", translate("SIP Provider Accounts"))
  48. s.anonymous = true
  49. s.addremove = true
  50. s:option(Value, "defaultuser", translate("User Name"))
  51. pwd = s:option(Value, "secret", translate("Password"),
  52. translate("When your password is saved, it disappears from this field and is not displayed \
  53. for your protection. The previously saved password will be changed only when you \
  54. enter a value different from the saved one."))
  55. pwd.password = true
  56. pwd.rmempty = false
  57. -- We skip reading off the saved value and return nothing.
  58. function pwd.cfgvalue(self, section)
  59. return ""
  60. end
  61. -- We check the entered value against the saved one, and only write if the entered value is
  62. -- something other than the empty string, and it differes from the saved value.
  63. function pwd.write(self, section, value)
  64. local orig_pwd = m:get(section, self.option)
  65. if value and #value > 0 and orig_pwd ~= value then
  66. Value.write(self, section, value)
  67. end
  68. end
  69. h = s:option(Value, "host", translate("SIP Server/Registrar"))
  70. h.datatype = "host(0)"
  71. p = s:option(ListValue, "register", translate("Enable Incoming Calls (Register via SIP)"),
  72. translate("This option should be set to \"Yes\" if you have a DID \(real telephone number\) \
  73. associated with this SIP account or want to receive SIP uri calls through this \
  74. provider."))
  75. p:value("yes", translate("Yes"))
  76. p:value("no", translate("No"))
  77. p.default = "yes"
  78. p = s:option(ListValue, "make_outgoing_calls", translate("Enable Outgoing Calls"),
  79. translate("Use this account to make outgoing calls."))
  80. p:value("yes", translate("Yes"))
  81. p:value("no", translate("No"))
  82. p.default = "yes"
  83. from = s:option(Value, "fromdomain",
  84. translate("SIP Realm (needed by some providers)"))
  85. from.optional = true
  86. from.datatype = "host(0)"
  87. port = s:option(Value, "port", translate("SIP Server/Registrar Port"))
  88. port.optional = true
  89. port.datatype = "port"
  90. op = s:option(Value, "outboundproxy", translate("Outbound Proxy"))
  91. op.optional = true
  92. op.datatype = "host(0)"
  93. return m