luci-app-firewall: align custom cbi teplates with new code
[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         local keys, vals = { }, { }
16         luci.sys.net.ipv4_hints(function(ip, name)
17                 keys[#keys+1] = ip
18                 vals[#vals+1] = '%s (%s)' %{ ip, name }
19         end)
20 -%>
21 <div class="cbi-section-create cbi-tblsection-create">
22         <br />
23         <table class="cbi-section-table" style="width:810px; margin-left:5px">
24                 <tr class="cbi-section-table-titles">
25                         <th class="cbi-section-table-cell" colspan="8"><%:New port forward%>:</th>
26                 </tr>
27                 <tr class="cbi-section-table-descr">
28                         <th class="cbi-section-table-cell"><%:Name%></th>
29                         <th class="cbi-section-table-cell"><%:Protocol%></th>
30                         <th class="cbi-section-table-cell"><%:External zone%></th>
31                         <th class="cbi-section-table-cell"><%:External port%></th>
32                         <th class="cbi-section-table-cell"><%:Internal zone%></th>
33                         <th class="cbi-section-table-cell"><%:Internal IP address%></th>
34                         <th class="cbi-section-table-cell"><%:Internal port%></th>
35                         <th class="cbi-section-table-cell"></th>
36                 </tr>
37                 <tr class="cbi-section-table-row">
38                         <td class="cbi-section-table-cell">
39                                 <input type="text" class="cbi-input-text" id="_newfwd.name" name="_newfwd.name" placeholder="<%:New port forward%>" />
40                         </td>
41                         <td class="cbi-section-table-cell" style="width:110px">
42                                 <select class="cbi-input-select" id="_newfwd.proto" name="_newfwd.proto">
43                                         <option value="tcp udp">TCP+UDP</option>
44                                         <option value="tcp">TCP</option>
45                                         <option value="udp">UDP</option>
46                                         <option value="other"><%:Other...%></option>
47                                 </select>
48                         </td>
49                         <td class="cbi-section-table-cell" style="width:55px">
50                                 <select class="cbi-input-select" id="_newfwd.extzone" name="_newfwd.extzone">
51                                         <% for _, z in ipairs(ezl) do -%><option value="<%=z:name()%>"><%=z:name()%></option><%- end %>
52                                 </select>
53                         </td>
54                         <td class="cbi-section-table-cell" style="width:110px">
55                                 <input type="text" class="cbi-input-text" id="_newfwd.extport" name="_newfwd.extport" data-type="portrange" data-optional="true" />
56                         </td>
57                         <td class="cbi-section-table-cell" style="width:55px">
58                                 <select class="cbi-input-select" id="_newfwd.intzone" name="_newfwd.intzone">
59                                         <% for _, z in ipairs(izl) do -%><option value="<%=z:name()%>"><%=z:name()%></option><%- end %>
60                                 </select>
61                         </td>
62                         <td class="cbi-section-table-cell" style="width:110px">
63                                 <input type="text" class="cbi-input-text" id="_newfwd.intaddr" name="_newfwd.intaddr" data-type="host" data-optional="true"<%=
64                                         ifattr(#keys > 0, "data-choices", luci.util.serialize_json({keys, vals}))
65                                 %>/>
66                         </td>
67                         <td class="cbi-section-table-cell" style="width:110px">
68                                 <input type="text" class="cbi-input-text" id="_newfwd.intport" name="_newfwd.intport" data-type="portrange" data-optional="true" />
69                         </td>
70                         <td class="cbi-section-table-cell">
71                                 <input type="submit" class="cbi-button cbi-button-add" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" value="<%:Add%>" />
72                         </td>
73                 </tr>
74         </table>
75
76         <script type="text/javascript">//<![CDATA[
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         //]]></script>
112 </div>