วิธีการเชื่อมต่อ PSU Passport ด้วย Drupal7 ผ่าน LDAPS Module Lightweight Directory Access Protocol
ทดสอบบน : Windows 2008 R2 / IIS 7.5 / Drupal 7.34 / LDAP Module 7.x-1.0-beta12
งานพัฒนาระบบ, เขียนโปรแกรม
วิธีการเชื่อมต่อ PSU Passport ด้วย Drupal7 ผ่าน LDAPS Module Lightweight Directory Access Protocol
ทดสอบบน : Windows 2008 R2 / IIS 7.5 / Drupal 7.34 / LDAP Module 7.x-1.0-beta12
วิธีการเชื่อมต่อ PSU Passport ด้วย Drupal6 ผ่าน LDAPS Module LDAP integration
ทดสอบบน : Windows 2008 R2 / IIS 7.5 / Drupal 6.34 / LDAP integration 6.x-1.x-dev
วิธีการเชื่อมต่อ PSU Passport ด้วย Joomla ผ่าน LDAPS Plugin
ทดสอบบน : Windows 2008 R2 / IIS 7.5 / Joomla 1.5.26/2.5.28/3.3.6
ก่อนอื่นขออธิบายนิดนะครับในส่วนการ Map Full Name
ชื่อ นามสกุล ภาษาไทย ให้ใช้ field = description
ชื่อ นามสกุล ภาษาอังกฤษ ให้ใช้ field = displayname
Joomla 1.5.26 Capture Authentication – LDAP Plugin Settings
(บทความเก่าทดสอบบน Ubuntu 12.04-Apache2)
Joomla 2.5.28 Capture Authentication – LDAP Plugin Settings
Joomla 3.3.6 Capture Authentication – LDAP Plugin Settings
วิธีการเชื่อมต่อ PSU Passport ด้วย ASP Classic ผ่าน LDAPS
ทดสอบบน : Windows 2008 R2 / IIS 7.5 / .NET 2.0
เนื่องจาก Code ค่อนข้างเยอะ ขอแป๊ะแค่ link ให้ Download File ดังนี้
Source Code : https://passport.psu.ac.th/ldap/dotnetpsuldap.7z
Password : psuldap#$%
วิธีการเชื่อมต่อ PSU Passport ด้วย ASP Classic ผ่าน LDAPS
ทดสอบบน : Windows 2008 R2 / IIS 7.5
Code ดังนี้
Class PSULdap (psuldap.inc)
<%
'PSU Passport ASP-LDAP Class Version 1.0.0
'Author : Jatuporn Chuchuay ISD CC PSU (Tel.2121)
'Update : 06/02/2013
Class PSULdap
Private strAdsPath
Private strUserName
Private strPassWord
Private strDC
Public Property Let AdsPath(sAdsPath)
strAdsPath = sAdsPath
End Property
Public Property Let UserName(sUserName)
strUserName = sUserName
End Property
Public Property Let PassWord(sPassWord)
strPassWord = sPassWord
End Property
Public Property Let DC(sDC)
strDC = sDC
End Property
Public Property Get vAdsPath
vAdsPath = strAdsPath
End Property
Public Property Get vUserName
vUserName = strUserName
End Property
Public Property Get vPassWord
vPassWord = strPassWord
End Property
Public Property Get vDC
vDC = strDC
End Property
Public Function LdapAuthen()
Dim objConn,objRS,objCom, strDescription, strLine, listDC, authenCheck, i
Dim MyVar(1,20)
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.provider ="ADsDSOObject"
objConn.Properties("User ID") = "psu\" & strUserName
objConn.Properties("Password") = strPassWord
objConn.Properties("Encrypt Password") = True
objConn.open "Active Directory Provider"
Set objCom = CreateObject("ADODB.Command")
Set objCom.ActiveConnection = objConn
listDC = Split(strDC,",",-1,1)
authenCheck = false
i = 0
While i <= UBound(listDC) and authenCheck = false
objCom.CommandText ="select sAMAccountname,cn," & _
"distinguishedName,employeeid,citizenid,company,campusid,department,departmentid," & _
"physicaldeliveryofficename,positionid,description,displayname,title,personaltitle," & _
"personaltitleid,givenname,sn,sex,userprincipalname,mail from 'LDAP://" & listDC(i) & _
":636/"+strAdsPath+"' where sAMAccountname='" & strUserName & "' and objectClass='user'"
On Error Resume Next
Set objRS = objCom.Execute
If Not Err.Number = 0 Then
MyVar(0,0) = false
MyVar(1,0) = Err.Description
'Debug
'Response.write listDC(i) & ":" & MyVar(0,0) & ":" & _
'MyVar(1,0) & "<br/>"
Else
MyVar(0,0) = true
'Debug
'Response.write listDC(i) & ":" & MyVar(0,0) & "<br/>"
authenCheck = true
End If
i = i + 1
Wend
If authenCheck = true Then
MyVar(1,0) = objRS("sAMAccountname")
MyVar(1,1) = objRS("cn")
MyVar(1,2) = objRS("employeeid")
MyVar(1,3) = objRS("citizenid")
MyVar(1,4) = objRS("company")
MyVar(1,5) = objRS("campusid")
MyVar(1,6) = objRS("department")
MyVar(1,7) = objRS("departmentid")
MyVar(1,8) = objRS("physicaldeliveryofficename")
MyVar(1,9) = objRS("positionid")
For Each strLine In objRS.Fields("description").Value
strDescription = strDescription & strLine
Next
MyVar(1,10) = strDescription
MyVar(1,11) = objRS("displayname")
MyVar(1,12) = objRS("title")
MyVar(1,13) = objRS("personaltitle")
MyVar(1,14) = objRS("personaltitleid")
MyVar(1,15) = objRS("givenname")
MyVar(1,16) = objRS("sn")
MyVar(1,17) = objRS("sex")
MyVar(1,18) = objRS("userprincipalname")
MyVar(1,19) = objRS("mail")
MyVar(1,20) = objRS("distinguishedName")
End If
LdapAuthen = MyVar
objRS.Close
objConn.Close
Set objRS = Nothing
Set objConn = Nothing
Set objCom = Nothing
End Function
End Class
%>
Code Login (default.asp)
<%@ Language=VBScript %>
<%
'PSU Passport ASP-LDAP Weblogin Version 1.0.0
'Author : Jatuporn Chuchuay ISD CC PSU (Tel.2121)
'Update : 06/02/2013
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PSU Passport : ASP-LDAP example</title>
</head>
<body>
<!-- #include file ="psuldap.inc" -->
<%
Response.CharSet = "TIS-620"
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
Dim PSULdapCls, AuthenResult, SamAccountName, EmployeeID, CitizenID, CN, DN
Dim Campus, CampusID, Department, DepartmentID, WorkDetail, PositionID
Dim Description,DisplayName, Detail, Title, TitleID, FirstName, LastName
Dim Sex, Mail, Othermail
Set PSULdapCls = New PSULdap
PSULdapCls.AdsPath = "DC=psu,DC=ac,DC=th"
'DC1(VM),2(RACK),7(VM)-Hatyai,DC3(RACK)-Pattani,DC5(RACK)-Surat,DC6(RACK)-Trang
PSULdapCls.DC = "dc2.psu.ac.th,dc7.psu.ac.th,dc1.psu.ac.th"
PSULdapCls.UserName = Request.Form("username")
PSULdapCls.PassWord = Request.Form("password")
AuthenResult = PSULdapCls.LdapAuthen()
If AuthenResult(0,0) = True Then
SamAccountName = AuthenResult(1,0)
CN = AuthenResult(1,1)
EmployeeID = AuthenResult(1,2)
CitizenID = AuthenResult(1,3)
CampusID = AuthenResult(1,5)
WorkDetail = AuthenResult(1,8)
Department = AuthenResult(1,6)
DepartmentID = AuthenResult(1,7)
Campus = AuthenResult(1,4)
PositionID = AuthenResult(1,9)
Description = AuthenResult(1,10)
Displayname = AuthenResult(1,11)
Detail = AuthenResult(1,12)
Title = AuthenResult(1,13)
TitleID = AuthenResult(1,14)
FirstName = AuthenResult(1,15)
LastName = AuthenResult(1,16)
Sex = AuthenResult(1,17)
Mail = AuthenResult(1,18)
Othermail = AuthenResult(1,19)
DN = AuthenResult(1,20)
'Display
'On Error Resume Next
Response.write "Authentication OK" & "<br/>"
Response.write "<br/>>> User Profile <<<br/>"
Response.write "Account Name : " & SamAccountName & "<br/>"
Response.write "Employee ID/Student ID : " & EmployeeID & "<br/>"
Response.write "Citizen ID : " & CitiZenID & "<br/>"
Response.write "CN : " & CN & "<br/>"
Response.write "DN : " & DN & "<br/>"
Response.write "Campus : " & Campus & "(" & CampusID & ")<br/>"
Response.write "Department : " & Department & "(" & DepartmentID & _
")<br/>"
Response.write "Work Detail : " & WorkDetail & "<br/>"
Response.write "Position ID : " & PositionID & "<br/>"
Response.write "Description : " & Description & "<br/>"
Response.write "Display Name : " & DisplayName & "<br/>"
Response.write "Detail : " & Detail & "<br/>"
Response.write "Title Name : " & Title & "(" & TitleID & ")<br/>"
Response.write "First Name : " & FirstName & "<br/>"
Response.write "Last Name : " & LastName & "<br/>"
Response.write "Sex : " & Sex & "<br/>"
Response.write "Mail : " & Mail & "<br/>"
Response.write "Other Mail : " & Othermail & "<br/>"
Response.write "<br/><a href='./default.asp'>Back to Login Page</a><br/>"
Else
Response.write "Authentication Failed" & "<br/>"
Response.write "Reason : " & AuthenResult(1,0) & "<br/>"
End If
Else
%>
This area is restricted.<br>
Please login to continue.<br>
<form method='post' action=''>
Username: <input type='text' name='username' value=''><br>
Password: <input type='password' name='password'><br>
<br>
<input type='submit' name='submit' value='Submit'><br>
</form>
<%
End If
%>
</body>
</html>
ต่อจาก
วิธีพัฒนา Squirrelmail Plugin – กรณี pagespeed
เทคนิคการส่งค่าจาก PHP ให้ JavaScript
เมื่อรู้ระยะเวลาที่ Web Browser ประมวลผลแล้ว ต่อไปก็ต้องการเก็บข้อมูลต่างๆมาเก็บที่ Web Server เพื่อบันทึกเก็บไว้วิเคราะห์ต่อไป สามารถทำได้โดยการใช้ JavaScript ส่งค่่าผ่าน HTTP GET Method มายัง PHP
เริ่มจากสร้าง PHP ให้ชื่อว่า getdata.php สำหรับรับค่าจาก JavaScript ที่ทำงานจาก Web Browser ของผู้ใช้ ดังนี้
<?php
$data=$_GET['data'];
$h = fopen('/var/log/userview.log', 'a');
fwrite($h, $data . "\n" );
fclose($h)
?>
สมมุติ เรียกใช้ผ่าน URL ต่อไปนี้
http://myserver.com/getdata.php?data=xxyyzz
ก็จะเอาค่า xxyyzz เขียนใส่ไฟล์ /var/log/userview.log และต่อท้ายไปเรื่อยๆ
ในฝั่งของ JavaScript ให้เขียนโค๊ดดังนี้
<SCRIPT LANGUAGE="JavaScript">
var xmlhttp;
var url;
var data;
data=servertime + ":" + second + ":" + total ;
url="http://myserver.com/getdata.php?data=" + data;
if (window.XMLHttpRequest)
xmlhttp = new XMLHttpRequest();
else
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open(\'GET\',url, true);
xmlhttp.send();
</script>
เท่านี้ก็จะสามารถเก็บค่าต่างๆจาก Web Browser มาไว้ที่ Web Server ได้
ต่อจากตอนที่แล้ว “วิธีพัฒนา Squirrelmail Plugin – กรณี pagespeed”
จากการพัฒนา pagespeed plugin สำหรับ Squirrelmail เพื่อแสดงให้ผู้ใช้เห็นถึง “ความเร็ว” ในการประมวลผลจากฝั่ง server ได้แล้ว
ต่อไปเราต้องการเอาดูว่า “ความเร็ว” ในการเดินทางและแสดงผลบน Web Browser ของผู้ใช้ เป็นเท่าไหร่
ทำได้โดยการใช้งาน JavaScript จับเวลาการทำงาน
โดยเขียนโค๊ดต่อไปนี้ ใน ฟังก์ชั่น pagespeed_top
echo ' <SCRIPT LANGUAGE="JavaScript"> beforeload = (new Date()).getTime(); </script> ';
และส่วนนี้ไปในฟังก์ชั่น pagespeed_bottom
echo ' <SCRIPT LANGUAGE="JavaScript">
afterload = (new Date()).getTime();
seconds = (afterload-beforeload)/1000;
document.write("Browser Speed: " + seconds + " s");
</script>
';
เท่านี้ก็จะทราบระยะเวลาในการเดินทางและแสดงผลเสร็จบน Web Browser แล้วแสดงผลต่อผู้ใช้
ต่อไปหากต้องการ รวมเวลาทั้งสิ้นที่ผู้ใช้ต้องรอ ตั้งแต่การทำงานที่ Squirrelmail จนกระทั้ง แสดงผลเสร็จ
ก็ต้องเอาค่าตัวแปรจาก PHP ที่ชื่อว่า $showtime มาบวกกับตัวแปรของ JavaScript ที่ชื่อว่า seconds
จะส่งค่าจาก PHP ให้ JavaScript อย่างไร ???
ดูเหมือนยาก แต่จริงๆแล้ว ก็เพียงแค่ให้ PHP แสดงผลเป็นตัวแปรของ JavaScript เท่านั้น ก็สามารถทำให้ JavaScript เอาไปใช้งานต่อได้แล้ว ดังนี้
echo ' <SCRIPT LANGUAGE="JavaScript"> servertime = ' . $showtime . ';</SCRIPT>' ;
แล้วปรับแต่งโค๊ดใน pagespeed_bottom ข้างต้นเป็น
echo ' <SCRIPT LANGUAGE="JavaScript">
servertime = ' . $showtime . ';</SCRIPT>' ;
echo ' <SCRIPT LANGUAGE="JavaScript">
afterload = (new Date()).getTime();
seconds = (afterload-beforeload)/1000;
document.write("Browser Speed: " + seconds + " s");
total=servertime + seconds;
document.write("Total:" + total + " s");
</script> ';
เป็นตัวอย่างเทคนิคในการส่งค่าระหว่างการคำนวนของ PHP และ JavaScript เบื้องต้น
ติดตามต่อไปในเรื่องของ “เทคนิคในการบันทึกความเร็วของ Web Browser มาเก็บไว้ที่ Web Server”
Squirrelmail เป็น IMAP Client Webmail แบบมาตราฐาน ทำงานบน PHP ซึ่งติดตั้งง่าย ใช้งานได้รวดเร็ว ไม่ต้องกังวลเรื่องความเข้ากันได้กับ Web Browser ของผู้ใช้หลากหลาย เพราะไม่ค่อยมีการใช้งานพวก JavaScript
มีความง่ายในการต่อขยายความสามารถ โดยผู้พัฒนาเปิดให้เขียน Plugin ได้ง่าย โดยไม่ต้องแก้ไข Code ของระบบโดยตรง ด้วยวิธีการเสียบ Code ผ่านจุดที่กำหนด ที่เรียกว่า “Hook” ทำให้ Plugin ที่เขียนขึ้น สามารถใช้งานต่อไปได้ แม้มีการปรับรุ่นของ Squirrelmail ต่อไป
ตัวอย่างการเขียน Squirrelmail Plugin เพื่อแสดงความเร็วในการประมวลผลในแต่ละส่วนของ Squirrelmail
ใช้ชื่อว่า pagespeed (ทำงานบน Squirrelmail 1.4.x)
$starttime=0;
function squirrelmail_plugin_init_pagespeed() {
global $squirrelmail_plugin_hooks;
// Code Go Here
}
ชื่อฟังกชั่นต้องเป็น squirrelmail_plug_init_xxx() โดยที่ xxx ต้องตรงกับชื่อ folder ในที่นี้คือ pagespeed
$squirrelmail_plugin_hooks['login_top']['pagespeed'] = 'pagespeed_top'; $squirrelmail_plugin_hooks['login_bottom']['pagespeed'] = 'pagespeed_bottom';
รูปแบบการเขียนคือ
$squirrelmail_plugin_hooks[‘ตำแหน่งที่จะเสียบ’][‘ชื่อ plugin’] = ‘ชื่อฟังก์ชั่น’;
function pagespeed_top() {
global $starttime;
$gentime = microtime();
$gentime = explode(' ',$gentime);
$gentime = $gentime[1] + $gentime[0];
$starttime=$gentime;
}
ส่วน pagespeed_bottom ทำหน้าที่ ดูเวลาสิ้นสุด แล้วคำนวนเวลาที่ใช้ไป
จากนั้น ก็แสดงผลการคำนวนได้
function pagespeed_bottom() {
global $starttime;
$gentime = microtime();
$gentime = explode(' ',$gentime);
$gentime = $gentime[1] + $gentime[0];
$pg_end = $gentime;
$totaltime = ($pg_end - $starttime);
$showtime = number_format($totaltime, 4, '.' , '');
echo 'Speed: ' . $showtime . ' s' ;
}
เท่านี้ก็ได้ plugin แล้ว ต่อไปก็เอาไปติดตั้งได้
หากต้องการวัดความเร็วในหน้าอื่นๆ เช่น ในส่วนของ right_main (ส่วนแสดงรายการ email ที่อยู่ใน mailbox) ก็สามารถเพิ่มเข้าไปในฟังก์ชั่น squirrelmail_plugin_init_pagespeed ดังนี้
$squirrelmail_plugin_hooks['right_main_after_header']['pagespeed'] = 'pagespeed_top'; $squirrelmail_plugin_hooks['right_main_bottom']['pagespeed'] = 'pagespeed_bottom';
รายละเอียดเกี่ยวกับตำแหน่งของ Hook ดูได้ที่นี่ http://squirrelmail.org/docs/devel/devel-4.html#ss4.4
วิธีการเชื่อมต่อ PSU Passport ด้วย PHP ผ่าน LDAPS
ทดสอบบน : Windows 2008 R2 / IIS 7.5
Code ดังนี้
Include Function ldappsu (ldappsu.php)
<?php
//Function LDAPPSU Version 1.0.0
//Author : Jatuporn Chuchuay ISD CC PSU (Tel.2082)
//Update : 22/12/2014
// The LDAP server
// Authenticate the against server the domain\username and password combination.
function authenticate($server,$basedn,$domain,$username,$password)
{
$auth_status = false;
$i=0;
while(($i<count($server))&&($auth_status==false)){
$ldap = ldap_connect("ldaps://".$server[$i]) or
$auth_status = false;
ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
$ldapbind = ldap_bind($ldap, $username."@".$domain,$password);
if($ldapbind){
if(empty($password)){
$auth_status = false;
}else{
$result[0] = true;
//Get User Info
$result[1] = get_user_info($ldap,$basedn,$username);
}
}else{
$result[0] = false;
}
ldap_close($ldap);
$i++;
}
return $result;
}
function get_user_info($ldap,$basedn,$username)
{
$user['cn'] = "";
$user['dn'] = "";
$user['accountname'] = "";
$user['personid'] = "";
$user['citizenid'] = "";
$user['campus'] = "";
$user['campusid'] = "";
$user['department'] = "";
$user['departmentid'] = "";
$user['workdetail'] = "";
$user['positionid'] = "";
$user['description'] = "";
$user['displayname'] = "";
$user['detail'] = "";
$user['title'] = "";
$user['titleid'] = "";
$user['firstname'] = "";
$user['lastname'] = "";
$user['sex'] = "";
$user['mail'] = "";
$user['othermail'] = "";
$sr=ldap_search($ldap, $basedn,
"(&(objectClass=user)(objectCategory=person)(sAMAccountName=".$username."))",
array("cn", "dn", "samaccountname", "employeeid", "citizenid", "company",
"campusid", "department", "departmentid", "physicaldeliveryofficename", "positionid",
"description", "displayname", "title", "personaltitle", "personaltitleid", "givenname",
"sn", "sex", "userprincipalname","mail"));
$info = ldap_get_entries($ldap, $sr);
$user['cn'] = $info[0]["cn"][0];
$user['dn'] = $info[0]["dn"];
$user['accountname'] = $info[0]["samaccountname"][0];
$user['personid'] = $info[0]["employeeid"][0];
$user['citizenid'] = $info[0]["citizenid"][0];
$user['campus'] = $info[0]["company"][0];
$user['campusid'] = $info[0]["campusid"][0];
$user['department'] = $info[0]["department"][0];
$user['departmentid'] = $info[0]["departmentid"][0];
$user['workdetail'] = $info[0]["physicaldeliveryofficename"][0];
$user['positionid'] = $info[0]["positionid"][0];
$user['description'] = $info[0]["description"][0];
$user['displayname'] = $info[0]["displayname"][0];
$user['detail'] = $info[0]["title"][0];
$user['title'] = $info[0]["personaltitle"][0];
$user['titleid'] = $info[0]["personaltitleid"][0];
$user['firstname'] = $info[0]["givenname"][0];
$user['lastname'] = $info[0]["sn"][0];
$user['sex'] = $info[0]["sex"][0];
$user['mail'] = $info[0]["userprincipalname"][0];
$user['othermail'] = $info[0]["mail"][0];
return $user;
}
?>
Code หน้า Login (login.php)
<?php
//PSU Passport PHP-LDAP Weblogin Version 1.0.0
//Author : Jatuporn Chuchuay ISD CC PSU (Tel.2121)
//Update : 04/01/2013
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PSU Passport : PHP-LDAP example</title>
</head>
<body>
<?php
if(isset($_POST['username'])){
//Include PHPLDAP Class File
require "./ldappsu.php";
//DC1(VM),2(RACK),7(VM)-Hatyai,DC3(RACK)-Pattani,DC5(RACK)-Surat,DC6(RACK)-Trang
$server = array("dc2.psu.ac.th","dc7.psu.ac.th","dc1.psu.ac.th");
$basedn = "dc=psu,dc=ac,dc=th";
$domain = "psu.ac.th";
$username = $_POST['username'];
$password = $_POST['password'];
//Call function authentication
$ldap = authenticate($server,$basedn,$domain,$username,$password);
if($ldap[0]){
echo "<br/>>> User Profile <<<br/>";
echo "Account Name : ".$ldap[1]['accountname']."<br/>";
echo "Employee ID/Student ID : ".$ldap[1]['personid']."<br/>";
echo "Citizen ID : ".$ldap[1]['citizenid']."<br/>";
echo "CN : ".$ldap[1]['cn']."<br/>";
echo "DN : ".$ldap[1]['dn']."<br/>";
echo "Campus : ".$ldap[1]['campus']."(".$ldap[1]['campusid'].")<br/>";
echo "Department : ".$ldap[1]['department']."(".$ldap[1]['departmentid'].")<br/>";
echo "Work Detail : ".$ldap[1]['workdetail']."<br/>";
echo "Position ID : ".$ldap[1]['positionid']."<br/>";
echo "Description : ".$ldap[1]['description']."<br/>";
echo "Display Name : ".$ldap[1]['displayname']."<br/>";
echo "Detail : ".$ldap[1]['detail']."<br/>";
echo "Title Name : ".$ldap[1]['title']."(".$ldap[1]['titleid'].")<br/>";
echo "First Name : ".$ldap[1]['firstname']."<br/>";
echo "Last Name : ".$ldap[1]['lastname']."<br/>";
echo "Sex : ".$ldap[1]['sex']."<br/>";
echo "Mail : ".$ldap[1]['mail']."<br/>";
echo "Other Mail : ".$ldap[1]['othermail']."<br/>";
}
}else{
?>
This area is restricted.<br>
Please login to continue.<br>
<form method='post' action=''>
Username: <input type='text' name='username' value=''><br>
Password: <input type='password' name='password'><br>
<br>
<input type='submit' name='submit' value='Submit'><br>
</form>
<?php
}
?>
</body>
</html>
**** บทความเก่าเชื่อมต่อผ่าน ADLDAP ด้วย ubuntu 12.04/Apache2 ****
1. หลังจากติดตั้ง Apache2 และ เปิด Module php5-ldap เรียบร้อยแล้ว
2. ทำการโหลดโปรแกรม adLDAP จาก Website : http://adldap.sourceforge.net/download.php (สำหรับ PHP 4 ให้โหลด Version 2.1)
# cd /var/www
# wget http://downloads.sourceforge.net/project/adldap/adLDAP/adLDAP_4.0.4/adLDAP_4.0.4r2.zip
# unzip adLDAP_4.0.4r2.zip
3. เปิดหน้าตัวอย่างการเข้าใช้งานได้ที่ https://localhost/adLDAP/examples/authenticate.php
(สำหรับ Web ตัวอย่างต้องใช้เป็น https เท่านั้น)
4. ทำการแก้ไขไฟล์ /var/www/adLDAP/src/adLDAP.php บรรทัดเหล่านี้
…
protected $accountSuffix = “@psu.ac.th”;
…
protected $baseDn = “DC=psu,DC=ac,DC=th”;
…
protected $domainControllers = array(“dc2.psu.ac.th”,”dc7.psu.ac.th”,”dc1.psu.ac.th”);
…
protected $useSSL = true;
…
(สำหรับรายการ DC ให้เลือก DC ใกล้ที่สุดก่อน DC3-ปัตตานี, DC4-ภูเก็ต,DC5-สุราษฎร์,DC6-ตรัง,DC1,2,7-หาดใหญ่)
5. กลับมาเข้าที่ Web https://localhost/adLDAP/examples/authenticate.php อีกครั้งน่าจะสามารถใช้งานได้แล้ว
โดยสำหรับตัวนี้แนะนำว่าให้ใช้เฉพาะในส่วน authen เพราะในส่วนของการดึง Profile ยังค่อนข้างมีข้อจำกัด อยู่ ซึ่งถ้าอยากให้สามารถดึง Profile ได้ด้วย ผมแนะนำในส่วนของ Code ที่ผมเขียนขึ้นมาให้ โดยจะกล่าวในส่วนถัดไป
วิธีเรียกใช้งานไฟล์ Class AdLDAP (ให้ copy file จาก folder src ไปด้วย)
include “./adLDAP.php”
วิธีเรียกใช้ Class AdLDAP
try {
$adldap = new adLDAP();
}catch(adLDAPException $e){
echo $e;
exit();
}
วิธี Authentication
if($adldap->authenticate($username,$password)){
session_start();
$_SESSION[“username”] = $username;
…
}