Cloudflare Domain Synchronization Feature
Overview
The Cloudflare Domain Synchronization feature allows administrators to update the local configuration
with domains from Cloudflare. 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.
Features
- One-click synchronization of domains from Cloudflare to local configuration
- Automatic fallback to existing configuration when API access is restricted
- Clear error messages with troubleshooting information
- IP restriction detection and helpful guidance
Usage
- Log in as an administrator
- Navigate to the Cloudflare DNS Management page (via Admin menu or directly at
/cloudflareapi)
- Click the "Update Domains from Cloudflare" button at the top of the page
- Confirm the action when prompted
Technical Implementation
Controller Endpoint
The feature is implemented as an endpoint in the CloudflareAPI controller:
sub update_domains :Path('update_domains') :Args(0) { ... }
This endpoint is accessible at /cloudflareapi/update_domains and handles:
- Authentication and authorization checks
- Calling the CloudflareManager to update domains
- Displaying appropriate success/error messages
- Supporting both web interface and API access
CloudflareManager Method
The core functionality is implemented in the CloudflareManager module:
sub update_user_domains_from_cloudflare { ... }
This method:
- Attempts to fetch domains from the Cloudflare API
- Falls back to existing configuration if API access is restricted
- Updates the configuration file with the domain information
- Returns detailed information about the operation
IP Restriction Handling
If your Cloudflare API token has IP restrictions that don't include your server's IP address,
the system will:
- Detect the IP restriction
- Log informational messages instead of errors
- Fall back to using existing configuration data
- Display a helpful message with your server's IP address
Resolving IP Restrictions
To allow direct API access, you can:
- Log in to your Cloudflare dashboard
- Go to "My Profile" > "API Tokens"
- Edit your API token
- Under "IP Address Filtering", add your server's IP address
- Save the changes
Alternatively, you can create a new API token without IP restrictions, but this is less secure.
Security Considerations
- Only administrators can trigger the domain synchronization
- The API token used for Cloudflare API access is kept secure in the configuration file
- All actions are logged for audit purposes
- IP restrictions on the Cloudflare API token are respected