* Retrieves the current configuration. * * @return array The configuration array, or defaults if not found. */
()
| 940 | * @return array The configuration array, or defaults if not found. |
| 941 | */ |
| 942 | public static function getConfig(): array |
| 943 | { |
| 944 | $configFile = USERS_DIR . 'adminConfig.json'; |
| 945 | |
| 946 | if (file_exists($configFile)) { |
| 947 | $encryptedContent = file_get_contents($configFile); |
| 948 | $decryptedContent = decryptData($encryptedContent, $GLOBALS['encryptionKey']); |
| 949 | if ($decryptedContent === false) { |
| 950 | clearstatcache(true, $configFile); |
| 951 | $retryContent = @file_get_contents($configFile); |
| 952 | if (is_string($retryContent) && $retryContent !== '') { |
| 953 | $encryptedContent = $retryContent; |
| 954 | $decryptedContent = decryptData($encryptedContent, $GLOBALS['encryptionKey']); |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | if ($decryptedContent === false) { |
| 959 | $rawConfig = json_decode((string)$encryptedContent, true); |
| 960 | if (is_array($rawConfig)) { |
| 961 | $config = $rawConfig; |
| 962 | } else { |
| 963 | // Do not set HTTP status here; let the controller decide. |
| 964 | return ["error" => "Failed to decrypt configuration."]; |
| 965 | } |
| 966 | } else { |
| 967 | $config = json_decode($decryptedContent, true); |
| 968 | } |
| 969 | |
| 970 | if (!is_array($config)) { |
| 971 | $config = []; |
| 972 | } |
| 973 | |
| 974 | // Normalize login options if missing |
| 975 | if (!isset($config['loginOptions'])) { |
| 976 | // Migrate legacy top-level flags; default OIDC to true (disabled) |
| 977 | $config['loginOptions'] = [ |
| 978 | 'disableFormLogin' => isset($config['disableFormLogin']) ? (bool)$config['disableFormLogin'] : false, |
| 979 | 'disableBasicAuth' => isset($config['disableBasicAuth']) ? (bool)$config['disableBasicAuth'] : false, |
| 980 | 'disableOIDCLogin' => isset($config['disableOIDCLogin']) ? (bool)$config['disableOIDCLogin'] : true, |
| 981 | ]; |
| 982 | unset($config['disableFormLogin'], $config['disableBasicAuth'], $config['disableOIDCLogin']); |
| 983 | } else { |
| 984 | // Normalize booleans; default OIDC to true (disabled) if missing |
| 985 | $lo = &$config['loginOptions']; |
| 986 | $lo['disableFormLogin'] = isset($lo['disableFormLogin']) ? (bool)$lo['disableFormLogin'] : false; |
| 987 | $lo['disableBasicAuth'] = isset($lo['disableBasicAuth']) ? (bool)$lo['disableBasicAuth'] : false; |
| 988 | $lo['disableOIDCLogin'] = isset($lo['disableOIDCLogin']) ? (bool)$lo['disableOIDCLogin'] : true; |
| 989 | } |
| 990 | |
| 991 | // Ensure OIDC structure exists |
| 992 | if (!isset($config['oidc']) || !is_array($config['oidc'])) { |
| 993 | $config['oidc'] = [ |
| 994 | 'providerUrl' => '', |
| 995 | 'clientId' => '', |
| 996 | 'clientSecret' => '', |
| 997 | 'redirectUri' => '', |
| 998 | 'groupClaim' => '', |
| 999 | 'extraScopes' => '', |
no test coverage detected