mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 10:13:31 +00:00
import/export/updatekey fixes for ciphers
This commit is contained in:
@@ -2,23 +2,23 @@
|
||||
.module('bit.tools')
|
||||
|
||||
.controller('toolsExportController', function ($scope, apiService, $uibModalInstance, cipherService, $q,
|
||||
toastr, $analytics) {
|
||||
toastr, $analytics, constants) {
|
||||
$analytics.eventTrack('toolsExportController', { category: 'Modal' });
|
||||
$scope.export = function (model) {
|
||||
$scope.startedExport = true;
|
||||
var decLogins = [],
|
||||
var decCiphers = [],
|
||||
decFolders = [];
|
||||
|
||||
var folderPromise = apiService.folders.list({}, function (folders) {
|
||||
decFolders = cipherService.decryptFolders(folders.Data);
|
||||
}).$promise;
|
||||
|
||||
var loginsPromise = apiService.ciphers.list({}, function (logins) {
|
||||
decLogins = cipherService.decryptLogins(logins.Data);
|
||||
var ciphersPromise = apiService.ciphers.list({}, function (ciphers) {
|
||||
decCiphers = cipherService.decryptCiphers(ciphers.Data);
|
||||
}).$promise;
|
||||
|
||||
$q.all([folderPromise, loginsPromise]).then(function () {
|
||||
if (!decLogins.length) {
|
||||
$q.all([folderPromise, ciphersPromise]).then(function () {
|
||||
if (!decCiphers.length) {
|
||||
toastr.error('Nothing to export.', 'Error!');
|
||||
$scope.close();
|
||||
return;
|
||||
@@ -30,23 +30,28 @@
|
||||
}
|
||||
|
||||
try {
|
||||
var exportLogins = [];
|
||||
for (i = 0; i < decLogins.length; i++) {
|
||||
var exportCiphers = [];
|
||||
for (i = 0; i < decCiphers.length; i++) {
|
||||
// only export logins for now
|
||||
if (decCiphers[i].type !== constants.cipherType.login) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var login = {
|
||||
name: decLogins[i].name,
|
||||
uri: decLogins[i].uri,
|
||||
username: decLogins[i].username,
|
||||
password: decLogins[i].password,
|
||||
notes: decLogins[i].notes,
|
||||
folder: decLogins[i].folderId && (decLogins[i].folderId in foldersDict) ?
|
||||
foldersDict[decLogins[i].folderId].name : null,
|
||||
favorite: decLogins[i].favorite ? 1 : null,
|
||||
totp: decLogins[i].totp,
|
||||
name: decCiphers[i].name,
|
||||
uri: decCiphers[i].login.uri,
|
||||
username: decCiphers[i].login.username,
|
||||
password: decCiphers[i].login.password,
|
||||
notes: decCiphers[i].notes,
|
||||
folder: decCiphers[i].folderId && (decCiphers[i].folderId in foldersDict) ?
|
||||
foldersDict[decCiphers[i].folderId].name : null,
|
||||
favorite: decCiphers[i].favorite ? 1 : null,
|
||||
totp: decCiphers[i].login.totp,
|
||||
fields: null
|
||||
};
|
||||
|
||||
if (decLogins[i].fields) {
|
||||
for (var j = 0; j < decLogins[i].fields.length; j++) {
|
||||
if (decCiphers[i].fields) {
|
||||
for (var j = 0; j < decCiphers[i].fields.length; j++) {
|
||||
if (!login.fields) {
|
||||
login.fields = '';
|
||||
}
|
||||
@@ -54,14 +59,14 @@
|
||||
login.fields += '\n';
|
||||
}
|
||||
|
||||
login.fields += ((decLogins[i].fields[j].name || '') + ': ' + decLogins[i].fields[j].value);
|
||||
login.fields += ((decCiphers[i].fields[j].name || '') + ': ' + decCiphers[i].fields[j].value);
|
||||
}
|
||||
}
|
||||
|
||||
exportLogins.push(login);
|
||||
exportCiphers.push(login);
|
||||
}
|
||||
|
||||
var csvString = Papa.unparse(exportLogins);
|
||||
var csvString = Papa.unparse(exportCiphers);
|
||||
var csvBlob = new Blob([csvString]);
|
||||
|
||||
// IE hack. ref http://msdn.microsoft.com/en-us/library/ie/hh779016.aspx
|
||||
|
||||
@@ -237,7 +237,7 @@
|
||||
{
|
||||
id: 'gnomejson',
|
||||
name: 'GNOME Passwords and Keys/Seahorse (json)',
|
||||
instructions: $sce.trustAsHtml('Make sure you have python-keyring and python-gnomekeyring installed. ' +
|
||||
instructions: $sce.trustAsHtml('Make sure you have python-keyring and python-gnomekeyring installed. ' +
|
||||
'Save the <a target="_blank" href="http://bit.ly/2sMldAI">GNOME Keyring Import/Export</a> ' +
|
||||
'python script by Luke Plant to your desktop as <code>pw_helper.py</code>. Open terminal and run ' +
|
||||
'<code>chmod +rx Desktop/pw_helper.py</code> and then ' +
|
||||
@@ -272,15 +272,15 @@
|
||||
importService.import(model.source, file || model.fileContents, importSuccess, importError);
|
||||
};
|
||||
|
||||
function importSuccess(folders, logins, folderRelationships) {
|
||||
if (!folders.length && !logins.length) {
|
||||
function importSuccess(folders, ciphers, folderRelationships) {
|
||||
if (!folders.length && !ciphers.length) {
|
||||
importError('Nothing was imported.');
|
||||
return;
|
||||
}
|
||||
else if (logins.length) {
|
||||
var halfway = Math.floor(logins.length / 2);
|
||||
var last = logins.length - 1;
|
||||
if (loginIsBadData(logins[0]) && loginIsBadData(logins[halfway]) && loginIsBadData(logins[last])) {
|
||||
else if (ciphers.length) {
|
||||
var halfway = Math.floor(ciphers.length / 2);
|
||||
var last = ciphers.length - 1;
|
||||
if (cipherIsBadData(ciphers[0]) && cipherIsBadData(ciphers[halfway]) && cipherIsBadData(ciphers[last])) {
|
||||
importError('CSV data is not formatted correctly. Please check your import file and try again.');
|
||||
return;
|
||||
}
|
||||
@@ -288,7 +288,7 @@
|
||||
|
||||
apiService.ciphers.import({
|
||||
folders: cipherService.encryptFolders(folders),
|
||||
ciphers: cipherService.encryptLogins(logins),
|
||||
ciphers: cipherService.encryptCiphers(ciphers),
|
||||
folderRelationships: folderRelationships
|
||||
}, function () {
|
||||
$uibModalInstance.dismiss('cancel');
|
||||
@@ -299,8 +299,9 @@
|
||||
}, importError);
|
||||
}
|
||||
|
||||
function loginIsBadData(login) {
|
||||
return (login.name === null || login.name === '--') && (login.password === null || login.password === '');
|
||||
function cipherIsBadData(cipher) {
|
||||
return (cipher.name === null || cipher.name === '--') &&
|
||||
(cipher.login && (cipher.login.password === null || cipher.login.password === ''));
|
||||
}
|
||||
|
||||
function importError(error) {
|
||||
|
||||
Reference in New Issue
Block a user