luci-app-firewall: only show portforward template if there are more then one zone
[project/luci.git] / applications / luci-app-firewall / luasrc / view / firewall / cbi_addrule.htm
1 <%
2         local fw = require "luci.model.firewall".init()
3         local wz = fw:get_zone("wan")
4         local lz = fw:get_zone("lan")
5         local zones = fw:get_zones()
6 %>
7
8 <div class="cbi-section-create cbi-tblsection-create">
9         <% if wz then %>
10                 <br />
11                 <table class="cbi-section-table" style="margin-left:5px">
12                         <tr class="cbi-section-table-titles">
13                                 <th class="cbi-section-table-cell left" colspan="4"><%:Open ports on router%>:</th>
14                         </tr>
15                         <tr class="cbi-section-table-descr">
16                                 <th class="cbi-section-table-cell"><%:Name%></th>
17                                 <th class="cbi-section-table-cell"><%:Protocol%></th>
18                                 <th class="cbi-section-table-cell"><%:External port%></th>
19                                 <th class="cbi-section-table-cell"></th>
20                         </tr>
21                         <tr class="cbi-section-table-row">
22                                 <td class="cbi-section-table-cell" style="width:130px">
23                                         <input type="text" class="cbi-input-text" id="_newopen.name" name="_newopen.name" placeholder="<%:New input rule%>" />
24                                 </td>
25                                 <td class="cbi-section-table-cell" style="width:110px">
26                                         <select class="cbi-input-select" id="_newopen.proto" name="_newopen.proto">
27                                                 <option value="tcp udp">TCP+UDP</option>
28                                                 <option value="tcp">TCP</option>
29                                                 <option value="udp">UDP</option>
30                                                 <option value="other"><%:Other...%></option>
31                                         </select>
32                                 </td>
33                                 <td class="cbi-section-table-cell" style="width:110px">
34                                         <input type="text" class="cbi-input-text" id="_newopen.extport" name="_newopen.extport" />
35                                 </td>
36                                 <td class="cbi-section-table-cell left">
37                                         <input type="submit" class="cbi-button cbi-button-add" name="_newopen.submit" value="<%:Add%>" />
38                                 </td>
39                         </tr>
40                 </table>
41         <% end %>
42         <% if #zones > 1 then %>
43                 <table class="cbi-section-table" style="margin-left:5px">
44                         <tr class="cbi-section-table-titles">
45                                 <th class="cbi-section-table-cell left" colspan="6"><br /><%:New forward rule%>:</th>
46                         </tr>
47                         <tr class="cbi-section-table-descr">
48                                 <th class="cbi-section-table-cell"><%:Name%></th>
49                                 <th class="cbi-section-table-cell"><%:Source zone%></th>
50                                 <th class="cbi-section-table-cell"><%:Destination zone%></th>
51                                 <th class="cbi-section-table-cell"></th>
52                         </tr>
53                         <tr class="cbi-section-table-row">
54                                 <td class="cbi-section-table-cell" style="width:130px">
55                                         <input type="text" class="cbi-input-text" id="_newfwd.name" name="_newfwd.name" placeholder="<%:New forward rule%>" />
56                                 </td>
57                                 <td class="cbi-section-table-cell" style="width:110px">
58                                         <select class="cbi-input-text" id="_newfwd.src" name="_newfwd.src">
59                                                 <% local k, v; for k, v in ipairs(fw:get_zones()) do -%>
60                                                         <option<%=ifattr(v:name() == "lan", "selected", "selected")%> value="<%=v:name()%>"><%=v:name()%></option>
61                                                 <%- end %>
62                                         </select>
63                                 </td>
64                                 <td class="cbi-section-table-cell" style="width:110px">
65                                         <select class="cbi-input-text" id="_newfwd.dest" name="_newfwd.dest">
66                                                 <% local k, v; for k, v in ipairs(fw:get_zones()) do -%>
67                                                         <option<%=ifattr(v:name() == "wan", "selected", "selected")%> value="<%=v:name()%>"><%=v:name()%></option>
68                                                 <%- end %>
69                                         </select>
70                                 </td>
71                                 <td class="cbi-section-table-cell left">
72                                         <input type="submit" class="cbi-button cbi-button-link" name="_newfwd.submit" value="<%:Add and edit...%>" />
73                                 </td>
74                         </tr>
75                 </table>
76         <% else %>
77                 <input type="submit" class="cbi-button cbi-button-add" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" value="<%:Add%>" />
78         <% end %>
79
80         <% if wz then %>
81                 <script type="text/javascript">//<![CDATA[
82                         cbi_validate_field('_newopen.extport', true, 'list(neg(portrange))');
83                         cbi_bind(document.getElementById('_newopen.extport'), 'blur',
84                                 function() {
85                                         var n = document.getElementById('_newopen.name');
86                                         var p = document.getElementById('_newopen.proto');
87                                         var hints = {
88                                         /*  port    name     0=both, 1=tcp, 2=udp, 3=other */
89                                                 22:   [ 'SSH',   1 ],
90                                                 53:   [ 'DNS',   0 ],
91                                                 80:   [ 'HTTP',  1 ],
92                                                 443:  [ 'HTTPS', 1 ],
93                                         };
94
95                                         if (!this.className.match(/invalid/))
96                                         {
97                                                 var hint = hints[this.value || 0];
98                                                 if (hint)
99                                                 {
100                                                         p.selectedIndex = hint[1];
101
102                                                         if (!n.value)
103                                                                 n.value = hint[0];
104                                                 }
105                                                 else if (!n.value && this.value)
106                                                 {
107                                                         n.value = 'Open' + this.value;
108                                                 }
109                                         }
110                                 });
111
112
113                         cbi_validate_field('cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>', true, 'uciname');
114                 //]]></script>
115         <% end %>
116 </div>