mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
Add support for receive mode's "public mode", which doesn't use a slug. Still needs more testing
This commit is contained in:
parent
6cfb7026da
commit
4f89082f18
@ -264,20 +264,27 @@ class Web(object):
|
|||||||
"""
|
"""
|
||||||
The web app routes for sharing files
|
The web app routes for sharing files
|
||||||
"""
|
"""
|
||||||
@self.app.route("/<slug_candidate>")
|
|
||||||
def index(slug_candidate):
|
|
||||||
self.check_slug_candidate(slug_candidate)
|
|
||||||
|
|
||||||
|
def index_logic():
|
||||||
r = make_response(render_template(
|
r = make_response(render_template(
|
||||||
'receive.html',
|
'receive.html',
|
||||||
slug=self.slug,
|
slug=self.slug,
|
||||||
receive_allow_receiver_shutdown=self.common.settings.get('receive_allow_receiver_shutdown')))
|
receive_allow_receiver_shutdown=self.common.settings.get('receive_allow_receiver_shutdown')))
|
||||||
return self.add_security_headers(r)
|
return self.add_security_headers(r)
|
||||||
|
|
||||||
@self.app.route("/<slug_candidate>/upload", methods=['POST'])
|
@self.app.route("/<slug_candidate>")
|
||||||
def upload(slug_candidate):
|
def index(slug_candidate):
|
||||||
self.check_slug_candidate(slug_candidate)
|
self.check_slug_candidate(slug_candidate)
|
||||||
|
return index_logic()
|
||||||
|
|
||||||
|
@self.app.route("/")
|
||||||
|
def index_public():
|
||||||
|
if not self.common.settings.get('receive_public_mode'):
|
||||||
|
return self.error404()
|
||||||
|
return index_logic()
|
||||||
|
|
||||||
|
|
||||||
|
def upload_logic(slug_candidate=''):
|
||||||
files = request.files.getlist('file[]')
|
files = request.files.getlist('file[]')
|
||||||
filenames = []
|
filenames = []
|
||||||
for f in files:
|
for f in files:
|
||||||
@ -328,10 +335,19 @@ class Web(object):
|
|||||||
|
|
||||||
return redirect('/{}'.format(slug_candidate))
|
return redirect('/{}'.format(slug_candidate))
|
||||||
|
|
||||||
@self.app.route("/<slug_candidate>/close", methods=['POST'])
|
@self.app.route("/<slug_candidate>/upload", methods=['POST'])
|
||||||
def close(slug_candidate):
|
def upload(slug_candidate):
|
||||||
self.check_slug_candidate(slug_candidate)
|
self.check_slug_candidate(slug_candidate)
|
||||||
|
return upload_logic(slug_candidate)
|
||||||
|
|
||||||
|
@self.app.route("/upload")
|
||||||
|
def upload_public():
|
||||||
|
if not self.common.settings.get('receive_public_mode'):
|
||||||
|
return self.error404()
|
||||||
|
return upload_logic()
|
||||||
|
|
||||||
|
|
||||||
|
def close_logic(slug_candidate=''):
|
||||||
if self.common.settings.get('receive_allow_receiver_shutdown'):
|
if self.common.settings.get('receive_allow_receiver_shutdown'):
|
||||||
self.force_shutdown()
|
self.force_shutdown()
|
||||||
r = make_response(render_template('closed.html'))
|
r = make_response(render_template('closed.html'))
|
||||||
@ -339,6 +355,17 @@ class Web(object):
|
|||||||
return self.add_security_headers(r)
|
return self.add_security_headers(r)
|
||||||
else:
|
else:
|
||||||
return redirect('/{}'.format(slug_candidate))
|
return redirect('/{}'.format(slug_candidate))
|
||||||
|
|
||||||
|
@self.app.route("/<slug_candidate>/close", methods=['POST'])
|
||||||
|
def close(slug_candidate):
|
||||||
|
self.check_slug_candidate(slug_candidate)
|
||||||
|
return close_logic(slug_candidate)
|
||||||
|
|
||||||
|
@self.app.route("/upload")
|
||||||
|
def close_public():
|
||||||
|
if not self.common.settings.get('receive_public_mode'):
|
||||||
|
return self.error404()
|
||||||
|
return close_logic()
|
||||||
|
|
||||||
def common_routes(self):
|
def common_routes(self):
|
||||||
"""
|
"""
|
||||||
@ -349,17 +376,7 @@ class Web(object):
|
|||||||
"""
|
"""
|
||||||
404 error page.
|
404 error page.
|
||||||
"""
|
"""
|
||||||
self.add_request(self.REQUEST_OTHER, request.path)
|
return self.error404()
|
||||||
|
|
||||||
if request.path != '/favicon.ico':
|
|
||||||
self.error404_count += 1
|
|
||||||
if self.error404_count == 20:
|
|
||||||
self.add_request(self.REQUEST_RATE_LIMIT, request.path)
|
|
||||||
self.force_shutdown()
|
|
||||||
print(strings._('error_rate_limit'))
|
|
||||||
|
|
||||||
r = make_response(render_template('404.html'), 404)
|
|
||||||
return self.add_security_headers(r)
|
|
||||||
|
|
||||||
@self.app.route("/<slug_candidate>/shutdown")
|
@self.app.route("/<slug_candidate>/shutdown")
|
||||||
def shutdown(slug_candidate):
|
def shutdown(slug_candidate):
|
||||||
@ -370,6 +387,21 @@ class Web(object):
|
|||||||
self.force_shutdown()
|
self.force_shutdown()
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
def error404(self):
|
||||||
|
self.add_request(self.REQUEST_OTHER, request.path)
|
||||||
|
if request.path != '/favicon.ico':
|
||||||
|
self.error404_count += 1
|
||||||
|
|
||||||
|
# In receive mode, with public mode enabled, skip rate limiting 404s
|
||||||
|
if not (self.receive_mode and self.common.settings.get('receive_public_mode')):
|
||||||
|
if self.error404_count == 20:
|
||||||
|
self.add_request(self.REQUEST_RATE_LIMIT, request.path)
|
||||||
|
self.force_shutdown()
|
||||||
|
print(strings._('error_rate_limit'))
|
||||||
|
|
||||||
|
r = make_response(render_template('404.html'), 404)
|
||||||
|
return self.add_security_headers(r)
|
||||||
|
|
||||||
def add_security_headers(self, r):
|
def add_security_headers(self, r):
|
||||||
"""
|
"""
|
||||||
Add security headers to a request
|
Add security headers to a request
|
||||||
|
@ -162,7 +162,7 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
else:
|
else:
|
||||||
self.url_description.setToolTip(strings._('gui_url_label_stay_open', True))
|
self.url_description.setToolTip(strings._('gui_url_label_stay_open', True))
|
||||||
|
|
||||||
self.url.setText('http://{0:s}/{1:s}'.format(self.app.onion_host, self.web.slug))
|
self.url.setText(self.get_url())
|
||||||
self.url.show()
|
self.url.show()
|
||||||
|
|
||||||
self.copy_url_button.show()
|
self.copy_url_button.show()
|
||||||
@ -299,10 +299,8 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
"""
|
"""
|
||||||
Copy the onionshare URL to the clipboard.
|
Copy the onionshare URL to the clipboard.
|
||||||
"""
|
"""
|
||||||
url = 'http://{0:s}/{1:s}'.format(self.app.onion_host, self.web.slug)
|
|
||||||
|
|
||||||
clipboard = self.qtapp.clipboard()
|
clipboard = self.qtapp.clipboard()
|
||||||
clipboard.setText(url)
|
clipboard.setText(self.get_url())
|
||||||
|
|
||||||
self.url_copied.emit()
|
self.url_copied.emit()
|
||||||
|
|
||||||
@ -314,3 +312,13 @@ class ServerStatus(QtWidgets.QWidget):
|
|||||||
clipboard.setText(self.app.auth_string)
|
clipboard.setText(self.app.auth_string)
|
||||||
|
|
||||||
self.hidservauth_copied.emit()
|
self.hidservauth_copied.emit()
|
||||||
|
|
||||||
|
def get_url(self):
|
||||||
|
"""
|
||||||
|
Returns the OnionShare URL.
|
||||||
|
"""
|
||||||
|
if self.mode == ServerStatus.MODE_RECEIVE and self.common.settings.get('receive_public_mode'):
|
||||||
|
url = 'http://{0:s}'.format(self.app.onion_host)
|
||||||
|
else:
|
||||||
|
url = 'http://{0:s}/{1:s}'.format(self.app.onion_host, self.web.slug)
|
||||||
|
return url
|
||||||
|
Loading…
Reference in New Issue
Block a user