5
0
mirror of https://github.com/cwinfo/yggdrasil-map synced 2024-11-09 16:00:27 +00:00

add uploaded_by, JS map fixes

This commit is contained in:
root 2015-11-21 12:44:45 +01:00 committed by Michał Zieliński
parent 3478a0023c
commit 26343b47fb
4 changed files with 21 additions and 13 deletions

View File

@ -31,22 +31,22 @@ class NodeDB:
node.ip, node.label, node.version, now, now, node.ip, node.label, node.version, now, now,
node.label, node.version, now)) node.label, node.version, now))
def insert_edge(self, edge): def insert_edge(self, edge, uploaded_by):
now = int(time.time()) now = int(time.time())
self.cur.execute(''' self.cur.execute('''
INSERT INTO edges (a, b, first_seen, last_seen) INSERT INTO edges (a, b, first_seen, last_seen, uploaded_by)
VALUES (%s, %s, %s, %s) VALUES (%s, %s, %s, %s, %s)
ON DUPLICATE KEY ON DUPLICATE KEY
UPDATE last_seen = %s''', ( UPDATE last_seen = %s''', (
edge.a.ip, edge.b.ip, now, now, edge.a.ip, edge.b.ip, now, now, uploaded_by,
now)) now))
def insert_graph(self, nodes, edges): def insert_graph(self, nodes, edges, uploaded_by):
for n in nodes.itervalues(): for n in nodes.itervalues():
self.insert_node(n) self.insert_node(n)
for e in edges: for e in edges:
self.insert_edge(e) self.insert_edge(e, uploaded_by)

View File

@ -12,6 +12,7 @@ CREATE TABLE `edges` (
`b` varchar(39) NOT NULL, `b` varchar(39) NOT NULL,
`first_seen` int(11) NOT NULL, `first_seen` int(11) NOT NULL,
`last_seen` int(11) NOT NULL, `last_seen` int(11) NOT NULL,
`uploaded_by` varchar(200) NOT NULL,
PRIMARY KEY (`a`,`b`) PRIMARY KEY (`a`,`b`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -34,9 +34,11 @@ def insert_graph_data(config, data, mail, ip):
if len(nodes) == 0 or len(edges) == 0: if len(nodes) == 0 or len(edges) == 0:
return 'No valid nodes or edges' return 'No valid nodes or edges'
uploaded_by = ip
try: try:
with NodeDB(config) as db: with NodeDB(config) as db:
db.insert_graph(nodes, edges) db.insert_graph(nodes, edges, uploaded_by)
except Exception: except Exception:
traceback.print_exc() traceback.print_exc()
return 'Database failure' return 'Database failure'

View File

@ -55,7 +55,7 @@ function drawNetwork() {
var edge = edges[i]; var edge = edges[i];
var highlight = edge.sourceNode.hover || edge.targetNode.hover; var highlight = edge.sourceNode.hover || edge.targetNode.hover;
var color = highlight ? 'rgba(0, 0, 0, 0.5)' : 'rgba(0, 0, 0, 0.15)'; var color = highlight ? 'rgba(0, 0, 0, 0.5)' : 'rgba(0, 0, 0, 0.15)';
drawLine(ctx, drawLine(ctx,
edge.sourceNode.x, edge.sourceNode.y, edge.sourceNode.x, edge.sourceNode.y,
edge.targetNode.x, edge.targetNode.y, edge.targetNode.x, edge.targetNode.y,
@ -204,7 +204,7 @@ $(document).ready(function() {
jQuery.getJSON('/static/graph.json', function(data) { jQuery.getJSON('/static/graph.json', function(data) {
nodes = data.nodes; nodes = data.nodes;
edges = data.edges; edges = data.edges;
// Calculate node radiuses // Calculate node radiuses
for (var i = 0; i < nodes.length; ++i) { for (var i = 0; i < nodes.length; ++i) {
@ -222,6 +222,7 @@ $(document).ready(function() {
node.textColor = node.color; node.textColor = node.color;
} }
var newEdges = []
// Find node references for edges // Find node references for edges
for (var i = 0; i < edges.length; ++i) { for (var i = 0; i < edges.length; ++i) {
var edge = edges[i]; var edge = edges[i];
@ -235,13 +236,17 @@ $(document).ready(function() {
edge.targetNode = nodes[n]; edge.targetNode = nodes[n];
} }
if (!edge.sourceNode || !edge.targetNode)
continue;
edge.sourceNode.edges.push(edge); edge.sourceNode.edges.push(edge);
edge.targetNode.edges.push(edge); edge.targetNode.edges.push(edge);
edge.sourceNode.peers.push(edge.targetNode); edge.sourceNode.peers.push(edge.targetNode);
edge.targetNode.peers.push(edge.sourceNode); edge.targetNode.peers.push(edge.sourceNode);
newEdges.push(edge);
} }
edges = newEdges;
// Set update time // Set update time
var delta = Math.round(new Date().getTime() / 1000) - data.created; var delta = Math.round(new Date().getTime() / 1000) - data.created;
@ -362,7 +367,7 @@ $(document).ready(function() {
$(canvas).mouseup(function(e) { $(canvas).mouseup(function(e) {
var mouse = mousePos(e); var mouse = mousePos(e);
var mouseMoved = var mouseMoved =
Math.abs(mouse.x - mouseDownPos.x) + Math.abs(mouse.x - mouseDownPos.x) +
Math.abs(mouse.y - mouseDownPos.y) > 3 Math.abs(mouse.y - mouseDownPos.y) > 3
if (!mouseMoved) { if (!mouseMoved) {