feat: Enhance domain management and configuration in the extension

- Introduce default configuration settings for API key, domains database URL, update interval, and warning message template in background.js and options.js.
- Update domains database URL to a new source for improved reliability.
- Refactor domain management UI in domains_management.js to support adding, editing, and removing trusted and blocked domains with enhanced user experience.
- Implement search functionality for filtering domains in the management interface.
- Improve status messaging for user feedback during domain operations.
This commit is contained in:
becarta
2025-05-10 03:52:10 +02:00
parent f757b4585a
commit 87506ae85a
6 changed files with 260 additions and 63 deletions

View File

@@ -134,27 +134,59 @@ const healthCheck = {
}
};
// Default configuration
const DEFAULT_CONFIG = {
apiKey: '',
domainsDBURL: 'https://git.365devnet.eu/365DevNet/EnterpriseAppProtection/raw/branch/main/domains.json',
updateInterval: 24, // hours
warningTemplate: 'Warning: This link claims to be {app} but goes to an unofficial domain.',
lastUpdate: null,
suspiciousCount: 0,
suspiciousLinks: []
};
// Function to get configuration
async function getConfig() {
return new Promise((resolve) => {
chrome.storage.local.get([
"safeBrowsingApiKey",
"domainsDBURL",
"updateInterval",
"warningTemplate"
], (result) => {
resolve({
apiKey: result.safeBrowsingApiKey || DEFAULT_CONFIG.apiKey,
domainsDBURL: result.domainsDBURL || DEFAULT_CONFIG.domainsDBURL,
updateInterval: result.updateInterval || DEFAULT_CONFIG.updateInterval,
warningTemplate: result.warningTemplate || DEFAULT_CONFIG.warningTemplate
});
});
});
}
// Function to update last update timestamp
async function updateLastUpdate() {
await chrome.storage.local.set({ lastUpdate: Date.now() });
}
// Function to update domains database
async function updateDomainsDB() {
chrome.storage.local.get(["domainsDBURL"], async function (result) {
const domainsDBURL = result.domainsDBURL || "https://raw.githubusercontent.com/rrpbergsma/EnterpriseAppProtection/refs/heads/main/domains.json";
console.log("updateDomainsDB: Starting update from URL:", domainsDBURL);
try {
const response = await fetch(domainsDBURL);
if (!response.ok) {
console.error("updateDomainsDB: Fetch failed with status", response.status, response.statusText);
return;
}
domainsDB = await response.json();
chrome.storage.local.set({
domainsDB: domainsDB,
lastUpdate: Date.now()
}, () => {
console.log("updateDomainsDB: Database updated successfully at", new Date().toLocaleString());
});
const config = await getConfig();
console.log("Updating domains database from:", config.domainsDBURL);
const response = await fetch(config.domainsDBURL);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
await chrome.storage.local.set({ domainsDB: data });
await updateLastUpdate();
console.log('Domains database updated successfully');
return true;
} catch (error) {
console.error("updateDomainsDB: Failed to update domains database:", error);
console.error('Failed to update domains database:', error);
return false;
}
});
}
// Run updates when the extension is installed or started