Files
webgis/poverty-mapping/src/config/config.php
T

52 lines
1.5 KiB
PHP

<?php
// Load environment from project root .env if present, then read API_KEY
function load_dotenv($path){
if(!file_exists($path)) return;
$lines = file($path, FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
foreach($lines as $line){
if(trim($line)==='' || strpos(trim($line),'#')===0) continue;
if(strpos($line,'=')===false) continue;
list($k,$v) = explode('=', $line, 2);
$k = trim($k); $v = trim($v);
// strip optional quotes
if((substr($v,0,1)==='"' && substr($v,-1)==='"') || (substr($v,0,1)==="'" && substr($v,-1)==="'")){
$v = substr($v,1,-1);
}
if(getenv($k) === false || getenv($k) === ''){
putenv("$k=$v");
$_ENV[$k] = $v;
}
}
}
$envPath = realpath(__DIR__ . '/../../.env');
if($envPath){ load_dotenv($envPath); }
$apiKey = getenv('API_KEY');
if(!$apiKey) {
// fallback (development) - but prefer .env or system env in production
$apiKey = '8f3b7e6a9c4d2f1a6b8c9d0e4f7a1b2c';
}
define('API_KEY', $apiKey);
$jwtSecret = getenv('JWT_SECRET');
if(!$jwtSecret) {
$jwtSecret = hash('sha256', $apiKey . ':jwt');
}
define('JWT_SECRET', $jwtSecret);
$internalKey = getenv('INTERNAL_AUTH_KEY');
if(!$internalKey) {
$internalKey = hash('sha256', $apiKey . ':internal');
}
define('INTERNAL_AUTH_KEY', $internalKey);
$basicApiUser = getenv('BASIC_API_USER');
if(!$basicApiUser) { $basicApiUser = 'webgis-api'; }
define('BASIC_API_USER', $basicApiUser);
$basicApiPass = getenv('BASIC_API_PASS');
if(!$basicApiPass) { $basicApiPass = hash('sha256', $apiKey . ':basic'); }
define('BASIC_API_PASS', $basicApiPass);
?>