Spaces:
Runtime error
Runtime error
import os | |
import subprocess | |
import threading | |
import requests | |
import gradio as gr | |
from fastapi import FastAPI, Request | |
from fastapi.responses import Response | |
import os | |
import json | |
import secrets | |
from pathlib import Path | |
# Create necessary directories | |
Path("/workspace/pufferpanel_data").mkdir(parents=True, exist_ok=True) | |
Path("/workspace/pufferpanel_data/servers").mkdir(parents=True, exist_ok=True) | |
Path("/workspace/pufferpanel_data/modules").mkdir(parents=True, exist_ok=True) | |
Path("/workspace/pufferpanel_data/cache").mkdir(parents=True, exist_ok=True) | |
# Generate secure credentials | |
username = "admin" + secrets.token_hex(2) | |
password = secrets.token_urlsafe(16) | |
# Create configuration | |
config = { | |
"web": { | |
"host": "0.0.0.0", | |
"port": 7860 | |
}, | |
"ssl": { | |
"enabled": False, | |
"redirect": False | |
}, | |
"database": { | |
"url": "sqlite:/workspace/pufferpanel_data/data.db", | |
"type": "sqlite" | |
}, | |
"data": { | |
"servers": "/workspace/pufferpanel_data/servers", | |
"modules": "/workspace/pufferpanel_data/modules", | |
"cache": "/workspace/pufferpanel_data/cache" | |
} | |
} | |
# Save configuration | |
with open('/etc/pufferpanel/config.json', 'w') as f: | |
json.dump(config, f, indent=2) | |
# Create Dockerfile | |
dockerfile_content = """# Use Ubuntu base image | |
FROM ubuntu:22.04 | |
# Install dependencies | |
RUN apt-get update && \\ | |
apt-get install -y wget curl sqlite3 && \\ | |
rm -rf /var/lib/apt/lists/* | |
# Download and install PufferPanel | |
RUN wget -q https://github.com/pufferpanel/pufferpanel/releases/download/v3.0.0-rc.14/pufferpanel_3.0.0-rc.14_amd64.deb && \\ | |
dpkg -i pufferpanel_3.0.0-rc.14_amd64.deb || apt-get install -f -y | |
# Create persistent storage directory | |
RUN mkdir -p /workspace/pufferpanel_data | |
# Copy configuration | |
COPY config.json /etc/pufferpanel/config.json | |
# Expose port | |
EXPOSE 7860 | |
# Start command | |
CMD pufferpanel user add {username} --email {username}@example.com --password {password} --admin && \\ | |
pufferpanel run | |
""".format(username=username, password=password) | |
with open('Dockerfile', 'w') as f: | |
f.write(dockerfile_content) | |
# Create README | |
readme_content = """--- | |
title: PufferPanel | |
emoji: ๐ฎ | |
colorFrom: blue | |
colorTo: purple | |
sdk: docker | |
pinned: false | |
--- | |
# PufferPanel on Hugging Face Spaces | |
This Space runs [PufferPanel](https://www.pufferpanel.com/), an open-source game server management panel. | |
## Access Information | |
- **Panel URL**: `https://YOUR_SPACE_NAME.hf.space` | |
- **Admin Username**: `{username}` | |
- **Admin Password**: `{password}` | |
## Features | |
- ๐น๏ธ Manage game servers from a web interface | |
- ๐ Persistent storage for servers and data | |
- ๐ Secure admin credentials | |
- โ๏ธ Supports various game servers | |
## First-Time Setup | |
1. Visit your Space URL after deployment | |
2. Login with the credentials above | |
3. Create your first game server | |
> **Note**: These credentials are randomly generated each time the Space is redeployed. For permanent access, configure environment variables as described below. | |
## Environment Variables | |
For permanent credentials, set these in your Space settings: | |
| Variable | Description | Default | | |
|----------|-------------|---------| | |
| `ADMIN_USERNAME` | Admin username | Randomly generated | | |
| `ADMIN_PASSWORD` | Admin password | Randomly generated | | |
| `PANEL_PORT` | Panel port | `7860` | | |
## Limitations | |
- Spaces shut down after 48 hours of inactivity | |
- Storage is preserved between sessions | |
- Resource-intensive game servers may not run well | |
[PufferPanel Documentation](https://docs.pufferpanel.com/) | |
""".format(username=username, password=password) | |
with open('README.md', 'w') as f: | |
f.write(readme_content) | |
print("Docker setup complete!") | |
print(f"Admin Username: {username}") | |
print(f"Admin Password: {password}") | |
print("Push these files to your Hugging Face Space repository") | |
# ========================== | |
# Gradio UI (clean) | |
# ========================== | |
def launch_panel(): | |
return """ | |
<iframe src="/proxy/" style="width: 100%; height: 90vh; border: none;"></iframe> | |
""" | |
with gr.Blocks() as demo: | |
gr.Markdown("# ๐ PufferPanel on Hugging Face") | |
gr.HTML(value=launch_panel()) | |
demo.launch(server_name="0.0.0.0", server_port=7860, root_path="/") | |