Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files5 unmodified lines67891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162635 unmodified linesENV SERVER_PORT=8012ENV KKFILEVIEW_SECURITY_TRUST_HOST=default# 创建 Token 验证脚本RUN cat > /token_check.py << 'PYEOF'#!/usr/bin/env python3import http.serverimport socketserverimport urllib.requestimport osfrom urllib.parse import urlparse, parse_qsPORT = 7860BACKEND = "http://127.0.0.1:8012"TOKEN = os.getenv("ACCESS_TOKEN", "changeme")class TokenHandler(http.server.SimpleHTTPRequestHandler):def do_GET(self):parsed = urlparse(self.path)params = parse_qs(parsed.query)# 检查 tokenif params.get('token', [''])[0] != TOKEN:self.send_response(403)self.end_headers()self.wfile.write(b'Access denied. Please provide valid token.')return# 转发到后端url = BACKEND + self.pathtry:response = urllib.request.urlopen(url)self.send_response(response.getcode())for header, value in response.headers.items():self.send_header(header, value)self.end_headers()self.wfile.write(response.read())except Exception as e:self.send_error(502, f"Backend error: {str(e)}")with socketserver.TCPServer(("", PORT), TokenHandler) as httpd:print(f"Token auth running. Access with ?token={TOKEN}")httpd.serve_forever()PYEOFRUN chmod +x /token_check.pyRUN printf '#!/bin/bash\n\Xvfb :99 -screen 0 1024x768x24 &\n\export DISPLAY=:99\n\sleep 2\n\/opt/kkFileView/bin/kkFileView --server.port=8012 &\n\sleep 5\n\python3 /token_check.py\n' > /start.sh && chmod +x /start.shEXPOSE 78605 unmodified lines67891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465665 unmodified linesENV SERVER_PORT=8012ENV KKFILEVIEW_SECURITY_TRUST_HOST=defaultENV ACCESS_TOKEN=your-secret-token-here# 创建 Token 验证脚本(使用 printf)RUN printf '#!/usr/bin/env python3\n\import http.server\n\import socketserver\n\import urllib.request\n\import os\n\from urllib.parse import urlparse, parse_qs\n\\n\PORT = 7860\n\BACKEND = "http://127.0.0.1:8012"\n\TOKEN = os.getenv("ACCESS_TOKEN", "changeme")\n\\n\class TokenHandler(http.server.SimpleHTTPRequestHandler):\n\def do_GET(self):\n\parsed = urlparse(self.path)\n\params = parse_qs(parsed.query)\n\\n\# 检查 token\n\if params.get("token", [""])[0] != TOKEN:\n\self.send_response(403)\n\self.end_headers()\n\self.wfile.write(b"Access denied. Please provide valid token.")\n\return\n\\n\# 转发到后端\n\url = BACKEND + self.path\n\try:\n\response = urllib.request.urlopen(url)\n\self.send_response(response.getcode())\n\for header, value in response.headers.items():\n\self.send_header(header, value)\n\self.end_headers()\n\self.wfile.write(response.read())\n\except Exception as e:\n\self.send_error(502, f"Backend error: {str(e)}")\n\\n\with socketserver.TCPServer(("", PORT), TokenHandler) as httpd:\n\print(f"Token auth running. Access with ?token={TOKEN}")\n\httpd.serve_forever()\n' > /token_check.py && \chmod +x /token_check.py# 启动脚本RUN printf '#!/bin/bash\n\echo "=== Starting kkFileView with Token Auth ==="\n\echo "Access token: [HIDDEN]"\n\echo ""\n\Xvfb :99 -screen 0 1024x768x24 &\n\export DISPLAY=:99\n\sleep 2\n\/opt/kkFileView/bin/kkFileView --server.port=8012 &\n\sleep 5\n\python3 /token_check.py\n' > /start.sh && \chmod +x /start.shEXPOSE 7860
Dockerfile+47-44