File size: 5,543 Bytes
32e4bbf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
---
title: Cloudflare Manager
emoji: βοΈ
colorFrom: orange
colorTo: yellow
sdk: gradio
sdk_version: "4.0.0"
app_file: app.py
pinned: false
license: mit
---
# Cloudflare Multi-Account Manager
π A comprehensive web interface for managing Cloudflare Pages, Domains, and Workers.
## Features
β
**Pages Management**
- Create and deploy Pages projects
- List all projects
- View deployment URLs
β
**Domain & Nameservers**
- Create DNS zones
- Get nameservers for domain registrars
- Bind custom domains to Pages projects
β
**Worker Routes**
- Configure worker routes
- Add custom domains to workers
- Manage route patterns
## Quick Start
### Using the Web Interface
1. Enter your Cloudflare Email and API Token
2. Click "Test Connection" to verify
3. Use the tabs to manage your resources
### Getting Your API Token
1. Go to https://dash.cloudflare.com/profile/api-tokens
2. Create a new token with these permissions:
- Account > Cloudflare Pages > Edit
- Zone > DNS > Edit
- Zone > Workers Routes > Edit
3. Copy the token and paste it in the interface
## Docker Deployment
Build and run with Docker:
```bash
# Build the image
docker build -t cloudflare-manager .
# Run the container
docker run -p 7860:7860 cloudflare-manager
```
Access at: http://localhost:7860
### With Environment Variables
```bash
docker run -p 7860:7860 \
-e CLOUDFLARE_EMAIL="your-email@example.com" \
-e CLOUDFLARE_TOKEN="your-api-token" \
cloudflare-manager
```
## Hugging Face Spaces Deployment
This app is designed to run on Hugging Face Spaces:
1. Create a new Space on Hugging Face
2. Select "Gradio" as the SDK
3. Upload all files or connect to Git
4. The app will automatically deploy
### Setting Secrets in Hugging Face
For better security, set your credentials as Secrets:
1. Go to your Space settings
2. Add secrets:
- `CLOUDFLARE_EMAIL`: Your Cloudflare email
- `CLOUDFLARE_TOKEN`: Your API token
3. The app will automatically use these credentials
## Local Development
```bash
# Install dependencies
pip install -r requirements.txt
# Run the app
python3 app.py
```
Access at: http://localhost:7860
## Python API
You can also use the Python API directly:
```python
from cloudflare_manager import CloudflareManager, CloudflareAccount
# Initialize
account = CloudflareAccount(
email="your-email@example.com",
token="your-api-token"
)
cf = CloudflareManager(account)
# Create Pages project
cf.create_pages_project("my-site", "main")
# Get nameservers
zone = cf.create_zone("example.com")
print(zone["name_servers"])
# Bind domain
cf.add_pages_domain("my-site", "example.com")
```
## CLI Tools
Run interactive commands:
```bash
# Quick start wizard
python3 quickstart.py
# Interactive menu
python3 cloudflare_manager.py
# Run examples
python3 example_usage.py
# Run tests
python3 test_manager.py
```
## Project Structure
```
.
βββ app.py # Gradio web interface
βββ cloudflare_manager.py # Core library
βββ Dockerfile # Docker configuration
βββ requirements.txt # Python dependencies
βββ quickstart.py # CLI quick start
βββ example_usage.py # Usage examples
βββ test_manager.py # Test suite
βββ docs/ # Documentation
βββ README.md
βββ GET_STARTED.md
βββ USAGE_GUIDE.md
βββ API_REFERENCE.md
```
## Documentation
- **[Quick Start Guide](GET_STARTED.md)** - Get started in 5 minutes
- **[Usage Guide](USAGE_GUIDE.md)** - Complete usage examples
- **[API Reference](API_REFERENCE.md)** - Full API documentation
- **[Project Summary](PROJECT_SUMMARY.md)** - Technical overview
## Common Use Cases
### 1. Deploy a Static Website
```python
# Create project
cf.create_pages_project("my-blog", "main")
# Deploy files
cf.deploy_pages_project("my-blog", "./public", "main")
# Add custom domain
zone = cf.create_zone("myblog.com")
cf.add_pages_domain("my-blog", "myblog.com")
# Get nameservers to set in registrar
print(zone["name_servers"])
```
### 2. Configure API Subdomain
```python
# Get zone
zone = cf.get_zone_by_name("example.com")
# Create worker route
cf.create_worker_route(
zone_id=zone["id"],
pattern="example.com/api/*",
script_name="api-worker"
)
# Add custom subdomain
cf.add_worker_domain(
hostname="api.example.com",
service="api-worker",
zone_id=zone["id"]
)
```
## Troubleshooting
### API Token Errors
**Error**: "Invalid request headers"
**Solution**: Make sure your API token has the correct permissions:
- Account > Cloudflare Pages > Edit
- Zone > DNS > Edit
- Zone > Workers Routes > Edit
### Zone Not Found
**Error**: "Zone not found"
**Solution**: Create the zone first:
```python
cf.create_zone("example.com")
```
### DNS Propagation
After adding a domain:
1. Update nameservers at your registrar
2. Wait 5-30 minutes for DNS propagation
3. Check status: `cf.get_zone_by_name("example.com")`
## Security
- Never commit API tokens to Git
- Use environment variables or Hugging Face Secrets
- Rotate tokens regularly
- Use least-privilege permissions
## Support
- π Full documentation in the `/docs` folder
- π Report issues on GitHub
- π¬ Ask questions in Hugging Face Discussions
## License
MIT License - Free to use and modify
## Credits
Built with:
- Python 3.10+
- Gradio for the web interface
- Cloudflare API
- Docker for containerization
---
**Version**: 1.0.0
**Last Updated**: 2024-01-27
**Status**: β
Production Ready
|