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 require
"luci.tools.webadmin"
22 local has_ip6tables = luci.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)
31 local wba = luci.tools.webadmin
36 return (rowcnt %
2) +
1
39 function link_target(t,c)
40 if ipt:is_custom_target(c) then
41 return '
<a href=
"#rule_%s_%s">%s
</a>' %{ t:lower(), c, c }
46 function link_iface(i)
47 local net = wba.iface_get_network(i)
48 if net and i ~=
"lo" then
49 return '
<a href=
"%s">%s
</a>' %{
50 luci.dispatcher.build_url(
"admin",
"network",
"network", net), i
57 local tables = {
"Filter",
"NAT",
"Mangle",
"Raw" }
59 tables = {
"Filter",
"Mangle",
"Raw" }
65 <style type=
"text/css">
68 text-decoration: underline;
72 <h2><a id=
"content" name=
"content"><%:Firewall Status%
></a></h2>
74 <% if has_ip6tables then %
>
75 <ul class=
"cbi-tabmenu">
76 <li class=
"cbi-tab<%= mode ~= 4 and "-disabled
" %>"><a href=
"<%=luci.dispatcher.build_url("admin/status/iptables/
4")%>"><%:IPv4 Firewall%
></a></li>
77 <li class=
"cbi-tab<%= mode ~= 6 and "-disabled
" %>"><a href=
"<%=luci.dispatcher.build_url("admin/status/iptables/
6")%>"><%:IPv6 Firewall%
></a></li>
81 <form method=
"post" action=
"<%=REQUEST_URI%>">
83 <fieldset class=
"cbi-section">
86 <li><a href=
"<%=REQUEST_URI%>?zero=<%=mode%>"><%:Reset Counters%
></a></li>
87 <li><a href=
"<%=REQUEST_URI%>?restart=1"><%:Restart Firewall%
></a></li>
91 <% for _, tbl in ipairs(tables) do chaincnt =
0 %
>
92 <h3><%:Table%
>: <%=tbl%
></h3>
93 <table class=
"cbi-section-table" style=
"font-size:90%">
94 <% for _, chain in ipairs(ipt:chains(tbl)) do
96 chaincnt = chaincnt +
1
97 chaininfo = ipt:chain(tbl, chain)
99 <tr class=
"cbi-section-table-titles cbi-rowstyle-<%=rowstyle()%>">
100 <th class=
"cbi-section-table-cell" style=
"text-align:left" colspan=
"11">
101 <br /><span id=
"rule_<%=tbl:lower()%>_<%=chain%>">
102 <%:Chain%
> <em><%=chain%
></em>
103 (<%- if chaininfo.policy then -%
>
104 <%:Policy%
>:
<em><%=chaininfo.policy%
></em>, <%:Packets%
>: <%=chaininfo.packets%
>, <%:Traffic%
>: <%=wba.byte_format(chaininfo.bytes)-%
>
106 <%:References%
>: <%=chaininfo.references-%
>
110 <tr class=
"cbi-section-table-descr">
111 <th class=
"cbi-section-table-cell"><%:Rule #%
></th>
112 <th class=
"cbi-section-table-cell"><%:Pkts.%
></th>
113 <th class=
"cbi-section-table-cell"><%:Traffic%
></th>
114 <th class=
"cbi-section-table-cell"><%:Target%
></th>
115 <th class=
"cbi-section-table-cell"><%:Prot.%
></th>
116 <th class=
"cbi-section-table-cell"><%:Flags%
></th>
117 <th class=
"cbi-section-table-cell"><%:In%
></th>
118 <th class=
"cbi-section-table-cell"><%:Out%
></th>
119 <th class=
"cbi-section-table-cell"><%:Source%
></th>
120 <th class=
"cbi-section-table-cell"><%:Destination%
></th>
121 <th class=
"cbi-section-table-cell" style=
"width:30%"><%:Options%
></th>
124 <% for _, rule in ipairs(ipt:find({table=tbl, chain=chain})) do %
>
125 <tr class=
"cbi-section-table-row cbi-rowstyle-<%=rowstyle()%>">
126 <td><%=rule.index%
></td>
127 <td><%=rule.packets%
></td>
128 <td><%=wba.byte_format(rule.bytes)%
></td>
129 <td><%=rule.target and link_target(tbl, rule.target) or
"-"%
></td>
130 <td><%=rule.protocol%
></td>
131 <td><%=rule.flags%
></td>
132 <td><%=link_iface(rule.inputif)%
></td>
133 <td><%=link_iface(rule.outputif)%
></td>
134 <td><%=rule.source%
></td>
135 <td><%=rule.destination%
></td>
136 <td style=
"width:30%"><small><%=#rule.options
> 0 and luci.util.pcdata(table.concat(rule.options,
" ")) or
"-"%
></small></td>
140 <% if rowcnt ==
1 then %
>
141 <tr class=
"cbi-section-table-titles cbi-rowstyle-<%=rowstyle()%>">
142 <td colspan=
"11"><em><%:No rules in this chain%
></em></td>
147 <% if chaincnt ==
0 then %
>
148 <tr class=
"cbi-section-table-titles cbi-rowstyle-<%=rowstyle()%>">
149 <td colspan=
"11"><em><%:No chains in this table%
></em></td>