ldap信息交互未完成

  1 <?php
2
3 error_reporting(E_all && ~E_notice);
4
5 class LDAP{
6 public $Server = '192.168.1.87';
7 public $Port = '389';
8 public $UserName = 'huangxiang@adtest.qy';
9 public $PassWord = 'ABC123abc';
10 public $LdapConn = null;
11
12 //打开连接
13 public function Conn(){
14 if($this -> LdapConn = ldap_connect($this -> Server, $this -> Port)){
15 if(!ldap_bind($this -> LdapConn, $this -> UserName, $this -> PassWord)) return false;
16 return true;
17 }
18 return false;
19 }
20
21 //关闭连接
22 public function Close(){
23 if($this -> LdapConn){
24 ldap_unbind($this -> LdapConn);
25 ldap_close($this -> LdapConn);
26 }
27 return true;
28 }
29
30 //添加用户
31 public function AddUser($Uinfo){
32 if(!(isset($Uinfo["objectclass"]) && $Uinfo["objectclass"] != '')) return false;
33 return ldap_add($this -> LdapConn, "cn=".$Uinfo["cn"].",o=jite", $Uinfo);
34 }
35
36 //删除用户
37 public function DelUser($DN){
38 return ldap_delete($this -> LdapConn, $DN);
39 }
40
41 //修改用户
42 public function EditUser($DN, $Uinfo){
43 return ldap_modify($this -> LdapConn, $DN , $Uinfo);
44 }
45
46 //获取资料
47 public function GetUser($sdn, $filter){
48 $sr=ldap_search($this -> LdapConn, $sdn, $filter);
49 $info = ldap_get_entries($this -> LdapConn, $sr);
50 $ReturnInfo = array();
51 for($i=0; $i < $info['count']; $i++){
52 $UserInfo = array();
53 for($j=0; $j < $info[$i]['count']; $j++){
54 $Name = $info[$i][$j];
55 if($info[$i][$Name]['count'] == 1){
56 $Value = $info[$i][$Name][0];
57 if($Name =='objectsid'){
58 $Value = $this -> bin_to_str_sid($Value);
59 }
60 if($Name =='objectguid'){
61 $Value = $this -> bin_to_str_guid($Value);
62 }
63 }else{
64 unset($info[$i][$Name]['count']);
65 $Value = $info[$i][$Name];
66 }
67 $UserInfo[$Name] = $Value;
68 }
69 $ReturnInfo[] = $UserInfo;
70 }
71 return $ReturnInfo;
72 }
73
74 //转SID
75 public function bin_to_str_sid($binsid){
76 $hex_sid = bin2hex($binsid);
77 $rev = hexdec(substr($hex_sid, 0, 2));
78 $subcount = hexdec(substr($hex_sid, 2, 2));
79 $auth = hexdec(substr($hex_sid, 4, 12));
80 $result = $rev.'-'.$auth;
81 for($x=0;$x < $subcount; $x++){
82 $subauth[$x] = hexdec($this -> little_endian(substr($hex_sid, 16 + ($x * 8), 8)));
83 $result .= '-'.$subauth[$x];
84 }
85 return 'S-'.$result;
86 }
87
88 public function little_endian($hex){
89 for($x = strlen($hex) - 2; $x >= 0; $x = $x - 2){
90 $result .= substr($hex, $x, 2);
91 }
92 return $result;
93 }
94
95 //转GID
96 public function bin_to_str_guid($object_guid){
97 $hex_guid = bin2hex($object_guid);
98 $hex_guid_to_guid_str = '';
99 for($k = 1; $k <= 4; ++$k){
100 $hex_guid_to_guid_str .= substr($hex_guid, 8 - 2 * $k, 2);
101 }
102 $hex_guid_to_guid_str .= '-';
103 for($k = 1; $k <= 2; ++$k){
104 $hex_guid_to_guid_str .= substr($hex_guid, 12 - 2 * $k, 2);
105 }
106 $hex_guid_to_guid_str .= '-';
107 for($k = 1; $k <= 2; ++$k){
108 $hex_guid_to_guid_str .= substr($hex_guid, 16 - 2 * $k, 2);
109 }
110 $hex_guid_to_guid_str .= '-' . substr($hex_guid, 16, 4);
111 $hex_guid_to_guid_str .= '-' . substr($hex_guid, 20);
112 return strtoupper($hex_guid_to_guid_str);
113 }
114
115 //时间转换
116 public function mtime_int($IntTime){
117 if(substr($IntTime, -3) == '.0Z'){
118 return mktime(substr($IntTime, 8, 2), substr($IntTime, 10, 2), substr($IntTime, 12, 2), substr($IntTime, 4, 2), substr($IntTime, 6, 2), substr($IntTime, 0, 4));
119 }else{
120 $SecTime = doubleval(substr($IntTime, -8));
121 $SecTimes = doubleval(substr($IntTime, 0, -8));
122 return $SecTime+$SecTimes;
123 }
124 }
125 }
126 $LDAP = new LDAP();
127 $LDAP -> Conn();
128
129 //时间处理测试
130 echo date("Y-m-d H:i:s", $LDAP -> mtime_int('20110303060135.0Z'));
131 echo '<br />';
132 echo date("Y-m-d H:i:s", $LDAP -> mtime_int('129436053140801250'));
133 //输出测试
134 $sdn = "cn=users,dc=adtest,dc=qy";
135 $filter = "(&(objectCategory=person))";
136 print_r($LDAP -> GetUser($sdn, $filter));
137
138
139 $LDAP -> Close();
140 ?>
141 <pre>
142
143
144 u_sysid 会员系统ID
145 u_username 登录名
146 [userprincipalname] => huangxiang@adtest.qy
147 u_email 邮箱地址
148 u_password 登录密码
149 u_actived 是否激活:1已激活;2未激活
150 u_company_id 公司ID:未加入公司前为0
151 u_register_date 注册时间
152 u_role 角色(1超管权限为all,2行管,3应管)
153 u_rights 权限(all为超管)
154 u_typeid 会员类型(对应qy_user_type表的u_type_sysid)
155 u_reg_type 会员注册类型(1为自行注册 2为管理器添加 3为业务员注册)
156 u_ad_sysid 用户来源id,1主站,2DNS导入
157 u_mod_username 默认1, 1不可修改、2可修改、3必须修改
158 u_guide_step 快速引导步骤(0为步骤完成,默认步骤为1,步骤数递增)
159
160
161
162
163
164
165
166 uinfo_u_sysid 会员ID:来源于会员表(q_user)
167 uinfo_company_name 公司名称
168 uinfo_department_name 部门名称
169 [department] => test
170 uinfo_jobs_name 岗位名称
171 uinfo_email 邮箱
172 uinfo_username 登陆名
173 [userprincipalname] => huangxiang@adtest.qy
174 uinfo_real_name 真实姓名
175 [cn] => 黄祥
176 uinfo_register_date 注册时间
177 [whencreated] => 20110303033239.0Z
178 uinfo_login_number 登陆次数
179 [logoncount] => 2
180 uinfo_last_login_date 最近登陆时间
181 [lastlogon] => 129436053219395000
182 uinfo_last_login_ip 最近登陆IP
183 uinfo_sex 性别:1男,2女,3保密
184 uinfo_birthday 生日
185 uinfo_country 所在国家
186 uinfo_province 所在省份
187 uinfo_city 所在市区
188 uinfo_adders 联系地址
189 uinfo_mobile 手机号
190 uinfo_qq QQ号
191 uinfo_msn
192 uinfo_id_number 身份证号
193 uinfo_pic_url 用户照片
194 uinfo_integral 会员积分
195 uinfo_homepage 个人主页
196 uinfo_phone 联系电话
197 uinfo_last_check_date
198
199 </pre>

 

posted @ 2012-01-17 15:55  祥辉  阅读(304)  评论(0编辑  收藏  举报