Add method for delDomain
This commit is contained in:
parent
6481137915
commit
c7cd2d08fe
|
@ -73,16 +73,6 @@ class LdapDomain extends LdapServer {
|
|||
return $this->alias;
|
||||
}
|
||||
|
||||
public function del() {
|
||||
$del = ldap_delete($this->conn, "cn=".$this->domain.",".LDAP_BASE);
|
||||
if ($del) {
|
||||
# EvoLog::log("Del domain ".$this->domain);
|
||||
} else {
|
||||
# EvoLog::log("Delete $this->domain failed");
|
||||
}
|
||||
return $del;
|
||||
}
|
||||
|
||||
public function addAccount($name,$active=false,$admin=false,$accountactive=false,$courieractive=false,$webmailactive=false,$authsmtpactive=false,$amavisBypassSpamChecks=false) {
|
||||
global $conf;
|
||||
$mail = $name.'@'.$this->name;
|
||||
|
|
|
@ -82,6 +82,40 @@ class LdapServer {
|
|||
}
|
||||
}
|
||||
|
||||
public function delDomain($name) {
|
||||
if ($sr = @ldap_search($this->conn, "cn=".$name.",".LDAP_BASE, "(ObjectClass=*)")) {
|
||||
$objects = ldap_get_entries($this->conn, $sr);
|
||||
// Delete aliases
|
||||
foreach($objects as $object) {
|
||||
if (!empty($object['objectclass']) && !in_array("postfixDomain", $object['objectclass']) && in_array("mailAlias", $object['objectclass'])) {
|
||||
$dn = "cn=".$object['cn'][0]. ",cn=".$name.",".LDAP_BASE;
|
||||
if (!ldap_delete($this->conn, $dn)) {
|
||||
$error = ldap_error($this->conn);
|
||||
throw new Exception("Erreur dans la suppression de l'alias $dn : $error");
|
||||
}
|
||||
}
|
||||
}
|
||||
// Delete accounts
|
||||
foreach($objects as $object) {
|
||||
if (!empty($object['objectclass']) && !in_array("postfixDomain", $object['objectclass']) && !in_array("mailAlias", $object['objectclass'])) {
|
||||
$dn = "uid=".$object['cn'][0]. ",cn=".$name.",".LDAP_BASE;
|
||||
if (!ldap_delete($this->conn, $dn)) {
|
||||
$error = ldap_error($this->conn);
|
||||
throw new Exception("Erreur dans la suppression du compte $dn : $error");
|
||||
}
|
||||
}
|
||||
}
|
||||
// Delete domain
|
||||
$dn = "cn=".$name.",".LDAP_BASE;
|
||||
if (!ldap_delete($this->conn, $dn)) {
|
||||
$error = ldap_error($this->conn);
|
||||
throw new Exception("Erreur dans la suppression du domaine $dn : $error");
|
||||
}
|
||||
} else {
|
||||
throw new Exception("Ce domaine n'existe pas !");
|
||||
}
|
||||
}
|
||||
|
||||
public function isSuperAdmin() {
|
||||
return $this->superadmin;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,12 @@ if (!empty($_POST['delete'])) {
|
|||
$domain = Html::clean($_POST['delete']);
|
||||
print '<div class="container">';
|
||||
print '<div class="alert alert-warning" role="alert">Suppression du domaine '.$domain.' ...</div>';
|
||||
print '<div class="alert alert-danger" role="alert">Cette fonction n\'est pas encore implémentée !</div>';
|
||||
try {
|
||||
$server->delDomain(Html::clean($_POST['delete']));
|
||||
print '<div class="alert alert-success" role="alert">Suppression effectué.</div>';
|
||||
} catch (Exception $e_ad) {
|
||||
print '<div class="alert alert-danger" role="alert">'.$e_ad->getMessage().'</div>';
|
||||
}
|
||||
print '</div>';
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue