status.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. entry({"admin", "status", "realtime", "wireless"}, template("admin_status/wireless"), _("Wireless"), 3).leaf = true
  20. entry({"admin", "status", "realtime", "wireless_status"}, call("action_wireless")).leaf = true
  21. entry({"admin", "status", "realtime", "connections"}, template("admin_status/connections"), _("Connections"), 4).leaf = true
  22. entry({"admin", "status", "realtime", "connections_status"}, call("action_connections")).leaf = true
  23. entry({"admin", "status", "nameinfo"}, call("action_nameinfo")).leaf = true
  24. end
  25. function action_syslog()
  26. local syslog = luci.sys.syslog()
  27. luci.template.render("admin_status/syslog", {syslog=syslog})
  28. end
  29. function action_dmesg()
  30. local dmesg = luci.sys.dmesg()
  31. luci.template.render("admin_status/dmesg", {dmesg=dmesg})
  32. end
  33. function action_iptables()
  34. if luci.http.formvalue("zero") then
  35. if luci.http.formvalue("family") == "6" then
  36. luci.util.exec("/usr/sbin/ip6tables -Z")
  37. else
  38. luci.util.exec("/usr/sbin/iptables -Z")
  39. end
  40. elseif luci.http.formvalue("restart") then
  41. luci.util.exec("/etc/init.d/firewall restart")
  42. end
  43. luci.http.redirect(luci.dispatcher.build_url("admin/status/iptables"))
  44. end
  45. function action_bandwidth(iface)
  46. luci.http.prepare_content("application/json")
  47. local bwc = io.popen("luci-bwc -i %q 2>/dev/null" % iface)
  48. if bwc then
  49. luci.http.write("[")
  50. while true do
  51. local ln = bwc:read("*l")
  52. if not ln then break end
  53. luci.http.write(ln)
  54. end
  55. luci.http.write("]")
  56. bwc:close()
  57. end
  58. end
  59. function action_wireless(iface)
  60. luci.http.prepare_content("application/json")
  61. local bwc = io.popen("luci-bwc -r %q 2>/dev/null" % iface)
  62. if bwc then
  63. luci.http.write("[")
  64. while true do
  65. local ln = bwc:read("*l")
  66. if not ln then break end
  67. luci.http.write(ln)
  68. end
  69. luci.http.write("]")
  70. bwc:close()
  71. end
  72. end
  73. function action_load()
  74. luci.http.prepare_content("application/json")
  75. local bwc = io.popen("luci-bwc -l 2>/dev/null")
  76. if bwc then
  77. luci.http.write("[")
  78. while true do
  79. local ln = bwc:read("*l")
  80. if not ln then break end
  81. luci.http.write(ln)
  82. end
  83. luci.http.write("]")
  84. bwc:close()
  85. end
  86. end
  87. function action_connections()
  88. local sys = require "luci.sys"
  89. luci.http.prepare_content("application/json")
  90. luci.http.write("{ connections: ")
  91. luci.http.write_json(sys.net.conntrack())
  92. local bwc = io.popen("luci-bwc -c 2>/dev/null")
  93. if bwc then
  94. luci.http.write(", statistics: [")
  95. while true do
  96. local ln = bwc:read("*l")
  97. if not ln then break end
  98. luci.http.write(ln)
  99. end
  100. luci.http.write("]")
  101. bwc:close()
  102. end
  103. luci.http.write(" }")
  104. end
  105. function action_nameinfo(...)
  106. local i
  107. local rv = { }
  108. for i = 1, select('#', ...) do
  109. local addr = select(i, ...)
  110. local fqdn = nixio.getnameinfo(addr)
  111. rv[addr] = fqdn or (addr:match(":") and "[%s]" % addr or addr)
  112. end
  113. luci.http.prepare_content("application/json")
  114. luci.http.write_json(rv)
  115. end