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

github.com/nextcloud/passman.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolFi <wolfi@wolfi.es>2017-06-04 20:07:10 +0300
committerWolFi <wolfi@wolfi.es>2017-06-04 20:08:32 +0300
commit92ac904f26e1f98064c273179040b3272f5dc8c9 (patch)
tree6a9d76ec3878d25183af015f75c7b1d07ab72f52
parent3259c9dc3227503c818ea1246ed837f26dc187e8 (diff)
Add custom_fields and files into the export FIX #305
-rw-r--r--js/app/controllers/export.js5
-rw-r--r--js/exporters/exporter-csv.js73
-rw-r--r--js/exporters/exporter-main.js81
3 files changed, 124 insertions, 35 deletions
diff --git a/js/app/controllers/export.js b/js/app/controllers/export.js
index b53b19b1..b284048c 100644
--- a/js/app/controllers/export.js
+++ b/js/app/controllers/export.js
@@ -31,7 +31,7 @@
* Controller of the passmanApp
*/
angular.module('passmanApp')
- .controller('ExportCtrl', ['$scope', '$window', 'CredentialService', 'VaultService', '$translate', function ($scope, $window, CredentialService, VaultService, $translate) {
+ .controller('ExportCtrl', ['$scope', '$window', 'CredentialService', 'VaultService', 'FileService', 'EncryptService', '$translate', function ($scope, $window, CredentialService, VaultService, FileService, EncryptService, $translate) {
$scope.available_exporters = [];
$scope.active_vault = VaultService.getActiveVault();
$scope.confirm_key = '';
@@ -76,10 +76,11 @@
if (_credential.hidden === 0) {
var key = CredentialService.getSharedKeyFromCredential(_credential);
_credential = CredentialService.decryptCredential(_credential, key);
+ _credential.vault_key = key;
_credentials.push(_credential);
}
}
- $window.PassmanExporter[$scope.selectedExporter.id].export(_credentials).then(function () {
+ $window.PassmanExporter[$scope.selectedExporter.id].export(_credentials, FileService, EncryptService).then(function () {
_log($translate.instant('done'));
});
}
diff --git a/js/exporters/exporter-csv.js b/js/exporters/exporter-csv.js
index 99494943..f3a25345 100644
--- a/js/exporters/exporter-csv.js
+++ b/js/exporters/exporter-csv.js
@@ -26,41 +26,52 @@ PassmanExporter.csv = {
info: {
name: 'CSV',
id: 'csv',
- description: 'Export credentials as csv.'
+ description: 'Export credentials as a csv file.'
}
};
-PassmanExporter.csv.export = function (credentials) {
+PassmanExporter.csv.export = function (credentials, FileService, EncryptService) {
/** global: C_Promise */
return new C_Promise(function () {
- var _this = this;
- var headers = ['label', 'username', 'password', 'email', 'description', 'tags', 'url'];
- 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');
+ PassmanExporter.getCredentialsWithFiles(credentials, FileService, EncryptService).then((function(data){
+ var headers = ['label', 'username', 'password', 'email', 'description', 'tags', 'url', 'custom_fields', 'files'];
+ 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 if (field == 'custom_fields' || field == 'files') {
+ var _fields = JSON.stringify(_credential[field]);
+ _fields = _fields.replaceAll('"', '""');
+ row_data.push('"' + _fields + '"');
+ }
+ 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');
+ }).bind(this)).progress(function(progress) {
+ console.log(progress);
+ });
+
+
});
};
diff --git a/js/exporters/exporter-main.js b/js/exporters/exporter-main.js
index 57cad60a..a4cf2034 100644
--- a/js/exporters/exporter-main.js
+++ b/js/exporters/exporter-main.js
@@ -22,6 +22,83 @@
// Importers should always start with this
if (!window['PassmanExporter']) {
- var PassmanExporter = {}
-}
+ var PassmanExporter = {
+ getCredentialsWithFiles: function(credentials, FileService, EncryptService) {
+ var t = {
+ cred: credentials,
+ FS: FileService,
+ ES: EncryptService
+ }
+
+ return new C_Promise(function() {
+ _this = this.parent;
+ var credentials = _this.cred;
+ this.parent.total = 0;
+ this.parent.finished = 0;
+ this.parent.fileGUID_cred = [];
+ this.parent.files = [];
+ this.parent.step = (function(file) {
+ this.parent.finished ++;
+ this.call_progress({
+ total: this.parent.total,
+ finished: this.parent.finished
+ });
+
+ var dta = this.parent.fileGUID_cred[file.guid];
+
+ file.filename = this.parent.ES.decryptString(file.filename, this.parent.cred[dta.cred_pos].vault_key);
+ file.file_data = this.parent.ES.decryptString(file.file_data, this.parent.cred[dta.cred_pos].vault_key);
+
+ // Files and custom_fields have different field structure
+ if (dta.on === 'files') {
+ this.parent.cred[dta.cred_pos][dta.on][dta.at] = file;
+ }
+ else {
+ this.parent.cred[dta.cred_pos][dta.on][dta.at].value = file;
+ }
+
+ // We have finished downloading everything, so let's hand over job to somewhere else!
+ if (this.parent.total === this.parent.finished) {
+ this.call_then(this.parent.cred);
+ }
+ }).bind(this);
+
+ for (var i = 0; i < credentials.length; i++) {
+
+ var item = credentials[i];
+
+ // Custom fields
+ for (var c = 0; c < item.custom_fields.length; c++) {
+ var cf = item.custom_fields[c];
+ if (cf.field_type === 'file') {
+ this.parent.total ++;
+ this.parent.fileGUID_cred[cf.value.guid] = {
+ cred_pos: i,
+ on: 'custom_fields',
+ at: c
+ };
+ this.parent.FS.getFile(cf.value).then((function(data){
+ this.parent.step(data);
+ }).bind(this));
+ }
+ }
+
+ // Also get all files
+ for (var c = 0; c < item.files.length; c++) {
+ this.parent.total ++;
+ this.parent.fileGUID_cred[item.files[c].guid] = {
+ cred_pos: i,
+ on: 'files',
+ at: c
+ };
+
+ this.parent.FS.getFile(item.files[c]).then((function(data){
+ this.parent.step(data);
+ }).bind(this));
+ }
+ }
+ }, t);
+ }
+ }
+}