2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2011 Jo-Philipp Wich <xm@subsignal.org>
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
15 module("luci.controller.admin.status", package.seeall)
18 luci.i18n.loadc("base")
19 local i18n = luci.i18n.translate
21 entry({"admin", "status"}, alias("admin", "status", "overview"), i18n("Status"), 20).index = true
22 entry({"admin", "status", "overview"}, template("admin_status/index"), i18n("Overview"), 1)
23 entry({"admin", "status", "iptables"}, call("action_iptables"), i18n("Firewall"), 2).leaf = true
24 entry({"admin", "status", "routes"}, template("admin_status/routes"), i18n("Routes"), 3)
25 entry({"admin", "status", "syslog"}, call("action_syslog"), i18n("System Log"), 4)
26 entry({"admin", "status", "dmesg"}, call("action_dmesg"), i18n("Kernel Log"), 5)
28 entry({"admin", "status", "load"}, template("admin_status/load"), i18n("Realtime Load"), 6).leaf = true
29 entry({"admin", "status", "load_status"}, call("action_load")).leaf = true
31 entry({"admin", "status", "bandwidth"}, template("admin_status/bandwidth"), i18n("Realtime Traffic"), 7).leaf = true
32 entry({"admin", "status", "bandwidth_status"}, call("action_bandwidth")).leaf = true
34 entry({"admin", "status", "connections"}, template("admin_status/connections"), i18n("Realtime Connections"), 8).leaf = true
35 entry({"admin", "status", "connections_status"}, call("action_connections")).leaf = true
37 entry({"admin", "status", "processes"}, cbi("admin_status/processes"), i18n("Processes"), 20)
40 function action_syslog()
41 local syslog = luci.sys.syslog()
42 luci.template.render("admin_status/syslog", {syslog=syslog})
45 function action_dmesg()
46 local dmesg = luci.sys.dmesg()
47 luci.template.render("admin_status/dmesg", {dmesg=dmesg})
50 function action_iptables()
51 if luci.http.formvalue("zero") then
52 if luci.http.formvalue("zero") == "6" then
53 luci.util.exec("ip6tables -Z")
55 luci.util.exec("iptables -Z")
58 luci.dispatcher.build_url("admin", "status", "iptables")
60 elseif luci.http.formvalue("restart") == "1" then
61 luci.util.exec("/etc/init.d/firewall restart")
63 luci.dispatcher.build_url("admin", "status", "iptables")
66 luci.template.render("admin_status/iptables")
70 function action_bandwidth()
71 local path = luci.dispatcher.context.requestpath
72 local iface = path[#path]
74 local fs = require "luci.fs"
75 if fs.access("/var/lib/luci-bwc/if/%s" % iface) then
76 luci.http.prepare_content("application/json")
78 local bwc = io.popen("luci-bwc -i %q 2>/dev/null" % iface)
83 local ln = bwc:read("*l")
84 if not ln then break end
95 luci.http.status(404, "No data available")
98 function action_load()
99 local fs = require "luci.fs"
100 if fs.access("/var/lib/luci-bwc/load") then
101 luci.http.prepare_content("application/json")
103 local bwc = io.popen("luci-bwc -l 2>/dev/null")
108 local ln = bwc:read("*l")
109 if not ln then break end
120 luci.http.status(404, "No data available")
123 function action_connections()
124 local fs = require "luci.fs"
125 local sys = require "luci.sys"
127 luci.http.prepare_content("application/json")
129 luci.http.write("{ connections: ")
130 luci.http.write_json(sys.net.conntrack())
132 if fs.access("/var/lib/luci-bwc/connections") then
133 local bwc = io.popen("luci-bwc -c 2>/dev/null")
135 luci.http.write(", statistics: [")
138 local ln = bwc:read("*l")
139 if not ln then break end
148 luci.http.write(" }")