clientdetails 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/usr/bin/lua
  2. -- clientdetails.lua : Provides details about client devices discovered by Noddos
  3. -- Copyright (C) 2017 Steven Hessing (steven.hessing@gmail.com)
  4. -- This is free software, licensed under the GNU General Public License v3.
  5. require "nixio.fs"
  6. print ("Content-type: Text/html\n")
  7. local info = os.getenv("QUERY_STRING")
  8. local params = {}
  9. local echo = {}
  10. function print_row(key)
  11. print ("<tr><th>")
  12. print (key)
  13. print ("</th><td>")
  14. print (device[key])
  15. print ("</td></tr>")
  16. end
  17. for name, value in string.gmatch(info .. '&', '(.-)%=(.-)%&') do
  18. value = string.gsub(value , '%+', ' ')
  19. value = string.gsub(value , '%%(%x%x)', function(dpc)
  20. return string.char(tonumber(dpc,16))
  21. end )
  22. params[name] = value
  23. value = string.gsub(value, "%&", "&amp;")
  24. value = string.gsub(value, "%<", "&lt;")
  25. value = string.gsub(value, '%"', "&quot;")
  26. echo[name] = value
  27. end
  28. device = {}
  29. profile = {}
  30. if nixio.fs.access("/var/lib/noddos/DeviceDump.json") then
  31. io.input("/var/lib/noddos/DeviceDump.json")
  32. local t = io.read("*all")
  33. local json = require "luci.jsonc"
  34. local devdump = json.parse(t)
  35. for i, v in ipairs(devdump) do
  36. if v.MacAddress == params["mac"] then
  37. device = v
  38. end
  39. end
  40. io.input("/var/lib/noddos/DeviceProfiles.json")
  41. t = io.read("*all")
  42. local temp = json.parse(t)
  43. for i, v in ipairs(temp) do
  44. if device.DeviceProfileUuid == v.DeviceProfileUuid then
  45. profile = v
  46. end
  47. end
  48. end
  49. pagetop = [[
  50. <html>
  51. <head>
  52. <title>Client Details by Noddos</title>
  53. <meta charset="utf-8">
  54. <!--[if lt IE 9]><script src="/luci-static/bootstrap/html5.js?v=git-17.100.70571-29fabe2"></script><![endif]-->
  55. <meta name="viewport" content="initial-scale=1.0">
  56. <link rel="stylesheet" href="/luci-static/bootstrap/cascade.css?v=git-17.100.70571-29fabe2">
  57. <link rel="stylesheet" media="only screen and (max-device-width: 854px)" href="/luci-static/bootstrap/mobile.css?v=git-17.100.70571-29fabe2" type="text/css" />
  58. <link rel="shortcut icon" href="/luci-static/bootstrap/favicon.ico">
  59. <script src="/luci-static/resources/xhr.js?v=git-17.100.70571-29fabe2"></script>
  60. </head>
  61. <body text=blue>
  62. <h1>Client Details</h1>
  63. ]]
  64. print (pagetop)
  65. if params["mac"] ~= nil then
  66. print ("<table>")
  67. for i, key in ipairs{"MacAddress", "Ipv4Address", "Ipv6Address", "DeviceProfileUuid", "DhcpHostname", "DhcpVendor", "SsdpFriendlyName", "SsdpLocation", "SsdpManufacturer", "SsdpModelName", "SsdpModelUrl", "SsdpSerialNumber", "SsdpServer","SsdpUserAgent", "MdnsDeviceUrl", "MdnsHw", "MdnsManufacturer", "MdnsModelName", "MdnsOs", "WsDiscoveryTypes", "WsDiscoveryXaddrs", "DnsQueries"} do
  68. print_row(key)
  69. end
  70. print ("</table>")
  71. else
  72. print ("no mac address specified")
  73. end
  74. pagebase = [[<br><br>
  75. Client Details by
  76. <a href=http://www.noddos.io>Noddos</a>
  77. </body></html>
  78. ]]
  79. print (pagebase)