Merge pull request #278 from nmav/ocserv
[project/luci.git] / modules / 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 require "luci.tools.webadmin"
20 require "luci.fs"
21
22 local has_ip6tables = luci.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 local wba = luci.tools.webadmin
32
33 local rowcnt = 1
34 function rowstyle()
35 rowcnt = rowcnt + 1
36 return (rowcnt % 2) + 1
37 end
38
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 }
42 end
43 return c
44 end
45
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
51 }
52
53 end
54 return i
55 end
56
57 local tables = { "Filter", "NAT", "Mangle", "Raw" }
58 if mode == 6 then
59 tables = { "Filter", "Mangle", "Raw" }
60 end
61 -%>
62
63 <%+header%>
64
65 <style type="text/css">
66 span:target {
67 color: blue;
68 text-decoration: underline;
69 }
70 </style>
71
72 <h2><a id="content" name="content"><%:Firewall Status%></a></h2>
73
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>
78 </ul>
79 <% end %>
80
81 <form method="post" action="<%=REQUEST_URI%>">
82 <div class="cbi-map">
83 <fieldset class="cbi-section">
84 <h3><%:Actions%></h3>
85 <ul>
86 <li><a href="<%=REQUEST_URI%>?zero=<%=mode%>"><%:Reset Counters%></a></li>
87 <li><a href="<%=REQUEST_URI%>?restart=1"><%:Restart Firewall%></a></li>
88 </ul>
89 <br /><br />
90
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
95 rowcnt = 0
96 chaincnt = chaincnt + 1
97 chaininfo = ipt:chain(tbl, chain)
98 %>
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)-%>
105 <%- else -%>
106 <%:References%>: <%=chaininfo.references-%>
107 <%- end -%>)</span>
108 </th>
109 </tr>
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>
122 </tr>
123
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>
137 </tr>
138 <% end %>
139
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>
143 </tr>
144 <% end %>
145 <% end %>
146
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>
150 </tr>
151 <% end %>
152 </table>
153 <br /><br />
154 <% end %>
155 </fieldset>
156 </div>
157 </form>
158
159 <%+footer%>