2017-12-15 20:25:29 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class LdapAccount extends LdapDomain {
|
2017-12-17 16:00:47 +01:00
|
|
|
static $objectClass = array('mailAccount', 'posixAccount', 'organizationalRole');
|
|
|
|
|
|
|
|
static public function getClassFilter() {
|
|
|
|
return '(ObjectClass='.self::$objectClass[0].')';
|
|
|
|
}
|
|
|
|
|
2017-12-15 22:55:51 +01:00
|
|
|
protected $domain,$uid,$name,$active=false,$admin=false,$courier=false,$authsmtp=false;
|
2017-12-17 02:11:19 +01:00
|
|
|
private $aliases=array(),$redirections=array();
|
2017-12-15 20:25:29 +01:00
|
|
|
|
2017-12-17 16:00:47 +01:00
|
|
|
public function __construct(LdapDomain $domain, $uid) {
|
2017-12-15 20:25:29 +01:00
|
|
|
$this->conn = $domain->conn;
|
|
|
|
$this->domain = $domain->getName();
|
|
|
|
|
|
|
|
$this->uid = $uid;
|
2017-12-17 16:00:47 +01:00
|
|
|
if ($sr = @ldap_search($this->conn, "uid=".$uid.",cn=".$this->domain.",".LDAP_BASE, self::getClassFilter())) {
|
2017-12-15 20:25:29 +01:00
|
|
|
$objects = ldap_get_entries($this->conn, $sr);
|
|
|
|
$object = $objects[0];
|
|
|
|
$this->name = $object['cn'][0];
|
2017-12-15 22:55:51 +01:00
|
|
|
$this->active = ($object['isactive'][0] == 'TRUE') ? true : false;
|
|
|
|
$this->admin = ($object['isadmin'][0] == 'TRUE') ? true : false;
|
|
|
|
$this->courier = ($object['courieractive'][0] == 'TRUE') ? true : false;
|
|
|
|
$this->authsmtp = ($object['authsmtpactive'][0] == 'TRUE') ? true : false;
|
2017-12-15 20:25:29 +01:00
|
|
|
//$this->quota = getquota($this->domain,'user');
|
2017-12-17 02:11:19 +01:00
|
|
|
$this->aliases = array_filter($object['mailacceptinggeneralid'], "is_string");
|
|
|
|
$this->redirections = array_filter($object['maildrop'], "is_string");
|
2017-12-15 20:25:29 +01:00
|
|
|
} else {
|
|
|
|
throw new Exception("Ce compte n'existe pas !");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-15 23:47:18 +01:00
|
|
|
public function update($name=NULL,$password=NULL,$active=NULL,$admin=NULL,$accountactive=NULL,$courieractive=NULL,$webmailactive=NULL,$authsmtpactive=NULL,$amavisBypassSpamChecks=NULL) {
|
|
|
|
$info["cn"] = (!empty($name)) ? $name : $this->name;
|
|
|
|
if (!empty($password)) {
|
|
|
|
$info["userPassword"] = $password;
|
|
|
|
}
|
|
|
|
$info["isActive"] = ($active) ? 'TRUE' : 'FALSE';
|
|
|
|
$info["isAdmin"] = ($admin) ? 'TRUE' : 'FALSE';
|
|
|
|
$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';
|
|
|
|
if (!ldap_mod_replace($this->conn, "uid=".$this->uid.",cn=".$this->domain.",".LDAP_BASE, $info)) {
|
|
|
|
$error = ldap_error($this->conn);
|
|
|
|
throw new Exception("Erreur pendant la modification du compte : $error");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-15 22:55:51 +01:00
|
|
|
public function isActive() {
|
|
|
|
return $this->active;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isAdmin() {
|
|
|
|
return $this->admin;
|
|
|
|
}
|
|
|
|
|
2017-12-15 20:25:29 +01:00
|
|
|
public function getUid() {
|
|
|
|
return $this->uid;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName() {
|
|
|
|
return $this->name;
|
|
|
|
}
|
|
|
|
|
2017-12-15 22:55:51 +01:00
|
|
|
public function getAliases() {
|
2017-12-17 02:11:19 +01:00
|
|
|
return preg_replace('/@'.$this->domain.'/', '', $this->aliases);
|
2017-12-15 22:55:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getRedirections() {
|
2017-12-17 02:11:19 +01:00
|
|
|
return $this->redirections;
|
2017-12-15 22:55:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function isCourier() {
|
|
|
|
return $this->courier;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isAuthSmtp() {
|
|
|
|
return $this->authsmtp;
|
|
|
|
}
|
|
|
|
|
2017-12-15 20:25:29 +01:00
|
|
|
public function __destruct() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|