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", "interfaces"), i18n("Status"), 20).index = true
22 entry({"admin", "status", "interfaces"}, 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
38 function action_syslog()
39 local syslog = luci.sys.syslog()
40 luci.template.render("admin_status/syslog", {syslog=syslog})
43 function action_dmesg()
44 local dmesg = luci.sys.dmesg()
45 luci.template.render("admin_status/dmesg", {dmesg=dmesg})
48 function action_iptables()
49 if luci.http.formvalue("zero") then
50 if luci.http.formvalue("zero") == "6" then
51 luci.util.exec("ip6tables -Z")
53 luci.util.exec("iptables -Z")
56 luci.dispatcher.build_url("admin", "status", "iptables")
58 elseif luci.http.formvalue("restart") == "1" then
59 luci.util.exec("/etc/init.d/firewall restart")
61 luci.dispatcher.build_url("admin", "status", "iptables")
64 luci.template.render("admin_status/iptables")
68 function action_bandwidth()
69 local path = luci.dispatcher.context.requestpath
70 local iface = path[#path]
72 local fs = require "luci.fs"
73 if fs.access("/var/lib/luci-bwc/if/%s" % iface) then
74 luci.http.prepare_content("application/json")
76 local bwc = io.popen("luci-bwc -i %q 2>/dev/null" % iface)
81 local ln = bwc:read("*l")
82 if not ln then break end
93 luci.http.status(404, "No data available")
96 function action_load()
97 local fs = require "luci.fs"
98 if fs.access("/var/lib/luci-bwc/load") then
99 luci.http.prepare_content("application/json")
101 local bwc = io.popen("luci-bwc -l 2>/dev/null")
106 local ln = bwc:read("*l")
107 if not ln then break end
118 luci.http.status(404, "No data available")
121 function action_connections()
122 local fs = require "luci.fs"
123 local sys = require "luci.sys"
125 luci.http.prepare_content("application/json")
127 luci.http.write("{ connections: ")
128 luci.http.write_json(sys.net.conntrack())
130 if fs.access("/var/lib/luci-bwc/connections") then
131 local bwc = io.popen("luci-bwc -c 2>/dev/null")
133 luci.http.write(", statistics: [")
136 local ln = bwc:read("*l")
137 if not ln then break end
146 luci.http.write(" }")