From 75eedd7645d90860d23b21372febae3245bc36bb Mon Sep 17 00:00:00 2001 From: Victor LABORIE Date: Fri, 15 Dec 2017 20:25:29 +0100 Subject: [PATCH] Add LdapAccount class and use it for list accounts --- htdocs/admin.php | 10 +++++----- htdocs/lib/class.ldapaccount.php | 32 ++++++++++++++++++++++++++++++++ htdocs/lib/class.ldapdomain.php | 9 ++++++--- 3 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 htdocs/lib/class.ldapaccount.php diff --git a/htdocs/admin.php b/htdocs/admin.php index 84291e2..d682d04 100644 --- a/htdocs/admin.php +++ b/htdocs/admin.php @@ -62,11 +62,11 @@ include("inc/debut.php"); getAccounts(); - foreach ($comptes as $compte) { - print '' .$compte. ''; - print '' .getquota($compte,'user'). ''; - print ''; + $accounts = $domain->getAccounts(); + foreach ($accounts as $account) { + print '' .$account->getName().' <'.$account->getUid().'>'; + print '' .getquota($account->getUid(),'user'). ''; + print ''; } print ""; } elseif ( (isset($_GET['viewonly'])) && ($_GET['viewonly']==2) ) { diff --git a/htdocs/lib/class.ldapaccount.php b/htdocs/lib/class.ldapaccount.php new file mode 100644 index 0000000..48a175e --- /dev/null +++ b/htdocs/lib/class.ldapaccount.php @@ -0,0 +1,32 @@ +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; + } +} diff --git a/htdocs/lib/class.ldapdomain.php b/htdocs/lib/class.ldapdomain.php index 191b9ca..edc2727 100644 --- a/htdocs/lib/class.ldapdomain.php +++ b/htdocs/lib/class.ldapdomain.php @@ -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;