Spaces:
Paused
Paused
proletcraft commited on
Commit ·
83c74a5
1
Parent(s): f3c0252
Switch to standard Gradio Python app
Browse files- Dockerfile +0 -25
- README.md +1 -1
- app.py +134 -0
- config.json +0 -57
- requirements.txt +1 -0
- start.sh +0 -6
Dockerfile
DELETED
|
@@ -1,25 +0,0 @@
|
|
| 1 |
-
FROM debian:bookworm-slim
|
| 2 |
-
|
| 3 |
-
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 4 |
-
curl \
|
| 5 |
-
ca-certificates \
|
| 6 |
-
unzip \
|
| 7 |
-
python3 \
|
| 8 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 9 |
-
|
| 10 |
-
# Install official Xray-core
|
| 11 |
-
RUN curl -sL https://github.com/XTLS/Xray-core/releases/download/v1.8.24/Xray-linux-64.zip -o /tmp/xray.zip \
|
| 12 |
-
&& unzip /tmp/xray.zip -d /usr/local/bin/ \
|
| 13 |
-
&& chmod +x /usr/local/bin/xray \
|
| 14 |
-
&& rm /tmp/xray.zip
|
| 15 |
-
|
| 16 |
-
WORKDIR /app
|
| 17 |
-
|
| 18 |
-
COPY config.json /app/config.json
|
| 19 |
-
COPY index.html /app/index.html
|
| 20 |
-
COPY start.sh /app/start.sh
|
| 21 |
-
RUN chmod +x /app/start.sh
|
| 22 |
-
|
| 23 |
-
EXPOSE 7860
|
| 24 |
-
|
| 25 |
-
CMD ["/app/start.sh"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
CHANGED
|
@@ -3,7 +3,7 @@ title: ProletCraft Server
|
|
| 3 |
emoji: ⚒️
|
| 4 |
colorFrom: red
|
| 5 |
colorTo: yellow
|
| 6 |
-
sdk:
|
| 7 |
app_port: 7860
|
| 8 |
pinned: false
|
| 9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
+
from aiohttp import web
|
| 6 |
+
|
| 7 |
+
ALLOWED_UUIDS = {
|
| 8 |
+
"91a77ee1-1918-66d1-398a-7ef36ab6f605", # leader
|
| 9 |
+
"51741641-3ea7-4aba-a78b-9241b29e453a", # Artur
|
| 10 |
+
"62a1f3e4-1205-48b0-b9b9-553a6ff50056", # Dima
|
| 11 |
+
"3d1cb43d-6b7b-462e-8c72-2696aa491459", # RinatA
|
| 12 |
+
"3315f393-8f7b-4983-8515-3b0326fa8084", # Tolyas
|
| 13 |
+
"223b5f2f-4c17-4182-9aec-1acc28939da2" # Misha
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
index_html = ""
|
| 17 |
+
if os.path.exists("index.html"):
|
| 18 |
+
with open("index.html", "r", encoding="utf-8") as f:
|
| 19 |
+
index_html = f.read()
|
| 20 |
+
|
| 21 |
+
async def handle_http_or_ws(request):
|
| 22 |
+
if request.headers.get("Upgrade", "").lower() == "websocket":
|
| 23 |
+
ws = web.WebSocketResponse()
|
| 24 |
+
await ws.prepare(request)
|
| 25 |
+
return await handle_vless_ws(ws)
|
| 26 |
+
|
| 27 |
+
return web.Response(text=index_html, content_type="text/html", headers={
|
| 28 |
+
"X-Powered-By": "ProletCraft HuggingFace Node"
|
| 29 |
+
})
|
| 30 |
+
|
| 31 |
+
async def handle_vless_ws(ws):
|
| 32 |
+
remote_reader = None
|
| 33 |
+
remote_writer = None
|
| 34 |
+
first_packet = True
|
| 35 |
+
|
| 36 |
+
try:
|
| 37 |
+
async for msg in ws:
|
| 38 |
+
if msg.type == web.WSMsgType.BINARY:
|
| 39 |
+
data = msg.data
|
| 40 |
+
if first_packet:
|
| 41 |
+
first_packet = False
|
| 42 |
+
if len(data) < 24:
|
| 43 |
+
await ws.close(code=1002, message=b"Short chunk")
|
| 44 |
+
return ws
|
| 45 |
+
|
| 46 |
+
user_uuid = str(uuid.UUID(bytes=data[1:17]))
|
| 47 |
+
if user_uuid not in ALLOWED_UUIDS:
|
| 48 |
+
await ws.close(code=1008, message=b"Unauthorized")
|
| 49 |
+
return ws
|
| 50 |
+
|
| 51 |
+
addon_len = data[17]
|
| 52 |
+
offset = 18 + addon_len
|
| 53 |
+
cmd = data[offset] # 1: TCP
|
| 54 |
+
offset += 1
|
| 55 |
+
port = struct.unpack('>H', data[offset:offset+2])[0]
|
| 56 |
+
offset += 2
|
| 57 |
+
addr_type = data[offset]
|
| 58 |
+
offset += 1
|
| 59 |
+
|
| 60 |
+
if addr_type == 1:
|
| 61 |
+
addr = ".".join(str(b) for b in data[offset:offset+4])
|
| 62 |
+
offset += 4
|
| 63 |
+
elif addr_type == 2:
|
| 64 |
+
domain_len = data[offset]
|
| 65 |
+
offset += 1
|
| 66 |
+
addr = data[offset:offset+domain_len].decode('utf-8')
|
| 67 |
+
offset += domain_len
|
| 68 |
+
elif addr_type == 3:
|
| 69 |
+
addr = ":".join(f"{data[offset+i]:02x}{data[offset+i+1]:02x}" for i in range(0, 16, 2))
|
| 70 |
+
offset += 16
|
| 71 |
+
else:
|
| 72 |
+
await ws.close(code=1002, message=b"Bad address type")
|
| 73 |
+
return ws
|
| 74 |
+
|
| 75 |
+
# Connect to destination
|
| 76 |
+
try:
|
| 77 |
+
remote_reader, remote_writer = await asyncio.wait_for(
|
| 78 |
+
asyncio.open_connection(addr, port), timeout=10
|
| 79 |
+
)
|
| 80 |
+
except Exception as e:
|
| 81 |
+
await ws.close(code=1006, message=str(e).encode('utf-8'))
|
| 82 |
+
return ws
|
| 83 |
+
|
| 84 |
+
# Send VLESS response: version 0, addons length 0
|
| 85 |
+
await ws.send_bytes(b'\x00\x00')
|
| 86 |
+
|
| 87 |
+
# Send initial payload if present
|
| 88 |
+
payload = data[offset:]
|
| 89 |
+
if payload:
|
| 90 |
+
remote_writer.write(payload)
|
| 91 |
+
await remote_writer.drain()
|
| 92 |
+
|
| 93 |
+
# Start background reader task from remote to websocket
|
| 94 |
+
async def remote_to_ws():
|
| 95 |
+
try:
|
| 96 |
+
while True:
|
| 97 |
+
chunk = await remote_reader.read(16384)
|
| 98 |
+
if not chunk:
|
| 99 |
+
break
|
| 100 |
+
await ws.send_bytes(chunk)
|
| 101 |
+
except Exception:
|
| 102 |
+
pass
|
| 103 |
+
finally:
|
| 104 |
+
if not ws.closed:
|
| 105 |
+
await ws.close()
|
| 106 |
+
|
| 107 |
+
asyncio.create_task(remote_to_ws())
|
| 108 |
+
else:
|
| 109 |
+
if remote_writer:
|
| 110 |
+
remote_writer.write(data)
|
| 111 |
+
await remote_writer.drain()
|
| 112 |
+
elif msg.type in (web.WSMsgType.CLOSE, web.WSMsgType.ERROR):
|
| 113 |
+
break
|
| 114 |
+
except Exception:
|
| 115 |
+
pass
|
| 116 |
+
finally:
|
| 117 |
+
if remote_writer:
|
| 118 |
+
try:
|
| 119 |
+
remote_writer.close()
|
| 120 |
+
await remote_writer.wait_closed()
|
| 121 |
+
except Exception:
|
| 122 |
+
pass
|
| 123 |
+
if not ws.closed:
|
| 124 |
+
await ws.close()
|
| 125 |
+
return ws
|
| 126 |
+
|
| 127 |
+
app = web.Application()
|
| 128 |
+
app.router.add_get('/', handle_http_or_ws)
|
| 129 |
+
app.router.add_get('/{tail:.*}', handle_http_or_ws)
|
| 130 |
+
|
| 131 |
+
if __name__ == '__main__':
|
| 132 |
+
port = int(os.environ.get('PORT', 7860))
|
| 133 |
+
print(f"Starting ProletCraft VLESS server on port {port}...")
|
| 134 |
+
web.run_app(app, host='0.0.0.0', port=port)
|
config.json
DELETED
|
@@ -1,57 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"log": {
|
| 3 |
-
"loglevel": "warning"
|
| 4 |
-
},
|
| 5 |
-
"inbounds": [
|
| 6 |
-
{
|
| 7 |
-
"port": 7860,
|
| 8 |
-
"listen": "0.0.0.0",
|
| 9 |
-
"protocol": "vless",
|
| 10 |
-
"settings": {
|
| 11 |
-
"clients": [
|
| 12 |
-
{
|
| 13 |
-
"id": "91a77ee1-1918-66d1-398a-7ef36ab6f605",
|
| 14 |
-
"email": "leader@proletcraft"
|
| 15 |
-
},
|
| 16 |
-
{
|
| 17 |
-
"id": "51741641-3ea7-4aba-a78b-9241b29e453a",
|
| 18 |
-
"email": "artur@proletcraft"
|
| 19 |
-
},
|
| 20 |
-
{
|
| 21 |
-
"id": "62a1f3e4-1205-48b0-b9b9-553a6ff50056",
|
| 22 |
-
"email": "dima@proletcraft"
|
| 23 |
-
},
|
| 24 |
-
{
|
| 25 |
-
"id": "3d1cb43d-6b7b-462e-8c72-2696aa491459",
|
| 26 |
-
"email": "rinata@proletcraft"
|
| 27 |
-
},
|
| 28 |
-
{
|
| 29 |
-
"id": "3315f393-8f7b-4983-8515-3b0326fa8084",
|
| 30 |
-
"email": "tolyas@proletcraft"
|
| 31 |
-
},
|
| 32 |
-
{
|
| 33 |
-
"id": "223b5f2f-4c17-4182-9aec-1acc28939da2",
|
| 34 |
-
"email": "misha@proletcraft"
|
| 35 |
-
}
|
| 36 |
-
],
|
| 37 |
-
"decryption": "none",
|
| 38 |
-
"fallbacks": [
|
| 39 |
-
{
|
| 40 |
-
"dest": 8081
|
| 41 |
-
}
|
| 42 |
-
]
|
| 43 |
-
},
|
| 44 |
-
"streamSettings": {
|
| 45 |
-
"network": "ws",
|
| 46 |
-
"wsSettings": {
|
| 47 |
-
"path": "/"
|
| 48 |
-
}
|
| 49 |
-
}
|
| 50 |
-
}
|
| 51 |
-
],
|
| 52 |
-
"outbounds": [
|
| 53 |
-
{
|
| 54 |
-
"protocol": "freedom"
|
| 55 |
-
}
|
| 56 |
-
]
|
| 57 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
aiohttp>=3.9.0
|
start.sh
DELETED
|
@@ -1,6 +0,0 @@
|
|
| 1 |
-
#!/bin/bash
|
| 2 |
-
# Start camouflage Minecraft web server on port 8081
|
| 3 |
-
python3 -m http.server 8081 --directory /app &
|
| 4 |
-
|
| 5 |
-
# Start Xray core on port 7860
|
| 6 |
-
exec /usr/local/bin/xray run -config /app/config.json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|