Files
hmac_BUT/src/index.php
T
2026-02-23 18:00:31 +09:00

116 lines
4.1 KiB
PHP

<?php
// Entry bootstrap for hmac_edu: load DB config and show skin/index.php as intro
$base = __DIR__;
// Load DB connection if present (bbs/db_conn.php contains DB info)
if (file_exists($base . '/bbs/db_conn.php')) {
require_once $base . '/bbs/db_conn.php';
} elseif (file_exists($base . '/db_conn.php')) {
require_once $base . '/db_conn.php';
}
// Serve skin/index.php as the intro page if it exists
$skin = $base . '/skin/index.php';
if (file_exists($skin)) {
if (session_status() === PHP_SESSION_NONE) {
@session_start();
}
require $skin;
exit;
}
// Try alternate locations (compat)
$alt = $base . '/hmac_edu/index.php';
if (file_exists($alt)) {
require $alt;
exit;
}
// Fallback diagnostic page
$dirs = [];
foreach (scandir($base) as $d) {
if ($d === '.' || $d === '..') continue;
if (is_dir($base . '/' . $d)) $dirs[] = $d;
}
// --- [추가된 부분] 도커 DB 연결 및 데이터 조회 테스트 로직 ---
$dbStatus = "";
$usersData = [];
try {
// ⚠️ TODO: 아래 유저명과 비밀번호를 .env 파일과 동일하게 맞춰주세요!
$dsn = "mysql:host=db;dbname=appdb;charset=utf8mb4";
$dbUser = "app"; // 또는 설정하신 유저명
$dbPass = "secret"; // .env에 설정한 비밀번호
$pdo = new PDO($dsn, $dbUser, $dbPass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbStatus = "<span style='color: green;'>✅ DB 연결 성공! (도커 내부 통신 정상)</span>";
// 아까 만든 users 테이블에서 데이터 가져오기
$stmt = $pdo->query("SELECT * FROM users");
$usersData = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
$dbStatus = "<span style='color: red;'>❌ DB 연결 실패: " . htmlspecialchars($e->getMessage()) . "</span>";
}
// -------------------------------------------------------------
?><!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<title>hmac_edu - Missing Intro</title>
<style>
body{font-family:Arial,Helvetica,sans-serif;padding:20px}
/* 추가된 DB 테스트용 CSS */
.test-box { border: 1px solid #ccc; padding: 15px; margin-top: 20px; border-radius: 5px; background: #f9f9f9; }
table { border-collapse: collapse; width: 100%; margin-top: 10px; background: #fff; }
th, td { border: 1px solid #ddd; padding: 10px; text-align: left; }
th { background-color: #eee; }
</style>
</head>
<body>
<h1>Intro 페이지를 찾을 수 없습니다</h1>
<p>현재 `skin/index.php` 파일이 프로젝트의 `src` 폴더에 없습니다.</p>
<div class="test-box">
<h2>🐳 도커 DB 연결 테스트</h2>
<p><?php echo $dbStatus; ?></p>
<?php if (!empty($usersData)): ?>
<h3>`users` 테이블 데이터:</h3>
<table>
<thead>
<tr>
<th>ID</th>
<th>Username</th>
<th>Email</th>
<th>Created At</th>
</tr>
</thead>
<tbody>
<?php foreach ($usersData as $row): ?>
<tr>
<td><?php echo htmlspecialchars($row['id'] ?? ''); ?></td>
<td><?php echo htmlspecialchars($row['username'] ?? ''); ?></td>
<td><?php echo htmlspecialchars($row['email'] ?? ''); ?></td>
<td><?php echo htmlspecialchars($row['created_at'] ?? ''); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else: ?>
<p>테이블에 데이터가 없거나 조회할 수 없습니다. (초기 데이터가 비어있을 수 있습니다)</p>
<?php endif; ?>
</div>
<p style="margin-top:30px;">호스트에 업로드된 디렉터리 목록:</p>
<ul>
<?php foreach ($dirs as $d): ?>
<li><?php echo htmlspecialchars($d); ?></li>
<?php endforeach; ?>
</ul>
</body>
</html>
<?php
// end
?>