* Rewrote Luci to be coroutine-safe allowing the use of non-forking webservers
[project/luci.git] / modules / freifunk / luasrc / controller / freifunk / luciinfo.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13 ]]--
14 module("luci.controller.freifunk.luciinfo", package.seeall)
15
16 function index()
17 node("freifunk", "luciinfo").target = call("action_index")
18 end
19
20 function action_index()
21 local uci = luci.model.uci
22 luci.http.prepare_content("text/plain")
23
24 -- General
25 luci.http.write("luciinfo.api=1\n")
26 luci.http.write("luciinfo.version=" .. tostring(require("luci").__version__) .. "\n")
27
28 -- Sysinfo
29 local s, m, r = luci.sys.sysinfo()
30 local dr = luci.sys.net.defaultroute()
31 dr = dr and luci.sys.net.hexip4(dr.Gateway) or ""
32 local l1, l5, l15 = luci.sys.loadavg()
33
34 luci.http.write("sysinfo.system=" .. sanitize(s) .. "\n")
35 luci.http.write("sysinfo.cpu=" .. sanitize(m) .. "\n")
36 luci.http.write("sysinfo.ram=" .. sanitize(r) .. "\n")
37 luci.http.write("sysinfo.hostname=" .. sanitize(luci.sys.hostname()) .. "\n")
38 luci.http.write("sysinfo.load1=" .. tostring(l1) .. "\n")
39 luci.http.write("sysinfo.load5=" .. tostring(l5) .. "\n")
40 luci.http.write("sysinfo.load15=" .. tostring(l15) .. "\n")
41 luci.http.write("sysinfo.defaultgw=" .. dr .. "\n")
42
43
44 -- Freifunk
45 local ff = uci.get_all("freifunk") or {}
46 for k, v in pairs(ff) do
47 for i, j in pairs(v) do
48 if i:sub(1, 1) ~= "." then
49 luci.http.write("freifunk." .. k .. "." .. i .. "=" .. j .. "\n")
50 end
51 end
52 end
53 end
54
55 function sanitize(val)
56 return val:gsub("\n", "\t")
57 end