lastLogon 특성을 매 분마다 수집하여 사용하고자 한다.
그런데 문제는 AD 서버가 2대인데 사용자 인증에 사용된 서버에서만 lastLogon 특성 값이 업데이트가 된다.
$options1 = array("domain_controllers" => array("ad1st"));
$options2 = array("domain_controllers" => array("ad2nd"));
$adldap1 = new adLDAP($options1);
$adldap2 = new adLDAP($options2);
$users = $adldap1->user()->all(true,"*", true);
$lastLogons = array();
foreach($users as $id => $name ) {
$info1 = $adldap1->user()->infoCollection($id, array("*"));
$mktime1 = round(convertWindowsTimestamp($info1->lastLogon));
$info2 = $adldap2->user()->infoCollection($id, array("*"));
$mktime2 = round(convertWindowsTimestamp($info2->lastLogon));
if( $mktime1 > $mktime2 ) {
$mktime = $mktime1;
$auth = "ad1st";
} else if( $mktime1 < $mktime2 ) {
$mktime = $mktime2;
$auth = "ad2nd";
} else {
$mktime = $mktime1;
$auth = "ad1st";
}
$lastLogon = date("YmdHis", $mktime);
$lastLogons["$id"] = array("auth" => $auth, "lastlogon" => $lastLogon);
}
전체 사용자 정보를 담은 인스턴스를 생성 후 각 사용자 마다 lastLogon 정보를 찾아서 비교 후에 다시 배열로 저장했다.
그런데 lastLogon 의 값은 linux 의 mktime() 값과 다르기에 convertWindowsTimestamp()를 사용하였다.
function convertWindowsTimestamp($wintime) {
return $wintime / 10000000 - 11644473600;
}