This commit is contained in:
unknown
2026-03-21 07:26:38 +09:00
parent 166d94fca4
commit 40150cd66d
406 changed files with 34179 additions and 55658 deletions
+79 -5
View File
@@ -333,7 +333,7 @@ def update_server_list():
try:
path.write_text(content, encoding="utf-8")
result = subprocess.run(
[sys.executable, str(Path(Config.SERVER_LIST_FOLDER) / "excel.py")],
[sys.executable, str(Path(Config.SERVER_LIST_FOLDER) / "unified_excel_generator.py"), "--mode", "mac"],
capture_output=True,
text=True,
check=True,
@@ -373,7 +373,7 @@ def update_guid_list():
logging.info(f"GUID 슬롯 우선순위: {slot_priority}")
result = subprocess.run(
[sys.executable, str(Path(Config.SERVER_LIST_FOLDER) / "GUIDtxtT0Execl.py")],
[sys.executable, str(Path(Config.SERVER_LIST_FOLDER) / "unified_excel_generator.py"), "--mode", "guid"],
capture_output=True,
text=True,
check=True,
@@ -417,8 +417,8 @@ def update_gpu_list():
# 2) 엑셀 생성 실행 (GPU 프리셋)
cmd = [
sys.executable,
str(script_path),
"--preset", "gpu",
str(Path(Config.SERVER_LIST_FOLDER) / "unified_excel_generator.py"),
"--mode", "gpu",
"--list-file", str(list_path),
]
result = subprocess.run(
@@ -522,4 +522,78 @@ def scan_network():
except Exception as e:
logging.error(f"Scan network fatal error: {e}")
return jsonify({"success": False, "error": f"서버 내부 오류: {str(e)}"}), 500
return jsonify({"success": False, "error": f"서버 내부 오류: {str(e)}"}), 500
@utils_bp.route("/api/system/control", methods=["POST"])
@login_required
def system_control():
"""
시스템 제어 명령 실행 (Power ON/OFF, Log Clear 등)
"""
data = request.get_json(silent=True) or {}
action = data.get("action")
ips = data.get("ips", [])
if not action or not ips:
return jsonify({"success": False, "error": "Action 또는 IP 목록이 없습니다."}), 400
# 통합 스크립트 사용
script_name = "unified/system_control.py"
script_path = Path(Config.SCRIPT_FOLDER) / script_name
if not script_path.exists():
return jsonify({"success": False, "error": f"스크립트 파일을 찾을 수 없습니다: {script_name}"}), 500
# 임시 IP 파일 생성
import tempfile
try:
# data/temp/uploads 폴더 사용
temp_dir = Path(Config.UPLOAD_FOLDER)
temp_dir.mkdir(parents=True, exist_ok=True)
with tempfile.NamedTemporaryFile(mode='w+', delete=False, dir=temp_dir, suffix=".txt", encoding='utf-8') as tf:
tf.write("\n".join(ips))
temp_ip_file = tf.name
# 스크립트 실행: python unified/system_control.py <action> <ip_file>
cmd = [sys.executable, str(script_path), action, temp_ip_file]
logging.info(f"[SystemControl] Executing {action} with {len(ips)} IPs (Unified Script)...")
# 타임아웃 넉넉하게 (작업에 따라 다름)
timeout = 600 if action in ["tsr_collect", "tsr_save"] else 300
result = subprocess.run(
cmd,
capture_output=True,
text=True,
check=False, # 에러 발생해도 결과 받음
timeout=timeout
)
# 임시 파일 삭제
try:
os.remove(temp_ip_file)
except OSError:
pass
if result.returncode == 0:
logging.info(f"[SystemControl] Success: {result.stdout}")
return jsonify({
"success": True,
"message": f"작업({action})이 성공적으로 완료되었습니다.",
"details": result.stdout
})
else:
logging.error(f"[SystemControl] Failed: {result.stderr}")
return jsonify({
"success": False,
"error": f"스크립트 실행 중 오류가 발생했습니다.\n{result.stderr}"
}), 500
except subprocess.TimeoutExpired:
return jsonify({"success": False, "error": "스크립트 실행 시간이 초과되었습니다."}), 504
except Exception as e:
logging.error(f"[SystemControl] Exception: {e}")
return jsonify({"success": False, "error": str(e)}), 500