mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-06 09:20:43 +01:00
handle logins & notes for generic export/import
This commit is contained in:
parent
805393b4db
commit
b0832578a4
@ -16,12 +16,7 @@
|
||||
|
||||
var ciphersPromise = apiService.ciphers.listOrganizationDetails({ organizationId: $state.params.orgId },
|
||||
function (ciphers) {
|
||||
for (var i = 0; i < ciphers.Data.length; i++) {
|
||||
if (ciphers.Data[i].Type === 1) {
|
||||
var decCipher = cipherService.decryptCipher(ciphers.Data[i]);
|
||||
decCiphers.push(decCipher);
|
||||
}
|
||||
}
|
||||
decCiphers = cipherService.decryptCiphers(ciphers.Data);
|
||||
}).$promise;
|
||||
|
||||
$q.all([collectionsPromise, ciphersPromise]).then(function () {
|
||||
@ -39,45 +34,64 @@
|
||||
try {
|
||||
var exportCiphers = [];
|
||||
for (i = 0; i < decCiphers.length; i++) {
|
||||
// only export logins for now
|
||||
if (decCiphers[i].type !== constants.cipherType.login) {
|
||||
// only export logins and secure notes
|
||||
if (decCiphers[i].type !== constants.cipherType.login &&
|
||||
decCiphers[i].type !== constants.cipherType.secureNote) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var login = {
|
||||
name: decCiphers[i].name,
|
||||
uri: decCiphers[i].login.uri,
|
||||
username: decCiphers[i].login.username,
|
||||
password: decCiphers[i].login.password,
|
||||
notes: decCiphers[i].notes,
|
||||
totp: decCiphers[i].login.totp,
|
||||
var cipher = {
|
||||
collections: [],
|
||||
fields: null
|
||||
type: null,
|
||||
name: decCiphers[i].name,
|
||||
notes: decCiphers[i].notes,
|
||||
fields: null,
|
||||
// Login props
|
||||
login_uri: null,
|
||||
login_username: null,
|
||||
login_password: null,
|
||||
login_totp: null
|
||||
};
|
||||
|
||||
var j;
|
||||
if (decCiphers[i].fields) {
|
||||
for (j = 0; j < decCiphers[i].fields.length; j++) {
|
||||
if (!login.fields) {
|
||||
login.fields = '';
|
||||
}
|
||||
else {
|
||||
login.fields += '\n';
|
||||
}
|
||||
|
||||
login.fields += ((decCiphers[i].fields[j].name || '') + ': ' + decCiphers[i].fields[j].value);
|
||||
}
|
||||
}
|
||||
|
||||
if (decCiphers[i].collectionIds) {
|
||||
for (j = 0; j < decCiphers[i].collectionIds.length; j++) {
|
||||
if (collectionsDict.hasOwnProperty(decCiphers[i].collectionIds[j])) {
|
||||
login.collections.push(collectionsDict[decCiphers[i].collectionIds[j]].name);
|
||||
cipher.collections.push(collectionsDict[decCiphers[i].collectionIds[j]].name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exportCiphers.push(login);
|
||||
if (decCiphers[i].fields) {
|
||||
for (j = 0; j < decCiphers[i].fields.length; j++) {
|
||||
if (!cipher.fields) {
|
||||
cipher.fields = '';
|
||||
}
|
||||
else {
|
||||
cipher.fields += '\n';
|
||||
}
|
||||
|
||||
cipher.fields += ((decCiphers[i].fields[j].name || '') + ': ' + decCiphers[i].fields[j].value);
|
||||
}
|
||||
}
|
||||
|
||||
switch (decCiphers[i].type) {
|
||||
case constants.cipherType.login:
|
||||
cipher.type = 'login';
|
||||
cipher.login_uri = decCiphers[i].login.uri;
|
||||
cipher.login_username = decCiphers[i].login.username;
|
||||
cipher.login_password = decCiphers[i].login.password;
|
||||
cipher.login_totp = decCiphers[i].login.totp;
|
||||
break;
|
||||
case constants.cipherType.secureNote:
|
||||
cipher.type = 'note';
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
exportCiphers.push(cipher);
|
||||
}
|
||||
|
||||
var csvString = Papa.unparse(exportCiphers);
|
||||
|
@ -167,7 +167,7 @@
|
||||
'url', 'hyper link', 'hyperlink', 'link',
|
||||
'host', 'hostname', 'host name', 'server', 'address',
|
||||
'hyper ref', 'href', 'web', 'website', 'web site', 'site',
|
||||
'web-site',
|
||||
'web-site', 'uri',
|
||||
|
||||
// Non-English names
|
||||
'ort', 'adresse'
|
||||
@ -270,13 +270,7 @@
|
||||
favorite: value.favorite && value.favorite !== '' && value.favorite !== '0' ? true : false,
|
||||
notes: value.notes && value.notes !== '' ? value.notes : null,
|
||||
name: value.name && value.name !== '' ? value.name : '--',
|
||||
type: constants.cipherType.login,
|
||||
login: {
|
||||
totp: value.totp && value.totp !== '' ? value.totp : null,
|
||||
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
|
||||
}
|
||||
type: constants.cipherType.login
|
||||
};
|
||||
|
||||
if (value.fields && value.fields !== '') {
|
||||
@ -309,6 +303,31 @@
|
||||
}
|
||||
}
|
||||
|
||||
switch (value.type) {
|
||||
case 'login': case null: case undefined:
|
||||
cipher.type = constants.cipherType.login;
|
||||
|
||||
var totp = value.login_totp || value.totp
|
||||
var uri = value.login_uri || value.uri;
|
||||
var username = value.login_username || value.username;
|
||||
var password = value.login_password || value.password;
|
||||
cipher.login = {
|
||||
totp: totp && totp !== '' ? totp : null,
|
||||
uri: uri && uri !== '' ? trimUri(uri) : null,
|
||||
username: username && username !== '' ? username : null,
|
||||
password: password && password !== '' ? password : null
|
||||
};
|
||||
break;
|
||||
case 'note':
|
||||
cipher.type = constants.cipherType.secureNote;
|
||||
cipher.secureNote = {
|
||||
type: 0 // generic note
|
||||
};
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
ciphers.push(cipher);
|
||||
|
||||
if (addFolder) {
|
||||
@ -378,13 +397,7 @@
|
||||
favorite: false,
|
||||
notes: value.notes && value.notes !== '' ? value.notes : null,
|
||||
name: value.name && value.name !== '' ? value.name : '--',
|
||||
type: constants.cipherType.login,
|
||||
login: {
|
||||
totp: value.totp && value.totp !== '' ? value.totp : null,
|
||||
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
|
||||
}
|
||||
type: constants.cipherType.login
|
||||
};
|
||||
|
||||
if (value.fields && value.fields !== '') {
|
||||
@ -417,6 +430,31 @@
|
||||
}
|
||||
}
|
||||
|
||||
switch (value.type) {
|
||||
case 'login': case null: case undefined:
|
||||
cipher.type = constants.cipherType.login;
|
||||
|
||||
var totp = value.login_totp || value.totp
|
||||
var uri = value.login_uri || value.uri;
|
||||
var username = value.login_username || value.username;
|
||||
var password = value.login_password || value.password;
|
||||
cipher.login = {
|
||||
totp: totp && totp !== '' ? totp : null,
|
||||
uri: uri && uri !== '' ? trimUri(uri) : null,
|
||||
username: username && username !== '' ? username : null,
|
||||
password: password && password !== '' ? password : null
|
||||
};
|
||||
break;
|
||||
case 'note':
|
||||
cipher.type = constants.cipherType.secureNote;
|
||||
cipher.secureNote = {
|
||||
type: 0 // generic note
|
||||
};
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
ciphers.push(cipher);
|
||||
});
|
||||
|
||||
|
@ -32,38 +32,57 @@
|
||||
try {
|
||||
var exportCiphers = [];
|
||||
for (i = 0; i < decCiphers.length; i++) {
|
||||
// only export logins for now
|
||||
if (decCiphers[i].type !== constants.cipherType.login) {
|
||||
// only export logins and secure notes
|
||||
if (decCiphers[i].type !== constants.cipherType.login &&
|
||||
decCiphers[i].type !== constants.cipherType.secureNote) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var login = {
|
||||
name: decCiphers[i].name,
|
||||
uri: decCiphers[i].login.uri,
|
||||
username: decCiphers[i].login.username,
|
||||
password: decCiphers[i].login.password,
|
||||
notes: decCiphers[i].notes,
|
||||
var cipher = {
|
||||
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
|
||||
type: null,
|
||||
name: decCiphers[i].name,
|
||||
notes: decCiphers[i].notes,
|
||||
fields: null,
|
||||
// Login props
|
||||
login_uri: null,
|
||||
login_username: null,
|
||||
login_password: null,
|
||||
login_totp: null
|
||||
};
|
||||
|
||||
if (decCiphers[i].fields) {
|
||||
for (var j = 0; j < decCiphers[i].fields.length; j++) {
|
||||
if (!login.fields) {
|
||||
login.fields = '';
|
||||
if (!cipher.fields) {
|
||||
cipher.fields = '';
|
||||
}
|
||||
else {
|
||||
login.fields += '\n';
|
||||
cipher.fields += '\n';
|
||||
}
|
||||
|
||||
login.fields += ((decCiphers[i].fields[j].name || '') + ': ' + decCiphers[i].fields[j].value);
|
||||
cipher.fields += ((decCiphers[i].fields[j].name || '') + ': ' + decCiphers[i].fields[j].value);
|
||||
}
|
||||
}
|
||||
|
||||
exportCiphers.push(login);
|
||||
switch (decCiphers[i].type) {
|
||||
case constants.cipherType.login:
|
||||
cipher.type = 'login';
|
||||
cipher.login_uri = decCiphers[i].login.uri;
|
||||
cipher.login_username = decCiphers[i].login.username;
|
||||
cipher.login_password = decCiphers[i].login.password;
|
||||
cipher.login_totp = decCiphers[i].login.totp;
|
||||
break;
|
||||
case constants.cipherType.secureNote:
|
||||
cipher.type = 'note';
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
exportCiphers.push(cipher);
|
||||
}
|
||||
|
||||
var csvString = Papa.unparse(exportCiphers);
|
||||
|
Loading…
Reference in New Issue
Block a user