2016-10-19 23:44:19 +08:00
|
|
|
/**
|
|
|
|
* Nextcloud - passman
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2016, Sander Brand (brantje@gmail.com)
|
|
|
|
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel (wolfi@wolfi.es)
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-10-08 01:56:29 +08:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
2016-09-25 02:24:41 +08:00
|
|
|
|
2016-10-08 01:56:29 +08:00
|
|
|
/**
|
|
|
|
* @ngdoc function
|
|
|
|
* @name passmanApp.controller:ImportCtrl
|
|
|
|
* @description
|
|
|
|
* # ImportCtrl
|
|
|
|
* Controller of the passmanApp
|
|
|
|
*/
|
|
|
|
angular.module('passmanApp')
|
2016-12-21 21:06:29 +08:00
|
|
|
.controller('ExportCtrl', ['$scope', '$window', 'CredentialService', 'VaultService', '$translate', function ($scope, $window, CredentialService, VaultService, $translate) {
|
2016-10-08 19:26:48 +08:00
|
|
|
$scope.available_exporters = [];
|
|
|
|
$scope.active_vault = VaultService.getActiveVault();
|
|
|
|
|
|
|
|
|
|
|
|
$scope.$watch(function () {
|
|
|
|
return $window.PassmanExporter;
|
|
|
|
}, function (exporters) {
|
2016-10-08 20:00:07 +08:00
|
|
|
exporters = Object.keys(angular.copy(exporters));
|
2016-10-08 19:56:17 +08:00
|
|
|
for (var i = 0; i < exporters.length; i++) {
|
|
|
|
var exporter = exporters[i];
|
|
|
|
if ($window.PassmanExporter[exporter].hasOwnProperty('info')) {
|
|
|
|
$scope.available_exporters.push($window.PassmanExporter[exporter].info);
|
2016-10-08 19:26:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
$scope.log = [];
|
|
|
|
$scope.setExporter = function (exporter) {
|
|
|
|
exporter = JSON.parse(exporter);
|
|
|
|
$scope.selectedExporter = exporter;
|
|
|
|
};
|
|
|
|
var _log = function (str) {
|
|
|
|
$scope.log.push(str);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
$scope.startExport = function () {
|
2016-12-21 21:06:29 +08:00
|
|
|
_log($translate.instant('export.starting'));
|
2016-10-08 19:26:48 +08:00
|
|
|
var _credentials = [];
|
|
|
|
VaultService.getVault(VaultService.getActiveVault()).then(function (vault) {
|
2016-12-21 21:06:29 +08:00
|
|
|
_log($translate.instant('export.decrypt'));
|
2016-10-08 20:00:07 +08:00
|
|
|
if (vault.hasOwnProperty('credentials')) {
|
|
|
|
if (vault.credentials.length > 0) {
|
|
|
|
for (var i = 0; i < vault.credentials.length; i++) {
|
2016-10-08 19:26:48 +08:00
|
|
|
var _credential = angular.copy(vault.credentials[i]);
|
2016-10-08 20:00:07 +08:00
|
|
|
if (_credential.hidden === 0) {
|
2016-10-08 19:26:48 +08:00
|
|
|
_credential = CredentialService.decryptCredential(_credential);
|
|
|
|
_credentials.push(_credential);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$window.PassmanExporter[$scope.selectedExporter.id].export(_credentials).then(function () {
|
2016-12-21 21:06:29 +08:00
|
|
|
_log($translate.instant('done'));
|
2016-10-08 19:26:48 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
2016-10-08 19:34:48 +08:00
|
|
|
};
|
2016-10-08 19:26:48 +08:00
|
|
|
|
|
|
|
|
2016-10-08 01:56:29 +08:00
|
|
|
}]);
|
|
|
|
|
|
|
|
}());
|