luci-app-firewall: rework internal/external zone list handling when adding forwards
[project/luci.git] / applications / luci-app-firewall / luasrc / view / firewall / cbi_addforward.htm
1 <%-
2         local fw = require "luci.model.firewall".init()
3         local izl = { }
4         local ezl = { }
5         local _, z
6         for _, z in ipairs(fw:get_zones()) do
7                 if z:name() ~= "wan" then
8                         izl[#izl+1] = z
9                 end
10                 if z:name() ~= "lan" then
11                         ezl[#ezl+1] = z
12                 end
13         end
14 -%>
15 <div class="cbi-section-create cbi-tblsection-create">
16         <br />
17         <table class="cbi-section-table" style="width:810px; margin-left:5px">
18                 <tr class="cbi-section-table-titles">
19                         <th class="cbi-section-table-cell" colspan="8"><%:New port forward%>:</th>
20                 </tr>
21                 <tr class="cbi-section-table-descr">
22                         <th class="cbi-section-table-cell"><%:Name%></th>
23                         <th class="cbi-section-table-cell"><%:Protocol%></th>
24                         <th class="cbi-section-table-cell"><%:External zone%></th>
25                         <th class="cbi-section-table-cell"><%:External port%></th>
26                         <th class="cbi-section-table-cell"><%:Internal zone%></th>
27                         <th class="cbi-section-table-cell"><%:Internal IP address%></th>
28                         <th class="cbi-section-table-cell"><%:Internal 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="_newfwd.name" name="_newfwd.name" placeholder="<%:New port forward%>" />
34                         </td>
35                         <td class="cbi-section-table-cell" style="width:110px">
36                                 <select class="cbi-input-select" id="_newfwd.proto" name="_newfwd.proto">
37                                         <option value="tcp udp">TCP+UDP</option>
38                                         <option value="tcp">TCP</option>
39                                         <option value="udp">UDP</option>
40                                         <option value="other"><%:Other...%></option>
41                                 </select>
42                         </td>
43                         <td class="cbi-section-table-cell" style="width:55px">
44                                 <select class="cbi-input-select" id="_newfwd.extzone" name="_newfwd.extzone">
45                                         <% for _, z in ipairs(ezl) do -%><option value="<%=z:name()%>"><%=z:name()%></option><%- end %>
46                                 </select>
47                         </td>
48                         <td class="cbi-section-table-cell" style="width:110px">
49                                 <input type="text" class="cbi-input-text" id="_newfwd.extport" name="_newfwd.extport" />
50                         </td>
51                         <td class="cbi-section-table-cell" style="width:55px">
52                                 <select class="cbi-input-select" id="_newfwd.intzone" name="_newfwd.intzone">
53                                         <% for _, z in ipairs(izl) do -%><option value="<%=z:name()%>"><%=z:name()%></option><%- end %>
54                                 </select>
55                         </td>
56                         <td class="cbi-section-table-cell" style="width:110px">
57                                 <input type="text" class="cbi-input-text" id="_newfwd.intaddr" name="_newfwd.intaddr" />
58                         </td>
59                         <td class="cbi-section-table-cell" style="width:110px">
60                                 <input type="text" class="cbi-input-text" id="_newfwd.intport" name="_newfwd.intport" />
61                         </td>
62                         <td class="cbi-section-table-cell">
63                                 <input type="submit" class="cbi-button cbi-button-add" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" value="<%:Add%>" />
64                         </td>
65                 </tr>
66         </table>
67
68         <script type="text/javascript">//<![CDATA[
69                 cbi_validate_field('_newfwd.extport', true, 'portrange');
70                 cbi_validate_field('_newfwd.intaddr', true, 'host');
71                 cbi_validate_field('_newfwd.intport', true, 'portrange');
72
73                 cbi_combobox_init('_newfwd.intaddr', {
74                         <% first = true; luci.sys.net.ipv4_hints(function(ip, name) %>
75                                 <%- if first then first = false else %>,<% end -%>'<%=ip%>': '<%=ip%> (<%=name%>)'
76                         <%- end) %> }, '', '<%: -- custom -- %>');
77
78                 cbi_bind(document.getElementById('_newfwd.extport'), 'blur',
79                         function() {
80                                 var n = document.getElementById('_newfwd.name');
81                                 var p = document.getElementById('_newfwd.proto');
82                                 var i = document.getElementById('_newfwd.intport');
83                                 var hints = {
84                                 /*  port    name     0=both, 1=tcp, 2=udp, 3=other */
85                                         21:   [ 'FTP',   1 ],
86                                         22:   [ 'SSH',   1 ],
87                                         53:   [ 'DNS',   0 ],
88                                         80:   [ 'HTTP',  1 ],
89                                         443:  [ 'HTTPS', 1 ],
90                                         3389: [ 'RDP',   1 ],
91                                         5900: [ 'VNC',   1 ],
92                                 };
93
94                                 if (!this.className.match(/invalid/))
95                                 {
96                                         if (!i.value) i.value = this.value;
97
98                                         var hint = hints[this.value || 0] || hints[i.value || 0];
99                                         if (hint)
100                                         {
101                                                 p.selectedIndex = hint[1];
102
103                                                 if (!n.value)
104                                                         n.value = hint[0];
105                                         }
106                                         else if (!n.value)
107                                         {
108                                                 n.value = 'Forward' + this.value;
109                                         }
110                                 }
111                         });
112
113
114                 cbi_validate_field('cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>', true, 'uciname');
115         //]]></script>
116 </div>