luci-app-olsr: handle empty result for non-status tables
[oweals/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
22 <h4><%:New port forward%></h4>
23 <div class="table">
24         <div class="tr table-titles">
25                 <div class="th"><%:Name%></div>
26                 <div class="th"><%:Protocol%></div>
27                 <div class="th"><%:External zone%></div>
28                 <div class="th"><%:External port%></div>
29                 <div class="th"><%:Internal zone%></div>
30                 <div class="th"><%:Internal IP address%></div>
31                 <div class="th"><%:Internal port%></div>
32                 <div class="th"></div>
33         </div>
34         <div class="tr">
35                 <div class="td">
36                         <input type="text" class="cbi-input-text" id="_newfwd.name" name="_newfwd.name" placeholder="<%:New port forward%>" />
37                 </div>
38                 <div class="td">
39                         <select class="cbi-input-select" id="_newfwd.proto" name="_newfwd.proto">
40                                 <option value="tcp udp">TCP+UDP</option>
41                                 <option value="tcp">TCP</option>
42                                 <option value="udp">UDP</option>
43                                 <option value="other"><%:Other...%></option>
44                         </select>
45                 </div>
46                 <div class="td">
47                         <select class="cbi-input-select" id="_newfwd.extzone" name="_newfwd.extzone">
48                                 <% for _, z in ipairs(ezl) do -%><option value="<%=z:name()%>"><%=z:name()%></option><%- end %>
49                         </select>
50                 </div>
51                 <div class="td">
52                         <input type="text" class="cbi-input-text" id="_newfwd.extport" name="_newfwd.extport" data-type="portrange" data-optional="true" />
53                 </div>
54                 <div class="td">
55                         <select class="cbi-input-select" id="_newfwd.intzone" name="_newfwd.intzone">
56                                 <% for _, z in ipairs(izl) do -%><option value="<%=z:name()%>"><%=z:name()%></option><%- end %>
57                         </select>
58                 </div>
59                 <div class="td">
60                         <input type="text" class="cbi-input-text" id="_newfwd.intaddr" name="_newfwd.intaddr" data-type="host" data-optional="true"<%=
61                                 ifattr(#keys > 0, "data-choices", {keys, vals})
62                         %>/>
63                 </div>
64                 <div class="td">
65                         <input type="text" class="cbi-input-text" id="_newfwd.intport" name="_newfwd.intport" data-type="portrange" data-optional="true" />
66                 </div>
67                 <div class="td bottom">
68                         <input type="submit" class="cbi-button cbi-button-add" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.<%=section%>" value="<%:Add%>" />
69                 </div>
70         </div>
71 </div>
72
73 <script type="text/javascript">//<![CDATA[
74         document.getElementById('_newfwd.extport').addEventListener('blur',
75                 function() {
76                         var n = document.getElementById('_newfwd.name');
77                         var p = document.getElementById('_newfwd.proto');
78                         var i = document.getElementById('_newfwd.intport');
79
80                         if (!this.className.match(/invalid/))
81                         {
82                                 if (!i.value) i.value = this.value;
83
84                                 if (!n.value)
85                                 {
86                                         n.value = 'Forward' + this.value;
87                                 }
88                         }
89                 });
90 //]]></script>