├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Cloudflare.sh ├── LICENSE ├── README.md └── config.template /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code de conduite _Contributor Covenant_ 2 | 3 | ## Notre engagement 4 | 5 | En tant que membres, contributeur·trice·s et dirigeant·e·s, nous nous engageons à faire de la participation à notre communauté une expérience sans harcèlement, quel que soit l'âge, la taille, le handicap visible ou non, l'ethnicité, les caractéristiques sexuelles, l'identité et l'expression de genre, le niveau d'expérience, l'éducation, le statut socio-économique, la nationalité, l'apparence, la race, la caste, la couleur de peau, la religion, ou l'identité et l'orientation sexuelle. 6 | 7 | Nous nous engageons à agir et interagir de manière à contribuer à une communauté ouverte, accueillante, diversifiée, inclusive et saine. 8 | 9 | ## Nos critères 10 | 11 | Exemples de comportements qui contribuent à créer un environnement positif : 12 | 13 | * Faire preuve d'empathie et de bienveillance envers les autres 14 | * Être respectueux des opinions, points de vue et expériences divergents 15 | * Donner et recevoir avec grâce les critiques constructives 16 | * Assumer ses responsabilités et s'excuser auprès des personnes affectées par nos erreurs et apprendre de ces expériences 17 | * Se concentrer sur ce qui est le meilleur non pas uniquement pour nous en tant qu'individu, mais aussi pour l'ensemble de la communauté 18 | 19 | Exemples de comportements inacceptables : 20 | 21 | * L'utilisation de langage ou d'images sexualisés et d'attentions ou d'avances sexuelles de toute nature 22 | * Le _trolling_, les commentaires insultants ou désobligeants et les attaques personnelles ou d'ordre politique 23 | * Le harcèlement en public ou en privé 24 | * La publication d'informations privées d'autrui, telle qu'une adresse postale ou une adresse électronique, sans leur autorisation explicite 25 | * Toute autre conduite qui pourrait raisonnablement être considérée comme inappropriée dans un cadre professionnel 26 | 27 | ## Responsabilités d'application 28 | 29 | Les dirigeant·e·s de la communauté sont chargé·e·s de clarifier et de faire respecter nos normes de comportements acceptables et prendront des mesures correctives appropriées et équitables en réponse à tout comportement qu'ils ou elles jugent inapproprié, menaçant, offensant ou nuisible. 30 | 31 | Les dirigeant·e·s de la communauté ont le droit et la responsabilité de supprimer, modifier ou rejeter les commentaires, les contributions, le code, les modifications de wikis, les rapports d'incidents ou de bogues et autres contributions qui ne sont pas alignés sur ce code de conduite, et communiqueront les raisons des décisions de modération le cas échéant. 32 | 33 | ## Portée d'application 34 | 35 | Ce code de conduite s'applique à la fois au sein des espaces du projet ainsi que dans les espaces publics lorsqu'un individu représente officiellement le projet ou sa communauté. Font parties des exemples de représentation d'un projet ou d'une communauté l'utilisation d'une adresse électronique officielle, la publication sur les réseaux sociaux à l'aide d'un compte officiel ou le fait d'agir en tant que représentant·e désigné·e lors d'un événement en ligne ou hors-ligne. 36 | 37 | ## Application 38 | 39 | Les cas de comportements abusifs, harcelants ou tout autre comportement inacceptables peuvent être signalés aux dirigeant·e·s de la communauté responsables de l'application du code de conduite à **aucun courriel disponible**. Toutes les plaintes seront examinées et feront l'objet d'une enquête rapide et équitable. 40 | 41 | Tou·te·s les dirigeant·e·s de la communauté sont tenu·e·s de respecter la vie privée et la sécurité des personnes ayant signalé un incident. 42 | 43 | ## Directives d'application 44 | 45 | Les dirigeant·e·s de communauté suivront ces directives d'application sur l'impact communautaire afin de déterminer les conséquences de toute action qu'ils jugent contraire au présent code de conduite : 46 | 47 | ### 1. Correction 48 | 49 | **Impact communautaire** : utilisation d'un langage inapproprié ou tout autre comportement jugé non professionnel ou indésirable dans la communauté. 50 | 51 | **Conséquence** : un avertissement écrit et privé de la part des dirigeant·e·s de la communauté, clarifiant la nature du non-respect et expliquant pourquoi le comportement était inapproprié. Des excuses publiques peuvent être demandées. 52 | 53 | ### 2. Avertissement 54 | 55 | **Impact communautaire** : un non-respect par un seul incident ou une série d'actions. 56 | 57 | **Conséquence** : un avertissement avec des conséquences dû à la poursuite du comportement. Aucune interaction avec les personnes concernées, y compris l'interaction non sollicitée avec celles et ceux qui sont chargé·e·s de l'application de ce code de conduite, pendant une période déterminée. Cela comprend le fait d'éviter les interactions dans les espaces communautaires ainsi que sur les canaux externes comme les médias sociaux. Le non-respect de ces conditions peut entraîner un bannissement temporaire ou permanent. 58 | 59 | ### 3. Bannissement temporaire 60 | 61 | **Impact communautaire** : un non-respect grave des normes communautaires, notamment 62 | un comportement inapproprié soutenu. 63 | 64 | **Conséquence** : un bannissement temporaire de toutes formes d'interactions ou de communications avec la communauté pendant une période déterminée. Aucune interaction publique ou privée avec les personnes concernées, y compris les interactions non sollicitées avec celles et ceux qui appliquent ce code de conduite, n'est autorisée pendant cette période. Le non-respect de ces conditions peut entraîner un bannissement permanent. 65 | 66 | ### 4. Bannissement permanent 67 | 68 | **Impact communautaire** : démontrer un schéma récurrent de non-respect des normes de la communauté y compris un comportement inapproprié soutenu, le harcèlement d'un individu ainsi que l'agression ou le dénigrement de catégories d'individus. 69 | 70 | **Conséquence** : un bannissement permanent de toutes formes d'interactions publiques au sein de la communauté. 71 | 72 | ## Attributions 73 | 74 | Ce code de conduite est adapté du [Contributor Covenant][homepage], version 2.1, disponible à [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. 75 | 76 | Les Directives d'application ont été inspirées par le [Code of conduct enforcement ladder][Mozilla CoC] de Mozilla. 77 | 78 | Pour obtenir des réponses aux questions courantes sur ce code de conduite, consultez la FAQ à [https://www.contributor-covenant.org/faq][FAQ]. Les traductions sont disponibles sur [https://www.contributor-covenant.org/translations][translations]. 79 | 80 | [homepage]: https://www.contributor-covenant.org 81 | [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html 82 | [Mozilla CoC]: https://github.com/mozilla/diversity 83 | [FAQ]: https://www.contributor-covenant.org/faq 84 | [translations]: https://www.contributor-covenant.org/translations 85 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution Guidelines 2 | 3 | ## Please ensure your pull request adheres to the following guidelines: 4 | 5 | * Make sure your submission is not a duplicate. 6 | * Follow the appropriate format. 7 | * Keep descriptions short and simple. 8 | * End all descriptions with a full stop. 9 | * Check your spelling and grammar. 10 | * Make an individual pull request for each suggestion. 11 | * The pull request and commit should have a useful title. 12 | * Insert new suggestions at the bottom of a category. 13 | * Use IMDb links & ratings. 14 | 15 | Once a PR is submitted, it will need to be "endorsed". This entails that your pull request will be merged once more people show interest in your suggestion (i.e. react positively, comment on your pull-req etc.) 16 | 17 | Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). 18 | By participating in this project you agree to abide by its terms. 19 | 20 | Your contributions are much appreciated. 21 | Thank you for your suggestions! 22 | 23 | 24 | # Contributing 25 | 26 | When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change. 27 | 28 | Please note we have a code of conduct, please follow it in all your interactions with the project. 29 | 30 | ## Pull Request Process 31 | 32 | 1. Ensure any install or build dependencies are removed before the end of the layer when doing a build ; 33 | 2. Update the README.md with details of changes to the interface, this includes new environment variables, exposed ports, useful file locations and container parameters ; 34 | 3. Increase the version numbers in any examples files and the README.md to the new version that this Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/) ; 35 | 4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you. 36 | 37 | ## Code of Conduct 38 | 39 | ### Our Pledge 40 | 41 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 42 | 43 | ### Our Standards 44 | 45 | Examples of behavior that contributes to creating a positive environment include : 46 | 47 | * Using welcoming and inclusive language 48 | * Being respectful of differing viewpoints and experiences 49 | * Gracefully accepting constructive criticism 50 | * Focusing on what is best for the community 51 | * Showing empathy towards other community members 52 | 53 | Examples of unacceptable behavior by participants include : 54 | 55 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 56 | * Trolling, insulting/derogatory comments, and personal or political attacks 57 | * Public or private harassment 58 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 59 | * Other conduct which could reasonably be considered inappropriate in a professional setting 60 | 61 | ### Our Responsibilities 62 | 63 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 64 | 65 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 66 | 67 | ### Scope 68 | 69 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 70 | 71 | ### Enforcement 72 | 73 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at no@nomail.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 74 | 75 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 76 | -------------------------------------------------------------------------------- /Cloudflare.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | # $1 = 1min, $2 = 5min, $3 = 15min 5 | loadavg=$(awk '{printf "%f", $1}' < /proc/loadavg) 6 | 7 | 8 | # load is 10, you can modify this if you want load more than 10 9 | maxload=10 10 | 11 | 12 | # Configuration API Cloudflare 13 | # Your Global API Key (https://dash.cloudflare.com/profile) 14 | api_key= 15 | # Email of your Cloudflare account 16 | email= 17 | # Zone ID (https://dash.cloudflare.com/_zone-id_/domain.com) 18 | zone_id= 19 | # Default security level when there is no attack, see in readme 20 | default_security_level=high 21 | # Whether to write debug messages to the debug.log file under script dir 22 | debug=0 23 | 24 | 25 | basedir=$(dirname "$0") 26 | 27 | attacked_file=$basedir/attacked 28 | 29 | [ "$debug" -eq 1 ] && exec > "${logfile:-$basedir/debug.log}" 30 | 31 | 32 | # You can put aforementioned config values either in-place 33 | # or in the file named 'config' in the script's directory. 34 | config_file=$basedir/config 35 | [ -e "$config_file" ] && source "$config_file" 36 | 37 | 38 | api_set_mode() { 39 | local mode 40 | mode=$1 41 | curl -s -X PATCH "https://api.cloudflare.com/client/v4/zones/$zone_id/settings/security_level" \ 42 | -H "X-Auth-Email: $email" \ 43 | -H "X-Auth-Key: $api_key" \ 44 | -H "Content-Type: application/json" \ 45 | --data "{\"value\":\"$mode\"}" \ 46 | || echo "Error: failed to set security level to $mode" 47 | } 48 | 49 | 50 | # create file "attacked" if doesn't exist 51 | if [ ! -e "$attacked_file" ]; then 52 | echo 0 > "$attacked_file" 53 | fi 54 | 55 | 56 | was_under_attack=$(cat "$attacked_file") 57 | under_attack=$(echo "$loadavg > $maxload" | bc) 58 | 59 | if [[ "$1" != [01] ]]; then 60 | echo "Incorrect usage! Please pass either 0 or 1 as an argument" 61 | exit 1 62 | fi 63 | 64 | if [ $debug -eq 1 ]; then 65 | echo "Mode: $1; was under attack: $was_under_attack; now under attack: $under_attack" 66 | echo "Load average: $loadavg" 67 | fi 68 | 69 | if [ "$1" -eq 0 ] && [ "$was_under_attack" -eq 0 ] && [ "$under_attack" -eq 1 ]; then 70 | # attack just started and we want to enable under-attack mode 71 | 72 | # Activate protection 73 | [ "$debug" -eq 1 ] && echo "Activating under-attack mode!" 74 | echo 1 > "$attacked_file" 75 | api_set_mode under_attack 76 | 77 | elif [ "$1" -eq 1 ] && [ "$was_under_attack" -eq 1 ] && [ "$under_attack" -eq 0 ]; then 78 | # attack just finished (and up to 20 minutes passed since) 79 | # and we want to disable under-attack mode 80 | 81 | # Disable Protection 82 | [ "$debug" -eq 1 ] && echo "Leaving under-attack mode!" 83 | echo 0 > "$attacked_file" 84 | api_set_mode "$default_security_level" 85 | 86 | fi 87 | 88 | exit 0 89 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Machou 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cloudflare-Block 2 | 3 | This script enable *I'm Under Attack Mode* of [Cloudflare](https://www.cloudflare.com/) if your server's load average exceeds a predefined limit. 4 | 5 | **Cloudflare.sh** will create a file named **attacked** to check if the protection is *enabled* or *disabled*. 6 | 7 | Load average is checked via a cron job (default: every 20 minutes) 8 | 9 | ## Configuration 10 | 11 | ### Script 12 | 13 | ```bash 14 | git clone https://github.com/Machou/Cloudflare-Block.git DDoS 15 | ``` 16 | 17 | ### Configure you API 18 | 19 | Copy config file `config.template` to `config` and edit it: 20 | add API keys (mandatory) and optionally change some of the other values. 21 | 22 | **API_KEY**: Your Global API Key (https://dash.cloudflare.com/profile) 23 | 24 | **MAIL_ACCOUNT**: Email of your Cloudflare account 25 | 26 | **DOMAIN**: Zone ID (https://dash.cloudflare.com/_zone-id_/domain.com) 27 | 28 | [Cloudflare API Documentation](https://api.cloudflare.com/#zone-settings-get-security-level-setting) 29 | 30 | | Mode | Description | 31 | |:------------:|:-------------:| 32 | | high | Threat scores greater than 0 will be challenged | 33 | | medium | Threat scores greater than 14 will be challenged | 34 | | low | Threat scores greater than 24 will be challenged | 35 | |under_attack | Under Attack Mode | 36 | 37 | ### Cron 38 | 39 | ```bash 40 | crontab -e 41 | 42 | */1 * * * * /root/DDoS/Cloudflare.sh 0 # check every 1 minute if protection is not enabled 43 | */20 * * * * /root/DDoS/Cloudflare.sh 1 # check every 20 minutes if protection is enabled 44 | ``` 45 | 46 | ### License 47 | 48 | **Cloudflare-Block** are distributed under the [The MIT License](https://opensource.org/licenses/MIT). -------------------------------------------------------------------------------- /config.template: -------------------------------------------------------------------------------- 1 | # Copy it to 'config' and change for your liking 2 | 3 | # Your Global API Key (https://dash.cloudflare.com/profile) 4 | api_key= 5 | # Email of your Cloudflare account 6 | email= 7 | # Zone ID (https://dash.cloudflare.com/_zone-id_/domain.com) 8 | zone_id= 9 | # Default security level when there is no attack, see in readme 10 | default_security_level=high 11 | # Whether to write debug messages to the debug.log file under script dir 12 | debug=0 13 | --------------------------------------------------------------------------------