Allow to configure LDAP port and TLS, generate LDAP URI, fix config example

Fix #48
This commit is contained in:
bohwaz 2024-01-31 14:25:35 +01:00
parent ea4d8b459d
commit 8f7937f2e7
3 changed files with 17 additions and 4 deletions

View file

@ -116,7 +116,13 @@ const AUTH_CALLBACK = null;
* All users logging in will be created locally and have the default quota.
*/
const LDAP_HOST = null;
//const LDAP_URI = '127.0.0.1';
//const LDAP_HOST = '127.0.0.1';
// LDAP server port
const LDAP_PORT = 389;
// Set to TRUE if using LDAPS
const LDAP_SECURE = false;
const LDAP_LOGIN = null;
//const LDAP_LOGIN = 'uid=%s,ou=users,dc=yunohost,dc=org';

View file

@ -8,7 +8,7 @@ class LDAP
static public function enabled(): bool
{
$config = [LDAP_HOST, LDAP_LOGIN, LDAP_FIND_USER, LDAP_FIND_IS_ADMIN, LDAP_BASE, LDAP_DISPLAY_NAME];
$config = [LDAP_HOST, LDAP_PORT, LDAP_SECURE, LDAP_LOGIN, LDAP_FIND_USER, LDAP_FIND_IS_ADMIN, LDAP_BASE, LDAP_DISPLAY_NAME];
$target = count($config);
$config = array_filter($config);
return count($config) == $target;
@ -20,7 +20,13 @@ class LDAP
return;
}
$l = ldap_connect(LDAP_HOST) || die('Cannot connect to LDAP');
$uri = sprintf('ldap%s://%s:%d', LDAP_SECURE ? 's' : '', LDAP_HOST, LDAP_PORT);
$l = ldap_connect($uri);
if (!$l) {
throw new \RuntimeException('Invalid LDAP connection URI: ' . $uri);
}
ldap_set_option($l, \LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($l, \LDAP_OPT_REFERRALS, 0);
ldap_set_option($l, \LDAP_OPT_NETWORK_TIMEOUT, 10);

View file

@ -34,9 +34,10 @@ $defaults = [
'ERRORS_REPORT_URL' => null,
'AUTH_CALLBACK' => null,
'LDAP_HOST' => null,
'LDAP_PORT' => null,
'LDAP_SECURE' => null,
'LDAP_LOGIN' => null,
'LDAP_BASE' => null,
'LDAP_URI' => null,
'LDAP_DISPLAY_NAME' => null,
'LDAP_FIND_USER' => null,
'LDAP_FIND_IS_ADMIN' => null,