remove group foo and replace it with flags

This commit is contained in:
Nils Schneider 2012-06-07 22:21:50 +02:00
parent 1a622da784
commit 523384d64c
8 changed files with 41 additions and 38 deletions

View file

@ -3,7 +3,6 @@
"name" : "Meute-AP" "name" : "Meute-AP"
}, },
"8e:3d:c2:10:10:28" : { "8e:3d:c2:10:10:28" : {
"name" : "holstentor", "name" : "holstentor"
"group" : 2
} }
} }

View file

@ -9,10 +9,11 @@ class D3MapBuilder:
nodes = self._db.get_nodes() nodes = self._db.get_nodes()
output['nodes'] = [{'group': x.group, 'name': x.name, 'id': x.id, output['nodes'] = [{'name': x.name, 'id': x.id,
'macs': ', '.join(x.macs), 'macs': ', '.join(x.macs),
'geo': x.gps.split(" ") if x.gps else None 'geo': x.gps.split(" ") if x.gps else None,
} for x in nodes if x.online] 'flags': x.flags
} for x in nodes if x.flags['online']]
output['links'] = [{'source': x.pair[0], 'target': x.pair[1], output['links'] = [{'source': x.pair[0], 'target': x.pair[1],
'distance': x.distance, 'distance': x.distance,
'strength': x.strength, 'strength': x.strength,

View file

@ -85,7 +85,7 @@ class GeoNode:
raise raise
name = self._node.name name = self._node.name
status = "up" if self._node.online else "down" status = "up" if self._node.flags['online'] else "down"
gps = gps_format(self._node.gps) gps = gps_format(self._node.gps)
text = " ".join(self._node.macs) text = " ".join(self._node.macs)

View file

@ -17,16 +17,16 @@
stroke-width: 5px !important; stroke-width: 5px !important;
} }
.node ellipse.group-0 { .node ellipse {
fill: #fff; fill: #fff;
stroke: #04f; stroke: #04f;
} }
.node ellipse.group-2 { .node ellipse.gateway {
stroke: #FF7F0E; stroke: #FF7F0E;
} }
.node ellipse.group-3 { .node ellipse.client {
stroke: #ff0; stroke: #ff0;
fill: #ff0; fill: #ff0;
stroke-width: 5px; stroke-width: 5px;

View file

@ -17,15 +17,15 @@
stroke-opacity: 1; stroke-opacity: 1;
} }
.node ellipse.group-0 { .node ellipse {
stroke: #AEC7E8; stroke: #AEC7E8;
} }
.node ellipse.group-2 { .node ellipse.gateway {
stroke: #FF7F0E; stroke: #FF7F0E;
} }
.node ellipse.group-3 { .node ellipse.client {
stroke: #1F77B4; stroke: #1F77B4;
fill: #1F77B4; fill: #1F77B4;
} }

View file

@ -251,12 +251,12 @@ function reload() {
json.links.forEach(function(d) { json.links.forEach(function(d) {
var node, other var node, other
if (d.source.group == 2) { if (d.source.flags.vpn) {
node = d.target; node = d.target;
other = d.source; other = d.source;
} }
if (d.target.group == 2) { if (d.target.flags.vpn) {
node = d.source; node = d.source;
other = d.target; other = d.target;
} }
@ -280,10 +280,10 @@ function reload() {
function update() { function update() {
var links = data.links var links = data.links
.filter(function (d) { .filter(function (d) {
if (!visible.clients && (d.source.group == 3 || d.target.group == 3)) if (!visible.clients && (d.source.flags.client || d.target.flags.client))
return false return false
if (!visible.vpn && (d.source.group == 2 || d.target.group == 2)) if (!visible.vpn && (d.source.flags.vpn || d.target.flags.vpn))
return false return false
return true return true
@ -324,13 +324,13 @@ function update() {
link.exit().remove() link.exit().remove()
var nodes = data.nodes.filter(function (d) { var nodes = data.nodes.filter(function (d) {
if (!visible.vpn && d.group == 2) if (!visible.vpn && d.flags.vpn)
return false return false
if (!visible.vpn && d.group == 3 && d.uplinks) if (!visible.vpn && d.flags.client && d.uplinks)
return false return false
if (!visible.clients && d.group == 3) if (!visible.clients && d.flags.client)
return false return false
return true return true
@ -353,21 +353,26 @@ function update() {
nodeEnter.append("ellipse") nodeEnter.append("ellipse")
.attr("class", function(d) { .attr("class", function(d) {
return "group-" + d.group var s = []
for (var key in d.flags)
if (d.flags.hasOwnProperty(key) && d.flags[key])
s.push(key)
return s.join(" ")
}) })
node.selectAll("ellipse") node.selectAll("ellipse")
.attr("rx", function(d) { .attr("rx", function(d) {
if (d.group == 3) return 4 if (d.flags.client) return 4
else return Math.max(10, d.name.length * 5) else return Math.max(10, d.name.length * 5)
}) })
.attr("ry", function(d) { .attr("ry", function(d) {
if (d.group == 3) return 4 if (d.flags.client) return 4
else return 10 else return 10
}) })
nodeEnter.filter(function(d) { nodeEnter.filter(function(d) {
return d.group != 3 return !d.flags.client
}) })
.append("text") .append("text")
.attr("class", "name") .attr("class", "name")

13
node.py
View file

@ -3,14 +3,13 @@ class Node():
self.name = "" self.name = ""
self.id = "" self.id = ""
self.macs = set() self.macs = set()
self.group = 0 self.flags = dict({
self.online = False "online": False,
"vpn": False,
"gateway": False,
"client": False
})
self.gps = None self.gps = None
# groups:
# 0 normal node
# 1 aftermath
# 2 gateways
# 3 TT
def add_mac(self, mac): def add_mac(self, mac):
mac = mac.lower() mac = mac.lower()

View file

@ -47,7 +47,7 @@ class NodeDB:
node = self.maybe_node_by_mac((x['of'], x['secondary'])) node = self.maybe_node_by_mac((x['of'], x['secondary']))
except: except:
node = Node() node = Node()
node.online = True node.flags['online'] = True
self._nodes.append(node) self._nodes.append(node)
node.add_mac(x['of']) node.add_mac(x['of'])
@ -61,7 +61,7 @@ class NodeDB:
node = self.maybe_node_by_mac((x['router'], )) node = self.maybe_node_by_mac((x['router'], ))
except: except:
node = Node() node = Node()
node.online = True node.flags['online'] = True
node.add_mac(x['router']) node.add_mac(x['router'])
self._nodes.append(node) self._nodes.append(node)
@ -97,9 +97,9 @@ class NodeDB:
node = self.maybe_node_by_mac((x['neighbor'], )) node = self.maybe_node_by_mac((x['neighbor'], ))
except: except:
node = Node() node = Node()
node.online = True node.flags['online'] = True
if x['label'] == 'TT': if x['label'] == 'TT':
node.group = 3 node.flags['client'] = True
node.add_mac(x['neighbor']) node.add_mac(x['neighbor'])
self._nodes.append(node) self._nodes.append(node)
@ -142,8 +142,6 @@ class NodeDB:
continue continue
node.name = alias['name'] node.name = alias['name']
if 'group' in alias:
node.group = alias['group']
# list of macs # list of macs
# if options['gateway']: # if options['gateway']:
@ -155,12 +153,13 @@ class NodeDB:
except: except:
continue continue
node.group = 2 node.flags['gateway'] = True
node.flags['vpn'] = True
def map_link(self, pair): def map_link(self, pair):
distance = 80 distance = 80
strength = 0.2 strength = 0.2
if any(filter(lambda x: self._nodes[x].group == 3, pair[0])): if any(filter(lambda x: self._nodes[x].flags['client'], pair[0])):
distance = 10 distance = 10
strength = 1 strength = 1