-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
31 lines (24 loc) · 904 Bytes
/
app.py
File metadata and controls
31 lines (24 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
import re
import json
import requests
from flask import Flask, request, render_template, make_response
app = Flask(__name__)
def get_current(proxy):
return requests.get('http://{0}:2020/behavior'.format(proxy)).json()['behavior']
def change_current(proxy, **optns):
requests.put('http://{0}:2020/behavior'.format(proxy),
data=json.dumps(optns))
@app.route("/", methods=['GET', 'POST'])
def flash():
if request.method == 'POST':
req = request.form.to_dict()
proxy = req.pop('proxy')
change_current(proxy, **req)
links = os.environ.get('links', '').split(',')
links = [(l,
' -> '.join(re.search('composemonkey_(.+)_(.+)', l).groups()),
get_current(l)) for l in links]
return render_template('index.html', links=links)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=2020, debug=True)