Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,62 +6,137 @@ import gradio as gr
|
|
6 |
from fastapi import FastAPI, Request
|
7 |
from fastapi.responses import Response
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
#
|
16 |
-
|
17 |
-
|
18 |
-
def start_pufferpanel():
|
19 |
-
if not os.path.exists("pufferpanel"):
|
20 |
-
subprocess.run(
|
21 |
-
[
|
22 |
-
"wget",
|
23 |
-
"https://github.com/pufferpanel/pufferpanel/releases/download/v3.0.0-rc.14/pufferpanel_3.0.0-rc.14_linux_amd64.tar.gz",
|
24 |
-
"-O",
|
25 |
-
"pufferpanel.tar.gz",
|
26 |
-
],
|
27 |
-
check=True,
|
28 |
-
)
|
29 |
-
subprocess.run(["tar", "xvzf", "pufferpanel.tar.gz"], check=True)
|
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 |
# Gradio UI (clean)
|
|
|
6 |
from fastapi import FastAPI, Request
|
7 |
from fastapi.responses import Response
|
8 |
|
9 |
+
import os
|
10 |
+
import json
|
11 |
+
import secrets
|
12 |
+
from pathlib import Path
|
13 |
|
14 |
+
# Create necessary directories
|
15 |
+
Path("/workspace/pufferpanel_data").mkdir(parents=True, exist_ok=True)
|
16 |
+
Path("/workspace/pufferpanel_data/servers").mkdir(parents=True, exist_ok=True)
|
17 |
+
Path("/workspace/pufferpanel_data/modules").mkdir(parents=True, exist_ok=True)
|
18 |
+
Path("/workspace/pufferpanel_data/cache").mkdir(parents=True, exist_ok=True)
|
19 |
|
20 |
+
# Generate secure credentials
|
21 |
+
username = "admin" + secrets.token_hex(2)
|
22 |
+
password = secrets.token_urlsafe(16)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
+
# Create configuration
|
25 |
+
config = {
|
26 |
+
"web": {
|
27 |
+
"host": "0.0.0.0",
|
28 |
+
"port": 7860
|
29 |
+
},
|
30 |
+
"ssl": {
|
31 |
+
"enabled": False,
|
32 |
+
"redirect": False
|
33 |
+
},
|
34 |
+
"database": {
|
35 |
+
"url": "sqlite:/workspace/pufferpanel_data/data.db",
|
36 |
+
"type": "sqlite"
|
37 |
+
},
|
38 |
+
"data": {
|
39 |
+
"servers": "/workspace/pufferpanel_data/servers",
|
40 |
+
"modules": "/workspace/pufferpanel_data/modules",
|
41 |
+
"cache": "/workspace/pufferpanel_data/cache"
|
42 |
+
}
|
43 |
+
}
|
44 |
|
45 |
+
# Save configuration
|
46 |
+
with open('/etc/pufferpanel/config.json', 'w') as f:
|
47 |
+
json.dump(config, f, indent=2)
|
48 |
|
49 |
+
# Create Dockerfile
|
50 |
+
dockerfile_content = """# Use Ubuntu base image
|
51 |
+
FROM ubuntu:22.04
|
52 |
|
53 |
+
# Install dependencies
|
54 |
+
RUN apt-get update && \\
|
55 |
+
apt-get install -y wget curl sqlite3 && \\
|
56 |
+
rm -rf /var/lib/apt/lists/*
|
57 |
|
58 |
+
# Download and install PufferPanel
|
59 |
+
RUN wget -q https://github.com/pufferpanel/pufferpanel/releases/download/v3.0.0-rc.14/pufferpanel_3.0.0-rc.14_amd64.deb && \\
|
60 |
+
dpkg -i pufferpanel_3.0.0-rc.14_amd64.deb || apt-get install -f -y
|
61 |
+
|
62 |
+
# Create persistent storage directory
|
63 |
+
RUN mkdir -p /workspace/pufferpanel_data
|
64 |
+
|
65 |
+
# Copy configuration
|
66 |
+
COPY config.json /etc/pufferpanel/config.json
|
67 |
+
|
68 |
+
# Expose port
|
69 |
+
EXPOSE 7860
|
70 |
+
|
71 |
+
# Start command
|
72 |
+
CMD pufferpanel user add {username} --email {username}@example.com --password {password} --admin && \\
|
73 |
+
pufferpanel run
|
74 |
+
""".format(username=username, password=password)
|
75 |
+
|
76 |
+
with open('Dockerfile', 'w') as f:
|
77 |
+
f.write(dockerfile_content)
|
78 |
+
|
79 |
+
# Create README
|
80 |
+
readme_content = """---
|
81 |
+
title: PufferPanel
|
82 |
+
emoji: ๐ฎ
|
83 |
+
colorFrom: blue
|
84 |
+
colorTo: purple
|
85 |
+
sdk: docker
|
86 |
+
pinned: false
|
87 |
+
---
|
88 |
+
|
89 |
+
# PufferPanel on Hugging Face Spaces
|
90 |
+
|
91 |
+
This Space runs [PufferPanel](https://www.pufferpanel.com/), an open-source game server management panel.
|
92 |
+
|
93 |
+
## Access Information
|
94 |
+
|
95 |
+
- **Panel URL**: `https://YOUR_SPACE_NAME.hf.space`
|
96 |
+
- **Admin Username**: `{username}`
|
97 |
+
- **Admin Password**: `{password}`
|
98 |
+
|
99 |
+
## Features
|
100 |
+
|
101 |
+
- ๐น๏ธ Manage game servers from a web interface
|
102 |
+
- ๐ Persistent storage for servers and data
|
103 |
+
- ๐ Secure admin credentials
|
104 |
+
- โ๏ธ Supports various game servers
|
105 |
+
|
106 |
+
## First-Time Setup
|
107 |
+
|
108 |
+
1. Visit your Space URL after deployment
|
109 |
+
2. Login with the credentials above
|
110 |
+
3. Create your first game server
|
111 |
+
|
112 |
+
> **Note**: These credentials are randomly generated each time the Space is redeployed. For permanent access, configure environment variables as described below.
|
113 |
+
|
114 |
+
## Environment Variables
|
115 |
+
|
116 |
+
For permanent credentials, set these in your Space settings:
|
117 |
+
|
118 |
+
| Variable | Description | Default |
|
119 |
+
|----------|-------------|---------|
|
120 |
+
| `ADMIN_USERNAME` | Admin username | Randomly generated |
|
121 |
+
| `ADMIN_PASSWORD` | Admin password | Randomly generated |
|
122 |
+
| `PANEL_PORT` | Panel port | `7860` |
|
123 |
+
|
124 |
+
## Limitations
|
125 |
+
|
126 |
+
- Spaces shut down after 48 hours of inactivity
|
127 |
+
- Storage is preserved between sessions
|
128 |
+
- Resource-intensive game servers may not run well
|
129 |
+
|
130 |
+
[PufferPanel Documentation](https://docs.pufferpanel.com/)
|
131 |
+
""".format(username=username, password=password)
|
132 |
+
|
133 |
+
with open('README.md', 'w') as f:
|
134 |
+
f.write(readme_content)
|
135 |
|
136 |
+
print("Docker setup complete!")
|
137 |
+
print(f"Admin Username: {username}")
|
138 |
+
print(f"Admin Password: {password}")
|
139 |
+
print("Push these files to your Hugging Face Space repository")
|
140 |
|
141 |
# ==========================
|
142 |
# Gradio UI (clean)
|