|
1
|
|
|
/** |
|
2
|
|
|
* Nextcloud - passman |
|
3
|
|
|
* |
|
4
|
|
|
* @copyright Copyright (c) 2016, Sander Brand ([email protected]) |
|
5
|
|
|
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected]) |
|
6
|
|
|
* @license GNU AGPL version 3 or any later version |
|
7
|
|
|
* |
|
8
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
10
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
11
|
|
|
* License, or (at your option) any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* This program is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU Affero General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
20
|
|
|
* |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
(function () { |
|
24
|
|
|
'use strict'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @ngdoc function |
|
28
|
|
|
* @name passmanApp.controller:ImportCtrl |
|
29
|
|
|
* @description |
|
30
|
|
|
* # ImportCtrl |
|
31
|
|
|
* Controller of the passmanApp |
|
32
|
|
|
*/ |
|
33
|
|
|
angular.module('passmanApp') |
|
34
|
|
|
.controller('ExportCtrl', ['$scope', '$window', 'CredentialService', 'VaultService', '$translate', function ($scope, $window, CredentialService, VaultService, $translate) { |
|
35
|
|
|
$scope.available_exporters = []; |
|
36
|
|
|
$scope.active_vault = VaultService.getActiveVault(); |
|
37
|
|
|
$scope.confirm_key = ''; |
|
38
|
|
|
|
|
39
|
|
|
$scope.$watch(function () { |
|
40
|
|
|
return $window.PassmanExporter; |
|
41
|
|
|
}, function (exporters) { |
|
42
|
|
|
exporters = Object.keys(angular.copy(exporters)); |
|
43
|
|
|
for (var i = 0; i < exporters.length; i++) { |
|
44
|
|
|
var exporter = exporters[i]; |
|
45
|
|
|
if ($window.PassmanExporter[exporter].hasOwnProperty('info')) { |
|
46
|
|
|
$scope.available_exporters.push($window.PassmanExporter[exporter].info); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
}, true); |
|
50
|
|
|
$scope.log = []; |
|
51
|
|
|
$scope.setExporter = function (exporter) { |
|
52
|
|
|
exporter = JSON.parse(exporter); |
|
53
|
|
|
$scope.selectedExporter = exporter; |
|
54
|
|
|
}; |
|
55
|
|
|
var _log = function (str) { |
|
56
|
|
|
$scope.log.push(str); |
|
57
|
|
|
}; |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
$scope.startExport = function () { |
|
61
|
|
|
$scope.error = false; |
|
62
|
|
|
if(VaultService.getActiveVault().vaultKey !== $scope.confirm_key){ |
|
63
|
|
|
var msg = $translate.instant('invalid.vault.key'); |
|
64
|
|
|
$scope.error = msg; |
|
65
|
|
|
_log(msg); |
|
66
|
|
|
return; |
|
67
|
|
|
} |
|
68
|
|
|
_log($translate.instant('export.starting')); |
|
69
|
|
|
var _credentials = []; |
|
70
|
|
|
VaultService.getVault(VaultService.getActiveVault()).then(function (vault) { |
|
71
|
|
|
_log($translate.instant('export.decrypt')); |
|
72
|
|
|
if (vault.hasOwnProperty('credentials')) { |
|
73
|
|
|
if (vault.credentials.length > 0) { |
|
74
|
|
|
for (var i = 0; i < vault.credentials.length; i++) { |
|
75
|
|
|
var _credential = angular.copy(vault.credentials[i]); |
|
76
|
|
|
if (_credential.hidden === 0) { |
|
77
|
|
|
var key = CredentialService.getSharedKeyFromCredential(_credential); |
|
78
|
|
|
_credential = CredentialService.decryptCredential(_credential, key); |
|
79
|
|
|
_credentials.push(_credential); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
$window.PassmanExporter[$scope.selectedExporter.id].export(_credentials).then(function () { |
|
83
|
|
|
_log($translate.instant('done')); |
|
84
|
|
|
}); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
}); |
|
89
|
|
|
}; |
|
90
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
}]); |
|
93
|
|
|
|
|
94
|
|
|
}()); |