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