@@ -23,12 +23,12 @@ discard block |
||
23 | 23 | return false; |
24 | 24 | } |
25 | 25 | |
26 | - public function getMemberUids($recursive=true) |
|
26 | + public function getMemberUids($recursive = true) |
|
27 | 27 | { |
28 | 28 | return array(); |
29 | 29 | } |
30 | 30 | |
31 | - public function members($details=false, $recursive=true, $includeGroups=true) |
|
31 | + public function members($details = false, $recursive = true, $includeGroups = true) |
|
32 | 32 | { |
33 | 33 | return array(); |
34 | 34 | } |
@@ -46,20 +46,20 @@ discard block |
||
46 | 46 | public function jsonSerialize() |
47 | 47 | { |
48 | 48 | $group = array(); |
49 | - try{ |
|
49 | + try { |
|
50 | 50 | $group['cn'] = $this->getGroupName(); |
51 | 51 | $group['description'] = $this->getDescription(); |
52 | 52 | $group['member'] = $this->getMemberUids(); |
53 | - } catch(\Exception $e) {echo $e->getMessage(); die();} |
|
53 | + } catch (\Exception $e) {echo $e->getMessage(); die(); } |
|
54 | 54 | return $group; |
55 | 55 | } |
56 | 56 | |
57 | - public function getNonMembers($select=false) |
|
57 | + public function getNonMembers($select = false) |
|
58 | 58 | { |
59 | 59 | return array(); |
60 | 60 | } |
61 | 61 | |
62 | - public function addMember($name, $isGroup=false, $flush=true) |
|
62 | + public function addMember($name, $isGroup = false, $flush = true) |
|
63 | 63 | { |
64 | 64 | return false; |
65 | 65 | } |
@@ -70,24 +70,24 @@ discard block |
||
70 | 70 | $auth = \AuthProvider::getInstance(); |
71 | 71 | $ldap = $auth->getAuthenticator('Auth\LDAPAuthenticator'); |
72 | 72 | $ldap->get_and_bind_server(true); |
73 | - if(isset($group->description)) |
|
73 | + if (isset($group->description)) |
|
74 | 74 | { |
75 | 75 | $this->setDescription($group->description); |
76 | 76 | unset($group->description); |
77 | 77 | } |
78 | - if(isset($group->member)) |
|
78 | + if (isset($group->member)) |
|
79 | 79 | { |
80 | 80 | $this->clearMembers(); |
81 | 81 | $count = count($group->member); |
82 | - for($i = 0; $i < $count; $i++) |
|
82 | + for ($i = 0; $i < $count; $i++) |
|
83 | 83 | { |
84 | 84 | $isLast = false; |
85 | - if($i === $count - 1) |
|
85 | + if ($i === $count - 1) |
|
86 | 86 | { |
87 | 87 | $isLast = true; |
88 | 88 | } |
89 | - if(!isset($group->member[$i]->type)) continue; |
|
90 | - if($group->member[$i]->type === 'Group') |
|
89 | + if (!isset($group->member[$i]->type)) continue; |
|
90 | + if ($group->member[$i]->type === 'Group') |
|
91 | 91 | { |
92 | 92 | $this->addMember($group->member[$i]->cn, true, $isLast); |
93 | 93 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | return true; |
102 | 102 | } |
103 | 103 | |
104 | - static function from_name($name, $data=false) |
|
104 | + static function from_name($name, $data = false) |
|
105 | 105 | { |
106 | 106 | return false; |
107 | 107 | } |
@@ -86,12 +86,13 @@ |
||
86 | 86 | { |
87 | 87 | $isLast = true; |
88 | 88 | } |
89 | - if(!isset($group->member[$i]->type)) continue; |
|
89 | + if(!isset($group->member[$i]->type)) { |
|
90 | + continue; |
|
91 | + } |
|
90 | 92 | if($group->member[$i]->type === 'Group') |
91 | 93 | { |
92 | 94 | $this->addMember($group->member[$i]->cn, true, $isLast); |
93 | - } |
|
94 | - else |
|
95 | + } else |
|
95 | 96 | { |
96 | 97 | $this->addMember($group->member[$i]->uid, false, $isLast); |
97 | 98 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | |
29 | 29 | function getEmail() |
30 | 30 | { |
31 | - if(is_array($this->blob->mail)) |
|
31 | + if (is_array($this->blob->mail)) |
|
32 | 32 | { |
33 | 33 | return $this->blob->mail[0]; |
34 | 34 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | |
38 | 38 | function getUid() |
39 | 39 | { |
40 | - if(is_array($this->blob->uid)) |
|
40 | + if (is_array($this->blob->uid)) |
|
41 | 41 | { |
42 | 42 | return $this->blob->uid[0]; |
43 | 43 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | |
47 | 47 | function getPassword() |
48 | 48 | { |
49 | - if(is_array($this->blob->password)) |
|
49 | + if (is_array($this->blob->password)) |
|
50 | 50 | { |
51 | 51 | return $this->blob->password[0]; |
52 | 52 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | public function getGroupName() |
14 | 14 | { |
15 | - if(isset($data['gid'])) |
|
15 | + if (isset($data['gid'])) |
|
16 | 16 | { |
17 | 17 | return $data['gid']; |
18 | 18 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | |
22 | 22 | public function getDescription() |
23 | 23 | { |
24 | - if(isset($data['description'])) |
|
24 | + if (isset($data['description'])) |
|
25 | 25 | { |
26 | 26 | return $data['description']; |
27 | 27 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | return $this->members(false); |
34 | 34 | } |
35 | 35 | |
36 | - public function members($details=false) |
|
36 | + public function members($details = false) |
|
37 | 37 | { |
38 | 38 | //TODO |
39 | 39 | return array(); |
@@ -264,7 +264,7 @@ |
||
264 | 264 | throw new \Exception('data must be set for LDAPGroup'); |
265 | 265 | } |
266 | 266 | $filter = new \Data\Filter("cn eq $name"); |
267 | - $group = $data->read($data->group_base, $filter); |
|
267 | + $group = $data->read($data->group_base, $filter); |
|
268 | 268 | if($group === false || !isset($group[0])) |
269 | 269 | { |
270 | 270 | return false; |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | { |
14 | 14 | $this->ldapObj = $data; |
15 | 15 | $this->server = \LDAP\LDAPServer::getInstance(); |
16 | - if(!is_object($data)) |
|
16 | + if (!is_object($data)) |
|
17 | 17 | { |
18 | 18 | throw new \Exception('Unable to setup LDAPGroup!'); |
19 | 19 | } |
@@ -38,17 +38,17 @@ discard block |
||
38 | 38 | { |
39 | 39 | $rawMembers = $this->getField('member'); |
40 | 40 | $fieldName = 'member'; |
41 | - if($rawMembers === false) |
|
41 | + if ($rawMembers === false) |
|
42 | 42 | { |
43 | 43 | $rawMembers = $this->getField('uniqueMember'); |
44 | 44 | $fieldName = 'uniqueMember'; |
45 | 45 | } |
46 | - if($rawMembers === false) |
|
46 | + if ($rawMembers === false) |
|
47 | 47 | { |
48 | 48 | $rawMembers = $this->getField('memberUid'); |
49 | 49 | $fieldName = 'memberUid'; |
50 | 50 | } |
51 | - if(!isset($rawMembers['count'])) |
|
51 | + if (!isset($rawMembers['count'])) |
|
52 | 52 | { |
53 | 53 | $rawMembers['count'] = count($rawMembers); |
54 | 54 | } |
@@ -58,23 +58,23 @@ discard block |
||
58 | 58 | private function getIDFromDN($dn) |
59 | 59 | { |
60 | 60 | $split = explode(',', $dn); |
61 | - if(strncmp('cn=', $split[0], 3) === 0) |
|
61 | + if (strncmp('cn=', $split[0], 3) === 0) |
|
62 | 62 | { |
63 | 63 | return substr($split[0], 3); |
64 | 64 | } |
65 | 65 | return substr($split[0], 4); |
66 | 66 | } |
67 | 67 | |
68 | - public function getMemberUids($recursive=true) |
|
68 | + public function getMemberUids($recursive = true) |
|
69 | 69 | { |
70 | 70 | $members = array(); |
71 | 71 | $rawMembers = $this->getMembersField(); |
72 | - for($i = 0; $i < $rawMembers['count']; $i++) |
|
72 | + for ($i = 0; $i < $rawMembers['count']; $i++) |
|
73 | 73 | { |
74 | - if($recursive && strncmp($rawMembers[$i], 'cn=', 3) === 0) |
|
74 | + if ($recursive && strncmp($rawMembers[$i], 'cn=', 3) === 0) |
|
75 | 75 | { |
76 | 76 | $child = self::from_dn($rawMembers[$i], $this->server); |
77 | - if($child !== false) |
|
77 | + if ($child !== false) |
|
78 | 78 | { |
79 | 79 | $members = array_merge($members, $child->members()); |
80 | 80 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | } |
86 | 86 | } |
87 | 87 | $count = count($members); |
88 | - for($i = 0; $i < $count; $i++) |
|
88 | + for ($i = 0; $i < $count; $i++) |
|
89 | 89 | { |
90 | 90 | $members[$i] = $this->getIDFromDN($members[$i]); |
91 | 91 | } |
@@ -95,36 +95,36 @@ discard block |
||
95 | 95 | private function getObjectFromDN($dn) |
96 | 96 | { |
97 | 97 | $split = explode(',', $dn); |
98 | - if(strncmp('cn=', $dn, 3) === 0) |
|
98 | + if (strncmp('cn=', $dn, 3) === 0) |
|
99 | 99 | { |
100 | - if(count($split) === 1) |
|
100 | + if (count($split) === 1) |
|
101 | 101 | { |
102 | 102 | return LDAPGroup::from_name($dn, $this->server); |
103 | 103 | } |
104 | 104 | return LDAPGroup::from_name(substr($split[0], 3), $this->server); |
105 | 105 | } |
106 | - if(count($split) === 1) |
|
106 | + if (count($split) === 1) |
|
107 | 107 | { |
108 | 108 | return LDAPUser::from_name($dn, $this->server); |
109 | 109 | } |
110 | 110 | return LDAPUser::from_name(substr($split[0], 4), $this->server); |
111 | 111 | } |
112 | 112 | |
113 | - public function members($details=false, $recursive=true, $includeGroups=true) |
|
113 | + public function members($details = false, $recursive = true, $includeGroups = true) |
|
114 | 114 | { |
115 | 115 | $members = array(); |
116 | 116 | $rawMembers = $this->getMembersField(); |
117 | - for($i = 0; $i < $rawMembers['count']; $i++) |
|
117 | + for ($i = 0; $i < $rawMembers['count']; $i++) |
|
118 | 118 | { |
119 | - if($recursive && strncmp($rawMembers[$i], 'cn=', 3) === 0) |
|
119 | + if ($recursive && strncmp($rawMembers[$i], 'cn=', 3) === 0) |
|
120 | 120 | { |
121 | 121 | $child = self::from_dn($rawMembers[$i], $this->server); |
122 | - if($child !== false) |
|
122 | + if ($child !== false) |
|
123 | 123 | { |
124 | 124 | $members = array_merge($members, $child->members()); |
125 | 125 | } |
126 | 126 | } |
127 | - else if($includeGroups === false && strncmp($rawMembers[$i], 'cn=', 3) === 0) |
|
127 | + else if ($includeGroups === false && strncmp($rawMembers[$i], 'cn=', 3) === 0) |
|
128 | 128 | { |
129 | 129 | //Drop this member |
130 | 130 | } |
@@ -133,11 +133,11 @@ discard block |
||
133 | 133 | array_push($members, $rawMembers[$i]); |
134 | 134 | } |
135 | 135 | } |
136 | - if($details === true) |
|
136 | + if ($details === true) |
|
137 | 137 | { |
138 | 138 | $details = array(); |
139 | 139 | $count = count($members); |
140 | - for($i = 0; $i < $count; $i++) |
|
140 | + for ($i = 0; $i < $count; $i++) |
|
141 | 141 | { |
142 | 142 | $details[$i] = $this->getObjectFromDN($members[$i]); |
143 | 143 | } |
@@ -147,37 +147,37 @@ discard block |
||
147 | 147 | return $members; |
148 | 148 | } |
149 | 149 | |
150 | - public function getNonMemebers($select=false) |
|
150 | + public function getNonMemebers($select = false) |
|
151 | 151 | { |
152 | 152 | $data = array(); |
153 | 153 | $groupFilter = '(&(cn=*)(!(cn='.$this->getGroupName().'))'; |
154 | 154 | $userFilter = '(&(cn=*)'; |
155 | 155 | $members = $this->members(); |
156 | 156 | $count = count($members); |
157 | - for($i = 0; $i < $count; $i++) |
|
157 | + for ($i = 0; $i < $count; $i++) |
|
158 | 158 | { |
159 | - $dnComps = explode(',',$members[$i]); |
|
160 | - if(strncmp($members[$i], "uid=", 4) == 0) |
|
159 | + $dnComps = explode(',', $members[$i]); |
|
160 | + if (strncmp($members[$i], "uid=", 4) == 0) |
|
161 | 161 | { |
162 | - $userFilter.='(!('.$dnComps[0].'))'; |
|
162 | + $userFilter .= '(!('.$dnComps[0].'))'; |
|
163 | 163 | } |
164 | 164 | else |
165 | 165 | { |
166 | - $groupFilter.='(!('.$dnComps[0].'))'; |
|
166 | + $groupFilter .= '(!('.$dnComps[0].'))'; |
|
167 | 167 | } |
168 | 168 | } |
169 | - $userFilter.=')'; |
|
170 | - $groupFilter.=')'; |
|
169 | + $userFilter .= ')'; |
|
170 | + $groupFilter .= ')'; |
|
171 | 171 | $groups = $this->server->read($this->server->group_base, $groupFilter); |
172 | 172 | $count = count($groups); |
173 | - for($i = 0; $i < $count; $i++) |
|
173 | + for ($i = 0; $i < $count; $i++) |
|
174 | 174 | { |
175 | - if($groups[$i] === false || $groups[$i] === null) continue; |
|
175 | + if ($groups[$i] === false || $groups[$i] === null) continue; |
|
176 | 176 | array_push($data, new LDAPGroup($groups[$i])); |
177 | 177 | } |
178 | 178 | $users = $this->server->read($this->server->user_base, $userFilter, false, $select); |
179 | 179 | $count = count($users); |
180 | - for($i = 0; $i < $count; $i++) |
|
180 | + for ($i = 0; $i < $count; $i++) |
|
181 | 181 | { |
182 | 182 | array_push($data, new LDAPUser($users[$i])); |
183 | 183 | } |
@@ -186,24 +186,24 @@ discard block |
||
186 | 186 | |
187 | 187 | public function clearMembers() |
188 | 188 | { |
189 | - if(isset($this->ldapObj['member'])) |
|
189 | + if (isset($this->ldapObj['member'])) |
|
190 | 190 | { |
191 | 191 | $this->ldapObj['member'] = array(); |
192 | 192 | } |
193 | - else if(isset($this->ldapObj['uniquemember'])) |
|
193 | + else if (isset($this->ldapObj['uniquemember'])) |
|
194 | 194 | { |
195 | 195 | $this->ldapObj['uniquemember'] = array(); |
196 | 196 | } |
197 | - else if(isset($this->ldapObj['memberuid'])) |
|
197 | + else if (isset($this->ldapObj['memberuid'])) |
|
198 | 198 | { |
199 | 199 | $this->ldapObj['memberuid'] = array(); |
200 | 200 | } |
201 | 201 | } |
202 | 202 | |
203 | - public function addMember($name, $isGroup=false, $flush=true) |
|
203 | + public function addMember($name, $isGroup = false, $flush = true) |
|
204 | 204 | { |
205 | 205 | $dn = false; |
206 | - if($isGroup) |
|
206 | + if ($isGroup) |
|
207 | 207 | { |
208 | 208 | $dn = 'cn='.$name.','.$this->server->group_base; |
209 | 209 | } |
@@ -212,14 +212,14 @@ discard block |
||
212 | 212 | $dn = 'uid='.$name.','.$this->server->user_base; |
213 | 213 | } |
214 | 214 | $propName = false; |
215 | - $rawMembers = $this->getMembersField($propName);; |
|
216 | - if(in_array($dn, $rawMembers) || in_array($name, $rawMembers)) |
|
215 | + $rawMembers = $this->getMembersField($propName); ; |
|
216 | + if (in_array($dn, $rawMembers) || in_array($name, $rawMembers)) |
|
217 | 217 | { |
218 | 218 | return true; |
219 | 219 | } |
220 | - if($propName === 'memberUid') |
|
220 | + if ($propName === 'memberUid') |
|
221 | 221 | { |
222 | - if($isGroup) |
|
222 | + if ($isGroup) |
|
223 | 223 | { |
224 | 224 | throw new \Exception('Unable to add a group as a child of this group type'); |
225 | 225 | } |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | } |
232 | 232 | $tmp = strtolower($propName); |
233 | 233 | $this->ldapObj->$tmp = $rawMembers; |
234 | - if($flush === true) |
|
234 | + if ($flush === true) |
|
235 | 235 | { |
236 | 236 | $obj = array('dn'=>$this->ldapObj->dn); |
237 | 237 | $obj[$propName] = $rawMembers; |
@@ -243,29 +243,29 @@ discard block |
||
243 | 243 | } |
244 | 244 | } |
245 | 245 | |
246 | - static function from_dn($dn, $data=false) |
|
246 | + static function from_dn($dn, $data = false) |
|
247 | 247 | { |
248 | - if($data === false) |
|
248 | + if ($data === false) |
|
249 | 249 | { |
250 | 250 | throw new \Exception('data must be set for LDAPGroup'); |
251 | 251 | } |
252 | 252 | $group = $data->read($dn, false, true); |
253 | - if($group === false || !isset($group[0])) |
|
253 | + if ($group === false || !isset($group[0])) |
|
254 | 254 | { |
255 | 255 | return false; |
256 | 256 | } |
257 | 257 | return new static($group[0]); |
258 | 258 | } |
259 | 259 | |
260 | - static function from_name($name, $data=false) |
|
260 | + static function from_name($name, $data = false) |
|
261 | 261 | { |
262 | - if($data === false) |
|
262 | + if ($data === false) |
|
263 | 263 | { |
264 | 264 | throw new \Exception('data must be set for LDAPGroup'); |
265 | 265 | } |
266 | 266 | $filter = new \Data\Filter("cn eq $name"); |
267 | 267 | $group = $data->read($data->group_base, $filter); |
268 | - if($group === false || !isset($group[0])) |
|
268 | + if ($group === false || !isset($group[0])) |
|
269 | 269 | { |
270 | 270 | return false; |
271 | 271 | } |
@@ -78,8 +78,7 @@ discard block |
||
78 | 78 | { |
79 | 79 | $members = array_merge($members, $child->members()); |
80 | 80 | } |
81 | - } |
|
82 | - else |
|
81 | + } else |
|
83 | 82 | { |
84 | 83 | array_push($members, $rawMembers[$i]); |
85 | 84 | } |
@@ -123,12 +122,10 @@ discard block |
||
123 | 122 | { |
124 | 123 | $members = array_merge($members, $child->members()); |
125 | 124 | } |
126 | - } |
|
127 | - else if($includeGroups === false && strncmp($rawMembers[$i], 'cn=', 3) === 0) |
|
125 | + } else if($includeGroups === false && strncmp($rawMembers[$i], 'cn=', 3) === 0) |
|
128 | 126 | { |
129 | 127 | //Drop this member |
130 | - } |
|
131 | - else |
|
128 | + } else |
|
132 | 129 | { |
133 | 130 | array_push($members, $rawMembers[$i]); |
134 | 131 | } |
@@ -160,8 +157,7 @@ discard block |
||
160 | 157 | if(strncmp($members[$i], "uid=", 4) == 0) |
161 | 158 | { |
162 | 159 | $userFilter.='(!('.$dnComps[0].'))'; |
163 | - } |
|
164 | - else |
|
160 | + } else |
|
165 | 161 | { |
166 | 162 | $groupFilter.='(!('.$dnComps[0].'))'; |
167 | 163 | } |
@@ -172,7 +168,9 @@ discard block |
||
172 | 168 | $count = count($groups); |
173 | 169 | for($i = 0; $i < $count; $i++) |
174 | 170 | { |
175 | - if($groups[$i] === false || $groups[$i] === null) continue; |
|
171 | + if($groups[$i] === false || $groups[$i] === null) { |
|
172 | + continue; |
|
173 | + } |
|
176 | 174 | array_push($data, new LDAPGroup($groups[$i])); |
177 | 175 | } |
178 | 176 | $users = $this->server->read($this->server->user_base, $userFilter, false, $select); |
@@ -189,12 +187,10 @@ discard block |
||
189 | 187 | if(isset($this->ldapObj['member'])) |
190 | 188 | { |
191 | 189 | $this->ldapObj['member'] = array(); |
192 | - } |
|
193 | - else if(isset($this->ldapObj['uniquemember'])) |
|
190 | + } else if(isset($this->ldapObj['uniquemember'])) |
|
194 | 191 | { |
195 | 192 | $this->ldapObj['uniquemember'] = array(); |
196 | - } |
|
197 | - else if(isset($this->ldapObj['memberuid'])) |
|
193 | + } else if(isset($this->ldapObj['memberuid'])) |
|
198 | 194 | { |
199 | 195 | $this->ldapObj['memberuid'] = array(); |
200 | 196 | } |
@@ -206,8 +202,7 @@ discard block |
||
206 | 202 | if($isGroup) |
207 | 203 | { |
208 | 204 | $dn = 'cn='.$name.','.$this->server->group_base; |
209 | - } |
|
210 | - else |
|
205 | + } else |
|
211 | 206 | { |
212 | 207 | $dn = 'uid='.$name.','.$this->server->user_base; |
213 | 208 | } |
@@ -224,8 +219,7 @@ discard block |
||
224 | 219 | throw new \Exception('Unable to add a group as a child of this group type'); |
225 | 220 | } |
226 | 221 | array_push($rawMembers, $name); |
227 | - } |
|
228 | - else |
|
222 | + } else |
|
229 | 223 | { |
230 | 224 | array_push($rawMembers, $dn); |
231 | 225 | } |
@@ -236,8 +230,7 @@ discard block |
||
236 | 230 | $obj = array('dn'=>$this->ldapObj->dn); |
237 | 231 | $obj[$propName] = $rawMembers; |
238 | 232 | return $this->server->update($obj); |
239 | - } |
|
240 | - else |
|
233 | + } else |
|
241 | 234 | { |
242 | 235 | return true; |
243 | 236 | } |
@@ -241,7 +241,7 @@ |
||
241 | 241 | $obj['userPassword'] = $this->generateLDAPPass($password); |
242 | 242 | if(isset($this->ldap_obj->uniqueidentifier)) |
243 | 243 | { |
244 | - $obj['uniqueIdentifier'] = null; |
|
244 | + $obj['uniqueIdentifier'] = null; |
|
245 | 245 | } |
246 | 246 | //Make sure we are bound in write mode |
247 | 247 | $auth = \AuthProvider::getInstance(); |
@@ -50,6 +50,9 @@ |
||
50 | 50 | return $res; |
51 | 51 | } |
52 | 52 | |
53 | + /** |
|
54 | + * @param string $listName |
|
55 | + */ |
|
53 | 56 | private function isInListOrChild($listName, $group, $dn) |
54 | 57 | { |
55 | 58 | if(!isset($group[$listName])) |
@@ -8,15 +8,15 @@ discard block |
||
8 | 8 | private $ldapObj; |
9 | 9 | private $server; |
10 | 10 | |
11 | - public function __construct($data=false) |
|
11 | + public function __construct($data = false) |
|
12 | 12 | { |
13 | 13 | $this->server = \LDAP\LDAPServer::getInstance(); |
14 | - if($data !== false && !isset($data['dn']) && !isset($data['extended'])) |
|
14 | + if ($data !== false && !isset($data['dn']) && !isset($data['extended'])) |
|
15 | 15 | { |
16 | 16 | //Generic user object |
17 | 17 | $filter = new \Data\Filter('mail eq '.$data['mail']); |
18 | 18 | $users = $this->server->read($this->server->user_base, $filter); |
19 | - if($users === false || !isset($users[0])) |
|
19 | + if ($users === false || !isset($users[0])) |
|
20 | 20 | { |
21 | 21 | throw new \Exception('No such LDAP User!'); |
22 | 22 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | } |
25 | 25 | else |
26 | 26 | { |
27 | - if(isset($data['extended'])) |
|
27 | + if (isset($data['extended'])) |
|
28 | 28 | { |
29 | 29 | $this->ldapObj = $data['extended']; |
30 | 30 | } |
@@ -38,13 +38,13 @@ discard block |
||
38 | 38 | private function check_child_group($array) |
39 | 39 | { |
40 | 40 | $res = false; |
41 | - for($i = 0; $i < $array['count']; $i++) |
|
41 | + for ($i = 0; $i < $array['count']; $i++) |
|
42 | 42 | { |
43 | - if(strpos($array[$i], $this->server->group_base) !== false) |
|
43 | + if (strpos($array[$i], $this->server->group_base) !== false) |
|
44 | 44 | { |
45 | 45 | $dn = explode(',', $array[$i]); |
46 | 46 | $res = $this->isInGroupNamed(substr($dn[0], 3)); |
47 | - if($res) return $res; |
|
47 | + if ($res) return $res; |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 | return $res; |
@@ -52,11 +52,11 @@ discard block |
||
52 | 52 | |
53 | 53 | private function isInListOrChild($listName, $group, $dn) |
54 | 54 | { |
55 | - if(!isset($group[$listName])) |
|
55 | + if (!isset($group[$listName])) |
|
56 | 56 | { |
57 | 57 | return false; |
58 | 58 | } |
59 | - if(in_array($dn, $group[$listName])) |
|
59 | + if (in_array($dn, $group[$listName])) |
|
60 | 60 | { |
61 | 61 | return true; |
62 | 62 | } |
@@ -67,17 +67,17 @@ discard block |
||
67 | 67 | { |
68 | 68 | $filter = new \Data\Filter('cn eq '.$name); |
69 | 69 | $group = $this->server->read($this->server->group_base, $filter); |
70 | - if(!empty($group)) |
|
70 | + if (!empty($group)) |
|
71 | 71 | { |
72 | 72 | $group = $group[0]; |
73 | 73 | $dn = $this->ldapObj->dn; |
74 | 74 | $uid = $this->ldapObj->uid[0]; |
75 | 75 | $ret = $this->isInListOrChild('member', $group, $dn); |
76 | - if($ret === false) |
|
76 | + if ($ret === false) |
|
77 | 77 | { |
78 | 78 | $ret = $this->isInListOrChild('uniquemember', $group, $dn); |
79 | 79 | } |
80 | - if($ret === false && isset($group['memberUid']) && in_array($uid, $group['memberUid'])) |
|
80 | + if ($ret === false && isset($group['memberUid']) && in_array($uid, $group['memberUid'])) |
|
81 | 81 | { |
82 | 82 | return true; |
83 | 83 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | public function getOrganization() |
120 | 120 | { |
121 | 121 | $org = $this->getFieldSingleValue('o'); |
122 | - if($org === false) |
|
122 | + if ($org === false) |
|
123 | 123 | { |
124 | 124 | return 'Volunteer'; |
125 | 125 | } |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | public function getTitles() |
130 | 130 | { |
131 | 131 | $titles = $this->getField('title'); |
132 | - if(isset($titles['count'])) |
|
132 | + if (isset($titles['count'])) |
|
133 | 133 | { |
134 | 134 | unset($titles['count']); |
135 | 135 | } |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | public function getOrganizationUnits() |
175 | 175 | { |
176 | 176 | $units = $this->getField('ou'); |
177 | - if(isset($units['count'])) |
|
177 | + if (isset($units['count'])) |
|
178 | 178 | { |
179 | 179 | unset($units['count']); |
180 | 180 | } |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | public function getLoginProviders() |
185 | 185 | { |
186 | 186 | $hosts = $this->getField('host'); |
187 | - if(isset($hosts['count'])) |
|
187 | + if (isset($hosts['count'])) |
|
188 | 188 | { |
189 | 189 | unset($hosts['count']); |
190 | 190 | } |
@@ -195,12 +195,12 @@ discard block |
||
195 | 195 | { |
196 | 196 | $res = array(); |
197 | 197 | $groups = $this->server->read($this->server->group_base); |
198 | - if(!empty($groups)) |
|
198 | + if (!empty($groups)) |
|
199 | 199 | { |
200 | 200 | $count = count($groups); |
201 | - for($i = 0; $i < $count; $i++) |
|
201 | + for ($i = 0; $i < $count; $i++) |
|
202 | 202 | { |
203 | - if($this->isInGroupNamed($groups[$i]['cn'][0])) |
|
203 | + if ($this->isInGroupNamed($groups[$i]['cn'][0])) |
|
204 | 204 | { |
205 | 205 | array_push($res, new LDAPGroup($groups[$i])); |
206 | 206 | } |
@@ -220,23 +220,23 @@ discard block |
||
220 | 220 | |
221 | 221 | private function generateLDAPPass($pass) |
222 | 222 | { |
223 | - mt_srand((double)microtime()*1000000); |
|
223 | + mt_srand((double)microtime() * 1000000); |
|
224 | 224 | $salt = pack("CCCC", mt_rand(), mt_rand(), mt_rand(), mt_rand()); |
225 | - $hash = base64_encode(pack('H*',sha1($pass.$salt)).$salt); |
|
225 | + $hash = base64_encode(pack('H*', sha1($pass.$salt)).$salt); |
|
226 | 226 | return '{SSHA}'.$hash; |
227 | 227 | } |
228 | 228 | |
229 | 229 | public function setPass($password) |
230 | 230 | { |
231 | - if(!is_object($this->ldapObj)) |
|
231 | + if (!is_object($this->ldapObj)) |
|
232 | 232 | { |
233 | - return $this->setFieldLocal('userPassword', $this->generateLDAPPass($password)); |
|
233 | + return $this->setFieldLocal('userPassword', $this->generateLDAPPass($password)); |
|
234 | 234 | } |
235 | 235 | else |
236 | 236 | { |
237 | 237 | $obj = array('dn'=>$this->ldapObj->dn); |
238 | 238 | $obj['userPassword'] = $this->generateLDAPPass($password); |
239 | - if(isset($this->ldapObj->uniqueidentifier)) |
|
239 | + if (isset($this->ldapObj->uniqueidentifier)) |
|
240 | 240 | { |
241 | 241 | $obj['uniqueIdentifier'] = null; |
242 | 242 | } |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | |
251 | 251 | public function validate_password($password) |
252 | 252 | { |
253 | - if($this->server->bind($this->ldapObj->dn, $password)) |
|
253 | + if ($this->server->bind($this->ldapObj->dn, $password)) |
|
254 | 254 | { |
255 | 255 | return true; |
256 | 256 | } |
@@ -259,37 +259,37 @@ discard block |
||
259 | 259 | |
260 | 260 | public function validate_reset_hash($hash) |
261 | 261 | { |
262 | - if(isset($this->ldapObj->uniqueidentifier) && strcmp($this->ldapObj->uniqueidentifier[0], $hash) === 0) |
|
262 | + if (isset($this->ldapObj->uniqueidentifier) && strcmp($this->ldapObj->uniqueidentifier[0], $hash) === 0) |
|
263 | 263 | { |
264 | 264 | return true; |
265 | 265 | } |
266 | 266 | return false; |
267 | 267 | } |
268 | 268 | |
269 | - static function from_name($name, $data=false) |
|
269 | + static function from_name($name, $data = false) |
|
270 | 270 | { |
271 | - if($data === false) |
|
271 | + if ($data === false) |
|
272 | 272 | { |
273 | 273 | throw new \Exception('data must be set for LDAPUser'); |
274 | 274 | } |
275 | 275 | $filter = new \Data\Filter("uid eq $name"); |
276 | 276 | $user = $data->read($data->user_base, $filter); |
277 | - if($user === false || !isset($user[0])) |
|
277 | + if ($user === false || !isset($user[0])) |
|
278 | 278 | { |
279 | 279 | return false; |
280 | 280 | } |
281 | 281 | return new static($user[0]); |
282 | 282 | } |
283 | 283 | |
284 | - static function from_dn($dn, $data=false) |
|
284 | + static function from_dn($dn, $data = false) |
|
285 | 285 | { |
286 | - if($data === false) |
|
286 | + if ($data === false) |
|
287 | 287 | { |
288 | 288 | throw new \Exception('data must be set for LDAPUser'); |
289 | 289 | } |
290 | 290 | $filter = new \Data\Filter("dn eq $dn"); |
291 | 291 | $user = $data->read($data->user_base, $filter); |
292 | - if($user === false || !isset($user[0])) |
|
292 | + if ($user === false || !isset($user[0])) |
|
293 | 293 | { |
294 | 294 | return false; |
295 | 295 | } |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | |
319 | 319 | public function setUid($uid) |
320 | 320 | { |
321 | - if(!is_object($this->ldapObj)) |
|
321 | + if (!is_object($this->ldapObj)) |
|
322 | 322 | { |
323 | 323 | return $this->setFieldLocal('uid', $uid); |
324 | 324 | } |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | |
367 | 367 | public function setTitles($titles) |
368 | 368 | { |
369 | - if(!is_array($titles)) |
|
369 | + if (!is_array($titles)) |
|
370 | 370 | { |
371 | 371 | $titles = array($titles); |
372 | 372 | } |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | |
376 | 376 | public function setOrganizationUnits($ous) |
377 | 377 | { |
378 | - if(!is_array($ous)) |
|
378 | + if (!is_array($ous)) |
|
379 | 379 | { |
380 | 380 | $ous = array($ous); |
381 | 381 | } |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | |
385 | 385 | public function flushUser() |
386 | 386 | { |
387 | - if(is_object($this->ldapObj)) |
|
387 | + if (is_object($this->ldapObj)) |
|
388 | 388 | { |
389 | 389 | //In this mode we are always up to date |
390 | 390 | return true; |
@@ -392,11 +392,11 @@ discard block |
||
392 | 392 | $obj = $this->ldapObj; |
393 | 393 | $obj['objectClass'] = array('top', 'inetOrgPerson', 'extensibleObject'); |
394 | 394 | $obj['dn'] = 'uid='.$this->ldapObj['uid'].','.$this->server->user_base; |
395 | - if(!isset($obj['sn'])) |
|
395 | + if (!isset($obj['sn'])) |
|
396 | 396 | { |
397 | 397 | $obj['sn'] = $obj['uid']; |
398 | 398 | } |
399 | - if(!isset($obj['cn'])) |
|
399 | + if (!isset($obj['cn'])) |
|
400 | 400 | { |
401 | 401 | $obj['cn'] = $obj['uid']; |
402 | 402 | } |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | $ldapObj = $this->server->read($ldap->user_base, new \Data\Filter('uid eq '.$this->getUid())); |
414 | 414 | $ldapObj = $ldapObj[0]; |
415 | 415 | $hash = false; |
416 | - if(isset($ldapObj->userpassword)) |
|
416 | + if (isset($ldapObj->userpassword)) |
|
417 | 417 | { |
418 | 418 | $hash = hash('sha512', $ldapObj->dn.';'.$ldapObj->userpassword[0].';'.$ldapObj->mail[0]); |
419 | 419 | } |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | } |
424 | 424 | $obj = array('dn'=>$this->ldapObj->dn); |
425 | 425 | $obj['uniqueIdentifier'] = $hash; |
426 | - if($this->server->update($obj) === false) |
|
426 | + if ($this->server->update($obj) === false) |
|
427 | 427 | { |
428 | 428 | throw new \Exception('Unable to create hash in LDAP object!'); |
429 | 429 | } |
@@ -21,14 +21,12 @@ discard block |
||
21 | 21 | throw new \Exception('No such LDAP User!'); |
22 | 22 | } |
23 | 23 | $this->ldapObj = $users[0]; |
24 | - } |
|
25 | - else |
|
24 | + } else |
|
26 | 25 | { |
27 | 26 | if(isset($data['extended'])) |
28 | 27 | { |
29 | 28 | $this->ldapObj = $data['extended']; |
30 | - } |
|
31 | - else |
|
29 | + } else |
|
32 | 30 | { |
33 | 31 | $this->ldapObj = $data; |
34 | 32 | } |
@@ -44,7 +42,9 @@ discard block |
||
44 | 42 | { |
45 | 43 | $dn = explode(',', $array[$i]); |
46 | 44 | $res = $this->isInGroupNamed(substr($dn[0], 3)); |
47 | - if($res) return $res; |
|
45 | + if($res) { |
|
46 | + return $res; |
|
47 | + } |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 | return $res; |
@@ -206,8 +206,7 @@ discard block |
||
206 | 206 | } |
207 | 207 | } |
208 | 208 | return $res; |
209 | - } |
|
210 | - else |
|
209 | + } else |
|
211 | 210 | { |
212 | 211 | return false; |
213 | 212 | } |
@@ -231,8 +230,7 @@ discard block |
||
231 | 230 | if(!is_object($this->ldapObj)) |
232 | 231 | { |
233 | 232 | return $this->setFieldLocal('userPassword', $this->generateLDAPPass($password)); |
234 | - } |
|
235 | - else |
|
233 | + } else |
|
236 | 234 | { |
237 | 235 | $obj = array('dn'=>$this->ldapObj->dn); |
238 | 236 | $obj['userPassword'] = $this->generateLDAPPass($password); |
@@ -321,8 +319,7 @@ discard block |
||
321 | 319 | if(!is_object($this->ldapObj)) |
322 | 320 | { |
323 | 321 | return $this->setFieldLocal('uid', $uid); |
324 | - } |
|
325 | - else |
|
322 | + } else |
|
326 | 323 | { |
327 | 324 | throw new \Exception('Unsupported!'); |
328 | 325 | } |
@@ -416,8 +413,7 @@ discard block |
||
416 | 413 | if(isset($ldapObj->userpassword)) |
417 | 414 | { |
418 | 415 | $hash = hash('sha512', $ldapObj->dn.';'.$ldapObj->userpassword[0].';'.$ldapObj->mail[0]); |
419 | - } |
|
420 | - else |
|
416 | + } else |
|
421 | 417 | { |
422 | 418 | $hash = hash('sha512', $ldapObj->dn.';'.openssl_random_pseudo_bytes(10).';'.$ldapObj->mail[0]); |
423 | 419 | } |
@@ -66,7 +66,7 @@ |
||
66 | 66 | $ret = $auth->activatePendingUser($user); |
67 | 67 | if($ret === false) |
68 | 68 | { |
69 | - throw new \Exception('Unable to create user! '.$res); |
|
69 | + throw new \Exception('Unable to create user! '.$res); |
|
70 | 70 | } |
71 | 71 | return self::SUCCESS; |
72 | 72 | } |
@@ -10,11 +10,11 @@ discard block |
||
10 | 10 | public function __construct($params) |
11 | 11 | { |
12 | 12 | parent::__construct($params); |
13 | - if(!isset($params['client_secrets_path'])) |
|
13 | + if (!isset($params['client_secrets_path'])) |
|
14 | 14 | { |
15 | 15 | throw new \Exception('Missing required parameter client_secrets_path!'); |
16 | 16 | } |
17 | - if(!isset($params['redirect_url'])) |
|
17 | + if (!isset($params['redirect_url'])) |
|
18 | 18 | { |
19 | 19 | $params['redirect_url'] = 'https://'.$_SERVER['HTTP_HOST'].'/oauth2callback.php?src=google'; |
20 | 20 | } |
@@ -34,21 +34,21 @@ discard block |
||
34 | 34 | public function authenticate($code, &$currentUser = false) |
35 | 35 | { |
36 | 36 | $googleUser = false; |
37 | - try{ |
|
37 | + try { |
|
38 | 38 | $this->client->authenticate($code); |
39 | 39 | $this->token = $this->client->getAccessToken(); |
40 | 40 | \FlipSession::setVar('GoogleToken', $this->token); |
41 | 41 | $oauth2Service = new \Google_Service_Oauth2($this->client); |
42 | 42 | $googleUser = $oauth2Service->userinfo->get(); |
43 | - } catch(\Exception $ex) { |
|
43 | + } catch (\Exception $ex) { |
|
44 | 44 | return self::LOGIN_FAILED; |
45 | 45 | } |
46 | 46 | |
47 | 47 | $auth = \AuthProvider::getInstance(); |
48 | 48 | $localUsers = $auth->getUsersByFilter(new \Data\Filter('mail eq '.$googleUser->email)); |
49 | - if($localUsers !== false && isset($localUsers[0])) |
|
49 | + if ($localUsers !== false && isset($localUsers[0])) |
|
50 | 50 | { |
51 | - if($localUsers[0]->canLoginWith('google.com')) |
|
51 | + if ($localUsers[0]->canLoginWith('google.com')) |
|
52 | 52 | { |
53 | 53 | $auth->impersonateUser($localUsers[0]); |
54 | 54 | return self::SUCCESS; |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $user->setLastName($googleUser->familyName); |
65 | 65 | $user->addLoginProvider('google.com'); |
66 | 66 | $ret = $auth->activatePendingUser($user); |
67 | - if($ret === false) |
|
67 | + if ($ret === false) |
|
68 | 68 | { |
69 | 69 | throw new \Exception('Unable to create user! '.$res); |
70 | 70 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | |
75 | 75 | public function getUser($data = false) |
76 | 76 | { |
77 | - if($data === false) |
|
77 | + if ($data === false) |
|
78 | 78 | { |
79 | 79 | $data = $this->token; |
80 | 80 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | $profileUser['displayName'] = $googleUser->name; |
90 | 90 | $profileUser['jpegPhoto'] = base64_encode(file_get_contents($googleUser->picture)); |
91 | 91 | return $profileUser; |
92 | - } catch(\Exception $e) |
|
92 | + } catch (\Exception $e) |
|
93 | 93 | { |
94 | 94 | return false; |
95 | 95 | } |
@@ -55,8 +55,7 @@ |
||
55 | 55 | } |
56 | 56 | $currentUser = $localUsers[0]; |
57 | 57 | return self::ALREADY_PRESENT; |
58 | - } |
|
59 | - else |
|
58 | + } else |
|
60 | 59 | { |
61 | 60 | $user = new PendingUser(); |
62 | 61 | $user->setEmail($googleUser->email); |
@@ -30,7 +30,7 @@ |
||
30 | 30 | |
31 | 31 | public function getUserFromToken($token) |
32 | 32 | { |
33 | - if($token === false) |
|
33 | + if ($token === false) |
|
34 | 34 | { |
35 | 35 | $token = \FlipSession::getVar('OAuthToken'); |
36 | 36 | } |
@@ -25,14 +25,14 @@ discard block |
||
25 | 25 | |
26 | 26 | public function getUserFromToken($token) |
27 | 27 | { |
28 | - if($token === false) |
|
28 | + if ($token === false) |
|
29 | 29 | { |
30 | 30 | $token = \FlipSession::getVar('OAuthToken'); |
31 | 31 | } |
32 | 32 | $resp = \Httpful\Request::get('https://api.github.com/user')->addHeader('Authorization', 'token '.$token['access_token'])->send(); |
33 | 33 | $github_user = $resp->body; |
34 | 34 | $user = new \Auth\PendingUser(); |
35 | - if(isset($github_user->name)) |
|
35 | + if (isset($github_user->name)) |
|
36 | 36 | { |
37 | 37 | $name = explode(' ', $github_user->name); |
38 | 38 | $user->setGivenName($name[0]); |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | public function login($username, $password) |
48 | 48 | { |
49 | 49 | $resp = \Httpful\Request::post('https://profiles.test.burningflipside.com/api/v1/login?username='.urlencode($username).'&password='.urlencode($password))->send(); |
50 | - if($resp->hasErrors()) |
|
50 | + if ($resp->hasErrors()) |
|
51 | 51 | { |
52 | 52 | return false; |
53 | 53 | } |
@@ -58,11 +58,11 @@ discard block |
||
58 | 58 | |
59 | 59 | public function isLoggedIn($data) |
60 | 60 | { |
61 | - if(isset($this->user)) |
|
61 | + if (isset($this->user)) |
|
62 | 62 | { |
63 | 63 | return true; |
64 | 64 | } |
65 | - if(isset($data['res'])) |
|
65 | + if (isset($data['res'])) |
|
66 | 66 | { |
67 | 67 | return $data['res']; |
68 | 68 | } |
@@ -30,14 +30,14 @@ |
||
30 | 30 | |
31 | 31 | public function getUserFromToken($token) |
32 | 32 | { |
33 | - if($token === false) |
|
33 | + if ($token === false) |
|
34 | 34 | { |
35 | 35 | $token = \FlipSession::getVar('OAuthToken'); |
36 | 36 | } |
37 | 37 | $resp = \Httpful\Request::get('https://api.github.com/user')->addHeader('Authorization', 'token '.$token['access_token'])->send(); |
38 | 38 | $github_user = $resp->body; |
39 | 39 | $user = new \Auth\PendingUser(); |
40 | - if(isset($github_user->name)) |
|
40 | + if (isset($github_user->name)) |
|
41 | 41 | { |
42 | 42 | $name = explode(' ', $github_user->name); |
43 | 43 | $user->setGivenName($name[0]); |