mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-26 12:25:20 +01:00
Added Chrome csv importer. Adjustments to 1Password importer in preparation for detecting different formats.
This commit is contained in:
parent
8badc1a354
commit
b6c9dba0fc
@ -32,6 +32,9 @@
|
|||||||
case '1password1pif':
|
case '1password1pif':
|
||||||
import1Password1Pif(file, success, error);
|
import1Password1Pif(file, success, error);
|
||||||
break;
|
break;
|
||||||
|
case 'chromecsv':
|
||||||
|
importChromeCsv(file, success, error);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
error();
|
error();
|
||||||
break;
|
break;
|
||||||
@ -556,12 +559,18 @@
|
|||||||
reader.readAsText(file, 'utf-8');
|
reader.readAsText(file, 'utf-8');
|
||||||
reader.onload = function (evt) {
|
reader.onload = function (evt) {
|
||||||
var fileContent = evt.target.result;
|
var fileContent = evt.target.result;
|
||||||
var jsonParts = fileContent.split(/(?:\r\n|\r|\n)\*\*\*.*?\*\*\*(?:\r\n|\r|\n)/);
|
var fileLines = fileContent.split(/(?:\r\n|\r|\n)/);
|
||||||
var jsonString = '[' + jsonParts.join(',') + ']';
|
//var jsonParts = fileContent.split(/(?:\r\n|\r|\n)\*\*\*.*?\*\*\*(?:\r\n|\r|\n)/);
|
||||||
var items = JSON.parse(jsonString);
|
//var jsonString = '[' + jsonParts.join(',') + ']';
|
||||||
|
//var items = JSON.parse(jsonString);
|
||||||
|
|
||||||
for (i = 0; i < items.length; i++) {
|
for (i = 0; i < fileLines.length; i++) {
|
||||||
var item = items[i];
|
var line = fileLines[i];
|
||||||
|
if (!line.length || line[0] !== '{') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var item = JSON.parse(line);
|
||||||
if (item.typeName !== 'webforms.WebForm') {
|
if (item.typeName !== 'webforms.WebForm') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -576,7 +585,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (item.secureContents) {
|
if (item.secureContents) {
|
||||||
if (item.secureContents.notesPlain) {
|
if (item.secureContents.notesPlain && item.secureContents.notesPlain !== '') {
|
||||||
site.notes = item.secureContents.notesPlain;
|
site.notes = item.secureContents.notesPlain;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -614,5 +623,32 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function importChromeCsv(file, success, error) {
|
||||||
|
Papa.parse(file, {
|
||||||
|
header: true,
|
||||||
|
encoding: 'UTF-8',
|
||||||
|
complete: function (results) {
|
||||||
|
parseCsvErrors(results);
|
||||||
|
|
||||||
|
var folders = [],
|
||||||
|
sites = [],
|
||||||
|
siteRelationships = [];
|
||||||
|
|
||||||
|
angular.forEach(results.data, function (value, key) {
|
||||||
|
sites.push({
|
||||||
|
favorite: false,
|
||||||
|
uri: value.url && value.url !== '' ? trimUri(value.url) : null,
|
||||||
|
username: value.username && value.username !== '' ? value.username : null,
|
||||||
|
password: value.password && value.password !== '' ? value.password : null,
|
||||||
|
notes: null,
|
||||||
|
name: value.name && value.name !== '' ? value.name : '--',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
success(folders, sites, siteRelationships);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return _service;
|
return _service;
|
||||||
});
|
});
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
function importSuccess(folders, sites, folderRelationships) {
|
function importSuccess(folders, sites, folderRelationships) {
|
||||||
if (!folders.length && !sites.length) {
|
if (!folders.length && !sites.length) {
|
||||||
|
$uibModalInstance.dismiss('cancel');
|
||||||
toastr.error('Nothing was imported.');
|
toastr.error('Nothing was imported.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
<select id="source" name="source" class="form-control" ng-model="model.source">
|
<select id="source" name="source" class="form-control" ng-model="model.source">
|
||||||
<option value="local">bitwarden (csv)</option>
|
<option value="local">bitwarden (csv)</option>
|
||||||
<option value="lastpass">LastPass (csv)</option>
|
<option value="lastpass">LastPass (csv)</option>
|
||||||
|
<option value="chromecsv">Chrome (csv)</option>
|
||||||
<option value="safeincloudxml">SafeInCloud (xml)</option>
|
<option value="safeincloudxml">SafeInCloud (xml)</option>
|
||||||
<option value="safeincloudcsv">SafeInCloud (csv)</option>
|
<option value="safeincloudcsv">SafeInCloud (csv)</option>
|
||||||
<option value="keypassxml">KeyPass (xml)</option>
|
<option value="keypassxml">KeyPass (xml)</option>
|
||||||
|
Loading…
Reference in New Issue
Block a user