modules/admin-full:
[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-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                         <h3><%:a_s_ipt_actions Actions%></h3>
58                         <ul>
59                                 <li><a href="<%=REQUEST_URI%>?zero=1"><%:a_s_ipt_reset Reset Counters%></a></li>
60                                 <li><a href="<%=REQUEST_URI%>?restart=1"><%:a_s_ipt_restart Restart Firewall%></a></li>
61                         </ul>
62                         <br /><br />
63
64                         <% for _, tbl in ipairs({"Filter", "NAT", "Mangle"}) do chaincnt = 0 %>
65                                 <h3><%:a_s_ipt_table Table%>: <%=tbl%></h3>
66                                 <table class="cbi-section-table" style="font-size:90%">
67                                         <% for _, chain in ipairs(ipt:chains(tbl)) do
68                                                 rowcnt    = 0
69                                                 chaincnt  = chaincnt + 1
70                                                 chaininfo = ipt:chain(tbl, chain)
71                                         %>
72                                                 <tr class="cbi-section-table-titles cbi-rowstyle-<%=rowstyle()%>">
73                                                         <th class="cbi-section-table-cell" style="text-align:left" colspan="11">
74                                                                 <br /><a name="rule_<%=tbl:lower()%>_<%=chain%>"></a>
75                                                                 <%:a_s_ipt_chain Chain%> <em><%=chain%></em>
76                                                                 (<%- if chaininfo.policy then -%>
77                                                                         <%: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)-%>
78                                                                 <%- else -%>
79                                                                         <%:a_s_ipt_references References%>: <%=chaininfo.references-%>
80                                                                 <%- end -%>)
81                                                         </th>
82                                                 </tr>
83                                                 <tr class="cbi-section-table-descr">
84                                                         <th class="cbi-section-table-cell"><%:a_s_ipt_rulenum Rule #%></th>
85                                                         <th class="cbi-section-table-cell"><%:a_s_ipt_packets Pkts.%></th>
86                                                         <th class="cbi-section-table-cell"><%:a_s_ipt_bytes Traffic%></th>
87                                                         <th class="cbi-section-table-cell"><%:a_s_ipt_target Target%></th>
88                                                         <th class="cbi-section-table-cell"><%:a_s_ipt_proto Prot.%></th>
89                                                         <th class="cbi-section-table-cell"><%:a_s_ipt_flags Flags%></th>
90                                                         <th class="cbi-section-table-cell"><%:a_s_ipt_inputif In%></th>
91                                                         <th class="cbi-section-table-cell"><%:a_s_ipt_outputif Out%></th>
92                                                         <th class="cbi-section-table-cell"><%:a_s_ipt_source Source%></th>
93                                                         <th class="cbi-section-table-cell"><%:a_s_ipt_destination Destination%></th>
94                                                         <th class="cbi-section-table-cell"><%:a_s_ipt_options Options%></th>
95                                                 </tr>
96
97                                                 <% for _, rule in ipairs(ipt:find({table=tbl, chain=chain})) do %>
98                                                         <tr class="cbi-section-table-row cbi-rowstyle-<%=rowstyle()%>">
99                                                                 <td><%=rule.index%></td>
100                                                                 <td><%=rule.packets%></td>
101                                                                 <td><%=wba.byte_format(rule.bytes)%></td>
102                                                                 <td><%=link_target(tbl, rule.target)%></td>
103                                                                 <td><%=rule.protocol%></td>
104                                                                 <td><%=rule.flags%></td>
105                                                                 <td><%=link_iface(rule.inputif)%></td>
106                                                                 <td><%=link_iface(rule.outputif)%></td>
107                                                                 <td><%=rule.source%></td>
108                                                                 <td><%=rule.destination%></td>
109                                                                 <td><small><%=#rule.options > 0 and table.concat(rule.options, " ") or "-"%></small></td>
110                                                         </tr>
111                                                 <% end %>
112
113                                                 <% if rowcnt == 1 then %>
114                                                         <tr class="cbi-section-table-titles cbi-rowstyle-<%=rowstyle()%>">
115                                                                 <td colspan="11"><em><%:a_s_ipt_norules No rules in this chain%></em></td>
116                                                         </tr>
117                                                 <% end %>
118                                         <% end %>
119
120                                         <% if chaincnt == 0 then %>
121                                                 <tr class="cbi-section-table-titles cbi-rowstyle-<%=rowstyle()%>">
122                                                         <td colspan="11"><em><%:a_s_ipt_nochains No chains in this table%></em></td>
123                                                 </tr>
124                                         <% end %>
125                                 </table>
126                                 <br /><br />
127                         <% end %>
128                 </fieldset>
129         </div>
130 </form>
131
132 <%+footer%>