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