mirror of
https://github.com/cwinfo/yggdrasil-map
synced 2024-11-22 12:50:27 +00:00
add uploaded_by, JS map fixes
This commit is contained in:
parent
3478a0023c
commit
26343b47fb
@ -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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
@ -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'
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user