diff --git a/htdocs/lib/auth.php b/htdocs/lib/auth.php
index c7242fe..adb5242 100644
--- a/htdocs/lib/auth.php
+++ b/htdocs/lib/auth.php
@@ -7,12 +7,18 @@ if (empty($_SESSION['login'])) {
header("location: auth.php\n\n");
exit(0);
} else {
- if (!$server = new LdapServer($_SESSION['login'])) {
- print "
'.$e_d->getMessage();
+ exit(1);
+ }
}
+ } catch (Exception $e_s) {
+ print '
'.$e_s->getMessage().'
';
+ exit(1);
}
}
diff --git a/htdocs/lib/class.ldapdomain.php b/htdocs/lib/class.ldapdomain.php
index c9e69ec..7964699 100644
--- a/htdocs/lib/class.ldapdomain.php
+++ b/htdocs/lib/class.ldapdomain.php
@@ -11,32 +11,32 @@ class LdapDomain extends LdapServer {
$this->dn = $server->dn;
$this->domain = $name;
- $sr = ldap_search($this->conn, "cn=".$this->domain.",".LDAP_BASE, "(ObjectClass=*)");
- $objects = ldap_get_entries($this->conn, $sr);
+ if ($sr = @ldap_search($this->conn, "cn=".$this->domain.",".LDAP_BASE, "(ObjectClass=*)")) {
+ $objects = ldap_get_entries($this->conn, $sr);
- foreach($objects as $object) {
- if (!empty($object['objectclass'])) {
- if (in_array("postfixDomain",$object['objectclass'])) {
- $this->active = $object['isactive'][0];
- }
- if (in_array("posixAccount",$object['objectclass'])) {
- array_push($this->posix_accounts,$object['uid'][0]);
- }
- if (in_array("mailAccount",$object['objectclass'])) {
- array_push($this->mail_accounts,$object['uid'][0]);
- }
- if (in_array("mailAlias",$object['objectclass'])) {
- array_push($this->mail_alias,$object['cn'][0]);
- }
- if (in_array("sambaSamAccount",$object['objectclass'])) {
- array_push($this->smb_accounts,$object['uid'][0]);
+ foreach($objects as $object) {
+ if (!empty($object['objectclass'])) {
+ if (in_array("postfixDomain",$object['objectclass'])) {
+ $this->active = $object['isactive'][0];
+ }
+ if (in_array("posixAccount",$object['objectclass'])) {
+ array_push($this->posix_accounts,$object['uid'][0]);
+ }
+ if (in_array("mailAccount",$object['objectclass'])) {
+ array_push($this->mail_accounts,$object['uid'][0]);
+ }
+ if (in_array("mailAlias",$object['objectclass'])) {
+ array_push($this->mail_alias,$object['cn'][0]);
+ }
+ if (in_array("sambaSamAccount",$object['objectclass'])) {
+ array_push($this->smb_accounts,$object['uid'][0]);
+ }
}
}
+ //$this->quota = getquota($this->domain,'group');
+ } else {
+ throw new Exception("Ce domaine n'existe pas !");
}
-
-// $this->quota = getquota($this->domain,'group');
-
- return $this;
}
public function getAccounts() {
diff --git a/htdocs/lib/class.ldapserver.php b/htdocs/lib/class.ldapserver.php
index 7312da9..45dc816 100644
--- a/htdocs/lib/class.ldapserver.php
+++ b/htdocs/lib/class.ldapserver.php
@@ -7,12 +7,15 @@ class LdapServer {
public function __construct($login) {
global $conf;
$this->login = $login;
- $this->conn = ldap_connect(LDAP_URI) or die ("Impossible de se connecter au serveur LDAP ".LDAP_URI);
- if (!ldap_set_option($this->conn, LDAP_OPT_PROTOCOL_VERSION, 3)) {
- echo 'Impossible de modifier la version du protocole à 3';
+ if (!$this->conn = ldap_connect(LDAP_URI)) {
+ throw new Exception("Impossible de se connecter au serveur LDPA ".LDAP_URI);
+ }
+ 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'])) {
$this->superadmin = true;
}