luci-mod-status: split status page into a series of partials
[project/luci.git] / modules / luci-mod-status / luasrc / view / admin_status / index.htm
1 <%#
2 Copyright 2008 Steven Barth <steven@midlink.org>
3 Copyright 2008-2018 Jo-Philipp Wich <jo@mein.io>
4 Licensed to the public under the Apache License 2.0.
5 -%>
6
7 <%
8 local fs = require "nixio.fs"
9 local ipc = require "luci.ip"
10 local util = require "luci.util"
11 local stat = require "luci.tools.status"
12 local ver = require "luci.version"
13
14 if luci.http.formvalue("status") == "1" then
15
16 local sysinfo = luci.util.ubus("system", "info") or { }
17
18 local meminfo = sysinfo.memory or {
19 total = 0,
20 free = 0,
21 buffered = 0,
22 shared = 0
23 }
24
25 local swapinfo = sysinfo.swap or {
26 total = 0,
27 free = 0
28 }
29
30 local has_dsl = fs.access("/etc/init.d/dsl_control")
31
32 local ntm = require "luci.model.network".init()
33 local wan_nets = ntm:get_wan_networks()
34 local wan6_nets = ntm:get_wan6_networks()
35
36 local conn_count = tonumber(
37 fs.readfile("/proc/sys/net/netfilter/nf_conntrack_count") or "") or 0
38
39 local conn_max = tonumber(luci.sys.exec(
40 "sysctl -n -e net.nf_conntrack_max net.ipv4.netfilter.ip_conntrack_max"
41 ):match("%d+")) or 4096
42
43 local rv = {
44 uptime = sysinfo.uptime or 0,
45 localtime = os.date(),
46 loadavg = sysinfo.load or { 0, 0, 0 },
47 memory = meminfo,
48 swap = swapinfo,
49 connmax = conn_max,
50 conncount = conn_count,
51 wifinets = stat.wifi_networks()
52 }
53
54 if #wan_nets > 0 then
55 local k, v
56
57 rv.wan = { }
58
59 for k, v in pairs(wan_nets) do
60 local dev = v:get_interface()
61 local link = dev and ipc.link(dev:name())
62
63 local wan_info = {
64 ipaddr = v:ipaddr(),
65 gwaddr = v:gwaddr(),
66 netmask = v:netmask(),
67 dns = v:dnsaddrs(),
68 expires = v:expires(),
69 uptime = v:uptime(),
70 proto = v:proto(),
71 i18n = v:get_i18n(),
72 ifname = v:ifname(),
73 link = v:adminlink(),
74 mac = dev and dev:mac(),
75 type = dev and dev:type(),
76 name = dev and dev:get_i18n(),
77 ether = link and link.type == 1
78 }
79
80 rv.wan[#rv.wan+1] = wan_info
81 end
82 end
83
84 if #wan6_nets > 0 then
85 local k, v
86
87 rv.wan6 = { }
88
89 for k, v in pairs(wan6_nets) do
90 local dev = v:get_interface()
91 local link = dev and ipc.link(dev:name())
92 local wan6_info = {
93 ip6addr = v:ip6addr(),
94 gw6addr = v:gw6addr(),
95 dns = v:dns6addrs(),
96 ip6prefix = v:ip6prefix(),
97 uptime = v:uptime(),
98 proto = v:proto(),
99 i18n = v:get_i18n(),
100 ifname = v:ifname(),
101 link = v:adminlink(),
102 mac = dev and dev:mac(),
103 type = dev and dev:type(),
104 name = dev and dev:get_i18n(),
105 ether = link and link.type == 1
106 }
107
108 rv.wan6[#rv.wan6+1] = wan6_info
109 end
110 end
111
112 if has_dsl then
113 local dsl_stat = luci.sys.exec("/etc/init.d/dsl_control lucistat")
114 local dsl_func = loadstring(dsl_stat)
115 if dsl_func then
116 rv.dsl = dsl_func()
117 end
118 end
119
120 luci.http.prepare_content("application/json")
121 luci.http.write_json(rv)
122
123 return
124 end
125 -%>
126
127 <%+header%>
128
129 <h2 name="content"><%:Status%></h2>
130
131 <%-
132 local incdir = util.libpath() .. "/view/admin_status/index/"
133 if fs.access(incdir) then
134 local _, inc
135 local includes = {}
136 for inc in fs.dir(incdir) do
137 if inc:match("%.htm$") then
138 includes[#includes + 1] = inc:gsub("%.htm$", "")
139 end
140 end
141 for _, inc in luci.util.vspairs(includes) do
142 include("admin_status/index/" .. inc)
143 end
144 end
145 -%>
146
147 <script type="text/javascript" src="<%=resource%>/view/status/index.js"></script>
148
149 <%+footer%>