sebdesign / artisan-cloudflare
Laravel artisan commands for Cloudflare
Installs: 190 870
Dependents: 0
Suggesters: 0
Security: 0
Stars: 77
Watchers: 5
Forks: 7
Open Issues: 2
Requires
- php: ^7.2.5|^8.0
- guzzlehttp/guzzle: ^7.0
- illuminate/console: ^5.5|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/support: ^5.5|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
Requires (Dev)
- mockery/mockery: ^0.9|^1.0
- orchestra/testbench: ^3.5|^4.0|^5.0|^6.0|^8.0|^9.0
- phpunit/phpunit: ^7.0|^8.5|^9.3|^10.5
README
Laravel artisan commands for interacting with the CloudFlare API.
Installation
You can install the package via composer. This package requires Laravel 5.5 or higher.
composer require sebdesign/artisan-cloudflare
Since version 5.5, Laravel uses package auto-discovery, so doesn't require you to manually add the ServiceProvider. If you don't use auto-discovery or you are using an older version, add the service provider in config/app.php
.
<?php 'providers' => [ Sebdesign\ArtisanCloudflare\ServiceProvider::class, ],
Configuration
Publish the config file in config/cloudflare.php
.
To authenticate with an API key set CLOUDFLARE_KEY
and CLOUDFLARE_EMAIL
in the .env
.
Otherwise you can use an API token by setting the CLOUDFLARE_TOKEN
in the .env
.
php artisan vendor:publish --provider="Sebdesign\ArtisanCloudflare\ServiceProvider"
The following options are available:
<?php return [ /** * API token generated from the User Profile 'My Profile > Api Tokens > API Tokens' page. * create token > Edit zone DNS > "Permissions" Zone:Cache Purge:Purge */ 'token' => env('CLOUDFLARE_TOKEN'), /** * Global API Key on the "My Profile > Api Tokens > API Keys" page. */ 'key' => env('CLOUDFLARE_KEY'), /** * Email address associated with your account. */ 'email' => env('CLOUDFLARE_EMAIL'), /** * Array of zones. * * Each zone must have its identifier as a key. The value is an * associated array with *optional* arrays of files and/or tags. * * you can find your zoneId under 'Account Home > site > Api'. * * E.g. * * '023e105f4ecef8ad9ca31a8372d0c353' => [ * 'files' => [ * 'http://example.com/css/app.css', * ], * 'tags' => [ * 'styles', * 'scripts', * ], * 'hosts' => [ * 'www.example.com', * 'images.example.com', * ], * ], */ 'zones' => [ // ], ];
Usage
Purge command
Read more about Purging cached resources from Cloudflare on the support article.
Execute the cloudflare:cache:purge
command in your console or integrate it in your deployment workflow.
Purge all the zones with their files and tags.
php artisan cloudflare:cache:purge
Purge a single zone.
If the zone exists in the config, then its files and tags will be purged. Otherwise everything will be purged from the given zone.
php artisan cloudflare:cache:purge 023e105f4ecef8ad9ca31a8372d0c353
Purge individual files from all the zones.
php artisan cloudflare:cache:purge --file="http://example.com/css/app.css" --file="http://example.com/img/logo.svg"
Purge individual tags from all the zones.
Purging tags is available for Enterprise accounts only.
php artisan cloudflare:cache:purge --tag=styles --tag=scripts
Purge individual hosts from all the zones.
Purging hosts is available for Enterprise accounts only.
php artisan cloudflare:cache:purge --host=www.example.com --host=images.example.com
Purge individual files, tags, and hosts from all the zones.
php artisan cloudflare:cache:purge --file="http://example.com/css/app.css" --tag=scripts --tag=images --host=www.example.com
Purge individual files, tags, and hosts from a single zone.
php artisan cloudflare:cache:purge 023e105f4ecef8ad9ca31a8372d0c353 --file="http://example.com/css/app.css" --tag=scripts --tag=images --host=www.example.com
Block IP command
Block an IP address for all the zones.
php artisan cloudflare:waf:block-ip 6.6.6.6
Block an IP address for a specific zone.
php artisan cloudflare:waf:block-ip 6.6.6.6 023e105f4ecef8ad9ca31a8372d0c353
Block an IP address for all the zones with a custom comment.
php artisan cloudflare:waf:block-ip 6.6.6.6 --notes="By Artisan Cloudflare"
Block an IP address for a specific zone with a custom comment.
php artisan cloudflare:waf:block-ip 6.6.6.6 023e105f4ecef8ad9ca31a8372d0c353 --notes="By Artisan Cloudflare"
Changelog
Please see CHANGELOG for more information on what has changed recently.
Testing
composer test
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email info@sebdesign.eu instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.