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