Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions core/class/user.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ public static function connect(string $_login, string $_mdp) {
$sMdp = (!is_sha512($_mdp)) ? sha512($_mdp) : $_mdp;
if (config::byKey('ldap:enable') == '1' && function_exists('ldap_connect')) {
log::add("connection", "info", __('LDAP Authentification', __FILE__));
// Configurer la verification des certificats SSL pour les certificats auto-signes
if (config::byKey('ldap:allow_selfsigned')) {
putenv('LDAPTLS_REQCERT=never');
ldap_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER);
} else {
putenv('LDAPTLS_REQCERT=demand');
ldap_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_DEMAND);
}
$ad = ldap_connect(config::byKey('ldap:host'), config::byKey('ldap:port'));
if (!$ad) {
log::add("connection", "info", __('Connection LDAP Error', __FILE__));
Expand All @@ -65,6 +73,12 @@ public static function connect(string $_login, string $_mdp) {
log::add("connection", "info", __('LDAP Connection OK', __FILE__));
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ad, LDAP_OPT_REFERRALS, 0);
// Appliquer l'option certificats auto-signes sur la connexion avant STARTTLS
if (config::byKey('ldap:allow_selfsigned')) {
ldap_set_option($ad, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER);
} else {
ldap_set_option($ad, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_DEMAND);
}
if (config::byKey('ldap:tls')) {
if (!ldap_start_tls($ad)) {
log::add("connection", "debug", __('start TLS KO', __FILE__));
Expand Down Expand Up @@ -153,9 +167,24 @@ public static function connect(string $_login, string $_mdp) {
}

public static function connectToLDAP() {
// Configurer la verification des certificats SSL pour les certificats auto-signes
if (config::byKey('ldap:allow_selfsigned')) {
putenv('LDAPTLS_REQCERT=never');
ldap_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER);
} else {
putenv('LDAPTLS_REQCERT=demand');
ldap_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_DEMAND);
}

$ad = ldap_connect(config::byKey('ldap:host'), config::byKey('ldap:port'));
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ad, LDAP_OPT_REFERRALS, 0);
// Appliquer l'option certificats auto-signes sur la connexion avant STARTTLS
if (config::byKey('ldap:allow_selfsigned')) {
ldap_set_option($ad, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_NEVER);
} else {
ldap_set_option($ad, LDAP_OPT_X_TLS_REQUIRE_CERT, LDAP_OPT_X_TLS_DEMAND);
}
if (config::byKey('ldap:tls') && !ldap_start_tls($ad)) {
return false;
}
Expand Down
8 changes: 8 additions & 0 deletions desktop/php/administration.php
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,14 @@
<input type="checkbox" class="configKey form-control" data-l1key="ldap:tls">
</div>
</div>
<div class="form-group">
<label class="col-md-3 col-sm-4 col-xs-12 control-label">{{Autoriser certificats auto-signés}}
<sup><i class="fas fa-question-circle" tooltip="{{Désactiver la vérification des certificats SSL pour les certificats auto-signés}}"></i></sup>
</label>
<div class="col-md-3 col-sm-4 col-xs-12">
<input type="checkbox" class="configKey form-control" data-l1key="ldap:allow_selfsigned">
</div>
</div>
<div class="form-group">
<label class="col-md-3 col-sm-4 col-xs-12 control-label">{{Hôte}}
<sup><i class="fas fa-question-circle" tooltip="{{URL utilisée pour contacter la base, en précisant le type de connexion (e.g ldap(s)://URL)}}"></i></sup>
Expand Down