Welcome Guest to Defaut site!

Cloudflare Domain Synchronization

Date: 2025-07-15

Author: System Administrator

Status: Implemented

Overview

This update adds functionality to synchronize domains from Cloudflare to the local configuration file. This ensures that the application always has an up-to-date list of domains managed by Cloudflare, even if changes were made directly in the Cloudflare dashboard.

Changes

  1. Added a new method to the CloudflareManager module:

    • Fetches the list of domains from Cloudflare API
    • Updates the user_domains section in the configuration file
    • Updates the domains section in the configuration file with zone IDs
    • Handles IP restrictions by falling back to existing configuration data
  2. Added a new endpoint to the CloudflareAPI controller:

    • Path: /cloudflareapi/update_domains
    • Requires admin authentication
    • Calls the new CloudflareManager method
    • Provides appropriate success/error messages
    • Handles both API and fallback scenarios
  3. Updated the Cloudflare management UI to include:

    • An "Update Domains from Cloudflare" button
    • Success/error message display
    • Confirmation dialog before updating

Technical Details

The implementation uses the existing list_zones method to fetch domains from Cloudflare, then updates the configuration file with the retrieved data. This ensures that any domains added or removed directly in Cloudflare are reflected in the application.

The update process preserves the structure of the configuration file while replacing the domain-related sections with fresh data from the Cloudflare API.

If the Cloudflare API cannot be accessed due to IP restrictions, the system will fall back to using the existing configuration data, ensuring that the functionality still works even when direct API access is not available.

Security Considerations

Usage

  1. Log in as an administrator
  2. Navigate to the Cloudflare DNS Management page (via Admin menu or directly at /cloudflareapi)
  3. Click the "Update Domains from Cloudflare" button at the top of the page
  4. Confirm the action when prompted

After synchronization, the updated domain list will be used for all Cloudflare-related operations in the application.

Troubleshooting

If you encounter an error message about IP restrictions, it means your Cloudflare API token is configured to only allow access from specific IP addresses, and your server's IP address is not on the allowed list. In this case, the system will fall back to using the existing configuration data.

To resolve this issue, you can either:

  1. Update your Cloudflare API token to allow access from your server's IP address
  2. Create a new API token without IP restrictions
  3. Continue using the fallback mechanism, which will still update the user_domains section but won't update the zone IDs