1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-06 05:28:51 +02:00

update importer for firefox

This commit is contained in:
Kyle Spearrin 2018-05-11 08:04:21 -04:00
parent c326e03eb2
commit cd9a43f359
2 changed files with 37 additions and 71 deletions

View File

@ -40,8 +40,8 @@
case 'operacsv': case 'operacsv':
importChromeCsv(file, success, error); importChromeCsv(file, success, error);
break; break;
case 'firefoxpasswordexportercsvxml': case 'firefoxpasswordexportercsv':
importFirefoxPasswordExporterCsvXml(file, success, error); importFirefoxPasswordExporterCsv(file, success, error);
break; break;
case 'upmcsv': case 'upmcsv':
importUpmCsv(file, success, error); importUpmCsv(file, success, error);
@ -173,6 +173,12 @@
'ort', 'adresse' 'ort', 'adresse'
]; ];
function loginNameFromUrl(url) {
var a = document.createElement('a');
a.href = url;
return a.hostname.startsWith('www.') ? a.hostname.replace('www.', '') : a.hostname;
}
function isField(fieldText, refFieldValues) { function isField(fieldText, refFieldValues) {
if (!fieldText || fieldText === '') { if (!fieldText || fieldText === '') {
return false; return false;
@ -1484,65 +1490,34 @@
}); });
} }
function importFirefoxPasswordExporterCsvXml(file, success, error) { function importFirefoxPasswordExporterCsv(file, success, error) {
var folders = [], Papa.parse(file, {
ciphers = []; header: true,
encoding: 'UTF-8',
complete: function (results) {
parseCsvErrors(results);
function getNameFromHost(host) { var folders = [],
var name = '--'; ciphers = [];
try {
if (host && host !== '') {
var parser = document.createElement('a');
parser.href = host;
if (parser.hostname) {
name = parser.hostname;
}
}
}
catch (e) {
// do nothing
}
return name; angular.forEach(results.data, function (value, key) {
}
ciphers.push({
function parseXml(xmlDoc) { type: constants.cipherType.login,
var xml = $(xmlDoc); favorite: false,
notes: null,
var entries = xml.find('entry'); name: value.hostname && value.hostname !== '' ? loginNameFromUrl(value.hostname) : '--',
for (var i = 0; i < entries.length; i++) { login: {
var entry = $(entries[i]); uris: makeUriArray(value.hostname),
if (!entry) { username: value.username && value.username !== '' ? value.username : null,
continue; password: value.password && value.password !== '' ? value.password : null
} }
});
var host = entry.attr('host'),
user = entry.attr('user'),
password = entry.attr('password');
ciphers.push({
type: constants.cipherType.login,
favorite: false,
notes: null,
name: getNameFromHost(host),
login: {
uris: makeUriArray(host),
username: user && user !== '' ? user : null,
password: password && password !== '' ? password : null,
}
}); });
success(folders, ciphers, []);
} }
});
success(folders, ciphers, []);
}
if (file.type && file.type === 'text/xml') {
getXmlFileContents(file, parseXml, error);
}
else {
error('Only .xml exports are supported.');
return;
}
} }
function importUpmCsv(file, success, error) { function importUpmCsv(file, success, error) {
@ -2601,12 +2576,6 @@
} }
function importSaferPassCsv(file, success, error) { function importSaferPassCsv(file, success, error) {
function urlDomain(data) {
var a = document.createElement('a');
a.href = data;
return a.hostname.startsWith('www.') ? a.hostname.replace('www.', '') : a.hostname;
}
var folders = [], var folders = [],
ciphers = []; ciphers = [];
@ -2621,7 +2590,7 @@
type: constants.cipherType.login, type: constants.cipherType.login,
favorite: false, favorite: false,
notes: value.notes && value.notes !== '' ? value.notes : null, notes: value.notes && value.notes !== '' ? value.notes : null,
name: value.url && value.url !== '' ? urlDomain(value.url) : '--', name: value.url && value.url !== '' ? loginNameFromUrl(value.url) : '--',
login: { login: {
uris: makeUriArray(value.url), uris: makeUriArray(value.url),
username: value.username && value.username !== '' ? value.username : null, username: value.username && value.username !== '' ? value.username : null,

View File

@ -36,16 +36,13 @@
'https://help.bitwarden.com/article/import-from-chrome/</a>') 'https://help.bitwarden.com/article/import-from-chrome/</a>')
}, },
{ {
id: 'firefoxpasswordexportercsvxml', id: 'firefoxpasswordexportercsv',
name: 'Firefox Password Exporter (xml)', name: 'Firefox Password Exporter (csv)',
featured: true, featured: true,
sort: 4, sort: 4,
instructions: $sce.trustAsHtml('Use the ' + instructions: $sce.trustAsHtml('Use the ' +
'<a target="_blank" href="https://addons.mozilla.org/en-US/firefox/addon/password-exporter/">' + '<a target="_blank" href="https://github.com/kspearrin/ff-password-exporter#ff-password-exporter">' +
'Password Exporter</a> addon for FireFox to export your passwords to a XML file. After installing ' + 'FF Password Exporter</a> application to export your passwords to a CSV file.')
'the addon, type <code>about:addons</code> in your FireFox navigation bar. Locate the Password Exporter ' +
'addon and click the "Options" button. In the dialog that pops up, click the "Export Passwords" button ' +
'to save the XML file.')
}, },
{ {
id: 'keepass2xml', id: 'keepass2xml',