ffho-debug 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #!/usr/bin/lua
  2. debugdata = ""
  3. ATH9K_DEBUGFS_DIR="/sys/kernel/debug/ieee80211/phy0/ath9k"
  4. PATH_DBG_REPORT='/tmp/debug-report.txt'
  5. local nixio = require('nixio'), require('nixio.util'), require('nixio.fs')
  6. -- wrapper for calling systemcommands
  7. function cmd(_command)
  8. local f = io.popen(_command)
  9. local l = f:read("*a")
  10. f:close()
  11. return "# " .. _command .. ": \n" .. l .. "\n"
  12. end
  13. -- read contents of a given file
  14. function readFile(_file)
  15. local f = io.open(_file, "r")
  16. if f~=nil then
  17. local l = f:read("*a")
  18. f:close()
  19. return "--- Content of file " .. _file .. " ---\n" .. l .. "\n\n"
  20. else
  21. return ""
  22. end
  23. end
  24. -- iterate through list
  25. function list_iter (_table)
  26. local i = 0
  27. local n = table.getn(_table)
  28. return function ()
  29. i = i + 1
  30. if i <= n then return _table[i] end
  31. end
  32. end
  33. localMode = false
  34. -- Should we enter local mode?
  35. if arg[1] == '-l' then
  36. localMode = true
  37. end
  38. -- search for existing debug report
  39. local oldReport = nixio.open(PATH_DBG_REPORT, "r")
  40. if oldReport==nil then
  41. -- no existing debugreport, let's generate a new one
  42. -- inform the User ;)
  43. print('-- Hello, Mr. Dillinger. Thank you for coming back early.')
  44. print('-- Sit right there; make yourself comfortable. Remember the time we spent play chess together?')
  45. -- first of all, collect some generic information about the system
  46. debugdata = debugdata .. "---- BEGIN SYSTEM INFORMATION ----\n"
  47. debugdata = debugdata .. cmd("uname -n")
  48. debugdata = debugdata .. cmd("cat /lib/gluon/release")
  49. debugdata = debugdata .. cmd("cat /tmp/sysinfo/model")
  50. debugdata = debugdata .. cmd("uptime")
  51. debugdata = debugdata .. cmd("date")
  52. debugdata = debugdata .. cmd("ps w")
  53. debugdata = debugdata .. "---- END SYSTEM INFORMATION ----\n\n"
  54. -- show uci variables
  55. debugdata = debugdata .. "---- BEGIN UCI VARIABLES ----\n"
  56. debugdata = debugdata .. cmd("uci show")
  57. debugdata = debugdata .. "---- END UCI VARIABLES ----\n\n"
  58. -- now get some information about the network status
  59. debugdata = debugdata .. "---- BEGIN IP AND ROUTUNG INFORMATION ----\n"
  60. debugdata = debugdata .. cmd("ip addr show")
  61. debugdata = debugdata .. cmd("ip route show")
  62. debugdata = debugdata .. cmd("ip -6 route show")
  63. debugdata = debugdata .. "---- BEGIN IP AND ROUTUNG INFORMATION ----\n\n"
  64. debugdata = debugdata .. "---- BEGIN FIREWALL INFORMATION ----\n"
  65. debugdata = debugdata .. cmd("iptables -t raw -L -v")
  66. debugdata = debugdata .. cmd("iptables -t filter -L -v")
  67. debugdata = debugdata .. cmd("iptables -t nat -L -v")
  68. debugdata = debugdata .. cmd("iptables -t mangle -L -v")
  69. debugdata = debugdata .. cmd("ip6tables -t raw -L -v")
  70. debugdata = debugdata .. cmd("ip6tables -t filter -L -v")
  71. debugdata = debugdata .. cmd("ip6tables -t mangle -L -v")
  72. debugdata = debugdata .. "---- BEGIN FIREWALL INFORMATION ----\n\n"
  73. -- get wireless status
  74. debugdata = debugdata .. "---- BEGIN WIRELESS INFORMATION ----\n"
  75. debugdata = debugdata .. cmd("iw phy phy0 info")
  76. debugdata = debugdata .. cmd("iw dev ibss0 info")
  77. debugdata = debugdata .. cmd("iw dev ibss0 station dump")
  78. debugdata = debugdata .. cmd("iw dev client0 station dump")
  79. debugdata = debugdata .. cmd("iwinfo phy0 scan")
  80. debugdata = debugdata .. cmd("iwinfo ibss0 info")
  81. debugdata = debugdata .. cmd("iwinfo client0 info")
  82. debugdata = debugdata .. cmd("iwinfo ibss0 assoclist")
  83. debugdata = debugdata .. cmd("iwinfo client0 assoclist")
  84. debugdata = debugdata .. "---- END WIRELESS INFORMATION ----\n\n"
  85. -- try to get some more information about wlan hardware status
  86. debugdata = debugdata .. "---- BEGIN HARDWARE STATUS ----\n"
  87. _files = {"reset", "queues", "interrupt"}
  88. for file in list_iter(_files) do
  89. debugdata = debugdata .. readFile(ATH9K_DEBUGFS_DIR .. "/" .. file)
  90. end
  91. -- sleep ten seconds and read interrupt again
  92. os.execute("sleep 10")
  93. debugdata = debugdata .. readFile(ATH9K_DEBUGFS_DIR .. "/interrupt")
  94. _files = {"ani", "base_eeprom", "dma", "dump_nfcal", "misc", "modal_eeprom", "phy_err", "recv", "xmit"}
  95. for file in list_iter(_files) do
  96. debugdata = debugdata .. readFile(ATH9K_DEBUGFS_DIR .. "/" .. file)
  97. end
  98. debugdata = debugdata .. "---- END HARDWARE STATUS ----\n\n"
  99. -- get batman status
  100. debugdata = debugdata .. "---- BEGIN BATMAN AND FASTD STATUS ----\n"
  101. debugdata = debugdata .. cmd("batctl gwl")
  102. debugdata = debugdata .. cmd("batctl tl")
  103. -- finally get fastd status
  104. os.execute("killall -USR1 fastd 2>/dev/null")
  105. debugdata = debugdata .. cmd("logread")
  106. debugdata = debugdata .. "---- END BATMAN AND FASTD STATUS ----\n\n"
  107. debugdata = debugdata .. "---- BEGIN DMESG KERNEL LOG ----\n"
  108. debugdata = debugdata .. cmd("dmesg")
  109. debugdata = debugdata .. "---- END DMESG KERNEL LOG ----\n\n"
  110. else
  111. print('Orphaned debug-report file found.')
  112. print('-- You wouldn\'t want me to dig up Flynn\'s file and read it up on a VDT at The Times, would you?')
  113. debugdata = oldReport:readall()
  114. oldReport:close()
  115. end
  116. -- if local mode is requested print the report, otherwise send it to the admin team
  117. siteConfig = require("gluon.site_config")
  118. if localMode then
  119. print('Omitting to send the report data to a report-server')
  120. print('-- Sark! All of my functions are now yours. Take them!:')
  121. print(debugdata)
  122. nixio.fs.unlink(PATH_DBG_REPORT)
  123. else
  124. local nixio = require('nixio'), require('nixio.util')
  125. print('-- My User has information that could... that could make this a free system again!')
  126. local sent = 0
  127. local reportname = nil
  128. local port = siteConfig.debugserver.port
  129. for host in list_iter(siteConfig.debugserver.host) do
  130. print('Trying to deliver debug-report to: ' .. host)
  131. local sock = nixio.connect(host, port, "inet6", "stream")
  132. if sock then
  133. sock:setopt('socket', 'sndtimeo', 30.0)
  134. sock:setopt('socket', 'rcvtimeo', 30.0)
  135. sent = sock:writeall(debugdata)
  136. if sent == debugdata:len() then
  137. -- half-side close to indicate the end of our transmission
  138. sock:shutdown('wr')
  139. print('Transmission succeeded. Waiting for report-name.')
  140. reportname = sock:readall(256)
  141. end
  142. sock:close()
  143. if reportname ~= nil then break end
  144. end
  145. end
  146. if reportname ~= nil then
  147. print('\nYour report has been stored at the debug-server with the name: ' .. reportname)
  148. print('-- With the information I can access, I can run things 900 to 1200 times better than any human.')
  149. else
  150. print('Sorry, I couldn\'t send the report.')
  151. print('-- If you are a User, then everything you\'ve done so far has been according to a plan, right?')
  152. print('-- I will try it again the next time you run me. See you soon ...')
  153. local f = nixio.open(PATH_DBG_REPORT, 'w')
  154. f:writeall(debugdata)
  155. f:close()
  156. end
  157. end
  158. print("-- You've almost reached your decision gate, and I cannot spare you any more time. End of Line.")
  159. os.exit(0)