modules/admin-full: implement connection graph, cross browser fixes
[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
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10         http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13 ]]--
14 module("luci.controller.admin.status", package.seeall)
15
16 function index()
17         luci.i18n.loadc("base")
18         local i18n = luci.i18n.translate
19
20         entry({"admin", "status"}, template("admin_status/index"), i18n("Status"), 20).index = true
21         entry({"admin", "status", "interfaces"}, template("admin_status/interfaces"), i18n("Interfaces"), 1)
22         entry({"admin", "status", "iptables"}, call("action_iptables"), i18n("Firewall"), 2)
23         entry({"admin", "status", "conntrack"}, template("admin_status/conntrack"), i18n("Active Connections"), 3)
24         entry({"admin", "status", "routes"}, template("admin_status/routes"), i18n("Routes"), 4)
25         entry({"admin", "status", "syslog"}, call("action_syslog"), i18n("System Log"), 5)
26         entry({"admin", "status", "dmesg"}, call("action_dmesg"), i18n("Kernel Log"), 6)
27
28         entry({"admin", "status", "load"}, template("admin_status/load"), i18n("Realtime Load"), 7).leaf = true
29         entry({"admin", "status", "load_status"}, call("action_load")).leaf = true
30
31         entry({"admin", "status", "bandwidth"}, template("admin_status/bandwidth"), i18n("Realtime Traffic"), 8).leaf = true
32         entry({"admin", "status", "bandwidth_status"}, call("action_bandwidth")).leaf = true
33
34         entry({"admin", "status", "connections"}, template("admin_status/connections"), i18n("Realtime Connections"), 9).leaf = true
35         entry({"admin", "status", "connections_status"}, call("action_connections")).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") == "1" then
50                 luci.util.exec("iptables -Z")
51                 luci.http.redirect(
52                         luci.dispatcher.build_url("admin", "status", "iptables")
53                 )
54         elseif luci.http.formvalue("restart") == "1" then
55                 luci.util.exec("/etc/init.d/firewall restart")
56                 luci.http.redirect(
57                         luci.dispatcher.build_url("admin", "status", "iptables")
58                 )
59         else
60                 luci.template.render("admin_status/iptables")
61         end
62 end
63
64 function action_bandwidth()
65         local path  = luci.dispatcher.context.requestpath
66         local iface = path[#path]
67
68         local fs = require "luci.fs"
69         if fs.access("/var/lib/luci-bwc/if/%s" % iface) then
70                 luci.http.prepare_content("application/json")
71
72                 local bwc = io.popen("luci-bwc -i %q 2>/dev/null" % iface)
73                 if bwc then
74                         luci.http.write("[")
75
76                         while true do
77                                 local ln = bwc:read("*l")
78                                 if not ln then break end
79                                 luci.http.write(ln)
80                         end
81
82                         luci.http.write("]")
83                         bwc:close()
84                 end
85
86                 return
87         end
88
89         luci.http.status(404, "No data available")
90 end
91
92 function action_load()
93         local fs = require "luci.fs"
94         if fs.access("/var/lib/luci-bwc/load") then
95                 luci.http.prepare_content("application/json")
96
97                 local bwc = io.popen("luci-bwc -l 2>/dev/null")
98                 if bwc then
99                         luci.http.write("[")
100
101                         while true do
102                                 local ln = bwc:read("*l")
103                                 if not ln then break end
104                                 luci.http.write(ln)
105                         end
106
107                         luci.http.write("]")
108                         bwc:close()
109                 end
110
111                 return
112         end
113
114         luci.http.status(404, "No data available")
115 end
116
117 function action_connections()
118         local fs = require "luci.fs"
119         if fs.access("/var/lib/luci-bwc/connections") then
120                 luci.http.prepare_content("application/json")
121
122                 local bwc = io.popen("luci-bwc -c 2>/dev/null")
123                 if bwc then
124                         luci.http.write("[")
125
126                         while true do
127                                 local ln = bwc:read("*l")
128                                 if not ln then break end
129                                 luci.http.write(ln)
130                         end
131
132                         luci.http.write("]")
133                         bwc:close()
134                 end
135
136                 return
137         end
138
139         luci.http.status(404, "No data available")
140 end