Spaces:
Runtime error
Runtime error
File size: 4,249 Bytes
6082a39 1c22605 97fb843 1c22605 97fb843 6082a39 f4c7a67 97fb843 f4c7a67 97fb843 f4c7a67 97fb843 f4c7a67 97fb843 f4c7a67 97fb843 f4c7a67 fd9d9e6 f4c7a67 1c22605 f4c7a67 97fb843 f4c7a67 1c22605 97fb843 b4e0314 97fb843 b4e0314 97fb843 fd9d9e6 1c22605 97fb843 b4e0314 97fb843 1c22605 b4e0314 |
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 |
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="/")
|