evoadmin-mail/htdocs/lib/LdapAlias.php
Gregory Colpart 308619b694
Some checks reported errors
continuous-integration/drone/tag Build encountered an error
Fix bug when updating aliases :
- array index for LDAP need to be in lowercase
- we need also array_filter() for mailacceptinggeneralid... especially to avoid null values
- array numeric indexes for LDAP attributes need to be consecutive, then we need order with array_values()
2019-09-10 23:11:23 +02:00

61 lines
2 KiB
PHP

<?php
class LdapAlias extends LdapDomain {
static $objectClass = array('mailAlias');
static $dn='cn';
protected $domain,$name,$active=false;
private $aliases=array(),$redirections=array();
public function __construct(LdapDomain $domain, $name) {
$this->domain = $domain;
$this->conn = $this->conn = $this->domain->server->getConn();
$this->name = $name;
if ($sr = @ldap_search($this->conn, self::getBaseDN($this->domain, $name), self::getClassFilter())) {
$objects = ldap_get_entries($this->conn, $sr);
$object = $objects[0];
$this->active = ($object['isactive'][0] == 'TRUE') ? true : false;
$this->aliases = array_filter($object['mailacceptinggeneralid'], "is_string");
$this->redirections = array_filter($object['maildrop'], "is_string");
} else {
throw new Exception("Cet alias n'existe pas !");
}
}
public function isActive() {
return $this->active;
}
public function update($active=false,$mailaccept=array(),$maildrop=array()) {
$info["isactive"] = ($active) ? 'TRUE' : 'FALSE';
$info["mailacceptinggeneralid"] = array_values(array_filter($mailaccept, function($value) {
return filter_var($value, FILTER_VALIDATE_EMAIL);
}));
$info["maildrop"] = array_values(array_filter($maildrop, function($value) {
return filter_var($value, FILTER_VALIDATE_EMAIL);
}));
if (!@ldap_mod_replace($this->conn, self::getBaseDN($this), $info)) {
$error = ldap_error($this->conn);
throw new Exception("Erreur pendant la modification de l'alias : $error");
}
}
public function getName() {
return $this->name;
}
public function getAliases() {
return preg_replace('/@'.$this->domain->getName().'/', '', $this->aliases);
}
public function getRedirections() {
return $this->redirections;
}
public function __destruct() {
return true;
}
}