5
0
mirror of https://github.com/cwinfo/yggdrasil-map synced 2025-02-16 22:29:14 +00:00

46 lines
1.2 KiB
Python
Raw Normal View History

2014-03-19 11:12:47 +02:00
from flask import Flask, render_template, request
2014-05-28 19:48:46 +03:00
from graphData import insert_graph_data
2014-03-19 11:12:47 +02:00
app = Flask(__name__)
app.config.from_pyfile('web_config.cfg')
2014-03-19 11:12:47 +02:00
2015-07-30 18:59:30 +02:00
def get_ip():
2015-08-28 00:07:44 -07:00
try:
ip = request.headers['x-real-ip']
except KeyError:
ip = None
2015-07-26 19:08:51 +02:00
if ip == '10.18.3.20':
ip = request.headers['x-atomshare-real-ip']
2015-07-30 18:59:30 +02:00
return ip
@app.context_processor
def add_ip():
return dict(ip=get_ip())
2014-03-19 11:12:47 +02:00
@app.route('/')
@app.route('/network')
def page_network():
2015-11-21 12:47:21 +01:00
return render_template('network.html', page='network')
2014-05-14 01:36:55 +03:00
@app.route('/about')
def page_about():
2015-11-21 12:47:21 +01:00
return render_template('about.html', page='about')
2014-03-19 11:12:47 +02:00
2014-05-28 19:48:46 +03:00
@app.route('/sendGraph', methods=['POST'])
def page_sendGraph():
2015-11-21 12:47:21 +01:00
print "Receiving graph from %s" % (request.remote_addr)
2015-11-21 13:03:19 +01:00
data = request.form['data']
mail = request.form.get('mail', 'none')
version = int(request.form.get('version', '1'))
ret = insert_graph_data(ip=get_ip(), config=app.config, data=data, mail=mail, version=version)
2015-11-21 12:47:21 +01:00
if ret == None:
return 'OK'
else:
return 'Error: %s' % ret
2014-03-19 11:12:47 +02:00
if __name__ == '__main__':
2015-11-21 12:47:21 +01:00
app.run(host='localhost', port=3000)