modules/admin-full: implement iptables status page
[project/luci.git] / modules / admin-full / luasrc / view / admin_status / iptables.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2009 Steven Barth <steven@midlink.org>
4 Copyright 2009 Jo-Philipp Wich <xm@leipzig.freifunk.net>
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
21 local ipt = luci.sys.iptparser.IptParser()
22 local wba = luci.tools.webadmin
23
24 local rowcnt = 1
25 function rowstyle()
26 rowcnt = rowcnt + 1
27 return (rowcnt % 2) + 1
28 end
29
30 function link_target(t,c)
31 if ipt:is_custom_target(c) then
32 return '<a href="#rule_%s_%s">%s</a>' %{ t:lower(), c, c }
33 end
34 return c
35 end
36
37 function link_iface(i)
38 local net = wba.iface_get_network(i)
39 if net and i ~= "lo" then
40 return '<a href="%s">%s</a>' %{
41 luci.dispatcher.build_url("admin", "network", "network", net), i
42 }
43
44 end
45 return i
46 end
47
48 -%>
49
50 <%+header%>
51
52 <h2><a id="content" name="content"><%:a_s_ipt_status Firewall Status%></a></h2>
53
54 <form method="post" action="<%=REQUEST_URI%>">
55 <div class="cbi-map">
56 <fieldset class="cbi-section">
57 <fieldset class="cbi-section-node">
58 <h3><%:a_s_ipt_actions Actions%></h3>
59 <ul>
60 <li><a href="<%=REQUEST_URI%>?zero=1"><%:a_s_ipt_reset Reset Counters%></a></li>
61 <li><a href="<%=REQUEST_URI%>?restart=1"><%:a_s_ipt_restart Restart Firewall%></a></li>
62 </ul>
63 </fieldset>
64 <br />
65
66 <fieldset class="cbi-section-node">
67 <% for _, tbl in ipairs({"Filter", "NAT", "Mangle"}) do chaincnt = 0 %>
68 <h3><%:a_s_ipt_table Table%>: <%=tbl%></h3>
69 <table class="cbi-section-table" style="font-size:90%">
70 <% for _, chain in ipairs(ipt:chains(tbl)) do
71 rowcnt = 0
72 chaincnt = chaincnt + 1
73 chaininfo = ipt:chain(tbl, chain)
74 %>
75 <tr class="cbi-section-table-titles cbi-rowstyle-<%=rowstyle()%>">
76 <th class="cbi-section-table-cell" style="text-align:left" colspan="11">
77 <br /><a name="rule_<%=tbl:lower()%>_<%=chain%>"></a>
78 <%:a_s_ipt_chain Chain%> <em><%=chain%></em>
79 (<%- if chaininfo.policy then -%>
80 <%:a_s_ipt_policy Policy%>: <em><%=chaininfo.policy%></em>, <%:a_s_ipt_packets Packets%>: <%=chaininfo.packets%>, <%:a_s_ipt_bytes Traffic%>: <%=wba.byte_format(chaininfo.bytes)-%>
81 <%- else -%>
82 <%:a_s_ipt_references References%>: <%=chaininfo.references-%>
83 <%- end -%>)
84 </th>
85 </tr>
86 <tr class="cbi-section-table-descr">
87 <th class="cbi-section-table-cell"><%:a_s_ipt_rulenum Rule #%></th>
88 <th class="cbi-section-table-cell"><%:a_s_ipt_packets Pkts.%></th>
89 <th class="cbi-section-table-cell"><%:a_s_ipt_bytes Traffic%></th>
90 <th class="cbi-section-table-cell"><%:a_s_ipt_target Target%></th>
91 <th class="cbi-section-table-cell"><%:a_s_ipt_proto Prot.%></th>
92 <th class="cbi-section-table-cell"><%:a_s_ipt_flags Flags%></th>
93 <th class="cbi-section-table-cell"><%:a_s_ipt_inputif In%></th>
94 <th class="cbi-section-table-cell"><%:a_s_ipt_outputif Out%></th>
95 <th class="cbi-section-table-cell"><%:a_s_ipt_source Source%></th>
96 <th class="cbi-section-table-cell"><%:a_s_ipt_destination Destination%></th>
97 <th class="cbi-section-table-cell"><%:a_s_ipt_options Options%></th>
98 </tr>
99
100 <% for _, rule in ipairs(ipt:find({table=tbl, chain=chain})) do %>
101 <tr class="cbi-section-table-row cbi-rowstyle-<%=rowstyle()%>">
102 <td><%=rule.index%></td>
103 <td><%=rule.packets%></td>
104 <td><%=wba.byte_format(rule.bytes)%></td>
105 <td><%=link_target(tbl, rule.target)%></td>
106 <td><%=rule.protocol%></td>
107 <td><%=rule.flags%></td>
108 <td><%=link_iface(rule.inputif)%></td>
109 <td><%=link_iface(rule.outputif)%></td>
110 <td><%=rule.source%></td>
111 <td><%=rule.destination%></td>
112 <td><small><%=#rule.options > 0 and table.concat(rule.options, " ") or "-"%></small></td>
113 </tr>
114 <% end %>
115
116 <% if rowcnt == 1 then %>
117 <tr class="cbi-section-table-titles cbi-rowstyle-<%=rowstyle()%>">
118 <td colspan="11"><em><%:a_s_ipt_norules No rules in this chain%></em></td>
119 </tr>
120 <% end %>
121 <% end %>
122
123 <% if chaincnt == 0 then %>
124 <tr class="cbi-section-table-titles cbi-rowstyle-<%=rowstyle()%>">
125 <td colspan="11"><em><%:a_s_ipt_nochains No chains in this table%></em></td>
126 </tr>
127 <% end %>
128 </table>
129 <br /><br />
130 <% end %>
131 </fieldset>
132 </fieldset>
133 </div>
134 </form>
135
136 <%+footer%>
137 <% if ret == 0 then luci.sys.reboot() end %>