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