sebdesign/artisan-cloudflare

Laravel artisan 命令用于与 Cloudflare API 交互

v2.7.0 2024-04-10 09:24 UTC

README

Latest Version on Packagist Software License Build Status Quality Score Scrutinizer Coverage StyleCI

Laravel artisan 命令,用于与 Cloudflare API 交互。

artisan-cloudflare.png

安装

您可以通过 composer 安装此包。此包需要 Laravel 5.5 或更高版本。

composer require sebdesign/artisan-cloudflare

自版本 5.5 以来,Laravel 使用包自动发现,因此不需要您手动添加 ServiceProvider。如果您不使用自动发现或使用的是旧版本,请在 config/app.php 中添加 ServiceProvider。

<?php

'providers' => [
    Sebdesign\ArtisanCloudflare\ServiceProvider::class,
],

配置

config/cloudflare.php 中发布配置文件。

要通过 API 密钥进行身份验证,请将 CLOUDFLARE_KEYCLOUDFLARE_EMAIL 设置在 .env 文件中。

否则,您可以在 .env 中设置 CLOUDFLARE_TOKEN 来使用 API 令牌。

php artisan vendor:publish --provider="Sebdesign\ArtisanCloudflare\ServiceProvider"

以下选项可用

<?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' => [
        //
    ],
];

用法

清除命令

有关从 Cloudflare 清除缓存的资源的更多信息,请参阅支持文章 清除缓存的资源

在控制台中执行 cloudflare:cache:purge 命令或将其集成到您的部署流程中。

清除所有区域及其文件和标签。

php artisan cloudflare:cache:purge

清除单个区域。

如果区域存在于配置中,则其文件和标签将被清除。否则,将清除指定区域中的所有内容。

php artisan cloudflare:cache:purge 023e105f4ecef8ad9ca31a8372d0c353

从所有区域中清除单个文件。

php artisan cloudflare:cache:purge --file="http://example.com/css/app.css" --file="http://example.com/img/logo.svg"

从所有区域中清除单个标签。

清除标签仅适用于 企业 账户。

php artisan cloudflare:cache:purge --tag=styles --tag=scripts

从所有区域中清除单个主机。

清除主机仅适用于 企业 账户。

php artisan cloudflare:cache:purge --host=www.example.com --host=images.example.com

从所有区域中清除单个文件、标签和主机。

php artisan cloudflare:cache:purge --file="http://example.com/css/app.css" --tag=scripts --tag=images --host=www.example.com

从单个区域中清除单个文件、标签和主机。

php artisan cloudflare:cache:purge 023e105f4ecef8ad9ca31a8372d0c353 --file="http://example.com/css/app.css" --tag=scripts --tag=images --host=www.example.com

阻止 IP 命令

阻止所有区域的 IP 地址。

php artisan cloudflare:waf:block-ip 6.6.6.6

阻止特定区域的 IP 地址。

php artisan cloudflare:waf:block-ip 6.6.6.6 023e105f4ecef8ad9ca31a8372d0c353

阻止所有区域带有自定义注释的 IP 地址。

php artisan cloudflare:waf:block-ip 6.6.6.6 --notes="By Artisan Cloudflare"

阻止特定区域带有自定义注释的 IP 地址。

php artisan cloudflare:waf:block-ip 6.6.6.6 023e105f4ecef8ad9ca31a8372d0c353 --notes="By Artisan Cloudflare"

变更日志

请参阅 CHANGELOG 了解最近更改的更多信息。

测试

composer test

贡献

有关详细信息,请参阅 CONTRIBUTING

安全

如果您发现任何安全问题,请通过电子邮件 info@sebdesign.eu 而不是使用问题跟踪器来报告。

许可证

MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件