|
| 1 | +<?php |
| 2 | + |
| 3 | +function simplesamlDefaultSettings(): array |
| 4 | +{ |
| 5 | + return [ |
| 6 | + 'simplesaml' => 'Saml', |
| 7 | + 'hide_default_login' => false, |
| 8 | + 'saml_idp' => 'https://sso.phplist.com:8443/realms/master', |
| 9 | + 'saml_entity_id' => 'phplisttest', |
| 10 | + 'saml_realm' => 'master', |
| 11 | + 'saml_trusted_url_domains' => 'localhost', |
| 12 | + 'saml_session_cookie_domain' => '.localhost', |
| 13 | + 'saml_session_save_path' => '/var/lib/php/sessions', |
| 14 | + 'saml_secret_salt' => 'defaultsecretsalt', |
| 15 | + 'saml_admin_password' => '123', |
| 16 | + ]; |
| 17 | +} |
| 18 | + |
| 19 | +function simplesamlHasConfigValue($value): bool |
| 20 | +{ |
| 21 | + return !($value === false || $value === null || $value === ''); |
| 22 | +} |
| 23 | + |
| 24 | +function simplesamlBootstrapPhpList(): void |
| 25 | +{ |
| 26 | + if (function_exists('getConfig')) { |
| 27 | + return; |
| 28 | + } |
| 29 | + |
| 30 | + $documentRoot = rtrim((string) ($_SERVER['DOCUMENT_ROOT'] ?? ''), '/'); |
| 31 | + $candidates = [ |
| 32 | + $documentRoot . '/lists/admin/defaultconfig.php', |
| 33 | + dirname(__DIR__, 4) . '/defaultconfig.php', |
| 34 | + dirname(__DIR__, 5) . '/admin/defaultconfig.php', |
| 35 | + dirname(__DIR__, 6) . '/lists/admin/defaultconfig.php', |
| 36 | + ]; |
| 37 | + |
| 38 | + foreach (array_unique($candidates) as $candidate) { |
| 39 | + if ($candidate === '' || strpos($candidate, '//') !== false) { |
| 40 | + continue; |
| 41 | + } |
| 42 | + if (is_file($candidate)) { |
| 43 | + require_once $candidate; |
| 44 | + } |
| 45 | + if (function_exists('getConfig')) { |
| 46 | + return; |
| 47 | + } |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +function simplesamlLoadSettings(): array |
| 52 | +{ |
| 53 | + $settings = simplesamlDefaultSettings(); |
| 54 | + simplesamlBootstrapPhpList(); |
| 55 | + |
| 56 | + if (!function_exists('getConfig')) { |
| 57 | + return $settings; |
| 58 | + } |
| 59 | + |
| 60 | + foreach ($settings as $key => $defaultValue) { |
| 61 | + $configured = getConfig($key); |
| 62 | + if (simplesamlHasConfigValue($configured)) { |
| 63 | + $settings[$key] = $configured; |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + return $settings; |
| 68 | +} |
0 commit comments