Initial profile site commit
This commit is contained in:
+101
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
// =====================================================
|
||||
// 설정 파일
|
||||
// =====================================================
|
||||
// ⚠️ 중요: 처음 사용 시 아래 ADMIN_PASSWORD_HASH를 변경하세요
|
||||
// 비밀번호 해시 생성 방법:
|
||||
// 브라우저에서 generate_password.php 접속 후 원하는 비번 입력
|
||||
// 또는 터미널에서: php -r "echo password_hash('your_password', PASSWORD_DEFAULT);"
|
||||
// =====================================================
|
||||
|
||||
// 기본 비밀번호: "admin1234" (반드시 변경하세요!)
|
||||
define('ADMIN_PASSWORD_HASH', '$2y$10$Wj/5fxQX90AlvyVPBfE0te2aUbysSBlE/Umm7EluG880rqcRUlHGm');
|
||||
|
||||
// 데이터 파일 경로
|
||||
define('DATA_DIR', __DIR__ . '/../data');
|
||||
define('UPLOADS_DIR', __DIR__ . '/../uploads');
|
||||
define('PROJECTS_FILE', DATA_DIR . '/projects.json');
|
||||
define('PROFILE_FILE', DATA_DIR . '/profile.json');
|
||||
|
||||
// 세션 설정
|
||||
define('SESSION_LIFETIME', 3600 * 4); // 4시간
|
||||
|
||||
// CORS 및 JSON 헤더
|
||||
function set_json_headers() {
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
header('X-Content-Type-Options: nosniff');
|
||||
}
|
||||
|
||||
// JSON 파일을 락 걸고 읽기
|
||||
function read_json_safe($filepath) {
|
||||
if (!file_exists($filepath)) {
|
||||
return null;
|
||||
}
|
||||
$fp = fopen($filepath, 'r');
|
||||
if (!$fp) return null;
|
||||
|
||||
if (flock($fp, LOCK_SH)) {
|
||||
$content = stream_get_contents($fp);
|
||||
flock($fp, LOCK_UN);
|
||||
fclose($fp);
|
||||
return json_decode($content, true);
|
||||
}
|
||||
fclose($fp);
|
||||
return null;
|
||||
}
|
||||
|
||||
// JSON 파일을 락 걸고 쓰기
|
||||
function write_json_safe($filepath, $data) {
|
||||
$json = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
if ($json === false) return false;
|
||||
|
||||
$fp = fopen($filepath, 'c+');
|
||||
if (!$fp) return false;
|
||||
|
||||
if (flock($fp, LOCK_EX)) {
|
||||
ftruncate($fp, 0);
|
||||
rewind($fp);
|
||||
fwrite($fp, $json);
|
||||
fflush($fp);
|
||||
flock($fp, LOCK_UN);
|
||||
fclose($fp);
|
||||
return true;
|
||||
}
|
||||
fclose($fp);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 인증 체크
|
||||
function require_auth() {
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
if (!isset($_SESSION['authenticated']) || $_SESSION['authenticated'] !== true) {
|
||||
http_response_code(401);
|
||||
echo json_encode(['error' => 'Unauthorized']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// 세션 타임아웃 체크
|
||||
if (isset($_SESSION['login_time']) &&
|
||||
(time() - $_SESSION['login_time']) > SESSION_LIFETIME) {
|
||||
session_destroy();
|
||||
http_response_code(401);
|
||||
echo json_encode(['error' => 'Session expired']);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// JSON 입력 받기
|
||||
function get_json_input() {
|
||||
$input = file_get_contents('php://input');
|
||||
return json_decode($input, true);
|
||||
}
|
||||
|
||||
// 응답 헬퍼
|
||||
function json_response($data, $status = 200) {
|
||||
http_response_code($status);
|
||||
echo json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
Reference in New Issue
Block a user