status.lua 4.3 KB

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