From 4ba55c8c8bf12385502c1db4c9ba28c33792e433 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 10 Jul 2018 23:17:55 -0400 Subject: [PATCH] add several simple csv importers --- src/importers/chromeCsvImporter.ts | 28 +++++++++++++++++++++++++ src/importers/firefoxCsvImporter.ts | 28 +++++++++++++++++++++++++ src/importers/meldiumCsvImporter.ts | 29 ++++++++++++++++++++++++++ src/importers/saferpassCsvImport.ts | 29 ++++++++++++++++++++++++++ src/importers/upmCsvImporter.ts | 32 +++++++++++++++++++++++++++++ 5 files changed, 146 insertions(+) create mode 100644 src/importers/chromeCsvImporter.ts create mode 100644 src/importers/firefoxCsvImporter.ts create mode 100644 src/importers/meldiumCsvImporter.ts create mode 100644 src/importers/saferpassCsvImport.ts create mode 100644 src/importers/upmCsvImporter.ts diff --git a/src/importers/chromeCsvImporter.ts b/src/importers/chromeCsvImporter.ts new file mode 100644 index 0000000000..5ca97dd20a --- /dev/null +++ b/src/importers/chromeCsvImporter.ts @@ -0,0 +1,28 @@ +import { BaseImporter } from './baseImporter'; +import { Importer } from './importer'; + +import { ImportResult } from '../models/domain/importResult'; + +export class ChromeCsvImporter extends BaseImporter implements Importer { + parse(data: string): ImportResult { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return result; + } + + results.forEach((value) => { + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(value.name, '--'); + cipher.login.username = this.getValueOrDefault(value.username); + cipher.login.password = this.getValueOrDefault(value.password); + cipher.login.uris = this.makeUriArray(value.url); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return result; + } +} diff --git a/src/importers/firefoxCsvImporter.ts b/src/importers/firefoxCsvImporter.ts new file mode 100644 index 0000000000..8c5b1c1313 --- /dev/null +++ b/src/importers/firefoxCsvImporter.ts @@ -0,0 +1,28 @@ +import { BaseImporter } from './baseImporter'; +import { Importer } from './importer'; + +import { ImportResult } from '../models/domain/importResult'; + +export class FirefoxCsvImporter extends BaseImporter implements Importer { + parse(data: string): ImportResult { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return result; + } + + results.forEach((value) => { + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(this.nameFromUrl(value.hostname), '--'); + cipher.login.username = this.getValueOrDefault(value.username); + cipher.login.password = this.getValueOrDefault(value.password); + cipher.login.uris = this.makeUriArray(value.hostname); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return result; + } +} diff --git a/src/importers/meldiumCsvImporter.ts b/src/importers/meldiumCsvImporter.ts new file mode 100644 index 0000000000..f73de0124a --- /dev/null +++ b/src/importers/meldiumCsvImporter.ts @@ -0,0 +1,29 @@ +import { BaseImporter } from './baseImporter'; +import { Importer } from './importer'; + +import { ImportResult } from '../models/domain/importResult'; + +export class MeldiumCsvImporter extends BaseImporter implements Importer { + parse(data: string): ImportResult { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return result; + } + + results.forEach((value) => { + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(value.DisplayName, '--'); + cipher.notes = this.getValueOrDefault(value.Notes); + cipher.login.username = this.getValueOrDefault(value.UserName); + cipher.login.password = this.getValueOrDefault(value.Password); + cipher.login.uris = this.makeUriArray(value.Url); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return result; + } +} diff --git a/src/importers/saferpassCsvImport.ts b/src/importers/saferpassCsvImport.ts new file mode 100644 index 0000000000..e36c3da498 --- /dev/null +++ b/src/importers/saferpassCsvImport.ts @@ -0,0 +1,29 @@ +import { BaseImporter } from './baseImporter'; +import { Importer } from './importer'; + +import { ImportResult } from '../models/domain/importResult'; + +export class SaferPassCsvImporter extends BaseImporter implements Importer { + parse(data: string): ImportResult { + const result = new ImportResult(); + const results = this.parseCsv(data, true); + if (results == null) { + result.success = false; + return result; + } + + results.forEach((value) => { + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(this.nameFromUrl(value.url), '--'); + cipher.notes = this.getValueOrDefault(value.notes); + cipher.login.username = this.getValueOrDefault(value.username); + cipher.login.password = this.getValueOrDefault(value.password); + cipher.login.uris = this.makeUriArray(value.url); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return result; + } +} diff --git a/src/importers/upmCsvImporter.ts b/src/importers/upmCsvImporter.ts new file mode 100644 index 0000000000..8b5002cad7 --- /dev/null +++ b/src/importers/upmCsvImporter.ts @@ -0,0 +1,32 @@ +import { BaseImporter } from './baseImporter'; +import { Importer } from './importer'; + +import { ImportResult } from '../models/domain/importResult'; + +export class UpmCsvImporter extends BaseImporter implements Importer { + parse(data: string): ImportResult { + const result = new ImportResult(); + const results = this.parseCsv(data, false); + if (results == null) { + result.success = false; + return result; + } + + results.forEach((value) => { + if (value.length !== 5) { + return; + } + const cipher = this.initLoginCipher(); + cipher.name = this.getValueOrDefault(value[0], '--'); + cipher.notes = this.getValueOrDefault(value[4]); + cipher.login.username = this.getValueOrDefault(value[1]); + cipher.login.password = this.getValueOrDefault(value[2]); + cipher.login.uris = this.makeUriArray(value[3]); + this.cleanupCipher(cipher); + result.ciphers.push(cipher); + }); + + result.success = true; + return result; + } +}