mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-13 16:29:31 -05:00
Fix issue with shutting down Flask server when not using --local-only (#238)
This commit is contained in:
parent
d35b5a9acd
commit
db1ed7c6de
@ -298,12 +298,7 @@ def page_not_found(e):
|
|||||||
error404_count += 1
|
error404_count += 1
|
||||||
if error404_count == 20:
|
if error404_count == 20:
|
||||||
add_request(REQUEST_RATE_LIMIT, request.path)
|
add_request(REQUEST_RATE_LIMIT, request.path)
|
||||||
|
force_shutdown()
|
||||||
# Learn the port the Flask app is running on, to stop it
|
|
||||||
# http://stackoverflow.com/questions/5085656/how-to-get-the-current-port-number-in-flask
|
|
||||||
port = int(request.host.split(':')[1])
|
|
||||||
stop(port)
|
|
||||||
|
|
||||||
print(strings._('error_rate_limit'))
|
print(strings._('error_rate_limit'))
|
||||||
|
|
||||||
return render_template_string(open(helpers.get_resource_path('html/404.html')).read())
|
return render_template_string(open(helpers.get_resource_path('html/404.html')).read())
|
||||||
@ -315,18 +310,23 @@ shutdown_slug = helpers.random_string(16)
|
|||||||
@app.route("/<slug_candidate>/shutdown")
|
@app.route("/<slug_candidate>/shutdown")
|
||||||
def shutdown(slug_candidate):
|
def shutdown(slug_candidate):
|
||||||
"""
|
"""
|
||||||
Stop the flask web server.
|
Stop the flask web server, from the context of an http request.
|
||||||
"""
|
"""
|
||||||
check_slug_candidate(slug_candidate, shutdown_slug)
|
check_slug_candidate(slug_candidate, shutdown_slug)
|
||||||
|
force_shutdown()
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
def force_shutdown():
|
||||||
|
"""
|
||||||
|
Stop the flask web server, from the context of the flask app.
|
||||||
|
"""
|
||||||
# shutdown the flask service
|
# shutdown the flask service
|
||||||
func = request.environ.get('werkzeug.server.shutdown')
|
func = request.environ.get('werkzeug.server.shutdown')
|
||||||
if func is None:
|
if func is None:
|
||||||
raise RuntimeError('Not running with the Werkzeug Server')
|
raise RuntimeError('Not running with the Werkzeug Server')
|
||||||
func()
|
func()
|
||||||
|
|
||||||
return ""
|
|
||||||
|
|
||||||
|
|
||||||
def start(port, stay_open=False, transparent_torification=False):
|
def start(port, stay_open=False, transparent_torification=False):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user