This repository provides automation scripts for integrating Cloudflare with cPanel. It includes scripts to automatically add or remove domains in Cloudflare when accounts are created or deleted in cPanel. The integration is achieved through WHM hooks.
- Automatic Cloudflare Account Addition: Adds a domain to Cloudflare when a new cPanel account is created.
- Automatic Cloudflare Account Deletion: Removes a domain from Cloudflare when a cPanel account is terminated.
- WHM Hook Integration: Seamlessly integrates with WHM using cPanel hooks.
account_add.py- Script to add a domain to Cloudflare when a cPanel account is created.account_delete.py- Script to remove a domain from Cloudflare when a cPanel account is deleted.
chmod +x /usr/local/cpanel/hooks/account_add.py
chmod +x /usr/local/cpanel/hooks/account_delete.pyUse the manage_hooks command to register the scripts with cPanel.
Register Account Creation Hook
/usr/local/cpanel/bin/manage_hooks add script /usr/local/cpanel/hooks/account_add.py --event Account::Create --stage postRegister Account Deletion Hook
/usr/local/cpanel/bin/manage_hooks add script /usr/local/cpanel/hooks/account_add.py --event Account::Create --stage post/usr/local/cpanel/bin/manage_hooks listEnsure the scripts are listed under the appropriate events.
Import sql_structure.sql file into your mysql database.
# Database
MYSQL_HOST=your_mysql_host
MYSQL_USER=your_mysql_user
MYSQL_PASSWORD=your_mysql_password
MYSQL_DATABASE=your_mysql_db
MYSQL_TABLE=your_mysql_table
# Cpanel configuration
CPANEL_API_TOKEN=your_cpanel_api_token
CPANEL_URL=https://your-cpanel-host
CPANEL_USERNAME=root
# Cloudflare configuration
API_TOKEN=cloudflare_api_token
API_ACCOUNT=cloudflare_account_id
CLOUDFLARE_ACCOUNT_EMAIL=cloudflare_email/scripts/wwwacct domain_here username_here password_here/scripts/removeacct username_here