modules/admin-full: add wireless live stats
[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         local function _(x) return x end
20
21         entry({"admin", "status"}, alias("admin", "status", "overview"), _("Status"), 20).index = true
22         entry({"admin", "status", "overview"}, template("admin_status/index"), _("Overview"), 1)
23         entry({"admin", "status", "iptables"}, call("action_iptables"), _("Firewall"), 2).leaf = true
24         entry({"admin", "status", "routes"}, template("admin_status/routes"), _("Routes"), 3)
25         entry({"admin", "status", "syslog"}, call("action_syslog"), _("System Log"), 4)
26         entry({"admin", "status", "dmesg"}, call("action_dmesg"), _("Kernel Log"), 5)
27
28         entry({"admin", "status", "load"}, template("admin_status/load"), _("Realtime Load"), 6).leaf = true
29         entry({"admin", "status", "load_status"}, call("action_load")).leaf = true
30
31         entry({"admin", "status", "bandwidth"}, template("admin_status/bandwidth"), _("Realtime Traffic"), 7).leaf = true
32         entry({"admin", "status", "bandwidth_status"}, call("action_bandwidth")).leaf = true
33
34         entry({"admin", "status", "wireless"}, template("admin_status/wireless"), _("Realtime Wireless"), 8).leaf = true
35         entry({"admin", "status", "wireless_status"}, call("action_wireless")).leaf = true
36
37         entry({"admin", "status", "connections"}, template("admin_status/connections"), _("Realtime Connections"), 9).leaf = true
38         entry({"admin", "status", "connections_status"}, call("action_connections")).leaf = true
39
40         entry({"admin", "status", "processes"}, cbi("admin_status/processes"), _("Processes"), 20)
41 end
42
43 function action_syslog()
44         local syslog = luci.sys.syslog()
45         luci.template.render("admin_status/syslog", {syslog=syslog})
46 end
47
48 function action_dmesg()
49         local dmesg = luci.sys.dmesg()
50         luci.template.render("admin_status/dmesg", {dmesg=dmesg})
51 end
52
53 function action_iptables()
54         if luci.http.formvalue("zero") then
55                 if luci.http.formvalue("zero") == "6" then
56                         luci.util.exec("ip6tables -Z")
57                 else
58                         luci.util.exec("iptables -Z")
59                 end
60                 luci.http.redirect(
61                         luci.dispatcher.build_url("admin", "status", "iptables")
62                 )
63         elseif luci.http.formvalue("restart") == "1" then
64                 luci.util.exec("/etc/init.d/firewall restart")
65                 luci.http.redirect(
66                         luci.dispatcher.build_url("admin", "status", "iptables")
67                 )
68         else
69                 luci.template.render("admin_status/iptables")
70         end
71 end
72
73 function action_bandwidth()
74         local path  = luci.dispatcher.context.requestpath
75         local iface = path[#path]
76
77         luci.http.prepare_content("application/json")
78
79         local bwc = io.popen("luci-bwc -i %q 2>/dev/null" % iface)
80         if bwc then
81                 luci.http.write("[")
82
83                 while true do
84                         local ln = bwc:read("*l")
85                         if not ln then break end
86                         luci.http.write(ln)
87                 end
88
89                 luci.http.write("]")
90                 bwc:close()
91         end
92 end
93
94 function action_wireless()
95         local path  = luci.dispatcher.context.requestpath
96         local iface = path[#path]
97
98         luci.http.prepare_content("application/json")
99
100         local bwc = io.popen("luci-bwc -r %q 2>/dev/null" % iface)
101         if bwc then
102                 luci.http.write("[")
103
104                 while true do
105                         local ln = bwc:read("*l")
106                         if not ln then break end
107                         luci.http.write(ln)
108                 end
109
110                 luci.http.write("]")
111                 bwc:close()
112         end
113 end
114
115 function action_load()
116         luci.http.prepare_content("application/json")
117
118         local bwc = io.popen("luci-bwc -l 2>/dev/null")
119         if bwc then
120                 luci.http.write("[")
121
122                 while true do
123                         local ln = bwc:read("*l")
124                         if not ln then break end
125                         luci.http.write(ln)
126                 end
127
128                 luci.http.write("]")
129                 bwc:close()
130         end
131 end
132
133 function action_connections()
134         local sys = require "luci.sys"
135
136         luci.http.prepare_content("application/json")
137
138         luci.http.write("{ connections: ")
139         luci.http.write_json(sys.net.conntrack())
140
141         local bwc = io.popen("luci-bwc -c 2>/dev/null")
142         if bwc then
143                 luci.http.write(", statistics: [")
144
145                 while true do
146                         local ln = bwc:read("*l")
147                         if not ln then break end
148                         luci.http.write(ln)
149                 end
150
151                 luci.http.write("]")
152                 bwc:close()
153         end
154
155         luci.http.write(" }")
156 end