Page 1 of 2

how do I auto import all users from ldap?

Posted: Mon Jan 15, 2018 11:29 pm
by murat
hi, I want to import all user into lms from ldap.
How do I this process ?
Do you know?

Re: how do I auto import all users from ldap?

Posted: Wed Jan 24, 2018 4:17 pm
by barlasd
I wrote a workaround that automatically adds the user to the database users, after the login (obviously after verifying that the LDAP accepts the login).

If you are interested i can share the code.

Re: how do I auto import all users from ldap?

Posted: Wed Jan 24, 2018 4:25 pm
by canelli
very interesting feature

can you share the code ? we will integrate in forma.lms 2.0

claudio

Re: how do I auto import all users from ldap?

Posted: Thu Jan 25, 2018 12:24 am
by murat
barlasd wrote:I wrote a workaround that automatically adds the user to the database users, after the login (obviously after verifying that the LDAP accepts the login).

If you are interested i can share the code.

please , can you share your codes?

Re: how do I auto import all users from ldap?

Posted: Thu Jan 25, 2018 10:15 am
by barlasd
Edit the file lib.user.php into the folder lib:

Replace the rows 231-235 with this code:

Code: Select all

if( $user_info === false ){
			
			if(Get::sett('ldap_used') == 'on') {
				
				$ldap_conn = @ldap_connect( Get::sett('ldap_server'), Get::sett('ldap_port', '389'));
				$ldap_user = ereg_replace( '\$user', $login, Get::sett('ldap_user_string') );
				if(ldap_bind($ldap_conn, $ldap_user, $password))
				{
					ldap_close($ldap_conn);
					$logldap = "/".$login;
					list($userid) = sql_fetch_row(sql_query("SELECT userid FROM core_user WHERE userid='$logldap'"));
					if($userid == ""){
						$date = date("Y-m-d H:i:s");
						list($idstMember) = sql_fetch_row(sql_query("SELECT max(idst)+1 FROM core_st"));
						sql_query("INSERT INTO core_user (idst, userid, valid, register_date) VALUES ($idstMember,'$logldap',1,'$date')");
						sql_query("INSERT INTO core_st (idst) VALUES ('$idstMember')"); 
						sql_query("INSERT INTO core_group_members (idst, idstMember) VALUES (1,'$idstMember')"); 
					}
				}
				else{
					  return $ret_value;
				}
			}	
			else{
				return $ret_value;
			} 
		}
    
		if( $user_info[ACL_INFO_VALID] != '1' && Get::sett('ldap_used') == 'off'){
			  return $ret_value;
		}
enjoy ;)

Re: how do I auto import all users from ldap?

Posted: Thu Jan 25, 2018 11:28 am
by canelli
Thank for sharing your work.

We will integrate this in forma.lms 2.x .
I hope in the 2.0, but we are in the final beta status and soon we will enter in the Release canditate status, so I'm not sure that we can made the change. For sure te code will be integrated in the 2.1

Claudio

Re: how do I auto import all users from ldap?

Posted: Thu Jan 25, 2018 11:33 am
by barlasd
Hi Claudio,
Is there a way to access to betatesting of the Forma 2.0 version?
I'm curious to see the new features.

Grazie. :)

Re: how do I auto import all users from ldap?

Posted: Thu Jan 25, 2018 12:01 pm
by canelli
hi barlasd .
to access beta you must enter in the "Contribution program".
you must fille the form available at www.formalms.org

Re: how do I auto import all users from ldap?

Posted: Thu Jan 25, 2018 12:19 pm
by barlasd
I had tried but i can't see the captcha...

Re: how do I auto import all users from ldap?

Posted: Thu Feb 01, 2018 11:39 am
by alberto
Captcha fixed, thanks for noticing it