status.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. module("luci.controller.admin.status", package.seeall)
  5. function index()
  6. entry({"admin", "status"}, alias("admin", "status", "overview"), _("Status"), 20).index = true
  7. entry({"admin", "status", "overview"}, template("admin_status/index"), _("Overview"), 1)
  8. entry({"admin", "status", "iptables"}, template("admin_status/iptables"), _("Firewall"), 2).leaf = true
  9. entry({"admin", "status", "iptables_action"}, post("action_iptables")).leaf = true
  10. entry({"admin", "status", "routes"}, template("admin_status/routes"), _("Routes"), 3)
  11. entry({"admin", "status", "syslog"}, call("action_syslog"), _("System Log"), 4)
  12. entry({"admin", "status", "dmesg"}, call("action_dmesg"), _("Kernel Log"), 5)
  13. entry({"admin", "status", "processes"}, cbi("admin_status/processes"), _("Processes"), 6)
  14. entry({"admin", "status", "realtime"}, alias("admin", "status", "realtime", "load"), _("Realtime Graphs"), 7)
  15. entry({"admin", "status", "realtime", "load"}, template("admin_status/load"), _("Load"), 1).leaf = true
  16. entry({"admin", "status", "realtime", "load_status"}, call("action_load")).leaf = true
  17. entry({"admin", "status", "realtime", "bandwidth"}, template("admin_status/bandwidth"), _("Traffic"), 2).leaf = true
  18. entry({"admin", "status", "realtime", "bandwidth_status"}, call("action_bandwidth")).leaf = true
  19. if nixio.fs.access("/etc/config/wireless") then
  20. entry({"admin", "status", "realtime", "wireless"}, template("admin_status/wireless"), _("Wireless"), 3).leaf = true
  21. entry({"admin", "status", "realtime", "wireless_status"}, call("action_wireless")).leaf = true
  22. end
  23. entry({"admin", "status", "realtime", "connections"}, template("admin_status/connections"), _("Connections"), 4).leaf = true
  24. entry({"admin", "status", "realtime", "connections_status"}, call("action_connections")).leaf = true
  25. entry({"admin", "status", "nameinfo"}, call("action_nameinfo")).leaf = true
  26. end
  27. function action_syslog()
  28. local syslog = luci.sys.syslog()
  29. luci.template.render("admin_status/syslog", {syslog=syslog})
  30. end
  31. function action_dmesg()
  32. local dmesg = luci.sys.dmesg()
  33. luci.template.render("admin_status/dmesg", {dmesg=dmesg})
  34. end
  35. function action_iptables()
  36. if luci.http.formvalue("zero") then
  37. if luci.http.formvalue("family") == "6" then
  38. luci.util.exec("/usr/sbin/ip6tables -Z")
  39. else
  40. luci.util.exec("/usr/sbin/iptables -Z")
  41. end
  42. elseif luci.http.formvalue("restart") then
  43. luci.util.exec("/etc/init.d/firewall restart")
  44. end
  45. luci.http.redirect(luci.dispatcher.build_url("admin/status/iptables"))
  46. end
  47. function action_bandwidth(iface)
  48. luci.http.prepare_content("application/json")
  49. local bwc = io.popen("luci-bwc -i %q 2>/dev/null" % iface)
  50. if bwc then
  51. luci.http.write("[")
  52. while true do
  53. local ln = bwc:read("*l")
  54. if not ln then break end
  55. luci.http.write(ln)
  56. end
  57. luci.http.write("]")
  58. bwc:close()
  59. end
  60. end
  61. function action_wireless(iface)
  62. luci.http.prepare_content("application/json")
  63. local bwc = io.popen("luci-bwc -r %q 2>/dev/null" % iface)
  64. if bwc then
  65. luci.http.write("[")
  66. while true do
  67. local ln = bwc:read("*l")
  68. if not ln then break end
  69. luci.http.write(ln)
  70. end
  71. luci.http.write("]")
  72. bwc:close()
  73. end
  74. end
  75. function action_load()
  76. luci.http.prepare_content("application/json")
  77. local bwc = io.popen("luci-bwc -l 2>/dev/null")
  78. if bwc then
  79. luci.http.write("[")
  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. luci.http.write("]")
  86. bwc:close()
  87. end
  88. end
  89. function action_connections()
  90. local sys = require "luci.sys"
  91. luci.http.prepare_content("application/json")
  92. luci.http.write("{ connections: ")
  93. luci.http.write_json(sys.net.conntrack())
  94. local bwc = io.popen("luci-bwc -c 2>/dev/null")
  95. if bwc then
  96. luci.http.write(", statistics: [")
  97. while true do
  98. local ln = bwc:read("*l")
  99. if not ln then break end
  100. luci.http.write(ln)
  101. end
  102. luci.http.write("]")
  103. bwc:close()
  104. end
  105. luci.http.write(" }")
  106. end
  107. function action_nameinfo(...)
  108. local i
  109. local rv = { }
  110. for i = 1, select('#', ...) do
  111. local addr = select(i, ...)
  112. local fqdn = nixio.getnameinfo(addr)
  113. rv[addr] = fqdn or (addr:match(":") and "[%s]" % addr or addr)
  114. end
  115. luci.http.prepare_content("application/json")
  116. luci.http.write_json(rv)
  117. end