summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-noddos/htdocs/cgi-bin/clientdetails
blob: 411113c6a683887a3a85b5f6998ae9c168c6f4fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/lua

-- clientdetails.lua : Provides details about client devices discovered by Noddos
-- Copyright (C) 2017 Steven Hessing (steven.hessing@gmail.com)
-- This is free software, licensed under the GNU General Public License v3.

require "nixio.fs"

print ("Content-type: Text/html\n")
local info = os.getenv("QUERY_STRING")

local params = {}
local echo = {}

function print_row(key)
	print ("<tr><th>")
	print (key)
	print ("</th><td>")
	print (device[key])
	print ("</td></tr>")
end

for name, value in string.gmatch(info .. '&', '(.-)%=(.-)%&') do
    value = string.gsub(value , '%+', ' ')
    value = string.gsub(value , '%%(%x%x)', function(dpc)
        return string.char(tonumber(dpc,16))
		end )
	params[name] = value

    value = string.gsub(value, "%&", "&amp;")
    value = string.gsub(value, "%<", "&lt;")
    value = string.gsub(value, '%"', "&quot;")
    echo[name] = value
end

device = {}
profile = {}

if nixio.fs.access("/var/lib/noddos/DeviceDump.json") then
        io.input("/var/lib/noddos/DeviceDump.json")
        local t = io.read("*all")
	local json = require "luci.jsonc"
        local devdump = json.parse(t)
        for i, v in ipairs(devdump) do
				if v.MacAddress == params["mac"] then
                        device = v
                end
        end
        io.input("/var/lib/noddos/DeviceProfiles.json")
        t = io.read("*all")
        local temp = json.parse(t)
        for i, v in ipairs(temp) do
                if device.DeviceProfileUuid == v.DeviceProfileUuid then
                        profile = v
                end
        end
end
pagetop = [[
<html>
  <head>
    <title>Client Details by Noddos</title>
    <meta charset="utf-8">
    <!--[if lt IE 9]><script src="/luci-static/bootstrap/html5.js?v=git-17.100.70571-29fabe2"></script><![endif]-->
    <meta name="viewport" content="initial-scale=1.0">
    <link rel="stylesheet" href="/luci-static/bootstrap/cascade.css?v=git-17.100.70571-29fabe2">
    <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" />
    <link rel="shortcut icon" href="/luci-static/bootstrap/favicon.png">
    <script src="/luci-static/resources/xhr.js?v=git-17.100.70571-29fabe2"></script>
  </head>
  <body text=blue>
    <h1>Client Details</h1>
]]
print (pagetop)

if params["mac"] ~= nil then
	print ("<table>")
	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
		print_row(key)
	end
	print ("</table>")
else 
	print ("no mac address specified")
end

pagebase = [[<br><br>
Client Details by
<a href=http://www.noddos.io>Noddos</a>
</body></html>
]]

print (pagebase)