build: split into luci and luci-addons packages
[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                 inst:unload("network")
46         end
47 -%>
48
49 <div><a href="?toggle_rtable=1"> &gt; <%:Toggle display of Routing Information%> &lt; </a></div>
50 <br />
51
52 <% if inst:get("network", "lan", "_showrtable") ~= "0" then %>
53 <div class="cbi-map" id="x-cbi-network">
54
55         <fieldset class="cbi-section" id="x-cbi-table-table">
56                 <legend><%_Active <abbr title="Internet Protocol Version 4">IPv4</abbr>-Routes%></legend>
57
58                 <div class="cbi-section-node">
59                         <table class="cbi-section-table">
60                                 <tr class="cbi-section-table-titles">
61                                         <th class="cbi-section-table-cell"><%:Network%></th>
62                                         <th class="cbi-section-table-cell"><%:Target%></th>
63                                         <th class="cbi-section-table-cell"><%_<abbr title="Internet Protocol Version 4">IPv4</abbr>-Netmask%></th>
64                                         <th class="cbi-section-table-cell"><%_<abbr title="Internet Protocol Version 4">IPv4</abbr>-Gateway%></th>
65                                         <th class="cbi-section-table-cell"><%:Metric%></th>
66                                 </tr>
67                                 <% luci.sys.net.routes(function(rt) %>
68                                 <tr class="cbi-section-table-row cbi-rowstyle-<%=(style and 1 or 2)%>">
69                                         <td class="cbi-value-field"><%=ifc[rt.device]%></td>
70                                         <td class="cbi-value-field"><%=rt.dest:network():string()%></td>
71                                         <td class="cbi-value-field"><%=rt.dest:mask():string()%></td>
72                                         <td class="cbi-value-field"><%=rt.gateway:string()%></td>
73                                         <td class="cbi-value-field"><%=rt.metric%></td>
74                                 </tr>
75                                 <% style = not style; end) %>
76                         </table>
77                 </div>
78         </fieldset>
79         <br />
80
81         <% if fs.access("/proc/net/ipv6_route") then style = true %>
82         <fieldset class="cbi-section" id="x-cbi-table-table-2">
83                 <legend><%_Active <abbr title="Internet Protocol Version 6">IPv6</abbr>-Routes%></legend>
84
85                 <div class="cbi-section-node">
86                         <table class="cbi-section-table">
87                                 <tr class="cbi-section-table-titles">
88                                         <th class="cbi-section-table-cell"><%:Network%></th>
89                                         <th class="cbi-section-table-cell"><%:Target%></th>
90                                         <th class="cbi-section-table-cell"><%_<abbr title="Internet Protocol Version 6">IPv6</abbr>-Gateway%></th>
91                                         <th class="cbi-section-table-cell"><%:Metric%></th>
92                                 </tr>
93                                 <% luci.sys.net.routes6(function(rt) %>
94                                 <tr class="cbi-section-table-row cbi-rowstyle-<%=(style and 1 or 2)%>">
95                                         <td class="cbi-value-field"><%=ifc[rt.device]%></td>
96                                         <td class="cbi-value-field"><%=rt.dest:string()%></td>
97                                         <td class="cbi-value-field"><%=rt.source:string()%></td>
98                                         <td class="cbi-value-field"><%- 
99                                                 local metr   = rt.metric
100                                                 local lower  = bit.band(metr, 0xffff)
101                                                 local higher = bit.rshift(bit.band(metr, 0xffff0000), 16)
102                                                 write(string.format("%04X%04X", higher, lower))
103                                         -%></td>
104                                 </tr>
105                                 <% style = not style; end) %>
106                         </table>
107                 </div>
108         </fieldset>
109         <br />
110         <% end %>
111 </div>
112 <% end %>