add several simple csv importers

This commit is contained in:
Kyle Spearrin 2018-07-10 23:17:55 -04:00
parent 089622d5b1
commit 4ba55c8c8b
5 changed files with 146 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}