2022-02-22 15:39:11 +01:00
|
|
|
import { ImportResult } from "../models/domain/importResult";
|
|
|
|
|
2018-07-18 05:47:28 +02:00
|
|
|
import { BaseImporter } from "./baseImporter";
|
|
|
|
import { Importer } from "./importer";
|
|
|
|
|
|
|
|
export class RoboFormCsvImporter extends BaseImporter implements Importer {
|
2020-12-05 03:05:11 +01:00
|
|
|
parse(data: string): Promise<ImportResult> {
|
2018-07-18 05:47:28 +02:00
|
|
|
const result = new ImportResult();
|
|
|
|
const results = this.parseCsv(data, true);
|
|
|
|
if (results == null) {
|
|
|
|
result.success = false;
|
2020-12-05 03:05:11 +01:00
|
|
|
return Promise.resolve(result);
|
2018-07-18 05:47:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
let i = 1;
|
2021-02-04 16:49:23 +01:00
|
|
|
results.forEach((value) => {
|
2018-07-23 23:37:32 +02:00
|
|
|
const folder =
|
2019-01-03 06:08:26 +01:00
|
|
|
!this.isNullOrWhitespace(value.Folder) && value.Folder.startsWith("/")
|
|
|
|
? value.Folder.replace("/", "")
|
|
|
|
: value.Folder;
|
2018-07-18 05:47:28 +02:00
|
|
|
const folderName = !this.isNullOrWhitespace(folder) ? folder : null;
|
|
|
|
this.processFolder(result, folderName);
|
|
|
|
|
|
|
|
const cipher = this.initLoginCipher();
|
|
|
|
cipher.notes = this.getValueOrDefault(value.Note);
|
|
|
|
cipher.name = this.getValueOrDefault(value.Name, "--");
|
|
|
|
cipher.login.username = this.getValueOrDefault(value.Login);
|
|
|
|
cipher.login.password = this.getValueOrDefault(value.Pwd);
|
|
|
|
cipher.login.uris = this.makeUriArray(value.Url);
|
2021-12-16 13:36:21 +01:00
|
|
|
|
2018-07-18 05:47:28 +02:00
|
|
|
if (!this.isNullOrWhitespace(value.Rf_fields)) {
|
|
|
|
let fields: string[] = [value.Rf_fields];
|
2019-01-03 06:08:26 +01:00
|
|
|
if (value.__parsed_extra != null && value.__parsed_extra.length > 0) {
|
2018-07-18 05:47:28 +02:00
|
|
|
fields = fields.concat(value.__parsed_extra);
|
|
|
|
}
|
2019-01-03 06:08:26 +01:00
|
|
|
fields.forEach((field: string) => {
|
|
|
|
const parts = field.split(":");
|
|
|
|
if (parts.length < 3) {
|
2021-12-16 13:36:21 +01:00
|
|
|
return;
|
|
|
|
}
|
2019-01-03 06:08:26 +01:00
|
|
|
const key = parts[0] === "-no-name-" ? null : parts[0];
|
|
|
|
const val = parts.length === 4 && parts[2] === "rck" ? parts[1] : parts[2];
|
|
|
|
this.processKvp(cipher, key, val);
|
2021-12-16 13:36:21 +01:00
|
|
|
});
|
|
|
|
}
|
2018-07-18 05:47:28 +02:00
|
|
|
|
|
|
|
this.convertToNoteIfNeeded(cipher);
|
|
|
|
this.cleanupCipher(cipher);
|
2021-12-16 13:36:21 +01:00
|
|
|
|
|
|
|
if (
|
2018-07-18 05:47:28 +02:00
|
|
|
i === results.length &&
|
|
|
|
cipher.name === "--" &&
|
|
|
|
this.isNullOrWhitespace(cipher.login.password)
|
2021-12-16 13:36:21 +01:00
|
|
|
) {
|
2020-12-05 03:05:11 +01:00
|
|
|
return;
|
2021-12-16 13:36:21 +01:00
|
|
|
}
|
|
|
|
|
2020-12-05 03:05:11 +01:00
|
|
|
result.ciphers.push(cipher);
|
2021-12-16 13:36:21 +01:00
|
|
|
i++;
|
|
|
|
});
|
|
|
|
|
2018-07-18 05:47:28 +02:00
|
|
|
if (this.organization) {
|
2020-12-05 03:05:11 +01:00
|
|
|
this.moveFoldersToCollections(result);
|
2018-07-18 05:47:28 +02:00
|
|
|
}
|
2021-12-16 13:36:21 +01:00
|
|
|
|
2018-07-18 05:47:28 +02:00
|
|
|
result.success = true;
|
|
|
|
return Promise.resolve(result);
|
2021-12-16 13:36:21 +01:00
|
|
|
}
|
2018-07-18 05:47:28 +02:00
|
|
|
}
|