sipcapture / homer-api

HOMER 5: Back-End (API) DEPRICATED - use sipcapture/homer-app
http://sipcapture.org
27 stars 67 forks source link

LDAP Integration #58

Closed shahbour closed 8 years ago

shahbour commented 9 years ago

Hello

I tried to add LDAP support , it worked eventually but i had to do couple of changes as below

so i liked to share them

diff --git a/api/Authentication/LDAP.php b/api/Authentication/LDAP.php
index 5e5dad5..1e26cdd 100644
--- a/api/Authentication/LDAP.php
+++ b/api/Authentication/LDAP.php
@@ -67,12 +67,11 @@ class LDAP extends Authentication {
                      @ldap_start_tls($ds);
                }

-               if (defined('LDAP_BIND_USER') && defined('LDAP_ADMIN_USER')) {
+               if (defined('LDAP_BIND_USER') && defined('LDAP_BIND_PASSWORD')) {
                      if (!@ldap_bind( $ds, LDAP_BIND_USER, LDAP_BIND_PASSWORD)) {
                            return array();
                       }
                }
-
                 $r=@ldap_search( $ds, LDAP_BASEDN, LDAP_USERNAME_ATTRIBUTE_OPEN .$param['username'].LDAP_USERNAME_ATTRIBUTE_CLOSE);
                 if ($r) {
                      $result = @ldap_get_entries( $ds, $r);
@@ -90,7 +89,11 @@ class LDAP extends Authentication {
                                    // Default each user has normal User Privs
                                     $_SESSION['loggedin'] = $param['username'];
                                     $_SESSION['userlevel'] = LDAP_USERLEVEL;
-                       
+                                   $_SESSION['uid']        = 1;
+                                   $_SESSION['username']   = $param['username'];
+                                           $_SESSION['gid']        = 10;
+                                   $_SESSION['grp']        = "users";
+       
                                    $user['uid']     =  1;
                                    $user['username'] = $param['username'];
                                    $user['gid']      = 10;
@@ -107,7 +110,8 @@ class LDAP extends Authentication {

                                        if ($value == $param['username']) {
                                          $_SESSION['userlevel'] = 1; # LDAP_ADMINLEVEL;
-                                         $user['grp'] = "users,admins";   
+                                         $user['grp'] = "users,admins"; 
+                                         $_SESSION['grp']        = "users";  
                                        }
                                    }
                                     return $user;

Also in preference.php

/* LDAP SETTINGS */

define('LDAP_HOST',"192.168.XX.11");
define('LDAP_PORT',389);
define('LDAP_BASEDN',"ou=people,dc=XXXX,dc=com");
define('LDAP_REALM',"My Realm");
define('LDAP_USERNAME_ATTRIBUTE_OPEN',"uid=");
define('LDAP_USERNAME_ATTRIBUTE_CLOSE',"");
define('LDAP_USERLEVEL',3); 
define('LDAP_BIND_USER','uid=XXXXX,cn=admins,cn=XXXXX');
define('LDAP_BIND_PASSWORD','XXXXXX');
define('LDAP_ENCRYPTION','no');
define('LDAP_VERSION','3');
define('LDAP_ADMIN_USER','ali');
adubovikov commented 9 years ago

Thank you,

can you please send a merge request for this code ?

shahbour commented 9 years ago

I am new to github , any help on how to do that ?

On Wed, Oct 21, 2015 at 1:35 PM Alexandr Dubovikov notifications@github.com wrote:

Thank you,

can you please send a merge request for this code ?

— Reply to this email directly or view it on GitHub https://github.com/sipcapture/homer-api/issues/58#issuecomment-149850093 .

lmangani commented 9 years ago

Hi @shahbour and thanks for your contribution! To create a request, just clone the repository to your account in Github, pull your fork and apply your patch. Once done and pushed back, you can send us back a PULL request from your Clone. We also kindly ask you to sign our CLA at http://cla.qxip.net

adubovikov commented 8 years ago

switching to: https://github.com/sipcapture/homer-api/pull/59

salehhoushangi commented 5 years ago

could yo tell me what is define('LDAP_BIND_USER','uid=XXXXX,cn=admins,cn=XXXXX')??

adubovikov commented 5 years ago

https://github.com/sipcapture/homer-api/blob/master/api/Authentication/LDAP.php#L71

https://www.php.net/manual/en/function.ldap-bind.php