restore: apply blocklist

This commit is contained in:
Girish Ramakrishnan
2026-03-10 21:34:09 +05:30
parent df96df776d
commit 77022bbd7f
2 changed files with 12 additions and 5 deletions
+11 -5
View File
@@ -56,6 +56,15 @@ async function getBlocklist() {
return value ? value.toString('utf8') : '';
}
async function applyBlocklist() {
const blocklist = await getBlocklist();
if (!safe.fs.writeFileSync(paths.FIREWALL_BLOCKLIST_FILE, blocklist + '\n', 'utf8')) throw new BoxError(BoxError.FS_ERROR, safe.error.message);
const [error] = await safe(shell.sudo([ SET_BLOCKLIST_CMD ], {}));
if (error) throw new BoxError(BoxError.IPTABLES_ERROR, `Error setting blocklist: ${error.message}`);
}
async function setBlocklist(blocklist, auditSource) {
assert.strictEqual(typeof blocklist, 'string');
assert.strictEqual(typeof auditSource, 'object');
@@ -84,11 +93,7 @@ async function setBlocklist(blocklist, auditSource) {
// store in blob since the value field is TEXT and has 16kb size limit
await settings.setBlob(settings.FIREWALL_BLOCKLIST_KEY, Buffer.from(blocklist));
// this is done only because it's easier for the shell script and the firewall service to get the value
if (!safe.fs.writeFileSync(paths.FIREWALL_BLOCKLIST_FILE, blocklist + '\n', 'utf8')) throw new BoxError(BoxError.FS_ERROR, safe.error.message);
const [error] = await safe(shell.sudo([ SET_BLOCKLIST_CMD ], {}));
if (error) throw new BoxError(BoxError.IPTABLES_ERROR, `Error setting blocklist: ${error.message}`);
await applyBlocklist();
}
async function getDynamicDns() {
@@ -189,6 +194,7 @@ export default {
testIPv4Config,
testIPv6Config,
applyBlocklist,
getBlocklist,
setBlocklist,