2022-02-22 15:39:11 +01:00
|
|
|
import { ImportResult } from "../models/domain/importResult";
|
|
|
|
|
2018-07-23 23:33:35 +02:00
|
|
|
import { BaseImporter } from "./baseImporter";
|
|
|
|
import { Importer } from "./importer";
|
|
|
|
|
|
|
|
export class PasswordAgentCsvImporter extends BaseImporter implements Importer {
|
2020-12-05 03:05:11 +01:00
|
|
|
parse(data: string): Promise<ImportResult> {
|
2018-07-23 23:33:35 +02:00
|
|
|
const result = new ImportResult();
|
2019-08-02 15:51:00 +02:00
|
|
|
const results = this.parseCsv(data, false);
|
|
|
|
if (results == null) {
|
|
|
|
result.success = false;
|
2019-06-21 14:19:38 +02:00
|
|
|
return Promise.resolve(result);
|
|
|
|
}
|
2018-07-23 23:33:35 +02:00
|
|
|
|
2019-06-21 14:19:38 +02:00
|
|
|
let newVersion = true;
|
|
|
|
results.forEach((value) => {
|
|
|
|
if (value.length !== 5 && value.length < 9) {
|
2021-12-16 13:36:21 +01:00
|
|
|
return;
|
|
|
|
}
|
2019-06-21 14:19:38 +02:00
|
|
|
const altFormat = value.length === 10 && value[0] === "0";
|
|
|
|
const cipher = this.initLoginCipher();
|
2019-08-02 15:51:00 +02:00
|
|
|
cipher.name = this.getValueOrDefault(value[altFormat ? 1 : 0], "--");
|
|
|
|
cipher.login.username = this.getValueOrDefault(value[altFormat ? 2 : 1]);
|
|
|
|
cipher.login.password = this.getValueOrDefault(value[altFormat ? 3 : 2]);
|
2018-07-23 23:33:35 +02:00
|
|
|
if (value.length === 5) {
|
|
|
|
newVersion = false;
|
|
|
|
cipher.notes = this.getValueOrDefault(value[4]);
|
|
|
|
cipher.login.uris = this.makeUriArray(value[3]);
|
2021-12-16 13:36:21 +01:00
|
|
|
} else {
|
2018-07-23 23:33:35 +02:00
|
|
|
const folder = this.getValueOrDefault(value[altFormat ? 9 : 8], "(None)");
|
|
|
|
let folderName = folder !== "(None)" ? folder.split("\\").join("/") : null;
|
2019-08-02 15:51:00 +02:00
|
|
|
if (folderName != null) {
|
|
|
|
folderName = folder.split(" > ").join("/");
|
|
|
|
folderName = folder.split(">").join("/");
|
2018-07-23 23:33:35 +02:00
|
|
|
}
|
2019-06-21 14:19:38 +02:00
|
|
|
this.processFolder(result, folderName);
|
2019-08-02 15:51:00 +02:00
|
|
|
cipher.notes = this.getValueOrDefault(value[altFormat ? 5 : 3]);
|
2019-06-21 14:19:38 +02:00
|
|
|
cipher.login.uris = this.makeUriArray(value[4]);
|
2021-12-16 13:36:21 +01:00
|
|
|
}
|
2018-07-23 23:33:35 +02:00
|
|
|
this.convertToNoteIfNeeded(cipher);
|
|
|
|
this.cleanupCipher(cipher);
|
|
|
|
result.ciphers.push(cipher);
|
2021-12-16 13:36:21 +01:00
|
|
|
});
|
2018-07-23 23:33:35 +02:00
|
|
|
|
|
|
|
if (newVersion && this.organization) {
|
2020-12-05 03:05:11 +01:00
|
|
|
this.moveFoldersToCollections(result);
|
2018-07-23 23:33:35 +02:00
|
|
|
}
|
2021-12-16 13:36:21 +01:00
|
|
|
|
2018-07-23 23:33:35 +02:00
|
|
|
result.success = true;
|
2020-12-05 03:05:11 +01:00
|
|
|
return Promise.resolve(result);
|
2021-12-16 13:36:21 +01:00
|
|
|
}
|
2018-07-23 23:33:35 +02:00
|
|
|
}
|