feat: add MVC base, with auth to ldap

This commit is contained in:
unknown
2025-02-02 10:22:31 -08:00
commit 3b1749292e
12 changed files with 448 additions and 0 deletions

52
models/LDAPAuth.php Normal file
View File

@@ -0,0 +1,52 @@
<?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);
}
}
}