I am currently working on writing an LDAP integration into Gallery 1.5 that will alter the creation and handling of user account names and passwords in order to verify it against LDAP instead of the Gallery User DB.
We're going to be hosting Gallery on an Apache server that will have direct local access to the LDAP server. At this time I've already written the LDAP verification method in PHP (against Netscape LDAP protocol v3) and I'm looking at the Gallery PHP code to do the following:
1. Remove the registration option completely. This is easily done by not allowing users to self-register via the built-in gallery settings. However, the ability to self-register is necessary for the method below. Thus, we basically just want to remove the Register button, not the code behind it.
2. Use only the login screen for getting into Gallery, and plug the self-registration into this part. This looks like the following abstraction:
// Username and Password are the same as the user's email username ( [username]@domain.com ) and password.
Authenticate = Login(Username, Password);
if(Authenticate)
{
UserExsists = SearchForUserInGallery(Username);
if(UserExsists)
{
LoginToGallery();
}
else
{
Create = AskToCreateUser();
if(Create)
{
CreateNewUser(Username, Password, FirstnameFromLDAP + LastNameFromLDAP);
}
else
{
exit();
}
}
}
else
{
handleAuthenticateError(ErrorMessageID);
}
To sum up, the user logs in with their Email username and password. The LDAP script authenticates this info against the LDAP server. If the info is not correct, it kicks back to the user with an error message. If it is correct, it checks the Gallery User DB to see if that user exsists. If they do, it logs them in. If they do not, it prompts the user to ask if they wish to create a new Gallery account with the username and password they provided. If they click yes, it creates the account using the First and Last Name from LDAP and logs them in. If they click no, it kicks them back out to the Login screen.
The only exception to this is the Admin account.
By removing the "Register" button and rolling the self-registration feature into the "Login" button, we enable the user to do everything needed through just one button click.
3. Not allow users to change their passwords in Gallery. If they do, it will be different from the LDAP password, which is what we want to avoid. This could be done by removing the Preferences button after the user has logged in, as the only thing that would be modified by the user would have already been handled by LDAP. The only other change we'd need to worry about would be if the user had a name change. It could either be written to check the LDAP info versus the Gallery info each time the user logs in, or just change the info in Gallery on a case-by-case basis.
I am looking through the Gallery code right now, and am beginning to understand the basics of the registration and user account management. The main thing I'm looking for is how to search to see if a user currently has a Gallery account. Any assistance is greatly appreciated!
I'll post here as the project continues.
Posts: 65
Have disabled the Preferences and Registration buttons by commenting out the following lines of code in .\gallery\albums.php:
Note that the gallery user information can still be changed if you login as the administrator and use the admin tools.
Posts: 65
I've made further progress, and now have the LDAP authentication up and working within Gallery. On the test install, if a user has an exsisting Gallery account, and logs in using their LDAP username and password, it will allow them to log in to Gallery.
However, I've run into a bit of a snag for creating Gallery accounts for users who log in via their LDAP info, but do not yet have an account in Gallery.
Where can I find the code for the method makeFormIntro(); ?
Posts: 65
Alright, a day and much soda later, further progress.
I've been migrating the registration methods from .\gallery\register.php over into .\gallery\login.php in order to allow all users to automatically be registered when they login to Gallery IFF they have certain LDAP roles (administrator, teacher, etc.). Otherwise, it will not allow them to log in and kick back an error.
This should be completed by tomorrow, at which point I'll polish the formatting and comments then zip up the files with instructions and post them for others to pick at.
Posts: 65
Everything is done...except that the user is not properly being created by the script. I'm using the same block of code as listed in .\gallery\register.php, but it is not allowing the user's creation for some reason.
Is there anything that the following block of code from .\gallery\register.php uses to create accounts that I'm missing?
Posts: 65
Found it-- Didn't have $tempUser->save(); moved over into the new registration module. Moving now and testing.
Posts: 65
Project completed. Currently testing the Gallery in-house and cleaning up error testing code, etc. I will be posting the instructions on how to set this up later on today after writing local documentation.
Posts: 65
INSTRUCTIONS (Updated for 1.5.2)
In order to set up this, you will need to edit the PHP files in the .\Gallery\ directory. This was developed on Apache 2.0.54 / PHP 5.0.4 / Windows XP SP1. It has also been tested and verified on IIS 6.0 / PHP 4.4.0 / Windows Server 2003. Your mileage may vary with different operating system / server configurations.
Step 1: Back up the original Gallery Files
Make a copy of the following files: .\Gallery\Albums.php and Login.php. Store these in a safe location outside of the .\Gallery directory.
Step 2: Edit Albums.php using a plain text editor to prevent registration and changing preferences by user.
Please change the following lines of code as directed.
Find and replace (removes the new album button; allows only admin to create new albums on top album page):
Find and comment out (removes the user preferences button; admins can still change preferences):
Find and comment out (removes the registration button; this is instead done through the integrated LDAP login):
Step 3: Edit the contents of Login.php
You will need to change settings where appropriate to connect to your LDAP server. I have typed items that should be changed in ALL CAPS.
Find the following block of code:
Replace this with the following (warning, this is long):
Below this, find the following block of code, and comment it out:
4. Input the appropriate information that pertains to your LDAP server.
What this does is check for a user in LDAP. If that user is authenticated with the password that they login with, it then checks if they're in Gallery. If they're NOT in Gallery, it pulls the appropriate roles from LDAP and checks those. If they have a role in LDAP that should allow them to create an account, it auto-generates the account and logs them in.
5. Dance!
This is by no means perfect; I wrote it in a week after having only first seen the Gallery program on the Friday before. All input is much appreciated!
Posts: 65
User dcain1 ran into an issue with the code wherein users will be created by the auto-create changes, but will not be logged into gallery; subsequently, it confirms that they exsist, but no navigation options are presented afterwords. They were able to fix the issue by commenting out the following lines of code in session.php:
YMMV, but I hope this helps anyone troubleshooting a similar issue!
Posts: 65
Additional info-- If you are running this under IIS, you will need to make sure to do the following (from http://us3.php.net/manual/en/ref.ldap.php):
Note to Win32 Users: In order to enable this module on a Windows environment, you must copy several files from the DLL folder of the PHP/Win32 binary package to the SYSTEM folder of your windows machine. (Ex: C:\WINNT\SYSTEM32, or C:\WINDOWS\SYSTEM). For PHP <= 4.2.0 copy libsasl.dll, for PHP >= 4.3.0 copy libeay32.dll and ssleay32.dll to your SYSTEM folder.
Posts: 65
This setup has now been verified to work on Windows 2003 with IIS 6.0 and PHP 4.4.0. Will test with PHP 5.x later on.
Posts: 65
Updated the install of Gallery to 1.5.1 and moved LDAP code changes over. Looks good as ever and still works for LDAP authentication. We have been using this for a staff of about 200+ for a few months now, and it runs without hitch.
-Patrick
Posts: 1
I've played with this for the past few days and finally got it working.
One thing to note is that echo statements in the code cause the login to fail.
I attached my working version. It is slightly modified for my server. I also attached ldap_tools.P9.php which contains the testGroupMembership function I use to determine if a user can login and if new users should be admins. The other file I'm not attaching is config.P9.php which contains global settings. They are just globals at this point. Also note mine checks for a secure server.
This probably won't work for anyone but me. I'm posting it so people can see a full login.php for comparison if they are having problems.
Posts: 65
Thanks for the contribution! Glad to hear that it's working out.
Since I didn't have much experience working with LDAP before making this, I know I probably left some things out. One thing I noticed while scanning your version was the inclusion of a ldap_close(); statement, which I'll work into the code above.
-Patrick
Posts: 65
Currently working on the 1.5.2 update!
-Patrick
Posts: 65
Instructions updated for 1.5.2
-Patrick
Posts: 65
It's been some time since I've sat down and looked at this, and I wanted to take some time to set it up and test it for Gallery 1.5.6. Unfortunately, I no longer am working where I was with an easily accessible and populated LDAP server to test against, so it will take some time to set one up, populate it, and then begin testing against it.
If someone who is using Gallery 1.5.6 has an installation that they want to get working with LDAP, please let me know, and I'd be glad to work with you on it.
-Patrick