summaryrefslogtreecommitdiffhomepage
path: root/modules/freifunk/src/controller/rpc/luciinfo.lua
blob: 611423fbb0244bab413f17e66c1172b40312d7a6 (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
module("ffluci.controller.rpc.luciinfo", package.seeall)

function action_index()
	local uci = ffluci.model.uci.StateSession()

	ffluci.http.prepare_content("text/plain")
	
	-- General
	print("luciinfo.api=1")
	print("luciinfo.version=" .. tostring(ffluci.__version__))
	
	-- Sysinfo
	local s, m, r = ffluci.sys.sysinfo()
	local dr = ffluci.sys.net.defaultroute()
	dr = dr and ffluci.sys.net.hexip4(dr.Gateway) or ""
	local l1, l5, l15 = ffluci.sys.loadavg()
	
	print("sysinfo.system=" .. sanitize(s))
	print("sysinfo.cpu=" .. sanitize(m))
	print("sysinfo.ram=" .. sanitize(r))
	print("sysinfo.hostname=" .. sanitize(ffluci.sys.hostname()))
	print("sysinfo.load1=" .. tostring(l1))
	print("sysinfo.load5=" .. tostring(l5))
	print("sysinfo.load15=" .. tostring(l15))
	print("sysinfo.defaultgw=" .. dr)

	
	-- Freifunk
	local ff = uci:sections("freifunk") or {}
	for k, v in pairs(ff) do
		if k:sub(1, 1) ~= "." then
			for i, j in pairs(v) do
				print("freifunk." .. k .. "." .. i .. "=" .. j)
			end
		end
	end
end

function sanitize(val)
	return val:gsub("\n", "\t")
end