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