summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-mod-status/luasrc/view/admin_status/index.htm
blob: 5b53e8ed343bc95293f94e42d5b829494e41e765 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<%#
 Copyright 2008 Steven Barth <steven@midlink.org>
 Copyright 2008-2018 Jo-Philipp Wich <jo@mein.io>
 Licensed to the public under the Apache License 2.0.
-%>

<%
	local fs = require "nixio.fs"
	local ipc = require "luci.ip"
	local util = require "luci.util"
	local stat = require "luci.tools.status"
	local ver = require "luci.version"

	if luci.http.formvalue("status") == "1" then

		local sysinfo = luci.util.ubus("system", "info") or { }

		local meminfo = sysinfo.memory or {
			total = 0,
			free = 0,
			buffered = 0,
			shared = 0
		}

		local swapinfo = sysinfo.swap or {
			total = 0,
			free = 0
		}

		local has_dsl = fs.access("/etc/init.d/dsl_control")

		local ntm = require "luci.model.network".init()
		local wan_nets = ntm:get_wan_networks()
		local wan6_nets = ntm:get_wan6_networks()

		local conn_count = tonumber(
			fs.readfile("/proc/sys/net/netfilter/nf_conntrack_count") or "") or 0

		local conn_max = tonumber(luci.sys.exec(
			"sysctl -n -e net.nf_conntrack_max net.ipv4.netfilter.ip_conntrack_max"
		):match("%d+")) or 4096

		local rv = {
			uptime     = sysinfo.uptime or 0,
			localtime  = os.date(),
			loadavg    = sysinfo.load or { 0, 0, 0 },
			memory     = meminfo,
			swap       = swapinfo,
			connmax    = conn_max,
			conncount  = conn_count,
			wifinets   = stat.wifi_networks()
		}

		if #wan_nets > 0 then
			local k, v

			rv.wan = { }

			for k, v in pairs(wan_nets) do
				local dev = v:get_interface()
				local link = dev and ipc.link(dev:name())

				local wan_info = {
					ipaddrs = v:ipaddrs(),
					gwaddr  = v:gwaddr(),
					dns     = v:dnsaddrs(),
					expires = v:expires(),
					uptime  = v:uptime(),
					proto   = v:proto(),
					i18n    = v:get_i18n(),
					ifname  = v:ifname(),
					link    = v:adminlink(),
					mac     = dev and dev:mac(),
					type    = dev and dev:type(),
					name    = dev and dev:get_i18n(),
					ether   = link and link.type == 1
				}

				rv.wan[#rv.wan+1] = wan_info
			end
		end

		if #wan6_nets > 0 then
			local k, v

			rv.wan6 = { }

			for k, v in pairs(wan6_nets) do
				local dev = v:get_interface()
				local link = dev and ipc.link(dev:name())
				local wan6_info = {
					ip6addrs  = v:ip6addrs(),
					gw6addr   = v:gw6addr(),
					dns       = v:dns6addrs(),
					ip6prefix = v:ip6prefix(),
					uptime    = v:uptime(),
					proto     = v:proto(),
					i18n      = v:get_i18n(),
					ifname    = v:ifname(),
					link      = v:adminlink(),
					mac       = dev and dev:mac(),
					type      = dev and dev:type(),
					name      = dev and dev:get_i18n(),
					ether     = link and link.type == 1
				}

				rv.wan6[#rv.wan6+1] = wan6_info
			end
		end

		if has_dsl then
			local dsl_stat = luci.sys.exec("/etc/init.d/dsl_control lucistat")
			local dsl_func = loadstring(dsl_stat)
			if dsl_func then
				rv.dsl = dsl_func()
			end
		end

		luci.http.prepare_content("application/json")
		luci.http.write_json(rv)

		return
	end
-%>

<%+header%>

<h2 name="content"><%:Status%></h2>

<%-
	local incdir = util.libpath() .. "/view/admin_status/index/"
	if fs.access(incdir) then
		local _, inc
		local includes = {}
		for inc in fs.dir(incdir) do
			if inc:match("%.htm$") then
				includes[#includes + 1] = inc:gsub("%.htm$", "")
			end
		end
		for _, inc in luci.util.vspairs(includes) do
			include("admin_status/index/" .. inc)
		end
	end
-%>

<script type="text/javascript" src="<%=resource%>/view/status/index.js"></script>

<%+footer%>