modules/admin-full: add ip6tables status output (#193)
[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 Copyright 2011 Jo-Philipp Wich <xm@subsignal.org>
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11         http://www.apache.org/licenses/LICENSE-2.0
12
13 $Id$
14 ]]--
15 module("luci.controller.admin.status", package.seeall)
16
17 function index()
18         luci.i18n.loadc("base")
19         local i18n = luci.i18n.translate
20
21         entry({"admin", "status"}, template("admin_status/index"), i18n("Status"), 20).index = true
22         entry({"admin", "status", "interfaces"}, template("admin_status/interfaces"), i18n("Interfaces"), 1)
23         entry({"admin", "status", "iptables"}, call("action_iptables"), i18n("Firewall"), 2).leaf = true
24         entry({"admin", "status", "conntrack"}, template("admin_status/conntrack"), i18n("Active Connections"), 3)
25         entry({"admin", "status", "routes"}, template("admin_status/routes"), i18n("Routes"), 4)
26         entry({"admin", "status", "syslog"}, call("action_syslog"), i18n("System Log"), 5)
27         entry({"admin", "status", "dmesg"}, call("action_dmesg"), i18n("Kernel Log"), 6)
28
29         entry({"admin", "status", "load"}, template("admin_status/load"), i18n("Realtime Load"), 7).leaf = true
30         entry({"admin", "status", "load_status"}, call("action_load")).leaf = true
31
32         entry({"admin", "status", "bandwidth"}, template("admin_status/bandwidth"), i18n("Realtime Traffic"), 8).leaf = true
33         entry({"admin", "status", "bandwidth_status"}, call("action_bandwidth")).leaf = true
34
35         entry({"admin", "status", "connections"}, template("admin_status/connections"), i18n("Realtime Connections"), 9).leaf = true
36         entry({"admin", "status", "connections_status"}, call("action_connections")).leaf = true
37 end
38
39 function action_syslog()
40         local syslog = luci.sys.syslog()
41         luci.template.render("admin_status/syslog", {syslog=syslog})
42 end
43
44 function action_dmesg()
45         local dmesg = luci.sys.dmesg()
46         luci.template.render("admin_status/dmesg", {dmesg=dmesg})
47 end
48
49 function action_iptables()
50         if luci.http.formvalue("zero") then
51                 if luci.http.formvalue("zero") == "6" then
52                         luci.util.exec("ip6tables -Z")
53                 else
54                         luci.util.exec("iptables -Z")
55                 end
56                 luci.http.redirect(
57                         luci.dispatcher.build_url("admin", "status", "iptables")
58                 )
59         elseif luci.http.formvalue("restart") == "1" then
60                 luci.util.exec("/etc/init.d/firewall restart")
61                 luci.http.redirect(
62                         luci.dispatcher.build_url("admin", "status", "iptables")
63                 )
64         else
65                 luci.template.render("admin_status/iptables")
66         end
67 end
68
69 function action_bandwidth()
70         local path  = luci.dispatcher.context.requestpath
71         local iface = path[#path]
72
73         local fs = require "luci.fs"
74         if fs.access("/var/lib/luci-bwc/if/%s" % iface) then
75                 luci.http.prepare_content("application/json")
76
77                 local bwc = io.popen("luci-bwc -i %q 2>/dev/null" % iface)
78                 if bwc then
79                         luci.http.write("[")
80
81                         while true do
82                                 local ln = bwc:read("*l")
83                                 if not ln then break end
84                                 luci.http.write(ln)
85                         end
86
87                         luci.http.write("]")
88                         bwc:close()
89                 end
90
91                 return
92         end
93
94         luci.http.status(404, "No data available")
95 end
96
97 function action_load()
98         local fs = require "luci.fs"
99         if fs.access("/var/lib/luci-bwc/load") then
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
116                 return
117         end
118
119         luci.http.status(404, "No data available")
120 end
121
122 function action_connections()
123         local fs = require "luci.fs"
124         if fs.access("/var/lib/luci-bwc/connections") then
125                 luci.http.prepare_content("application/json")
126
127                 local bwc = io.popen("luci-bwc -c 2>/dev/null")
128                 if bwc then
129                         luci.http.write("[")
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                 return
142         end
143
144         luci.http.status(404, "No data available")
145 end