89ebda735304dfd2f28bf1c5bddcd5917f376890
[project/luci.git] / modules / admin-full / luasrc / controller / admin / status.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2011 Jo-Philipp Wich <xm@subsignal.org>
6
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
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 $Id$
14 ]]--
15
16 module("luci.controller.admin.status", package.seeall)
17
18 function index()
19 entry({"admin", "status"}, alias("admin", "status", "overview"), _("Status"), 20).index = true
20 entry({"admin", "status", "overview"}, template("admin_status/index"), _("Overview"), 1)
21 entry({"admin", "status", "iptables"}, call("action_iptables"), _("Firewall"), 2).leaf = true
22 entry({"admin", "status", "routes"}, template("admin_status/routes"), _("Routes"), 3)
23 entry({"admin", "status", "syslog"}, call("action_syslog"), _("System Log"), 4)
24 entry({"admin", "status", "dmesg"}, call("action_dmesg"), _("Kernel Log"), 5)
25 entry({"admin", "status", "processes"}, cbi("admin_status/processes"), _("Processes"), 6)
26
27 entry({"admin", "status", "realtime"}, alias("admin", "status", "realtime", "load"), _("Realtime Graphs"), 7)
28
29 entry({"admin", "status", "realtime", "load"}, template("admin_status/load"), _("Load"), 1).leaf = true
30 entry({"admin", "status", "realtime", "load_status"}, call("action_load")).leaf = true
31
32 entry({"admin", "status", "realtime", "bandwidth"}, template("admin_status/bandwidth"), _("Traffic"), 2).leaf = true
33 entry({"admin", "status", "realtime", "bandwidth_status"}, call("action_bandwidth")).leaf = true
34
35 entry({"admin", "status", "realtime", "wireless"}, template("admin_status/wireless"), _("Wireless"), 3).leaf = true
36 entry({"admin", "status", "realtime", "wireless_status"}, call("action_wireless")).leaf = true
37
38 entry({"admin", "status", "realtime", "connections"}, template("admin_status/connections"), _("Connections"), 4).leaf = true
39 entry({"admin", "status", "realtime", "connections_status"}, call("action_connections")).leaf = true
40
41 entry({"admin", "status", "nameinfo"}, call("action_nameinfo")).leaf = true
42 end
43
44 function action_syslog()
45 local syslog = luci.sys.syslog()
46 luci.template.render("admin_status/syslog", {syslog=syslog})
47 end
48
49 function action_dmesg()
50 local dmesg = luci.sys.dmesg()
51 luci.template.render("admin_status/dmesg", {dmesg=dmesg})
52 end
53
54 function action_iptables()
55 if luci.http.formvalue("zero") then
56 if luci.http.formvalue("zero") == "6" then
57 luci.util.exec("ip6tables -Z")
58 else
59 luci.util.exec("iptables -Z")
60 end
61 luci.http.redirect(
62 luci.dispatcher.build_url("admin", "status", "iptables")
63 )
64 elseif luci.http.formvalue("restart") == "1" then
65 luci.util.exec("/etc/init.d/firewall reload")
66 luci.http.redirect(
67 luci.dispatcher.build_url("admin", "status", "iptables")
68 )
69 else
70 luci.template.render("admin_status/iptables")
71 end
72 end
73
74 function action_bandwidth(iface)
75 luci.http.prepare_content("application/json")
76
77 local bwc = io.popen("luci-bwc -i %q 2>/dev/null" % iface)
78 if bwc then
79 luci.http.write("[")
80
81 while true do
82 local ln = bwc:read("*l")
83 if not ln then break end
84 luci.http.write(ln)
85 end
86
87 luci.http.write("]")
88 bwc:close()
89 end
90 end
91
92 function action_wireless(iface)
93 luci.http.prepare_content("application/json")
94
95 local bwc = io.popen("luci-bwc -r %q 2>/dev/null" % iface)
96 if bwc then
97 luci.http.write("[")
98
99 while true do
100 local ln = bwc:read("*l")
101 if not ln then break end
102 luci.http.write(ln)
103 end
104
105 luci.http.write("]")
106 bwc:close()
107 end
108 end
109
110 function action_load()
111 luci.http.prepare_content("application/json")
112
113 local bwc = io.popen("luci-bwc -l 2>/dev/null")
114 if bwc then
115 luci.http.write("[")
116
117 while true do
118 local ln = bwc:read("*l")
119 if not ln then break end
120 luci.http.write(ln)
121 end
122
123 luci.http.write("]")
124 bwc:close()
125 end
126 end
127
128 function action_connections()
129 local sys = require "luci.sys"
130
131 luci.http.prepare_content("application/json")
132
133 luci.http.write("{ connections: ")
134 luci.http.write_json(sys.net.conntrack())
135
136 local bwc = io.popen("luci-bwc -c 2>/dev/null")
137 if bwc then
138 luci.http.write(", statistics: [")
139
140 while true do
141 local ln = bwc:read("*l")
142 if not ln then break end
143 luci.http.write(ln)
144 end
145
146 luci.http.write("]")
147 bwc:close()
148 end
149
150 luci.http.write(" }")
151 end
152
153 function action_nameinfo(...)
154 local i
155 local rv = { }
156 for i = 1, select('#', ...) do
157 local addr = select(i, ...)
158 local fqdn = nixio.getnameinfo(addr)
159 rv[addr] = fqdn or (addr:match(":") and "[%s]" % addr or addr)
160 end
161
162 luci.http.prepare_content("application/json")
163 luci.http.write_json(rv)
164 end