POSA_LEAKSMS/php/setup_wizard.php
유창욱 90f121e14c chore: import codebase with security hardening
SHT30 온습도 모니터링 시스템 전체 소스(서버 PHP, STM32 펌웨어, SQL, 테스트).
전체 코드리뷰에서 도출된 보안 하드닝 10건 반영:
- 요청 서명 HMAC-SHA256 전환(펌웨어 sig.c/서버 config.php/호스트 패리티 동시)
- 재전송 방어 + 기본 API_KEY fail-closed + 디바이스 문자열 정제(api/sensor_data.php)
- 오프라인 SMS 중복 발송 경합 제거(cron_heartbeat.php, 원자적 선점)
- CSV 수식 주입 방지(monthly_report.php), 감사로그 회전 락(retention_cleanup.php)
- 브루트포스 카운터 원자화(login.php), 예시 TOTP 비밀키 무효화, 마이그레이션 멱등화

_backup/(하드코딩 실 비밀값 포함)·config.local.php·런타임 상태는 .gitignore 제외.
2026-06-20 09:37:40 +09:00

119 lines
5.4 KiB
PHP

<?php
// =============================================================================
// setup_wizard.php - 설치/운영 점검 화면 (v2606, SHT30 온습도)
// =============================================================================
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/sms_send.php';
require_once __DIR__ . '/ops_checks.php';
ini_set('session.cookie_httponly', 1);
ini_set('session.cookie_secure', 1);
ini_set('session.cookie_samesite', 'Strict');
ini_set('session.use_strict_mode', 1);
session_start();
if (empty($_SESSION['logged_in']) || $_SESSION['logged_in'] !== true) {
header('Location: login.php');
exit;
}
if (empty($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}
$checks = collect_ops_checks();
$sms_test_result = null;
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'send_test_sms') {
if (!hash_equals($_SESSION['csrf_token'], $_POST['csrf_token'] ?? '')) {
http_response_code(400);
echo 'Invalid request';
exit;
}
$message = "[온습도 모니터링 테스트]\n"
. "설치/운영 점검 문자입니다.\n"
. "시각: " . date('Y-m-d H:i:s');
$results = [];
foreach (SMS_RECIPIENTS as $receiver) {
$digits = preg_replace('/\D+/', '', $receiver);
$results[] = ['receiver' => $digits, 'result' => send_sms_cafe24($digits, $message)];
}
$sms_test_result = $results;
}
$failed_count = ops_failed_count($checks);
?>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>설치 점검 - 온습도 모니터링 <?= htmlspecialchars(APP_VERSION) ?></title>
<style>
* { box-sizing: border-box; }
body { margin: 0; font-family: 'Noto Sans KR', sans-serif; background: #f0f4f8; color: #1f2937; }
header { background: #1a56db; color: #fff; padding: 16px 24px; display: flex; justify-content: space-between; align-items: center; }
header h1 { font-size: 1.15rem; margin: 0; }
header a { color: #fff; text-decoration: none; background: rgba(255,255,255,.15); padding: 7px 12px; border-radius: 6px; font-size: .85rem; }
.container { max-width: 980px; margin: 24px auto; padding: 0 16px; }
.summary { background: #fff; border-radius: 8px; padding: 18px; box-shadow: 0 1px 4px rgba(0,0,0,.1); margin-bottom: 18px; }
.summary strong { font-size: 1.2rem; color: <?= $failed_count ? '#b91c1c' : '#166534' ?>; }
.check-list { display: grid; gap: 10px; }
.check { background: #fff; border-radius: 8px; padding: 14px 16px; box-shadow: 0 1px 4px rgba(0,0,0,.08); border-left: 6px solid #22c55e; }
.check.fail { border-left-color: #ef4444; }
.check h2 { margin: 0 0 6px; font-size: .98rem; }
.check p { margin: 0; color: #64748b; font-size: .84rem; }
.fix { margin-top: 7px; color: #92400e; font-size: .8rem; }
.actions { margin: 18px 0; display: flex; gap: 10px; flex-wrap: wrap; }
button { border: 0; background: #1a56db; color: #fff; padding: 10px 14px; border-radius: 7px; font-weight: 700; cursor: pointer; }
.result { background: #fff; border-radius: 8px; padding: 14px 16px; box-shadow: 0 1px 4px rgba(0,0,0,.08); margin-top: 18px; }
@media (max-width: 520px) { header { align-items: flex-start; flex-direction: column; gap: 10px; } }
</style>
</head>
<body>
<header>
<h1>설치/운영 점검 <?= htmlspecialchars(APP_VERSION) ?></h1>
<div style="display:flex;gap:8px;flex-wrap:wrap">
<a href="dashboard.php">대시보드</a>
<a href="security_evidence.php">보안 증적</a>
</div>
</header>
<main class="container">
<section class="summary">
<strong><?= $failed_count === 0 ? '전체 점검 통과' : "확인 필요 {$failed_count}건" ?></strong>
<div style="color:#64748b;font-size:.86rem;margin-top:6px">운영 반영 전 이 화면에서 설정, DB, 권한, SMS를 확인합니다.</div>
</section>
<div class="check-list">
<?php foreach ($checks as $check): ?>
<section class="check <?= $check['ok'] ? '' : 'fail' ?>">
<h2><?= htmlspecialchars($check['category']) ?> · <?= htmlspecialchars($check['label']) ?> · <?= $check['ok'] ? '정상' : '확인 필요' ?></h2>
<p><?= htmlspecialchars($check['detail']) ?></p>
<?php if (!$check['ok'] && $check['fix'] !== ''): ?>
<div class="fix">조치: <?= htmlspecialchars($check['fix']) ?></div>
<?php endif; ?>
<?php if (($check['evidence'] ?? '') !== ''): ?>
<div class="fix">증적: <?= htmlspecialchars($check['evidence']) ?></div>
<?php endif; ?>
</section>
<?php endforeach; ?>
</div>
<form method="POST" class="actions">
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($_SESSION['csrf_token']) ?>">
<button type="submit" name="action" value="send_test_sms">테스트 SMS 발송</button>
</form>
<?php if ($sms_test_result !== null): ?>
<section class="result">
<strong>테스트 SMS 결과</strong>
<?php foreach ($sms_test_result as $row): ?>
<p><?= htmlspecialchars($row['receiver']) ?> · <?= $row['result']['success'] ? '성공' : '실패' ?> · <?= htmlspecialchars($row['result']['message']) ?></p>
<?php endforeach; ?>
</section>
<?php endif; ?>
</main>
</body>
</html>