2 LuCI - Lua Configuration Interface
3 Copyright
2008 Steven Barth
<steven@midlink.org
>
4 Copyright
2008 Jo-Philipp Wich
<xm@leipzig.freifunk.net
>
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
10 http://www.apache.org/licenses/LICENSE-
2.0
19 local uci = luci.model.uci.cursor_state()
21 function find_rules(plan)
23 if plan and plan.include then
24 local i = luci.util.split(plan.include,
"%s+", nil, true)
25 for _, i in ipairs(i) do
26 i = uci:get(
"asterisk",
"dialzone", i)
37 function dialplan_lookup(s)
38 if not dp_lookup_table[s['.name']] then
40 s.matches = type(s.match) ==
"table" and s.match or { s.match }
41 s.name, s.type = s['.name'], s['.type']
42 s['.name'], s['.type'] = nil, nil
43 dp_lookup_table[s.name] = s
47 uci:foreach(
"asterisk",
"dialplan", dialplan_lookup)
48 uci:foreach(
"asterisk",
"dialzone", dialplan_lookup)
50 for k, p in pairs(dp_lookup_table) do
52 local i = type(p.include) ==
"string"
53 and luci.util.split(p.include,
"%s+", nil, true) or p.include
55 for _, i in ipairs(i) do
56 i = dp_lookup_table[i]
58 p.childs[#p.childs+
1] = i
65 function digit_pattern(s)
66 return
"<code style='padding: 2px; border:1px solid #CCCCCC; background-color: #FFFFFF'>%s</code>" % s
70 return
"cbi-rowstyle-%i" %{
71 ( i %
2 ) ==
0 and
2 or
1
75 function link_trunks(s)
77 for s in s:gmatch(
"(%S+)") do
78 if s:match(
"^[sS][iI][pP]/") then
79 l[#l+
1] = '
<a href=
"%s">%s
</a>' %{
80 luci.dispatcher.build_url(
"admin",
"asterisk",
"trunks",
81 "sip", (s:gsub(
"^.+/",
""))),
82 (s:gsub(
"^.+/",
"SIP: "))
86 return '
<small>%s
</small>' % table.concat(l,
", ")
91 <form method=
"post" action=
"<%=luci.dispatcher.build_url("admin
", "asterisk
", "dialplans
")%>" enctype=
"multipart/form-data">
93 <script type=
"text/javascript" src=
"/luci-static/resources/cbi.js"></script>
94 <input type=
"hidden" name=
"cbi.submit" value=
"1" />
95 <input type=
"submit" value=
"Save" class=
"hidden" />
98 <div class=
"cbi-map" id=
"cbi-asterisk">
99 <h2><a id=
"content" name=
"content">Outgoing Call Routing
</a></h2>
100 <div class=
"cbi-map-descr"></div><!-- tblsection -->
101 <fieldset class=
"cbi-section" id=
"cbi-asterisk-sip">
102 <!--<legend>Dialplans</legend>-->
103 <div class=
"cbi-section-descr"></div>
109 <% for name, plan in luci.util.kspairs(dp_lookup_table) do
110 if plan.type ==
"dialplan" then %
>
111 <div class=
"cbi-section-node">
112 <table class=
"cbi-section-table">
113 <tr class=
"cbi-section-table-titles">
114 <th style=
"text-align: left; padding: 3px" class=
"cbi-section-table-cell" colspan=
"5">
115 <big> Dialplan
<em><%=name%
></em></big>
119 <tr class=
"cbi-section-table-descr">
120 <th style=
"width: 5%; text-align:right" class=
"cbi-section-table-cell">Prepend
</th>
121 <th style=
"width: 20%; text-align:left" class=
"cbi-section-table-cell">- Match
</th>
122 <th style=
"text-align:left" class=
"cbi-section-table-cell">Trunk
</th>
123 <th style=
"width: 40%; text-align:left" class=
"cbi-section-table-cell">Description
</th>
124 <th style=
"width: 4%; text-align:left" class=
"cbi-section-table-cell"></th>
127 <% for i, rule in pairs(plan.childs) do
128 if rule.type ==
"dialzone" then %
>
129 <tr class=
"cbi-section-table-row <%=rowstyle(i)%>">
130 <td style=
"text-align:right" class=
"cbi-value-field">
131 <% for _ in ipairs(rule.matches) do %
>
132 <%=rule.addprefix and digit_pattern(rule.addprefix)%
> <br />
135 <td style=
"text-align:left" class=
"cbi-value-field">
136 <% for _, m in ipairs(rule.matches) do %
>
137 <%=rule.localprefix and
"%s " % digit_pattern(rule.localprefix)%
>
138 <%=digit_pattern(m)%
><br />
141 <td style=
"text-align:left" class=
"cbi-value-field">
142 <%=rule.uses and link_trunks(rule.uses)%
>
144 <td style=
"text-align:left" class=
"cbi-value-field">
145 <%=rule.description or rule.name%
>
147 <td style=
"text-align:left" class=
"cbi-value-field">
148 <a href=
"<%=luci.dispatcher.build_url('admin', 'asterisk', 'dialplans', 'out', rule.name)%>">
149 <img style=
"border:none" alt=
"Edit entry" title=
"Edit entry" src=
"/luci-static/resources/cbi/edit.gif" />
151 <a href=
"<%=luci.dispatcher.build_url('admin', 'asterisk', 'dialplans')%>?delete=<%=rule.name%>">
152 <img style=
"border:none" alt=
"Delete entry" title=
"Delete entry" src=
"/luci-static/resources/cbi/remove.gif" />
159 <div class=
"cbi-section-create cbi-tblsection-create">
160 <input type=
"text" class=
"cbi-section-create-name" name=
"create_entry.<%=name%>"/>
161 <input type=
"submit" class=
"cbi-button cbi-button-add" value=
"Add entry" title=
"Add entry"/>
170 <div class=
"clear"></div>