定制 calkeo/laravel-cloudflare-ddns 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

calkeo/laravel-cloudflare-ddns

Composer 安装命令:

composer require calkeo/laravel-cloudflare-ddns

包简介

This package facilitates dynamic DNS (DDNS) for Cloudflare with no third-party integrations. The package interacts directly with the Cloudflare API to sync the current system's IP address with your Cloudflare DNS records.

README 文档

README

Latest Stable Version Total Downloads License GitHub Code Style Action Status

This package facilitates dynamic DNS (DDNS) for Cloudflare with no third-party integrations. The package interacts directly with the Cloudflare API to sync the current system's IP address with your Cloudflare DNS records.

Use Cases

This package can be used for multiple purposes. For instance:

  • Running a server on your home network that you want to be accessible to the public.
  • Automatically updating your DNS records when you deploy or migrate a site to a new server.

Prerequisites

  • PHP 8
  • Laravel 8

Installation

Install the package via composer:

composer require calkeo/laravel-cloudflare-ddns

Publish the config file and migrations:

php artisan vendor:publish --provider="Calkeo\Ddns\DdnsServiceProvider" 

Run the migrations:

php artisan migrate

Configuration

The configuration file can be found at config/cloudflare_ddns:

return [

    /**
     * The Cloudflare API token for the account that has privileges to manage
     * the domains that you add to this file.
     */
    'cloudflare_api_token' => env('CLOUDFLARE_API_TOKEN'),

    /**
     * The amount of time in seconds that the public IP address is cached for
     * each time the ddns:sync command is executed.
     */
    'cache_duration' => env('DDNS_CACHE_DURATION', 60),

    /**
     * The domains to sync with this system's IP address.
     */
    'domains' => [
        [
            'domain' => '',
            // The domain that the DNS records will be synced with.
            'sync_interval' => 5,
            // The interval in minutes for which this domain's records will be updated
            'records' => [
                [
                    'name' => '', // DNS record name
                    'type' => '', // DNS record type
                    'ttl' => 1,
                    // Time to live for DNS record. Value of 1 is 'automatic'
                    'proxied' => true,
                    // Whether the DNS record is proxied through Cloudflare
                ],
            ],
        ],
    ],

];

cloudflare_api_token

(string)

A Cloudflare API token that has sufficient privileges to access the DNS records for the domains listed in the config file. How to generate a Cloudflare API token.

cache_duration

(integer)

The amount of time in seconds that the public IP address is cached for each time the ddns:sync command is executed.

The IP address is automatically flushed from the cache each time the ddns:sync command is executed. Because an external network request has to be made in order to retrieve the public IP address, increasing the cache duration will increase performance.

domains[]

(array)

The domains to be synced. A domain is referred to as a Zone within Cloudflare.

domains[][domain]

(string)

The base domain name, also referred to as the Zone. This must be the base of the domain as any subdomains will be configured within the records array.

domains[][sync_interval]

(integer)

How often (in minutes) the domain's DNS records will be synced with the server's public IP address.

domains[][records]

(array)

The DNS records to be synced for the domain.

A record will be synced if there is already an existing DNS record in Cloudflare for this domain that matches the type and name specified for the record in the config file.

domains[][records][name]

(string)

The DNS record name.

For instance:

  • Record name www for www.domain.com
  • Record name mysubdomain for mysubdomain.domain.com

domains[][records][type]

(string)

The DNS record type. Valid types are:

  • A
  • AAAA
  • CNAME
  • HTTPS
  • TXT
  • SRV
  • LOC
  • MX
  • NS
  • SPF
  • CERT
  • DNSKEY
  • DS
  • NAPTR
  • SMIMEA
  • SSHFP
  • SVCB
  • TLSA
  • URI

domains[][records][ttl]

(integer)

The DNS record TTL (time-to-live). Setting this value to 1 sets the DNS record TTL to 'automatic'.

domains[][records][proxied]

(boolean)

Whether the DNS record should be proxied through Cloudflare's network.

A brief explanation of Cloudflare DNS proxying (source):

The DNS proxied means it will be shown a Cloudflare IP if you look it up. Thus all attacks at that domain will DDoS Cloudflare and not you host directly.

Non proxied means all traffic goes directly to your own IP without Cloudflare being a safety net in front.

The upside of proxied is that you will enjoy the Coudflare benefits but you can not make a direct connection to your IP, which means any custom ports wont work.

Non proxied has the advantage of being able to use custom ports to connect as it will connect to your IP directly.

If you are using this package to setup DDNS for your home network, you should take note from the above, that if you proxy your IP address through Cloudflare then you cannot use custom ports. Read about the ports available whilst proxying through Cloudflare.

Usage

To continually sync your configured domains, it is recommended to create a scheduled task that runs the ddns:sync command every minute.

// App/Console/Kernel.php

protected function schedule(Schedule $schedule)
{
    $schedule->command('ddns:sync')->everyMinute();
}

The package will only sync with a domain in Cloudflare if the domain has not yet been synced, or if it is due to run based on the sync_interval value set for the domain in the config file.

An individual record will also not be updated if it is determined that there has been no change in IP address, and if the ttl and proxied values for the record in the config file are up-to-date in Cloudflare.

Roadmap

Feature Status
Allow creation of new records Upcoming
Support custom IP resolvers Upcoming
Event Broadcasting Upcoming

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

calkeo/laravel-cloudflare-ddns 适用场景与选型建议

calkeo/laravel-cloudflare-ddns 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 426 次下载、GitHub Stars 达 7, 最近一次更新时间为 2021 年 05 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「cloudflare」 「ddns」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 calkeo/laravel-cloudflare-ddns 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 calkeo/laravel-cloudflare-ddns 我们能提供哪些服务?
定制开发 / 二次开发

基于 calkeo/laravel-cloudflare-ddns 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 426
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-05-08