mirror of
https://gitlab.com/SIGBUS/nyaa.git
synced 2024-12-22 11:10:00 +00:00
Don't enforce site tracker as first, just that it exists on the torrent
Fixes issue #42 Also adds logic for private torrents requiring site tracker as the main tracker (otherwise there's no point on uploading them on the site) Changes upload.html wording to reflect the requirement to have the tracker, not necessarily as the first one.
This commit is contained in:
parent
22cea7af17
commit
c1df153e98
|
@ -221,19 +221,23 @@ class UploadForm(FlaskForm):
|
|||
except AssertionError as e:
|
||||
raise ValidationError('Malformed torrent metadata ({})'.format(e.args[0]))
|
||||
|
||||
|
||||
site_tracker = app.config.get('MAIN_ANNOUNCE_URL')
|
||||
ensure_tracker = app.config.get('ENFORCE_MAIN_ANNOUNCE_URL')
|
||||
|
||||
try:
|
||||
_validate_trackers(torrent_dict)
|
||||
tracker_found = _validate_trackers(torrent_dict, site_tracker)
|
||||
except AssertionError as e:
|
||||
raise ValidationError('Malformed torrent trackers ({})'.format(e.args[0]))
|
||||
|
||||
if app.config.get('ENFORCE_MAIN_ANNOUNCE_URL'):
|
||||
main_announce_url = app.config.get('MAIN_ANNOUNCE_URL')
|
||||
if not main_announce_url:
|
||||
raise Exception('Config MAIN_ANNOUNCE_URL not set!')
|
||||
# Ensure private torrents are using our tracker
|
||||
if torrent_dict['info'].get('private') == 1:
|
||||
if torrent_dict['announce'].decode('utf-8') != site_tracker:
|
||||
raise ValidationError('Private torrent: please set {} as the main tracker'.format(site_tracker))
|
||||
|
||||
elif ensure_tracker and not tracker_found:
|
||||
raise ValidationError('Please include {} in the trackers of the torrent'.format(site_tracker))
|
||||
|
||||
announce = torrent_dict.get('announce', b'').decode('utf-8')
|
||||
if announce != main_announce_url:
|
||||
raise ValidationError('Please set {} as the first tracker in the torrent'.format(main_announce_url))
|
||||
|
||||
# Note! bencode will sort dict keys, as per the spec
|
||||
# This may result in a different hash if the uploaded torrent does not match the
|
||||
|
@ -262,9 +266,11 @@ class TorrentFileData(object):
|
|||
|
||||
# https://wiki.theory.org/BitTorrentSpecification#Metainfo_File_Structure
|
||||
|
||||
def _validate_trackers(torrent_dict):
|
||||
def _validate_trackers(torrent_dict, tracker_to_check_for=None):
|
||||
announce = torrent_dict.get('announce')
|
||||
_validate_bytes(announce)
|
||||
announce_string = _validate_bytes(announce, 'announce', 'utf-8')
|
||||
|
||||
tracker_found = tracker_to_check_for and (announce_string.lower() == tracker_to_check_for.lower()) or False
|
||||
|
||||
announce_list = torrent_dict.get('announce-list')
|
||||
if announce_list is not None:
|
||||
|
@ -273,7 +279,11 @@ def _validate_trackers(torrent_dict):
|
|||
for announce in announce_list:
|
||||
_validate_list(announce, 'announce-list item')
|
||||
|
||||
_validate_bytes(announce[0], 'announce-list item item')
|
||||
announce_string = _validate_bytes(announce[0], 'announce-list item url', 'utf-8')
|
||||
if tracker_to_check_for and announce_string.lower() == tracker_to_check_for.lower():
|
||||
tracker_found = True
|
||||
|
||||
return tracker_found
|
||||
|
||||
|
||||
def _validate_torrent_metadata(torrent_dict):
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
|
||||
<form method="POST" enctype="multipart/form-data">
|
||||
{% if config.ENFORCE_MAIN_ANNOUNCE_URL %}<p><strong>Important:</strong> Please put <i>{{config.MAIN_ANNOUNCE_URL}}</i> as your first tracker</p>{% endif %}
|
||||
{% if config.ENFORCE_MAIN_ANNOUNCE_URL %}<p><strong>Important:</strong> Please include <i>{{config.MAIN_ANNOUNCE_URL}}</i> in your trackers</p>{% endif %}
|
||||
<div class="row">
|
||||
<div class="form-group col-md-6">
|
||||
{{ render_upload(form.torrent_file, accept=".torrent") }}
|
||||
|
|
Loading…
Reference in a new issue