summaryrefslogtreecommitdiffhomepage
path: root/modules/admin-full/luasrc/view/admin_status/iptables.htm
blob: 957604e8af8bef10d2203eecf7dff10b1be3fb33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<%#
LuCI - Lua Configuration Interface
Copyright 2008-2009 Steven Barth <steven@midlink.org>
Copyright 2008-2011 Jo-Philipp Wich <xm@subsignal.org>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

$Id$

-%>

<%-

	require "luci.sys.iptparser"
	require "luci.tools.webadmin"
	require "luci.fs"

	local has_ip6tables = luci.fs.access("/usr/sbin/ip6tables")
	local mode = 4

	if has_ip6tables then
		mode = luci.dispatcher.context.requestpath
	    mode = tonumber(mode[#mode] ~= "iptables" and mode[#mode]) or 4
	end

	local ipt = luci.sys.iptparser.IptParser(mode)
	local wba = luci.tools.webadmin

	local rowcnt = 1
	function rowstyle()
		rowcnt = rowcnt + 1
		return (rowcnt % 2) + 1
	end

	function link_target(t,c)
		if ipt:is_custom_target(c) then
			return '<a href="#rule_%s_%s">%s</a>' %{ t:lower(), c, c }
		end
		return c
	end

	function link_iface(i)
		local net = wba.iface_get_network(i)
		if net and i ~= "lo" then
			return '<a href="%s">%s</a>' %{
				luci.dispatcher.build_url("admin", "network", "network", net), i
			}

		end
		return i
	end

	local tables = { "Filter", "NAT", "Mangle", "Raw" }
	if mode == 6 then
		tables = { "Filter", "Mangle", "Raw" }
	end
-%>

<%+header%>

<style type="text/css">
	span:target {
		color: blue;
		text-decoration: underline;
	}
</style>

<h2><a id="content" name="content"><%:Firewall Status%></a></h2>

<% if has_ip6tables then %>
<ul class="cbi-tabmenu">
	<li class="cbi-tab<%= mode ~= 4 and "-disabled" %>"><a href="<%=luci.dispatcher.build_url("admin/status/iptables/4")%>"><%:IPv4 Firewall%></a></li>
	<li class="cbi-tab<%= mode ~= 6 and "-disabled" %>"><a href="<%=luci.dispatcher.build_url("admin/status/iptables/6")%>"><%:IPv6 Firewall%></a></li>
</ul>
<% end %>

<form method="post" action="<%=REQUEST_URI%>">
	<div class="cbi-map">
		<fieldset class="cbi-section">
			<h3><%:Actions%></h3>
			<ul>
				<li><a href="<%=REQUEST_URI%>?zero=<%=mode%>"><%:Reset Counters%></a></li>
				<li><a href="<%=REQUEST_URI%>?restart=1"><%:Restart Firewall%></a></li>
			</ul>
			<br /><br />

			<% for _, tbl in ipairs(tables) do chaincnt = 0 %>
				<h3><%:Table%>: <%=tbl%></h3>
				<table class="cbi-section-table" style="font-size:90%">
					<% for _, chain in ipairs(ipt:chains(tbl)) do
						rowcnt    = 0
						chaincnt  = chaincnt + 1
						chaininfo = ipt:chain(tbl, chain)
					%>
						<tr class="cbi-section-table-titles cbi-rowstyle-<%=rowstyle()%>">
							<th class="cbi-section-table-cell" style="text-align:left" colspan="11">
								<br /><span id="rule_<%=tbl:lower()%>_<%=chain%>">
								<%:Chain%> <em><%=chain%></em>
								(<%- if chaininfo.policy then -%>
									<%:Policy%>: <em><%=chaininfo.policy%></em>, <%:Packets%>: <%=chaininfo.packets%>, <%:Traffic%>: <%=wba.byte_format(chaininfo.bytes)-%>
								<%- else -%>
									<%:References%>: <%=chaininfo.references-%>
								<%- end -%>)</span>
							</th>
						</tr>
						<tr class="cbi-section-table-descr">
							<th class="cbi-section-table-cell"><%:Rule #%></th>
							<th class="cbi-section-table-cell"><%:Pkts.%></th>
							<th class="cbi-section-table-cell"><%:Traffic%></th>
							<th class="cbi-section-table-cell"><%:Target%></th>
							<th class="cbi-section-table-cell"><%:Prot.%></th>
							<th class="cbi-section-table-cell"><%:Flags%></th>
							<th class="cbi-section-table-cell"><%:In%></th>
							<th class="cbi-section-table-cell"><%:Out%></th>
							<th class="cbi-section-table-cell"><%:Source%></th>
							<th class="cbi-section-table-cell"><%:Destination%></th>
							<th class="cbi-section-table-cell" style="width:30%"><%:Options%></th>
						</tr>

						<% for _, rule in ipairs(ipt:find({table=tbl, chain=chain})) do %>
							<tr class="cbi-section-table-row cbi-rowstyle-<%=rowstyle()%>">
								<td><%=rule.index%></td>
								<td><%=rule.packets%></td>
								<td><%=wba.byte_format(rule.bytes)%></td>
								<td><%=rule.target and link_target(tbl, rule.target) or "-"%></td>
								<td><%=rule.protocol%></td>
								<td><%=rule.flags%></td>
								<td><%=link_iface(rule.inputif)%></td>
								<td><%=link_iface(rule.outputif)%></td>
								<td><%=rule.source%></td>
								<td><%=rule.destination%></td>
								<td style="width:30%"><small><%=#rule.options > 0 and luci.util.pcdata(table.concat(rule.options, " ")) or "-"%></small></td>
							</tr>
						<% end %>

						<% if rowcnt == 1 then %>
							<tr class="cbi-section-table-titles cbi-rowstyle-<%=rowstyle()%>">
								<td colspan="11"><em><%:No rules in this chain%></em></td>
							</tr>
						<% end %>
					<% end %>

					<% if chaincnt == 0 then %>
						<tr class="cbi-section-table-titles cbi-rowstyle-<%=rowstyle()%>">
							<td colspan="11"><em><%:No chains in this table%></em></td>
						</tr>
					<% end %>
				</table>
				<br /><br />
			<% end %>
		</fieldset>
	</div>
</form>

<%+footer%>