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