4452a87dbcf275b6fd1e7a3b966cf5e4ad3f4a09
[project/luci.git] / modules / niu / luasrc / view / niu / network / rtable.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2008-2009 Steven Barth <steven@midlink.org>
4 Copyright 2008-2009 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         local fs = require "nixio.fs"
18         local bit = require "nixio".bit
19         local sys = require "luci.sys"
20         local uci = require "luci.model.uci"
21         local inst = uci.inst
22         local state = uci.inst_state
23         local http = require "luci.http"
24         local style = true
25
26
27         local ifc = {__index = function(self, key)
28                 local net = key
29                 state:foreach("network", "interface", function(s)
30                         if s.ifname == key then
31                                 net = s[".name"]
32                         end
33                 end)
34                 rawset(self, key, net) 
35                 return net
36         end}
37         setmetatable(ifc, ifc)
38         
39         if http.formvalue("toggle_rtable") then
40                 local cursor = uci.cursor()
41                 local rt = cursor:get("network", "lan", "_showrtable") or "1"
42                 cursor:set("network", "lan", "_showrtable", rt == "1" and "0" or "1")
43                 cursor:save("network")
44                 cursor:unload("network")
45         end
46 -%>
47
48 <div><a href="?toggle_rtable=1"> &gt; <%:Toggle display of Routing Information%> &lt; </a></div>
49 <br />
50
51 <% if inst:get("network", "lan", "_showrtable") ~= "0" then %>
52 <div class="cbi-map" id="x-cbi-network">
53
54         <fieldset class="cbi-section" id="x-cbi-table-table">
55                 <legend><%_Active <abbr title="Internet Protocol Version 4">IPv4</abbr>-Routes%></legend>
56
57                 <div class="cbi-section-node">
58                         <table class="cbi-section-table">
59                                 <tr class="cbi-section-table-titles">
60                                         <th class="cbi-section-table-cell"><%:Network%></th>
61                                         <th class="cbi-section-table-cell"><%:Target%></th>
62                                         <th class="cbi-section-table-cell"><%_<abbr title="Internet Protocol Version 4">IPv4</abbr>-Netmask%></th>
63                                         <th class="cbi-section-table-cell"><%_<abbr title="Internet Protocol Version 4">IPv4</abbr>-Gateway%></th>
64                                         <th class="cbi-section-table-cell"><%:Metric%></th>
65                                 </tr>
66                                 <% luci.sys.net.routes(function(rt) %>
67                                 <tr class="cbi-section-table-row cbi-rowstyle-<%=(style and 1 or 2)%>">
68                                         <td class="cbi-value-field"><%=ifc[rt.device]%></td>
69                                         <td class="cbi-value-field"><%=rt.dest:network():string()%></td>
70                                         <td class="cbi-value-field"><%=rt.dest:mask():string()%></td>
71                                         <td class="cbi-value-field"><%=rt.gateway:string()%></td>
72                                         <td class="cbi-value-field"><%=rt.metric%></td>
73                                 </tr>
74                                 <% style = not style; end) %>
75                         </table>
76                 </div>
77         </fieldset>
78         <br />
79
80         <% if fs.access("/proc/net/ipv6_route") then style = true %>
81         <fieldset class="cbi-section" id="x-cbi-table-table-2">
82                 <legend><%_Active <abbr title="Internet Protocol Version 6">IPv6</abbr>-Routes%></legend>
83
84                 <div class="cbi-section-node">
85                         <table class="cbi-section-table">
86                                 <tr class="cbi-section-table-titles">
87                                         <th class="cbi-section-table-cell"><%:Network%></th>
88                                         <th class="cbi-section-table-cell"><%:Target%></th>
89                                         <th class="cbi-section-table-cell"><%_<abbr title="Internet Protocol Version 6">IPv6</abbr>-Gateway%></th>
90                                         <th class="cbi-section-table-cell"><%:Metric%></th>
91                                 </tr>
92                                 <% luci.sys.net.routes6(function(rt) %>
93                                 <tr class="cbi-section-table-row cbi-rowstyle-<%=(style and 1 or 2)%>">
94                                         <td class="cbi-value-field"><%=ifc[rt.device]%></td>
95                                         <td class="cbi-value-field"><%=rt.dest:string()%></td>
96                                         <td class="cbi-value-field"><%=rt.source:string()%></td>
97                                         <td class="cbi-value-field"><%- 
98                                                 local metr   = rt.metric
99                                                 local lower  = bit.band(metr, 0xffff)
100                                                 local higher = bit.rshift(bit.band(metr, 0xffff0000), 16)
101                                                 write(string.format("%04X%04X", higher, lower))
102                                         -%></td>
103                                 </tr>
104                                 <% style = not style; end) %>
105                         </table>
106                 </div>
107         </fieldset>
108         <br />
109         <% end %>
110 </div>
111 <% end %>