pbx-users.lua 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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-users"
  23. modulenamecalls = "pbx-calls"
  24. modulenameadvanced = "pbx-advanced"
  25. m = Map (modulename, translate("User Accounts"),
  26. translate("Here you must configure at least one SIP account, that you \
  27. will use to register with this service. Use this account either in an Analog Telephony \
  28. Adapter (ATA), or in a SIP software like CSipSimple, Linphone, or Sipdroid on your \
  29. smartphone, or Ekiga, Linphone, or X-Lite on your computer. By default, all SIP accounts \
  30. will ring simultaneously if a call is made to one of your VoIP provider accounts or GV \
  31. numbers."))
  32. -- Recreate the config, and restart services after changes are commited to the configuration.
  33. function m.on_after_commit(self)
  34. luci.sys.call("/etc/init.d/pbx-" .. server .. " restart 1\>/dev/null 2\>/dev/null")
  35. luci.sys.call("/etc/init.d/" .. server .. " restart 1\>/dev/null 2\>/dev/null")
  36. end
  37. externhost = m.uci:get(modulenameadvanced, "advanced", "externhost")
  38. bindport = m.uci:get(modulenameadvanced, "advanced", "bindport")
  39. ipaddr = m.uci:get("network", "lan", "ipaddr")
  40. -----------------------------------------------------------------------------
  41. s = m:section(NamedSection, "server", "user", translate("Server Setting"))
  42. s.anonymous = true
  43. if ipaddr == nil or ipaddr == "" then
  44. ipaddr = "(IP address not static)"
  45. end
  46. if bindport ~= nil then
  47. just_ipaddr = ipaddr
  48. ipaddr = ipaddr .. ":" .. bindport
  49. end
  50. s:option(DummyValue, "ipaddr", translate("Server Setting for Local SIP Devices"),
  51. translate("Enter this IP (or IP:port) in the Server/Registrar setting of SIP devices you will \
  52. use ONLY locally and never from a remote location.")).default = ipaddr
  53. if externhost ~= nil then
  54. if bindport ~= nil then
  55. just_externhost = externhost
  56. externhost = externhost .. ":" .. bindport
  57. end
  58. s:option(DummyValue, "externhost", translate("Server Setting for Remote SIP Devices"),
  59. translate("Enter this hostname (or hostname:port) in the Server/Registrar setting of SIP \
  60. devices you will use from a remote location (they will work locally too).")
  61. ).default = externhost
  62. end
  63. if bindport ~= nil then
  64. s:option(DummyValue, "bindport", translate("Port Setting for SIP Devices"),
  65. translatef("If setting Server/Registrar to %s or %s does not work for you, try setting \
  66. it to %s or %s and entering this port number in a separate field that specifies the \
  67. Server/Registrar port number. Beware that some devices have a confusing \
  68. setting that sets the port where SIP requests originate from on the SIP \
  69. device itself (the bind port). The port specified on this page is NOT this bind port \
  70. but the port this service listens on.",
  71. ipaddr, externhost, just_ipaddr, just_externhost)).default = bindport
  72. end
  73. -----------------------------------------------------------------------------
  74. s = m:section(TypedSection, "local_user", translate("SIP Device/Softphone Accounts"))
  75. s.anonymous = true
  76. s.addremove = true
  77. s:option(Value, "fullname", translate("Full Name"),
  78. translate("You can specify a real name to show up in the Caller ID here."))
  79. du = s:option(Value, "defaultuser", translate("User Name"),
  80. translate("Use (four to five digit) numeric user name if you are connecting normal telephones \
  81. with ATAs to this system (so they can dial user names)."))
  82. du.datatype = "uciname"
  83. pwd = s:option(Value, "secret", translate("Password"),
  84. translate("Your password disappears when saved for your protection. It will be changed \
  85. only when you enter a value different from the saved one."))
  86. pwd.password = true
  87. pwd.rmempty = false
  88. -- We skip reading off the saved value and return nothing.
  89. function pwd.cfgvalue(self, section)
  90. return ""
  91. end
  92. -- We check the entered value against the saved one, and only write if the entered value is
  93. -- something other than the empty string, and it differes from the saved value.
  94. function pwd.write(self, section, value)
  95. local orig_pwd = m:get(section, self.option)
  96. if value and #value > 0 and orig_pwd ~= value then
  97. Value.write(self, section, value)
  98. end
  99. end
  100. p = s:option(ListValue, "ring", translate("Receives Incoming Calls"))
  101. p:value("yes", translate("Yes"))
  102. p:value("no", translate("No"))
  103. p.default = "yes"
  104. p = s:option(ListValue, "can_call", translate("Makes Outgoing Calls"))
  105. p:value("yes", translate("Yes"))
  106. p:value("no", translate("No"))
  107. p.default = "yes"
  108. return m