1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-27 12:36:14 +01:00

stick password xml importer

This commit is contained in:
Kyle Spearrin 2018-07-13 17:11:19 -04:00
parent 51f041a959
commit 76ece834d1
2 changed files with 79 additions and 2 deletions

View File

@ -3,8 +3,6 @@ import { Importer } from './importer';
import { ImportResult } from '../models/domain/importResult';
import { FolderView } from '../models/view/folderView';
export class PasswordDragonXmlImporter extends BaseImporter implements Importer {
parse(data: string): ImportResult {
const result = new ImportResult();

View File

@ -0,0 +1,79 @@
import { BaseImporter } from './baseImporter';
import { Importer } from './importer';
import { ImportResult } from '../models/domain/importResult';
export class StickyPasswordXmlImporter 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 loginNodes = doc.querySelectorAll('root > Database > Logins > Login');
Array.from(loginNodes).forEach((loginNode) => {
const accountId = loginNode.getAttribute('ID');
if (this.isNullOrWhitespace(accountId)) {
return;
}
const usernameText = loginNode.getAttribute('Name');
const passwordText = loginNode.getAttribute('Password');
let titleText: string = null;
let linkText: string = null;
let notesText: string = null;
let groupId: string = null;
let groupText: string = null;
const accountLogin = doc.querySelector('root > Database > Accounts > Account > ' +
'LoginLinks > Login[SourceLoginID="' + accountId + '"]');
if (accountLogin != null) {
const account = accountLogin.parentElement.parentElement;
if (account != null) {
titleText = account.getAttribute('Name');
linkText = account.getAttribute('Link');
groupId = account.getAttribute('ParentID');
notesText = account.getAttribute('Comments');
if (!this.isNullOrWhitespace(notesText)) {
notesText = notesText.split('/n').join('\n');
}
}
}
if (!this.isNullOrWhitespace(groupId)) {
groupText = this.buildGroupText(doc, groupId, '');
this.processFolder(result, groupText);
}
const cipher = this.initLoginCipher();
cipher.name = this.getValueOrDefault(titleText, '--');
cipher.notes = this.getValueOrDefault(notesText);
cipher.login.username = this.getValueOrDefault(usernameText);
cipher.login.password = this.getValueOrDefault(passwordText);
cipher.login.uris = this.makeUriArray(linkText);
this.cleanupCipher(cipher);
result.ciphers.push(cipher);
});
if (this.organization) {
this.moveFoldersToCollections(result);
}
result.success = true;
return result;
}
buildGroupText(doc: Document, groupId: string, groupText: string): string {
const group = doc.querySelector('root > Database > Groups > Group[ID="' + groupId + '"]');
if (group == null) {
return groupText;
}
if (!this.isNullOrWhitespace(groupText)) {
groupText = ' > ' + groupText;
}
groupText = group.getAttribute('Name') + groupText;
return this.buildGroupText(doc, group.getAttribute('ParentID'), groupText);
}
}