PHP操作AD,adLDAP類API詳解與執行個體_PHP教程

來源:互聯網
上載者:User
本文簡述通過PHP操作AD
工具 ADLDAP.php
下載位置http://adldap.sourceforge.net/download.php
API(以下來自http://adldap.sourceforge.net,翻譯水平有限,如有不妥之處敬請指正)
constructor($options=array())//構造器
你可以通過組態變數的方式指定該類中AD的設定, 或者當類被調用的時候可以通過指定$option數組的方式被覆蓋.
調用方式形似 $object = new adLDAP($options); $options 是一個由下列一個或多個keys組成的數組

account_suffix
預設:”@mydomain.local”
完整的域帳戶尾碼
base_dn
預設: “DC=mydomain,DC=local”
域的base dn. 一般來講 base dn 與account suffix相同, 但是被隔開的且以"DC="為首碼. base dn 可被定位於Active Directory Users及Computers MMC的擴
展屬性上
如果認證使用者正常,但不能搜尋,一般來說是由於指定了不正確的base_dn

domain_controllers
預設: array (“dc01.mydomain.local”)
網域控制站數組,如果你希望該類通過多個控制器來平衡查詢,可以在該數組中指定多個控制器,記住該類會向一個不可串連的網域控制站發送請求,因為它只實施平衡
而無容錯
.

ad_username
預設: NULL
預設地,adLDAP會以已經認證的使用者帳號許可權執行查詢,你可以指定一個擁有更高許可權的用來執行授權操作的使用者帳號

ad_password
預設: NULL
ad_username相應的密碼.

real_primarygroup
通過“Domain Users” 覆蓋 primary group

use_ssl
預設: false
adLDAP 可以通過SSL使用LDAP以提供額外功能例如修改密碼,選擇此項時你的網域控制站和WEB伺服器均需配置相應選項,不只將其設定為true,詳細請參考SSL方式的
LDAP選項

recursive_groups
預設: true
遞迴查詢群組成員
如使用者Fred是組“Business Unit” 的成員,“Business Unit” 是組Department”的成員,Department”是組“Company”的成員
user_ingroup(“Fred”,”Company”)當該項開啟的時候返回true,否則返回false
------------------------以下主要的操作方法
authenticate($username,$password,$prevent_rebind=false)
鑒別網域控制站使用者的username/password

group_add_group($parent,$child)
向父組裡添加子組,返回true或false

group_add_user($group,$username)
向一個組裡添加一個使用者,返回true或false

group_create($attributes)
以指定屬性建立一個組,返回true或false

Attribute Req Notes
group_name *
container *
description

group_del_group($parent,$child)
從父組裡刪除子組,返回true或false

group_del_user($group,$users)
從一個組裡刪除一個使用者,返回true或false

group_info($group_name,$fields=NULL)
返回一個關於指定組的資訊數組,組名稱區分大小寫
預設檔案包含member, memberof, description, distinguishedname, objectcategory, samaccountname

user_create($attributes)
建立一個使用者,操作成功或失敗時返回true或false

Attribute Req Notes
username *
firstname *
surname *
email *
container * The folder in AD to add the user to.
address_city
address_code
address_pobox
address_state
address_street
change_password 如果為0使用者下次登入時無需修改密碼為1時下次登入時必須修改密碼
company 公司名稱.
department
description
display_name
email email地址,非exchange mailbox
enabled 0 為 disabled 1 為 enabled
expires 帳戶有效期間 (unix timestamp).
firstname
home_directory
home_drive
initials
logon_name 登入名稱稱不同於其他使用者名稱.
manager
office
password The password can only be set over SSL. It must also meet the password policy for your domain.
profile_path
script_path
surname
title
telephone
web_page

user_delete($username)
刪除一個使用者,返回 true 或 false

user_groups($username,$recursive=NULL)
返回使用者所屬組的資訊

如果$recursive為 true, 將遞迴返回組列表.

user_info($username,$fields=NULL)
返回指定使用者的資訊數組,$fields必須為數組
預設fields 為: samaccountname, mail, memberof, department, displayname, telephonenumber, primarygroupid
欲查看所有可用資訊,將$fields 設定"*"調用此函數
這個函數將返回一個有限集,除非當前認證帳戶為administrator,一個使用者也不能查詢另一個使用者的"memberof"域,除非它們是這個容器的管理者

user_ingroup($username,$group,$recursive=NULL)
使用者是否屬於該組,返回true或false
像user_info()函數一樣,這個函數只有噹噹前認證使用者是administrator時才會返回有效結果

user_modify($username,$attributes)
修改使用者屬性,返回true或false

user_password($username,$password)
設定指定使用者的密碼,. 要求配置通過ldaps.

computer_info($computer_name,$fields=NULL)
返回指定電腦的詳細資料.

all_users($include_desc = false, $search = "*", $sorted = true)
返回AD裡使用者所有列表,在大目錄裡可能無法工作
all_groups($include_desc = false,$search = "*", $sorted = true)
返回AD裡組所有列表,在大目錄裡可能無法工作
Samples:
登入
include "adLDAP.php"
$config['account_suffix'] = '@xxx.com';//網域控制站尾碼
$config['adserver'] = array('192.168.1.10','192.168.1.1');//網域控制站,如果只有一台array('192.168.1.10')
$config['base_dn'] = 'cn=users,dc=xxx,dc=com';
$adldap =new adLDAP(array('domain_controllers'=>$config['adserver'],'account_suffix'=>$config['account_suffix'],'base_dn'=>$config
['base_dn'],'ad_username' => 'administrator','ad_password' => ''));
if($adldap)
{
echo "登入成功";
}
else
{
echo "登入失敗";
}
?>
列出所有使用者
echo "All users
";
foreach($adldap->all_users() as $val)
{
echo $val."
";
}
?>
列出所有組
echo "groups
";
foreach($adldap->all_groups() as $val)
{
echo $val."
";
}
?>
列印某台電腦資訊
print_r($adldap->user_info("wang"));
?>
建立使用者
if ($adldap->user_create(array('username' => 'tonix','firstname' => 'firstname','surname' => "surname",'email' => 'e@123.com','container' =>
'container')))
{
echo "OK";
}
else
{
echo "error";
}
?>
建立組
if ($adldap->group_create("group_name=test,container=www"))
{
echo "OK";
}
else
{
echo "error";
}
?>

作者“飛翔的人生”

http://www.bkjia.com/PHPjc/478629.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/478629.htmlTechArticle本文簡述通過PHP操作AD 工具 ADLDAP.php 下載位置http://adldap.sourceforge.net/download.php API(以下來自http://adldap.sourceforge.net,翻譯水平有限,如有不妥之...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.