| Server IP : 104.21.21.239 / Your IP : 216.73.216.11 Web Server : Apache/2.4.68 (Amazon Linux) OpenSSL/3.5.5 System : Linux ip-172-31-69-123.ec2.internal 6.1.176-223.369.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Jul 24 13:34:27 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/home2/cgny/public_html/2019/events-chattg/ |
Upload File : |
<?php
declare(strict_types=1);
/**
* Thought Gallery events chat — loads credentials from /home/home2/cgny/.env
*/
final class EventsChatConfig
{
private static ?array $cfg = null;
public static function get(): array
{
if (self::$cfg !== null) {
return self::$cfg;
}
$envPath = '/home/home2/cgny/.env';
if (!is_readable($envPath)) {
throw new RuntimeException('Config file not readable.');
}
$raw = file_get_contents($envPath);
if ($raw === false) {
throw new RuntimeException('Unable to read config file.');
}
if (!preg_match('/db\s*=\s*(\S+)\s*\/\s*(\S+)/i', $raw, $dbMatch)) {
throw new RuntimeException('DB credentials missing from config.');
}
if (!preg_match('/([a-z0-9.-]+\.rds\.amazonaws\.com)/i', $raw, $hostMatch)) {
throw new RuntimeException('DB host missing from config.');
}
if (!preg_match('/(?:openapi|openai)\s*key\s*=\s*(sk-[A-Za-z0-9_\-]+)/i', $raw, $keyMatch)) {
throw new RuntimeException('OpenAI API key missing from config.');
}
self::$cfg = [
'db_host' => $hostMatch[1],
'db_user' => $dbMatch[1],
'db_pass' => $dbMatch[2],
'db_name' => 'tgnew_prod',
'openai_api_key' => $keyMatch[1],
'openai_model' => 'gpt-4o-mini',
'admin_password' => $dbMatch[2],
'event_base_url' => 'https://thoughtgallery.org/events/',
'cache_path' => __DIR__ . '/cache/events.json',
'cache_max_age_seconds' => 90 * 60,
'history_limit' => 12,
'rate_input' => 0.15,
'rate_cached_input' => 0.075,
'rate_output' => 0.60,
];
return self::$cfg;
}
}