diff --git a/README.md b/README.md index 4134f4c..2411623 100755 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ After `cd`-ing into the configured phpList plugin directory: ## Configuration ### You can configure saml from the phplist configuration page "SSO config" category (except for certificate which should be added manually in the cert folder) -you will need to give write permission to the simplesaml/settings.php file +on first install the plugin uses built-in defaults and then reads values from phpList configuration https://resources.phplist.com/plugin/simplesaml#simplesamlphp_installation_check diff --git a/plugins/simplesaml.php b/plugins/simplesaml.php index 328db15..fcbbcef 100755 --- a/plugins/simplesaml.php +++ b/plugins/simplesaml.php @@ -1,6 +1,6 @@ self::CONFIG_CATEGORY, ], ]; - private const SETTINGS_FILE_NAME= 'settings.php'; function __construct() { if ( version_compare(PHP_VERSION, '7.4.0') >= 0) { @@ -100,15 +99,14 @@ function __construct() } parent::__construct(); $this->tables = $GLOBALS['tables']; - $filename = __DIR__ . '/simplesaml/' . self::SETTINGS_FILE_NAME; - - $dataToWrite = []; + $configuredDisplayName = getConfig($this->name); + if ($configuredDisplayName !== false && $configuredDisplayName !== null && $configuredDisplayName !== '') { + $this->settings[$this->name]['value'] = $configuredDisplayName; + } foreach ($this->settings as $key => $setting) { - $dataToWrite[$key] = !empty(getConfig($key)) ? getConfig($key) : $setting['value']; + $this->settings[$key]['value'] = !empty(getConfig($key)) ? getConfig($key) : $setting['value']; } - $this->settings[$this->name]['value'] = $dataToWrite[$this->name]; - file_put_contents($filename, "settings['saml_secret_salt']['value'] == getConfig('saml_secret_salt')) { $GLOBALS['msg'] = ($GLOBALS['I18N']->get('Please change saml secret salt').'
'); } diff --git a/plugins/simplesaml/settings.php b/plugins/simplesaml/settings.php deleted file mode 100644 index d3907a5..0000000 --- a/plugins/simplesaml/settings.php +++ /dev/null @@ -1,14 +0,0 @@ - 'Saml', - 'hide_default_login' => false, - 'saml_idp' => 'https://sso.phplist.com:8443/realms/master', - 'saml_entity_id' => 'phplisttest', - 'saml_realm' => 'master', - 'saml_trusted_url_domains' => 'localhost', - 'saml_session_cookie_domain' => '.localhost', - 'saml_session_save_path' => '/var/lib/php/sessions', - 'saml_secret_salt' => 'defaultsecretsalt', - 'saml_admin_password' => '1234', -); diff --git a/plugins/simplesaml/simplesamlphp/cert/.gitignore b/plugins/simplesaml/simplesamlphp/cert/.gitignore index e1d8724..4371155 100644 --- a/plugins/simplesaml/simplesamlphp/cert/.gitignore +++ b/plugins/simplesaml/simplesamlphp/cert/.gitignore @@ -1,3 +1,4 @@ saml-private-key.pem saml-certificate.pem saml-remote-idp.crt +*.crt diff --git a/plugins/simplesaml/simplesamlphp/config/authsources.php b/plugins/simplesaml/simplesamlphp/config/authsources.php index fa00d3c..b007dab 100755 --- a/plugins/simplesaml/simplesamlphp/config/authsources.php +++ b/plugins/simplesaml/simplesamlphp/config/authsources.php @@ -1,6 +1,7 @@ 'Saml', + 'hide_default_login' => false, + 'saml_idp' => 'https://sso.phplist.com:8443/realms/master', + 'saml_entity_id' => 'phplisttest', + 'saml_realm' => 'master', + 'saml_trusted_url_domains' => 'localhost', + 'saml_session_cookie_domain' => '.localhost', + 'saml_session_save_path' => '/var/lib/php/sessions', + 'saml_secret_salt' => 'defaultsecretsalt', + 'saml_admin_password' => '123', + ]; +} + +function simplesamlHasConfigValue($value): bool +{ + return !($value === false || $value === null || $value === ''); +} + +function simplesamlBootstrapPhpList(): void +{ + if (function_exists('getConfig')) { + return; + } + + $documentRoot = rtrim((string) ($_SERVER['DOCUMENT_ROOT'] ?? ''), '/'); + $candidates = [ + $documentRoot . '/lists/admin/defaultconfig.php', + dirname(__DIR__, 4) . '/defaultconfig.php', + dirname(__DIR__, 5) . '/admin/defaultconfig.php', + dirname(__DIR__, 6) . '/lists/admin/defaultconfig.php', + ]; + + foreach (array_unique($candidates) as $candidate) { + if ($candidate === '' || strpos($candidate, '//') !== false) { + continue; + } + if (is_file($candidate)) { + require_once $candidate; + } + if (function_exists('getConfig')) { + return; + } + } +} + +function simplesamlLoadSettings(): array +{ + $settings = simplesamlDefaultSettings(); + simplesamlBootstrapPhpList(); + + if (!function_exists('getConfig')) { + return $settings; + } + + foreach ($settings as $key => $defaultValue) { + $configured = getConfig($key); + if (simplesamlHasConfigValue($configured)) { + $settings[$key] = $configured; + } + } + + return $settings; +} diff --git a/plugins/simplesaml/simplesamlphp/metadata/saml20-idp-remote.php b/plugins/simplesaml/simplesamlphp/metadata/saml20-idp-remote.php index 1583e3c..270fcba 100755 --- a/plugins/simplesaml/simplesamlphp/metadata/saml20-idp-remote.php +++ b/plugins/simplesaml/simplesamlphp/metadata/saml20-idp-remote.php @@ -1,7 +1,8 @@