2 LuCI - Lua Configuration Interface
3 Copyright
2008-
2009 Steven Barth
<steven@midlink.org
>
4 Copyright
2008-
2011 Jo-Philipp Wich
<xm@subsignal.org
>
6 Licensed under the Apache License, Version
2.0 (the
"License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-
2.0
18 require
"luci.sys.iptparser"
19 local wba = require
"luci.tools.webadmin"
20 local fs = require
"nixio.fs"
22 local has_ip6tables = fs.access(
"/usr/sbin/ip6tables")
26 mode = luci.dispatcher.context.requestpath
27 mode = tonumber(mode[#mode] ~=
"iptables" and mode[#mode]) or
4
30 local ipt = luci.sys.iptparser.IptParser(mode)
35 return (rowcnt %
2) +
1
38 function link_target(t,c)
39 if ipt:is_custom_target(c) then
40 return '
<a href=
"#rule_%s_%s">%s
</a>' %{ t:lower(), c, c }
45 function link_iface(i)
46 local net = wba.iface_get_network(i)
47 if net and i ~=
"lo" then
48 return '
<a href=
"%s">%s
</a>' %{
49 luci.dispatcher.build_url(
"admin",
"network",
"network", net), i
56 local tables = {
"Filter",
"NAT",
"Mangle",
"Raw" }
58 tables = {
"Filter",
"Mangle",
"Raw" }
64 <style type=
"text/css">
67 text-decoration: underline;
71 <h2><a id=
"content" name=
"content"><%:Firewall Status%
></a></h2>
73 <% if has_ip6tables then %
>
74 <ul class=
"cbi-tabmenu">
75 <li class=
"cbi-tab<%= mode ~= 4 and "-disabled
" %>"><a href=
"<%=luci.dispatcher.build_url("admin/status/iptables/
4")%>"><%:IPv4 Firewall%
></a></li>
76 <li class=
"cbi-tab<%= mode ~= 6 and "-disabled
" %>"><a href=
"<%=luci.dispatcher.build_url("admin/status/iptables/
6")%>"><%:IPv6 Firewall%
></a></li>
80 <form method=
"post" action=
"<%=REQUEST_URI%>">
82 <fieldset class=
"cbi-section">
85 <li><a href=
"<%=REQUEST_URI%>?zero=<%=mode%>"><%:Reset Counters%
></a></li>
86 <li><a href=
"<%=REQUEST_URI%>?restart=1"><%:Restart Firewall%
></a></li>
90 <% for _, tbl in ipairs(tables) do chaincnt =
0 %
>
91 <h3><%:Table%
>: <%=tbl%
></h3>
92 <table class=
"cbi-section-table" style=
"font-size:90%">
93 <% for _, chain in ipairs(ipt:chains(tbl)) do
95 chaincnt = chaincnt +
1
96 chaininfo = ipt:chain(tbl, chain)
98 <tr class=
"cbi-section-table-titles cbi-rowstyle-<%=rowstyle()%>">
99 <th class=
"cbi-section-table-cell" style=
"text-align:left" colspan=
"11">
100 <br /><span 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 <tr class=
"cbi-section-table-descr">
110 <th class=
"cbi-section-table-cell"><%:Rule #%
></th>
111 <th class=
"cbi-section-table-cell"><%:Pkts.%
></th>
112 <th class=
"cbi-section-table-cell"><%:Traffic%
></th>
113 <th class=
"cbi-section-table-cell"><%:Target%
></th>
114 <th class=
"cbi-section-table-cell"><%:Prot.%
></th>
115 <th class=
"cbi-section-table-cell"><%:Flags%
></th>
116 <th class=
"cbi-section-table-cell"><%:In%
></th>
117 <th class=
"cbi-section-table-cell"><%:Out%
></th>
118 <th class=
"cbi-section-table-cell"><%:Source%
></th>
119 <th class=
"cbi-section-table-cell"><%:Destination%
></th>
120 <th class=
"cbi-section-table-cell" style=
"width:30%"><%:Options%
></th>
123 <% for _, rule in ipairs(ipt:find({table=tbl, chain=chain})) do %
>
124 <tr class=
"cbi-section-table-row cbi-rowstyle-<%=rowstyle()%>">
125 <td><%=rule.index%
></td>
126 <td><%=rule.packets%
></td>
127 <td><%=wba.byte_format(rule.bytes)%
></td>
128 <td><%=rule.target and link_target(tbl, rule.target) or
"-"%
></td>
129 <td><%=rule.protocol%
></td>
130 <td><%=rule.flags%
></td>
131 <td><%=link_iface(rule.inputif)%
></td>
132 <td><%=link_iface(rule.outputif)%
></td>
133 <td><%=rule.source%
></td>
134 <td><%=rule.destination%
></td>
135 <td style=
"width:30%"><small><%=#rule.options
> 0 and luci.util.pcdata(table.concat(rule.options,
" ")) or
"-"%
></small></td>
139 <% if rowcnt ==
1 then %
>
140 <tr class=
"cbi-section-table-titles cbi-rowstyle-<%=rowstyle()%>">
141 <td colspan=
"11"><em><%:No rules in this chain%
></em></td>
146 <% if chaincnt ==
0 then %
>
147 <tr class=
"cbi-section-table-titles cbi-rowstyle-<%=rowstyle()%>">
148 <td colspan=
"11"><em><%:No chains in this table%
></em></td>