dialplan_out.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 function find_outgoing_contexts(uci)
  5. local c = { }
  6. local h = { }
  7. -- uci:foreach("asterisk", "dialplan",
  8. -- function(s)
  9. -- if not h[s['.name']] then
  10. -- c[#c+1] = { s['.name'], "Dialplan: %s" % s['.name'] }
  11. -- h[s['.name']] = true
  12. -- end
  13. -- end)
  14. uci:foreach("asterisk", "dialzone",
  15. function(s)
  16. if not h[s['.name']] then
  17. c[#c+1] = { s['.name'], "Dialzone: %s" % s['.name'] }
  18. h[s['.name']] = true
  19. end
  20. end)
  21. return c
  22. end
  23. local function find_incoming_contexts(uci)
  24. local c = { }
  25. local h = { }
  26. uci:foreach("asterisk", "sip",
  27. function(s)
  28. if s.context and not h[s.context] and
  29. uci:get_bool("asterisk", s['.name'], "provider")
  30. then
  31. c[#c+1] = { s.context, "Incoming: %s" % s['.name'] or s.context }
  32. h[s.context] = true
  33. end
  34. end)
  35. return c
  36. end
  37. local function find_trunks(uci)
  38. local t = { }
  39. uci:foreach("asterisk", "sip",
  40. function(s)
  41. if uci:get_bool("asterisk", s['.name'], "provider") then
  42. t[#t+1] = {
  43. "SIP/%s" % s['.name'],
  44. "SIP: %s" % s['.name']
  45. }
  46. end
  47. end)
  48. uci:foreach("asterisk", "iax",
  49. function(s)
  50. t[#t+1] = {
  51. "IAX/%s" % s['.name'],
  52. "IAX: %s" % s.extension or s['.name']
  53. }
  54. end)
  55. return t
  56. end
  57. --[[
  58. dialzone {name} - Outgoing zone.
  59. uses - Outgoing line to use: TYPE/Name
  60. match (list) - Number to match
  61. countrycode - The effective country code of this dialzone
  62. international (list) - International prefix to match
  63. localzone - dialzone for local numbers
  64. addprefix - Prexix required to dial out.
  65. localprefix - Prefix for a local call
  66. ]]
  67. --
  68. -- SIP dialzone configuration
  69. --
  70. if arg[1] then
  71. cbimap = Map("asterisk", "Edit Dialplan Entry")
  72. entry = cbimap:section(NamedSection, arg[1])
  73. back = entry:option(DummyValue, "_overview", "Back to dialplan overview")
  74. back.value = ""
  75. back.titleref = luci.dispatcher.build_url("admin", "asterisk", "dialplans")
  76. desc = entry:option(Value, "description", "Description")
  77. function desc.cfgvalue(self, s, ...)
  78. return Value.cfgvalue(self, s, ...) or s
  79. end
  80. match = entry:option(DynamicList, "match", "Number matches")
  81. intl = entry:option(DynamicList, "international", "Intl. prefix matches (optional)")
  82. trunk = entry:option(MultiValue, "uses", "Used trunk")
  83. for _, v in ipairs(find_trunks(cbimap.uci)) do
  84. trunk:value(unpack(v))
  85. end
  86. aprefix = entry:option(Value, "addprefix", "Add prefix to dial out (optional)")
  87. --ast.idd.cbifill(aprefix)
  88. ccode = entry:option(Value, "countrycode", "Effective countrycode (optional)")
  89. ast.cc.cbifill(ccode)
  90. lzone = entry:option(ListValue, "localzone", "Dialzone for local numbers")
  91. lzone:value("", "no special treatment of local numbers")
  92. for _, v in ipairs(find_outgoing_contexts(cbimap.uci)) do
  93. lzone:value(unpack(v))
  94. end
  95. lprefix = entry:option(Value, "localprefix", "Prefix for local calls (optional)")
  96. return cbimap
  97. end