dialplans.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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", "Registered 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. host = sip_table:option(DummyValue, "host", "Hostname")
  49. function host.cfgvalue(self, s)
  50. if sip_peers[s] and sip_peers[s].info.address then
  51. return "%s:%i" %{ sip_peers[s].info.address, sip_peers[s].info.port }
  52. else
  53. return "n/a"
  54. end
  55. end
  56. context = sip_table:option(DummyValue, "context", "Dialplan")
  57. context.href = luci.dispatcher.build_url("admin", "asterisk", "dialplan")
  58. function context.cfgvalue(...)
  59. return AbstractValue.cfgvalue(...) or "(default)"
  60. end
  61. online = sip_table:option(DummyValue, "online", "Registered")
  62. function online.cfgvalue(self, s)
  63. if sip_peers[s] and sip_peers[s].info.online == nil then
  64. return "n/a"
  65. else
  66. return sip_peers[s] and sip_peers[s].info.online
  67. and "yes" or "no (%s)" %{
  68. sip_peers[s] and sip_peers[s].info.Status:lower() or "unknown"
  69. }
  70. end
  71. end
  72. delay = sip_table:option(DummyValue, "delay", "Delay")
  73. function delay.cfgvalue(self, s)
  74. if sip_peers[s] and sip_peers[s].info.online then
  75. return "%i ms" % sip_peers[s].info.delay
  76. else
  77. return "n/a"
  78. end
  79. end
  80. info = sip_table:option(Button, "_info", "Info")
  81. function info.write(self, s)
  82. luci.http.redirect(luci.dispatcher.build_url(
  83. "admin", "asterisk", "trunks", "sip", s, "info"
  84. ))
  85. end
  86. return cbimap