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
|
|
|
|
2019-01-14 22:10:21 -06: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 11:12:47 +02:00
|
|
|
app = Flask(__name__)
|
2014-05-30 17:34:00 +03:00
|
|
|
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
|
|
|
|
2018-12-14 23:01:27 -06:00
|
|
|
@app.after_request
|
|
|
|
def add_header(response):
|
|
|
|
response.cache_control.max_age = 300
|
|
|
|
return response
|
|
|
|
|
2014-03-19 11:12:47 +02:00
|
|
|
if __name__ == '__main__':
|
2019-01-14 22:10:21 -06:00
|
|
|
args = parser.parse_args()
|
|
|
|
app.run(host=args.host, port=args.port)
|