f77d91b3434552aa833705c48c638f3bd8602094
[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 end
41
42 function action_syslog()
43         local syslog = luci.sys.syslog()
44         luci.template.render("admin_status/syslog", {syslog=syslog})
45 end
46
47 function action_dmesg()
48         local dmesg = luci.sys.dmesg()
49         luci.template.render("admin_status/dmesg", {dmesg=dmesg})
50 end
51
52 function action_iptables()
53         if luci.http.formvalue("zero") then
54                 if luci.http.formvalue("zero") == "6" then
55                         luci.util.exec("ip6tables -Z")
56                 else
57                         luci.util.exec("iptables -Z")
58                 end
59                 luci.http.redirect(
60                         luci.dispatcher.build_url("admin", "status", "iptables")
61                 )
62         elseif luci.http.formvalue("restart") == "1" then
63                 luci.util.exec("/etc/init.d/firewall restart")
64                 luci.http.redirect(
65                         luci.dispatcher.build_url("admin", "status", "iptables")
66                 )
67         else
68                 luci.template.render("admin_status/iptables")
69         end
70 end
71
72 function action_bandwidth()
73         local path  = luci.dispatcher.context.requestpath
74         local iface = path[#path]
75
76         luci.http.prepare_content("application/json")
77
78         local bwc = io.popen("luci-bwc -i %q 2>/dev/null" % iface)
79         if bwc then
80                 luci.http.write("[")
81
82                 while true do
83                         local ln = bwc:read("*l")
84                         if not ln then break end
85                         luci.http.write(ln)
86                 end
87
88                 luci.http.write("]")
89                 bwc:close()
90         end
91 end
92
93 function action_wireless()
94         local path  = luci.dispatcher.context.requestpath
95         local iface = path[#path]
96
97         luci.http.prepare_content("application/json")
98
99         local bwc = io.popen("luci-bwc -r %q 2>/dev/null" % iface)
100         if bwc then
101                 luci.http.write("[")
102
103                 while true do
104                         local ln = bwc:read("*l")
105                         if not ln then break end
106                         luci.http.write(ln)
107                 end
108
109                 luci.http.write("]")
110                 bwc:close()
111         end
112 end
113
114 function action_load()
115         luci.http.prepare_content("application/json")
116
117         local bwc = io.popen("luci-bwc -l 2>/dev/null")
118         if bwc then
119                 luci.http.write("[")
120
121                 while true do
122                         local ln = bwc:read("*l")
123                         if not ln then break end
124                         luci.http.write(ln)
125                 end
126
127                 luci.http.write("]")
128                 bwc:close()
129         end
130 end
131
132 function action_connections()
133         local sys = require "luci.sys"
134
135         luci.http.prepare_content("application/json")
136
137         luci.http.write("{ connections: ")
138         luci.http.write_json(sys.net.conntrack())
139
140         local bwc = io.popen("luci-bwc -c 2>/dev/null")
141         if bwc then
142                 luci.http.write(", statistics: [")
143
144                 while true do
145                         local ln = bwc:read("*l")
146                         if not ln then break end
147                         luci.http.write(ln)
148                 end
149
150                 luci.http.write("]")
151                 bwc:close()
152         end
153
154         luci.http.write(" }")
155 end