settings.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. declare(strict_types=1);
  3. use Monolog\Level;
  4. $appEnv = getenv('APP_ENV') ?: 'production';
  5. if ($appEnv === 'development' && file_exists(__DIR__ . '/../.env')) {
  6. $dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/..');
  7. $dotenv->safeLoad();
  8. }
  9. $logLevelName = strtoupper((string) (getenv('LOG_LEVEL') ?: 'info'));
  10. $logLevel = match ($logLevelName) {
  11. 'DEBUG' => Level::Debug,
  12. 'NOTICE' => Level::Notice,
  13. 'WARNING' => Level::Warning,
  14. 'ERROR' => Level::Error,
  15. 'CRITICAL' => Level::Critical,
  16. 'ALERT' => Level::Alert,
  17. 'EMERGENCY' => Level::Emergency,
  18. default => Level::Info,
  19. };
  20. $truthy = static fn (string $env, bool $default = false): bool => match (strtolower((string) (getenv($env) ?: ''))) {
  21. 'true', '1', 'yes', 'on' => true,
  22. 'false', '0', 'no', 'off' => false,
  23. '' => $default,
  24. default => $default,
  25. };
  26. return [
  27. 'app_env' => $appEnv,
  28. 'log_level' => $logLevel,
  29. 'public_url' => getenv('PUBLIC_URL') ?: 'http://localhost:8080',
  30. 'ui_secret' => getenv('UI_SECRET') ?: '',
  31. // BFF — talking to the api
  32. 'api_base_url' => getenv('API_BASE_URL') ?: '',
  33. 'ui_service_token' => getenv('UI_SERVICE_TOKEN') ?: '',
  34. 'api_timeout_seconds' => (float) (getenv('API_TIMEOUT_SECONDS') ?: 5),
  35. // OIDC — Microsoft Entra ID by default
  36. 'oidc_enabled' => $truthy('OIDC_ENABLED', true),
  37. 'oidc_issuer' => getenv('OIDC_ISSUER') ?: '',
  38. 'oidc_client_id' => getenv('OIDC_CLIENT_ID') ?: '',
  39. 'oidc_client_secret' => getenv('OIDC_CLIENT_SECRET') ?: '',
  40. 'oidc_redirect_uri' => getenv('OIDC_REDIRECT_URI') ?: '',
  41. // Local admin (UI-side credentials only)
  42. 'local_admin_enabled' => $truthy('LOCAL_ADMIN_ENABLED', true),
  43. 'local_admin_username' => getenv('LOCAL_ADMIN_USERNAME') ?: 'admin',
  44. 'local_admin_password_hash' => getenv('LOCAL_ADMIN_PASSWORD_HASH') ?: '',
  45. // Session: 8h inactivity, 24h absolute
  46. 'session_idle_seconds' => (int) (getenv('SESSION_IDLE_SECONDS') ?: 28800),
  47. 'session_absolute_seconds' => (int) (getenv('SESSION_ABSOLUTE_SECONDS') ?: 86400),
  48. // SEC_REVIEW F36: how often the AuthRequired middleware re-checks the
  49. // current user's role / disabled state against `GET /api/v1/admin/me`.
  50. // Lower = faster propagation of group/role changes from Entra and
  51. // explicit disable actions in the api; higher = fewer api calls per
  52. // active user. Default 5 minutes.
  53. 'session_revalidate_seconds' => (int) (getenv('UI_SESSION_REVALIDATE_SECONDS') ?: 300),
  54. // Local-admin login throttle: file-backed JSON store on the container's
  55. // writable layer. Persists across FrankenPHP worker recycles and is
  56. // shared between workers; cleared by container restart (operator unlock
  57. // path). Override only if /tmp is unsuitable for the deployment.
  58. 'login_throttle_path' => getenv('LOGIN_THROTTLE_PATH') ?: (sys_get_temp_dir() . '/irdb_login_throttle.json'),
  59. // GeoIP — only the provider name. The UI uses it to pick the right
  60. // attribution string for the IP-detail enrichment panel. The api
  61. // owns the actual provider config; this is a display-only mirror.
  62. 'geoip_provider' => strtolower((string) (getenv('GEOIP_PROVIDER') ?: 'dbip')),
  63. // Optional BCP 47 locale hint (e.g. "de-CH", "en-GB"). Browser locale
  64. // wins; this is appended as a fallback when the browser's locale is
  65. // unavailable or unsupported. Empty = browser-only.
  66. 'ui_locale' => trim((string) (getenv('UI_LOCALE') ?: '')),
  67. ];