fix(core,installer): 프로세스 출력 인코딩으로 인한 JSON 빈 응답 차단
한국어 Windows 에서 whoami 가 CP949 로 출력해 계정명에 한글이 있으면 invalid UTF-8 이 응답 배열에 실리고 json_encode 가 false 를 반환한다. echo false 는 빈 문자열이라 HTTP 200 + 빈 본문이 나가는데 예외도 로그도 남지 않아, 설치 마법사 2단계가 진행 불가 상태로 멈춘다. 2026-07 수정(7.0.2)은 로그 축 4곳만 막았다. 출처에서 정규화하고(1차), 응답 경계를 단일 헬퍼로 닫고(2차), 실패 시 문제 필드 경로를 로그에 남기도록(3차) 세 층으로 처리해 다른 경로가 열린 채 남지 않게 했다. 정규화는 복원 가능한 코드페이지 출력을 먼저 되살리므로, 종전 mb_scrub 단독 처리와 달리 한글이 U+FFFD 로 훼손되지 않는다. 같은 원인으로 한국어 Windows 에서 관리자 환경설정의 시스템 정보가 500 이 되던 것도 함께 막았다.
This commit is contained in:
1 parent
f094a5f3fc
commit
01d319e74b
37 files changed
+1662
-277
No files matched your search
@@ -15,6 +15,7 @@ use App\Support\PrivilegedDatabaseAccounts;
|
||||
|
||||
// 실행 바이너리 경로 허용 형태 정책 — 인스톨러 API 와 설치 워커가 같은 규칙을 공유한다.
|
||||
// 한쪽만 고치면 다른 쪽이 우회로가 되므로 의존성 없는 공용 파일로 두고 양쪽에서 로드한다.
|
||||
require_once __DIR__.'/../includes/utf8.php';
|
||||
require_once __DIR__.'/../includes/binary-path-policy.php';
|
||||
|
||||
/**
|
||||
@@ -87,7 +88,7 @@ class ValidationApi
|
||||
$requirements['is_windows'] = isWindows();
|
||||
|
||||
// JSON 응답 반환
|
||||
echo json_encode($requirements, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
echo installer_json_encode($requirements, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +103,7 @@ class ValidationApi
|
||||
// POST 메서드만 허용
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
http_response_code(405);
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('api_method_not_allowed'),
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
@@ -204,7 +205,7 @@ class ValidationApi
|
||||
}
|
||||
|
||||
// 성공 응답
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => true,
|
||||
'message' => $message,
|
||||
'type' => $type,
|
||||
@@ -229,7 +230,7 @@ class ValidationApi
|
||||
logInstallationError(lang('error_db_connection_failed', ['error' => $e->getMessage()]), $e);
|
||||
|
||||
// 에러 응답 (200 OK + success: false)
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('error_db_connection_failed_detail', ['type' => ($isReadDb ? 'Read' : 'Write'), 'error' => $e->getMessage()]),
|
||||
'type' => $type ?? 'write',
|
||||
@@ -250,7 +251,7 @@ class ValidationApi
|
||||
logInstallationError(lang('error_db_test_failed'), $e);
|
||||
|
||||
// 에러 응답 (200 OK + success: false)
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'message' => $e->getMessage(),
|
||||
'type' => $type ?? 'write',
|
||||
@@ -774,7 +775,7 @@ class ValidationApi
|
||||
$phpForComposer = ! empty($found) ? $found[0]['path'] : 'php';
|
||||
$composerResult = $this->detectComposerBinary($phpForComposer);
|
||||
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => ! empty($found),
|
||||
'binaries' => $found,
|
||||
'default_php_available' => $defaultPhpAvailable,
|
||||
@@ -833,7 +834,7 @@ class ValidationApi
|
||||
|
||||
$result = $this->validatePhpPath($path);
|
||||
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => $result['valid'],
|
||||
'version' => $result['version'],
|
||||
'message' => $result['message'],
|
||||
@@ -856,7 +857,7 @@ class ValidationApi
|
||||
|
||||
$result = $this->validateComposerPath($composerPath, $phpPath);
|
||||
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => $result['valid'],
|
||||
'version' => $result['version'],
|
||||
'message' => $result['message'],
|
||||
@@ -871,7 +872,7 @@ class ValidationApi
|
||||
{
|
||||
$path = $_GET['path'] ?? '';
|
||||
if (empty($path)) {
|
||||
echo json_encode(['success' => false, 'message' => lang('error_path_required')], JSON_UNESCAPED_UNICODE);
|
||||
echo installer_json_encode(['success' => false, 'message' => lang('error_path_required')], JSON_UNESCAPED_UNICODE);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -881,7 +882,7 @@ class ValidationApi
|
||||
// 상대경로 부모 추적이 필요한 시나리오가 없다.
|
||||
$hasParentSegment = preg_match('#(^|[/\\\\])\.\.([/\\\\]|$)#', $path) === 1;
|
||||
if ($hasParentSegment || str_contains($path, "\0")) {
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('error_core_pending_path_invalid'),
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
@@ -898,7 +899,7 @@ class ValidationApi
|
||||
if ($resolved === false || ! is_dir($resolved)) {
|
||||
// 존재 여부/타입 차이를 응답으로 분기하지 않고 단일 메시지로 통일하여
|
||||
// 임의 경로 enumeration 신호 차단.
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('error_core_pending_path_invalid'),
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
@@ -907,7 +908,7 @@ class ValidationApi
|
||||
}
|
||||
|
||||
$writable = is_writable($resolved);
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => $writable,
|
||||
'message' => $writable
|
||||
? lang('success_core_pending_path')
|
||||
@@ -1147,7 +1148,7 @@ class ValidationApi
|
||||
private function error400(string $message): void
|
||||
{
|
||||
http_response_code(400);
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'error' => 'Bad Request',
|
||||
'message' => $message,
|
||||
@@ -1167,7 +1168,7 @@ class ValidationApi
|
||||
|
||||
// 에러 응답
|
||||
http_response_code(500);
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'error' => 'Internal Server Error',
|
||||
'message' => $e->getMessage(),
|
||||
|
||||
@@ -5,14 +5,12 @@
|
||||
*
|
||||
* Step 5 진입 시 JavaScript에서 호출하여 .env 파일의
|
||||
* 존재 여부 및 쓰기 가능 여부를 확인합니다.
|
||||
*
|
||||
* @package G7\Installer
|
||||
*/
|
||||
|
||||
// 필수 파일 include
|
||||
require_once __DIR__ . '/../includes/config.php';
|
||||
require_once __DIR__ . '/../includes/functions.php';
|
||||
require_once __DIR__ . '/_guard.php';
|
||||
require_once __DIR__.'/../includes/config.php';
|
||||
require_once __DIR__.'/../includes/functions.php';
|
||||
require_once __DIR__.'/_guard.php';
|
||||
installer_guard_or_410();
|
||||
|
||||
// JSON 응답 헤더
|
||||
@@ -21,14 +19,14 @@ header('Content-Type: application/json; charset=utf-8');
|
||||
// GET 요청만 허용
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
|
||||
http_response_code(405);
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Only GET requests are allowed.',
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$envPath = BASE_PATH . '/.env';
|
||||
$envPath = BASE_PATH.'/.env';
|
||||
|
||||
// 소유자 === 웹 서버 사용자 여부 판별 (chgrp/sudo 생략 기준)
|
||||
$webUser = getWebServerUser();
|
||||
@@ -37,7 +35,7 @@ $baseOwner = function_exists('posix_getpwuid') && function_exists('posix_getuid'
|
||||
: null;
|
||||
$ownerIsWebUser = $webUser && $baseOwner && $webUser === $baseOwner;
|
||||
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'env_exists' => file_exists($envPath),
|
||||
'env_writable' => file_exists($envPath) && is_writable($envPath),
|
||||
'path' => BASE_PATH,
|
||||
|
||||
@@ -37,7 +37,7 @@ if (session_status() === PHP_SESSION_ACTIVE) {
|
||||
|
||||
ignore_user_abort(true);
|
||||
|
||||
$accepted = json_encode(['accepted' => true]);
|
||||
$accepted = installer_json_encode(['accepted' => true]);
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
header('Content-Length: '.strlen($accepted));
|
||||
|
||||
@@ -36,7 +36,7 @@ header('Content-Type: application/json; charset=UTF-8');
|
||||
*/
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
http_response_code(405);
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('error_method_not_allowed'),
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
@@ -58,7 +58,7 @@ try {
|
||||
// state.json에도 config가 없으면 에러
|
||||
if (empty($config)) {
|
||||
http_response_code(400);
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('error_config_not_in_session'),
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
@@ -108,7 +108,7 @@ try {
|
||||
|
||||
if (! empty($missingFields)) {
|
||||
http_response_code(400);
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('error_required_fields_missing', ['fields' => implode(', ', $missingFields)]),
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
@@ -125,7 +125,7 @@ try {
|
||||
|
||||
if (! empty($missingRequiredFiles)) {
|
||||
http_response_code(400);
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('error_env_not_found'),
|
||||
'env_required' => true,
|
||||
@@ -250,7 +250,7 @@ try {
|
||||
/**
|
||||
* 응답 JSON 준비 (echo 이전에 미리 문자열화하여 Content-Length 계산용)
|
||||
*/
|
||||
$responseJson = json_encode([
|
||||
$responseJson = installer_json_encode([
|
||||
'success' => true,
|
||||
'status' => 'started',
|
||||
'message' => lang('success_installation_started'),
|
||||
@@ -374,7 +374,7 @@ try {
|
||||
|
||||
// 에러 응답
|
||||
http_response_code(500);
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('error_installation_start_exception', ['error' => $e->getMessage()]),
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
|
||||
@@ -31,16 +31,14 @@
|
||||
* 적용하지 않음 — SSE 호환성 사전 체크(sse-probe.php) 가 buffered 환경을 감지하면
|
||||
* 클라이언트가 폴링 모드로 fallback.
|
||||
* ============================================================================
|
||||
*
|
||||
* @package G7\Installer
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../includes/config.php';
|
||||
require_once __DIR__ . '/../includes/functions.php';
|
||||
require_once __DIR__ . '/../includes/installer-state.php';
|
||||
require_once __DIR__ . '/../includes/progress-emitter.php';
|
||||
require_once __DIR__ . '/../includes/task-runner.php';
|
||||
require_once __DIR__ . '/_guard.php';
|
||||
require_once __DIR__.'/../includes/config.php';
|
||||
require_once __DIR__.'/../includes/functions.php';
|
||||
require_once __DIR__.'/../includes/installer-state.php';
|
||||
require_once __DIR__.'/../includes/progress-emitter.php';
|
||||
require_once __DIR__.'/../includes/task-runner.php';
|
||||
require_once __DIR__.'/_guard.php';
|
||||
installer_guard_or_410();
|
||||
|
||||
// SSE는 세션을 사용하지 않음 (세션 잠금 방지)
|
||||
@@ -52,7 +50,7 @@ $translations = loadTranslations($lang);
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
|
||||
http_response_code(405);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('sse_method_not_allowed'),
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
@@ -94,14 +92,14 @@ error_reporting(E_ALL);
|
||||
|
||||
// Worker 시작 로그 (디버깅용)
|
||||
addLog('=== Install Worker SSE Started ===');
|
||||
addLog('Client IP: ' . ($_SERVER['REMOTE_ADDR'] ?? 'unknown'));
|
||||
addLog('Client IP: '.($_SERVER['REMOTE_ADDR'] ?? 'unknown'));
|
||||
|
||||
// 워커 lock 획득 — 다른 워커가 활동 중이면 진입 거부 (race 차단).
|
||||
// SSE 응답으로 거부 사유 전달 후 종료.
|
||||
$lockResult = acquireWorkerLock(15);
|
||||
if (! $lockResult['acquired']) {
|
||||
addLog('=== SSE Worker rejected — another worker is active ===');
|
||||
setProgressEmitter(new SseEmitter());
|
||||
setProgressEmitter(new SseEmitter);
|
||||
sendSSEEvent('aborted', [
|
||||
'message' => lang('error_worker_busy'),
|
||||
'reason' => 'busy',
|
||||
@@ -110,7 +108,7 @@ if (! $lockResult['acquired']) {
|
||||
}
|
||||
|
||||
$workerId = $lockResult['worker_id'];
|
||||
addLog('Worker lock acquired: ' . $workerId . ' (reason: ' . $lockResult['reason'] . ')');
|
||||
addLog('Worker lock acquired: '.$workerId.' (reason: '.$lockResult['reason'].')');
|
||||
|
||||
// 워커 종료 시 lock 자동 해제
|
||||
register_shutdown_function('releaseWorkerLock', $workerId);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* 사용자가 선택한 확장 기능 목록을 state.json에 저장합니다.
|
||||
*
|
||||
* @method POST
|
||||
*
|
||||
* @body {
|
||||
* "admin_templates": ["sirsoft-admin_basic"],
|
||||
* "user_templates": ["sirsoft-basic"],
|
||||
@@ -26,11 +27,11 @@ header('Content-Type: application/json; charset=utf-8');
|
||||
define('BASE_PATH', realpath(dirname(__DIR__, 3)) ?: dirname(__DIR__, 3));
|
||||
|
||||
// 세션 및 설정 포함
|
||||
require_once dirname(__DIR__) . '/includes/session.php';
|
||||
require_once dirname(__DIR__) . '/includes/config.php';
|
||||
require_once dirname(__DIR__) . '/includes/installer-state.php';
|
||||
require_once dirname(__DIR__) . '/includes/functions.php';
|
||||
require_once __DIR__ . '/_guard.php';
|
||||
require_once dirname(__DIR__).'/includes/session.php';
|
||||
require_once dirname(__DIR__).'/includes/config.php';
|
||||
require_once dirname(__DIR__).'/includes/installer-state.php';
|
||||
require_once dirname(__DIR__).'/includes/functions.php';
|
||||
require_once __DIR__.'/_guard.php';
|
||||
installer_guard_or_410();
|
||||
|
||||
// 다국어 로드
|
||||
@@ -40,7 +41,7 @@ $translations = loadTranslations($currentLang);
|
||||
// POST 요청만 허용
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
http_response_code(405);
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'error' => lang('api_method_not_allowed'),
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
@@ -52,7 +53,7 @@ $input = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
http_response_code(400);
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'error' => lang('api_invalid_request'),
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
@@ -88,7 +89,7 @@ $extensionNames = isset($input['extension_names']) && is_array($input['extension
|
||||
// 관리자 템플릿은 최소 1개 필수
|
||||
if (empty($adminTemplates)) {
|
||||
http_response_code(400);
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'error' => lang('error_admin_template_required'),
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
@@ -114,9 +115,9 @@ $identifierGroups = [
|
||||
];
|
||||
foreach ($identifierGroups as $groupKey => $ids) {
|
||||
foreach ($ids as $id) {
|
||||
if (!preg_match($identifierPattern, $id)) {
|
||||
if (! preg_match($identifierPattern, $id)) {
|
||||
http_response_code(400);
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'error' => lang('error_invalid_extension_identifier', ['identifier' => $id, 'group' => $groupKey]),
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
@@ -153,7 +154,7 @@ try {
|
||||
// 상태 저장
|
||||
$saved = saveInstallationState($state);
|
||||
|
||||
if (!$saved) {
|
||||
if (! $saved) {
|
||||
throw new Exception(lang('state_save_failed'));
|
||||
}
|
||||
|
||||
@@ -167,7 +168,7 @@ try {
|
||||
]));
|
||||
|
||||
// 성공 응답
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('log_extensions_saved'),
|
||||
'data' => [
|
||||
@@ -178,7 +179,7 @@ try {
|
||||
|
||||
} catch (Throwable $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'error' => $e->getMessage(),
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
|
||||
@@ -458,7 +458,7 @@ function extractDependenciesDetailedFromJson(array $data): array
|
||||
$rawDeps = $data['dependencies'] ?? [];
|
||||
$detailed = [];
|
||||
|
||||
if (!is_array($rawDeps)) {
|
||||
if (! is_array($rawDeps)) {
|
||||
return $detailed;
|
||||
}
|
||||
|
||||
@@ -519,7 +519,7 @@ try {
|
||||
// Admin 템플릿 필수 검증
|
||||
if (empty($templates['admin'])) {
|
||||
http_response_code(400);
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'error' => 'no_admin_template',
|
||||
'error_message' => 'Admin template is required but not found. Please ensure at least one admin template exists in the templates/_bundled directory.',
|
||||
@@ -528,7 +528,7 @@ try {
|
||||
}
|
||||
|
||||
// 결과 반환
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => true,
|
||||
'data' => [
|
||||
'admin_templates' => $templates['admin'],
|
||||
@@ -541,7 +541,7 @@ try {
|
||||
|
||||
} catch (Throwable $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'error' => $e->getMessage(),
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
|
||||
@@ -64,10 +64,10 @@ $sessionProbeLibraryMode = defined('SESSION_PROBE_LIBRARY') && constant('SESSION
|
||||
|
||||
if (! $sessionProbeLibraryMode) {
|
||||
// 정식 진입점 — config / session / functions / guard 로드
|
||||
require_once __DIR__ . '/../includes/config.php';
|
||||
require_once __DIR__ . '/../includes/session.php';
|
||||
require_once __DIR__ . '/../includes/functions.php';
|
||||
require_once __DIR__ . '/_guard.php';
|
||||
require_once __DIR__.'/../includes/config.php';
|
||||
require_once __DIR__.'/../includes/session.php';
|
||||
require_once __DIR__.'/../includes/functions.php';
|
||||
require_once __DIR__.'/_guard.php';
|
||||
installer_guard_or_410();
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
@@ -75,18 +75,18 @@ if (! $sessionProbeLibraryMode) {
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
|
||||
http_response_code(405);
|
||||
echo json_encode(['error' => 'GET method required'], JSON_UNESCAPED_UNICODE);
|
||||
echo installer_json_encode(['error' => 'GET method required'], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$action = $_GET['action'] ?? '';
|
||||
|
||||
if ($action === 'set') {
|
||||
echo json_encode(sessionProbeSet(), JSON_UNESCAPED_UNICODE);
|
||||
echo installer_json_encode(sessionProbeSet(), JSON_UNESCAPED_UNICODE);
|
||||
} elseif ($action === 'verify') {
|
||||
echo json_encode(sessionProbeVerify(), JSON_UNESCAPED_UNICODE);
|
||||
echo installer_json_encode(sessionProbeVerify(), JSON_UNESCAPED_UNICODE);
|
||||
} else {
|
||||
http_response_code(400);
|
||||
echo json_encode(['error' => 'Invalid action — use ?action=set or ?action=verify'], JSON_UNESCAPED_UNICODE);
|
||||
echo installer_json_encode(['error' => 'Invalid action — use ?action=set or ?action=verify'], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
}
|
||||
@@ -25,11 +25,11 @@
|
||||
* data: {"phase":2,"server_ts":1234567892.456}
|
||||
*
|
||||
* @method GET
|
||||
* @package G7\Installer
|
||||
*/
|
||||
|
||||
// 설치 완료 시 인스톨러 비즈니스 로직 진입 차단
|
||||
require_once __DIR__ . '/_guard.php';
|
||||
require_once __DIR__.'/../includes/utf8.php';
|
||||
require_once __DIR__.'/_guard.php';
|
||||
installer_guard_or_410();
|
||||
|
||||
// SSE 헤더 설정 (install-worker.php 와 동일 — 호환성 검증의 정확도 보장)
|
||||
@@ -55,7 +55,7 @@ ignore_user_abort(false);
|
||||
|
||||
// Phase 1 — 즉시 송신
|
||||
echo "event: probe\n";
|
||||
echo 'data: ' . json_encode(['phase' => 1, 'server_ts' => microtime(true)], JSON_UNESCAPED_UNICODE) . "\n\n";
|
||||
echo 'data: '.installer_json_encode(['phase' => 1, 'server_ts' => microtime(true)], JSON_UNESCAPED_UNICODE)."\n\n";
|
||||
@flush();
|
||||
|
||||
// 클라이언트는 두 phase 도착 시각 차이로 streaming 호환성 판정.
|
||||
@@ -64,7 +64,7 @@ sleep(2);
|
||||
|
||||
// Phase 2 — 송신 후 즉시 종료
|
||||
echo "event: probe\n";
|
||||
echo 'data: ' . json_encode(['phase' => 2, 'server_ts' => microtime(true)], JSON_UNESCAPED_UNICODE) . "\n\n";
|
||||
echo 'data: '.installer_json_encode(['phase' => 2, 'server_ts' => microtime(true)], JSON_UNESCAPED_UNICODE)."\n\n";
|
||||
@flush();
|
||||
|
||||
exit;
|
||||
@@ -63,7 +63,7 @@ class StateManagementApi
|
||||
// GET 메서드만 허용
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
|
||||
http_response_code(405);
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'error' => 'Method Not Allowed',
|
||||
'message' => lang('error_get_method_required'),
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
@@ -139,27 +139,22 @@ class StateManagementApi
|
||||
|
||||
// JSON 응답 반환
|
||||
//
|
||||
// 최종 안전망 (gnuboard/g7#62): $response['logs'] 에 invalid UTF-8 바이트가
|
||||
// 섞이면 json_encode 가 false 를 반환하고 echo false = 빈 본문(HTTP 200) 이 되어
|
||||
// 최종 안전망 (gnuboard/g7#62): $response 의 로그·경로에 invalid UTF-8 바이트가
|
||||
// 섞이면 표준 json_encode 는 false 를 반환하고, echo false = 빈 본문(HTTP 200) 이 되어
|
||||
// 프론트 폴링(res.json())이 "Unexpected end of JSON input" 으로 폭주한다.
|
||||
// 로그는 addLog / task-runner 에서 이미 scrub 되지만, 어떤 경로로도 응답이
|
||||
// 빈 본문이 되지 않도록 JSON_INVALID_UTF8_SUBSTITUTE 로 치환하고 false 를 가드한다.
|
||||
$encoded = json_encode(
|
||||
//
|
||||
// installer_json_encode 는 값을 정규화하고 substitute 를 적용하며,
|
||||
// 실패하더라도 파싱 가능한 오류 JSON 을 돌려주므로 빈 본문이 나갈 수 없다.
|
||||
//
|
||||
// 폴백에도 `status`/`logs`/`log_total` 을 실어 보낸다. 프론트 PollingMonitor 는
|
||||
// `state.status` 로 진행/완료/실패를 판정하므로, 그 키가 없는 응답은 파싱은 되지만
|
||||
// 아무 전이도 일으키지 못해 화면이 조용히 멈춘 것처럼 보인다(파싱 실패 카운터도
|
||||
// 걸리지 않는다). 도달 확률과 무관하게 소비자 계약을 폴백에서도 유지한다.
|
||||
echo installer_json_encode(
|
||||
$response,
|
||||
JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_INVALID_UTF8_SUBSTITUTE
|
||||
JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT,
|
||||
['status' => $status, 'logs' => [], 'log_total' => $logTotal]
|
||||
);
|
||||
|
||||
if ($encoded === false) {
|
||||
// substitute 플래그로도 인코딩 실패한 극단적 케이스 — 폴링이 파싱 가능한
|
||||
// 최소 유효 JSON 을 반환해 프론트가 다음 tick 에서 정상 복구되도록 한다.
|
||||
$encoded = json_encode([
|
||||
'status' => $status,
|
||||
'logs' => [],
|
||||
'log_total' => $logTotal,
|
||||
], JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE);
|
||||
}
|
||||
|
||||
echo $encoded;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -175,7 +170,7 @@ class StateManagementApi
|
||||
// POST 메서드만 허용
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
http_response_code(405);
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Only POST method is allowed',
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
@@ -224,7 +219,7 @@ class StateManagementApi
|
||||
// 성공 응답
|
||||
http_response_code(200);
|
||||
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('state_reset_completed', ['step' => $targetStep]),
|
||||
'target_step' => $targetStep,
|
||||
@@ -243,7 +238,7 @@ class StateManagementApi
|
||||
// POST 메서드만 허용
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
http_response_code(405);
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('api_method_not_allowed'),
|
||||
]);
|
||||
@@ -263,7 +258,7 @@ class StateManagementApi
|
||||
// 설치가 이미 완료된 경우
|
||||
if (isset($state['installation_status']) && $state['installation_status'] === 'completed') {
|
||||
addLog(lang('abort_api_already_completed'));
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('abort_api_already_completed'),
|
||||
]);
|
||||
@@ -273,7 +268,7 @@ class StateManagementApi
|
||||
// 이미 중단된 경우 - 멱등성 보장 (재진입 시 400 에러 방지)
|
||||
if (isset($state['installation_status']) && $state['installation_status'] === 'aborted') {
|
||||
addLog(lang('abort_api_already_aborted'));
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('abort_api_already_aborted'),
|
||||
]);
|
||||
@@ -283,7 +278,7 @@ class StateManagementApi
|
||||
// 설치가 진행 중이 아닌 경우
|
||||
if (! isset($state['installation_status']) || $state['installation_status'] !== 'running') {
|
||||
addLog(lang('abort_api_not_running', ['status' => $state['installation_status'] ?? 'null']));
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'message' => lang('abort_api_not_running', ['status' => $state['installation_status'] ?? 'null']),
|
||||
]);
|
||||
@@ -329,7 +324,7 @@ class StateManagementApi
|
||||
addLog(lang('abort_installation_stopped'));
|
||||
|
||||
// 성공 응답 (리다이렉트 없음 - 현재 Step 5 유지)
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => true,
|
||||
'message' => lang('abort_installation_stopped'),
|
||||
]);
|
||||
@@ -341,7 +336,7 @@ class StateManagementApi
|
||||
private function error400(string $message): void
|
||||
{
|
||||
http_response_code(400);
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'error' => 'Bad Request',
|
||||
'message' => $message,
|
||||
@@ -363,7 +358,7 @@ class StateManagementApi
|
||||
|
||||
// 에러 응답
|
||||
http_response_code(500);
|
||||
echo json_encode([
|
||||
echo installer_json_encode([
|
||||
'success' => false,
|
||||
'error' => 'Internal Server Error',
|
||||
'message' => $e->getMessage(),
|
||||
|
||||
Reference in new issue
Block a user