Merge pull request #1818 from dibdot/lxc_fix
[project/luci.git] / applications / luci-app-firewall / luasrc / view / firewall / cbi_addsnat.htm
1 <%
2         local fw = require "luci.model.firewall".init()
3         local nw = require "luci.model.network".init()
4         local zones = fw:get_zones()
5
6         local keys, vals, a, k, v = {}, {}
7         for k, v in ipairs(nw:get_interfaces()) do
8                 for k, a in ipairs(v:ipaddrs()) do
9                         keys[#keys+1] = a:host():string()
10                         vals[#vals+1] = '%s (%s)' %{ a:host(), v:shortname() }
11                 end
12         end
13 %>
14
15 <div class="cbi-section-create cbi-tblsection-create">
16         <% if #zones > 1 then %>
17                 <br />
18                 <table class="cbi-section-table" style="width:700px; margin-left:5px">
19                         <tr class="cbi-section-table-titles">
20                                 <th class="cbi-section-table-cell left" colspan="6"><%:New source NAT%>:</th>
21                         </tr>
22                         <tr class="cbi-section-table-descr">
23                                 <th class="cbi-section-table-cell"><%:Name%></th>
24                                 <th class="cbi-section-table-cell"><%:Source zone%></th>
25                                 <th class="cbi-section-table-cell"><%:Destination zone%></th>
26                                 <th class="cbi-section-table-cell"><%:To source IP%></th>
27                                 <th class="cbi-section-table-cell"><%:To source port%></th>
28                                 <th class="cbi-section-table-cell"></th>
29                         </tr>
30                         <tr class="cbi-section-table-row">
31                                 <td class="cbi-section-table-cell">
32                                         <input type="text" class="cbi-input-text" id="_newsnat.name" name="_newsnat.name" placeholder="<%:New SNAT rule%>" />
33                                 </td>
34                                 <td class="cbi-section-table-cell" style="width:110px">
35                                         <select class="cbi-input-text" id="_newsnat.src" name="_newsnat.src">
36                                                 <% local k, v; for k, v in ipairs(fw:get_zones()) do -%>
37                                                         <option<%=ifattr(v:name() == "lan", "selected", "selected")%> value="<%=v:name()%>"><%=v:name()%></option>
38                                                 <%- end %>
39                                         </select>
40                                 </td>
41                                 <td class="cbi-section-table-cell" style="width:110px">
42                                         <select class="cbi-input-text" id="_newsnat.dest" name="_newsnat.dest">
43                                                 <% local k, v; for k, v in ipairs(fw:get_zones()) do -%>
44                                                         <option<%=ifattr(v:name() == "wan", "selected", "selected")%> value="<%=v:name()%>"><%=v:name()%></option>
45                                                 <%- end %>
46                                         </select>
47                                 </td>
48                                 <td class="cbi-section-table-cell" style="width:110px">
49                                         <input type="text" class="cbi-input-text" id="_newsnat.dip" name="_newsnat.dip" placeholder="<%:Do not rewrite%>" data-type="ip4addr" data-optional="true"<%=
50                                                 ifattr(#keys > 0, "data-choices", { keys, vals })
51                                         %> />
52                                 </td>
53                                 <td class="cbi-section-table-cell" style="width:110px">
54                                         <input type="text" class="cbi-input-text" id="_newsnat.dport" name="_newsnat.dport" placeholder="<%:Do not rewrite%>" data-type="portrange" data-optional="true" />
55                                 </td>
56                                 <td class="cbi-section-table-cell">
57                                         <input type="submit" class="cbi-button cbi-button-link" name="_newsnat.submit" value="<%:Add and edit...%>" />
58                                 </td>
59                         </tr>
60                 </table>
61         <% else %>
62                 <input type="submit" class="cbi-button cbi-button-add" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" value="<%:Add%>" />
63         <% end %>
64 </div>