做企业应用的也不时要与 LDAP 打交道的,例如组织架构、人员的管理,权限的分级控制等。以前管理 LDAP 都是用客户端工具 LDAP Browser 什么的,有时不甚方便。幸运的是,网上有一个现成的、功能完备的 LDAP Web 管理工具,那就是赫赫有名的 phpMyAdmin 的姊妹 phpLDAPadmin。
Web 方式的 phpLDAPadmin 利于发布,随处使用,基本上它有 LDAP Browser 客户端工具的所有功能,诸如条目管理、属性管理、导入导出、条件搜索等。还有比 LDAP Browser 所没有的 Schema 信息明细展示功能。
phpLDAPadmin 的界面截图请见:http://phpldapadmin.sourceforge.net/screenshots.php
您也可以进到 phpLDAPadmin 的 Demo 站点:http://thesmithfam.org/phpldapadmin-demo/htdocs/index.php 先睹为快。
本篇就来介绍 phpLDAPadmin 的安装及体验,读者最好是对 Apache、PHP、LDAP 有一定的了解。因未涉及非常具体的安装细节,只拣关键之处说明,所以如若对以上几个太过陌生的,可能中间稍有差池就要费些思量了。
一:软件准备
1. Apache HTTP Server,版本可选择 1.x 或 2.x,到 http://httpd.apache.org/ 下载。本文测试用的是 Apache 1.3.28。我偷了一下懒,直接用了安装 WAS 5.1 装上的 IBM HTTP Server。
2. OpenLDAP for Windows,文中版本是 2.2.29,可从 http://download.bergmans.us/openldap/openldap-2.2.29/openldap-2.2.29-db-4.3.29-openssl-0.9.8a-win32_Setup.exe 下载。当然你也可以选择其他的版本。
3. PHP 5,本文所用版本为 5.2.6,从 http://cn.php.net/distributions/php-5.2.6-Win32.zip 下载。因为这里的 phpLDAPadmin-1.1.0.5 要求是 PHP 5。
4. phpLDAPadmin,目前版本是 1.1.0.5,不过本文仍使用 1.1.0 版本,因为 1.1.0.5 我使用中有些问题,可从 http://nchc.dl.sourceforge.net/sourceforge/phpldapadmin/phpldapadmin-1.1.0.zip 下载。
二:软件安装
1. Apache 的安装
这个东西的安装、启动和停止就不多说了,用 %APACHE_HOME% 表示 Apache 的安装目录。
2. OpenLDAP 的安装配置
请参考之前写过的一篇日志:Windows下安装使用openldap。当然,你也可以藉此连接到一个已有的 LDAP 服务器,那么这一步就可以直接跳过。
只是我们将使用 OpenLDAP Samples(http://www.zytrax.com/books/ldap/ch5/index.html) 中的目录结构。所以与前面不同的是要把 OpenLDAP 安装目录下的 slapd.conf 中的 suffix、rootdn 和 rootpw 分别改为如下:
suffix "dc=example,dc=com"
rootdn "cn=jimbob,dc=example,dc=com"
rootpw dirtysecret
然后拷贝下面文本框中的内容保存为 example.ldif 文件,比如放在 C 盘根目录下。
version: 1 # 为: dc=example,dc=com,导出LDIF # 由phpLDAPadmin ( http://phpldapadmin.sourceforge.net/ ) 在 September 11, 2008 8:33 am上生成的 # 服务器: My LDAP Server (10.128.12.16) # 搜索范围: sub # 搜索过滤器: (objectClass=*) # 条目总数: 15 dn: dc=example,dc=com dc: example description: My wonderful company as much text as you want to place in this line up to 32K continuation data for the line above must have or < LF> i.e. ENTER works on both Windows and *nix system - new line MUST begin with ONE SPACE objectClass: dcObject objectClass: organization o: Example, Inc. dn: ou=customers,dc=example,dc=com objectClass: organizationalUnit ou: customers description: customer address book branch dn: ou=equipment,dc=example,dc=com objectClass: organizationalUnit ou: equipment description: IT assets branch dn: cn=LP1,ou=equipment,dc=example,dc=com objectClass: device cn: LP1 description: Some brand of printer serialNumber: 1-77-23-15 l: Room 17 owner: cn=John Smith,ou=people,dc=example,dc=com ou: printers dn: ou=groups,dc=example,dc=com objectClass: organizationalUnit ou: groups description: generic groups branch dn: cn=hrpeople,ou=groups,dc=example,dc=com objectClass: groupOfNames cn: hrpeople description: Human Resources group member: cn=Robert Smith,ou=people,dc=example,dc=com dn: cn=itpeople,ou=groups,dc=example,dc=com objectClass: groupOfNames cn: itpeople description: IT security group member: cn=William Smith,ou=people,dc=example,dc=com dn: cn=salespeople,ou=groups,dc=example,dc=com objectClass: groupOfNames cn: salespeople description: Sales group member: cn=John Smith,ou=people,dc=example,dc=com dn: ou=people,dc=example,dc=com ou: people description: All people in organisation objectClass: organizationalUnit dn: cn=John Smith,ou=people,dc=example,dc=com objectClass: inetOrgPerson cn: John Smith cn: John J Smith sn: Smith uid: jsmith userPassword: jSmitH carLicense: HISCAR 124 homePhone: 555-111-2223 mail: [email protected] mail: [email protected] mail: [email protected] ou: Sales dn: ou=addressbook,cn=John Smith,ou=people,dc=example,dc=com objectClass: organizationalUnit ou: addressbook description: Personal Address Book dn: cn=Robert Smith,ou=people,dc=example,dc=com objectClass: inetOrgPerson cn: Robert Smith cn: Robert J Smith cn: bob smith sn: smith uid: rjsmith userPassword: rJsmitH carLicense: HISCAR 123 homePhone: 555-111-2222 mail: [email protected] mail: [email protected] mail: [email protected] description: swell guy ou: Human Resources dn: ou=addressbook,cn=Robert Smith,ou=people,dc=example,dc=com objectClass: organizationalUnit ou: addressbook description: Personal Address Book dn: cn=Sheri Smith,ou=people,dc=example,dc=com objectClass: inetOrgPerson cn: Sheri Smith sn: smith uid: ssmith userPassword: sSmitH carLicense: HERCAR 125 homePhone: 555-111-2225 mail: [email protected] mail: [email protected] mail: [email protected] ou: IT dn: ou=addressbook,cn=Sheri Smith,ou=people,dc=example,dc=com objectClass: organizationalUnit ou: addressbook description: Personal Address Book
接着在 slapd -d 1 启动了 OpenLDAP 后,再用命令
ldapadd -x -D "cn=jimbob,dc=example,dc=com" -w dirtysecret -f c:/example.ldif
导入到 OpenLDAP 中。导入后 LDAP 的目录结构如下图所示:
Your install of PHP appears to be missing GETTEXT support.
GETTEXT is used for language translation.
Please install GETTEXT support before using phpLDAPadmin.
(Dont forget to restart your web server afterwards)