mirror of
https://github.com/Nezumi-2711/cloudflare-gateway-pihole-scripts.git
synced 2026-09-22 13:38:37 +00:00
improve CI privacy features
This commit is contained in:
@@ -37,7 +37,7 @@ async function getZeroTrustLists() {
|
|||||||
wirefilter_expression = wirefilter_expression.slice(0, -4);
|
wirefilter_expression = wirefilter_expression.slice(0, -4);
|
||||||
}
|
}
|
||||||
wirefilter_expression = wirefilter_expression.trim().replace('\n', '');
|
wirefilter_expression = wirefilter_expression.trim().replace('\n', '');
|
||||||
console.log(`Firewall expression contains ${wirefilter_expression.length} characters, and checks against ${filtered_lists.length} filter lists.`)
|
if (!process.env.CI) console.log(`Firewall expression contains ${wirefilter_expression.length} characters, and checks against ${filtered_lists.length} filter lists.`)
|
||||||
|
|
||||||
const resp = await axios.request({
|
const resp = await axios.request({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ async function getZeroTrustRules() {
|
|||||||
|
|
||||||
if (!filtered_rule) return console.warn("No rule with matching name found - this is not an issue if you haven't run the create script yet. Exiting.");
|
if (!filtered_rule) return console.warn("No rule with matching name found - this is not an issue if you haven't run the create script yet. Exiting.");
|
||||||
|
|
||||||
console.log(`Deleting rule ` + process.env.CI ? "(redacted, running in CI)" : `${filtered_rule.name} with ID ${filtered_rule.id}`);
|
console.log(`Deleting rule`, process.env.CI ? "(redacted, running in CI)" : `${filtered_rule.name} with ID ${filtered_rule.id}`);
|
||||||
|
|
||||||
const resp = await axios.request({
|
const resp = await axios.request({
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
|
|||||||
+4
-4
@@ -7,7 +7,7 @@ const ACCOUNT_ID = process.env.CLOUDFLARE_ACCOUNT_ID;
|
|||||||
const ACCOUNT_EMAIL = process.env.CLOUDFLARE_ACCOUNT_EMAIL;
|
const ACCOUNT_EMAIL = process.env.CLOUDFLARE_ACCOUNT_EMAIL;
|
||||||
const LIST_ITEM_LIMIT = Number.isSafeInteger(Number(process.env.CLOUDFLARE_LIST_ITEM_LIMIT)) ? Number(process.env.CLOUDFLARE_LIST_ITEM_LIMIT) : 300000;
|
const LIST_ITEM_LIMIT = Number.isSafeInteger(Number(process.env.CLOUDFLARE_LIST_ITEM_LIMIT)) ? Number(process.env.CLOUDFLARE_LIST_ITEM_LIMIT) : 300000;
|
||||||
|
|
||||||
console.log(`List item limit set to ${LIST_ITEM_LIMIT}`);
|
if (!process.env.CI) console.log(`List item limit set to ${LIST_ITEM_LIMIT}`);
|
||||||
|
|
||||||
// Read input.csv and parse domains
|
// Read input.csv and parse domains
|
||||||
fs.readFile('input.csv', 'utf8', async (err, data) => {
|
fs.readFile('input.csv', 'utf8', async (err, data) => {
|
||||||
@@ -56,7 +56,7 @@ fs.readFile('input.csv', 'utf8', async (err, data) => {
|
|||||||
|
|
||||||
const listsToCreate = Math.ceil(domains.length / 1000);
|
const listsToCreate = Math.ceil(domains.length / 1000);
|
||||||
|
|
||||||
console.log(`Found ${domains.length} valid domains in input.csv after cleanup - ${listsToCreate} list(s) will be created`);
|
if (!process.env.CI) console.log(`Found ${domains.length} valid domains in input.csv after cleanup - ${listsToCreate} list(s) will be created`);
|
||||||
|
|
||||||
// Separate domains into chunks of 1000 (Cloudflare list cap)
|
// Separate domains into chunks of 1000 (Cloudflare list cap)
|
||||||
const chunks = chunkArray(domains, 1000);
|
const chunks = chunkArray(domains, 1000);
|
||||||
@@ -75,7 +75,7 @@ fs.readFile('input.csv', 'utf8', async (err, data) => {
|
|||||||
await createZeroTrustList(listName, properList, (index+1), listsToCreate);
|
await createZeroTrustList(listName, properList, (index+1), listsToCreate);
|
||||||
await sleep(350); // Sleep for 350ms between list additions
|
await sleep(350); // Sleep for 350ms between list additions
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error creating list ` + process.env.CI ? "(redacted on CI)" : `"${listName}": ${error.response.data}`);
|
console.error(`Error creating list `, process.env.CI ? "(redacted on CI)" : `"${listName}": ${error.response.data}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -119,7 +119,7 @@ async function createZeroTrustList(name, items, currentItem, totalItems) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const listId = response.data.result.id;
|
const listId = response.data.result.id;
|
||||||
console.log(`Created Zero Trust list ` + process.env.CI ? "(redacted on CI)" : `"${name}" with ID ${listId} - ${totalItems - currentItem} left`);
|
console.log(`Created Zero Trust list`, process.env.CI ? "(redacted on CI)" : `"${name}" with ID ${listId} - ${totalItems - currentItem} left`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function percentage(percent, total) {
|
function percentage(percent, total) {
|
||||||
|
|||||||
+2
-2
@@ -28,10 +28,10 @@ async function getZeroTrustLists() {
|
|||||||
const cgps_lists = lists.filter(list => list.name.startsWith('CGPS List'));
|
const cgps_lists = lists.filter(list => list.name.startsWith('CGPS List'));
|
||||||
if (!cgps_lists.length) return console.warn("No lists with matching name found - this is not an issue if you haven't created any filter lists before. Exiting.");
|
if (!cgps_lists.length) return console.warn("No lists with matching name found - this is not an issue if you haven't created any filter lists before. Exiting.");
|
||||||
|
|
||||||
console.log(`Got ${lists.length} lists, ${cgps_lists.length} of which are CGPS lists that will be deleted.`);
|
if (!process.env.CI) console.log(`Got ${lists.length} lists, ${cgps_lists.length} of which are CGPS lists that will be deleted.`);
|
||||||
|
|
||||||
for (const list of cgps_lists) {
|
for (const list of cgps_lists) {
|
||||||
console.log(`Deleting list ` + process.env.CI ? "(redacted, running in CI)" : `${list.name} with ID ${list.id}`);
|
console.log(`Deleting list`, process.env.CI ? "(redacted, running in CI)" : `${list.name} with ID ${list.id}`);
|
||||||
const resp = await axios.request({
|
const resp = await axios.request({
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
url: `https://api.cloudflare.com/client/v4/accounts/${ACCOUNT_ID}/gateway/lists/${list.id}`,
|
url: `https://api.cloudflare.com/client/v4/accounts/${ACCOUNT_ID}/gateway/lists/${list.id}`,
|
||||||
|
|||||||
Reference in New Issue
Block a user