1 Commits

2 changed files with 24 additions and 34 deletions

View File

@@ -450,7 +450,7 @@ async function fillFields(settings, login, fields) {
// build focus or submit request
let focusOrSubmitRequest = {
origin: new BrowserpassURL(settings.tab.url).origin,
autoSubmit: helpers.getSetting("autoSubmit", login, settings),
autoSubmit: getSetting("autoSubmit", login, settings),
filledFields: filledFields,
};
@@ -561,6 +561,25 @@ async function getFullSettings() {
return settings;
}
/**
* Get most relevant setting value
*
* @param string key Setting key
* @param object login Login object (or null)
* @param object settings Settings object
* @return object Setting value
*/
function getSetting(key, login, settings) {
if (login !== null && typeof login.settings[key] !== "undefined") {
return login.settings[key];
}
if (typeof settings.stores[login.store.id].settings[key] !== "undefined") {
return settings.stores[login.store.id].settings[key];
}
return settings[key];
}
/**
* Deep copy an object
*
@@ -724,7 +743,7 @@ async function handleMessage(settings, message, sendResponse) {
}
break;
case "copyOTP":
if (settings.enableOTP) {
if (getSetting("enableOTP", null, settings)) {
try {
if (!message.login.fields.otp) {
throw new Exception("No OTP seed available");
@@ -796,7 +815,7 @@ async function handleMessage(settings, message, sendResponse) {
// copy OTP token after fill
if (
settings.enableOTP &&
getSetting("enableOTP", null, settings) &&
typeof message.login !== "undefined" &&
message.login.fields.hasOwnProperty("otp")
) {
@@ -949,7 +968,7 @@ async function parseFields(settings, login) {
if (key === "secret" && lines.length) {
login.fields.secret = lines[0];
} else if (key === "login") {
const defaultUsername = helpers.getSetting("username", login, settings);
const defaultUsername = getSetting("username", login, settings);
login.fields[key] = defaultUsername || login.login.match(/([^\/]+)$/)[1];
} else {
delete login.fields[key];
@@ -963,7 +982,7 @@ async function parseFields(settings, login) {
}
// preprocess otp
if (settings.enableOTP && login.fields.hasOwnProperty("otp")) {
if (getSetting("enableOTP", null, settings) && login.fields.hasOwnProperty("otp")) {
if (login.fields.otp.match(/^otpauth:\/\/.+/i)) {
// attempt to parse otp data as URI
try {

View File

@@ -11,41 +11,12 @@ const BrowserpassURL = require("@browserpass/url");
module.exports = {
prepareLogins,
filterSortLogins,
getSetting,
ignoreFiles,
makeTOTP,
SettingScope,
};
const SettingScope = {
// query a setting first from the login, then the store, then globally
Login: "login",
// query a setting first from the store, then globally
Store: "store",
};
//----------------------------------- Function definitions ----------------------------------//
/**
* Get most relevant setting value
*
* @param string key Setting key
* @param object login Login object
* @param object settings Settings object
* @param string scope SettingScope value to specify where to search for the setting (optional)
* @return object Setting value
*/
function getSetting(key, login, settings, scope = SettingScope.Login) {
if (scope === SettingScope.Login && typeof login.settings[key] !== "undefined") {
return login.settings[key];
}
if (typeof settings.stores[login.store.id].settings[key] !== "undefined") {
return settings.stores[login.store.id].settings[key];
}
return settings[key];
}
/**
* Get the deepest available domain component of a path
*