diff --git a/web/database.py b/web/database.py index c058a8a..66b8ab5 100644 --- a/web/database.py +++ b/web/database.py @@ -31,22 +31,22 @@ class NodeDB: node.ip, node.label, node.version, now, now, node.label, node.version, now)) - def insert_edge(self, edge): + def insert_edge(self, edge, uploaded_by): now = int(time.time()) self.cur.execute(''' - INSERT INTO edges (a, b, first_seen, last_seen) - VALUES (%s, %s, %s, %s) + INSERT INTO edges (a, b, first_seen, last_seen, uploaded_by) + VALUES (%s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE last_seen = %s''', ( - edge.a.ip, edge.b.ip, now, now, - now)) + edge.a.ip, edge.b.ip, now, now, uploaded_by, + now)) - def insert_graph(self, nodes, edges): + def insert_graph(self, nodes, edges, uploaded_by): for n in nodes.itervalues(): self.insert_node(n) for e in edges: - self.insert_edge(e) + self.insert_edge(e, uploaded_by) diff --git a/web/database.sql b/web/database.sql index d09fbee..3c8714e 100644 --- a/web/database.sql +++ b/web/database.sql @@ -12,6 +12,7 @@ CREATE TABLE `edges` ( `b` varchar(39) NOT NULL, `first_seen` int(11) NOT NULL, `last_seen` int(11) NOT NULL, + `uploaded_by` varchar(200) NOT NULL, PRIMARY KEY (`a`,`b`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/web/graphData.py b/web/graphData.py index 8161358..32f33ad 100644 --- a/web/graphData.py +++ b/web/graphData.py @@ -34,9 +34,11 @@ def insert_graph_data(config, data, mail, ip): if len(nodes) == 0 or len(edges) == 0: return 'No valid nodes or edges' + uploaded_by = ip + try: with NodeDB(config) as db: - db.insert_graph(nodes, edges) + db.insert_graph(nodes, edges, uploaded_by) except Exception: traceback.print_exc() return 'Database failure' diff --git a/web/static/network.js b/web/static/network.js index 667cb9c..f364800 100644 --- a/web/static/network.js +++ b/web/static/network.js @@ -55,7 +55,7 @@ function drawNetwork() { var edge = edges[i]; var highlight = edge.sourceNode.hover || edge.targetNode.hover; var color = highlight ? 'rgba(0, 0, 0, 0.5)' : 'rgba(0, 0, 0, 0.15)'; - + drawLine(ctx, edge.sourceNode.x, edge.sourceNode.y, edge.targetNode.x, edge.targetNode.y, @@ -204,7 +204,7 @@ $(document).ready(function() { jQuery.getJSON('/static/graph.json', function(data) { nodes = data.nodes; - edges = data.edges; + edges = data.edges; // Calculate node radiuses for (var i = 0; i < nodes.length; ++i) { @@ -222,6 +222,7 @@ $(document).ready(function() { node.textColor = node.color; } + var newEdges = [] // Find node references for edges for (var i = 0; i < edges.length; ++i) { var edge = edges[i]; @@ -235,13 +236,17 @@ $(document).ready(function() { edge.targetNode = nodes[n]; } + if (!edge.sourceNode || !edge.targetNode) + continue; + edge.sourceNode.edges.push(edge); edge.targetNode.edges.push(edge); edge.sourceNode.peers.push(edge.targetNode); edge.targetNode.peers.push(edge.sourceNode); + + newEdges.push(edge); } - - + edges = newEdges; // Set update time var delta = Math.round(new Date().getTime() / 1000) - data.created; @@ -362,7 +367,7 @@ $(document).ready(function() { $(canvas).mouseup(function(e) { var mouse = mousePos(e); var mouseMoved = - Math.abs(mouse.x - mouseDownPos.x) + + Math.abs(mouse.x - mouseDownPos.x) + Math.abs(mouse.y - mouseDownPos.y) > 3 if (!mouseMoved) {