Welcome to mirror list, hosted at ThFree Co, Russian Federation.

RestoreDirectController.js « controllers « scripts « ngax « webroot « Server « Duplicati - github.com/duplicati/duplicati.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3381921f7ac64f00249f70f197ba9dc2fc926bf3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
backupApp.controller('RestoreDirectController', function ($rootScope, $scope, $location, AppService, AppUtils, SystemInfo, ServerStatus, DialogService, gettextCatalog) {

    $scope.SystemInfo = SystemInfo.watch($scope);
    $scope.AppUtils = AppUtils;
    $scope.ServerStatus = ServerStatus;
    $scope.serverstate = ServerStatus.watch($scope);

    $scope.CurrentStep = 0;
    $scope.connecting = false;

    $scope.nextPage = function() {
        $scope.CurrentStep = Math.min(1, $scope.CurrentStep + 1);
    };

    $scope.prevPage = function() {
        $scope.CurrentStep = Math.max(0, $scope.CurrentStep - 1);
    };

    $scope.setBuilduriFn = function(builduriFn) {
        $scope.builduri = builduriFn;
    };

    $scope.importUrl = function () {
        DialogService.textareaDialog('Import URL', 'Enter a Backup destination URL:', null, gettextCatalog.getString('Enter URL'), [gettextCatalog.getString('Cancel'), gettextCatalog.getString('OK')], null, function(btn, input) {
            if (btn == 1) {
                $scope.TargetURL = input;
            }
        });
    };

    $scope.copyUrlToClipboard = function () {
        $scope.builduri(function(res) {
            DialogService.textareaDialog('Copy URL', null, null, res, [gettextCatalog.getString('OK')], 'templates/copy_clipboard_buttons.html');
        });
    };

    $scope.doConnect = function() {
        function connect() {
            $scope.connecting = true;
            $scope.ConnectionProgress = gettextCatalog.getString('Registering temporary backup ...');

            var opts = {};
            var obj = {'Backup': {'TargetURL':  $scope.TargetURL } };

            if (($scope.EncryptionPassphrase || '') == '')
                opts['--no-encryption'] = 'true';
            else
                opts['passphrase'] = $scope.EncryptionPassphrase;

            if (!AppUtils.parse_extra_options($scope.ExtendedOptions, opts))
                return false;

            obj.Backup.Settings = [];
            for(var k in opts) {
                obj.Backup.Settings.push({
                    Name: k,
                    Value: opts[k]
                });
            }

            AppService.post('/backups?temporary=true', obj, {'headers': {'Content-Type': 'application/json'}}).then(
                function(resp) {

                    $scope.ConnectionProgress = gettextCatalog.getString('Listing backup dates ...');
                    $scope.BackupID = resp.data.ID;
                    $scope.fetchBackupTimes();
                }, function(resp) {
                    var message = resp.statusText;
                    if (resp.data != null && resp.data.Message != null)
                        message = resp.data.Message;

                    $scope.connecting = false;
                    $scope.ConnectionProgress = '';
                    DialogService.dialog(gettextCatalog.getString('Error'), gettextCatalog.getString('Failed to connect: {{message}}', { message: message }));
                }
            );
        }

        function checkForValidBackupDestination(continuation) {
            $scope.builduri(function(res) {
                $scope.TargetURL = res;
                continuation();
            });
            $scope.CurrentStep = 0;
        }

        checkForValidBackupDestination(connect);
    };

    $scope.fetchBackupTimes = function() {
        AppService.get('/backup/' + $scope.BackupID + '/filesets').then(
            function(resp) {
                // Pass the filesets through a global variable
                if ($rootScope.filesets == null)
                    $rootScope.filesets = {};
                $rootScope.filesets[$scope.BackupID] = resp.data;
                $location.path('/restore/' + $scope.BackupID);
            },

            function(resp) {
                var message = resp.statusText;
                if (resp.data != null && resp.data.Message != null)
                    message = resp.data.Message;

                if (message == 'encrypted-storage')
                    message = gettextCatalog.getString('The target folder contains encrypted files, please supply the passphrase');

                $scope.connecting = false;
                $scope.ConnectionProgress = '';
                DialogService.dialog(gettextCatalog.getString('Error'), gettextCatalog.getString('Failed to connect: {{message}}', { message: message }));
            }
        );
    };

    if ($location.$$path.indexOf('/restoredirect-import') == 0 && $rootScope.importConfig != null)
    {
        $scope.TargetURL = $rootScope.importConfig.Backup.TargetURL;

        var tmpsettings = angular.copy($rootScope.importConfig.Backup.Settings);
        var res = {};
        for (var i = tmpsettings.length - 1; i >= 0; i--) {
            if (tmpsettings[i].Name == 'passphrase') {
                $scope.EncryptionPassphrase = tmpsettings[i].Value;
                tmpsettings.splice(i, 1);
            } else {
                res['--' + tmpsettings[i].Name] = tmpsettings[i].Value;
            }
        }

        $scope.showAdvanced = true;
        $scope.ExtendedOptions = AppUtils.serializeAdvancedOptions(res);
    }

});