forked from mrrfv/cloudflare-gateway-pihole-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcf_gateway_rule_delete.js
More file actions
30 lines (25 loc) · 1.04 KB
/
cf_gateway_rule_delete.js
File metadata and controls
30 lines (25 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { deleteZeroTrustRule, getZeroTrustRules } from "./lib/api.js";
import { DELETION_ENABLED } from "./lib/constants.js";
import { notifyWebhook } from "./lib/utils.js";
if (!DELETION_ENABLED) {
console.warn(
"The rule deletion step is no longer needed to update filter lists, safely skipping. To proceed with deletion to e.g. stop using CGPS, set the environment variable CGPS_DELETION_ENABLED=true and re-run the script. Exiting."
);
process.exit(0);
}
const { result: rules } = await getZeroTrustRules();
const cgpsRules = rules.filter(({ name }) => name.startsWith("CGPS Filter Lists"));
(async () => {
if (!cgpsRules.length) {
console.warn(
"No rule(s) with matching name found - this is not an issue if you haven't run the create script yet. Exiting."
);
return;
}
for (const cgpsRule of cgpsRules) {
console.log(`Deleting rule ${cgpsRule.name}...`);
await deleteZeroTrustRule(cgpsRule.id);
}
})();
// Send a notification to the webhook
await notifyWebhook("CF Gateway Rule Delete script finished running");