Skip to content

Command-line client of Cloudflare API written in PHP.

License

Notifications You must be signed in to change notification settings

miamibc/cloudflare-cli

Repository files navigation

Cloudflare cli

Command-line client of Cloudflare API written in PHP. Allows to:

  • Execute Cloudflare API commands, like listing available zones or changing zones:settings:development_mode
  • Parse documentation
  • Generate commands from parsed information (Not completed yet)

Laravel

Start cloudflare-cli

Download the latest binary

wget https://raw.githubusercontent.com/miamibc/cloudflare-cli/main/builds/cloudflare-cli

Create API token

To work with Cloudflare from cloudflare-cli, you need to create an API token with all necessary permissions and pass it as env variable.

You have at least two ways do it (change xxxxxx to your API token):

  1. Create .env file with CLOUDFLARE_API_TOKEN variable set

    echo 'CLOUDFLARE_API_TOKEN="xxxxxx"' > .env
    
  2. Or export as a Bash variable

    export CLOUDFLARE_API_TOKEN="xxxxxx"
    

Now you can check, is it set properly, by running

php cloudflare-cli user:tokens:verify

If you did setup correctly, you will see id and status of your API token.

Make it executable and globally accessible

Additionnaly, you can make cloudflare-cli executable and visible system-wide

chmod a+x cloudflare-cli
sudo ln -s $(pwd)/cloudflare-cli /usr/bin/

Now you can run it as a simple command, from any directory

cloudflare-cli

Work with cloudflare-cli

To get list of all commands available, run cloudflare-cli without arguments

cloudflare-cli

To get more information on command, add help and command you need to get help for, for example

cloudflare-cli help zones:settings:development_mode

Extend cloudflare-cli

Project is made with help of Laravel Zero framework.

Install

Clone the project source code

git clone https://github.com/miamibc/cloudflare-cli.git

Go to the created directory

cd cloudflare-cli

Install composer dependencies

composer install

Add new command

Create new command

php cloudflare-cli make:command

And add functionality to the new file in app/Commands directory.

You can add App\Cloudflare\Client $client as a parameter of handle() method, to inject very simple and useful Cloudflare client, that performs authorization, results pagination and possibility to parse documentation.

Test

To test components, run phpunit

php vendor/bin/phpunit

Create binary

To create phar file, use this command and answer few questions

php cloudflare-cli app:build

Built binary (PHAR) file can be found in builds folder.

Support the development

Do you like this project? Support it by donating by PayPal Donate

License

Cloudflare-cli is an open-source software licensed under the MIT license.

License: MIT

About

Command-line client of Cloudflare API written in PHP.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages