applications/luci-asterisk:
[project/luci.git] / applications / luci-asterisk / luasrc / view / asterisk / dialplans.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2008 Steven Barth <steven@midlink.org>
4 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
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 <%+header%>
17
18 <%
19 local uci = luci.model.uci.cursor_state()
20
21 function find_rules(plan)
22 local r = { }
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)
27 if i then
28 r[#r+1] = i
29 end
30 end
31 end
32 return r
33 end
34
35 dp_lookup_table = { }
36
37 function dialplan_lookup(s)
38 if not dp_lookup_table[s['.name']] then
39 s.childs = { }
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
44 end
45 end
46
47 uci:foreach("asterisk", "dialplan", dialplan_lookup)
48 uci:foreach("asterisk", "dialzone", dialplan_lookup)
49
50 for k, p in pairs(dp_lookup_table) do
51 if p.include then
52 local i = type(p.include) == "string"
53 and luci.util.split(p.include, "%s+", nil, true) or p.include
54
55 for _, i in ipairs(i) do
56 i = dp_lookup_table[i]
57 if i then
58 p.childs[#p.childs+1] = i
59 i.parent = p
60 end
61 end
62 end
63 end
64
65 function digit_pattern(s)
66 return "<code style='padding: 2px; border:1px solid #CCCCCC; background-color: #FFFFFF'>%s</code>" % s
67 end
68
69 function rowstyle(i)
70 return "cbi-rowstyle-%i" %{
71 ( i % 2 ) == 0 and 2 or 1
72 }
73 end
74
75 function link_trunks(s)
76 local l = { }
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: "))
83 }
84 end
85 end
86 return '<small>%s</small>' % table.concat(l, ", ")
87 end
88 %>
89
90
91 <form method="post" action="<%=luci.dispatcher.build_url("admin", "asterisk", "dialplans")%>" enctype="multipart/form-data">
92 <div>
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" />
96 </div>
97
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>
104
105
106
107
108
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>&nbsp;Dialplan <em><%=name%></em></big>
116 </th>
117 </tr>
118
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>
125 </tr>
126
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)%>&nbsp;<br />
133 <% end %>
134 </td>
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 />
139 <% end %>
140 </td>
141 <td style="text-align:left" class="cbi-value-field">
142 <%=rule.uses and link_trunks(rule.uses)%>
143 </td>
144 <td style="text-align:left" class="cbi-value-field">
145 <%=rule.description or rule.name%>
146 </td>
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" />
150 </a>
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" />
153 </a>
154 </td>
155 </tr>
156 <% end end %>
157 </table>
158
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"/>
162 </div>
163 </div>
164 <br />
165 <% end end %>
166
167 </fieldset>
168 </div>
169 </form>
170 <div class="clear"></div>
171 <%+footer%>