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