53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
<?php
|
|
class LDAPAuth
|
|
{
|
|
private $ldap_server;
|
|
private $domain;
|
|
private $FISA;
|
|
private $admin;
|
|
private $ad;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->ldap_server = 'ldap://intranet.epul3a.local';
|
|
$this->domain = 'intranet.epul3a.local';
|
|
$this->FISA = 'OU=3AFISA,DC=epul3a,DC=local';
|
|
$this->admin = 'CN=Users,DC=epul3a,DC=local';
|
|
}
|
|
|
|
public function connect()
|
|
{
|
|
$this->ad = ldap_connect($this->ldap_server)
|
|
or die("Impossible de se connecter au LDAP");
|
|
ldap_set_option($this->ad, LDAP_OPT_PROTOCOL_VERSION, 3);
|
|
ldap_set_option($this->ad, LDAP_OPT_REFERRALS, 0);
|
|
}
|
|
|
|
public function authenticate($user_pseudo, $user_password)
|
|
{
|
|
$this->connect();
|
|
|
|
$ldap_user_3afisa = "CN=$user_pseudo,$this->FISA";
|
|
$ldap_user_admin = "CN=$user_pseudo,$this->admin";
|
|
|
|
$bind_3afisa = @ldap_bind($this->ad, $ldap_user_3afisa, $user_password);
|
|
$bind_admin = false;
|
|
|
|
if (!$bind_3afisa) {
|
|
$bind_admin = @ldap_bind($this->ad, $ldap_user_admin, $user_password);
|
|
}
|
|
|
|
if ($bind_3afisa || $bind_admin) {
|
|
return ['success' => true, 'is_admin' => $bind_admin];
|
|
}
|
|
return ['success' => false];
|
|
}
|
|
|
|
public function close()
|
|
{
|
|
if ($this->ad) {
|
|
ldap_close($this->ad);
|
|
}
|
|
}
|
|
}
|