Add docker entrypoint and env loader

This commit is contained in:
Lectom C Han
2026-02-02 18:52:20 +09:00
parent 0037b90573
commit bf86b1d1e7
30 changed files with 2627 additions and 1547 deletions

View File

@@ -1,10 +1,17 @@
<?php
$dsn = "pgsql:host=172.16.9.44;port=5432;dbname=KNGIL";
$user = "postgres";
$pass = "erpteam1!";
require_once __DIR__ . '/env.php';
kngil_load_env_once(dirname(__DIR__, 2) . '/.env');
$dbHost = getenv('DB_HOST') ?: 'db';
$dbPort = getenv('DB_PORT') ?: '5432';
$dbName = getenv('DB_NAME') ?: 'kngil';
$dbUser = getenv('DB_USER') ?: 'postgres';
$dbPass = getenv('DB_PASS') ?: 'postgres';
$dsn = "pgsql:host={$dbHost};port={$dbPort};dbname={$dbName}";
try {
$pdo = new PDO($dsn, $user, $pass, [
$pdo = new PDO($dsn, $dbUser, $dbPass, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
]);
// echo "PostgreSQL 연결 성공 🎉";

59
kngil/bbs/env.php Normal file
View File

@@ -0,0 +1,59 @@
<?php
// .env 파일을 한 번만 읽어 환경변수로 주입합니다.
function kngil_load_env_once(string $path): void
{
static $loaded = false;
if ($loaded) {
return;
}
$loaded = true;
if (!is_file($path) || !is_readable($path)) {
return;
}
$lines = file($path, FILE_IGNORE_NEW_LINES);
if ($lines === false) {
return;
}
foreach ($lines as $line) {
$line = trim($line);
if ($line === '' || str_starts_with($line, '#')) {
continue;
}
if (str_starts_with($line, 'export ')) {
$line = substr($line, 7);
}
$pos = strpos($line, '=');
if ($pos === false) {
continue;
}
$name = trim(substr($line, 0, $pos));
$value = trim(substr($line, $pos + 1));
if ($name === '') {
continue;
}
if (
(str_starts_with($value, '"') && str_ends_with($value, '"')) ||
(str_starts_with($value, "'") && str_ends_with($value, "'"))
) {
$value = substr($value, 1, -1);
}
$current = getenv($name);
if ($current !== false && $current !== '') {
continue;
}
putenv($name . '=' . $value);
$_ENV[$name] = $value;
$_SERVER[$name] = $value;
}
}

View File

@@ -1,10 +1,22 @@
<?php
// /kngil/bbs/oidc_config.php
require_once __DIR__ . '/env.php';
kngil_load_env_once(dirname(__DIR__, 2) . '/.env');
$issuer = getenv('OIDC_ISSUER') ?: '';
$clientId = getenv('OIDC_CLIENT_ID') ?: '';
$clientSecret = getenv('OIDC_CLIENT_SECRET') ?: '';
$redirectUrl = getenv('OIDC_REDIRECT_URL') ?: '';
$scopesRaw = getenv('OIDC_SCOPES');
$scopes = ['openid'];
if ($scopesRaw !== false && $scopesRaw !== '') {
$scopes = array_values(array_filter(preg_split('/\s*,\s*|\s+/', $scopesRaw)));
}
return [
'issuer' => 'https://api.descope.com/v1/apps/P2x26KgEwOu0xIwgNZutJjIZc1zz', // 예: https://idp.example.com/auth/realms/master
'client_id' => 'UDJ4MjZLZ0V3T3UweEl3Z05adXRKaklaYzF6ejpUUEEzOTVtSmx5MXhiczFwZWxrUHdDVFlvU2hiYXc=',
'client_secret' => 'uTjiKweHYUINalroA1LVu9OacbEEMPtPbfFITfHu3r5',
'redirect_url' => "https://kngil.hmac.kr/kngil/auth/oidc-callback.php",
'scopes' => ['openid'],
'issuer' => $issuer, // 예: https://idp.example.com/auth/realms/master
'client_id' => $clientId,
'client_secret' => $clientSecret,
'redirect_url' => $redirectUrl,
'scopes' => $scopes,
];

View File

@@ -3,6 +3,14 @@ ini_set('display_errors', 1);
error_reporting(E_ALL);
header("Content-Type: application/json; charset=utf-8");
// 기능 비활성화 (PostgreSQL만 사용)
http_response_code(410);
echo json_encode([
"status" => "disabled",
"message" => "해당 기능은 현재 비활성화되어 있습니다."
]);
exit;
/* -----------------------------------------------------
🔵 DB 연결
----------------------------------------------------- */