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.
9 require
"luci.sys.iptparser"
10 local wba = require
"luci.tools.webadmin"
11 local fs = require
"nixio.fs"
13 local has_ip6tables = fs.access(
"/usr/sbin/ip6tables")
17 mode = luci.dispatcher.context.requestpath
18 mode = tonumber(mode[#mode] ~=
"iptables" and mode[#mode]) or
4
21 local ipt = luci.sys.iptparser.IptParser(mode)
26 return (rowcnt %
2) +
1
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 }
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
47 local tables = {
"Filter",
"NAT",
"Mangle",
"Raw" }
49 tables = {
"Filter",
"Mangle",
"Raw" }
55 <style type=
"text/css">
58 text-decoration: underline;
62 <h2 name=
"content"><%:Firewall Status%
></h2>
64 <% if has_ip6tables then %
>
65 <ul class=
"cbi-tabmenu">
66 <li class=
"cbi-tab<%= mode ~= 4 and "-disabled
" %>"><a href=
"<%=url("admin/status/iptables/
4")%>"><%:IPv4 Firewall%
></a></li>
67 <li class=
"cbi-tab<%= mode ~= 6 and "-disabled
" %>"><a href=
"<%=url("admin/status/iptables/
6")%>"><%:IPv6 Firewall%
></a></li>
71 <form method=
"post" action=
"<%=REQUEST_URI%>">
73 <fieldset class=
"cbi-section">
76 <li><a href=
"<%=REQUEST_URI%>?zero=<%=mode%>"><%:Reset Counters%
></a></li>
77 <li><a href=
"<%=REQUEST_URI%>?restart=1"><%:Restart Firewall%
></a></li>
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
86 chaincnt = chaincnt +
1
87 chaininfo = ipt:chain(tbl, chain)
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)-%
>
96 <%:References%
>: <%=chaininfo.references-%
>
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>
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>
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>
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>