#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ WebShell 系统启动脚本 """ import os import sys import logging from app import app, socketio def setup_logging(): """设置日志""" logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', handlers=[ logging.StreamHandler(sys.stdout), logging.FileHandler('webshell.log', encoding='utf-8') ] ) def check_dependencies(): """检查依赖""" try: import flask import flask_socketio print("✓ 依赖检查通过") return True except ImportError as e: print(f"✗ 缺少依赖: {e}") print("请运行: pip install -r requirements.txt") return False def main(): """主函数""" print("="*50) print("🚀 WebShell 管理系统") print("="*50) # 检查依赖 if not check_dependencies(): sys.exit(1) # 设置日志 setup_logging() # 获取配置 host = os.environ.get('HOST', '0.0.0.0') port = int(os.environ.get('PORT', 5000)) debug = os.environ.get('DEBUG', 'True').lower() == 'true' print(f"📡 服务器地址: http://{host}:{port}") print(f"🔧 调试模式: {'开启' if debug else '关闭'}") print(f"📁 工作目录: {os.getcwd()}") print("="*50) print("💡 使用说明:") print(" - 在浏览器中访问上述地址") print(" - 按 Ctrl+C 停止服务器") print("="*50) try: # 启动服务器 socketio.run( app, host=host, port=port, debug=debug, allow_unsafe_werkzeug=True ) except KeyboardInterrupt: print("\n👋 服务器已停止") except Exception as e: print(f"❌ 启动失败: {e}") sys.exit(1) if __name__ == '__main__': main()