mirror of
https://github.com/cwinfo/yggdrasil-map
synced 2024-11-09 16:00:27 +00:00
sendGraph.py updates
This commit is contained in:
parent
f4fc407f8e
commit
8cfd0bf957
@ -1,18 +1,18 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# CONFIG
|
# CONFIG
|
||||||
|
|
||||||
# URL where data is sent
|
# URL where data is sent
|
||||||
# fc00.atomshare.net for clearnet access
|
# www.fc00.org for clearnet access
|
||||||
# h.fc00.atomshare.net for hyperboria
|
# h.fc00.org for hyperboria
|
||||||
# [fc53:dcc5:e89d:9082:4097:6622:5e82:c654] for DNS-less access
|
# [fc53:dcc5:e89d:9082:4097:6622:5e82:c654] for DNS-less access
|
||||||
url = 'http://fc00.atomshare.net/sendGraph'
|
url = 'http://www.fc00.org/sendGraph'
|
||||||
|
# update your email address, so I can contact you in case something goes wrong
|
||||||
|
your_mail = 'bad_mail@example.com'
|
||||||
|
|
||||||
# Cjdns path without trailing slash
|
# Cjdns path without trailing slash
|
||||||
cjdns_path = '/opt/cjdns'
|
cjdns_path = '/opt/cjdns'
|
||||||
|
|
||||||
|
|
||||||
# ----------------------
|
# ----------------------
|
||||||
# RPC connection details
|
# RPC connection details
|
||||||
# ----------------------
|
# ----------------------
|
||||||
@ -29,9 +29,11 @@ cjdns_processes = 1 # This can be used if you are running multiple instances
|
|||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
if your_mail == 'bad_mail@example.com':
|
||||||
|
sys.exit('Please edit sendGraph.py to include your email address.')
|
||||||
|
|
||||||
import urllib
|
import urllib
|
||||||
import urllib2
|
import urllib2
|
||||||
from collections import deque
|
from collections import deque
|
||||||
@ -200,7 +202,6 @@ def cjdns_graph_from_nodes(cjdns, source_nodes):
|
|||||||
|
|
||||||
# Add edge
|
# Add edge
|
||||||
e = Edge(nodes[node.ip], nodes[child_ip])
|
e = Edge(nodes[node.ip], nodes[child_ip])
|
||||||
print node.ip, child_ip
|
|
||||||
if not e in edges:
|
if not e in edges:
|
||||||
edges.append(e)
|
edges.append(e)
|
||||||
|
|
||||||
@ -209,7 +210,7 @@ def cjdns_graph_from_nodes(cjdns, source_nodes):
|
|||||||
|
|
||||||
|
|
||||||
def send_data(graph_data):
|
def send_data(graph_data):
|
||||||
post_data = urllib.urlencode({'data': graph_data})
|
post_data = urllib.urlencode({'data': graph_data, 'mail': your_mail})
|
||||||
req = urllib2.Request(url, post_data)
|
req = urllib2.Request(url, post_data)
|
||||||
response = urllib2.urlopen(req)
|
response = urllib2.urlopen(req)
|
||||||
return response.read()
|
return response.read()
|
||||||
|
@ -3,9 +3,9 @@ from database import NodeDB
|
|||||||
from graph import Node, Edge
|
from graph import Node, Edge
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
def insert_graph_data(config, json_str):
|
def insert_graph_data(config, data, mail, ip):
|
||||||
try:
|
try:
|
||||||
graph_data = json.loads(json_str)
|
graph_data = json.loads(data)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return 'Invalid JSON'
|
return 'Invalid JSON'
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ def insert_graph_data(config, json_str):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
with NodeDB(config) as db:
|
with NodeDB(config) as db:
|
||||||
db.insert_graph(nodes, edges)
|
db.insert_graph(nodes, edges)
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return 'Database failure'
|
return 'Database failure'
|
||||||
|
@ -9,9 +9,13 @@
|
|||||||
|
|
||||||
<h3>Network map</h3>
|
<h3>Network map</h3>
|
||||||
<p>The network page has a map of Hyperboria as it is now. The map is not complete since it is hard/impossible to get a full picture of the network. A rough estimate is that at least half of the nodes are pictured here, probably more. The nodes and links that are shown on the page are very likely to exist but this should not be taken as a guarantee.</p>
|
<p>The network page has a map of Hyperboria as it is now. The map is not complete since it is hard/impossible to get a full picture of the network. A rough estimate is that at least half of the nodes are pictured here, probably more. The nodes and links that are shown on the page are very likely to exist but this should not be taken as a guarantee.</p>
|
||||||
|
|
||||||
|
<h3>Node names</h3>
|
||||||
|
<p>For now, node names are assigned manually. You can submit Pull Request to <a href="https://github.com/zielmicha/nodedb">nodedb</a> if you want to have your node named.
|
||||||
|
In future this will be replaced by some reverse DNS system.
|
||||||
|
|
||||||
<h3>Contact</h3>
|
<h3>Contact</h3>
|
||||||
<p>fc00 was orginally created by <em>Randati</em>. Currently fc00 is run by <em>zielmicha</em>.
|
<p>fc00 was orginally created by <em>Randati</em>. fc00 is currently run by <em>zielmicha</em>.
|
||||||
If you have something to say or you would like to help, contact him via michal@zielinscy.org.pl.</p>
|
If you have something to say or you would like to help, contact him via michal@zielinscy.org.pl.</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
15
web/web.py
15
web/web.py
@ -4,13 +4,15 @@ from graphData import insert_graph_data
|
|||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config.from_pyfile('web_config.cfg')
|
app.config.from_pyfile('web_config.cfg')
|
||||||
|
|
||||||
|
def get_ip():
|
||||||
@app.context_processor
|
|
||||||
def add_ip():
|
|
||||||
ip = request.headers['x-real-ip']
|
ip = request.headers['x-real-ip']
|
||||||
if ip == '10.18.3.20':
|
if ip == '10.18.3.20':
|
||||||
ip = request.headers['x-atomshare-real-ip']
|
ip = request.headers['x-atomshare-real-ip']
|
||||||
return dict(ip=ip)
|
return ip
|
||||||
|
|
||||||
|
@app.context_processor
|
||||||
|
def add_ip():
|
||||||
|
return dict(ip=get_ip())
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
@ -26,8 +28,9 @@ def page_about():
|
|||||||
def page_sendGraph():
|
def page_sendGraph():
|
||||||
print "Receiving graph from %s" % (request.remote_addr)
|
print "Receiving graph from %s" % (request.remote_addr)
|
||||||
|
|
||||||
data = request.form['data']
|
data = request.form['data']
|
||||||
ret = insert_graph_data(app.config, data)
|
mail = request.form.get('mail', 'none')
|
||||||
|
ret = insert_graph_data(ip=get_ip(), config=app.config, data=data, mail=mail)
|
||||||
if ret == None:
|
if ret == None:
|
||||||
return 'OK'
|
return 'OK'
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user