Merge pull request #1933 from Ansuel/hostname_upnp
[oweals/luci.git] / modules / luci-mod-admin-full / luasrc / view / admin_status / routes.htm
1 <%#
2  Copyright 2008-2009 Steven Barth <steven@midlink.org>
3  Copyright 2008-2015 Jo-Philipp Wich <jow@openwrt.org>
4  Licensed to the public under the Apache License 2.0.
5 -%>
6
7 <%-
8         require "luci.tools.webadmin"
9         require "nixio.fs"
10
11         local ip = require "luci.ip"
12         local style = true
13         local _, v
14
15         local rtn = {
16                 [255] = "local",
17                 [254] = "main",
18                 [253] = "default",
19                 [0]   = "unspec"
20         }
21
22         if nixio.fs.access("/etc/iproute2/rt_tables") then
23                 local ln
24                 for ln in io.lines("/etc/iproute2/rt_tables") do
25                         local i, n = ln:match("^(%d+)%s+(%S+)")
26                         if i and n then
27                                 rtn[tonumber(i)] = n
28                         end
29                 end
30         end
31 -%>
32
33 <%+header%>
34
35
36 <div class="cbi-map" id="cbi-network">
37         <h2 name="content"><%:Routes%></h2>
38         <div class="cbi-map-descr"><%:The following rules are currently active on this system.%></div>
39
40         <div class="cbi-section">
41                 <legend>ARP</legend>
42                 <div class="cbi-section-node">
43                         <div class="table">
44                                 <div class="tr table-titles">
45                                         <div class="th"><%_<abbr title="Internet Protocol Version 4">IPv4</abbr>-Address%></div>
46                                         <div class="th"><%_<abbr title="Media Access Control">MAC</abbr>-Address%></div>
47                                         <div class="th"><%:Interface%></div>
48                                 </div>
49
50                                 <%
51                                         for _, v in ipairs(ip.neighbors({ family = 4 })) do
52                                                 if v.mac then
53                                 %>
54                                 <div class="tr cbi-rowstyle-<%=(style and 1 or 2)%>">
55                                         <div class="td"><%=v.dest%></div>
56                                         <div class="td"><%=v.mac%></div>
57                                         <div class="td"><%=luci.tools.webadmin.iface_get_network(v.dev) or '(' .. v.dev .. ')'%></div>
58                                 </div>
59                                 <%
60                                                         style = not style
61                                                 end
62                                         end
63                                 %>
64                         </div>
65                 </div>
66         </div>
67
68         <div class="cbi-section">
69                 <legend><%_Active <abbr title="Internet Protocol Version 4">IPv4</abbr>-Routes%></legend>
70                 <div class="cbi-section-node">
71                         <div class="table">
72                                 <div class="tr table-titles">
73                                         <div class="th"><%:Network%></div>
74                                         <div class="th"><%:Target%></div>
75                                         <div class="th"><%_<abbr title="Internet Protocol Version 4">IPv4</abbr>-Gateway%></div>
76                                         <div class="th"><%:Metric%></div>
77                                         <div class="th"><%:Table%></div>
78                                 </div>
79                                 <% for _, v in ipairs(ip.routes({ family = 4, type = 1 })) do %>
80                                 <div class="tr cbi-rowstyle-<%=(style and 1 or 2)%>">
81                                         <div class="td"><%=luci.tools.webadmin.iface_get_network(v.dev) or v.dev%></div>
82                                         <div class="td"><%=v.dest%></div>
83                                         <div class="td"><%=v.gw or "-"%></div>
84                                         <div class="td"><%=v.metric or 0%></div>
85                                         <div class="td"><%=rtn[v.table] or v.table%></div>
86                                 </div>
87                                 <% style = not style end %>
88                         </div>
89                 </div>
90         </div>
91
92         <%
93                 if nixio.fs.access("/proc/net/ipv6_route") then
94                         style = true
95         %>
96         <div class="cbi-section">
97                 <legend><%_Active <abbr title="Internet Protocol Version 6">IPv6</abbr>-Routes%></legend>
98                 <div class="cbi-section-node">
99                         <div class="table">
100                                 <div class="tr table-titles">
101                                         <div class="th"><%:Network%></div>
102                                         <div class="th"><%:Target%></div>
103                                         <div class="th"><%:Source%></div>
104                                         <div class="th"><%:Metric%></div>
105                                         <div class="th"><%:Table%></div>
106                                 </div>
107                                 <%
108                                         for _, v in ipairs(ip.routes({ family = 6, type = 1 })) do
109                                                 if v.dest and not v.dest:is6linklocal() then
110                                 %>
111                                 <div class="tr cbi-rowstyle-<%=(style and 1 or 2)%>">
112                                         <div class="td"><%=luci.tools.webadmin.iface_get_network(v.dev) or '(' .. v.dev .. ')'%></div>
113                                         <div class="td"><%=v.dest%></div>
114                                         <div class="td"><%=v.from%></div>
115                                         <div class="td"><%=v.metric or 0%></div>
116                                         <div class="td"><%=rtn[v.table] or v.table%></div>
117                                 </div>
118                                 <%
119                                                         style = not style
120                                                 end
121                                         end
122                                 %>
123                         </div>
124                 </div>
125         </div>
126
127         <div class="cbi-section">
128                 <legend><%:IPv6 Neighbours%></legend>
129                 <div class="cbi-section-node">
130                         <div class="table">
131                                 <div class="tr table-titles">
132                                         <div class="th"><%:IPv6-Address%></div>
133                                         <div class="th"><%:MAC-Address%></div>
134                                         <div class="th"><%:Interface%></div>
135                                 </div>
136                                 <%
137                                         for _, v in ipairs(ip.neighbors({ family = 6 })) do
138                                                 if v.dest and not v.dest:is6linklocal() and v.mac then
139                                 %>
140                                 <div class="tr cbi-rowstyle-<%=(style and 1 or 2)%>">
141                                         <div class="td"><%=v.dest%></div>
142                                         <div class="td"><%=v.mac%></div>
143                                         <div class="td"><%=luci.tools.webadmin.iface_get_network(v.dev) or '(' .. v.dev .. ')'%></div>
144                                 </div>
145                                 <%
146                                                         style = not style
147                                                 end
148                                         end
149                                 %>
150                         </div>
151                 </div>
152         </div>
153         <% end %>
154 </div>
155
156 <%+footer%>