2 Copyright
2008-
2009 Steven Barth
<steven@midlink.org
>
3 Copyright
2008-
2015 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"
12 local io = require
"io"
14 local has_ip6tables = fs.access(
"/usr/sbin/ip6tables")
18 mode = luci.dispatcher.context.requestpath
19 mode = tonumber(mode[#mode] ~=
"iptables" and mode[#mode]) or
4
22 local ipt = luci.sys.iptparser.IptParser(mode)
27 return (rowcnt %
2) +
1
30 function link_target(t,c)
31 if ipt:is_custom_target(c) then
32 return '
<a href=
"#rule_%s_%s">%s
</a>' %{ t:lower(), c, c }
37 function link_iface(i)
38 local net = wba.iface_get_network(i)
39 if net and i ~=
"lo" then
40 return '
<a href=
"%s">%s
</a>' %{
41 url(
"admin/network/network", net), i
48 local tables = {
"Filter",
"NAT",
"Mangle",
"Raw" }
50 tables = {
"Filter",
"Mangle",
"Raw" }
51 local ok, lines = pcall(io.lines,
"/proc/net/ip6_tables_names")
56 tables = {
"Filter",
"NAT",
"Mangle",
"Raw" }
65 <style type=
"text/css">
68 text-decoration: underline;
72 <h2 name=
"content"><%:Firewall Status%
></h2>
74 <% if has_ip6tables then %
>
75 <ul class=
"cbi-tabmenu">
76 <li class=
"cbi-tab<%= mode ~= 4 and "-disabled
" %>"><a href=
"<%=url("admin/status/iptables/
4")%>"><%:IPv4 Firewall%
></a></li>
77 <li class=
"cbi-tab<%= mode ~= 6 and "-disabled
" %>"><a href=
"<%=url("admin/status/iptables/
6")%>"><%:IPv6 Firewall%
></a></li>
81 <div class=
"cbi-map" style=
"position: relative">
83 <form method=
"post" action=
"<%=url("admin/status/iptables_action
")%>" style=
"position: absolute; right: 0">
84 <input type=
"hidden" name=
"token" value=
"<%=token%>" />
85 <input type=
"hidden" name=
"family" value=
"<%=mode%>" />
86 <input type=
"submit" class=
"cbi-button" name=
"zero" value=
"<%:Reset Counters%>" />
87 <input type=
"submit" class=
"cbi-button" name=
"restart" value=
"<%:Restart Firewall%>" />
90 <div class=
"cbi-section">
92 <% for _, tbl in ipairs(tables) do chaincnt =
0 %
>
93 <h3><%:Table%
>: <%=tbl%
></h3>
95 <% for _, chain in ipairs(ipt:chains(tbl)) do
97 chaincnt = chaincnt +
1
98 chaininfo = ipt:chain(tbl, chain)
100 <h4 id=
"rule_<%=tbl:lower()%>_<%=chain%>">
101 <%:Chain%
> <em><%=chain%
></em>
102 (<%- if chaininfo.policy then -%
>
103 <%:Policy%
>:
<em><%=chaininfo.policy%
></em>, <%:Packets%
>: <%=chaininfo.packets%
>, <%:Traffic%
>: <%=wba.byte_format(chaininfo.bytes)-%
>
105 <%:References%
>: <%=chaininfo.references-%
>
109 <div class=
"cbi-section-node">
110 <div class=
"table" style=
"font-size:90%">
111 <div class=
"tr table-titles cbi-rowstyle-<%=rowstyle()%>">
112 <div class=
"th hide-xs"><%:Pkts.%
></div>
113 <div class=
"th nowrap"><%:Traffic%
></div>
114 <div class=
"th col-5"><%:Target%
></div>
115 <div class=
"th"><%:Prot.%
></div>
116 <div class=
"th"><%:In%
></div>
117 <div class=
"th"><%:Out%
></div>
118 <div class=
"th"><%:Source%
></div>
119 <div class=
"th"><%:Destination%
></div>
120 <div class=
"th col-9 hide-xs"><%:Options%
></div>
123 <% for _, rule in ipairs(ipt:find({table=tbl, chain=chain})) do %
>
124 <div class=
"tr cbi-rowstyle-<%=rowstyle()%>">
125 <div class=
"td"><%=rule.packets%
></div>
126 <div class=
"td nowrap"><%=wba.byte_format(rule.bytes)%
></div>
127 <div class=
"td col-5"><%=rule.target and link_target(tbl, rule.target) or
"-"%
></div>
128 <div class=
"td"><%=rule.protocol%
></div>
129 <div class=
"td"><%=link_iface(rule.inputif)%
></div>
130 <div class=
"td"><%=link_iface(rule.outputif)%
></div>
131 <div class=
"td"><%=rule.source%
></div>
132 <div class=
"td"><%=rule.destination%
></div>
133 <div class=
"td col-9 hide-xs"><%=#rule.options
> 0 and luci.util.pcdata(table.concat(rule.options,
" ")) or
"-"%
></div>
137 <% if rowcnt ==
1 then %
>
138 <div class=
"tr cbi-rowstyle-<%=rowstyle()%>">
139 <div class=
"td" colspan=
"9"><em><%:No rules in this chain%
></em></div>
146 <% if chaincnt ==
0 then %
>
147 <em><%:No chains in this table%
></em>