2 LuCI - Lua Configuration Interface
3 Copyright
2008-
2009 Steven Barth
<steven@midlink.org
>
4 Copyright
2008-
2009 Jo-Philipp Wich
<xm@subsignal.org
>
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
10 http://www.apache.org/licenses/LICENSE-
2.0
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"
22 local state = uci.inst_state
23 local http = require
"luci.http"
27 local ifc = {__index = function(self, key)
29 state:foreach(
"network",
"interface", function(s)
30 if s.ifname == key then
34 rawset(self, key, net)
37 setmetatable(ifc, ifc)
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")
49 <div><a href=
"?toggle_rtable=1"> > <%:Toggle display of Routing Information%
> < </a></div>
52 <% if inst:get(
"network",
"lan",
"_showrtable") ~=
"0" then %
>
53 <div class=
"cbi-map" id=
"x-cbi-network">
55 <fieldset class=
"cbi-section" id=
"x-cbi-table-table">
56 <legend><%_Active
<abbr title=
"Internet Protocol Version 4">IPv4
</abbr>-Routes%
></legend>
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>
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>
75 <% style = not style; end) %
>
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>
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>
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))
105 <% style = not style; end) %
>