A Python script that automates the login and SSL certificate retrieval process from Hestia Control Panel (HestiaCP) web interfaces.
- Automated Login Flow: Handles complete authentication with username/password
- Session Management: Manages cookies and CSRF tokens automatically
- SSL Certificate Extraction: Retrieves certificates, private keys, and CA bundles
- Batch Processing: Fetches certificates for all domains or specific domain
- File Output: Saves certificates to organized files (CRT, KEY, CA, fullchain)
- Rich Logging: Enhanced logging with color output and debug mode
- Error Handling: Comprehensive error handling with detailed feedback
The script automatically installs required dependencies, but you can also install them manually:
pip install httpx rich rich-argparsehttpx- Modern HTTP client for API requestsrich- Rich text and beautiful formatting in terminalrich-argparse- Rich help formatter for argparse
- Clone or download the script:
git clone <repository-url>
cd Hastia_Panel_CertFetcher- Make the script executable (optional):
chmod +x cert_fetcher.pypython cert_fetcher.py -U https://your-hestia-panel.com -u username -p password# Write certificates to files
python cert_fetcher.py -U https://panel.example.com -u admin -p password -w
# Specify custom output directory
python cert_fetcher.py -U https://panel.example.com -u admin -p password -w -o /path/to/certs
# Fetch certificate for specific domain only
python cert_fetcher.py -U https://panel.example.com -u admin -p password -w -d example.com
# Enable debug logging
python cert_fetcher.py -U https://panel.example.com -u admin -p password -w --debug| Argument | Short | Required | Description |
|---|---|---|---|
--url |
-U |
Yes | Base URL of the Hestia Control Panel |
--username |
-u |
Yes | Username for login |
--password |
-p |
Yes | Password for login |
--write-to-file |
-w |
No | Write certificates to files |
--output-dir |
-o |
No | Output directory (default: ./certificates) |
--domain |
-d |
No | Specific domain to fetch |
--debug |
No | Enable debug logging | |
--version |
-v |
No | Show version and exit |
--help |
-h |
No | Show help message |
When using the --write-to-file option, the script creates the following files for each domain:
certificates/
├── example.com.crt # SSL Certificate
├── example.com.key # Private Key
├── example.com.ca # Certificate Authority Bundle
└── fullchain_example.com.pem # Full Certificate Chain (cert + CA)
python cert_fetcher.py -U https://panel.mydomain.com -u admin -p mypassword -wpython cert_fetcher.py \
-U https://control.example.com \
-u username \
-p password \
-w \
-o /etc/ssl/certs \
--debugpython cert_fetcher.py \
-U https://hestia.example.com \
-u admin \
-p secretpass \
-w \
-d mydomain.com- Credentials: Never hardcode credentials. Use environment variables or secure credential storage
- SSL Verification: The script disables SSL verification by default for self-signed panels
- File Permissions: Ensure certificate files have appropriate permissions (600/644)
- Logging: Avoid debug mode in production to prevent credential leakage
export HESTIA_URL="https://panel.example.com"
export HESTIA_USER="admin"
export HESTIA_PASS="password"
python cert_fetcher.py -U "$HESTIA_URL" -u "$HESTIA_USER" -p "$HESTIA_PASS" -w-
Login Failed
- Verify URL, username, and password
- Check if 2FA is enabled (not currently supported)
- Ensure the panel is accessible
-
No Certificates Found
- Verify domain exists in the panel
- Check if SSL is configured for the domain
- Use debug mode to see detailed logs
-
Permission Denied
- Check output directory permissions
- Ensure you have write access to the target directory
Enable debug mode to see detailed information:
python cert_fetcher.py -U https://panel.com -u user -p pass --debugDebug mode shows:
- HTTP requests and responses
- Cookie and session management
- Token extraction process
- Certificate parsing details
-
Login Process:
- GET
/login/- Fetch login page and extract CSRF token - POST username with token
- POST password with token
- Verify successful authentication
- GET
-
Certificate Retrieval:
- GET
/list/web/- Fetch domain list - For each domain: GET
/edit/web/{domain}- Fetch certificate page - Parse HTML to extract certificate, key, and CA values
- Save to files if requested
- GET
-
Session Management:
- Automatically handles HESTIASID cookies
- Updates CSRF tokens for each request
- Maintains proper referer headers
The main class that handles the certificate fetching process.
run()- Main entry point, executes the full workflowfull_login_flow()- Handles authentication and certificate retrievalwrite_certificate_to_file(domain_data)- Saves certificates to files
The class accepts an args object with the following attributes:
url- Panel URLusername- Login usernamepassword- Login passwordwrite_to_file- Boolean for file outputoutput_dir- Output directory pathdomain- Specific domain filterdebug- Debug logging flag
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Initial release
- Basic login and certificate retrieval
- File output support
- Debug logging
- Rich terminal output
For issues, questions, or contributions, please open an issue on the project repository.