|
1
|
|
|
(function () { |
|
2
|
|
|
'use strict'; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* @ngdoc function |
|
6
|
|
|
* @name passmanApp.controller:ImportCtrl |
|
7
|
|
|
* @description |
|
8
|
|
|
* # ImportCtrl |
|
9
|
|
|
* Controller of the passmanApp |
|
10
|
|
|
*/ |
|
11
|
|
|
angular.module('passmanApp') |
|
12
|
|
|
.controller('ExportCtrl', ['$scope', '$window', 'CredentialService', 'VaultService', function ($scope, $window, CredentialService, VaultService) { |
|
13
|
|
|
$scope.available_exporters = []; |
|
14
|
|
|
$scope.active_vault = VaultService.getActiveVault(); |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
$scope.$watch(function () { |
|
18
|
|
|
return $window.PassmanExporter; |
|
19
|
|
|
}, function (exporters) { |
|
20
|
|
|
exporters = Object.keys(angular.copy(exporters)); |
|
21
|
|
|
for (var i = 0; i < exporters.length; i++) { |
|
22
|
|
|
var exporter = exporters[i]; |
|
23
|
|
|
if ($window.PassmanExporter[exporter].hasOwnProperty('info')) { |
|
24
|
|
|
$scope.available_exporters.push($window.PassmanExporter[exporter].info); |
|
25
|
|
|
} |
|
26
|
|
|
} |
|
27
|
|
|
}, true); |
|
28
|
|
|
$scope.log = []; |
|
29
|
|
|
$scope.setExporter = function (exporter) { |
|
30
|
|
|
exporter = JSON.parse(exporter); |
|
31
|
|
|
$scope.selectedExporter = exporter; |
|
32
|
|
|
}; |
|
33
|
|
|
var _log = function (str) { |
|
34
|
|
|
$scope.log.push(str); |
|
35
|
|
|
}; |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
$scope.startExport = function () { |
|
39
|
|
|
_log('Starting export'); |
|
40
|
|
|
var _credentials = []; |
|
41
|
|
|
VaultService.getVault(VaultService.getActiveVault()).then(function (vault) { |
|
42
|
|
|
_log('Decrypting credentials'); |
|
43
|
|
|
if (vault.hasOwnProperty('credentials')) { |
|
44
|
|
|
if (vault.credentials.length > 0) { |
|
45
|
|
|
for (var i = 0; i < vault.credentials.length; i++) { |
|
46
|
|
|
var _credential = angular.copy(vault.credentials[i]); |
|
47
|
|
|
if (_credential.hidden === 0) { |
|
48
|
|
|
_credential = CredentialService.decryptCredential(_credential); |
|
49
|
|
|
_credentials.push(_credential); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
$window.PassmanExporter[$scope.selectedExporter.id].export(_credentials).then(function () { |
|
53
|
|
|
_log('Done'); |
|
54
|
|
|
}); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
}); |
|
59
|
|
|
}; |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
}]); |
|
63
|
|
|
|
|
64
|
|
|
}()); |