<%# LuCI - Lua Configuration Interface Copyright 2008 Steven Barth Copyright 2008 Jo-Philipp Wich Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 $Id$ -%> <%+header%> <% local uci = luci.model.uci.cursor_state() function find_rules(plan) local r = { } if plan and plan.include then local i = luci.util.split(plan.include, "%s+", nil, true) for _, i in ipairs(i) do i = uci:get("asterisk", "dialzone", i) if i then r[#r+1] = i end end end return r end dp_lookup_table = { } function dialplan_lookup(s) if not dp_lookup_table[s['.name']] then s.childs = { } s.matches = type(s.match) == "table" and s.match or { s.match } s.name, s.type = s['.name'], s['.type'] s['.name'], s['.type'] = nil, nil dp_lookup_table[s.name] = s end end uci:foreach("asterisk", "dialplan", dialplan_lookup) uci:foreach("asterisk", "dialzone", dialplan_lookup) for k, p in pairs(dp_lookup_table) do if p.include then local i = type(p.include) == "string" and luci.util.split(p.include, "%s+", nil, true) or p.include for _, i in ipairs(i) do i = dp_lookup_table[i] if i then p.childs[#p.childs+1] = i i.parent = p end end end end function digit_pattern(s) return "%s" % s end function rowstyle(i) return "cbi-rowstyle-%i" %{ ( i % 2 ) == 0 and 2 or 1 } end function link_trunks(s) local l = { } for s in s:gmatch("(%S+)") do if s:match("^[sS][iI][pP]/") then l[#l+1] = '%s' %{ luci.dispatcher.build_url("admin", "asterisk", "trunks", "sip", (s:gsub("^.+/",""))), (s:gsub("^.+/","SIP: ")) } end end return '%s' % table.concat(l, ", ") end %>
" enctype="multipart/form-data">

Outgoing Call Routing

<% for name, plan in luci.util.kspairs(dp_lookup_table) do if plan.type == "dialplan" then %>
<% for i, rule in pairs(plan.childs) do if rule.type == "dialzone" then %> <% end end %>
 Dialplan <%=name%>
Prepend - Match Trunk Description
<% for _ in ipairs(rule.matches) do %> <%=rule.addprefix and digit_pattern(rule.addprefix)%> 
<% end %>
<% for _, m in ipairs(rule.matches) do %> <%=rule.localprefix and "%s " % digit_pattern(rule.localprefix)%> <%=digit_pattern(m)%>
<% end %>
<%=rule.uses and link_trunks(rule.uses)%> <%=rule.description or rule.name%> Edit entry Delete entry

<% end end %>
<%+footer%>