Ldap Integration -- PHP Error
  • I am trying to get the login to integrate with ldap. I found the old campsite plugin and I tried it. I followed the instructions by adding it to the root folder and changing the configuration, when I try logging in after I create a user i get a PHP error stating
    PHP Fatal error: Call to undefined function camp_set_error_handler() in /srv/www/htdocs/newscoop/include/pear/LiveUser/Auth/Ldap.php on line 31, referer: http://ip/newscoop/en/issue2/real_estate/

    any idea as of why?
  • 27 Comments sorted by
  • Vote Up0Vote Down Andrey PodshivalovAndrey Podshivalov
    Posts: 1,526Member, Administrator, Sourcefabric Team
    Ldap add-on is a bit incompatible with 3.5.x

    Remove lines #18 and #31 in pear/LiveUser/Auth/Ldap.php and try again.
  • now it gave the same error but on line 30.
  • Vote Up0Vote Down Andrey PodshivalovAndrey Podshivalov
    Posts: 1,526Member, Administrator, Sourcefabric Team
    you have removed wrong lines.
    Restore file and remove exactly 18 & 31 lines

  • well the errors are gone but it resturns a blank page.

    I noticed in the file there is another place where you can set the LDAP credentials, but in the README it just says change the ones in conf/liveuser_configuration_ext.php.. do i need to change the ones in pear/LiveUser/Auth/Ldap.php this one as well?
  • Vote Up0Vote Down Andrey PodshivalovAndrey Podshivalov
    Posts: 1,526Member, Administrator, Sourcefabric Team
    blank screen means a error. Switch on the display errors in php.ini
    Quote:
    do i need to change the ones in pear/LiveUser/Auth/Ldap.php this one as well?
    You don't need to change default settings in Ldap.php.
  • so it took forever but I figured out that when you said remove line 18 and 31.. i removed line 18 and line 31 became line 30... i don't get a blank page now..

    It works so far.. I will let you know if anything pops up... again thank you very much
  • I have another question..

    What I am trying to do:
    Instead of registering, they log in and if it passes by ldap it automatically registers them with their username Full name and email which I can grab by ldap..

    I know how to grab their attributes but I am having problems inserting them into the database.. any suggestions?
  • Vote Up0Vote Down Andrey PodshivalovAndrey Podshivalov
    Posts: 1,526Member, Administrator, Sourcefabric Team
    you can find useful code in admin-files/users/do_add.php file, like:
    require_once($GLOBALS['g_campsiteDir']. "/$ADMIN_DIR/users/users_common.php");
    $fieldValues = array(....) // define all necessary fields from ldap
    $editUser = new User();
    if ($editUser->create($fieldValues)) {
        if ($uType == 'Staff') {
            $editUser->setUserType($Type);
        }
    }
    
  • Sorry, but I am very new at PHP
    This is the function I have been working with
        function readUserData($handle = '', $passwd = '', $auth_user_id = false)
        {
            if (!$auth_user_id) {
                $result = false;
                $connect = @ldap_connect('ldap://' . $this->ldap_host, $this->ldap_port);
                if ($connect) {
                    ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, $this->ldap_protocol_ver);
                    if ($this->ldap_tls) {
                        @ldap_start_tls($connect);
                    }
                   // Perform search for user...
                   $base = "o=blah";
                   $filter = "cn=$handle";
                   $attributes = array("dn","givenname","sn","mail" );
    
                   $results = ldap_search($connect, $base, $filter, $attributes);
    
                   // Retrieve results...
                   $entry = ldap_get_entries($connect, $results);
                    $dn = $entry[0]['dn'];
                    $fname = $entry[0]['givenname'][0];
                    $lname = $entry[0]['sn'][0];
                    $email = $entry[0]['mail'][0];
                    $bind = sprintf($dn, $handle);
                    if (@ldap_bind($connect, $bind, $passwd)) {
                        $result = true;
                    $fullname = "$fname $lname";
                    $password="michigan";
                    require_once($GLOBALS['g_campsiteDir']. "/$ADMIN_DIR/users/users_common.php");
                    $fieldValues = array("$handle","$password","$fullname","$email"); // define all necessary fields from ldap
                    $editUser = new User();
                    $phorumUser = new Phorum_user();
                    if (!$phorumUser->UserNameExists($fieldValues['UName']) &&
                    $editUser->create($fieldValues)) {
            if ($uType == 'Staff') {
            $editUser->setUserType($Type);
        }
            $phorumUser->create($fieldValues['UName'], $password, $fieldValues['EMail'], $editUser->getUserId());
    
                    ldap_close($connect);
    
    

    i added what you said... and I get this error

    Notice: Undefined variable: ADMIN_DIR in /srv/www/htdocs/newscoop/include/pear/LiveUser/Auth/Ldap.php on line 45

    Warning: LiveUser_Auth_Ldap::require_once(/srv/www/htdocs/newscoop//u sers/users_common.php) [liveuser-auth-ldap.require-once]: failed to open stream: No such file or directory in /srv/www/htdocs/newscoop/include/pear/LiveUser/Auth/Ldap.php on line 45

    Fatal error: LiveUser_Auth_Ldap::require_once() [function.require]: Failed opening required '/srv/www/htdocs/newscoop//users/users_common.php' (include_path='/srv/www/htdocs/newscoop/include/pear:.:/usr/ share/php5:/usr/share/php5/PEAR') in /srv/www/htdocs/newscoop/include/pear/LiveUser/Auth/Ldap.php on line 45
  • Vote Up0Vote Down Andrey PodshivalovAndrey Podshivalov
    Posts: 1,526Member, Administrator, Sourcefabric Team
    change to
    require_once($GLOBALS['g_campsiteDir']. "/$ADMIN_DIR/users/users_common.php");
  • Vote Up0Vote Down Andrey PodshivalovAndrey Podshivalov
    Posts: 1,526Member, Administrator, Sourcefabric Team
    Andrey Podshivalov wrote on Fri, 08 July 2011 16:21
    change to
    require_once($GLOBALS['g_campsiteDir']. "/$ADMIN_DIR/users/users_common.php");

    sorry,

    just add global $ADMIN_DIR before require_once
  • I've been playing with it for a while now... i edited it down to this
    global $ADMIN_DIR;
    require_once($GLOBALS['g_campsiteDir']. "/$ADMIN_DIR/users/users_common.php");
    $editUser = new User();
    $phorumUser = new Phorum_user();
    $phorumUser->create($fieldValues['UName']=$handle, $password, $fieldValues['EMail']=$email, $editUser->getUserId());
    
    


    and managed to get this error... am I on the right track?

    Notice: Undefined index: system_email_from_address in /srv/www/htdocs/newscoop/include/phorum/include/db/mysql.php on line 4689
    Duplicate entry '0' for key 2: insert into phorum_users set username='teststu', password='446494b1fd32a6b2d66e2b5f470feb0f7e1fd6c3', email='teststu@blah.edu'[/email], date_added=1310140918, date_last_active=1310140918, hide_email='1', active=1
  • In your code
    $phorumUser->create($fieldValues['UName']=$handle, $password, $fieldValues['EMail']=$email, $editUser->getUserId());
    

    how do you set the fk_campsite_user_id.. everytime i create a user it is set to 0
  • Vote Up0Vote Down Andrey PodshivalovAndrey Podshivalov
    Posts: 1,526Member, Administrator, Sourcefabric Team
    you don't need to define fk_campsite_user_id. It's a system field which handled by framework

    do_add.php has complete code for user adding.

  • Thanks. I will try this
  • i am getting an error with this code

                   $entry = ldap_get_entries($connect, $results);
                    $dn = $entry[0]['dn'];
                    $fname = $entry[0]['givenname'][0];
                    $lname = $entry[0]['sn'][0];
                    $email = $entry[0]['mail'][0];
                    $fullname = "$fname $lname";
                    $password="michigan";
    
                    $bind = sprintf($dn, $handle);
                    if (@ldap_bind($connect, $bind, $passwd)) {
                        $result = true;
                    }
                    ldap_close($connect);
                 global $ADMIN_DIR;
                    require_once($GLOBALS['g_campsiteDir']. "/$ADMIN_DIR/users/users_common.php");
                   $fieldValues = array($fullname,$handle,$password,$email); // define all necessary fields from ldap
                   $editUser = new User();
                    $phorumUser = new Phorum_user();
    
    $phorumUser->create($fieldValues['UName']=$handle, $password,$fieldValues['EMail']=$email,$editUser->getUserId());
    $editUser->create($fieldValues['UName']=$handle, $fieldValues['Name']=$fullname,$password, $fieldValues['EMail']=$email,$fieldValues['Type']='Subscribers');
    
    


    Warning: Invalid argument supplied for foreach() in /srv/www/htdocs/newscoop/classes/User.php on line 109

    and again it adds it into the phorum users but not the liveuser_users database
  • Vote Up0Vote Down Andrey PodshivalovAndrey Podshivalov
    Posts: 1,526Member, Administrator, Sourcefabric Team
    please, follow do_add.php code. You are using wrong parameters in editUser->create
  • I followed the format of your do_add.php
    I don't get any error codes so i put in some echo statements to see if it was actually doing what it was supposed to do..
    Here is what I have.
     global $ADMIN_DIR;
                    require_once($GLOBALS['g_campsiteDir']. "/$ADMIN_DIR/users/users_common.php");
                    $fieldValues = array('UName'=>$handle, 'Name'=>$fullname, 'EMail'=>$email, 'Type'=>'Subscribers');
                    $editUser = new User();
                    $phorumUser = new Phorum_user();
                    if (!$phorumUser->UserNameExists($fieldValues['UName']) &&
                    $editUser->create($fieldValues)) {
                    echo "blah";
                    $phorumUser->create($fieldValues['UName']=$handle, $password,$fieldValues['EMail']=$email,$editUser->getUserId());
    } else {
            echo "blahhhhhhhhhhhhhhhhhhhhh";
    
    }            }
    
    

    It keeps echoing the blahhhhhhhhhhhhhhhhh that is out of the loop..

    if (!$phorumUser->UserNameExists($fieldValues['UName']) &&
                    $editUser->create($fieldValues)) 
    

    The teststu is not in the database, so I don't know why it keeps forgoing the loop.. I tried removing the phorum user part.. and just leave the $editUser part but i still end up with .. There was an error when entering data: Invalid user credentials

    By the time I am done with this I should be an expert in PHP lol
    seriously thank you for your time on this... when this gets all done can I buy you a pizza or something?
  • Vote Up0Vote Down Andrey PodshivalovAndrey Podshivalov
    Posts: 1,526Member, Administrator, Sourcefabric Team
    you have to define password. It could be any text.
  • I tried this with the same result

     global $ADMIN_DIR;
                    require_once($GLOBALS['g_campsiteDir']. "/$ADMIN_DIR/users/users_common.php");
                  
                    $fieldValues = array('UName'=>$handle, 'Name'=>$fullname, 'EMail'=>$email, 'Type'=>'Subscribers');
                    $fieldValues['passwd'] = $password;
    
                    $editUser = new User();
                    $phorumUser = new Phorum_user();
                    if (!$phorumUser->UserNameExists($fieldValues['UName']) &&
                    $editUser->create($fieldValues)) {
                    echo "blah";
                    $phorumUser->create($fieldValues['UName']=$handle, $password,$fieldValues['EMail']=$email,$editUser->getUserId());
    } else {
            echo "blahhhhhhhhhhhhhhhhhhhhh";
    
    }            }
    
    


    I just tried this adding 'passwd'=>$password to the fieldValues and that didn't work either

    I don't know if you meant I actually had to define password, but that is above the code I showed..

     $entry = ldap_get_entries($connect, $results);
                    $dn = $entry[0]['dn'];
                    $fname = $entry[0]['givenname'][0];
                    $lname = $entry[0]['sn'][0];
                    $email = $entry[0]['mail'][0];
                    $fullname = "$fname $lname";
                    $password="michigan";
    

  • Vote Up0Vote Down Andrey PodshivalovAndrey Podshivalov
    Posts: 1,526Member, Administrator, Sourcefabric Team
    there is full functional code:
    $editUser = new User();
    
    $fields['UName'] = 'test';
    $fields['Name'] = 'Test';
    $fields['EMail'] = 'test@test';
    $fields['Reader'] = 'Y';
    $fields['passwd'] = '1234567890';
    
    if ($editUser->create($fields)) {
        $editUser->setUserType('Subscriber');
        echo 'OK';
    }
    
    Post edited by Andrey Podshivalov at 2011-11-02 16:22:26
  • I just figured it out before I looked at this... You sir are awesome...
    Can I buy you pizza or something?
  • Vote Up0Vote Down Andrey PodshivalovAndrey Podshivalov
    Posts: 1,526Member, Administrator, Sourcefabric Team
    Johnathon wrote on Thu, 14 July 2011 18:19
    I just
    Can I buy you pizza or something?

    for sure...when you will be in Minsk/Belarus Wink
  • paypal?
  • Vote Up0Vote Down Andrey PodshivalovAndrey Podshivalov
    Posts: 1,526Member, Administrator, Sourcefabric Team
  • i meant more of a personal paypal so I can give you money to buy a pizza
  • Vote Up0Vote Down Andrey PodshivalovAndrey Podshivalov
    Posts: 1,526Member, Administrator, Sourcefabric Team
    Thank you Johnathon, but Sofab is my family too Wink
  • Start a New Discussion

    Howdy, Stranger!

    It looks like you're new here. If you want to get involved, click one of these buttons!

    Poll

    No poll attached to this discussion.