luci-mod-admin-full: switch to nixio.fs
[project/luci.git] / modules / luci-mod-admin-full / luasrc / view / admin_status / iptables.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2008-2009 Steven Barth <steven@midlink.org>
4 Copyright 2008-2011 Jo-Philipp Wich <xm@subsignal.org>
5
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
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13
14 -%>
15
16 <%-
17
18 require "luci.sys.iptparser"
19 local wba = require "luci.tools.webadmin"
20 local fs = require "nixio.fs"
21
22 local has_ip6tables = fs.access("/usr/sbin/ip6tables")
23 local mode = 4
24
25 if has_ip6tables then
26 mode = luci.dispatcher.context.requestpath
27 mode = tonumber(mode[#mode] ~= "iptables" and mode[#mode]) or 4
28 end
29
30 local ipt = luci.sys.iptparser.IptParser(mode)
31
32 local rowcnt = 1
33 function rowstyle()
34 rowcnt = rowcnt + 1
35 return (rowcnt % 2) + 1
36 end
37
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 }
41 end
42 return c
43 end
44
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
50 }
51
52 end
53 return i
54 end
55
56 local tables = { "Filter", "NAT", "Mangle", "Raw" }
57 if mode == 6 then
58 tables = { "Filter", "Mangle", "Raw" }
59 end
60 -%>
61
62 <%+header%>
63
64 <style type="text/css">
65 span:target {
66 color: blue;
67 text-decoration: underline;
68 }
69 </style>
70
71 <h2><a id="content" name="content"><%:Firewall Status%></a></h2>
72
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>
77 </ul>
78 <% end %>
79
80 <form method="post" action="<%=REQUEST_URI%>">
81 <div class="cbi-map">
82 <fieldset class="cbi-section">
83 <h3><%:Actions%></h3>
84 <ul>
85 <li><a href="<%=REQUEST_URI%>?zero=<%=mode%>"><%:Reset Counters%></a></li>
86 <li><a href="<%=REQUEST_URI%>?restart=1"><%:Restart Firewall%></a></li>
87 </ul>
88 <br /><br />
89
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
94 rowcnt = 0
95 chaincnt = chaincnt + 1
96 chaininfo = ipt:chain(tbl, chain)
97 %>
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)-%>
104 <%- else -%>
105 <%:References%>: <%=chaininfo.references-%>
106 <%- end -%>)</span>
107 </th>
108 </tr>
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>
121 </tr>
122
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>
136 </tr>
137 <% end %>
138
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>
142 </tr>
143 <% end %>
144 <% end %>
145
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>
149 </tr>
150 <% end %>
151 </table>
152 <br /><br />
153 <% end %>
154 </fieldset>
155 </div>
156 </form>
157
158 <%+footer%>