コード例 #1
0
ファイル: pyloadweb.py プロジェクト: torrero007/pyload
def downloads():
    root = PYLOAD.getConfigValue("general", "download_folder")

    if not isdir(root):
        return base([_('Download directory not found.')])
    data = {
        'folder': [],
        'files': []
    }

    items = listdir(fs_encode(root))

    for item in sorted([fs_decode(x) for x in items]):
        if isdir(fs_join(root, item)):
            folder = {
                'name': item,
                'path': item,
                'files': []
            }
            files = listdir(fs_join(root, item))
            for file in sorted([fs_decode(x) for x in files]):
                try:
                    if isfile(fs_join(root, item, file)):
                        folder['files'].append(file)
                except Exception:
                    pass

            data['folder'].append(folder)
        elif isfile(join(root, item)):
            data['files'].append(item)

    return render_to_response('downloads.html', {'files': data}, [pre_processor])
コード例 #2
0
ファイル: UnRar.py プロジェクト: PaddyPat/pyload
    def list(self, password=None):
        command = "vb" if self.fullpath else "lb"

        p = self.call_cmd(command,
                          "-v",
                          fs_encode(self.filename),
                          password=password)
        out, err = p.communicate()

        if "Cannot open" in err:
            raise ArchiveError(_("Cannot open file"))

        if err.strip():  #: only log error at this point
            self.manager.logError(err.strip())

        result = set()
        if not self.fullpath and self.VERSION.startswith('5'):
            # NOTE: Unrar 5 always list full path
            for f in fs_decode(out).splitlines():
                f = fs_join(self.out, os.path.basename(f.strip()))
                if os.path.isfile(f):
                    result.add(fs_join(self.out, os.path.basename(f)))
        else:
            for f in fs_decode(out).splitlines():
                f = f.strip()
                result.add(fs_join(self.out, f))

        return list(result)
コード例 #3
0
ファイル: app.py プロジェクト: Arisharr/Download-Manager
def downloads():
    root = PYLOAD.getConfigValue("general", "download_folder")

    if not os.path.isdir(root):
        return base([_('Download directory not found.')])
    data = {'folder': [], 'files': []}

    items = os.listdir(fs_encode(root))

    for item in sorted([fs_decode(x) for x in items]):
        if os.path.isdir(fs_join(root, item)):
            folder = {'name': item, 'path': item, 'files': []}
            files = os.listdir(fs_join(root, item))
            for file in sorted([fs_decode(x) for x in files]):
                try:
                    if os.path.isfile(fs_join(root, item, file)):
                        folder['files'].append(file)
                except Exception:
                    pass

            data['folder'].append(folder)
        elif os.path.isfile(os.path.join(root, item)):
            data['files'].append(item)

    return render_to_response('downloads.html', {'files': data},
                              [pre_processor])
コード例 #4
0
ファイル: UnRar.py プロジェクト: achimschneider/pyload
    def list(self, password=None):
        command = "vb" if self.fullpath else "lb"

        p = self.call_cmd(command, "-v", fs_encode(self.filename), password=password)
        out, err = p.communicate()

        if "Cannot open" in err:
            raise ArchiveError(_("Cannot open file"))

        if err.strip():  #: only log error at this point
            self.manager.logError(err.strip())

        result = set()
        if not self.fullpath and self.VERSION.startswith('5'):
            # NOTE: Unrar 5 always list full path
            for f in fs_decode(out).splitlines():
                f = fs_join(self.out, os.path.basename(f.strip()))
                if os.path.isfile(f):
                    result.add(fs_join(self.out, os.path.basename(f)))
        else:
            for f in fs_decode(out).splitlines():
                f = f.strip()
                result.add(fs_join(self.out, f))

        return list(result)
コード例 #5
0
                    location,
                    int(self.core.config.get("permission", "folder"), 8))

                if self.core.config.get("permission",
                                        "change_dl") and os.name != "nt":
                    uid = pwd.getpwnam(
                        self.core.config.get("permission", "user"))[2]
                    gid = grp.getgrnam(
                        self.core.config.get("permission", "group"))[2]
                    os.chown(location, uid, gid)

            except Exception, e:
                self.fail(e)

        # convert back to unicode
        location = fs_decode(location)
        name = safe_filename(self.pyfile.name)

        filename = os.path.join(location, name)

        self.core.addonManager.dispatchEvent("download-start", self.pyfile,
                                             url, filename)

        try:
            newname = self.req.httpDownload(
                url,
                filename,
                get=get,
                post=post,
                ref=ref,
                cookies=cookies,
コード例 #6
0
ファイル: Plugin.py プロジェクト: Bobbaone/pyload
        location = fs_join(download_folder, self.pyfile.package().folder)

        if not os.path.exists(location):
            try:
                os.makedirs(location, int(self.core.config.get("permission", "folder"), 8))

                if self.core.config.get("permission", "change_dl") and os.name != "nt":
                    uid = pwd.getpwnam(self.core.config.get("permission", "user"))[2]
                    gid = grp.getgrnam(self.core.config.get("permission", "group"))[2]
                    os.chown(location, uid, gid)

            except Exception, e:
                self.fail(e)

        # convert back to unicode
        location = fs_decode(location)
        name = safe_filename(self.pyfile.name)

        filename = os.path.join(location, name)

        self.core.addonManager.dispatchEvent("download-start", self.pyfile, url, filename)

        try:
            newname = self.req.httpDownload(url, filename, get=get, post=post, ref=ref, cookies=cookies,
                                            chunks=self.getChunkCount(), resume=self.resumeDownload,
                                            progressNotify=self.pyfile.setProgress, disposition=disposition)
        finally:
            self.pyfile.size = self.req.size

        if newname:
            newname = urlparse.urlparse(newname).path.split('/')[-1]
コード例 #7
0
ファイル: MegaCoNz.py プロジェクト: Arisharr/Download-Manager
class MegaCoNz(Hoster):
    __name = "MegaCoNz"
    __type = "hoster"
    __version = "0.26"

    __pattern = r'(?:https?://(?:www\.)?mega\.co\.nz/|mega:|chrome:.+?)#(?P<TYPE>N|)!(?P<ID>[\w^_]+)!(?P<KEY>[\w,-]+)'

    __description = """Mega.co.nz hoster plugin"""
    __license = "GPLv3"
    __authors = [("RaNaN", "*****@*****.**"),
                 ("Walter Purcaro", "*****@*****.**")]

    API_URL = "https://eu.api.mega.co.nz/cs"
    FILE_SUFFIX = ".crypted"

    def b64_decode(self, data):
        data = data.replace("-", "+").replace("_", "/")
        return base64.standard_b64decode(data + '=' * (-len(data) % 4))

    def getCipherKey(self, key):
        """ Construct the cipher key from the given data """
        a = array.array("I", self.b64_decode(key))

        k = array.array("I",
                        (a[0] ^ a[4], a[1] ^ a[5], a[2] ^ a[6], a[3] ^ a[7]))
        iv = a[4:6] + array.array("I", (0, 0))
        meta_mac = a[6:8]

        return k, iv, meta_mac

    def api_response(self, **kwargs):
        """ Dispatch a call to the api, see https://mega.co.nz/#developers """

        # generate a session id, no idea where to obtain elsewhere
        uid = random.random.randint(10 << 9, 10**10)

        res = self.load(self.API_URL,
                        get={'id': uid},
                        post=json_dumps([kwargs]))
        self.logDebug("Api Response: " + res)
        return json_loads(res)

    def decryptAttr(self, data, key):
        k, iv, meta_mac = self.getCipherKey(key)
        cbc = Crypto.Cipher.AES.new(k, Crypto.Cipher.AES.MODE_CBC, "\0" * 16)
        attr = decode(cbc.decrypt(self.b64_decode(data)))

        self.logDebug("Decrypted Attr: %s" % attr)
        if not attr.startswith("MEGA"):
            self.fail(_("Decryption failed"))

        # Data is padded, 0-bytes must be stripped
        return json_loads(re.search(r'{.+?}', attr).group(0))

    def decryptFile(self, key):
        """  Decrypts the file at lastDownload` """

        # upper 64 bit of counter start
        n = self.b64_decode(key)[16:24]

        # convert counter to long and shift bytes
        k, iv, meta_mac = self.getCipherKey(key)
        ctr = Crypto.Util.Counter.new(
            128, initial_value=long(n.encode("hex"), 16) << 64)
        cipher = Crypto.Cipher.AES.new(k,
                                       Crypto.Cipher.AES.MODE_CTR,
                                       counter=ctr)

        self.pyfile.setStatus("decrypting")
        self.pyfile.setProgress(0)

        file_crypted = fs_encode(self.lastDownload)
        file_decrypted = file_crypted.rsplit(self.FILE_SUFFIX)[0]

        try:
            f = open(file_crypted, "rb")
            df = open(file_decrypted, "wb")

        except IOError, e:
            self.fail(e)

        chunk_size = 2**15  #: buffer size, 32k
        # file_mac   = [0, 0, 0, 0]  #: calculate CBC-MAC for checksum

        chunks = os.path.getsize(file_crypted) / chunk_size + 1
        for i in xrange(chunks):
            buf = f.read(chunk_size)
            if not buf:
                break

            chunk = cipher.decrypt(buf)
            df.write(chunk)

            self.pyfile.setProgress(int((100.0 / chunks) * i))

            # chunk_mac = [iv[0], iv[1], iv[0], iv[1]]
            # for i in xrange(0, chunk_size, 16):
            # block = chunk[i:i+16]
            # if len(block) % 16:
            # block += '=' * (16 - (len(block) % 16))
            # block = array.array("I", block)

            # chunk_mac = [chunk_mac[0] ^ a_[0], chunk_mac[1] ^ block[1], chunk_mac[2] ^ block[2], chunk_mac[3] ^ block[3]]
            # chunk_mac = aes_cbc_encrypt_a32(chunk_mac, k)

            # file_mac = [file_mac[0] ^ chunk_mac[0], file_mac[1] ^ chunk_mac[1], file_mac[2] ^ chunk_mac[2], file_mac[3] ^ chunk_mac[3]]
            # file_mac = aes_cbc_encrypt_a32(file_mac, k)

        self.pyfile.setProgress(100)

        f.close()
        df.close()

        # if file_mac[0] ^ file_mac[1], file_mac[2] ^ file_mac[3] != meta_mac:
        # os.remove(file_decrypted)
        # self.fail(_("Checksum mismatch"))

        os.remove(file_crypted)
        self.lastDownload = fs_decode(file_decrypted)