Пример #1
0
def generate_keys(path):
    # generate private/public key pair
    key = rsa.generate_private_key(backend=default_backend(),
                                   public_exponent=65537,
                                   key_size=2048)

    # get public key in OpenSSH format
    public_key = key.public_key().public_bytes(
        serialization.Encoding.OpenSSH, serialization.PublicFormat.OpenSSH)

    # get private key in PEM container format
    pem = key.private_bytes(
        encoding=serialization.Encoding.PEM,
        format=serialization.PrivateFormat.TraditionalOpenSSL,
        encryption_algorithm=serialization.NoEncryption())

    # decode to printable strings
    private_key_str = pem.decode('utf-8')
    public_key_str = public_key.decode('utf-8')

    ensure_dir(path)

    with open(os.path.join(path, "id_rsa"), "w") as w:
        w.write(private_key_str)
    with open(os.path.join(path, "id_rsa.pub"), "w") as w:
        w.write(public_key_str)

    return private_key_str, public_key_str
Пример #2
0
def get_config():
    if not os.path.isfile(CONFIG_PATH):
        ensure_dir(os.path.dirname(CONFIG_PATH))
        shutil.copy(CONFIG_PATH_DEFAULT, CONFIG_PATH)
    with open(CONFIG_PATH) as f:
        return yaml.load(f, Loader=yaml.FullLoader)
    return
Пример #3
0
    def get_id(self):
        run_folder = self.get_run_folder()
        if not ensure_dir(run_folder):
            return 0

        log_files = self.get_log_files()
        for i, folder in enumerate(log_files):
            # print(i, folder)
            if str(i) != str(folder):
                return str(i)

        return len(log_files)
Пример #4
0
    def run_backup(self):
        pub.sendMessage(START_JOB_MSG, name=self.name)
        self.prepare_job()
        if debug:
            print("hello!!!!!!!!!!!!!!")
        config = get_config()

        self.process_object = SyncProcess(self.window)
        self.process_object.Redirect()

        bin_path, ssh_path = self.get_bin_ssh_path()

        if get_os() == "windows":
            cmd = [
                bin_path, "-v6", "--remote-schema", '"' + ssh_path + " -p " +
                str(self.port) + " -o StrictHostKeyChecking=no -i '" +
                self.key + "' %s rdiff-backup --server" + '"', "--",
                '"' + self.source + '"', self.dest
            ]
            command = " ".join(cmd)

            known_hosts_location = os.path.realpath(
                os.path.join(os.path.dirname(ssh_path), "..", "home",
                             os.getlogin()))
            ensure_dir(known_hosts_location)

        else:
            cmd = [
                bin_path, "-v6", " --remote-schema 'ssh -p " + str(self.port) +
                " -o StrictHostKeyChecking=no -i \"" + self.key +
                "\" %s rdiff-backup --server'", "--",
                quote(self.source),
                quote(self.dest)
            ]
            command = " ".join(cmd)

        if debug:
            print("running: " + command)
        print("running: " + str(command))

        self.pid = wx.Execute(command,
                              wx.EXEC_ASYNC,
                              callback=self.process_object)

        if debug:
            print("pid: " + str(self.pid))
        time.sleep(1)
        stream = self.process_object.GetInputStream()

        while stream is not None and stream.CanRead():
            text = stream.read()
            self.update_log(text)
            wx.LogMessage(text)

        stream_err = self.process_object.GetErrorStream()

        while stream_err is not None and stream_err.CanRead():
            text = stream_err.read()
            self.update_log(text)
            wx.LogMessage(text)

        print("Finish reading")
        return
Пример #5
0
    def run_backup(self):
        self.prepare_job()
        if debug:
            print("hello!!!!!!!!!!!!!!")
        config = get_config()

        self.process_object = SyncProcess(self.window)
        self.process_object.Redirect()
        bin_path = config["main"]["bin"]
        ssh_path = config["main"]["ssh"]

        if "win" in sys.platform:
            if debug:
                print("windows detected, adjusting binary path in package")

            # rdiff_path = r'"C:\Users\user\Desktop\backupfriend-client\src\rdiff-backup.exe"'
            # ssh_path = r'C:\Users\user\Desktop\backupfriend-client\ssh.exe'
            ssh_path = ssh_path.replace("__package_path__", resource_path())
            bin_path = bin_path.replace("__package_path__", resource_path())

            cmd = [
                bin_path, "-v6", "--remote-schema", '"' + ssh_path + " -p " +
                str(self.port) + " -o StrictHostKeyChecking=no -i '" +
                self.key + "' %s rdiff-backup --server" + '"', "--",
                self.source, self.dest
            ]
            command = " ".join(cmd)
            known_hosts_location = os.path.realpath(
                os.path.join(os.path.dirname(ssh_path), "..", "home",
                             os.getlogin()))
            ensure_dir(known_hosts_location)

        else:
            cmd = [
                bin_path, "-v6", " --remote-schema 'ssh -p " + str(self.port) +
                " -o StrictHostKeyChecking=no -i " + self.key +
                " %s rdiff-backup --server'", "--", self.source, self.dest
            ]
            command = " ".join(cmd)

        if debug:
            print("running: " + command)
        print("running: " + str(command))

        self.pid = wx.Execute(command,
                              wx.EXEC_ASYNC,
                              callback=self.process_object)

        if debug:
            print("pid: " + str(self.pid))
        time.sleep(1)
        stream = self.process_object.GetInputStream()

        while stream is not None and stream.CanRead():
            text = stream.read()
            self.update_log(text)
            wx.LogMessage(text)

        stream_err = self.process_object.GetErrorStream()

        while stream_err is not None and stream_err.CanRead():
            text = stream_err.read()
            self.update_log(text)
            wx.LogMessage(text)

        print("Finish reading")

        return