Beispiel #1
0
    def decode(self):
        '''
        Dekodovanie bencode torrentu.
        @return True v pridade uspesneho spracovania
        '''

        torrent, bdictionary = None, None

        try:
            torrent = open(self.path, 'rb')
        except:
            Log.error("Torrent: Nepodarilo sa otvorit torrent {}".format(self.path))
            return False

        try:
            bdictionary = bnc.bdecode(torrent.read())
        except:
            Log.error("Torrent: Nepodarilo sa dekodovat bencode v torrente {}".format(self.path))
            return False

        # Spracovanie info sekcie
        info               = bdictionary['info']
        self.info_hash     = hashlib.sha1(bnc.bencode(info)).hexdigest()
        self.info_hash_url = urllib.quote_plus(hashlib.sha1(bnc.bencode(info)).digest())
        self.name          = info['name']

        # Ziskanie trackerov
        try:
            announce_list = bdictionary['announce-list']
            for al in announce_list:
                if isinstance(al, list):
                    for a in al:
                        self.announce_list.append(a)
                else:
                    self.announce_list.append(a)
            self.announce_list = set(self.announce_list)
        except:
            self.announce_list.append(bdictionary['announce'])

        return True
Beispiel #2
0
    def remove_all(self):
        """ Remove all comprimizing fields
        """
        with open(self.filename, 'r') as f:
            decoded = bencode.bdecode(f.read())

        cleaned = self.__remove_all_recursively(decoded)

        with open(self.output, 'w') as f:  # encode the decoded torrent
            f.write(bencode.bencode(cleaned))  # and write it in self.output

        self.do_backup()
        return True
Beispiel #3
0
    def remove_all(self):
        """ Remove all comprimizing fields
        """
        with open(self.filename, 'r') as f:
            decoded = bencode.bdecode(f.read())

        cleaned = self.__remove_all_recursively(decoded)

        with open(self.output, 'w') as f:  # encode the decoded torrent
            f.write(bencode.bencode(cleaned))  # and write it in self.output

        self.do_backup()
        return True
Beispiel #4
0
    def remove_all(self):
        """ Remove all comprimizing fields
        """
        with open(self.filename, 'r') as f:
            decoded = bencode.bdecode(f.read())

        cleaned = {i: j for i, j in list(decoded.items()) if i in self.fields}

        with open(self.output, 'w') as f:  # encode the decoded torrent
            f.write(bencode.bencode(cleaned))  # and write it in self.output

        self.do_backup()
        return True
Beispiel #5
0
 def remove_all(self):
     '''
         Remove all the files that are compromizing
     '''
     with open(self.filename, 'r') as f:
         decoded = bencode.bdecode(f.read())
     for key in self.fields:
         try:
             decoded[key] = ''
         except:
             pass
     with open(self.output, 'w') as f:  # encode the decoded torrent
         f.write(bencode.bencode(decoded))  # and write it in self.output
     self.do_backup()
Beispiel #6
0
    def remove_all(self):
        """ Remove all comprimizing fields
        """
        decoded = ''
        with open(self.filename, 'r') as f:
            decoded = bencode.bdecode(f.read())

        cleaned = {i: j for i, j in list(decoded.items()) if i in self.fields}

        with open(self.output, 'w') as f:  # encode the decoded torrent
            f.write(bencode.bencode(cleaned))  # and write it in self.output

        self.do_backup()
        return True
Beispiel #7
0
 def remove_all(self):
     """
         Remove all the files that are compromising
     """
     with open(self.filename, "r") as f:
         decoded = bencode.bdecode(f.read())
     for key in self.fields:
         try:
             decoded[key] = ""
         except KeyError:
             pass
     with open(self.output, "w") as f:  # encode the decoded torrent
         f.write(bencode.bencode(decoded))  # and write it in self.output
     self.do_backup()
     return True
Beispiel #8
0
    def do_GET(self):
        self.send_response(200)
        self.send_header('Content-type', 'text/plain')
        self.end_headers()
        request = parse_qs(urlparse(self.path).query)
        hash = request['info_hash'][0]
        ip = self.client_address[0]
        port = request['port'][0]
        if hash in peers:
            if (ip, port) not in peers[hash]:
                peers[hash].append((ip, port))
        else:
            peers[hash] = [
                (ip, port),
            ]

        print peers
        prepared_peers = ''
        for p in peers[hash]:
            prepared_peers += ''.join(map(chr, map(int, p[0].split('.'))))
            prepared_peers += struct.pack('>H', int(p[1]))
        response = bencode({'interval': 60, 'peers': prepared_peers})
        print response
        self.wfile.write(response)
Beispiel #9
0
file.close()
info = bdecode(data)

if len(sys.argv) == 2 :
	print info
	sys.exit()

if 'announce-list' not in info :
	list = [info['announce']]
	for i in range(len(sys.argv)-2) :
		tracker = sys.argv[i+2]
		if tracker not in list :
			list.append(tracker)
	print list
	info['announce-list'] = [list]
else :
	list = info['announce-list'][0]
	if type(list) == StringType :
		list = [list]
	for i in range(len(sys.argv)-2) :
		tracker = sys.argv[i+2]
		if tracker not in list :
			list.append(tracker)
	print list
	info['announce-list'][0] = list

writedata = bencode(info)
file = open(torrent, "wb")
file.write(writedata)
file.close()
Beispiel #10
0
def encode(data):
    return bencode.bencode(data)