Update my email addresses in the license headers
[project/luci.git] / modules / luci-mod-admin-full / luasrc / view / admin_status / iptables.htm
1 <%#
2 Copyright 2008-2009 Steven Barth <steven@midlink.org>
3 Copyright 2008-2011 Jo-Philipp Wich <jow@openwrt.org>
4 Licensed to the public under the Apache License 2.0.
5 -%>
6
7 <%-
8
9 require "luci.sys.iptparser"
10 local wba = require "luci.tools.webadmin"
11 local fs = require "nixio.fs"
12
13 local has_ip6tables = fs.access("/usr/sbin/ip6tables")
14 local mode = 4
15
16 if has_ip6tables then
17 mode = luci.dispatcher.context.requestpath
18 mode = tonumber(mode[#mode] ~= "iptables" and mode[#mode]) or 4
19 end
20
21 local ipt = luci.sys.iptparser.IptParser(mode)
22
23 local rowcnt = 1
24 function rowstyle()
25 rowcnt = rowcnt + 1
26 return (rowcnt % 2) + 1
27 end
28
29 function link_target(t,c)
30 if ipt:is_custom_target(c) then
31 return '<a href="#rule_%s_%s">%s</a>' %{ t:lower(), c, c }
32 end
33 return c
34 end
35
36 function link_iface(i)
37 local net = wba.iface_get_network(i)
38 if net and i ~= "lo" then
39 return '<a href="%s">%s</a>' %{
40 luci.dispatcher.build_url("admin", "network", "network", net), i
41 }
42
43 end
44 return i
45 end
46
47 local tables = { "Filter", "NAT", "Mangle", "Raw" }
48 if mode == 6 then
49 tables = { "Filter", "Mangle", "Raw" }
50 end
51 -%>
52
53 <%+header%>
54
55 <style type="text/css">
56 span:target {
57 color: blue;
58 text-decoration: underline;
59 }
60 </style>
61
62 <h2><a id="content" name="content"><%:Firewall Status%></a></h2>
63
64 <% if has_ip6tables then %>
65 <ul class="cbi-tabmenu">
66 <li class="cbi-tab<%= mode ~= 4 and "-disabled" %>"><a href="<%=luci.dispatcher.build_url("admin/status/iptables/4")%>"><%:IPv4 Firewall%></a></li>
67 <li class="cbi-tab<%= mode ~= 6 and "-disabled" %>"><a href="<%=luci.dispatcher.build_url("admin/status/iptables/6")%>"><%:IPv6 Firewall%></a></li>
68 </ul>
69 <% end %>
70
71 <form method="post" action="<%=REQUEST_URI%>">
72 <div class="cbi-map">
73 <fieldset class="cbi-section">
74 <h3><%:Actions%></h3>
75 <ul>
76 <li><a href="<%=REQUEST_URI%>?zero=<%=mode%>"><%:Reset Counters%></a></li>
77 <li><a href="<%=REQUEST_URI%>?restart=1"><%:Restart Firewall%></a></li>
78 </ul>
79 <br /><br />
80
81 <% for _, tbl in ipairs(tables) do chaincnt = 0 %>
82 <h3><%:Table%>: <%=tbl%></h3>
83 <table class="cbi-section-table" style="font-size:90%">
84 <% for _, chain in ipairs(ipt:chains(tbl)) do
85 rowcnt = 0
86 chaincnt = chaincnt + 1
87 chaininfo = ipt:chain(tbl, chain)
88 %>
89 <tr class="cbi-section-table-titles cbi-rowstyle-<%=rowstyle()%>">
90 <th class="cbi-section-table-cell" style="text-align:left" colspan="11">
91 <br /><span id="rule_<%=tbl:lower()%>_<%=chain%>">
92 <%:Chain%> <em><%=chain%></em>
93 (<%- if chaininfo.policy then -%>
94 <%:Policy%>: <em><%=chaininfo.policy%></em>, <%:Packets%>: <%=chaininfo.packets%>, <%:Traffic%>: <%=wba.byte_format(chaininfo.bytes)-%>
95 <%- else -%>
96 <%:References%>: <%=chaininfo.references-%>
97 <%- end -%>)</span>
98 </th>
99 </tr>
100 <tr class="cbi-section-table-descr">
101 <th class="cbi-section-table-cell"><%:Rule #%></th>
102 <th class="cbi-section-table-cell"><%:Pkts.%></th>
103 <th class="cbi-section-table-cell"><%:Traffic%></th>
104 <th class="cbi-section-table-cell"><%:Target%></th>
105 <th class="cbi-section-table-cell"><%:Prot.%></th>
106 <th class="cbi-section-table-cell"><%:Flags%></th>
107 <th class="cbi-section-table-cell"><%:In%></th>
108 <th class="cbi-section-table-cell"><%:Out%></th>
109 <th class="cbi-section-table-cell"><%:Source%></th>
110 <th class="cbi-section-table-cell"><%:Destination%></th>
111 <th class="cbi-section-table-cell" style="width:30%"><%:Options%></th>
112 </tr>
113
114 <% for _, rule in ipairs(ipt:find({table=tbl, chain=chain})) do %>
115 <tr class="cbi-section-table-row cbi-rowstyle-<%=rowstyle()%>">
116 <td><%=rule.index%></td>
117 <td><%=rule.packets%></td>
118 <td><%=wba.byte_format(rule.bytes)%></td>
119 <td><%=rule.target and link_target(tbl, rule.target) or "-"%></td>
120 <td><%=rule.protocol%></td>
121 <td><%=rule.flags%></td>
122 <td><%=link_iface(rule.inputif)%></td>
123 <td><%=link_iface(rule.outputif)%></td>
124 <td><%=rule.source%></td>
125 <td><%=rule.destination%></td>
126 <td style="width:30%"><small><%=#rule.options > 0 and luci.util.pcdata(table.concat(rule.options, " ")) or "-"%></small></td>
127 </tr>
128 <% end %>
129
130 <% if rowcnt == 1 then %>
131 <tr class="cbi-section-table-titles cbi-rowstyle-<%=rowstyle()%>">
132 <td colspan="11"><em><%:No rules in this chain%></em></td>
133 </tr>
134 <% end %>
135 <% end %>
136
137 <% if chaincnt == 0 then %>
138 <tr class="cbi-section-table-titles cbi-rowstyle-<%=rowstyle()%>">
139 <td colspan="11"><em><%:No chains in this table%></em></td>
140 </tr>
141 <% end %>
142 </table>
143 <br /><br />
144 <% end %>
145 </fieldset>
146 </div>
147 </form>
148
149 <%+footer%>