mirror of
https://github.com/nextcloud/passman.git
synced 2025-10-11 14:06:07 +08:00
Merge branch 'exporter'
This commit is contained in:
commit
e17f52bdd0
7 changed files with 122 additions and 4 deletions
|
@ -34,6 +34,7 @@ module.exports = function (grunt) {
|
||||||
globals: {
|
globals: {
|
||||||
"angular": true,
|
"angular": true,
|
||||||
"PassmanImporter": true,
|
"PassmanImporter": true,
|
||||||
|
"PassmanExporter": true,
|
||||||
"OC": true,
|
"OC": true,
|
||||||
"window": true,
|
"window": true,
|
||||||
"console": true,
|
"console": true,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
(function () {
|
(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ngdoc function
|
* @ngdoc function
|
||||||
* @name passmanApp.controller:ImportCtrl
|
* @name passmanApp.controller:ImportCtrl
|
||||||
|
@ -10,7 +9,55 @@
|
||||||
* Controller of the passmanApp
|
* Controller of the passmanApp
|
||||||
*/
|
*/
|
||||||
angular.module('passmanApp')
|
angular.module('passmanApp')
|
||||||
.controller('ExportCtrl', ['$scope', function ($scope) {
|
.controller('ExportCtrl', ['$scope', '$window', 'CredentialService', 'VaultService', function ($scope, $window, CredentialService, VaultService) {
|
||||||
|
$scope.available_exporters = [];
|
||||||
|
$scope.active_vault = VaultService.getActiveVault();
|
||||||
|
|
||||||
|
|
||||||
|
$scope.$watch(function () {
|
||||||
|
return $window.PassmanExporter;
|
||||||
|
}, function (exporters) {
|
||||||
|
exporters = Object.keys(angular.copy(exporters));
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 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 () {
|
||||||
|
_log('Starting export');
|
||||||
|
var _credentials = [];
|
||||||
|
VaultService.getVault(VaultService.getActiveVault()).then(function (vault) {
|
||||||
|
_log('Decrypting credentials');
|
||||||
|
if (vault.hasOwnProperty('credentials')) {
|
||||||
|
if (vault.credentials.length > 0) {
|
||||||
|
for (var i = 0; i < vault.credentials.length; i++) {
|
||||||
|
var _credential = angular.copy(vault.credentials[i]);
|
||||||
|
if (_credential.hidden === 0) {
|
||||||
|
_credential = CredentialService.decryptCredential(_credential);
|
||||||
|
_credentials.push(_credential);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$window.PassmanExporter[$scope.selectedExporter.id].export(_credentials).then(function () {
|
||||||
|
_log('Done');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
|
|
43
js/exporters/exporter-csv.js
Normal file
43
js/exporters/exporter-csv.js
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/** global: PassmanExporter */
|
||||||
|
PassmanExporter.csv = {
|
||||||
|
info: {
|
||||||
|
name: 'CSV',
|
||||||
|
id: 'csv',
|
||||||
|
description: 'Export credentials as csv.'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
PassmanExporter.csv.export = function (credentials) {
|
||||||
|
/** global: C_Promise */
|
||||||
|
return new C_Promise(function () {
|
||||||
|
var _this = this;
|
||||||
|
var headers = ['label', 'username', 'password', 'email', 'description', 'tags'];
|
||||||
|
var file_data = '"' + headers.join('","') + '"\n';
|
||||||
|
for (var i = 0; i < credentials.length; i++) {
|
||||||
|
var _credential = credentials[i];
|
||||||
|
var row_data = [];
|
||||||
|
for (var h = 0; h < headers.length; h++) {
|
||||||
|
var field = headers[h];
|
||||||
|
if (field === 'tags') {
|
||||||
|
var _tags = [];
|
||||||
|
for (var t = 0; t < _credential[field].length; t++) {
|
||||||
|
_tags.push(_credential[field][t].text);
|
||||||
|
}
|
||||||
|
var data = '[' + _tags.join(",") + ']';
|
||||||
|
row_data.push('"' + data + '"');
|
||||||
|
} else {
|
||||||
|
row_data.push('"' + _credential[field] + '"');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var progress = {
|
||||||
|
percent: i / credentials.length * 100,
|
||||||
|
loaded: i,
|
||||||
|
total: credentials.length
|
||||||
|
};
|
||||||
|
_this.call_progress(progress);
|
||||||
|
file_data += row_data.join(',') + "\n";
|
||||||
|
}
|
||||||
|
_this.call_then();
|
||||||
|
download(file_data, 'passman-export.csv');
|
||||||
|
});
|
||||||
|
};
|
5
js/exporters/exporter-main.js
Normal file
5
js/exporters/exporter-main.js
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
// Importers should always start with this
|
||||||
|
if (!window['PassmanExporter']) {
|
||||||
|
var PassmanExporter = {}
|
||||||
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ angular.module('views/partials/forms/edit_credential/password.html', []).run(['$
|
||||||
angular.module('views/partials/forms/settings/export.html', []).run(['$templateCache', function($templateCache) {
|
angular.module('views/partials/forms/settings/export.html', []).run(['$templateCache', function($templateCache) {
|
||||||
'use strict';
|
'use strict';
|
||||||
$templateCache.put('views/partials/forms/settings/export.html',
|
$templateCache.put('views/partials/forms/settings/export.html',
|
||||||
'<div ng-controller="ExportCtrl">Export credentials</div>');
|
'<div ng-controller="ExportCtrl"><div class="row"><div class="col-xs-6"><label>Export type<select ng-init="raw" ng-model="raw" ng-change="setExporter(raw)"><option ng-repeat="exporter in available_exporters" value="{{exporter}}">{{exporter.name}}</option></select></label><div><b>{{selectedExporter.description}}</b></div><button class="button" ng-click="startExport()" ng-if="selectedExporter">Export</button></div><div class="col-xs-6"><div ng-if="log" class="import_log"><textarea id="import_log" auto-scroll="log">{{log.join(\'\\n\')}}</textarea></div></div></div></div>');
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
angular.module('views/partials/forms/settings/general_settings.html', []).run(['$templateCache', function($templateCache) {
|
angular.module('views/partials/forms/settings/general_settings.html', []).run(['$templateCache', function($templateCache) {
|
||||||
|
|
|
@ -77,6 +77,8 @@ script('passman', 'importers/importer-passmanjson');
|
||||||
script('passman', 'importers/importer-clipperz');
|
script('passman', 'importers/importer-clipperz');
|
||||||
script('passman', 'importers/importer-passpackcsv');
|
script('passman', 'importers/importer-passpackcsv');
|
||||||
script('passman', 'importers/importer-randomdata');
|
script('passman', 'importers/importer-randomdata');
|
||||||
|
script('passman', 'exporters/exporter-main');
|
||||||
|
script('passman', 'exporters/exporter-csv');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Styles
|
* Styles
|
||||||
|
|
|
@ -1,3 +1,23 @@
|
||||||
<div ng-controller="ExportCtrl">
|
<div ng-controller="ExportCtrl">
|
||||||
Export credentials
|
<div class="row">
|
||||||
|
<div class="col-xs-6">
|
||||||
|
<label>Export type
|
||||||
|
<select ng-init="raw" ng-model="raw"
|
||||||
|
ng-change="setExporter(raw)">
|
||||||
|
<option ng-repeat="exporter in available_exporters"
|
||||||
|
value="{{exporter}}">
|
||||||
|
{{exporter.name}}
|
||||||
|
</option>
|
||||||
|
</select></label>
|
||||||
|
<div><b>{{selectedExporter.description}}</b></div>
|
||||||
|
<button class="button" ng-click="startExport()"
|
||||||
|
ng-if="selectedExporter">Export
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-6">
|
||||||
|
<div ng-if="log" class="import_log">
|
||||||
|
<textarea id="import_log" auto-scroll="log">{{log.join('\n')}}</textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
Loading…
Add table
Reference in a new issue