mirror of
https://github.com/ntop/ntopng.git
synced 2026-05-08 23:25:13 +00:00
Initial discovery <-> DOA integration (work in progress)
This commit is contained in:
parent
1296211ccc
commit
f85f3be347
5 changed files with 233 additions and 47 deletions
42
scripts/lua/modules/base64.lua
Normal file
42
scripts/lua/modules/base64.lua
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
-- Lua 5.1+ base64 v3.0 (c) 2009 by Alex Kloss <alexthkloss@web.de>
|
||||
-- licensed under the terms of the LGPL2
|
||||
|
||||
local base64 = {}
|
||||
|
||||
-- character table string
|
||||
local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
||||
|
||||
-- encoding
|
||||
local function enc(data)
|
||||
return ((data:gsub('.', function(x)
|
||||
local r,b='',x:byte()
|
||||
for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
|
||||
return r;
|
||||
end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
|
||||
if (#x < 6) then return '' end
|
||||
local c=0
|
||||
for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end
|
||||
return b:sub(c+1,c+1)
|
||||
end)..({ '', '==', '=' })[#data%3+1])
|
||||
end
|
||||
|
||||
-- decoding
|
||||
local function dec(data)
|
||||
data = string.gsub(data, '[^'..b..'=]', '')
|
||||
return (data:gsub('.', function(x)
|
||||
if (x == '=') then return '' end
|
||||
local r,f='',(b:find(x)-1)
|
||||
for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end
|
||||
return r;
|
||||
end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x)
|
||||
if (#x ~= 8) then return '' end
|
||||
local c=0
|
||||
for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(7-i) or 0) end
|
||||
return string.char(c)
|
||||
end))
|
||||
end
|
||||
|
||||
base64.enc = enc
|
||||
base64.dec = dec
|
||||
|
||||
return base64
|
||||
|
|
@ -380,58 +380,58 @@ local function findDevice(ip, mac, manufacturer, _mdns, ssdp_str, ssdp_entries,
|
|||
|
||||
if(osx ~= nil) then ret = ret .. osx end
|
||||
interface.setMacOperatingSystem(mac, 3) -- 3 = OSX
|
||||
return icon, ret
|
||||
return icon, ret, nil
|
||||
elseif(mdns["_nvstream_dbd._tcp.local"] ~= nil) then
|
||||
interface.setMacOperatingSystem(mac, 2) -- 2 = windows
|
||||
return 'workstation', discover.asset_icons['workstation']..' (Windows)'
|
||||
return 'workstation', discover.asset_icons['workstation']..' (Windows)', nil
|
||||
elseif(mdns["_workstation._tcp.local"] ~= nil) then
|
||||
interface.setMacOperatingSystem(mac, 1) -- 1 = Linux
|
||||
return 'workstation', discover.asset_icons['workstation']..' (Linux)'
|
||||
return 'workstation', discover.asset_icons['workstation']..' (Linux)', nil
|
||||
end
|
||||
|
||||
if(string.contains(friendlyName, "TV")) then
|
||||
return 'tv', discover.asset_icons['tv']
|
||||
return 'tv', discover.asset_icons['tv'], nil
|
||||
end
|
||||
|
||||
if((ssdp["urn:upnp-org:serviceId:AVTransport"] ~= nil)
|
||||
or (ssdp["urn:upnp-org:serviceId:RenderingControl"] ~= nil)) then
|
||||
return 'multimedia', discover.asset_icons['multimedia']
|
||||
return 'multimedia', discover.asset_icons['multimedia'], nil
|
||||
end
|
||||
|
||||
if(ssdp_entries and ssdp_entries["modelDescription"]) then
|
||||
local descr = string.lower(ssdp_entries["modelDescription"])
|
||||
|
||||
if(string.contains(descr, "camera")) then
|
||||
return 'video', discover.asset_icons['video']
|
||||
return 'video', discover.asset_icons['video'], nil
|
||||
elseif(string.contains(descr, "router")) then
|
||||
return 'networking', discover.asset_icons['networking']
|
||||
return 'networking', discover.asset_icons['networking'], nil
|
||||
end
|
||||
end
|
||||
|
||||
if(discover.debug) then io.write("[manufacturer] "..manufacturer.."\n") end
|
||||
if(string.contains(manufacturer, "Oki Electric") and (snmpName ~= nil)) then
|
||||
return 'printer', discover.asset_icons['printer'].. ' ('..snmpName..')'
|
||||
return 'printer', discover.asset_icons['printer'].. ' ('..snmpName..')', snmpName
|
||||
elseif(string.contains(manufacturer, "Hikvision")) then
|
||||
return 'video', discover.asset_icons['video']
|
||||
return 'video', discover.asset_icons['video'], nil
|
||||
elseif(string.contains(manufacturer, "Super Micro")) then
|
||||
return 'workstation', discover.asset_icons['workstation']
|
||||
return 'workstation', discover.asset_icons['workstation'], nil
|
||||
elseif(string.contains(manufacturer, "Raspberry")) then
|
||||
return 'workstation', discover.asset_icons['workstation']
|
||||
return 'workstation', discover.asset_icons['workstation'], nil
|
||||
elseif(string.contains(manufacturer, "Juniper Networks")) then
|
||||
return 'networking', discover.asset_icons['networking']
|
||||
return 'networking', discover.asset_icons['networking'], nil
|
||||
elseif(string.contains(manufacturer, "Cisco")) then
|
||||
return 'networking', discover.asset_icons['networking']
|
||||
return 'networking', discover.asset_icons['networking'], nil
|
||||
elseif(string.contains(manufacturer, "Palo Alto Networks")) then
|
||||
return 'networking', discover.asset_icons['networking']
|
||||
return 'networking', discover.asset_icons['networking'], nil
|
||||
elseif(string.contains(manufacturer, "Liteon Technology")) then
|
||||
return 'workstation', discover.asset_icons['workstation']
|
||||
return 'workstation', discover.asset_icons['workstation'], nil
|
||||
elseif(string.contains(manufacturer, 'TP%-LINK')) then -- % is the escape char in Lua
|
||||
return 'wifi', discover.asset_icons['wifi']
|
||||
return 'wifi', discover.asset_icons['wifi'], nil
|
||||
elseif(string.contains(manufacturer, 'Broadband')) then -- % is the escape char in Lua
|
||||
return 'networking', discover.asset_icons['networking']
|
||||
return 'networking', discover.asset_icons['networking'], nil
|
||||
elseif(string.contains(manufacturer, 'Nest Labs')
|
||||
or string.contains(manufacturer, 'Netatmo')) then
|
||||
return 'iot', discover.asset_icons['iot']
|
||||
return 'iot', discover.asset_icons['iot'], nil
|
||||
elseif(string.contains(manufacturer, "Samsung Electronics")
|
||||
or string.contains(manufacturer, "SAMSUNG ELECTRO")
|
||||
or string.contains(manufacturer, "HTC Corporation")
|
||||
|
|
@ -440,7 +440,7 @@ local function findDevice(ip, mac, manufacturer, _mdns, ssdp_str, ssdp_entries,
|
|||
or string.contains(manufacturer, "Mobile Communications") -- LG Electronics (Mobile Communications)
|
||||
) then
|
||||
interface.setMacOperatingSystem(mac, 5) -- 5 = Android
|
||||
return 'phone', discover.asset_icons['phone'].. ' ' ..discover.android_icon
|
||||
return 'phone', discover.asset_icons['phone'].. ' ' ..discover.android_icon, nil
|
||||
elseif(string.contains(manufacturer, "Hewlett Packard") and (snmpName ~= nil)) then
|
||||
local _snmpName = string.lower(snmpName)
|
||||
local _snmpDescr
|
||||
|
|
@ -454,86 +454,86 @@ local function findDevice(ip, mac, manufacturer, _mdns, ssdp_str, ssdp_entries,
|
|||
|
||||
if(string.contains(_snmpDescr, "jet") -- JetDirect, LaserJet, InkJet, DeskJet
|
||||
or string.contains(_snmpDescr, "fax")) then
|
||||
return 'printer', discover.asset_icons['printer']..' ('..snmpName..')'
|
||||
return 'printer', discover.asset_icons['printer']..' ('..snmpName..')', snmpName
|
||||
elseif(string.contains(_snmpDescr, "curve")) then
|
||||
return 'networking', discover.asset_icons['networking']..' ('..snmpName..')'
|
||||
return 'networking', discover.asset_icons['networking']..' ('..snmpName..')', snmpName
|
||||
else
|
||||
return 'workstation', discover.asset_icons['workstation']..' ('..snmpName..')'
|
||||
return 'workstation', discover.asset_icons['workstation']..' ('..snmpName..')', snmpName
|
||||
end
|
||||
elseif(string.contains(manufacturer, "VMware")
|
||||
or string.contains(manufacturer, "QEMU")
|
||||
or string.contains(manufacturer, "Xen")
|
||||
or string.contains(manufacturer, "Parallel")
|
||||
) then
|
||||
return 'workstation', discover.asset_icons['workstation']
|
||||
return 'workstation', discover.asset_icons['workstation'], nil
|
||||
elseif(string.contains(manufacturer, "Xerox") and (snmpName ~= nil)) then
|
||||
return 'printer', discover.asset_icons['printer']..' ('..snmpName..')'
|
||||
return 'printer', discover.asset_icons['printer']..' ('..snmpName..')', snmpName
|
||||
elseif(string.contains(manufacturer, "Apple, Inc.")) then
|
||||
if(string.contains(hostname, "iphone") or string.contains(symName, "iphone")) then
|
||||
interface.setMacOperatingSystem(mac, 4) -- 4 = iOS
|
||||
return 'phone', discover.asset_icons['phone']..' (' .. discover.apple_icon .. ' iPhone)'
|
||||
return 'phone', discover.asset_icons['phone']..' (' .. discover.apple_icon .. ' iPhone)', nil
|
||||
elseif(string.contains(hostname, "ipad") or string.contains(symName, "ipad")) then
|
||||
interface.setMacOperatingSystem(mac, 4) -- 4 = iOS
|
||||
return 'tablet', discover.asset_icons['tablet']..' (' .. discover.apple_icon .. 'iPad)'
|
||||
return 'tablet', discover.asset_icons['tablet']..' (' .. discover.apple_icon .. 'iPad)', nil
|
||||
elseif(string.contains(hostname, "ipod") or string.contains(symName, "ipod")) then
|
||||
interface.setMacOperatingSystem(mac, 4) -- 4 = iOS
|
||||
return 'phone', discover.asset_icons['phone']..' (' .. discover.apple_icon .. 'iPod)'
|
||||
return 'phone', discover.asset_icons['phone']..' (' .. discover.apple_icon .. 'iPod)', nil
|
||||
else
|
||||
local ret = '</i> '..discover.asset_icons['workstation']..' ' .. discover.apple_icon
|
||||
local what = 'workstation'
|
||||
|
||||
if(((snmpName ~= nil) and string.contains(snmpName, "capsule"))
|
||||
or string.contains(symName, "capsule") or string.contains(hostname, "capsule")) then
|
||||
ret = '</i> '..discover.asset_icons['nas']
|
||||
ret = '</i> '..discover.asset_icons['nas'], nil
|
||||
what = 'nas'
|
||||
elseif(string.contains(symName, "book") or string.contains(hostname, "book")) then
|
||||
ret = '</i> '..discover.asset_icons['laptop']..' ' .. discover.apple_icon
|
||||
ret = '</i> '..discover.asset_icons['laptop']..' ' .. discover.apple_icon, nil
|
||||
what = 'laptop'
|
||||
end
|
||||
|
||||
if(snmpName ~= nil) then ret = ret .. " ["..snmpName.."]" end
|
||||
interface.setMacOperatingSystem(mac, 3) -- 3 = OSX
|
||||
return what, ret
|
||||
return what, ret, snmpName
|
||||
end
|
||||
end
|
||||
|
||||
if(string.contains(mac, "F0:4F:7C") and string.contains(hostname, "kindle-")) then
|
||||
return 'tablet', discover.asset_icons['tablet']..' (Kindle)'
|
||||
return 'tablet', discover.asset_icons['tablet']..' (Kindle)', "Kindle"
|
||||
end
|
||||
|
||||
if(names["gateway.local"] == ip) then
|
||||
return 'networking', discover.asset_icons['networking']
|
||||
return 'networking', discover.asset_icons['networking'], nil
|
||||
end
|
||||
|
||||
if(string.starts(hostname, "desktop-") or string.starts(symName, "desktop-")) then
|
||||
interface.setMacOperatingSystem(mac, 2) -- 2 = windows
|
||||
return 'workstation', discover.asset_icons['workstation']..' (Windows)'
|
||||
return 'workstation', discover.asset_icons['workstation']..' (Windows)', nil
|
||||
elseif(string.contains(hostname, "thinkpad") or string.contains(symName, "thinkpad")) then
|
||||
return 'laptop', discover.asset_icons['laptop']
|
||||
return 'laptop', discover.asset_icons['laptop'], nil
|
||||
elseif(string.contains(hostname, "android") or string.contains(symName, "android")) then
|
||||
interface.setMacOperatingSystem(mac, 5) -- 5 = Android
|
||||
return 'phone', discover.asset_icons['phone']..' ' ..discover.android_icon
|
||||
return 'phone', discover.asset_icons['phone']..' ' ..discover.android_icon, nil
|
||||
elseif(string.contains(hostname, "%-NAS") or string.contains(symName, "%-NAS")) then
|
||||
return 'nas', discover.asset_icons['nas']
|
||||
return 'nas', discover.asset_icons['nas'], nil
|
||||
end
|
||||
|
||||
if(snmpName ~= nil) then
|
||||
if(string.contains(snmpName, "router")
|
||||
or string.contains(snmpName, "switch")
|
||||
) then
|
||||
return 'networking', discover.asset_icons['networking']..' ('..snmpName..')'
|
||||
return 'networking', discover.asset_icons['networking']..' ('..snmpName..')', snmpName
|
||||
elseif(string.contains(snmpName, "air")) then
|
||||
return 'wifi', discover.asset_icons['wifi']..' ('..snmpName..')'
|
||||
return 'wifi', discover.asset_icons['wifi']..' ('..snmpName..')', snmpName
|
||||
else
|
||||
return 'unknown', snmpName
|
||||
return 'unknown', snmpName, nil
|
||||
end
|
||||
end
|
||||
|
||||
if(string.contains(manufacturer, "Ubiquity")) then
|
||||
return 'networking', discover.asset_icons['networking']
|
||||
return 'networking', discover.asset_icons['networking'], nil
|
||||
end
|
||||
|
||||
return 'unknown', ""
|
||||
return 'unknown', "", nil
|
||||
end
|
||||
|
||||
-- #############################################################################
|
||||
|
|
@ -834,12 +834,15 @@ function discover.discover2table(interface_name, recache)
|
|||
|
||||
if(ghost_macs[mac] == true) then entry["ghost"] = true end
|
||||
|
||||
device_type, device_label = findDevice(ip, mac, entry["manufacturer"] or get_manufacturer_mac(mac),
|
||||
arp_mdns[ip], services, ssdp[ip],mdns, snmp[ip], snmpSysDescr[ip],
|
||||
osx_devices[ip], sym)
|
||||
device_type, device_label, device_info = findDevice(ip, mac, entry["manufacturer"] or get_manufacturer_mac(mac),
|
||||
arp_mdns[ip], services, ssdp[ip],
|
||||
mdns, snmp[ip], snmpSysDescr[ip],
|
||||
osx_devices[ip], sym)
|
||||
|
||||
if isEmptyString(device_label) then
|
||||
local mac_info = interface.getMacInfo(mac, 0) -- 0 = VLAN
|
||||
|
||||
entry["device_label_noicon"] = device_label
|
||||
if mac_info ~= nil then
|
||||
device_label = device_label .. discover.devtype2icon(mac_info.devtype)
|
||||
end
|
||||
|
|
@ -850,6 +853,10 @@ function discover.discover2table(interface_name, recache)
|
|||
entry["device_type"] = device_type
|
||||
entry["device_label"] = device_label
|
||||
|
||||
if(device_info ~= nil) then
|
||||
entry["device_info"] = device_info
|
||||
end
|
||||
|
||||
res[#res + 1] = entry
|
||||
::continue::
|
||||
end
|
||||
|
|
|
|||
91
scripts/lua/modules/doa.lua
Normal file
91
scripts/lua/modules/doa.lua
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
--
|
||||
-- (C) 2017 - ntop.org
|
||||
--
|
||||
|
||||
--
|
||||
-- https://www.internetsociety.org/resources/doc/2016/overview-of-the-digital-object-architecture-doa/
|
||||
-- https://tools.ietf.org/html/draft-durand-doa-over-dns-00
|
||||
--
|
||||
-- Update DNS with command
|
||||
-- nsupdate -k Kntop.org.+157+16148.private -v /tmp/doa.update
|
||||
--
|
||||
|
||||
local base64 = require "base64"
|
||||
|
||||
local doa = {}
|
||||
|
||||
local function initDOA(path)
|
||||
return(io.open(path, "w"))
|
||||
end
|
||||
doa.init = initDOA
|
||||
|
||||
local function printDOAHeader(fd)
|
||||
fd:write("server localhost\n")
|
||||
fd:write("zone ntop.org.\n")
|
||||
end
|
||||
doa.header = printDOAHeader
|
||||
|
||||
local function printDOAFooter(fd)
|
||||
fd:write("send\n")
|
||||
end
|
||||
doa.footer = printDOAFooter
|
||||
|
||||
local function device2DOA(fd, dev)
|
||||
-- update add FE5400577C58.ntop.org. 3600 IN DOA 35632 1 1 "text/plain" c2FtcGxlIERPQSB0ZXh0IHJlY29yZA==
|
||||
local mac = dev.mac:gsub(":", "")
|
||||
local base_string = "update add ".. mac ..".ntop.org 3600 IN DOA 35632 "
|
||||
local v
|
||||
|
||||
-- Delete record first
|
||||
fd:write("update delete ".. mac ..".ntop.org. DOA\n")
|
||||
|
||||
-- 101 - Operating System
|
||||
if(dev.operatingSystem ~= nil) then
|
||||
fd:write(base_string.."101 1 \"text/plain\" "..base64.enc(dev.operatingSystem).."\n")
|
||||
end
|
||||
|
||||
-- 102 - Device Type
|
||||
if(dev.device_type ~= nil) then
|
||||
fd:write(base_string.."102 1 \"text/plain\" "..base64.enc(dev.device_type).."\n")
|
||||
end
|
||||
|
||||
-- 103 - Device (Symbolic) Name
|
||||
if(dev.sym ~= nil) then
|
||||
v = dev.sym
|
||||
elseif(dev.symIP ~= nil) then
|
||||
v = dev.symIP
|
||||
else
|
||||
v = nil
|
||||
end
|
||||
if(v ~= nil) then
|
||||
fd:write(base_string.."103 1 \"text/plain\" "..base64.enc(v).."\n")
|
||||
end
|
||||
|
||||
-- 104 - Provided services (SSDP)
|
||||
if(dev.information ~= nil) then
|
||||
v = table.concat(dev.information, ",")
|
||||
if(v ~= "") then
|
||||
fd:write(base_string.."104 1 \"text/plain\" "..base64.enc(table.concat(dev.information, ",")).."\n")
|
||||
end
|
||||
end
|
||||
|
||||
-- 105 - Description
|
||||
if((dev.device_info ~= nil) and (dev.device_info ~= "")) then
|
||||
-- io.write("=========> [device_info] "..dev.device_info.."\n")
|
||||
fd:write(base_string.."105 2 \"text/plain\" "..base64.enc(dev.device_info).."\n")
|
||||
end
|
||||
|
||||
-- 106 - (SSDP) URL
|
||||
if(dev.url ~= nil) then
|
||||
fd:write(base_string.."106 2 \"text/plain\" "..base64.enc(dev.url).."\n")
|
||||
end
|
||||
end
|
||||
doa.device2DOA = device2DOA
|
||||
|
||||
local function termDOA(fd)
|
||||
fd:close()
|
||||
end
|
||||
doa.term = termDOA
|
||||
|
||||
return doa
|
||||
|
||||
|
|
@ -1390,12 +1390,30 @@ end
|
|||
|
||||
-- #################################
|
||||
|
||||
function getOperatingSystemName(id)
|
||||
if(id == 1) then return("Linux")
|
||||
elseif(id == 2) then return("Windows")
|
||||
elseif(id == 3) then return("MacOS")
|
||||
elseif(id == 4) then return("iOS")
|
||||
elseif(id == 5) then return("Android")
|
||||
elseif(id == 6) then return("LaserJET")
|
||||
elseif(id == 7) then return("AppleAirport")
|
||||
else
|
||||
return("") -- Unknown
|
||||
end
|
||||
end
|
||||
|
||||
-- #################################
|
||||
|
||||
function getOperatingSystemIcon(id)
|
||||
if(id == 1) then return(' <i class=\'fa fa-linux fa-lg\'></i>')
|
||||
elseif(id == 2) then return(' <i class=\'fa fa-windows fa-lg\'></i>')
|
||||
elseif(id == 3) then return(' <i class=\'fa fa-apple fa-lg\'></i>')
|
||||
elseif(id == 4) then return(' <i class=\'fa fa-apple fa-lg\'></i>')
|
||||
elseif(id == 5) then return(' <i class=\'fa fa-android fa-lg\'></i>')
|
||||
elseif(id == 6) then return(' LasetJET')
|
||||
elseif(id == 7) then return(' Apple Airport')
|
||||
|
||||
else return("")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue