mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-27 12:36:14 +01:00
more importer helpers
This commit is contained in:
parent
4004449aa8
commit
c9fc74c5cb
@ -3,11 +3,6 @@ import { Importer } from './importer';
|
|||||||
|
|
||||||
import { ImportResult } from '../models/domain/importResult';
|
import { ImportResult } from '../models/domain/importResult';
|
||||||
|
|
||||||
import { CipherView } from '../models/view/cipherView';
|
|
||||||
import { LoginView } from '../models/view/loginView';
|
|
||||||
|
|
||||||
import { CipherType } from '../enums/cipherType';
|
|
||||||
|
|
||||||
export class AviraCsvImporter extends BaseImporter implements Importer {
|
export class AviraCsvImporter extends BaseImporter implements Importer {
|
||||||
parse(data: string): ImportResult {
|
parse(data: string): ImportResult {
|
||||||
const result = new ImportResult();
|
const result = new ImportResult();
|
||||||
@ -18,11 +13,9 @@ export class AviraCsvImporter extends BaseImporter implements Importer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
results.forEach((value) => {
|
results.forEach((value) => {
|
||||||
const cipher = new CipherView();
|
const cipher = this.initLoginCipher();
|
||||||
cipher.type = CipherType.Login;
|
|
||||||
cipher.name = this.getValueOrDefault(value.name,
|
cipher.name = this.getValueOrDefault(value.name,
|
||||||
this.getValueOrDefault(this.nameFromUrl(value.website), '--'));
|
this.getValueOrDefault(this.nameFromUrl(value.website), '--'));
|
||||||
cipher.login = new LoginView();
|
|
||||||
cipher.login.uris = this.makeUriArray(value.website);
|
cipher.login.uris = this.makeUriArray(value.website);
|
||||||
cipher.login.password = this.getValueOrDefault(value.password);
|
cipher.login.password = this.getValueOrDefault(value.password);
|
||||||
|
|
||||||
@ -33,6 +26,7 @@ export class AviraCsvImporter extends BaseImporter implements Importer {
|
|||||||
cipher.notes = this.getValueOrDefault(value.secondary_username);
|
cipher.notes = this.getValueOrDefault(value.secondary_username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.cleanupCipher(cipher);
|
||||||
result.ciphers.push(cipher);
|
result.ciphers.push(cipher);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2,10 +2,16 @@ import * as papa from 'papaparse';
|
|||||||
|
|
||||||
import { ImportResult } from '../models/domain/importResult';
|
import { ImportResult } from '../models/domain/importResult';
|
||||||
|
|
||||||
|
import { CipherView } from '../models/view/cipherView';
|
||||||
import { CollectionView } from '../models/view/collectionView';
|
import { CollectionView } from '../models/view/collectionView';
|
||||||
import { LoginUriView } from '../models/view/loginUriView';
|
import { LoginUriView } from '../models/view/loginUriView';
|
||||||
|
|
||||||
import { Utils } from '../misc/utils';
|
import { Utils } from '../misc/utils';
|
||||||
|
import { FieldView } from '../models/view/fieldView';
|
||||||
|
import { LoginView } from '../models/view/loginView';
|
||||||
|
|
||||||
|
import { CipherType } from '../enums/cipherType';
|
||||||
|
import { FieldType } from '../enums/fieldType';
|
||||||
|
|
||||||
export abstract class BaseImporter {
|
export abstract class BaseImporter {
|
||||||
organization = false;
|
organization = false;
|
||||||
@ -227,4 +233,58 @@ export abstract class BaseImporter {
|
|||||||
protected querySelectorAllDirectChild(parentEl: Element, query: string) {
|
protected querySelectorAllDirectChild(parentEl: Element, query: string) {
|
||||||
return Array.from(parentEl.querySelectorAll(query)).filter((el) => el.parentNode === parentEl);
|
return Array.from(parentEl.querySelectorAll(query)).filter((el) => el.parentNode === parentEl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected initLoginCipher() {
|
||||||
|
const cipher = new CipherView();
|
||||||
|
cipher.favorite = false;
|
||||||
|
cipher.notes = '';
|
||||||
|
cipher.fields = [];
|
||||||
|
cipher.login = new LoginView();
|
||||||
|
cipher.type = CipherType.Login;
|
||||||
|
return cipher;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected cleanupCipher(cipher: CipherView) {
|
||||||
|
if (cipher == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (cipher.type !== CipherType.Login) {
|
||||||
|
cipher.login = null;
|
||||||
|
}
|
||||||
|
if (this.isNullOrWhitespace(cipher.name)) {
|
||||||
|
cipher.name = '--';
|
||||||
|
}
|
||||||
|
if (this.isNullOrWhitespace(cipher.notes)) {
|
||||||
|
cipher.notes = null;
|
||||||
|
} else {
|
||||||
|
cipher.notes = cipher.notes.trim();
|
||||||
|
}
|
||||||
|
if (cipher.fields != null && cipher.fields.length === 0) {
|
||||||
|
cipher.fields = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected processKvp(cipher: CipherView, key: string, value: string) {
|
||||||
|
if (this.isNullOrWhitespace(value)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.isNullOrWhitespace(key)) {
|
||||||
|
key = '';
|
||||||
|
}
|
||||||
|
if (value.length > 200 || value.search(this.newLineRegex) > -1) {
|
||||||
|
if (cipher.notes == null) {
|
||||||
|
cipher.notes = '';
|
||||||
|
}
|
||||||
|
cipher.notes += (key + ': ' + value + '\n');
|
||||||
|
} else {
|
||||||
|
if (cipher.fields == null) {
|
||||||
|
cipher.fields = [];
|
||||||
|
}
|
||||||
|
const field = new FieldView();
|
||||||
|
field.type = FieldType.Text;
|
||||||
|
field.name = key;
|
||||||
|
field.value = value;
|
||||||
|
cipher.fields.push(field);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,6 @@ import { Importer } from './importer';
|
|||||||
|
|
||||||
import { ImportResult } from '../models/domain/importResult';
|
import { ImportResult } from '../models/domain/importResult';
|
||||||
|
|
||||||
import { CipherView } from '../models/view/cipherView';
|
|
||||||
import { LoginView } from '../models/view/loginView';
|
|
||||||
|
|
||||||
import { CipherType } from '../enums/cipherType';
|
|
||||||
|
|
||||||
export class BlurCsvImporter extends BaseImporter implements Importer {
|
export class BlurCsvImporter extends BaseImporter implements Importer {
|
||||||
parse(data: string): ImportResult {
|
parse(data: string): ImportResult {
|
||||||
const result = new ImportResult();
|
const result = new ImportResult();
|
||||||
@ -18,14 +13,12 @@ export class BlurCsvImporter extends BaseImporter implements Importer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
results.forEach((value) => {
|
results.forEach((value) => {
|
||||||
const cipher = new CipherView();
|
|
||||||
cipher.type = CipherType.Login;
|
|
||||||
if (value.label === 'null') {
|
if (value.label === 'null') {
|
||||||
value.label = null;
|
value.label = null;
|
||||||
}
|
}
|
||||||
|
const cipher = this.initLoginCipher();
|
||||||
cipher.name = this.getValueOrDefault(value.label,
|
cipher.name = this.getValueOrDefault(value.label,
|
||||||
this.getValueOrDefault(this.nameFromUrl(value.domain), '--'));
|
this.getValueOrDefault(this.nameFromUrl(value.domain), '--'));
|
||||||
cipher.login = new LoginView();
|
|
||||||
cipher.login.uris = this.makeUriArray(value.domain);
|
cipher.login.uris = this.makeUriArray(value.domain);
|
||||||
cipher.login.password = this.getValueOrDefault(value.password);
|
cipher.login.password = this.getValueOrDefault(value.password);
|
||||||
|
|
||||||
@ -36,6 +29,7 @@ export class BlurCsvImporter extends BaseImporter implements Importer {
|
|||||||
cipher.notes = this.getValueOrDefault(value.username);
|
cipher.notes = this.getValueOrDefault(value.username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.cleanupCipher(cipher);
|
||||||
result.ciphers.push(cipher);
|
result.ciphers.push(cipher);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -3,11 +3,7 @@ import { Importer } from './importer';
|
|||||||
|
|
||||||
import { ImportResult } from '../models/domain/importResult';
|
import { ImportResult } from '../models/domain/importResult';
|
||||||
|
|
||||||
import { CipherView } from '../models/view/cipherView';
|
|
||||||
import { FolderView } from '../models/view/folderView';
|
import { FolderView } from '../models/view/folderView';
|
||||||
import { LoginView } from '../models/view/loginView';
|
|
||||||
|
|
||||||
import { CipherType } from '../enums/cipherType';
|
|
||||||
|
|
||||||
export class KeePassXCsvImporter extends BaseImporter implements Importer {
|
export class KeePassXCsvImporter extends BaseImporter implements Importer {
|
||||||
parse(data: string): ImportResult {
|
parse(data: string): ImportResult {
|
||||||
@ -50,15 +46,13 @@ export class KeePassXCsvImporter extends BaseImporter implements Importer {
|
|||||||
result.folderRelationships.push([result.ciphers.length, folderIndex]);
|
result.folderRelationships.push([result.ciphers.length, folderIndex]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const cipher = new CipherView();
|
const cipher = this.initLoginCipher();
|
||||||
cipher.type = CipherType.Login;
|
|
||||||
cipher.favorite = false;
|
|
||||||
cipher.notes = this.getValueOrDefault(value.Notes);
|
cipher.notes = this.getValueOrDefault(value.Notes);
|
||||||
cipher.name = this.getValueOrDefault(value.Title, '--');
|
cipher.name = this.getValueOrDefault(value.Title, '--');
|
||||||
cipher.login = new LoginView();
|
|
||||||
cipher.login.username = this.getValueOrDefault(value.Username);
|
cipher.login.username = this.getValueOrDefault(value.Username);
|
||||||
cipher.login.password = this.getValueOrDefault(value.Password);
|
cipher.login.password = this.getValueOrDefault(value.Password);
|
||||||
cipher.login.uris = this.makeUriArray(value.URL);
|
cipher.login.uris = this.makeUriArray(value.URL);
|
||||||
|
this.cleanupCipher(cipher);
|
||||||
result.ciphers.push(cipher);
|
result.ciphers.push(cipher);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -3,14 +3,8 @@ import { Importer } from './importer';
|
|||||||
|
|
||||||
import { ImportResult } from '../models/domain/importResult';
|
import { ImportResult } from '../models/domain/importResult';
|
||||||
|
|
||||||
import { CipherView } from '../models/view/cipherView';
|
|
||||||
import { CollectionView } from '../models/view/collectionView';
|
import { CollectionView } from '../models/view/collectionView';
|
||||||
import { FieldView } from '../models/view/fieldView';
|
|
||||||
import { FolderView } from '../models/view/folderView';
|
import { FolderView } from '../models/view/folderView';
|
||||||
import { LoginView } from '../models/view/loginView';
|
|
||||||
|
|
||||||
import { CipherType } from '../enums/cipherType';
|
|
||||||
import { FieldType } from '../enums/fieldType';
|
|
||||||
|
|
||||||
export class PadlockCsvImporter extends BaseImporter implements Importer {
|
export class PadlockCsvImporter extends BaseImporter implements Importer {
|
||||||
parse(data: string): ImportResult {
|
parse(data: string): ImportResult {
|
||||||
@ -84,13 +78,8 @@ export class PadlockCsvImporter extends BaseImporter implements Importer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const cipher = new CipherView();
|
const cipher = this.initLoginCipher();
|
||||||
cipher.type = CipherType.Login;
|
|
||||||
cipher.favorite = false;
|
|
||||||
cipher.notes = '';
|
|
||||||
cipher.fields = [];
|
|
||||||
cipher.name = this.getValueOrDefault(value[0], '--');
|
cipher.name = this.getValueOrDefault(value[0], '--');
|
||||||
cipher.login = new LoginView();
|
|
||||||
|
|
||||||
for (let i = 2; i < value.length; i++) {
|
for (let i = 2; i < value.length; i++) {
|
||||||
const header = headers[i].trim().toLowerCase();
|
const header = headers[i].trim().toLowerCase();
|
||||||
@ -105,27 +94,11 @@ export class PadlockCsvImporter extends BaseImporter implements Importer {
|
|||||||
} else if (this.uriFieldNames.indexOf(header) > -1) {
|
} else if (this.uriFieldNames.indexOf(header) > -1) {
|
||||||
cipher.login.uris = this.makeUriArray(value[i]);
|
cipher.login.uris = this.makeUriArray(value[i]);
|
||||||
} else {
|
} else {
|
||||||
if (value[i].length > 200 || value[i].search(this.newLineRegex) > -1) {
|
this.processKvp(cipher, headers[i], value[i]);
|
||||||
cipher.notes += (headers[i] + ': ' + value[i] + '\n');
|
|
||||||
} else {
|
|
||||||
const field = new FieldView();
|
|
||||||
field.type = FieldType.Text;
|
|
||||||
field.name = headers[i];
|
|
||||||
field.value = value[i];
|
|
||||||
cipher.fields.push(field);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isNullOrWhitespace(cipher.notes)) {
|
this.cleanupCipher(cipher);
|
||||||
cipher.notes = null;
|
|
||||||
} else {
|
|
||||||
cipher.notes = cipher.notes.trim();
|
|
||||||
}
|
|
||||||
if (cipher.fields.length === 0) {
|
|
||||||
cipher.fields = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
result.ciphers.push(cipher);
|
result.ciphers.push(cipher);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -3,14 +3,10 @@ import { Importer } from './importer';
|
|||||||
|
|
||||||
import { ImportResult } from '../models/domain/importResult';
|
import { ImportResult } from '../models/domain/importResult';
|
||||||
|
|
||||||
import { CipherView } from '../models/view/cipherView';
|
|
||||||
import { FieldView } from '../models/view/fieldView';
|
|
||||||
import { FolderView } from '../models/view/folderView';
|
import { FolderView } from '../models/view/folderView';
|
||||||
import { LoginView } from '../models/view/loginView';
|
|
||||||
import { SecureNoteView } from '../models/view/secureNoteView';
|
import { SecureNoteView } from '../models/view/secureNoteView';
|
||||||
|
|
||||||
import { CipherType } from '../enums/cipherType';
|
import { CipherType } from '../enums/cipherType';
|
||||||
import { FieldType } from '../enums/fieldType';
|
|
||||||
import { SecureNoteType } from '../enums/secureNoteType';
|
import { SecureNoteType } from '../enums/secureNoteType';
|
||||||
|
|
||||||
export class SafeInCloudXmlImporter extends BaseImporter implements Importer {
|
export class SafeInCloudXmlImporter extends BaseImporter implements Importer {
|
||||||
@ -55,11 +51,8 @@ export class SafeInCloudXmlImporter extends BaseImporter implements Importer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const cipher = new CipherView();
|
const cipher = this.initLoginCipher();
|
||||||
cipher.favorite = false;
|
|
||||||
cipher.notes = '';
|
|
||||||
cipher.name = this.getValueOrDefault(cardEl.getAttribute('title'), '--');
|
cipher.name = this.getValueOrDefault(cardEl.getAttribute('title'), '--');
|
||||||
cipher.fields = null;
|
|
||||||
|
|
||||||
const cardType = cardEl.getAttribute('type');
|
const cardType = cardEl.getAttribute('type');
|
||||||
if (cardType === 'note') {
|
if (cardType === 'note') {
|
||||||
@ -67,8 +60,6 @@ export class SafeInCloudXmlImporter extends BaseImporter implements Importer {
|
|||||||
cipher.secureNote = new SecureNoteView();
|
cipher.secureNote = new SecureNoteView();
|
||||||
cipher.secureNote.type = SecureNoteType.Generic;
|
cipher.secureNote.type = SecureNoteType.Generic;
|
||||||
} else {
|
} else {
|
||||||
cipher.type = CipherType.Login;
|
|
||||||
cipher.login = new LoginView();
|
|
||||||
Array.from(this.querySelectorAllDirectChild(cardEl, 'field')).forEach((fieldEl) => {
|
Array.from(this.querySelectorAllDirectChild(cardEl, 'field')).forEach((fieldEl) => {
|
||||||
const text = fieldEl.textContent;
|
const text = fieldEl.textContent;
|
||||||
if (this.isNullOrWhitespace(text)) {
|
if (this.isNullOrWhitespace(text)) {
|
||||||
@ -84,17 +75,8 @@ export class SafeInCloudXmlImporter extends BaseImporter implements Importer {
|
|||||||
cipher.notes += (text + '\n');
|
cipher.notes += (text + '\n');
|
||||||
} else if (fieldType === 'weblogin' || fieldType === 'website') {
|
} else if (fieldType === 'weblogin' || fieldType === 'website') {
|
||||||
cipher.login.uris = this.makeUriArray(text);
|
cipher.login.uris = this.makeUriArray(text);
|
||||||
} else if (text.length > 200) {
|
|
||||||
cipher.notes += (name + ': ' + text + '\n');
|
|
||||||
} else {
|
} else {
|
||||||
if (cipher.fields == null) {
|
this.processKvp(cipher, name, text);
|
||||||
cipher.fields = [];
|
|
||||||
}
|
|
||||||
const field = new FieldView();
|
|
||||||
field.name = name;
|
|
||||||
field.value = text;
|
|
||||||
field.type = FieldType.Text;
|
|
||||||
cipher.fields.push(field);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -103,11 +85,7 @@ export class SafeInCloudXmlImporter extends BaseImporter implements Importer {
|
|||||||
cipher.notes += (notesEl.textContent + '\n');
|
cipher.notes += (notesEl.textContent + '\n');
|
||||||
});
|
});
|
||||||
|
|
||||||
cipher.notes = cipher.notes.trim();
|
this.cleanupCipher(cipher);
|
||||||
if (cipher.notes === '') {
|
|
||||||
cipher.notes = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
result.ciphers.push(cipher);
|
result.ciphers.push(cipher);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user