luci-base: form.js: implement Textfield widget
[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 ipaddrs = v:ipaddrs(),
65 gwaddr = v:gwaddr(),
66 dns = v:dnsaddrs(),
67 expires = v:expires(),
68 uptime = v:uptime(),
69 proto = v:proto(),
70 i18n = v:get_i18n(),
71 ifname = v:ifname(),
72 link = v:adminlink(),
73 mac = dev and dev:mac(),
74 type = dev and dev:type(),
75 name = dev and dev:get_i18n(),
76 ether = link and link.type == 1
77 }
78
79 rv.wan[#rv.wan+1] = wan_info
80 end
81 end
82
83 if #wan6_nets > 0 then
84 local k, v
85
86 rv.wan6 = { }
87
88 for k, v in pairs(wan6_nets) do
89 local dev = v:get_interface()
90 local link = dev and ipc.link(dev:name())
91 local wan6_info = {
92 ip6addrs = v:ip6addrs(),
93 gw6addr = v:gw6addr(),
94 dns = v:dns6addrs(),
95 ip6prefix = v:ip6prefix(),
96 uptime = v:uptime(),
97 proto = v:proto(),
98 i18n = v:get_i18n(),
99 ifname = v:ifname(),
100 link = v:adminlink(),
101 mac = dev and dev:mac(),
102 type = dev and dev:type(),
103 name = dev and dev:get_i18n(),
104 ether = link and link.type == 1
105 }
106
107 rv.wan6[#rv.wan6+1] = wan6_info
108 end
109 end
110
111 if has_dsl then
112 local dsl_stat = luci.sys.exec("/etc/init.d/dsl_control lucistat")
113 local dsl_func = loadstring(dsl_stat)
114 if dsl_func then
115 rv.dsl = dsl_func()
116 end
117 end
118
119 luci.http.prepare_content("application/json")
120 luci.http.write_json(rv)
121
122 return
123 end
124 -%>
125
126 <%+header%>
127
128 <h2 name="content"><%:Status%></h2>
129
130 <%-
131 local incdir = util.libpath() .. "/view/admin_status/index/"
132 if fs.access(incdir) then
133 local _, inc
134 local includes = {}
135 for inc in fs.dir(incdir) do
136 if inc:match("%.htm$") then
137 includes[#includes + 1] = inc:gsub("%.htm$", "")
138 end
139 end
140 for _, inc in luci.util.vspairs(includes) do
141 include("admin_status/index/" .. inc)
142 end
143 end
144 -%>
145
146 <script type="text/javascript" src="<%=resource%>/view/status/index.js"></script>
147
148 <%+footer%>