count clients and add clientcount attribute to each node
This commit is contained in:
parent
fbc5c636df
commit
ac3366ff13
|
@ -64,6 +64,8 @@ if options['alfred']:
|
|||
af = alfred()
|
||||
db.import_aliases(af.aliases())
|
||||
|
||||
db.count_clients()
|
||||
|
||||
if options['obscure']:
|
||||
db.obscure_clients()
|
||||
|
||||
|
|
|
@ -16,7 +16,8 @@ class D3MapBuilder:
|
|||
'macs': ', '.join(x.macs),
|
||||
'geo': [float(x) for x in x.gps.split(" ")] if x.gps else None,
|
||||
'firmware': x.firmware,
|
||||
'flags': x.flags
|
||||
'flags': x.flags,
|
||||
'clientcount': x.clientcount
|
||||
} for x in nodes]
|
||||
|
||||
links = self._db.get_links()
|
||||
|
|
1
node.py
1
node.py
|
@ -11,6 +11,7 @@ class Node():
|
|||
})
|
||||
self.gps = None
|
||||
self.firmware = None
|
||||
self.clientcount = 0
|
||||
|
||||
def add_mac(self, mac):
|
||||
mac = mac.lower()
|
||||
|
|
19
nodedb.py
19
nodedb.py
|
@ -218,6 +218,25 @@ class NodeDB:
|
|||
|
||||
link.type = "vpn"
|
||||
|
||||
def count_clients(self):
|
||||
for link in self._links:
|
||||
try:
|
||||
a = self.maybe_node_by_id(link.source.interface)
|
||||
b = self.maybe_node_by_id(link.target.interface)
|
||||
|
||||
if a.flags['client']:
|
||||
client = a
|
||||
node = b
|
||||
elif b.flags['client']:
|
||||
client = b
|
||||
node = a
|
||||
else:
|
||||
continue
|
||||
|
||||
node.clientcount += 1
|
||||
except:
|
||||
pass
|
||||
|
||||
def obscure_clients(self):
|
||||
|
||||
globalIdCounter = 0
|
||||
|
|
Loading…
Reference in a new issue