trunks.lua 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. -- Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
  2. -- Licensed to the public under the Apache License 2.0.
  3. local ast = require("luci.asterisk")
  4. cbimap = Map("asterisk", "Trunks")
  5. cbimap.pageaction = false
  6. local sip_peers = { }
  7. cbimap.uci:foreach("asterisk", "sip",
  8. function(s)
  9. if s.type == "peer" then
  10. s.name = s['.name']
  11. s.info = ast.sip.peer(s.name)
  12. sip_peers[s.name] = s
  13. end
  14. end)
  15. sip_table = cbimap:section(TypedSection, "sip", "SIP Trunks")
  16. sip_table.template = "cbi/tblsection"
  17. sip_table.extedit = luci.dispatcher.build_url("admin", "asterisk", "trunks", "sip", "%s")
  18. sip_table.addremove = true
  19. sip_table.sectionhead = "Extension"
  20. function sip_table.filter(self, s)
  21. return s and (
  22. cbimap.uci:get("asterisk", s, "type") == nil or
  23. cbimap.uci:get_bool("asterisk", s, "provider")
  24. )
  25. end
  26. function sip_table.create(self, section)
  27. if TypedSection.create(self, section) then
  28. created = section
  29. else
  30. self.invalid_cts = true
  31. end
  32. end
  33. function sip_table.parse(self, ...)
  34. TypedSection.parse(self, ...)
  35. if created then
  36. cbimap.uci:tset("asterisk", created, {
  37. type = "friend",
  38. qualify = "yes",
  39. provider = "yes"
  40. })
  41. cbimap.uci:save("asterisk")
  42. luci.http.redirect(luci.dispatcher.build_url(
  43. "admin", "asterisk", "trunks", "sip", created
  44. ))
  45. end
  46. end
  47. user = sip_table:option(DummyValue, "username", "Username")
  48. context = sip_table:option(DummyValue, "context", "Dialplan")
  49. context.href = luci.dispatcher.build_url("admin", "asterisk", "dialplan")
  50. function context.cfgvalue(...)
  51. return AbstractValue.cfgvalue(...) or "(default)"
  52. end
  53. online = sip_table:option(DummyValue, "online", "Registered")
  54. function online.cfgvalue(self, s)
  55. if sip_peers[s] and sip_peers[s].info.online == nil then
  56. return "n/a"
  57. else
  58. return sip_peers[s] and sip_peers[s].info.online
  59. and "yes" or "no (%s)" %{
  60. sip_peers[s] and sip_peers[s].info.Status:lower() or "unknown"
  61. }
  62. end
  63. end
  64. delay = sip_table:option(DummyValue, "delay", "Delay")
  65. function delay.cfgvalue(self, s)
  66. if sip_peers[s] and sip_peers[s].info.online then
  67. return "%i ms" % sip_peers[s].info.delay
  68. else
  69. return "n/a"
  70. end
  71. end
  72. info = sip_table:option(Button, "_info", "Info")
  73. function info.write(self, s)
  74. luci.http.redirect(luci.dispatcher.build_url(
  75. "admin", "asterisk", "trunks", "sip", s, "info"
  76. ))
  77. end
  78. return cbimap