1 -- Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
2 -- Licensed to the public under the Apache License 2.0.
4 local ast = require("luci.asterisk")
5 local uci = require("luci.model.uci").cursor()
8 Dialzone overview table
12 zonemap = Map("asterisk", "Dial Zones", [[
13 Dial zones hold patterns of dialed numbers to match.
14 Each zone has one or more trunks assigned. If the first trunk is
15 congested, Asterisk will try to use the next available connection.
16 If all trunks fail, then the following zones in the parent dialplan
20 local zones, znames = ast.dialzone.zones()
22 zonetbl = zonemap:section(Table, zones, "Zone Overview")
23 zonetbl.sectionhead = "Zone"
24 zonetbl.addremove = true
25 zonetbl.anonymous = false
26 zonetbl.extedit = luci.dispatcher.build_url(
27 "admin", "asterisk", "dialplans", "zones", "%s"
30 function zonetbl.cfgsections(self)
34 function zonetbl.parse(self)
35 for k, v in pairs(self.map:formvaluetable(
36 luci.cbi.REMOVE_PREFIX .. self.config
38 if k:sub(-2) == ".x" then k = k:sub(1, #k - 2) end
39 uci:delete("asterisk", k)
43 if znames[i] == k then
44 table.remove(znames, i)
53 zonetbl:option(DummyValue, "description", "Description")
54 zonetbl:option(DummyValue, "addprefix")
56 match = zonetbl:option(DummyValue, "matches")
57 function match.cfgvalue(self, s)
58 return table.concat(zones[s].matches, ", ")
61 trunks = zonetbl:option(DummyValue, "trunk")
62 trunks.template = "asterisk/cbi/cell"
63 function trunks.cfgvalue(self, s)
64 return ast.tools.hyperlinks(zones[s].trunks)
74 zoneedit = Map("asterisk", "Edit Dialzone")
76 entry = zoneedit:section(NamedSection, arg[1])
77 entry.title = "Zone %q" % arg[1];
79 back = entry:option(DummyValue, "_overview", "Back to dialzone overview")
81 back.titleref = luci.dispatcher.build_url(
82 "admin", "asterisk", "dialplans", "zones"
85 desc = entry:option(Value, "description", "Description")
86 function desc.cfgvalue(self, s, ...)
87 return Value.cfgvalue(self, s, ...) or s
90 trunks = entry:option(MultiValue, "uses", "Used trunks")
91 trunks.widget = "checkbox"
92 uci:foreach("asterisk", "sip",
94 if s.provider == "yes" then
96 "SIP/%s" % s['.name'],
97 "SIP/%s (%s)" %{ s['.name'], s.host or 'n/a' }
103 match = entry:option(DynamicList, "match", "Number matches")
105 intl = entry:option(DynamicList, "international", "Intl. prefix matches (optional)")
107 aprefix = entry:option(Value, "addprefix", "Add prefix to dial out (optional)")
108 ccode = entry:option(Value, "countrycode", "Effective countrycode (optional)")
110 lzone = entry:option(ListValue, "localzone", "Dialzone for local numbers")
111 lzone:value("", "no special treatment of local numbers")
112 for _, z in ipairs(ast.dialzone.zones()) do
113 lzone:value(z.name, "%q (%s)" %{ z.name, z.description })
115 --for _, v in ipairs(find_outgoing_contexts(zoneedit.uci)) do
116 -- lzone:value(unpack(v))
119 lprefix = entry:option(Value, "localprefix", "Prefix for local calls (optional)")