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