add ldap class
authorStricted <info@nexus-irc.de>
Sun, 16 Feb 2014 23:56:52 +0000 (00:56 +0100)
committerStricted <info@nexus-irc.de>
Sun, 16 Feb 2014 23:56:52 +0000 (00:56 +0100)
LDAP.class.php [new file with mode: 0644]

diff --git a/LDAP.class.php b/LDAP.class.php
new file mode 100644 (file)
index 0000000..fbf4623
--- /dev/null
@@ -0,0 +1,88 @@
+<?php
+/**
+ * @author      Jan Altensen (Stricted)
+ * @copyright   2013-2014 Jan Altensen (Stricted)
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ */
+
+class LDAP {
+       /**
+        * LDAP resource id
+        */
+       protected $ldap = Null; 
+       
+       /**
+        * LDAP DN
+        */
+       protected $dn = '';
+       
+       /**
+        * Constructs a new instance of LDAP class.
+        */
+       public function __construct () {
+               if(!extension_loaded("ldap")) {
+                       throw new Exception("Can not find LDAP extension.");
+               }
+
+       }
+       
+       /**
+        * connect to a ldap server
+        *
+        * @param       string  $server
+        * @param       integer $port
+        * @param       string  $dn
+        * @return      bool    true/false
+        */
+       public function connect ($server, $port, $dn) {
+               $this->ldap = ldap_connect($server, $port);
+               $this->dn = $dn;
+               if($this->ldap) {
+                       ldap_set_option($this->ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
+                       ldap_set_option($this->ldap, LDAP_OPT_REFERRALS, 0);
+                       return true;
+               } else {
+                       throw new Exception("Cant connect to ldap server.");
+               }
+               return false;
+       }
+       
+       /**
+        *      returns ldap user array
+        *
+        *      @param  string  $user
+        *      @param  string  $password
+        *      @return array
+        */
+       public function bind ($user, $password) {
+               return ldap_bind($this->ldap, $user.",".$this->dn, $password);
+       }
+       
+       /**
+        *      search user on ldap server
+        *
+        * @param       string  $search
+        * @return      resource
+        */
+       public function search ($search) {
+               return ldap_search($this->ldap, $this->dn, $search);
+       }
+       
+       /**
+        * get entries from search resource
+        *
+        * @param       resource        $resource
+        * @return      array
+        */
+       public function get_entries ($resource) {
+               return ldap_get_entries($this->ldap, $resource);
+       }
+       
+       /**
+        * close ldap connection
+        */
+       public function close () {
+               ldap_close($this->ldap);
+       }
+}
+?>
\ No newline at end of file