root/luci/trunk/modules/admin-full/luasrc/controller/admin/status.lua @ 7362

Revision 7362, 3.9 KB (checked in by jow, 22 months ago)

applications, modules: remove i18n handling from controller modules as it moved to the themes now

  • Property svn:keywords set to Id
Line 
1--[[
2LuCI - Lua Configuration Interface
3
4Copyright 2008 Steven Barth <steven@midlink.org>
5Copyright 2011 Jo-Philipp Wich <xm@subsignal.org>
6
7Licensed under the Apache License, Version 2.0 (the "License");
8you may not use this file except in compliance with the License.
9You may obtain a copy of the License at
10
11    http://www.apache.org/licenses/LICENSE-2.0
12
13$Id$
14]]--
15
16module("luci.controller.admin.status", package.seeall)
17
18function 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", "connections"}, template("admin_status/connections"), _("Realtime Connections"), 8).leaf = true
33    entry({"admin", "status", "connections_status"}, call("action_connections")).leaf = true
34
35    entry({"admin", "status", "processes"}, cbi("admin_status/processes"), _("Processes"), 20)
36end
37
38function action_syslog()
39    local syslog = luci.sys.syslog()
40    luci.template.render("admin_status/syslog", {syslog=syslog})
41end
42
43function action_dmesg()
44    local dmesg = luci.sys.dmesg()
45    luci.template.render("admin_status/dmesg", {dmesg=dmesg})
46end
47
48function action_iptables()
49    if luci.http.formvalue("zero") then
50        if luci.http.formvalue("zero") == "6" then
51            luci.util.exec("ip6tables -Z")
52        else
53            luci.util.exec("iptables -Z")
54        end
55        luci.http.redirect(
56            luci.dispatcher.build_url("admin", "status", "iptables")
57        )
58    elseif luci.http.formvalue("restart") == "1" then
59        luci.util.exec("/etc/init.d/firewall restart")
60        luci.http.redirect(
61            luci.dispatcher.build_url("admin", "status", "iptables")
62        )
63    else
64        luci.template.render("admin_status/iptables")
65    end
66end
67
68function action_bandwidth()
69    local path  = luci.dispatcher.context.requestpath
70    local iface = path[#path]
71
72    local fs = require "luci.fs"
73    if fs.access("/var/lib/luci-bwc/if/%s" % iface) then
74        luci.http.prepare_content("application/json")
75
76        local bwc = io.popen("luci-bwc -i %q 2>/dev/null" % iface)
77        if bwc then
78            luci.http.write("[")
79
80            while true do
81                local ln = bwc:read("*l")
82                if not ln then break end
83                luci.http.write(ln)
84            end
85
86            luci.http.write("]")
87            bwc:close()
88        end
89
90        return
91    end
92
93    luci.http.status(404, "No data available")
94end
95
96function action_load()
97    local fs = require "luci.fs"
98    if fs.access("/var/lib/luci-bwc/load") then
99        luci.http.prepare_content("application/json")
100
101        local bwc = io.popen("luci-bwc -l 2>/dev/null")
102        if bwc then
103            luci.http.write("[")
104
105            while true do
106                local ln = bwc:read("*l")
107                if not ln then break end
108                luci.http.write(ln)
109            end
110
111            luci.http.write("]")
112            bwc:close()
113        end
114
115        return
116    end
117
118    luci.http.status(404, "No data available")
119end
120
121function action_connections()
122    local fs  = require "luci.fs"
123    local sys = require "luci.sys"
124
125    luci.http.prepare_content("application/json")
126
127    luci.http.write("{ connections: ")
128    luci.http.write_json(sys.net.conntrack())
129
130    if fs.access("/var/lib/luci-bwc/connections") then
131        local bwc = io.popen("luci-bwc -c 2>/dev/null")
132        if bwc then
133            luci.http.write(", statistics: [")
134
135            while true do
136                local ln = bwc:read("*l")
137                if not ln then break end
138                luci.http.write(ln)
139            end
140
141            luci.http.write("]")
142            bwc:close()
143        end
144    end
145
146    luci.http.write(" }")
147end
Note: See TracBrowser for help on using the browser.