This is a Flask application that interacts with the WHM API to manage accounts, DNS records, backups, and other functionalities on a WHM server.
- List accounts
- Create an account
- Suspend an account
- Modify an account
- Change account plan/package
- Change account password
- Delete an account
- Unsuspend an account
- List users
- Add, remove, and edit DNS zone records
- Configure backups
- Add a backup destination
- Get backup configuration
- Add a restore task to the queue
- Python 3.6 or higher
- pip (Python package installer)
-
Clone the repository:
git clone https://github.com/alilotfi23/whm-api.git cd whm-api
-
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install the dependencies:
pip install -r requirements.txt
-
Create a
.env
file in the root directory of your project and add your WHM server URL and token:URL=https://server_ip:whm_port# Defualt is 2087 TOKEN=your_token_here
-
Run the application:
python app.py
-
Ensure you have Docker installed:
-
Build the Docker image:
- Navigate to the directory containing your
Dockerfile
and the application code. - Run the following command to build the Docker image:
docker build -t flask-whm-api .
- Navigate to the directory containing your
-
Run the Docker container:
- Use the following command to run the container:
docker run -d -p 80:8080 --name flask-whm-api-container flask-whm-api
- Use the following command to run the container:
-
Access the application:
- Open your web browser and navigate to
http://localhost:8080
to access your Flask application.
- Open your web browser and navigate to
- URL:
/listaccts
- Method:
GET
- Response:
[ { "user": "example_user", "domain": "example.com", "plan": "basic", "email": "user@example.com", "backup": "enabled", "suspended": "no" } ]
- URL:
/createacct
- Method:
POST
- Request Body:
{ "domain": "example.com", "username": "example_user", "password": "password123", "contactemail": "user@example.com", "plan": "basic", "dkim": "enabled" }
- Response:
{ "result": "success", "details": "Account created successfully." }
- URL:
/suspend
- Method:
POST
- Request Body:
{ "user": "example_user" }
- Response:
{ "result": "success", "details": "Account suspended successfully." }
- URL:
/modify
- Method:
POST
- Request Body:
{ "user": "example_user", "domain": "example.com", "contactemail": "new_email@example.com" }
- Response:
{ "result": "success", "details": "Account modified successfully." }
- URL:
/changeplan
- Method:
POST
- Request Body:
{ "user": "example_user", "pkg": "premium" }
- Response:
{ "result": "success", "details": "Account package changed successfully." }
- URL:
/changepass
- Method:
POST
- Request Body:
{ "user": "example_user", "password": "new_password123" }
- Response:
{ "result": "success", "details": "Account password changed successfully." }
- URL:
/deleteacct
- Method:
POST
- Request Body:
{ "username": "example_user" }
- Response:
{ "result": "success", "details": "Account deleted successfully." }
- URL:
/unsuspend
- Method:
POST
- Request Body:
{ "user": "example_user" }
- Response:
{ "result": "success", "details": "Account unsuspended successfully." }
- URL:
/listusers
- Method:
GET
- Response:
[ { "username": "example_user", "email": "user@example.com" } ]
- URL:
/addzonerecord
- Method:
POST
- Request Body:
{ "domain": "example.com", "name": "www", "dnsclass": "IN", "ttl": "3600", "type": "A", "address": "192.0.2.1" }
- Response:
{ "result": "success", "details": "DNS zone record added successfully." }
- URL:
/removezonerecord
- Method:
POST
- Request Body:
{ "zone": "example.com", "line": "1" }
- Response:
{ "result": "success", "details": "DNS zone record removed successfully." }
- URL:
/editzonerecord
- Method:
POST
- Request Body:
{ "domain": "example.com", "line": "1", "name": "www", "dnsclass": "IN", "ttl": "3600", "type": "A", "address": "192.0.2.2" }
- Response:
{ "result": "success", "details": "DNS zone record edited successfully." }
- URL:
/backupconfig
- Method:
POST
- Request Body:
{ "backup_daily_retention": 7, "backup_monthly_enable": "yes", "backup_monthly_dates": [1, 15], "backup_monthly_retention": 3, "backup_weekly_day": "Sunday", "backup_weekly_enable": "yes", "backup_weekly_retention": 4, "backupdays": ["Monday", "Wednesday", "Friday"], "backupenable": "yes", "backuplogs": "yes", "backupsuspendedaccts": "yes", "backuptype": "full", "maximum_restore_timeout": 3600, "maximum_timeout": 1800, "min_free_space": 500, "min_free_space_unit": "MB", "mysqlbackup": "yes" }
- Response:
{ "result": "success", "details": "Backup configuration set successfully." }
- URL:
/backupdest
- Method:
POST
- Request Body:
{ "name": "example_backup", "type": "S3", "disabled": "no", "bucket": "example-bucket", "aws_access_key_id": "your_access_key_id", "password": "your_password", "application_key": "your_application_key", "application_key_id": "your_application_key_id", "bucket_id": "your_bucket_id", "bucket_name": "example-bucket", "script": "your_script", "host": "example.com", "username": "your_username", "client_id": "your_client_id", "client_secret": "your_client_secret", "authtype": "your_authtype", "path": "/backup/path" }
- Response:
{ "result": "success", "details": "Backup destination added successfully." }
- URL:
/getbackupconfig
- Method:
GET
- Response:
{ "backup_daily_retention": 7, "backup_monthly_enable": "yes", "backup_monthly_dates": [1, 15], "backup_monthly_retention": 3, "backup_weekly_day": "Sunday", "backup_weekly_enable": "yes", "backup_weekly_retention": "yes", "backupdays": ["Monday", "Wednesday", "Friday"], "backupenable": "yes", "backuplogs": "yes", "backupsuspendedaccts": "yes", "backuptype": "full", "maximum_restore_timeout": 3600, "maximum_timeout": 1800, "min_free_space": 500, "min_free_space_unit": "MB", "mysqlbackup": "yes" }
- URL:
/restorequeueadd
- Method:
POST
- Request Body:
{ "user": "example_user", "restore_point": "2022-01-01T00:00:00Z" }
- Response:
{ "result": "success", "details": "Restore task added to queue successfully." }
This project is licensed under the MIT License. See the LICENSE file for details.
We welcome contributions to improve this project! Here are some ways you can contribute:
- Report Bugs: If you find a bug, please open an issue on GitHub with detailed information on how to reproduce it.
- Feature Requests: If you have ideas for new features or improvements, feel free to open an issue or submit a pull request.
- Pull Requests: If you'd like to contribute code, fork the repository and create a new branch for your feature or bug fix. Submit a pull request with a clear description of your changes.
Please ensure your contributions adhere to our coding standards and include appropriate tests.
Thank you for your contributions!