1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 01:03:35 +00:00

org export/import

This commit is contained in:
Kyle Spearrin
2017-09-06 09:05:53 -04:00
parent ff9030e7af
commit aaa91e50b7
10 changed files with 345 additions and 3 deletions

View File

@@ -109,6 +109,22 @@
}
};
_service.importOrg = function (source, file, success, error) {
if (!file) {
error();
return;
}
switch (source) {
case 'bitwardencsv':
importBitwardenOrgCsv(file, success, error);
break;
default:
error();
break;
}
};
var _passwordFieldNames = [
'password', 'pass word', 'passphrase', 'pass phrase',
'pass', 'code', 'code word', 'codeword',
@@ -272,6 +288,64 @@
});
}
function importBitwardenOrgCsv(file, success, error) {
Papa.parse(file, {
header: true,
encoding: 'UTF-8',
complete: function (results) {
parseCsvErrors(results);
var collections = [],
logins = [],
collectionRelationships = [];
angular.forEach(results.data, function (value, key) {
var loginIndex = logins.length;
if (value.collections && value.collections !== '') {
var loginCollections = value.collections.split(',');
for (var i = 0; i < loginCollections.length; i++) {
var addCollection = true;
var collectionIndex = collections.length;
for (var j = 0; j < collections.length; j++) {
if (collections[j].name === loginCollections[i]) {
addCollection = false;
collectionIndex = j;
break;
}
}
if (addCollection) {
collections.push({
name: loginCollections[i]
});
}
collectionRelationships.push({
key: loginIndex,
value: collectionIndex
});
}
}
logins.push({
favorite: false,
uri: value.uri && value.uri !== '' ? trimUri(value.uri) : null,
username: value.username && value.username !== '' ? value.username : null,
password: value.password && value.password !== '' ? value.password : null,
notes: value.notes && value.notes !== '' ? value.notes : null,
name: value.name && value.name !== '' ? value.name : '--',
totp: value.totp && value.totp !== '' ? value.totp : null
});
});
success(collections, logins, collectionRelationships);
}
});
}
function importLastPass(file, success, error) {
if (typeof file !== 'string' && file.type && file.type === 'text/html') {
var reader = new FileReader();