5
0
mirror of https://github.com/cwinfo/yggdrasil-map synced 2024-11-09 23:00:26 +00:00
yggdrasil-map/web/web.py

57 lines
1.6 KiB
Python
Raw Normal View History

2014-03-19 09:12:47 +00:00
from flask import Flask, render_template, request
2014-05-28 16:48:46 +00:00
from graphData import insert_graph_data
2014-03-19 09:12:47 +00:00
2019-01-15 04:10:21 +00:00
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--host", type=str, help="host to listen on (default 'localhost')", default="localhost")
parser.add_argument("--port", type=int, help="port to listen on (default '3000')", default=3000)
2014-03-19 09:12:47 +00:00
app = Flask(__name__)
app.config.from_pyfile('web_config.cfg')
2014-03-19 09:12:47 +00:00
2015-07-30 16:59:30 +00:00
def get_ip():
2015-08-28 07:07:44 +00:00
try:
ip = request.headers['x-real-ip']
except KeyError:
ip = None
2015-07-26 17:08:51 +00:00
if ip == '10.18.3.20':
ip = request.headers['x-atomshare-real-ip']
2015-07-30 16:59:30 +00:00
return ip
@app.context_processor
def add_ip():
return dict(ip=get_ip())
2014-03-19 09:12:47 +00:00
@app.route('/')
@app.route('/network')
def page_network():
2015-11-21 11:47:21 +00:00
return render_template('network.html', page='network')
2014-05-13 22:36:55 +00:00
@app.route('/about')
def page_about():
2015-11-21 11:47:21 +00:00
return render_template('about.html', page='about')
2014-03-19 09:12:47 +00:00
2014-05-28 16:48:46 +00:00
@app.route('/sendGraph', methods=['POST'])
def page_sendGraph():
2015-11-21 11:47:21 +00:00
print "Receiving graph from %s" % (request.remote_addr)
2015-11-21 12:03:19 +00: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 11:47:21 +00:00
if ret == None:
return 'OK'
else:
return 'Error: %s' % ret
2014-03-19 09:12:47 +00:00
2018-12-15 05:01:27 +00:00
@app.after_request
def add_header(response):
response.cache_control.max_age = 300
return response
2014-03-19 09:12:47 +00:00
if __name__ == '__main__':
2019-01-15 04:10:21 +00:00
args = parser.parse_args()
app.run(host=args.host, port=args.port)