pbx.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. modulename = "pbx"
  16. if nixio.fs.access("/etc/init.d/asterisk") then
  17. server = "asterisk"
  18. elseif nixio.fs.access("/etc/init.d/freeswitch") then
  19. server = "freeswitch"
  20. else
  21. server = ""
  22. end
  23. -- Returns formatted output of string containing only the words at the indices
  24. -- specified in the table "indices".
  25. function format_indices(string, indices)
  26. if indices == nil then
  27. return "Error: No indices to format specified.\n"
  28. end
  29. -- Split input into separate lines.
  30. lines = luci.util.split(luci.util.trim(string), "\n")
  31. -- Split lines into separate words.
  32. splitlines = {}
  33. for lpos,line in ipairs(lines) do
  34. splitlines[lpos] = luci.util.split(luci.util.trim(line), "%s+", nil, true)
  35. end
  36. -- For each split line, if the word at all indices specified
  37. -- to be formatted are not null, add the formatted line to the
  38. -- gathered output.
  39. output = ""
  40. for lpos,splitline in ipairs(splitlines) do
  41. loutput = ""
  42. for ipos,index in ipairs(indices) do
  43. if splitline[index] ~= nil then
  44. loutput = loutput .. string.format("%-40s", splitline[index])
  45. else
  46. loutput = nil
  47. break
  48. end
  49. end
  50. if loutput ~= nil then
  51. output = output .. loutput .. "\n"
  52. end
  53. end
  54. return output
  55. end
  56. m = Map (modulename, translate("PBX Main Page"),
  57. translate("This configuration page allows you to configure a phone system (PBX) service which \
  58. permits making phone calls through multiple Google and SIP (like Sipgate, \
  59. SipSorcery, and Betamax) accounts and sharing them among many SIP devices. \
  60. Note that Google accounts, SIP accounts, and local user accounts are configured in the \
  61. \"Google Accounts\", \"SIP Accounts\", and \"User Accounts\" sub-sections. \
  62. You must add at least one User Account to this PBX, and then configure a SIP device or \
  63. softphone to use the account, in order to make and receive calls with your Google/SIP \
  64. accounts. Configuring multiple users will allow you to make free calls between all users, \
  65. and share the configured Google and SIP accounts. If you have more than one Google and SIP \
  66. accounts set up, you should probably configure how calls to and from them are routed in \
  67. the \"Call Routing\" page. If you're interested in using your own PBX from anywhere in the \
  68. world, then visit the \"Remote Usage\" section in the \"Advanced Settings\" page."))
  69. -----------------------------------------------------------------------------------------
  70. s = m:section(NamedSection, "connection_status", "main",
  71. translate("PBX Service Status"))
  72. s.anonymous = true
  73. s:option (DummyValue, "status", translate("Service Status"))
  74. sts = s:option(DummyValue, "_sts")
  75. sts.template = "cbi/tvalue"
  76. sts.rows = 20
  77. function sts.cfgvalue(self, section)
  78. if server == "asterisk" then
  79. regs = luci.sys.exec("asterisk -rx 'sip show registry' | sed 's/peer-//'")
  80. jabs = luci.sys.exec("asterisk -rx 'jabber show connections' | grep onnected")
  81. usrs = luci.sys.exec("asterisk -rx 'sip show users'")
  82. chan = luci.sys.exec("asterisk -rx 'core show channels'")
  83. return format_indices(regs, {1, 5}) ..
  84. format_indices(jabs, {2, 4}) .. "\n" ..
  85. format_indices(usrs, {1} ) .. "\n" .. chan
  86. elseif server == "freeswitch" then
  87. return "Freeswitch is not supported yet.\n"
  88. else
  89. return "Neither Asterisk nor FreeSwitch discovered, please install Asterisk, as Freeswitch is not supported yet.\n"
  90. end
  91. end
  92. return m