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"
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 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>
65 <% if has_ip6tables then %>
66 <ul class="cbi-tabmenu">
67 <li class="cbi-tab<%= mode ~= 4 and "-disabled" %>"><a href="<%=url("admin/status/iptables/4")%>"><%:IPv4 Firewall%></a></li>
68 <li class="cbi-tab<%= mode ~= 6 and "-disabled" %>"><a href="<%=url("admin/status/iptables/6")%>"><%:IPv6 Firewall%></a></li>
72 <div class="cbi-map" style="position: relative">
74 <form method="post" action="<%=url("admin/status/iptables_action")%>" style="position: absolute; right: 0">
75 <input type="hidden" name="token" value="<%=token%>" />
76 <input type="hidden" name="family" value="<%=mode%>" />
77 <input type="submit" class="cbi-button" name="zero" value="<%:Reset Counters%>" />
78 <input type="submit" class="cbi-button" name="restart" value="<%:Restart Firewall%>" />
81 <fieldset class="cbi-section">
83 <% for _, tbl in ipairs(tables) do chaincnt = 0 %>
84 <h3><%:Table%>: <%=tbl%></h3>
85 <table class="cbi-section-table" style="font-size:90%">
86 <% for _, chain in ipairs(ipt:chains(tbl)) do
88 chaincnt = chaincnt + 1
89 chaininfo = ipt:chain(tbl, chain)
91 <tr class="cbi-section-table-titles cbi-rowstyle-<%=rowstyle()%>">
92 <th class="cbi-section-table-cell" style="text-align:left" colspan="11">
93 <br /><span id="rule_<%=tbl:lower()%>_<%=chain%>">
94 <%:Chain%> <em><%=chain%></em>
95 (<%- if chaininfo.policy then -%>
96 <%:Policy%>: <em><%=chaininfo.policy%></em>, <%:Packets%>: <%=chaininfo.packets%>, <%:Traffic%>: <%=wba.byte_format(chaininfo.bytes)-%>
98 <%:References%>: <%=chaininfo.references-%>
102 <tr class="cbi-section-table-descr">
103 <th class="cbi-section-table-cell"><%:Pkts.%></th>
104 <th class="cbi-section-table-cell"><%:Traffic%></th>
105 <th class="cbi-section-table-cell"><%:Target%></th>
106 <th class="cbi-section-table-cell"><%:Prot.%></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.packets%></td>
117 <td style="white-space: nowrap"><%=wba.byte_format(rule.bytes)%></td>
118 <td><%=rule.target and link_target(tbl, rule.target) or "-"%></td>
119 <td><%=rule.protocol%></td>
120 <td><%=link_iface(rule.inputif)%></td>
121 <td><%=link_iface(rule.outputif)%></td>
122 <td><%=rule.source%></td>
123 <td><%=rule.destination%></td>
124 <td style="width:30%"><small><%=#rule.options > 0 and luci.util.pcdata(table.concat(rule.options, " ")) or "-"%></small></td>
128 <% if rowcnt == 1 then %>
129 <tr class="cbi-section-table-titles cbi-rowstyle-<%=rowstyle()%>">
130 <td colspan="9"><em><%:No rules in this chain%></em></td>
135 <% if chaincnt == 0 then %>
136 <tr class="cbi-section-table-titles cbi-rowstyle-<%=rowstyle()%>">
137 <td colspan="9"><em><%:No chains in this table%></em></td>