File size: 2,012 Bytes
a4d706b |
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 |
#!/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() |