mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-24 12:06:15 +01:00
folder helps and pwsafe xml importer
This commit is contained in:
parent
768b41153d
commit
7ca2a40478
@ -8,6 +8,7 @@ import { LoginUriView } from '../models/view/loginUriView';
|
||||
|
||||
import { Utils } from '../misc/utils';
|
||||
import { FieldView } from '../models/view/fieldView';
|
||||
import { FolderView } from '../models/view/folderView';
|
||||
import { LoginView } from '../models/view/loginView';
|
||||
|
||||
import { CipherType } from '../enums/cipherType';
|
||||
@ -287,4 +288,29 @@ export abstract class BaseImporter {
|
||||
cipher.fields.push(field);
|
||||
}
|
||||
}
|
||||
|
||||
protected processFolder(result: ImportResult, folderName: string) {
|
||||
let folderIndex = result.folders.length;
|
||||
const hasFolder = !this.isNullOrWhitespace(folderName);
|
||||
let addFolder = hasFolder;
|
||||
|
||||
if (hasFolder) {
|
||||
for (let i = 0; i < result.folders.length; i++) {
|
||||
if (result.folders[i].name === folderName) {
|
||||
addFolder = false;
|
||||
folderIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (addFolder) {
|
||||
const f = new FolderView();
|
||||
f.name = folderName;
|
||||
result.folders.push(f);
|
||||
}
|
||||
if (hasFolder) {
|
||||
result.folderRelationships.push([result.ciphers.length, folderIndex]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
62
src/importers/passwordSafeXmlImporter.ts
Normal file
62
src/importers/passwordSafeXmlImporter.ts
Normal file
@ -0,0 +1,62 @@
|
||||
import { BaseImporter } from './baseImporter';
|
||||
import { Importer } from './importer';
|
||||
|
||||
import { ImportResult } from '../models/domain/importResult';
|
||||
|
||||
export class PasswordSafeXmlImporter extends BaseImporter implements Importer {
|
||||
parse(data: string): ImportResult {
|
||||
const result = new ImportResult();
|
||||
const doc = this.parseXml(data);
|
||||
if (doc == null) {
|
||||
result.success = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
const passwordSafe = doc.querySelector('passwordsafe');
|
||||
if (passwordSafe == null) {
|
||||
result.errorMessage = 'Missing `passwordsafe` node.';
|
||||
result.success = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
const notesDelimiter = passwordSafe.getAttribute('delimiter');
|
||||
const entries = doc.querySelectorAll('passwordsafe > entry');
|
||||
Array.from(entries).forEach((entry) => {
|
||||
const group = this.querySelectorDirectChild(entry, 'group');
|
||||
const groupText = group != null && !this.isNullOrWhitespace(group.textContent) ?
|
||||
group.textContent.split('.').join(' > ') : null;
|
||||
this.processFolder(result, groupText);
|
||||
|
||||
const title = this.querySelectorDirectChild(entry, 'title');
|
||||
const username = this.querySelectorDirectChild(entry, 'username');
|
||||
const email = this.querySelectorDirectChild(entry, 'email');
|
||||
const password = this.querySelectorDirectChild(entry, 'password');
|
||||
const url = this.querySelectorDirectChild(entry, 'url');
|
||||
const notes = this.querySelectorDirectChild(entry, 'notes');
|
||||
const cipher = this.initLoginCipher();
|
||||
cipher.name = title != null ? this.getValueOrDefault(title.textContent, '--') : '--';
|
||||
cipher.notes = notes != null ?
|
||||
this.getValueOrDefault(notes.textContent, '').split(notesDelimiter).join('\n') : null;
|
||||
cipher.login.username = username != null ? this.getValueOrDefault(username.textContent) : null;
|
||||
cipher.login.password = password != null ? this.getValueOrDefault(password.textContent) : null;
|
||||
cipher.login.uris = url != null ? this.makeUriArray(url.textContent) : null;
|
||||
|
||||
if (this.isNullOrWhitespace(cipher.login.username) && email != null) {
|
||||
cipher.login.username = this.getValueOrDefault(email.textContent);
|
||||
} else if (email != null && !this.isNullOrWhitespace(email.textContent)) {
|
||||
cipher.notes = this.isNullOrWhitespace(cipher.notes) ? 'Email: ' + email.textContent
|
||||
: (cipher.notes + '\n' + 'Email: ' + email.textContent);
|
||||
}
|
||||
|
||||
this.cleanupCipher(cipher);
|
||||
result.ciphers.push(cipher);
|
||||
});
|
||||
|
||||
if (this.organization) {
|
||||
this.moveFoldersToCollections(result);
|
||||
}
|
||||
|
||||
result.success = true;
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import { CipherString } from '../domain/cipherString';
|
||||
import { CipherString } from './cipherString';
|
||||
|
||||
import { View } from '../view/view';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user