Add basic torrent validation
This commit is contained in:
sqozz 2017-12-30 20:28:14 +01:00
commit b34348f035

View File

@ -124,6 +124,30 @@ def createNewTorrent(reuqest):
bcoded = bencoder.decode(content)
info_hash = sha1(bencoder.encode(bcoded[b'info'])).hexdigest()
#TODO: Validate the input serverside before writing it to the database
name = request.form["name"]
category = request.form["category"]
subcategory = request.form["subcategory"]
description = request.form["description"]
audioquality_description = request.form["audioquality_description"]
videoquality_description = request.form["videoquality_description"]
newTFile = TorrentFile(info_hash, name, category, subcategory, description, audioquality_description, videoquality_description)
try:
announce = bcoded[b'announce-list']
except KeyError:
announce = (bcoded[b'announce'], )
is_ours = False
for a in announce:
if a in [b'udp://tracker.lootbox.cf:6969/announce', b'udp://tracker.lootbox.cf:6969/announce/',b'udp://tracker.lootbox.cf/announce',b'udp://tracker.lootbox.cf/announce/']:
is_ours = True
break
if not is_ours:
newTFile.errors = ["Rejecting torrent <a href=\"/search?h={}\">{}</a>, as it does not use our tracker".format(info_hash, info_hash[:-20])]
return newTFile
with open("torrentFiles/" + info_hash, "wb") as torrent_file:
torrent_file.write(content)
@ -161,8 +185,11 @@ def createNewTorrent(reuqest):
class Metadata():
def __init__(self, fileid):
try:
with open("torrentFiles/" + fileid, "rb") as f:
torrent = f.read()
except FileNotFoundError:
return
self.fileid = fileid
self.bcoded = bencoder.decode(torrent)
self.created_by = self.bcoded.get(b'created by', b"")