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.
5 module("luci.controller.admin.status", package.seeall)
10 entry({"admin", "status", "overview"}, template("admin_status/index"), _("Overview"), 1)
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
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)
21 entry({"admin", "status", "realtime"}, alias("admin", "status", "realtime", "load"), _("Realtime Graphs"), 7)
23 entry({"admin", "status", "realtime", "load"}, template("admin_status/load"), _("Load"), 1).leaf = true
24 entry({"admin", "status", "realtime", "load_status"}, call("action_load")).leaf = true
26 entry({"admin", "status", "realtime", "bandwidth"}, template("admin_status/bandwidth"), _("Traffic"), 2).leaf = true
27 entry({"admin", "status", "realtime", "bandwidth_status"}, call("action_bandwidth")).leaf = true
29 page = entry({"admin", "status", "realtime", "wireless"}, template("admin_status/wireless"), _("Wireless"), 3)
30 page.uci_depends = { wireless = true }
33 page = entry({"admin", "status", "realtime", "wireless_status"}, call("action_wireless"))
34 page.uci_depends = { wireless = true }
37 entry({"admin", "status", "realtime", "connections"}, template("admin_status/connections"), _("Connections"), 4).leaf = true
38 entry({"admin", "status", "realtime", "connections_status"}, call("action_connections")).leaf = true
40 entry({"admin", "status", "nameinfo"}, call("action_nameinfo")).leaf = true
43 function action_syslog()
44 local syslog = luci.sys.syslog()
45 luci.template.render("admin_status/syslog", {syslog=syslog})
48 function action_dmesg()
49 local dmesg = luci.sys.dmesg()
50 luci.template.render("admin_status/dmesg", {dmesg=dmesg})
53 function dump_iptables(family, table)
54 local prefix = (family == "6") and "ip6" or "ip"
55 local ok, lines = pcall(io.lines, "/proc/net/%s_tables_names" % prefix)
60 luci.http.prepare_content("text/plain")
61 luci.sys.process.exec({
62 "/usr/sbin/%stables" % prefix, "-w", "-t", table,
63 "--line-numbers", "-nxvL"
70 luci.http.status(404, "No such table")
71 luci.http.prepare_content("text/plain")
74 function action_iptables()
75 if luci.http.formvalue("zero") then
76 if luci.http.formvalue("family") == "6" then
77 luci.util.exec("/usr/sbin/ip6tables -Z")
79 luci.util.exec("/usr/sbin/iptables -Z")
81 elseif luci.http.formvalue("restart") then
82 luci.util.exec("/etc/init.d/firewall restart")
85 luci.http.redirect(luci.dispatcher.build_url("admin/status/iptables"))
88 function action_bandwidth(iface)
89 luci.http.prepare_content("application/json")
91 local bwc = io.popen("luci-bwc -i %s 2>/dev/null"
92 % luci.util.shellquote(iface))
98 local ln = bwc:read("*l")
99 if not ln then break end
108 function action_wireless(iface)
109 luci.http.prepare_content("application/json")
111 local bwc = io.popen("luci-bwc -r %s 2>/dev/null"
112 % luci.util.shellquote(iface))
118 local ln = bwc:read("*l")
119 if not ln then break end
128 function action_load()
129 luci.http.prepare_content("application/json")
131 local bwc = io.popen("luci-bwc -l 2>/dev/null")
136 local ln = bwc:read("*l")
137 if not ln then break end
146 function action_connections()
147 local sys = require "luci.sys"
149 luci.http.prepare_content("application/json")
151 luci.http.write('{ "connections": ')
152 luci.http.write_json(sys.net.conntrack())
154 local bwc = io.popen("luci-bwc -c 2>/dev/null")
156 luci.http.write(', "statistics": [')
159 local ln = bwc:read("*l")
160 if not ln then break end
168 luci.http.write(" }")
171 function action_nameinfo(...)
172 local util = require "luci.util"
174 luci.http.prepare_content("application/json")
175 luci.http.write_json(util.ubus("network.rrdns", "lookup", {