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");
|
||||
exit(0);
|
||||
} else {
|
||||
if (!$server = new LdapServer($_SESSION['login'])) {
|
||||
print "<div class=\"alert alert-danger\" role=\"alert\">Erreur de connexion LDAP !</div>";
|
||||
exit(1);
|
||||
} else {
|
||||
try {
|
||||
$server = new LdapServer($_SESSION['login']);
|
||||
if (!empty($_GET['domain'])) {
|
||||
$domain = new LdapDomain($server, Html::clean($_GET['domain']));
|
||||
try {
|
||||
$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,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() {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue