dialzones.lua 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. local uci = require("luci.model.uci").cursor()
  5. --[[
  6. Dialzone overview table
  7. ]]
  8. if not arg[1] then
  9. zonemap = Map("asterisk", "Dial Zones", [[
  10. Dial zones hold patterns of dialed numbers to match.
  11. Each zone has one or more trunks assigned. If the first trunk is
  12. congested, Asterisk will try to use the next available connection.
  13. If all trunks fail, then the following zones in the parent dialplan
  14. are tried.
  15. ]])
  16. local zones, znames = ast.dialzone.zones()
  17. zonetbl = zonemap:section(Table, zones, "Zone Overview")
  18. zonetbl.sectionhead = "Zone"
  19. zonetbl.addremove = true
  20. zonetbl.anonymous = false
  21. zonetbl.extedit = luci.dispatcher.build_url(
  22. "admin", "asterisk", "dialplans", "zones", "%s"
  23. )
  24. function zonetbl.cfgsections(self)
  25. return znames
  26. end
  27. function zonetbl.parse(self)
  28. for k, v in pairs(self.map:formvaluetable(
  29. luci.cbi.REMOVE_PREFIX .. self.config
  30. ) or {}) do
  31. if k:sub(-2) == ".x" then k = k:sub(1, #k - 2) end
  32. uci:delete("asterisk", k)
  33. uci:save("asterisk")
  34. self.data[k] = nil
  35. for i = 1,#znames do
  36. if znames[i] == k then
  37. table.remove(znames, i)
  38. break
  39. end
  40. end
  41. end
  42. Table.parse(self)
  43. end
  44. zonetbl:option(DummyValue, "description", "Description")
  45. zonetbl:option(DummyValue, "addprefix")
  46. match = zonetbl:option(DummyValue, "matches")
  47. function match.cfgvalue(self, s)
  48. return table.concat(zones[s].matches, ", ")
  49. end
  50. trunks = zonetbl:option(DummyValue, "trunk")
  51. trunks.template = "asterisk/cbi/cell"
  52. function trunks.cfgvalue(self, s)
  53. return ast.tools.hyperlinks(zones[s].trunks)
  54. end
  55. return zonemap
  56. --[[
  57. Zone edit form
  58. ]]
  59. else
  60. zoneedit = Map("asterisk", "Edit Dialzone")
  61. entry = zoneedit:section(NamedSection, arg[1])
  62. entry.title = "Zone %q" % arg[1];
  63. back = entry:option(DummyValue, "_overview", "Back to dialzone overview")
  64. back.value = ""
  65. back.titleref = luci.dispatcher.build_url(
  66. "admin", "asterisk", "dialplans", "zones"
  67. )
  68. desc = entry:option(Value, "description", "Description")
  69. function desc.cfgvalue(self, s, ...)
  70. return Value.cfgvalue(self, s, ...) or s
  71. end
  72. trunks = entry:option(MultiValue, "uses", "Used trunks")
  73. trunks.widget = "checkbox"
  74. uci:foreach("asterisk", "sip",
  75. function(s)
  76. if s.provider == "yes" then
  77. trunks:value(
  78. "SIP/%s" % s['.name'],
  79. "SIP/%s (%s)" %{ s['.name'], s.host or 'n/a' }
  80. )
  81. end
  82. end)
  83. match = entry:option(DynamicList, "match", "Number matches")
  84. intl = entry:option(DynamicList, "international", "Intl. prefix matches (optional)")
  85. aprefix = entry:option(Value, "addprefix", "Add prefix to dial out (optional)")
  86. ccode = entry:option(Value, "countrycode", "Effective countrycode (optional)")
  87. lzone = entry:option(ListValue, "localzone", "Dialzone for local numbers")
  88. lzone:value("", "no special treatment of local numbers")
  89. for _, z in ipairs(ast.dialzone.zones()) do
  90. lzone:value(z.name, "%q (%s)" %{ z.name, z.description })
  91. end
  92. --for _, v in ipairs(find_outgoing_contexts(zoneedit.uci)) do
  93. -- lzone:value(unpack(v))
  94. --end
  95. lprefix = entry:option(Value, "localprefix", "Prefix for local calls (optional)")
  96. return zoneedit
  97. end