applications/luci-asterisk: initial dialplan voicemail box support
[project/luci.git] / applications / luci-asterisk / luasrc / model / cbi / asterisk / dialplan_out.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Jo-Philipp Wich <xm@subsignal.org>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13
14 ]]--
15
16 local ast = require("luci.asterisk")
17
18 local function find_outgoing_contexts(uci)
19 local c = { }
20 local h = { }
21
22 -- uci:foreach("asterisk", "dialplan",
23 -- function(s)
24 -- if not h[s['.name']] then
25 -- c[#c+1] = { s['.name'], "Dialplan: %s" % s['.name'] }
26 -- h[s['.name']] = true
27 -- end
28 -- end)
29
30 uci:foreach("asterisk", "dialzone",
31 function(s)
32 if not h[s['.name']] then
33 c[#c+1] = { s['.name'], "Dialzone: %s" % s['.name'] }
34 h[s['.name']] = true
35 end
36 end)
37
38 return c
39 end
40
41 local function find_incoming_contexts(uci)
42 local c = { }
43 local h = { }
44
45 uci:foreach("asterisk", "sip",
46 function(s)
47 if s.context and not h[s.context] and
48 uci:get_bool("asterisk", s['.name'], "provider")
49 then
50 c[#c+1] = { s.context, "Incoming: %s" % s['.name'] or s.context }
51 h[s.context] = true
52 end
53 end)
54
55 return c
56 end
57
58 local function find_trunks(uci)
59 local t = { }
60
61 uci:foreach("asterisk", "sip",
62 function(s)
63 if uci:get_bool("asterisk", s['.name'], "provider") then
64 t[#t+1] = {
65 "SIP/%s" % s['.name'],
66 "SIP: %s" % s['.name']
67 }
68 end
69 end)
70
71 uci:foreach("asterisk", "iax",
72 function(s)
73 t[#t+1] = {
74 "IAX/%s" % s['.name'],
75 "IAX: %s" % s.extension or s['.name']
76 }
77 end)
78
79 return t
80 end
81
82 --[[
83
84 dialzone {name} - Outgoing zone.
85 uses - Outgoing line to use: TYPE/Name
86 match (list) - Number to match
87 countrycode - The effective country code of this dialzone
88 international (list) - International prefix to match
89 localzone - dialzone for local numbers
90 addprefix - Prexix required to dial out.
91 localprefix - Prefix for a local call
92
93 ]]
94
95
96 --
97 -- SIP dialzone configuration
98 --
99 if arg[1] then
100 cbimap = Map("asterisk", "Edit Dialplan Entry")
101
102 entry = cbimap:section(NamedSection, arg[1])
103
104 back = entry:option(DummyValue, "_overview", "Back to dialplan overview")
105 back.value = ""
106 back.titleref = luci.dispatcher.build_url("admin", "asterisk", "dialplans")
107
108 desc = entry:option(Value, "description", "Description")
109 function desc.cfgvalue(self, s, ...)
110 return Value.cfgvalue(self, s, ...) or s
111 end
112
113 match = entry:option(DynamicList, "match", "Number matches")
114
115 intl = entry:option(DynamicList, "international", "Intl. prefix matches (optional)")
116
117 trunk = entry:option(MultiValue, "uses", "Used trunk")
118 for _, v in ipairs(find_trunks(cbimap.uci)) do
119 trunk:value(unpack(v))
120 end
121
122 aprefix = entry:option(Value, "addprefix", "Add prefix to dial out (optional)")
123 --ast.idd.cbifill(aprefix)
124
125 ccode = entry:option(Value, "countrycode", "Effective countrycode (optional)")
126 ast.cc.cbifill(ccode)
127
128 lzone = entry:option(ListValue, "localzone", "Dialzone for local numbers")
129 lzone:value("", "no special treatment of local numbers")
130 for _, v in ipairs(find_outgoing_contexts(cbimap.uci)) do
131 lzone:value(unpack(v))
132 end
133
134 lprefix = entry:option(Value, "localprefix", "Prefix for local calls (optional)")
135
136 return cbimap
137 end