Wrapper library to import / export multiple remote rules and easily create, modify and delete rules.
Project description
Welcome to Cloudflare WAF Custom rules library 👋
Previously known as Cloudflare Firewall Rules
A Cloudflare wrapper to bulk add / edit your WAF custom rules using Cloudflare's API.
This library is a wrapper that aims to easily create, modify, delete rules. It also provides a way to import & export new rules in your domain's firewall.
If you have several rules that you want to duplicate among your domains, this module is made for you!
A complete documentation can be found at: https://quentiumyt.github.io/Cloudflare-Firewall-Rules/
📥 Installation
pip install cf_rules
# OR
git clone https://github.com/QuentiumYT/Cloudflare-Firewall-Rules.git
cd Cloudflare-Firewall-Rules/
pip install .
🚀 Usage
You have 2 auth methods available:
A Global API Key or a specific API Token generated from here: https://dash.cloudflare.com/profile/api-tokens
Cloudflare Global API Key
Using a Global API Key, you will have access to everything allowed by a Cloudflare account. It can access all domains from every account you have, this might be overpowered...
Cloudflare API Token
An API token is recommended to keep control of specific domains only. You will need to give the correct permissions for Cloudflare's WAF Custom rules to work.
The required permissions are "Zone.Zone, Zone.Firewall Services"
Here is a token creation example:
💨 Quickstart
You can use any example scripts in the examples folder, just create a .env file
I might add more examples in the future, but everything is in the docs :)
Create any Python file in the cloned directory and paste these lines
from cf_rules import Cloudflare
cf = Cloudflare()
cf.auth_key("<your-address@email.com>", "<your-global-api-key>")
# OR
cf.auth_token("<your-specific-bearer-token>")
domains = cf.domains[0].name
print(domains)
# >>> ['example.com']
cf.export_rules("example.com")
# Creates a text file for every rule you have on your domain
cf.create_rule("example.com", "My Bad Bots FW rule", "Bad Bots", "challenge")
# Create a new rule with the content of the "Bad bots.txt" file with the challenge action
cf.update_rule("example.com", "My Bad Bots FW rule", "Bad Bots lib")
# Change the rule's expression to the content of the "Bad bots lib.txt" file
🤝 Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change and join your fork with the modifications.
Please make sure to test your suggestions before committing.
If you don't feel comfortable coding, you can submit your idea about what you would like to see implemented.
Any PR with small code examples or better documentation changes is appreciated :)
👤 Author
Quentin L.
- Website: quentium.fr
- Twitter: @QuentiumYT
- Contact: Mail
Please ✰ this repository if this project helped you!
📖 License
Made with ❤ by QuentiumYT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cf_rules-2.0.0.tar.gz
.
File metadata
- Download URL: cf_rules-2.0.0.tar.gz
- Upload date:
- Size: 24.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | de98121d2bec836e2bdeb3a10232852c6268283e2010a1fde625bbe830c6a279 |
|
MD5 | f6cedb9a1820930ab10bcf3b1f519d5c |
|
BLAKE2b-256 | ae4420253ff11d792689328a507e228a0a0c0d3c17ac6af342256d437cbb6c60 |
File details
Details for the file cf_rules-2.0.0-py3-none-any.whl
.
File metadata
- Download URL: cf_rules-2.0.0-py3-none-any.whl
- Upload date:
- Size: 20.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1c8d61f71b49116f756fe00bb1b958a12183f6a3d9d328adc4e20e6bff2e453 |
|
MD5 | b244abe9bb7262904d1d8677c7885722 |
|
BLAKE2b-256 | 646d8b122608a7e68f5b3c44509f0b9f1dcb264d4224c1e9632a7e709c261c21 |