reject torrents that are not announced by our tracker
This commit is contained in:
parent
2c220afced
commit
ef3224ecf3
37
indexer.py
37
indexer.py
|
@ -131,10 +131,33 @@ 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)
|
||||
|
||||
bcoded = bencoder.decode(content)
|
||||
size = ((len(bcoded[b'info'][b'pieces']) / 20) * bcoded[b'info'][b'piece length']) / 1024 / 1024
|
||||
|
||||
print("=== CREATE NEW TORRENT FILE ===")
|
||||
|
@ -144,14 +167,6 @@ def createNewTorrent(reuqest):
|
|||
print( "Subcategory: " + request.form["subcategory"] )
|
||||
print( "Description: " + request.form["description"] )
|
||||
|
||||
#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:
|
||||
connection = sqlite3.connect("torrentdb.sqlite")
|
||||
newTFile.writeToDb(connection.cursor())
|
||||
|
@ -162,14 +177,18 @@ def createNewTorrent(reuqest):
|
|||
print(e)
|
||||
newTFile.errors = ["Torrent <a href=\"/search?h={}\">{}</a> already exists".format(info_hash, info_hash[:-20])]
|
||||
except Exception as e:
|
||||
print(e)
|
||||
newTFile.errors = ["Unknown error in creation"]
|
||||
|
||||
return newTFile
|
||||
|
||||
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"")
|
||||
|
|
Loading…
Reference in a new issue