From 22785b06e895a9c60709570f470511afd8c6752f Mon Sep 17 00:00:00 2001 From: Norbert Date: Sun, 14 May 2023 22:01:39 +0200 Subject: [PATCH 01/24] whitelist --- cf_list_create.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/cf_list_create.js b/cf_list_create.js index 64535e6..32992be 100644 --- a/cf_list_create.js +++ b/cf_list_create.js @@ -9,6 +9,34 @@ const LIST_ITEM_LIMIT = Number.isSafeInteger(Number(process.env.CLOUDFLARE_LIST_ if (!process.env.CI) console.log(`List item limit set to ${LIST_ITEM_LIMIT}`); + +// Read whitelist.csv and parse +fs.readFile('whitelist.csv', 'utf8', async (err, data) => { + if (err) { + console.error('Error reading whitelist.csv:', err); + return; + } + + // Convert into array and cleanup whitelist + const domainValidationPattern = /^(?!-)[A-Za-z0-9-]+([\-\.]{1}[a-z0-9]+)*\.[A-Za-z]{2,6}$/; + let whitelist = data.split('\n').filter(domain => { + // Remove entire lines starting with "127.0.0.1" or "::1", empty lines or comments + return domain && !domain.startsWith('#') && !domain.startsWith('//') && !domain.startsWith('/*') && !domain.startsWith('*/') && !(domain === '\r'); + }).map(domain => { + // Remove "\r", "0.0.0.0 ", "127.0.0.1 ", "::1 " and similar from domain items + return domain + .replace('\r', '') + .replace('0.0.0.0 ', '') + .replace('127.0.0.1 ', '') + .replace('::1 ', '') + .replace(':: ', ''); + }).filter(domain => { + return domainValidationPattern.test(domain); + }); + +}); + + // Read input.csv and parse domains fs.readFile('input.csv', 'utf8', async (err, data) => { if (err) { @@ -33,6 +61,12 @@ fs.readFile('input.csv', 'utf8', async (err, data) => { return domainValidationPattern.test(domain); }); + // Remove domains from the domains array that are present in the whitelist array + const whitelist = whitelist + domains = domains.filter(domain => { + return !whitelist.includes(domain); + }); + // Trim array to 300,000 domains if it's longer than that if (domains.length > LIST_ITEM_LIMIT) { domains = trimArray(domains, LIST_ITEM_LIMIT); @@ -130,3 +164,4 @@ function percentage(percent, total) { function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } + From dd97ff6cd409fe42a248a73f5235efc92934dbde Mon Sep 17 00:00:00 2001 From: Norbert Date: Sun, 14 May 2023 22:03:27 +0200 Subject: [PATCH 02/24] test whitelist --- get_recommended_whitelist.sh | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 get_recommended_whitelist.sh diff --git a/get_recommended_whitelist.sh b/get_recommended_whitelist.sh new file mode 100644 index 0000000..8d04176 --- /dev/null +++ b/get_recommended_whitelist.sh @@ -0,0 +1,49 @@ +#!/bin/bash +# https://oisd.nl/includedlists/whitelists +# create an empty whitelist.csv file +touch whitelist.csv + +# declare an array of urls +urls=( + + # https://raw.githubusercontent.com/im-sm/Pi-hole-Torrent-Blocklist/main/all-torrent-trackres.txt + # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/banks.txt + # https://raw.githubusercontent.com/hagezi/dns-blocklists/main/whitelist.txt + # https://raw.githubusercontent.com/TogoFire-Home/AD-Settings/main/Filters/whitelist.txt + # https://raw.githubusercontent.com/freekers/whitelist/master/domains/whitelist.txt + # https://raw.githubusercontent.com/DandelionSprout/AdGuard-Home-Whitelist/master/whitelist.txt + # https://www.aadvantageeshopping.com/adBlockWhitelist.php + # https://raw.githubusercontent.com/AdguardTeam/AdGuardSDNSFilter/master/Filters/exclusions.txt + # https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/optional-list.txt + # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/issues.txt + # https://raw.githubusercontent.com/hagezi/dns-blocklists/main/whitelist-referral.txt + # https://raw.githubusercontent.com/mawenjian/china-cdn-domain-whitelist/master/china-cdn-domain-whitelist.txt + # https://raw.githubusercontent.com/notracking/hosts-blocklists-scripts/master/hostnames.whitelist.txt + # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/mac.txt + # https://raw.githubusercontent.com/boutetnico/url-shorteners/master/list.txt + # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/windows.txt + # https://raw.githubusercontent.com/Dogino/Discord-Phishing-URLs/main/official-domains.txt + # https://raw.githubusercontent.com/ookangzheng/blahdns/master/hosts/whitelist.txt + # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/android.txt + # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/sensitive.txt + # https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/whitelist.txt + # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/firefox.txt + # https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/referral-sites.txt + +) + +# loop through the urls and download each file with curl +for url in "${urls[@]}"; do + # get the file name from the url + file=$(basename "$url") + # download the file with curl and save it as file.txt + curl -o "$file.txt" "$url" + # append the file contents to whitelist.csv and add a newline + cat "$file.txt" >> whitelist.csv + echo "" >> whitelist.csv + # remove the file.txt + rm "$file.txt" +done + +# print a message when done +echo "Done. The whitelist.csv file contains merged data from recommended whitelist." From 4de9403d31832e172e1e0b1701f63777dc71c040 Mon Sep 17 00:00:00 2001 From: Norbert Date: Sun, 14 May 2023 22:03:40 +0200 Subject: [PATCH 03/24] hup --- hup.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 hup.txt diff --git a/hup.txt b/hup.txt new file mode 100644 index 0000000..283df7f --- /dev/null +++ b/hup.txt @@ -0,0 +1 @@ +hup.hu \ No newline at end of file From acb2fbc12137f9dbdd81d3a03093eb534e62fe52 Mon Sep 17 00:00:00 2001 From: Norbert Date: Sun, 14 May 2023 22:05:09 +0200 Subject: [PATCH 04/24] hup --- get_recommended_whitelist.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/get_recommended_whitelist.sh b/get_recommended_whitelist.sh index 8d04176..81f116d 100644 --- a/get_recommended_whitelist.sh +++ b/get_recommended_whitelist.sh @@ -5,7 +5,7 @@ touch whitelist.csv # declare an array of urls urls=( - + https://raw.githubusercontent.com/norbertjoni/cloudflare-gateway-pihole-scripts/main/hup.txt # https://raw.githubusercontent.com/im-sm/Pi-hole-Torrent-Blocklist/main/all-torrent-trackres.txt # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/banks.txt # https://raw.githubusercontent.com/hagezi/dns-blocklists/main/whitelist.txt From d87649485203421fa974a4474334c8efd836e4ba Mon Sep 17 00:00:00 2001 From: Norbert Date: Sun, 14 May 2023 22:09:09 +0200 Subject: [PATCH 05/24] ubuntu --- ubuntu.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 ubuntu.txt diff --git a/ubuntu.txt b/ubuntu.txt new file mode 100644 index 0000000..6e6d1c7 --- /dev/null +++ b/ubuntu.txt @@ -0,0 +1 @@ +ubuntu.hu \ No newline at end of file From b497c1d8306de92be4ea8ab6956d737e51360f8b Mon Sep 17 00:00:00 2001 From: Norbert Date: Sun, 14 May 2023 22:11:02 +0200 Subject: [PATCH 06/24] test --- get_recommended_filters.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/get_recommended_filters.sh b/get_recommended_filters.sh index 9e0d28c..44a50c9 100644 --- a/get_recommended_filters.sh +++ b/get_recommended_filters.sh @@ -5,13 +5,15 @@ touch input.csv # declare an array of urls urls=( - https://raw.githubusercontent.com/mullvad/dns-blocklists/main/output/doh/doh_adblock.txt - https://raw.githubusercontent.com/mullvad/dns-blocklists/main/output/doh/doh_gambling.txt - https://raw.githubusercontent.com/mullvad/dns-blocklists/main/output/doh/doh_privacy.txt - https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Risk/hosts - https://raw.githubusercontent.com/DandelionSprout/adfilt/master/Alternate%20versions%20Anti-Malware%20List/AntiMalwareHosts.txt - https://adaway.org/hosts.txt - https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts + https://raw.githubusercontent.com/norbertjoni/cloudflare-gateway-pihole-scripts/main/ubuntu.txt + https://raw.githubusercontent.com/norbertjoni/cloudflare-gateway-pihole-scripts/main/hup.txt + # https://raw.githubusercontent.com/mullvad/dns-blocklists/main/output/doh/doh_adblock.txt + # https://raw.githubusercontent.com/mullvad/dns-blocklists/main/output/doh/doh_gambling.txt + # https://raw.githubusercontent.com/mullvad/dns-blocklists/main/output/doh/doh_privacy.txt + # https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Risk/hosts + # https://raw.githubusercontent.com/DandelionSprout/adfilt/master/Alternate%20versions%20Anti-Malware%20List/AntiMalwareHosts.txt + # https://adaway.org/hosts.txt + # https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts ) # loop through the urls and download each file with curl From 3d456499a8b3d6355e2b33b310197bd4463c6946 Mon Sep 17 00:00:00 2001 From: Norbert Date: Sun, 14 May 2023 22:18:47 +0200 Subject: [PATCH 07/24] const --- auto_update_github_action.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/auto_update_github_action.yml b/auto_update_github_action.yml index 5ab8301..fc6ef34 100644 --- a/auto_update_github_action.yml +++ b/auto_update_github_action.yml @@ -30,6 +30,10 @@ jobs: - name: Download recommended filters run: bash ./get_recommended_filters.sh working-directory: cloudflare-gateway-pihole-scripts + + - name: Download recommended whitelist + run: bash ./get_recommended_whitelist.sh + working-directory: cloudflare-gateway-pihole-scripts - name: Delete old rules and lists run: | From 0783c539b6d8bae6826cf475f3b57523129ee9cf Mon Sep 17 00:00:00 2001 From: Norbert Date: Sun, 14 May 2023 22:21:50 +0200 Subject: [PATCH 08/24] ? --- cf_list_create.js | 1 - 1 file changed, 1 deletion(-) diff --git a/cf_list_create.js b/cf_list_create.js index 32992be..c407ddc 100644 --- a/cf_list_create.js +++ b/cf_list_create.js @@ -62,7 +62,6 @@ fs.readFile('input.csv', 'utf8', async (err, data) => { }); // Remove domains from the domains array that are present in the whitelist array - const whitelist = whitelist domains = domains.filter(domain => { return !whitelist.includes(domain); }); From b14c11c1ccedb3b6fcd711c74f3d79a1c7b4e299 Mon Sep 17 00:00:00 2001 From: Norbert Date: Sun, 14 May 2023 22:34:23 +0200 Subject: [PATCH 09/24] let whitelist = []; --- cf_list_create.js | 1 + 1 file changed, 1 insertion(+) diff --git a/cf_list_create.js b/cf_list_create.js index c407ddc..af7180a 100644 --- a/cf_list_create.js +++ b/cf_list_create.js @@ -9,6 +9,7 @@ const LIST_ITEM_LIMIT = Number.isSafeInteger(Number(process.env.CLOUDFLARE_LIST_ if (!process.env.CI) console.log(`List item limit set to ${LIST_ITEM_LIMIT}`); +let whitelist = []; // Read whitelist.csv and parse fs.readFile('whitelist.csv', 'utf8', async (err, data) => { From bd8422597db43b9333d0afffb7b7782ffa699f50 Mon Sep 17 00:00:00 2001 From: Norbert Date: Sun, 14 May 2023 22:36:44 +0200 Subject: [PATCH 10/24] list --- get_recommended_filters.sh | 16 ++++++------ get_recommended_whitelist.sh | 47 ++++++++++++++++++------------------ 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/get_recommended_filters.sh b/get_recommended_filters.sh index 44a50c9..9e0d28c 100644 --- a/get_recommended_filters.sh +++ b/get_recommended_filters.sh @@ -5,15 +5,13 @@ touch input.csv # declare an array of urls urls=( - https://raw.githubusercontent.com/norbertjoni/cloudflare-gateway-pihole-scripts/main/ubuntu.txt - https://raw.githubusercontent.com/norbertjoni/cloudflare-gateway-pihole-scripts/main/hup.txt - # https://raw.githubusercontent.com/mullvad/dns-blocklists/main/output/doh/doh_adblock.txt - # https://raw.githubusercontent.com/mullvad/dns-blocklists/main/output/doh/doh_gambling.txt - # https://raw.githubusercontent.com/mullvad/dns-blocklists/main/output/doh/doh_privacy.txt - # https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Risk/hosts - # https://raw.githubusercontent.com/DandelionSprout/adfilt/master/Alternate%20versions%20Anti-Malware%20List/AntiMalwareHosts.txt - # https://adaway.org/hosts.txt - # https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts + https://raw.githubusercontent.com/mullvad/dns-blocklists/main/output/doh/doh_adblock.txt + https://raw.githubusercontent.com/mullvad/dns-blocklists/main/output/doh/doh_gambling.txt + https://raw.githubusercontent.com/mullvad/dns-blocklists/main/output/doh/doh_privacy.txt + https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Risk/hosts + https://raw.githubusercontent.com/DandelionSprout/adfilt/master/Alternate%20versions%20Anti-Malware%20List/AntiMalwareHosts.txt + https://adaway.org/hosts.txt + https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts ) # loop through the urls and download each file with curl diff --git a/get_recommended_whitelist.sh b/get_recommended_whitelist.sh index 81f116d..95e61f8 100644 --- a/get_recommended_whitelist.sh +++ b/get_recommended_whitelist.sh @@ -5,30 +5,29 @@ touch whitelist.csv # declare an array of urls urls=( - https://raw.githubusercontent.com/norbertjoni/cloudflare-gateway-pihole-scripts/main/hup.txt - # https://raw.githubusercontent.com/im-sm/Pi-hole-Torrent-Blocklist/main/all-torrent-trackres.txt - # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/banks.txt - # https://raw.githubusercontent.com/hagezi/dns-blocklists/main/whitelist.txt - # https://raw.githubusercontent.com/TogoFire-Home/AD-Settings/main/Filters/whitelist.txt - # https://raw.githubusercontent.com/freekers/whitelist/master/domains/whitelist.txt - # https://raw.githubusercontent.com/DandelionSprout/AdGuard-Home-Whitelist/master/whitelist.txt - # https://www.aadvantageeshopping.com/adBlockWhitelist.php - # https://raw.githubusercontent.com/AdguardTeam/AdGuardSDNSFilter/master/Filters/exclusions.txt - # https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/optional-list.txt - # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/issues.txt - # https://raw.githubusercontent.com/hagezi/dns-blocklists/main/whitelist-referral.txt - # https://raw.githubusercontent.com/mawenjian/china-cdn-domain-whitelist/master/china-cdn-domain-whitelist.txt - # https://raw.githubusercontent.com/notracking/hosts-blocklists-scripts/master/hostnames.whitelist.txt - # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/mac.txt - # https://raw.githubusercontent.com/boutetnico/url-shorteners/master/list.txt - # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/windows.txt - # https://raw.githubusercontent.com/Dogino/Discord-Phishing-URLs/main/official-domains.txt - # https://raw.githubusercontent.com/ookangzheng/blahdns/master/hosts/whitelist.txt - # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/android.txt - # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/sensitive.txt - # https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/whitelist.txt - # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/firefox.txt - # https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/referral-sites.txt + https://raw.githubusercontent.com/im-sm/Pi-hole-Torrent-Blocklist/main/all-torrent-trackres.txt + https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/banks.txt + https://raw.githubusercontent.com/hagezi/dns-blocklists/main/whitelist.txt + https://raw.githubusercontent.com/TogoFire-Home/AD-Settings/main/Filters/whitelist.txt + https://raw.githubusercontent.com/freekers/whitelist/master/domains/whitelist.txt + https://raw.githubusercontent.com/DandelionSprout/AdGuard-Home-Whitelist/master/whitelist.txt + https://www.aadvantageeshopping.com/adBlockWhitelist.php + https://raw.githubusercontent.com/AdguardTeam/AdGuardSDNSFilter/master/Filters/exclusions.txt + https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/optional-list.txt + https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/issues.txt + https://raw.githubusercontent.com/hagezi/dns-blocklists/main/whitelist-referral.txt + https://raw.githubusercontent.com/mawenjian/china-cdn-domain-whitelist/master/china-cdn-domain-whitelist.txt + https://raw.githubusercontent.com/notracking/hosts-blocklists-scripts/master/hostnames.whitelist.txt + https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/mac.txt + https://raw.githubusercontent.com/boutetnico/url-shorteners/master/list.txt + https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/windows.txt + https://raw.githubusercontent.com/Dogino/Discord-Phishing-URLs/main/official-domains.txt + https://raw.githubusercontent.com/ookangzheng/blahdns/master/hosts/whitelist.txt + https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/android.txt + https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/sensitive.txt + https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/whitelist.txt + https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/firefox.txt + https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/referral-sites.txt ) From 50375c73cb429e98d8c81c7b19fbb47243ac0581 Mon Sep 17 00:00:00 2001 From: Norbert Date: Sun, 14 May 2023 22:43:49 +0200 Subject: [PATCH 11/24] .replace('||', '') .replace('^', '') --- cf_list_create.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cf_list_create.js b/cf_list_create.js index af7180a..420d6bd 100644 --- a/cf_list_create.js +++ b/cf_list_create.js @@ -9,7 +9,7 @@ const LIST_ITEM_LIMIT = Number.isSafeInteger(Number(process.env.CLOUDFLARE_LIST_ if (!process.env.CI) console.log(`List item limit set to ${LIST_ITEM_LIMIT}`); -let whitelist = []; + // Read whitelist.csv and parse fs.readFile('whitelist.csv', 'utf8', async (err, data) => { @@ -30,7 +30,9 @@ fs.readFile('whitelist.csv', 'utf8', async (err, data) => { .replace('0.0.0.0 ', '') .replace('127.0.0.1 ', '') .replace('::1 ', '') - .replace(':: ', ''); + .replace(':: ', '') + .replace('||', '') + .replace('^', ''); }).filter(domain => { return domainValidationPattern.test(domain); }); From 7ed92ac1a66f1d8a1089ce8f4b960d14879edb29 Mon Sep 17 00:00:00 2001 From: Norbert Date: Sun, 14 May 2023 22:50:13 +0200 Subject: [PATCH 12/24] let whitelist = []; // Define an empty array for the whitelist --- cf_list_create.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cf_list_create.js b/cf_list_create.js index 420d6bd..f6057e3 100644 --- a/cf_list_create.js +++ b/cf_list_create.js @@ -9,6 +9,8 @@ const LIST_ITEM_LIMIT = Number.isSafeInteger(Number(process.env.CLOUDFLARE_LIST_ if (!process.env.CI) console.log(`List item limit set to ${LIST_ITEM_LIMIT}`); +let whitelist = []; // Define an empty array for the whitelist + // Read whitelist.csv and parse From 10fd1fd439cd5446b472d398d23dd1033c1c971e Mon Sep 17 00:00:00 2001 From: Norbert Date: Sun, 14 May 2023 23:06:36 +0200 Subject: [PATCH 13/24] ^$important --- cf_list_create.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cf_list_create.js b/cf_list_create.js index f6057e3..1945b4a 100644 --- a/cf_list_create.js +++ b/cf_list_create.js @@ -34,6 +34,8 @@ fs.readFile('whitelist.csv', 'utf8', async (err, data) => { .replace('::1 ', '') .replace(':: ', '') .replace('||', '') + .replace('@@||', '') + .replace('^$important', '') .replace('^', ''); }).filter(domain => { return domainValidationPattern.test(domain); From d965525b66043ee0103a81dc68fb1b995b846507 Mon Sep 17 00:00:00 2001 From: Norbert Date: Sun, 14 May 2023 23:39:31 +0200 Subject: [PATCH 14/24] fix --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0562bc9..a8163bf 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ Cloudflare Gateway allows you to create custom rules to filter HTTP, DNS, and ne 2. Cloudflare [Zero Trust](https://one.dash.cloudflare.com/) account - the Free plan is enough. Use the Cloudflare [documentation](https://developers.cloudflare.com/cloudflare-one/) for details. 3. Cloudflare email, API key (NOT the API token), and account ID 4. A file containing the domains you want to block - **max 300,000 domains for the free plan** - in the working directory named `input.csv`. Mullvad provides awesome [DNS blocklists](https://github.com/mullvad/dns-blocklists) that work well with this project. A bash script that downloads recommended blocklists, `get_recommended_filters.sh`, is included. +5. Optional: You can add whitlelist domains to the `get_reccomended_whitelist.sh` if you wish. ### Running locally From 7e37946e8b51171b2be1c888d07db1b3dc90f936 Mon Sep 17 00:00:00 2001 From: Norbert Date: Sun, 14 May 2023 23:40:02 +0200 Subject: [PATCH 15/24] fix --- hup.txt | 1 - ubuntu.txt | 1 - 2 files changed, 2 deletions(-) delete mode 100644 hup.txt delete mode 100644 ubuntu.txt diff --git a/hup.txt b/hup.txt deleted file mode 100644 index 283df7f..0000000 --- a/hup.txt +++ /dev/null @@ -1 +0,0 @@ -hup.hu \ No newline at end of file diff --git a/ubuntu.txt b/ubuntu.txt deleted file mode 100644 index 6e6d1c7..0000000 --- a/ubuntu.txt +++ /dev/null @@ -1 +0,0 @@ -ubuntu.hu \ No newline at end of file From 1b6460fcd895b269dd1b42f037886e7f633a6caa Mon Sep 17 00:00:00 2001 From: Norbert Date: Sun, 14 May 2023 23:43:53 +0200 Subject: [PATCH 16/24] fix up --- README.md | 2 +- auto_update_github_action.yml | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a8163bf..5da0017 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Cloudflare Gateway allows you to create custom rules to filter HTTP, DNS, and ne 2. Cloudflare [Zero Trust](https://one.dash.cloudflare.com/) account - the Free plan is enough. Use the Cloudflare [documentation](https://developers.cloudflare.com/cloudflare-one/) for details. 3. Cloudflare email, API key (NOT the API token), and account ID 4. A file containing the domains you want to block - **max 300,000 domains for the free plan** - in the working directory named `input.csv`. Mullvad provides awesome [DNS blocklists](https://github.com/mullvad/dns-blocklists) that work well with this project. A bash script that downloads recommended blocklists, `get_recommended_filters.sh`, is included. -5. Optional: You can add whitlelist domains to the `get_reccomended_whitelist.sh` if you wish. +5. Optional: You can add whitelist domains to the `get_reccomended_whitelist.sh` if you wish. ### Running locally diff --git a/auto_update_github_action.yml b/auto_update_github_action.yml index fc6ef34..16c17d6 100644 --- a/auto_update_github_action.yml +++ b/auto_update_github_action.yml @@ -26,14 +26,13 @@ jobs: - name: Install npm dependencies run: npm ci working-directory: cloudflare-gateway-pihole-scripts - - - name: Download recommended filters - run: bash ./get_recommended_filters.sh - working-directory: cloudflare-gateway-pihole-scripts - - name: Download recommended whitelist run: bash ./get_recommended_whitelist.sh working-directory: cloudflare-gateway-pihole-scripts + + - name: Download recommended filters + run: bash ./get_recommended_filters.sh + working-directory: cloudflare-gateway-pihole-scripts - name: Delete old rules and lists run: | From a20b8ffb9ee7ebb731aab1b45bd58c65d432bbaa Mon Sep 17 00:00:00 2001 From: Norbert Date: Sun, 14 May 2023 23:45:30 +0200 Subject: [PATCH 17/24] fix --- auto_update_github_action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/auto_update_github_action.yml b/auto_update_github_action.yml index 16c17d6..747b937 100644 --- a/auto_update_github_action.yml +++ b/auto_update_github_action.yml @@ -26,6 +26,7 @@ jobs: - name: Install npm dependencies run: npm ci working-directory: cloudflare-gateway-pihole-scripts + - name: Download recommended whitelist run: bash ./get_recommended_whitelist.sh working-directory: cloudflare-gateway-pihole-scripts From 743583fe4c00fd229dc709dbdbaaaf90a497f535 Mon Sep 17 00:00:00 2001 From: Norbert Date: Mon, 15 May 2023 00:06:19 +0200 Subject: [PATCH 18/24] fixup --- cf_list_create.js | 6 ++--- get_recommended_whitelist.sh | 48 +++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/cf_list_create.js b/cf_list_create.js index 1945b4a..fc87b6a 100644 --- a/cf_list_create.js +++ b/cf_list_create.js @@ -11,8 +11,6 @@ if (!process.env.CI) console.log(`List item limit set to ${LIST_ITEM_LIMIT}`); let whitelist = []; // Define an empty array for the whitelist - - // Read whitelist.csv and parse fs.readFile('whitelist.csv', 'utf8', async (err, data) => { if (err) { @@ -63,7 +61,9 @@ fs.readFile('input.csv', 'utf8', async (err, data) => { .replace('0.0.0.0 ', '') .replace('127.0.0.1 ', '') .replace('::1 ', '') - .replace(':: ', ''); + .replace(':: ', '') + .replace('^', '') + .replace('||', ''); }).filter(domain => { return domainValidationPattern.test(domain); }); diff --git a/get_recommended_whitelist.sh b/get_recommended_whitelist.sh index 95e61f8..df3e095 100644 --- a/get_recommended_whitelist.sh +++ b/get_recommended_whitelist.sh @@ -1,33 +1,35 @@ #!/bin/bash +# +# Uncomment the provided list or add you own # https://oisd.nl/includedlists/whitelists # create an empty whitelist.csv file touch whitelist.csv # declare an array of urls urls=( - https://raw.githubusercontent.com/im-sm/Pi-hole-Torrent-Blocklist/main/all-torrent-trackres.txt - https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/banks.txt - https://raw.githubusercontent.com/hagezi/dns-blocklists/main/whitelist.txt - https://raw.githubusercontent.com/TogoFire-Home/AD-Settings/main/Filters/whitelist.txt - https://raw.githubusercontent.com/freekers/whitelist/master/domains/whitelist.txt - https://raw.githubusercontent.com/DandelionSprout/AdGuard-Home-Whitelist/master/whitelist.txt - https://www.aadvantageeshopping.com/adBlockWhitelist.php - https://raw.githubusercontent.com/AdguardTeam/AdGuardSDNSFilter/master/Filters/exclusions.txt - https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/optional-list.txt - https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/issues.txt - https://raw.githubusercontent.com/hagezi/dns-blocklists/main/whitelist-referral.txt - https://raw.githubusercontent.com/mawenjian/china-cdn-domain-whitelist/master/china-cdn-domain-whitelist.txt - https://raw.githubusercontent.com/notracking/hosts-blocklists-scripts/master/hostnames.whitelist.txt - https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/mac.txt - https://raw.githubusercontent.com/boutetnico/url-shorteners/master/list.txt - https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/windows.txt - https://raw.githubusercontent.com/Dogino/Discord-Phishing-URLs/main/official-domains.txt - https://raw.githubusercontent.com/ookangzheng/blahdns/master/hosts/whitelist.txt - https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/android.txt - https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/sensitive.txt - https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/whitelist.txt - https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/firefox.txt - https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/referral-sites.txt + # https://raw.githubusercontent.com/im-sm/Pi-hole-Torrent-Blocklist/main/all-torrent-trackres.txt + # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/banks.txt + # https://raw.githubusercontent.com/hagezi/dns-blocklists/main/whitelist.txt + # https://raw.githubusercontent.com/TogoFire-Home/AD-Settings/main/Filters/whitelist.txt + # https://raw.githubusercontent.com/freekers/whitelist/master/domains/whitelist.txt + # https://raw.githubusercontent.com/DandelionSprout/AdGuard-Home-Whitelist/master/whitelist.txt + # https://www.aadvantageeshopping.com/adBlockWhitelist.php + # https://raw.githubusercontent.com/AdguardTeam/AdGuardSDNSFilter/master/Filters/exclusions.txt + # https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/optional-list.txt + # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/issues.txt + # https://raw.githubusercontent.com/hagezi/dns-blocklists/main/whitelist-referral.txt + # https://raw.githubusercontent.com/mawenjian/china-cdn-domain-whitelist/master/china-cdn-domain-whitelist.txt + # https://raw.githubusercontent.com/notracking/hosts-blocklists-scripts/master/hostnames.whitelist.txt + # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/mac.txt + # https://raw.githubusercontent.com/boutetnico/url-shorteners/master/list.txt + # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/windows.txt + # https://raw.githubusercontent.com/Dogino/Discord-Phishing-URLs/main/official-domains.txt + # https://raw.githubusercontent.com/ookangzheng/blahdns/master/hosts/whitelist.txt + # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/android.txt + # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/sensitive.txt + # https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/whitelist.txt + # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/firefox.txt + # https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/referral-sites.txt ) From 8939843a8bdb594b43a9eb6793629c587ff3a10c Mon Sep 17 00:00:00 2001 From: Norbert Date: Mon, 15 May 2023 00:30:19 +0200 Subject: [PATCH 19/24] typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5da0017..464570a 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Cloudflare Gateway allows you to create custom rules to filter HTTP, DNS, and ne 2. Cloudflare [Zero Trust](https://one.dash.cloudflare.com/) account - the Free plan is enough. Use the Cloudflare [documentation](https://developers.cloudflare.com/cloudflare-one/) for details. 3. Cloudflare email, API key (NOT the API token), and account ID 4. A file containing the domains you want to block - **max 300,000 domains for the free plan** - in the working directory named `input.csv`. Mullvad provides awesome [DNS blocklists](https://github.com/mullvad/dns-blocklists) that work well with this project. A bash script that downloads recommended blocklists, `get_recommended_filters.sh`, is included. -5. Optional: You can add whitelist domains to the `get_reccomended_whitelist.sh` if you wish. +5. Optional: You can add whitelist domains to the `get_recomended_whitelist.sh` if you wish. ### Running locally From 8b065e98d7080dbfa1e9bd728c52016b7ad387b5 Mon Sep 17 00:00:00 2001 From: mrrfv Date: Mon, 15 May 2023 15:00:02 +0200 Subject: [PATCH 20/24] improve whitelist documentation adds 'whitelist support' to feature list, and clarifies how to use the whitelist --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 464570a..18eb348 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Cloudflare Gateway allows you to create custom rules to filter HTTP, DNS, and ne - Full support for domain lists - Automatically cleans up filter lists: removes duplicates, invalid domains, comments and more - Works fully unattended +- Whitelist support, allowing you to prevent false positives and breakage by forcing trusted domains to always be unblocked. ## Usage @@ -26,7 +27,7 @@ Cloudflare Gateway allows you to create custom rules to filter HTTP, DNS, and ne 2. Cloudflare [Zero Trust](https://one.dash.cloudflare.com/) account - the Free plan is enough. Use the Cloudflare [documentation](https://developers.cloudflare.com/cloudflare-one/) for details. 3. Cloudflare email, API key (NOT the API token), and account ID 4. A file containing the domains you want to block - **max 300,000 domains for the free plan** - in the working directory named `input.csv`. Mullvad provides awesome [DNS blocklists](https://github.com/mullvad/dns-blocklists) that work well with this project. A bash script that downloads recommended blocklists, `get_recommended_filters.sh`, is included. -5. Optional: You can add whitelist domains to the `get_recomended_whitelist.sh` if you wish. +5. Optional: You can whitelist domains by putting them in a file `whitelist.csv`. You can also use the `get_recomended_whitelist.sh` Bash script to get the recommended whitelists. ### Running locally From a6c2a98d804cdf1db04aca2ef617864c401b06c7 Mon Sep 17 00:00:00 2001 From: mrrfv Date: Mon, 15 May 2023 15:02:21 +0200 Subject: [PATCH 21/24] Uncomment recommended whitelists --- get_recommended_whitelist.sh | 51 ++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/get_recommended_whitelist.sh b/get_recommended_whitelist.sh index df3e095..9f99ec9 100644 --- a/get_recommended_whitelist.sh +++ b/get_recommended_whitelist.sh @@ -1,35 +1,36 @@ #!/bin/bash # -# Uncomment the provided list or add you own +# Use the provided lists or add you own # https://oisd.nl/includedlists/whitelists -# create an empty whitelist.csv file +# by creating an empty whitelist.csv file touch whitelist.csv # declare an array of urls urls=( - # https://raw.githubusercontent.com/im-sm/Pi-hole-Torrent-Blocklist/main/all-torrent-trackres.txt - # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/banks.txt - # https://raw.githubusercontent.com/hagezi/dns-blocklists/main/whitelist.txt - # https://raw.githubusercontent.com/TogoFire-Home/AD-Settings/main/Filters/whitelist.txt - # https://raw.githubusercontent.com/freekers/whitelist/master/domains/whitelist.txt - # https://raw.githubusercontent.com/DandelionSprout/AdGuard-Home-Whitelist/master/whitelist.txt + https://raw.githubusercontent.com/im-sm/Pi-hole-Torrent-Blocklist/main/all-torrent-trackres.txt + https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/banks.txt + https://raw.githubusercontent.com/hagezi/dns-blocklists/main/whitelist.txt + https://raw.githubusercontent.com/TogoFire-Home/AD-Settings/main/Filters/whitelist.txt + https://raw.githubusercontent.com/freekers/whitelist/master/domains/whitelist.txt + https://raw.githubusercontent.com/DandelionSprout/AdGuard-Home-Whitelist/master/whitelist.txt + # Commented out because it looks suspicious # https://www.aadvantageeshopping.com/adBlockWhitelist.php - # https://raw.githubusercontent.com/AdguardTeam/AdGuardSDNSFilter/master/Filters/exclusions.txt - # https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/optional-list.txt - # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/issues.txt - # https://raw.githubusercontent.com/hagezi/dns-blocklists/main/whitelist-referral.txt - # https://raw.githubusercontent.com/mawenjian/china-cdn-domain-whitelist/master/china-cdn-domain-whitelist.txt - # https://raw.githubusercontent.com/notracking/hosts-blocklists-scripts/master/hostnames.whitelist.txt - # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/mac.txt - # https://raw.githubusercontent.com/boutetnico/url-shorteners/master/list.txt - # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/windows.txt - # https://raw.githubusercontent.com/Dogino/Discord-Phishing-URLs/main/official-domains.txt - # https://raw.githubusercontent.com/ookangzheng/blahdns/master/hosts/whitelist.txt - # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/android.txt - # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/sensitive.txt - # https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/whitelist.txt - # https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/firefox.txt - # https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/referral-sites.txt + https://raw.githubusercontent.com/AdguardTeam/AdGuardSDNSFilter/master/Filters/exclusions.txt + https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/optional-list.txt + https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/issues.txt + https://raw.githubusercontent.com/hagezi/dns-blocklists/main/whitelist-referral.txt + https://raw.githubusercontent.com/mawenjian/china-cdn-domain-whitelist/master/china-cdn-domain-whitelist.txt + https://raw.githubusercontent.com/notracking/hosts-blocklists-scripts/master/hostnames.whitelist.txt + https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/mac.txt + https://raw.githubusercontent.com/boutetnico/url-shorteners/master/list.txt + https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/windows.txt + https://raw.githubusercontent.com/Dogino/Discord-Phishing-URLs/main/official-domains.txt + https://raw.githubusercontent.com/ookangzheng/blahdns/master/hosts/whitelist.txt + https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/android.txt + https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/sensitive.txt + https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/whitelist.txt + https://raw.githubusercontent.com/AdguardTeam/HttpsExclusions/master/exclusions/firefox.txt + https://raw.githubusercontent.com/anudeepND/whitelist/master/domains/referral-sites.txt ) @@ -47,4 +48,4 @@ for url in "${urls[@]}"; do done # print a message when done -echo "Done. The whitelist.csv file contains merged data from recommended whitelist." +echo "Done. The whitelist.csv file contains merged data from recommended whitelists." From f5380ede47eca3a11935408ad96496b55474e181 Mon Sep 17 00:00:00 2001 From: mrrfv Date: Mon, 15 May 2023 15:03:53 +0200 Subject: [PATCH 22/24] Don't exit if whitelist doesn't exit --- cf_list_create.js | 54 ++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/cf_list_create.js b/cf_list_create.js index fc87b6a..422f03a 100644 --- a/cf_list_create.js +++ b/cf_list_create.js @@ -14,31 +14,30 @@ let whitelist = []; // Define an empty array for the whitelist // Read whitelist.csv and parse fs.readFile('whitelist.csv', 'utf8', async (err, data) => { if (err) { - console.error('Error reading whitelist.csv:', err); - return; - } - - // Convert into array and cleanup whitelist - const domainValidationPattern = /^(?!-)[A-Za-z0-9-]+([\-\.]{1}[a-z0-9]+)*\.[A-Za-z]{2,6}$/; - let whitelist = data.split('\n').filter(domain => { - // Remove entire lines starting with "127.0.0.1" or "::1", empty lines or comments - return domain && !domain.startsWith('#') && !domain.startsWith('//') && !domain.startsWith('/*') && !domain.startsWith('*/') && !(domain === '\r'); - }).map(domain => { - // Remove "\r", "0.0.0.0 ", "127.0.0.1 ", "::1 " and similar from domain items - return domain - .replace('\r', '') - .replace('0.0.0.0 ', '') - .replace('127.0.0.1 ', '') - .replace('::1 ', '') - .replace(':: ', '') - .replace('||', '') - .replace('@@||', '') - .replace('^$important', '') - .replace('^', ''); - }).filter(domain => { - return domainValidationPattern.test(domain); - }); - + console.warn('Error reading whitelist.csv:', err); + console.warn('Assuming whitelist is empty.') + } else { + // Convert into array and cleanup whitelist + const domainValidationPattern = /^(?!-)[A-Za-z0-9-]+([\-\.]{1}[a-z0-9]+)*\.[A-Za-z]{2,6}$/; + whitelist = data.split('\n').filter(domain => { + // Remove entire lines starting with "127.0.0.1" or "::1", empty lines or comments + return domain && !domain.startsWith('#') && !domain.startsWith('//') && !domain.startsWith('/*') && !domain.startsWith('*/') && !(domain === '\r'); + }).map(domain => { + // Remove "\r", "0.0.0.0 ", "127.0.0.1 ", "::1 " and similar from domain items + return domain + .replace('\r', '') + .replace('0.0.0.0 ', '') + .replace('127.0.0.1 ', '') + .replace('::1 ', '') + .replace(':: ', '') + .replace('||', '') + .replace('@@||', '') + .replace('^$important', '') + .replace('^', ''); + }).filter(domain => { + return domainValidationPattern.test(domain); + }); + } }); @@ -63,7 +62,10 @@ fs.readFile('input.csv', 'utf8', async (err, data) => { .replace('::1 ', '') .replace(':: ', '') .replace('^', '') - .replace('||', ''); + .replace('||', '') + .replace('@@||', '') + .replace('^$important', '') + .replace('^', ''); }).filter(domain => { return domainValidationPattern.test(domain); }); From 718ab036cd498701ec84bb15fd2bf10b6adf2580 Mon Sep 17 00:00:00 2001 From: mrrfv Date: Mon, 15 May 2023 15:06:35 +0200 Subject: [PATCH 23/24] List the amount of items found in the whitelist --- cf_list_create.js | 1 + 1 file changed, 1 insertion(+) diff --git a/cf_list_create.js b/cf_list_create.js index 422f03a..07237e0 100644 --- a/cf_list_create.js +++ b/cf_list_create.js @@ -40,6 +40,7 @@ fs.readFile('whitelist.csv', 'utf8', async (err, data) => { } }); +console.log(`Found ${whitelist.length} valid domains in whitelist.`); // Read input.csv and parse domains fs.readFile('input.csv', 'utf8', async (err, data) => { From 1b6c744cb20a06ac76104f04a7b3a2a2281832b9 Mon Sep 17 00:00:00 2001 From: mrrfv Date: Mon, 15 May 2023 15:08:31 +0200 Subject: [PATCH 24/24] add more info to github actions documentation --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 18eb348..43afebb 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,8 @@ Cloudflare Gateway allows you to create custom rules to filter HTTP, DNS, and ne These scripts can be run using GitHub Actions so your filters will be automatically updated and pushed to Cloudflare Gateway. This is useful if you are using a frequently updated malware blocklist. +Please note that the GitHub Action downloads the recommended blocklists and whitelist by default. You can change this behavior by editing the file. + 1. Create a new empty, private repository. Forking or public repositories are discouraged, but supported - although the script never leaks your API keys and GitHub Actions secrets are automatically redacted from the logs, it's better to be safe than sorry. 2. Create the following GitHub Actions secrets in your repository settings: