__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4; encoding:utf-8 -*- # # Copyright 2017 Tomas Vondra (Launchpad id: tomas-v) # Copyright 2017 Kenneth Loafman <[email protected]> # # This file is part of duplicity. # # Duplicity is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; either version 2 of the License, or (at your # option) any later version. # # Duplicity is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with duplicity; if not, write to the Free Software Foundation, # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import os import subprocess import duplicity.backend from duplicity.errors import BackendException class MegaBackend(duplicity.backend.Backend): """Connect to remote store using Mega.co.nz API""" def __init__(self, parsed_url): duplicity.backend.Backend.__init__(self, parsed_url) # ensure all the necessary megatools binaries exist self._check_binary_exists("megals") self._check_binary_exists("megamkdir") self._check_binary_exists("megaget") self._check_binary_exists("megaput") self._check_binary_exists("megarm") # store some basic info self._hostname = parsed_url.hostname if parsed_url.password is None: self._megarc = f"{os.getenv('HOME')}/.megarc" else: self._megarc = False self._username = parsed_url.username self._password = self.get_password() # remote folder (Can we assume /Root prefix?) self._root = "/Root" self._folder = f"{self._root}/{parsed_url.path[1:]}" # make sure the remote folder exists (the whole path) self._makedir_recursive(parsed_url.path[1:].split("/")) def _check_binary_exists(self, cmd): """checks that a specified command exists in the current path""" try: # ignore the output, we only need the return code subprocess.check_output(["which", cmd]) except Exception as e: raise BackendException(f"command '{cmd}' not found, make sure megatools are installed") def _makedir(self, path): """creates a remote directory""" if self._megarc: cmd = ["megamkdir", "--config", self._megarc, path] else: cmd = ["megamkdir", "-u", self._username, "-p", self._password, path] self.subprocess_popen(cmd) def _makedir_recursive(self, path): """creates a remote directory (recursively the whole path), ingores errors""" print(f"mkdir: {'/'.join(path)}") p = self._root for folder in path: p = f"{p}/{folder}" try: self._makedir(p) except Exception as e: pass def _put(self, source_path, remote_filename): """uploads file to Mega (deletes it first, to ensure it does not exist)""" try: self.delete(os.fsdecode(remote_filename)) except Exception: pass self.upload(local_file=os.fsdecode(source_path.get_canonical()), remote_file=os.fsdecode(remote_filename)) def _get(self, remote_filename, local_path): """downloads file from Mega""" self.download(remote_file=os.fsdecode(remote_filename), local_file=os.fsdecode(local_path.name)) def _list(self): """list files in the backup folder""" return self.folder_contents(files_only=True) def _delete(self, filename): """deletes remote""" self.delete(remote_file=os.fsdecode(filename)) def folder_contents(self, files_only=False): """lists contents of a folder, optionally ignoring subdirectories""" print(f"megals: {self._folder}") if self._megarc: cmd = ["megals", "--config", self._megarc, self._folder] else: cmd = ["megals", "-u", self._username, "-p", self._password, self._folder] files = subprocess.check_output(cmd) files = os.fsdecode(files.strip()).split("\n") # remove the folder name, including the path separator files = [f[len(self._folder) + 1 :] for f in files] # optionally ignore entries containing path separator (i.e. not files) if files_only: files = [f for f in files if "/" not in f] return [os.fsencode(f) for f in files] def download(self, remote_file, local_file): print(f"megaget: {remote_file}") if self._megarc: cmd = [ "megaget", "--config", self._megarc, "--no-progress", "--path", local_file, f"{self._folder}/{remote_file}", ] else: cmd = [ "megaget", "-u", self._username, "-p", self._password, "--no-progress", "--path", local_file, f"{self._folder}/{remote_file}", ] self.subprocess_popen(cmd) def upload(self, local_file, remote_file): print(f"megaput: {remote_file}") if self._megarc: cmd = [ "megaput", "--config", self._megarc, "--no-progress", "--path", f"{self._folder}/{remote_file}", local_file, ] else: cmd = [ "megaput", "-u", self._username, "-p", self._password, "--no-progress", "--path", f"{self._folder}/{remote_file}", local_file, ] try: self.subprocess_popen(cmd) except Exception as e: error_str = str(e) if "EOVERQUOTA" in error_str: raise BackendException( f"MEGA account over quota, could not write file : '{remote_file}'. " f"Upgrade your storage at https://mega.nz/pro or remove some data." ) else: raise BackendException(f"Failed writing file '{remote_file}' to MEGA , reason : '{e}'") def delete(self, remote_file): print(f"megarm: {remote_file}") if self._megarc: cmd = ["megarm", "--config", self._megarc, f"{self._folder}/{remote_file}"] else: cmd = ["megarm", "-u", self._username, "-p", self._password, f"{self._folder}/{remote_file}"] self.subprocess_popen(cmd) duplicity.backend.register_backend("mega", MegaBackend) duplicity.backend.uses_netloc.extend(["mega"])
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| __pycache__ | Folder | 0755 |
|
|
| pyrax_identity | Folder | 0755 |
|
|
| __init__.py | File | 1.09 KB | 0644 |
|
| _cf_cloudfiles.py | File | 3.83 KB | 0644 |
|
| _cf_pyrax.py | File | 5.02 KB | 0644 |
|
| _testbackend.py | File | 10.95 KB | 0644 |
|
| adbackend.py | File | 16.17 KB | 0644 |
|
| azurebackend.py | File | 5.41 KB | 0644 |
|
| b2backend.py | File | 9.31 KB | 0644 |
|
| boxbackend.py | File | 6.63 KB | 0644 |
|
| cfbackend.py | File | 1.12 KB | 0644 |
|
| dpbxbackend.py | File | 19.09 KB | 0644 |
|
| gdocsbackend.py | File | 8.9 KB | 0644 |
|
| gdrivebackend.py | File | 16.28 KB | 0644 |
|
| giobackend.py | File | 7.74 KB | 0644 |
|
| hsibackend.py | File | 2.54 KB | 0644 |
|
| hubicbackend.py | File | 2.37 KB | 0644 |
|
| idrivedbackend.py | File | 18.86 KB | 0644 |
|
| imapbackend.py | File | 9.53 KB | 0644 |
|
| jottacloudbackend.py | File | 5.62 KB | 0644 |
|
| lftpbackend.py | File | 8.97 KB | 0644 |
|
| localbackend.py | File | 2.97 KB | 0644 |
|
| mediafirebackend.py | File | 4.53 KB | 0644 |
|
| megabackend.py | File | 6.93 KB | 0644 |
|
| megav2backend.py | File | 8.42 KB | 0644 |
|
| megav3backend.py | File | 9.63 KB | 0644 |
|
| multibackend.py | File | 15.39 KB | 0644 |
|
| ncftpbackend.py | File | 5.32 KB | 0644 |
|
| onedrivebackend.py | File | 15.94 KB | 0644 |
|
| par2backend.py | File | 8.78 KB | 0644 |
|
| pcabackend.py | File | 12.18 KB | 0644 |
|
| pydrivebackend.py | File | 12.72 KB | 0644 |
|
| rclonebackend.py | File | 4.64 KB | 0644 |
|
| rsyncbackend.py | File | 6.3 KB | 0644 |
|
| s3_boto3_backend.py | File | 10.25 KB | 0644 |
|
| slatebackend.py | File | 6.37 KB | 0644 |
|
| ssh_paramiko_backend.py | File | 19.21 KB | 0644 |
|
| ssh_pexpect_backend.py | File | 12.63 KB | 0644 |
|
| swiftbackend.py | File | 9.91 KB | 0644 |
|
| sxbackend.py | File | 2.26 KB | 0644 |
|
| tahoebackend.py | File | 2.5 KB | 0644 |
|
| webdavbackend.py | File | 18.2 KB | 0644 |
|
| xorrisobackend.py | File | 11.96 KB | 0644 |
|