f93496df8baae8787b41a47a5885da068390cbfe
[project/luci.git] / applications / luci-app-asterisk / luasrc / view / asterisk / dialzones.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         local ast = require("luci.asterisk")
21
22         function digit_pattern(s)
23                 return "<code style='padding: 2px; border:1px solid #CCCCCC; background-color: #FFFFFF'>%s</code>" % s
24         end
25
26         function rowstyle(i)
27                 return "cbi-rowstyle-%i" %{
28                         ( i % 2 ) == 0 and 2 or 1
29                 }
30         end
31
32         local function find_trunks()
33                 local t = { }
34
35                 uci:foreach("asterisk", "sip",
36                         function(s)
37                                 if uci:get_bool("asterisk", s['.name'], "provider") then
38                                         t[#t+1] = {
39                                                 "SIP/%s" % s['.name'],
40                                                 "SIP: %s" % s['.name']
41                                         }
42                                 end
43                         end)
44
45                 uci:foreach("asterisk", "iax",
46                         function(s)
47                                 t[#t+1] = {
48                                         "IAX/%s" % s['.name'],
49                                         "IAX: %s" % s.extension or s['.name']
50                                 }
51                         end)
52
53                 return t
54         end
55
56 %>
57
58
59 <form method="post" action="<%=luci.dispatcher.build_url("admin", "asterisk", "dialplans", "zones")%>" enctype="multipart/form-data">
60         <div>
61                 <script type="text/javascript" src="/luci-static/resources/cbi.js"></script>
62                 <input type="hidden" name="cbi.submit" value="1" />
63                 <input type="submit" value="Save" class="hidden" />
64         </div>
65
66 <div class="cbi-map" id="cbi-asterisk">
67         <h2><a id="content" name="content">Dial Zone Management</a></h2>
68         <div class="cbi-map-descr">
69                 <a href="<%=luci.dispatcher.build_url("admin/asterisk/dialplans")%>" class="cbi-title-ref">Back to dialplan overview</a><br /><br />
70                 Here you can manage your dial zones. The zones are used to route outgoing calls to the destination.
71                 Each zone groups multiple trunks and number matches to represent a logical destination. Zones can
72                 also be used to enforce certain dial restrictions on selected extensions.
73         </div>
74
75         <!-- tblsection -->
76         <fieldset class="cbi-section" id="cbi-asterisk-sip">
77                 <div class="cbi-section-node">
78                         <table class="cbi-section-table">
79                                 <tr class="cbi-section-table-titles">
80                                         <th style="text-align: left; padding: 3px" class="cbi-section-table-cell" colspan="6">
81                                                 <h3>Dialzone Overview</h3>
82                                         </th>
83                                 </tr>
84
85                                 <tr class="cbi-section-table-descr">
86                                         <th style="width: 5%; text-align:right" class="cbi-section-table-cell">Name</th>
87                                         <th style="width: 5%; text-align:right" class="cbi-section-table-cell">Prepend</th>
88                                         <th style="width: 20%; text-align:left" class="cbi-section-table-cell">- Match</th>
89                                         <th style="text-align:left" class="cbi-section-table-cell">Trunk</th>
90                                         <th style="width: 35%; text-align:left" class="cbi-section-table-cell">Description</th>
91                                         <th style="width: 4%; text-align:left" class="cbi-section-table-cell"></th>
92                                 </tr>
93
94                                 <% for i, rule in pairs(ast.dialzone.zones()) do %>
95                                 <tr class="cbi-section-table-row <%=rowstyle(i)%>">
96                                         <td style="text-align:right" class="cbi-value-field">
97                                                 <%=rule.name%>
98                                         </td>
99                                         <td style="text-align:right" class="cbi-value-field">
100                                                 <% for _ in ipairs(rule.matches) do %>
101                                                         <%=rule.addprefix and digit_pattern(rule.addprefix)%>&#160;<br />
102                                                 <% end %>
103                                         </td>
104                                         <td style="text-align:left" class="cbi-value-field">
105                                                 <% for _, m in ipairs(rule.matches) do %>
106                                                         <%=rule.localprefix and "%s " % digit_pattern(rule.localprefix)%>
107                                                         <%=digit_pattern(m)%><br />
108                                                 <% end %>
109                                         </td>
110                                         <td style="text-align:left" class="cbi-value-field">
111                                                 <%=ast.tools.hyperlinks(
112                                                         rule.trunks, function(v)
113                                                                 return luci.dispatcher.build_url("admin", "asterisk", "trunks", "%s") % v:lower()
114                                                         end
115                                                 )%>
116                                         </td>
117                                         <td style="text-align:left" class="cbi-value-field">
118                                                 <%=rule.description or rule.name%>
119                                         </td>
120                                         <td style="text-align:left" class="cbi-value-field">
121                                                 <a href="<%=luci.dispatcher.build_url('admin', 'asterisk', 'dialplans', 'out', rule.name)%>">
122                                                         <img style="border:none" alt="Edit entry" title="Edit entry" src="/luci-static/resources/cbi/edit.gif" />
123                                                 </a>
124                                                 <a href="<%=luci.dispatcher.build_url('admin', 'asterisk', 'dialplans', 'zones')%>?delzone=<%=rule.name%>">
125                                                         <img style="border:none" alt="Delete entry" title="Delete entry" src="/luci-static/resources/cbi/remove.gif" />
126                                                 </a>
127                                         </td>
128                                 </tr>
129                                 <% end %>
130                         </table>
131                         <div class="cbi-section-create cbi-tblsection-create"></div>
132                 </div>
133                 <br />
134
135                 <div class="cbi-section-node">
136                         <div class="cbi-section-create cbi-tblsection-create" style="padding: 3px">
137                                 <h3>Create a new dialzone</h3>
138                                 The name is required and must be unique. It may only contain the characters A-Z, a-z, 0-9 and _ .<br />
139                                 You can specifiy multiple number matches by separating them with spaces.<br />
140
141                                 <%- if create_error then %>
142                                         <br /><span style="color:red">Invalid name given!</span><br />
143                                 <% end -%>
144
145                                 <table>
146                                         <tr>
147                                                 <td style="padding:3px">
148                                                         <label for="create1">1) Name</label><br />
149                                                         <input type="text" class="cbi-section-create-name" id="create1" name="newzone_name" style="width:200px" />
150                                                         <br /><br />
151
152                                                         <label for="create2">2) Number Match</label><br />
153                                                         <input type="text" class="cbi-section-create-name" id="create2" name="newzone_match" style="width:200px" />
154                                                 </td>
155                                                 <td style="padding:3px">
156                                                         <label for="create3">3) Trunks</label><br />
157                                                         <select class="cbi-input-select" multiple="multiple" id="create3" name="newzone_uses" size="4"  style="width:200px">
158                                                                 <% for i, t in ipairs(find_trunks()) do %>
159                                                                         <option value="<%=t[1]%>"><%=t[2]%></option>
160                                                                 <% end %>
161                                                         </select>
162                                                 </td>
163                                         </tr>
164                                 </table>
165                                 <br />
166
167                                 <input type="submit" class="cbi-button cbi-button-add" name="newzone" value="Add entry" title="Add entry"/>
168                         </div>
169                 </div>
170         </fieldset>
171 </div>
172 </form>
173 <div class="clear"></div>
174 <%+footer%>