Use ldapdomain class for account adding and deleting
This commit is contained in:
parent
75eedd7645
commit
531e08c14d
|
@ -16,6 +16,29 @@ if (empty($_GET['domain'])) {
|
|||
include("inc/haut.php");
|
||||
include("inc/debut.php");
|
||||
|
||||
if (!empty($_POST['account'])) {
|
||||
$account = Html::clean($_POST['account']);
|
||||
|
||||
print '<div class="container"><form name="del "method="post" action="admin.php?domain='.$domain->getName().'">';
|
||||
print '<div class="alert alert-warning" role="alert">Voulez vous vraiment supprimer le compte '.$account.' ?</div>';
|
||||
print '<div class="alert alert-warning" role="alert"><button type="submit" name="delete" value="'.$account.'">Confirmer</button> / <a href="admin.php?domain='.$domain->getName().'">Annuler</a></div>';
|
||||
print '</form></div>';
|
||||
}
|
||||
|
||||
if (!empty($_POST['delete'])) {
|
||||
$account = Html::clean($_POST['delete']);
|
||||
print '<div class="container">';
|
||||
print '<div class="alert alert-warning" role="alert">Suppression du compte '.$account.' ...</div>';
|
||||
try {
|
||||
$domain->delAccount($account);
|
||||
print '<div class="alert alert-success" role="alert">Suppression effectué.</div>';
|
||||
} catch (Exception $e) {
|
||||
print '<div class="alert alert-danger" role="alert">'.$e->getMessage().'</div>';
|
||||
}
|
||||
print '</div>';
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<div class="container">
|
||||
<div class="text-center">
|
||||
|
@ -41,7 +64,7 @@ include("inc/debut.php");
|
|||
</select>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<form name="del" method="post" action="admin.php?domain=<?php print $domain->getName(); ?>">
|
||||
<?php
|
||||
}
|
||||
|
||||
|
@ -66,7 +89,8 @@ include("inc/debut.php");
|
|||
foreach ($accounts as $account) {
|
||||
print '<tr><td style="text-align:left;"><a href="compte.php?domain='.$domain->getName().'&account='.$account->getUid().'">' .$account->getName().' <'.$account->getUid().'></a></td>';
|
||||
print '<td>' .getquota($account->getUid(),'user'). '</td>';
|
||||
print '<td><a href="compte.php?domain='.$domain->getName().'&del=' .$account->getUid(). '"><span class="glyphicon glyphicon-trash"></span></a></td></tr>';
|
||||
print '<td><button type="submit" name="account" value="'.$account->getUid().'"><span class="glyphicon glyphicon-trash"></span></button></td>';
|
||||
print '</tr>';
|
||||
}
|
||||
print "</tbody></table>";
|
||||
} elseif ( (isset($_GET['viewonly'])) && ($_GET['viewonly']==2) ) {
|
||||
|
@ -95,6 +119,7 @@ include("inc/debut.php");
|
|||
?>
|
||||
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php include("inc/fin.php"); ?>
|
||||
|
|
|
@ -76,38 +76,55 @@ class LdapDomain extends LdapServer {
|
|||
return $this->alias;
|
||||
}
|
||||
|
||||
public function addAccount($name,$active=false,$admin=false,$accountactive=false,$courieractive=false,$webmailactive=false,$authsmtpactive=false,$amavisBypassSpamChecks=false) {
|
||||
public function addAccount($uid,$name,$password,$active=false,$admin=false,$accountactive=false,$courieractive=false,$webmailactive=false,$authsmtpactive=false,$amavisBypassSpamChecks=false) {
|
||||
global $conf;
|
||||
$mail = $name.'@'.$this->name;
|
||||
if (badname($uid)) {
|
||||
throw new Exception("Erreur, <u>$name</u> est un nom invalide.");
|
||||
}
|
||||
if (Auth::badpassword($password)) {
|
||||
throw new Exception("Erreur, mot de passe invalide.");
|
||||
}
|
||||
$mail = $uid.'@'.$this->getName();
|
||||
$password = "{SSHA}".Ldap::ssha($password);
|
||||
$info["uid"] = $mail;
|
||||
$info["cn"] = $name;
|
||||
$info["homeDirectory"] = "/home/vmail/" .$this->name. "/" .$name. "/";
|
||||
$info["homeDirectory"] = "/home/vmail/" .$this->getName(). "/" .$uid. "/";
|
||||
$info["uidNumber"]= $conf['unix']['uid'];
|
||||
$info["gidNumber"]= getgid($this->name);
|
||||
$info["isActive"] = $active;
|
||||
$info["isAdmin"] = $admin;
|
||||
$info["isActive"] = ($active) ? 'TRUE' : 'FALSE';
|
||||
$info["isAdmin"] = ($admin) ? 'TRUE' : 'FALSE';
|
||||
$info["objectclass"][0] = "posixAccount";
|
||||
$info["objectclass"][1] = "organizationalRole";
|
||||
$info["objectclass"][2] = "mailAccount";
|
||||
#$info["objectclass"][3] = "amavisAccount";
|
||||
$info["maildrop"] = $mail;
|
||||
$info["mailacceptinggeneralid"] = $mail;
|
||||
$info["accountActive"] = $accountactive;
|
||||
$info["courierActive"] = $courieractive;
|
||||
$info["webmailActive"] = $webmailactive;
|
||||
$info["authsmtpActive"] = $authsmtpactive;
|
||||
#$info["amavisBypassSpamChecks"] = $amavisBypassSpamChecks;
|
||||
$info["userPassword"] = "{SSHA}" .Ldap::ssha($_POST['pass1']);
|
||||
$info["accountActive"] = ($accountactive) ? 'TRUE' : 'FALSE';
|
||||
$info["courierActive"] = ($courieractive) ? 'TRUE' : 'FALSE';
|
||||
$info["webmailActive"] = ($webmailactive) ? 'TRUE' : 'FALSE';
|
||||
$info["authsmtpActive"] = ($authsmtpactive) ? 'TRUE' : 'FALSE';
|
||||
#$info["amavisBypassSpamChecks"] = ($amavisBypassSpamChecks) ? 'TRUE' : 'FALSE';
|
||||
$info["userPassword"] = $password;
|
||||
|
||||
if (ldap_add($this->conn, "uid=".$mail.",cn=".$this->domain.",".LDAP_BASE, $info)) {
|
||||
if (@ldap_add($this->conn, "uid=".$mail.",cn=".$this->domain.",".LDAP_BASE, $info)) {
|
||||
mail($name, 'Premier message',"Mail d'initialisation du compte.");
|
||||
mailnotify($info,$_GET['domain'],$_POST['pass1']);
|
||||
# EvoLog::log("Add user ".$name);
|
||||
return TRUE;
|
||||
mailnotify($info,$this->getname(),$password);
|
||||
} else {
|
||||
# EvoLog::log("Add $name failed");
|
||||
var_dump($info);
|
||||
return FALSE;
|
||||
$error = ldap_error($this->conn);
|
||||
throw new Exception("Erreur dans l'ajout du compte : $error");
|
||||
}
|
||||
}
|
||||
|
||||
public function delAccount($uid) {
|
||||
$dn = "uid=".$uid.",cn=".$this->domain.",".LDAP_BASE;
|
||||
if ($sr = @ldap_search($this->conn, $dn, "(ObjectClass=mailAccount)")) {
|
||||
// Delete account
|
||||
if (!ldap_delete($this->conn, $dn)) {
|
||||
$error = ldap_error($this->conn);
|
||||
throw new Exception("Erreur dans la suppression du compte $uid : $error");
|
||||
}
|
||||
} else {
|
||||
throw new Exception("Ce compte n'existe pas !");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue