|
from flask import Flask, request, Response, jsonify |
|
import requests |
|
|
|
app = Flask(__name__) |
|
|
|
app.logger.disabled = True |
|
|
|
@app.route('/') |
|
def show_ip(): |
|
|
|
return jsonify({ |
|
"status": "running", |
|
"proxy_config_url": request.url_root + "proxy.pac" |
|
}) |
|
|
|
@app.route('/proxy.pac') |
|
def proxy_pac(): |
|
pac_content = """function FindProxyForURL(url, host) { |
|
return "PROXY %s:7860; DIRECT"; |
|
}""" % request.host |
|
|
|
return Response( |
|
pac_content, |
|
mimetype='application/x-ns-proxy-autoconfig' |
|
) |
|
|
|
@app.route('/<path:url>', methods=['GET', 'POST', 'PUT', 'DELETE']) |
|
def proxy(url): |
|
try: |
|
response = requests.request( |
|
method=request.method, |
|
url=url, |
|
headers={key: value for (key, value) in request.headers if key != 'Host'}, |
|
data=request.get_data(), |
|
allow_redirects=False |
|
) |
|
return Response(response.content, response.status_code) |
|
except: |
|
return Response("Error", 500) |
|
|
|
if __name__ == "__main__": |
|
|
|
import logging |
|
log = logging.getLogger('werkzeug') |
|
log.disabled = True |
|
app.run(host="0.0.0.0", port=7860) |