Add exception to LdapServer and LdapDomain construct
This commit is contained in:
parent
a99bfd9900
commit
8c91f6ff2a
|
@ -7,12 +7,18 @@ if (empty($_SESSION['login'])) {
|
||||||
header("location: auth.php\n\n");
|
header("location: auth.php\n\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
} else {
|
} else {
|
||||||
if (!$server = new LdapServer($_SESSION['login'])) {
|
try {
|
||||||
print "<div class=\"alert alert-danger\" role=\"alert\">Erreur de connexion LDAP !</div>";
|
$server = new LdapServer($_SESSION['login']);
|
||||||
exit(1);
|
|
||||||
} else {
|
|
||||||
if (!empty($_GET['domain'])) {
|
if (!empty($_GET['domain'])) {
|
||||||
|
try {
|
||||||
$domain = new LdapDomain($server, Html::clean($_GET['domain']));
|
$domain = new LdapDomain($server, Html::clean($_GET['domain']));
|
||||||
|
} catch (Exception $e_d) {
|
||||||
|
print '<div class="alert alert-danger" role="alert">'.$e_d->getMessage();
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception $e_s) {
|
||||||
|
print '<div class="alert alert-danger" role="alert">'.$e_s->getMessage().'</div>';
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ class LdapDomain extends LdapServer {
|
||||||
$this->dn = $server->dn;
|
$this->dn = $server->dn;
|
||||||
|
|
||||||
$this->domain = $name;
|
$this->domain = $name;
|
||||||
$sr = ldap_search($this->conn, "cn=".$this->domain.",".LDAP_BASE, "(ObjectClass=*)");
|
if ($sr = @ldap_search($this->conn, "cn=".$this->domain.",".LDAP_BASE, "(ObjectClass=*)")) {
|
||||||
$objects = ldap_get_entries($this->conn, $sr);
|
$objects = ldap_get_entries($this->conn, $sr);
|
||||||
|
|
||||||
foreach($objects as $object) {
|
foreach($objects as $object) {
|
||||||
|
@ -33,10 +33,10 @@ class LdapDomain extends LdapServer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//$this->quota = getquota($this->domain,'group');
|
//$this->quota = getquota($this->domain,'group');
|
||||||
|
} else {
|
||||||
return $this;
|
throw new Exception("Ce domaine n'existe pas !");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAccounts() {
|
public function getAccounts() {
|
||||||
|
|
|
@ -7,12 +7,15 @@ class LdapServer {
|
||||||
public function __construct($login) {
|
public function __construct($login) {
|
||||||
global $conf;
|
global $conf;
|
||||||
$this->login = $login;
|
$this->login = $login;
|
||||||
$this->conn = ldap_connect(LDAP_URI) or die ("Impossible de se connecter au serveur LDAP ".LDAP_URI);
|
if (!$this->conn = ldap_connect(LDAP_URI)) {
|
||||||
if (!ldap_set_option($this->conn, LDAP_OPT_PROTOCOL_VERSION, 3)) {
|
throw new Exception("Impossible de se connecter au serveur LDPA ".LDAP_URI);
|
||||||
echo 'Impossible de modifier la version du protocole à 3';
|
}
|
||||||
|
if (!ldap_set_option($this->conn, LDAP_OPT_PROTOCOL_VERSION, 3)) {
|
||||||
|
throw new Exception("Impossible de modifier la version du protocole LDAP à 3");
|
||||||
|
}
|
||||||
|
if (!ldap_bind($this->conn, LDAP_ADMIN_DN, LDAP_ADMIN_PASS)) {
|
||||||
|
throw new Exception("Authentification LDAP échoué !");
|
||||||
}
|
}
|
||||||
ldap_bind($this->conn, LDAP_ADMIN_DN, LDAP_ADMIN_PASS) or die ("Authentification LDAP échoué !");
|
|
||||||
|
|
||||||
if (in_array($this->login, $conf['admin']['logins'])) {
|
if (in_array($this->login, $conf['admin']['logins'])) {
|
||||||
$this->superadmin = true;
|
$this->superadmin = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue