rbroder
Posts: 67
|
Posted: 03/27/2018, 8:47 AM |
|
Here's my setup and what I did on my testing server. WampServer 2.2 running php 5.3.10, Apache 2.2.21 on Windows 2012 R2. The key is getting the php_ldap library and driver to work. Make sure that the following files are COPIED from /wamp/bin/php/php5.3.10 to /wamp/bin/apache/apache2.2.21/bin: libsasl.dll, libeay32.dll,ssleay32.dll. The last 2 were already there in my case. The coding requires calling the ldap connection function and authenticating the user, then setting the Session Variables required by CCS5. If you don't set these variables the target page never loads and you are kicked back to the login page. I did not modify common.php. I just didn't call CCLoginUser().
Make a new login page using the CCS5 builder or modify your existing. Here is the CCS5 code with my modifications. Note that words between <> must be put in by you. Don't include the <>:
<?php
//BindEvents Method @1-D3E6B248
function BindEvents()
{
global $Login;
global $CCSEvents;
$Login->Button_DoLogin->CCSEvents["OnClick"] = "Login_Button_DoLogin_OnClick";
}
//End BindEvents Method
//Login_Button_DoLogin_OnClick @3-1454CF55
function Login_Button_DoLogin_OnClick(& $sender)
{
$Login_Button_DoLogin_OnClick = true;
$Component = & $sender;
$Container = & CCGetParentContainer($sender);
global $Login; //Compatibility
//End Login_Button_DoLogin_OnClick
//Login @4-A8229250
global $CCSLocales;
global $Redirect;
$username = $Container->login->Value;
$password = $Container->password->Value;
if ($Container->autoLogin->Value != $Container->autoLogin->CheckedValue) {
CCSetCookie("ccPOTESTLogin", "");
}
$ldap = ldap_connect("<your domain controller hostname or IP address");
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
//ldap_set_option($ldap, LDAP_OPT_DEBUG_LEVEL, 7);
$ldaprdn = '<your Domain name>'."\\".$username;
if(!$ldap){
//die( "LDAP Failed To Connect: ".ldap_error($ldap));
}
if (!$bind = ldap_bind($ldap, $ldaprdn, $password))
{
//die("user: ".$Container->password->Value);
// if ( !CCLoginUser( $Container->login->Value, $Container->password->Value)) {
$Container->Errors->addError($CCSLocales->GetText("CCS_LoginError"));
$Container->password->SetValue("");
$Login_Button_DoLogin_OnClick = 0;
CCSetCookie("ccPOTESTLogin", "");
} else {
//echo("ldap is good");
//add the next line to establish CCS session variables (id, group, username)
SetUserVariables($username);
global $Redirect;
if ($Container->autoLogin->Value == $Container->autoLogin->CheckedValue) {
$ALLogin = $Container->login->Value;
$ALPassword = $Container->password->Value;
CCSetALCookie($ALLogin, $ALPassword);
}
// die("ready to redirect: ".ccGetParam("ret_link"));
//die(ccGetUserID()."; ".ccgetGroupID()."; ".ccgetUserLogin());
$Redirect = CCGetParam("ret_link", $Redirect);
$Login_Button_DoLogin_OnClick = 1;
}
//End Login
//Close Login_Button_DoLogin_OnClick @3-0EB5DCFE
return $Login_Button_DoLogin_OnClick;
}
//End Close Login_Button_DoLogin_OnClick
//Page_BeforeInitialize @1-0242CABD
function Page_BeforeInitialize(& $sender)
{
$Page_BeforeInitialize = true;
$Component = & $sender;
$Container = & CCGetParentContainer($sender);
global $login; //Compatibility
//End Page_BeforeInitialize
//Custom Code @9-2A29BDB7
// -------------------------
// Write your own code here.
// -------------------------
//End Custom Code
//Close Page_BeforeInitialize @1-23E6A029
return $Page_BeforeInitialize;
}
//End Close Page_BeforeInitialize
Function SetUserVariables($username)
{
$db = new clsDBSecurity();
$sql = "Select userid, groupid from tblUsers WHERE username = ".$db->ToSQL($username, ccsText);
//die($sql);
$db->query($sql);
$result = $db->next_record();
//{die("userID= ". $db->f("userid"));
ccSetSession("UserID", $db->f("userid"));
ccSetSession("GroupID", $db->f("groupid"));
CCSetSession("UserAddr", $_SERVER["REMOTE_ADDR"]);
ccSetSession("UserLogin",$username);
$db->close();
}
?>
You can verify this is working by changing a user's password from your security database and then trying to log in. Try an incorrect password to test for that also.
Happy coding.
|