Add LdapAccount class and use it for list accounts

This commit is contained in:
Victor LABORIE 2017-12-15 20:25:29 +01:00
parent 8e78ac199a
commit 75eedd7645
3 changed files with 43 additions and 8 deletions

View file

@ -62,11 +62,11 @@ include("inc/debut.php");
<tbody>
<?php
$comptes = $domain->getAccounts();
foreach ($comptes as $compte) {
print '<tr><td style="text-align:left;"><a href="compte.php?domain='.$domain->getName().'&view='.$compte. '">' .$compte. '</a></td>';
print '<td>' .getquota($compte,'user'). '</td>';
print '<td><a href="compte.php?domain='.$domain->getName().'&del=' .$compte. '"><span class="glyphicon glyphicon-trash"></span></a></td></tr>';
$accounts = $domain->getAccounts();
foreach ($accounts as $account) {
print '<tr><td style="text-align:left;"><a href="compte.php?domain='.$domain->getName().'&account='.$account->getUid().'">' .$account->getName().' &lt;'.$account->getUid().'&gt;</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 "</tbody></table>";
} elseif ( (isset($_GET['viewonly'])) && ($_GET['viewonly']==2) ) {

View file

@ -0,0 +1,32 @@
<?php
class LdapAccount extends LdapDomain {
protected $domain,$uid,$name,$active=false;
public function __construct($domain, $uid) {
$this->conn = $domain->conn;
$this->domain = $domain->getName();
$this->uid = $uid;
if ($sr = @ldap_search($this->conn, "uid=".$uid.",cn=".$this->domain.",".LDAP_BASE, "(ObjectClass=mailAccount)")) {
$objects = ldap_get_entries($this->conn, $sr);
$object = $objects[0];
$this->name = $object['cn'][0];
//$this->quota = getquota($this->domain,'user');
} else {
throw new Exception("Ce compte n'existe pas !");
}
}
public function getUid() {
return $this->uid;
}
public function getName() {
return $this->name;
}
public function __destruct() {
return true;
}
}

View file

@ -48,9 +48,12 @@ class LdapDomain extends LdapServer {
$rdn = "ou=people," .LDAP_BASE;
}
$sr = ldap_search($this->conn, $rdn, "(objectClass=mailAccount)");
$info = ldap_get_entries($this->conn, $sr);
for ($i=0;$i<$info["count"];$i++) {
array_push($this->accounts,$info[$i]["uid"][0]);
$objects = ldap_get_entries($this->conn, $sr);
foreach($objects as $object) {
if(!empty($object["uid"][0])) {
$account = new LdapAccount($this, $object["uid"][0]);
array_push($this->accounts, $account);
}
}
}
return $this->accounts;