Spaces:
Running
Running
File size: 3,998 Bytes
0c799ac e4cf850 919170c bbf8af3 e7e4e66 919170c e7e4e66 0c799ac ae0ce11 0c799ac ae0ce11 19c209b ae0ce11 19c209b ae0ce11 19c209b ae0ce11 19c209b ae0ce11 19c209b ae0ce11 19c209b ae0ce11 19c209b ae0ce11 19c209b ae0ce11 19c209b ae0ce11 19c209b ae0ce11 19c209b ae0ce11 19c209b ae0ce11 19c209b ae0ce11 19c209b e7e4e66 ae0ce11 0c799ac ae0ce11 19c209b ae0ce11 0c799ac ae0ce11 0c799ac ae0ce11 0c799ac ae0ce11 e7e4e66 ae0ce11 19c209b e4cf850 1930ef6 |
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 |
FROM ymlisoft/kkfileview
USER root
RUN apt-get update && apt-get install -y xvfb python3 && rm -rf /var/lib/apt/lists/*
ENV SERVER_PORT=8012
ENV KKFILEVIEW_SECURITY_TRUST_HOST=default
ENV ACCESS_TOKEN=your-secret-token-here
# 创建 Token 验证脚本(添加更多日志)
RUN printf '#!/usr/bin/env python3\n\
import http.server\n\
import socketserver\n\
import urllib.request\n\
import os\n\
import sys\n\
from urllib.parse import urlparse, parse_qs\n\
\n\
# 强制立即输出(不缓冲)\n\
sys.stdout = os.fdopen(sys.stdout.fileno(), "w", buffering=1)\n\
sys.stderr = os.fdopen(sys.stderr.fileno(), "w", buffering=1)\n\
\n\
PORT = 7860\n\
BACKEND = "http://127.0.0.1:8012"\n\
TOKEN = os.getenv("ACCESS_TOKEN", "changeme")\n\
\n\
print(f"[TOKEN_PROXY] Starting on port {PORT}", flush=True)\n\
print(f"[TOKEN_PROXY] Backend: {BACKEND}", flush=True)\n\
print(f"[TOKEN_PROXY] Token configured: {TOKEN[:5]}...", flush=True)\n\
\n\
class TokenHandler(http.server.SimpleHTTPRequestHandler):\n\
def log_message(self, format, *args):\n\
print(f"[TOKEN_PROXY] {format % args}", flush=True)\n\
\n\
def do_GET(self):\n\
parsed = urlparse(self.path)\n\
params = parse_qs(parsed.query)\n\
\n\
provided_token = params.get("token", [""])[0]\n\
\n\
if provided_token != TOKEN:\n\
print(f"[TOKEN_PROXY] Access denied - invalid token", flush=True)\n\
self.send_response(403)\n\
self.send_header("Content-type", "text/html")\n\
self.end_headers()\n\
self.wfile.write(b"<h1>Access Denied</h1><p>Please provide valid token in URL: ?token=YOUR_TOKEN</p>")\n\
return\n\
\n\
print(f"[TOKEN_PROXY] Valid token - forwarding request", flush=True)\n\
url = BACKEND + self.path\n\
try:\n\
response = urllib.request.urlopen(url, timeout=30)\n\
self.send_response(response.getcode())\n\
for header, value in response.headers.items():\n\
if header.lower() not in ["connection", "transfer-encoding"]:\n\
self.send_header(header, value)\n\
self.end_headers()\n\
self.wfile.write(response.read())\n\
except Exception as e:\n\
print(f"[TOKEN_PROXY] Backend error: {str(e)}", flush=True)\n\
self.send_error(502, f"Backend error: {str(e)}")\n\
\n\
do_POST = do_GET\n\
\n\
try:\n\
with socketserver.TCPServer(("", PORT), TokenHandler) as httpd:\n\
print(f"[TOKEN_PROXY] Server running successfully!", flush=True)\n\
print(f"[TOKEN_PROXY] Access URL: http://localhost:{PORT}/onlinePreview?url=YOUR_FILE&token={TOKEN}", flush=True)\n\
httpd.serve_forever()\n\
except Exception as e:\n\
print(f"[TOKEN_PROXY] FATAL ERROR: {str(e)}", flush=True)\n\
import traceback\n\
traceback.print_exc()\n\
sys.exit(1)\n' > /token_check.py && \
chmod +x /token_check.py
# 启动脚本(添加更多调试)
RUN printf '#!/bin/bash\n\
set -e\n\
\n\
echo "=== Starting kkFileView with Token Auth ==="\n\
echo "Step 1: Starting Xvfb..."\n\
Xvfb :99 -screen 0 1024x768x24 &\n\
XVFB_PID=$!\n\
export DISPLAY=:99\n\
echo "Xvfb started with PID: $XVFB_PID"\n\
sleep 2\n\
\n\
echo ""\n\
echo "Step 2: Starting kkFileView backend on port 8012..."\n\
/opt/kkFileView/bin/kkFileView --server.port=8012 &\n\
KKFILEVIEW_PID=$!\n\
echo "kkFileView started with PID: $KKFILEVIEW_PID"\n\
\n\
echo ""\n\
echo "Step 3: Waiting for backend to be ready..."\n\
for i in {1..30}; do\n\
if curl -s http://127.0.0.1:8012 > /dev/null 2>&1; then\n\
echo "Backend is ready!"\n\
break\n\
fi\n\
echo "Waiting... ($i/30)"\n\
sleep 1\n\
done\n\
\n\
echo ""\n\
echo "Step 4: Starting Token Auth Proxy on port 7860..."\n\
echo "Python version: $(python3 --version)"\n\
echo ""\n\
python3 -u /token_check.py\n' > /start.sh && \
chmod +x /start.sh
EXPOSE 7860
CMD ["/start.sh"]
|