Skip to content

Commit

Permalink
Fallback to retrieve profiles during Firefox private browsing (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
tilfin committed Nov 7, 2023
1 parent a1f85d4 commit d9651fc
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/js/lib/target_profiles.js
@@ -1,6 +1,18 @@
import { ConfigParser } from "aesr-config";
import { DBManager } from "./db.js";
import { loadConfigIni } from "./config_ini";
import { StorageProvider } from "./storage_repository.js";

export async function findTargetProfiles(ctx) {
try {
return await retrieveTargetProfilesFromDB(ctx);
} catch (err) {
// Firefox private browsing
return await retriveTargetProfilesFromLztext(ctx);
}
}

async function retrieveTargetProfilesFromDB(ctx) {
const { baseAccount, loginRole, filterByTargetRole } = ctx;
const dbManager = new DBManager('aesr');
await dbManager.open();
Expand Down Expand Up @@ -44,3 +56,26 @@ function convertComplexTarget(item, baseProfile) {

return item
}

async function retrieveTargetProfilesFromLztext(ctx) {
const { baseAccount, loginRole, filterByTargetRole } = ctx;

const localRepo = StorageProvider.getLocalRepository();
const cfgText = await loadConfigIni(localRepo);
if (!cfgText) return [];

const profileSet = ConfigParser.parseIni(cfgText);

const results = [...profileSet.singles];

const matchedComplexSrc = profileSet.complexes.find(it => matchSourceProfile(it, baseAccount, loginRole));
if (matchedComplexSrc) {
let targets = matchedComplexSrc.targets;
if (filterByTargetRole) {
targets = targets.filter(it => it.role_name === filterByTargetRole);
}
results.push(...targets)
}

return results;
}

0 comments on commit d9651fc

Please sign in to comment.