handle logins & notes for generic export/import

This commit is contained in:
Kyle Spearrin 2017-10-23 12:40:42 -04:00
parent 805393b4db
commit b0832578a4
3 changed files with 132 additions and 61 deletions

View File

@ -16,12 +16,7 @@
var ciphersPromise = apiService.ciphers.listOrganizationDetails({ organizationId: $state.params.orgId }, var ciphersPromise = apiService.ciphers.listOrganizationDetails({ organizationId: $state.params.orgId },
function (ciphers) { function (ciphers) {
for (var i = 0; i < ciphers.Data.length; i++) { decCiphers = cipherService.decryptCiphers(ciphers.Data);
if (ciphers.Data[i].Type === 1) {
var decCipher = cipherService.decryptCipher(ciphers.Data[i]);
decCiphers.push(decCipher);
}
}
}).$promise; }).$promise;
$q.all([collectionsPromise, ciphersPromise]).then(function () { $q.all([collectionsPromise, ciphersPromise]).then(function () {
@ -39,45 +34,64 @@
try { try {
var exportCiphers = []; var exportCiphers = [];
for (i = 0; i < decCiphers.length; i++) { for (i = 0; i < decCiphers.length; i++) {
// only export logins for now // only export logins and secure notes
if (decCiphers[i].type !== constants.cipherType.login) { if (decCiphers[i].type !== constants.cipherType.login &&
decCiphers[i].type !== constants.cipherType.secureNote) {
continue; continue;
} }
var login = { var cipher = {
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,
collections: [], 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; 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) { if (decCiphers[i].collectionIds) {
for (j = 0; j < decCiphers[i].collectionIds.length; j++) { for (j = 0; j < decCiphers[i].collectionIds.length; j++) {
if (collectionsDict.hasOwnProperty(decCiphers[i].collectionIds[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); var csvString = Papa.unparse(exportCiphers);

View File

@ -167,7 +167,7 @@
'url', 'hyper link', 'hyperlink', 'link', 'url', 'hyper link', 'hyperlink', 'link',
'host', 'hostname', 'host name', 'server', 'address', 'host', 'hostname', 'host name', 'server', 'address',
'hyper ref', 'href', 'web', 'website', 'web site', 'site', 'hyper ref', 'href', 'web', 'website', 'web site', 'site',
'web-site', 'web-site', 'uri',
// Non-English names // Non-English names
'ort', 'adresse' 'ort', 'adresse'
@ -270,13 +270,7 @@
favorite: value.favorite && value.favorite !== '' && value.favorite !== '0' ? true : false, favorite: value.favorite && value.favorite !== '' && value.favorite !== '0' ? true : false,
notes: value.notes && value.notes !== '' ? value.notes : null, notes: value.notes && value.notes !== '' ? value.notes : null,
name: value.name && value.name !== '' ? value.name : '--', name: value.name && value.name !== '' ? value.name : '--',
type: constants.cipherType.login, 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
}
}; };
if (value.fields && value.fields !== '') { 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); ciphers.push(cipher);
if (addFolder) { if (addFolder) {
@ -378,13 +397,7 @@
favorite: false, favorite: false,
notes: value.notes && value.notes !== '' ? value.notes : null, notes: value.notes && value.notes !== '' ? value.notes : null,
name: value.name && value.name !== '' ? value.name : '--', name: value.name && value.name !== '' ? value.name : '--',
type: constants.cipherType.login, 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
}
}; };
if (value.fields && value.fields !== '') { 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); ciphers.push(cipher);
}); });

View File

@ -32,38 +32,57 @@
try { try {
var exportCiphers = []; var exportCiphers = [];
for (i = 0; i < decCiphers.length; i++) { for (i = 0; i < decCiphers.length; i++) {
// only export logins for now // only export logins and secure notes
if (decCiphers[i].type !== constants.cipherType.login) { if (decCiphers[i].type !== constants.cipherType.login &&
decCiphers[i].type !== constants.cipherType.secureNote) {
continue; continue;
} }
var login = { var cipher = {
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) ? folder: decCiphers[i].folderId && (decCiphers[i].folderId in foldersDict) ?
foldersDict[decCiphers[i].folderId].name : null, foldersDict[decCiphers[i].folderId].name : null,
favorite: decCiphers[i].favorite ? 1 : null, favorite: decCiphers[i].favorite ? 1 : null,
totp: decCiphers[i].login.totp, type: null,
fields: 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) { if (decCiphers[i].fields) {
for (var j = 0; j < decCiphers[i].fields.length; j++) { for (var j = 0; j < decCiphers[i].fields.length; j++) {
if (!login.fields) { if (!cipher.fields) {
login.fields = ''; cipher.fields = '';
} }
else { 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); var csvString = Papa.unparse(exportCiphers);