2018-07-23 23:33:35 +02:00
|
|
|
import { BaseImporter } from './baseImporter';
|
|
|
|
import { Importer } from './importer';
|
|
|
|
|
|
|
|
import { ImportResult } from '../models/domain/importResult';
|
|
|
|
|
|
|
|
export class PasswordAgentCsvImporter 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;
|
|
|
|
}
|
|
|
|
|
2019-06-21 14:19:38 +02:00
|
|
|
let newVersion = true;
|
2018-07-23 23:33:35 +02:00
|
|
|
results.forEach((value) => {
|
2019-06-21 14:19:38 +02:00
|
|
|
if (value.length !== 5 && value.length < 9) {
|
2018-07-23 23:33:35 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const cipher = this.initLoginCipher();
|
|
|
|
cipher.name = this.getValueOrDefault(value[0], '--');
|
|
|
|
cipher.login.username = this.getValueOrDefault(value[1]);
|
|
|
|
cipher.login.password = this.getValueOrDefault(value[2]);
|
2019-06-21 14:19:38 +02:00
|
|
|
if (value.length === 5) {
|
|
|
|
newVersion = false;
|
|
|
|
cipher.notes = this.getValueOrDefault(value[4]);
|
|
|
|
cipher.login.uris = this.makeUriArray(value[3]);
|
|
|
|
} else {
|
|
|
|
const folder = this.getValueOrDefault(value[8], '(None)');
|
|
|
|
const folderName = folder !== '(None)' ? folder.split('\\').join('/') : null;
|
|
|
|
this.processFolder(result, folderName);
|
|
|
|
cipher.notes = this.getValueOrDefault(value[3]);
|
|
|
|
cipher.login.uris = this.makeUriArray(value[4]);
|
|
|
|
}
|
2018-07-23 23:33:35 +02:00
|
|
|
this.convertToNoteIfNeeded(cipher);
|
|
|
|
this.cleanupCipher(cipher);
|
|
|
|
result.ciphers.push(cipher);
|
|
|
|
});
|
|
|
|
|
2019-06-21 14:19:38 +02:00
|
|
|
if (newVersion && this.organization) {
|
2018-07-23 23:33:35 +02:00
|
|
|
this.moveFoldersToCollections(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
result.success = true;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|