mirror of
https://github.com/Nezumi-2711/cloudflare-gateway-pihole-scripts.git
synced 2026-09-22 05:31:50 +00:00
Merge pull request #41 from hlqviet/feature/keep-workflow-alive
Use gautamkrishnar/keepalive-workflow to prevent workflow suspension
This commit is contained in:
@@ -28,7 +28,7 @@ Cloudflare Gateway allows you to create custom rules to filter HTTP, DNS, and ne
|
||||
1. Node.js installed on your machine
|
||||
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 `blocklist.txt`. 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.
|
||||
4. A file containing the domains you want to block - **max 300,000 domains for the free plan** - in the working directory named `blocklist.txt`. Mullvad provides awesome [DNS blocklists](https://github.com/mullvad/dns-blocklists) that work well with this project. A script that downloads recommended blocklists, `download_lists.js`, is included.
|
||||
5. Optional: You can whitelist domains by putting them in a file `allowlist.txt`. You can also use the `get_recomended_whitelist.sh` Bash script to get the recommended whitelists.
|
||||
|
||||
### Running locally
|
||||
@@ -37,7 +37,7 @@ Cloudflare Gateway allows you to create custom rules to filter HTTP, DNS, and ne
|
||||
2. Run `npm install` to install dependencies.
|
||||
3. Copy `.env.example` to `.env` and fill in the values.
|
||||
4. If this is a subsequent run, execute `node cf_gateway_rule_delete.js` and `node cf_list_delete.js` (in order) to delete old data.
|
||||
5. If you're on Linux and haven't downloaded any filters yourself, use the `get_recommended_filters.sh` script to download recommended filter lists (about 250 000 domains).
|
||||
5. If you haven't downloaded any filters yourself, run the `node download_lists.js` command to download recommended filter lists (about 250 000 domains).
|
||||
6. Run `node cf_list_create.js` to create the lists in Cloudflare Gateway. This will take a while.
|
||||
7. Run `node cf_gateway_rule_create.js` to create the firewall rule in Cloudflare Gateway.
|
||||
8. Profit!
|
||||
|
||||
@@ -67,3 +67,6 @@ jobs:
|
||||
curl "${{ env.PING_URL }}"
|
||||
env:
|
||||
PING_URL: ${{ secrets.PING_URL }}
|
||||
|
||||
- name: Keep workflow alive
|
||||
uses: gautamkrishnar/keepalive-workflow@v1
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
# Environment variables
|
||||
|
||||
Environment variables are like a configuration file. They are stored in a file called `.env` in the same directory as the scripts. You have to create this file yourself (an example file is provided in the repository). Below is a list of the most important environment variables and their descriptions.
|
||||
|
||||
## Obtaining your Cloudflare credentials
|
||||
|
||||
### `CLOUDFLARE_ACCOUNT_ID`
|
||||
|
||||
You can find your Cloudflare account ID in the [Cloudflare dashboard](https://dash.cloudflare.com/). Click on any domain you own, then on the "Overview" tab. Scroll down to the bottom of the page and you will see your account ID on the right side.
|
||||
|
||||
Alternatively, you can copy the account ID from the URL of any page in the Cloudflare dashboard. The URL will look like this:
|
||||
|
||||
```
|
||||
https://dash.cloudflare.com/1234567890abcdef1234567890abcdef
|
||||
```
|
||||
|
||||
In this example, `1234567890abcdef1234567890abcdef` is the account ID.
|
||||
|
||||
### `CLOUDFLARE_API_KEY`
|
||||
|
||||
The Cloudflare API key can be found in the [Cloudflare dashboard](https://dash.cloudflare.com/) too. Click on your profile picture (or user icon) in the top right corner, then click on "API Tokens" in the sidebar. Scroll down to the "API Keys" section and click on "View" next to the Global API Key.
|
||||
|
||||
### `CLOUDFLARE_ACCOUNT_EMAIL`
|
||||
|
||||
The Cloudflare account email is the email address you use to log in to the Cloudflare dashboard.
|
||||
|
||||
### `CLOUDFLARE_LIST_ITEM_LIMIT`
|
||||
|
||||
The Cloudflare list item limit is the maximum number of items (blocked domains) that can be added to Cloudflare. The default value of 300,000 is the maximum allowed by Cloudflare for free accounts. If you pay for Cloudflare Zero Trust, you might be able to increase this value.
|
||||
|
||||
## Other
|
||||
|
||||
### `DRY_RUN`
|
||||
|
||||
Processes block/allow lists without actually adding/removing domains from Cloudflare. Avoid using this option unless you know what you are doing.
|
||||
|
||||
### `FAST_MODE`
|
||||
|
||||
Sends requests much faster, but might cause rate limiting issues. Use with caution.
|
||||
|
||||
# Example usage
|
||||
|
||||
These commands should be run in a terminal.
|
||||
|
||||
```bash
|
||||
# Assumes you have already cloned the repository and installed dependencies such as git and node.js.
|
||||
|
||||
# 1. Clone the repository
|
||||
git clone https://github.com/mrrfv/cloudflare-gateway-pihole-scripts
|
||||
cd cloudflare-gateway-pihole-scripts # change the current directory to the cloned repository
|
||||
# 2. Run npm install to install dependencies.
|
||||
npm install
|
||||
# 3.1. Copy the example.env file to .env
|
||||
# Files starting with a dot are hidden by default on Linux and macOS.
|
||||
cp example.env .env
|
||||
# 3.2. Edit the .env file and add your Cloudflare credentials.
|
||||
# (This command varies depending on your system and preferred text editor.)
|
||||
nano .env
|
||||
# 4. If this is a subsequent run, execute node cf_gateway_rule_delete.js and node cf_list_delete.js (in order) to delete old data.
|
||||
# Not needed if setting up for the first time.
|
||||
node cf_gateway_rule_delete.js
|
||||
node cf_list_delete.js
|
||||
# 5. Download the default filter lists.
|
||||
# If you want to use your own lists, put your blocked and allowed domains in files called "blocklist.txt" and "allowlist.txt" respectively.
|
||||
node download_lists.js
|
||||
# 6. Send the filter lists to Cloudflare.
|
||||
node cf_list_create.js
|
||||
# 7. Add the Cloudflare firewall rule.
|
||||
node cf_gateway_rule_create.js
|
||||
# Set up your DNS settings to use Cloudflare Gateway if you haven't already.
|
||||
# 8. Profit!
|
||||
ping google-analytics.com
|
||||
```
|
||||
Reference in New Issue
Block a user