mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-14 10:26:19 +01:00
0e78910582
* Rename all importer related files Renamed all files based on our naming convention which we decided on with https://github.com/bitwarden/adr/blob/master/decisions/0012-angular-filename-convention.md * Removed entries from whitelist-capital-letters.txt * Rename missing safeInCloud test data * Fix broken import * Renamed folders (removed capital letters) * Fix filename of BitwardenCsvImporter * Fix imports of onepassword mac/win importer tests * Remove already renamed folders from whitelist * Rename dashlaneImporters to dashlane Rename the folder Fix all the imports Remove dashlaneImporters from white-list * Rename keeperImporters to keeper Rename the folder Fix all the imports Remove keeperImporters from white-list * Rename onepasswordImporters to onepassword Rename the folder Fix all the imports Remove onepasswordImporters from white-list * Rename safeinCloud test data folder * Fix onepassword importer type imports
84 lines
2.8 KiB
TypeScript
84 lines
2.8 KiB
TypeScript
import { ImportResult } from "../models/domain/import-result";
|
|
|
|
import { BaseImporter } from "./base-importer";
|
|
import { Importer } from "./importer";
|
|
|
|
export class StickyPasswordXmlImporter extends BaseImporter implements Importer {
|
|
parse(data: string): Promise<ImportResult> {
|
|
const result = new ImportResult();
|
|
const doc = this.parseXml(data);
|
|
if (doc == null) {
|
|
result.success = false;
|
|
return Promise.resolve(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 Promise.resolve(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);
|
|
}
|
|
}
|