luci-base, luci-mod-status: convert realtime stats to client side views
[project/luci.git] / modules / luci-mod-status / luasrc / controller / admin / status.lua
1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Copyright 2011 Jo-Philipp Wich <jow@openwrt.org>
3 -- Licensed to the public under the Apache License 2.0.
4
5 module("luci.controller.admin.status", package.seeall)
6
7 function index()
8 local page
9
10 entry({"admin", "status", "overview"}, template("admin_status/index"), _("Overview"), 1)
11
12 entry({"admin", "status", "iptables"}, template("admin_status/iptables"), _("Firewall"), 2).leaf = true
13 entry({"admin", "status", "iptables_dump"}, call("dump_iptables")).leaf = true
14 entry({"admin", "status", "iptables_action"}, post("action_iptables")).leaf = true
15
16 entry({"admin", "status", "routes"}, template("admin_status/routes"), _("Routes"), 3)
17 entry({"admin", "status", "syslog"}, call("action_syslog"), _("System Log"), 4)
18 entry({"admin", "status", "dmesg"}, call("action_dmesg"), _("Kernel Log"), 5)
19 entry({"admin", "status", "processes"}, form("admin_status/processes"), _("Processes"), 6)
20
21 entry({"admin", "status", "realtime"}, alias("admin", "status", "realtime", "load"), _("Realtime Graphs"), 7)
22
23 entry({"admin", "status", "realtime", "load"}, view("status/load"), _("Load"), 1)
24 entry({"admin", "status", "realtime", "bandwidth"}, view("status/bandwidth"), _("Traffic"), 2)
25 entry({"admin", "status", "realtime", "wireless"}, view("status/wireless"), _("Wireless"), 3).uci_depends = { wireless = true }
26 entry({"admin", "status", "realtime", "connections"}, view("status/connections"), _("Connections"), 4)
27
28 entry({"admin", "status", "nameinfo"}, call("action_nameinfo")).leaf = true
29 end
30
31 function action_syslog()
32 local syslog = luci.sys.syslog()
33 luci.template.render("admin_status/syslog", {syslog=syslog})
34 end
35
36 function action_dmesg()
37 local dmesg = luci.sys.dmesg()
38 luci.template.render("admin_status/dmesg", {dmesg=dmesg})
39 end
40
41 function dump_iptables(family, table)
42 local prefix = (family == "6") and "ip6" or "ip"
43 local ok, lines = pcall(io.lines, "/proc/net/%s_tables_names" % prefix)
44 if ok and lines then
45 local s
46 for s in lines do
47 if s == table then
48 luci.http.prepare_content("text/plain")
49 luci.sys.process.exec({
50 "/usr/sbin/%stables" % prefix, "-w", "-t", table,
51 "--line-numbers", "-nxvL"
52 }, luci.http.write)
53 return
54 end
55 end
56 end
57
58 luci.http.status(404, "No such table")
59 luci.http.prepare_content("text/plain")
60 end
61
62 function action_iptables()
63 if luci.http.formvalue("zero") then
64 if luci.http.formvalue("family") == "6" then
65 luci.util.exec("/usr/sbin/ip6tables -Z")
66 else
67 luci.util.exec("/usr/sbin/iptables -Z")
68 end
69 elseif luci.http.formvalue("restart") then
70 luci.util.exec("/etc/init.d/firewall restart")
71 end
72
73 luci.http.redirect(luci.dispatcher.build_url("admin/status/iptables"))
74 end