1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-23 11:56:00 +01:00

Add importer for Passman (#13)

* Add importer for Passman

The importer reads JSON files generated by the Nextcloud app Passman.

The first tag is used as the folder name. This works well if passwords
have no or only one tag. If no username is set then the email address is
used as the username.

Files are not being imported.

* Fix indentation

* Remove unsettable revision date

* Fix tslint findings

* Add email to notes when there is also a username

If a username is set, that will become the username. Otherwise the email
will become the username.

If a username and an email is set the email will be added to the notes.
This commit is contained in:
ServiusHack 2018-10-08 21:41:32 +02:00 committed by Kyle Spearrin
parent 4b7962dc8f
commit 30a5257671
2 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,63 @@
import { BaseImporter } from './baseImporter';
import { Importer } from './importer';
import { ImportResult } from '../models/domain/importResult';
export class PassmanJsonImporter extends BaseImporter implements Importer {
parse(data: string): ImportResult {
const result = new ImportResult();
const results = JSON.parse(data);
if (results == null || results.length === 0) {
result.success = false;
return result;
}
results.forEach((credential: any) => {
if (credential.tags.length > 0) {
const folderName = credential.tags[0].text;
this.processFolder(result, folderName);
}
const cipher = this.initLoginCipher();
cipher.name = credential.label;
if (cipher.name.length > 30) {
cipher.name = cipher.name.substring(0, 30);
}
cipher.login.username = this.getValueOrDefault(credential.username);
if (cipher.login.username === null) {
cipher.login.username = this.getValueOrDefault(credential.email);
} else if (credential.email !== '') {
cipher.notes += 'E-Mail: ' + credential.email;
}
cipher.login.password = this.getValueOrDefault(credential.password);
cipher.login.uris = this.makeUriArray(credential.url);
cipher.notes = this.getValueOrDefault(credential.description);
if (credential.otp) {
cipher.login.totp = credential.otp.secret;
}
credential.custom_fields.forEach((customField: any) => {
switch (customField.field_type) {
case 'text':
case 'password':
this.processKvp(cipher, customField.label, customField.value);
break;
}
});
this.convertToNoteIfNeeded(cipher);
this.cleanupCipher(cipher);
result.ciphers.push(cipher);
});
if (this.organization) {
this.moveFoldersToCollections(result);
}
result.success = true;
return result;
}
}

View File

@ -41,6 +41,7 @@ import { OnePasswordWinCsvImporter } from '../importers/onepasswordWinCsvImporte
import { PadlockCsvImporter } from '../importers/padlockCsvImporter';
import { PassKeepCsvImporter } from '../importers/passkeepCsvImporter';
import { PasspackCsvImporter } from '../importers/passpackCsvImporter';
import { PassmanJsonImporter } from '../importers/passmanJsonImporter';
import { PasswordAgentCsvImporter } from '../importers/passwordAgentCsvImporter';
import { PasswordBossJsonImporter } from '../importers/passwordBossJsonImporter';
import { PasswordDragonXmlImporter } from '../importers/passwordDragonXmlImporter';
@ -95,6 +96,7 @@ export class ImportService implements ImportServiceAbstraction {
{ id: 'blurcsv', name: 'Blur (csv)' },
{ id: 'passwordagentcsv', name: 'Password Agent (csv)' },
{ id: 'passpackcsv', name: 'Passpack (csv)' },
{ id: 'passmanjson', name: 'Passman (json)' },
];
constructor(private cipherService: CipherService, private folderService: FolderService,
@ -211,6 +213,8 @@ export class ImportService implements ImportServiceAbstraction {
return new PasswordAgentCsvImporter();
case 'passpackcsv':
return new PasspackCsvImporter();
case 'passmanjson':
return new PassmanJsonImporter();
default:
return null;
}