[1780] | 1 | <?php |
---|
| 2 | /***************************************************************************\ |
---|
| 3 | * Expresso - Expresso Messenger * |
---|
| 4 | * - Alexandre Correia / Rodrigo Souza * |
---|
| 5 | * - JETI - http://jeti-im.org/ * |
---|
| 6 | * ------------------------------------------------------------------------- * |
---|
| 7 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 8 | * under the terms of the GNU General Public License as published by the * |
---|
| 9 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 10 | * option) any later version. * |
---|
| 11 | \***************************************************************************/ |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | require_once "class.ldap_im.inc.php"; |
---|
| 15 | require_once "class.db_im.inc.php"; |
---|
| 16 | |
---|
| 17 | class contacts_im |
---|
| 18 | { |
---|
| 19 | private $ldap; |
---|
| 20 | private $db; |
---|
| 21 | private $dn_User; |
---|
| 22 | private $ou_User; |
---|
| 23 | private $serverJabber; |
---|
| 24 | private $serverLdap; |
---|
| 25 | |
---|
| 26 | function __construct() |
---|
| 27 | { |
---|
| 28 | $this->ldap = new ldap_im(); |
---|
| 29 | $this->db = new db_im(); |
---|
| 30 | |
---|
| 31 | // (DN) User |
---|
| 32 | $this->dn_User = $_SESSION['phpgw_info']['jabberit_messenger']['account_dn']; |
---|
| 33 | |
---|
| 34 | // (OU) User |
---|
| 35 | $this->ou_User = $this->dn_User; |
---|
| 36 | $this->ou_User = substr($this->ou_User,strpos($this->ou_User, "ou=")); |
---|
| 37 | $this->ou_User = strtoupper(substr($this->ou_User, 0, strpos($this->ou_User, ",dc="))); |
---|
| 38 | |
---|
| 39 | // Server Name Jabber |
---|
| 40 | $this->serverJabber = $_SESSION['phpgw_info']['jabberit_messenger']['name_jabberit']; |
---|
| 41 | |
---|
| 42 | // Server Name Ldap |
---|
| 43 | $this->serverLdap = $_SESSION['phpgw_info']['jabberit_messenger']['server_ldap_jabberit']; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | private final function groupsLocked() |
---|
| 47 | { |
---|
| 48 | $memberShip = array(); |
---|
| 49 | $groupsLocked = explode(";",$_SESSION['phpgw_info']['jabberit_messenger']['groups_locked']); |
---|
| 50 | |
---|
| 51 | foreach($_SESSION['phpgw_info']['jabberit_messenger']['membership'] as $tmp) |
---|
| 52 | $memberShip[] = $tmp['account_name']; |
---|
| 53 | |
---|
| 54 | foreach($groupsLocked as $tmp) |
---|
| 55 | { |
---|
| 56 | $groups = explode(":", $tmp); |
---|
| 57 | |
---|
| 58 | if( array_search($groups[1], $memberShip) !== False ) |
---|
| 59 | { |
---|
| 60 | $_SESSION['phpgw_info']['jabberit_messenger']['organizationsGroupsLocked'] = $groups[2]; |
---|
| 61 | return true; |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | return false; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | public final function list_contacts($param) |
---|
| 69 | { |
---|
| 70 | $order = array(); |
---|
| 71 | $ou_User = substr($this->ou_User, (strpos($this->ou_User,"=")+1)); |
---|
| 72 | $return = '<empty/>'; |
---|
| 73 | $users = $this->getUsersIm($param['name']); |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | if (!is_array($users) && trim($users) === 'Many Results') |
---|
| 77 | return "<error>Many Results</error>"; |
---|
| 78 | |
---|
| 79 | // Hosts Jabber |
---|
| 80 | $hostsJabber = unserialize($_SESSION['phpgw_info']['jabberit_messenger']['map_org_realm_jabberit']); |
---|
| 81 | |
---|
| 82 | if( is_array($users) ) |
---|
| 83 | { |
---|
| 84 | for($i = 0; $i < count($users); $i++) |
---|
| 85 | { |
---|
| 86 | if( is_array($hostsJabber) ) |
---|
| 87 | { |
---|
| 88 | foreach($hostsJabber as $itens) |
---|
| 89 | { |
---|
| 90 | if( trim($users[$i]['ou']) === trim($itens['org']) && strpos($users[$i]['jid'],"@") === false ) |
---|
| 91 | { |
---|
| 92 | $users[$i]['jid'] = $users[$i]['jid']."@".$itens['jabberName']; |
---|
| 93 | } |
---|
| 94 | } |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | if( strpos($users[$i]['jid'],"@") === false ) |
---|
| 98 | { |
---|
| 99 | $users[$i]['jid'] = $users[$i]['jid']."@".$this->serverJabber; |
---|
| 100 | } |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | foreach($users as $tmp) |
---|
| 104 | { |
---|
| 105 | if ( !array_key_exists($tmp['ou'], $order) ) |
---|
| 106 | $order[$tmp['ou']] = array(); |
---|
| 107 | |
---|
| 108 | $order[$tmp['ou']][] = '<data><ou>'.$tmp['ou'].'</ou><cn>'.$tmp['cn'].'</cn><mail>'.$tmp['mail'].'</mail><uid>'.$tmp['uid'].'</uid><jid>'.$tmp['jid'].'</jid><photo>'.$tmp['photo'].'</photo></data>'; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | ksort($order); |
---|
| 112 | |
---|
| 113 | $return = '<uids>'; |
---|
| 114 | foreach ( $order as $key => $val ) |
---|
| 115 | $return .= '<'.$key.'>'.implode('',$val).'</'.$key.'>'; |
---|
| 116 | $return .= '</uids>'; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | return $return; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | private final function getUsersIm($pName) |
---|
| 123 | { |
---|
| 124 | $array_uids = array(); |
---|
| 125 | $members = array(); |
---|
| 126 | $result = array(); |
---|
| 127 | $uidType = "uid"; |
---|
| 128 | $serversLdap = unserialize(trim($_SESSION['phpgw_info']['jabberit_messenger']['groups_search'])); |
---|
[1875] | 129 | |
---|
[1780] | 130 | if( $serversLdap ) |
---|
| 131 | { |
---|
| 132 | if( array_key_exists($this->serverLdap, $serversLdap) ) |
---|
[1875] | 133 | { |
---|
[1780] | 134 | $groups = unserialize($serversLdap[$this->serverLdap]); |
---|
[1875] | 135 | } |
---|
[1780] | 136 | |
---|
| 137 | if( count($groups) > 0 ) |
---|
| 138 | { |
---|
| 139 | foreach($groups as $tmp) |
---|
| 140 | { |
---|
| 141 | $group = explode(":",$tmp); |
---|
[1853] | 142 | $array_result = $this->ldap->getGroupsMemberUid($group[0], $this->serverLdap ); |
---|
[1859] | 143 | @array_shift($array_result[0]['memberuid']); |
---|
[1864] | 144 | $array_uids = @array_merge($array_uids, $array_result[0]['memberuid']); |
---|
[1853] | 145 | unset($array_result); |
---|
[1780] | 146 | } |
---|
| 147 | } |
---|
[1853] | 148 | |
---|
[1780] | 149 | } |
---|
[1856] | 150 | |
---|
[1780] | 151 | if( count($array_uids) == 0 ) |
---|
| 152 | { |
---|
| 153 | $array_uids = $this->db->get_accounts_acl(); |
---|
| 154 | $uidType = "uidnumber"; |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | for( $i = 0; $i < count($array_uids) ; $i+=50 ) |
---|
| 158 | { |
---|
| 159 | $partial_uids = array_slice($array_uids,$i,50); |
---|
| 160 | $filter_uid = implode(")(".$uidType."=",$partial_uids); |
---|
| 161 | $filter_uid = "(".$uidType."=". $filter_uid. ")"; |
---|
| 162 | |
---|
| 163 | if( $this->groupsLocked() ) |
---|
| 164 | { |
---|
| 165 | $orgs[] = $this->ou_User; |
---|
| 166 | $orgsGroupsLocked = explode(",", $_SESSION['phpgw_info']['jabberit_messenger']['organizationsGroupsLocked']); |
---|
| 167 | |
---|
| 168 | foreach( $orgsGroupsLocked as $tmp ) |
---|
| 169 | { |
---|
| 170 | if( $tmp != "" ) |
---|
| 171 | { |
---|
| 172 | if( strpos($tmp, "/") !== false ) |
---|
| 173 | { |
---|
| 174 | $tt = explode("/", $tmp); |
---|
| 175 | $newOU = implode(",OU=",array_reverse($tt)); |
---|
| 176 | $orgs[] = "OU=". $newOU ; |
---|
| 177 | } |
---|
| 178 | else |
---|
| 179 | $orgs[] = "OU=". $tmp; |
---|
| 180 | } |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | $orgs = array_unique($orgs); |
---|
[1862] | 184 | |
---|
| 185 | foreach( $orgs as $orgB ) |
---|
[1780] | 186 | $result[] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*", $filter_uid, $orgB ); |
---|
[1862] | 187 | |
---|
[1780] | 188 | } |
---|
| 189 | else |
---|
| 190 | $result[] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*", $filter_uid); |
---|
| 191 | } |
---|
[1875] | 192 | |
---|
[1780] | 193 | if( !$this->groupsLocked() ) |
---|
| 194 | { |
---|
[1856] | 195 | $array_uids_external = array(); |
---|
[1780] | 196 | |
---|
| 197 | if( $serversLdap ) |
---|
| 198 | { |
---|
| 199 | foreach( $serversLdap as $key => $tmp ) |
---|
| 200 | { |
---|
| 201 | if( $key != $this->serverLdap ) |
---|
| 202 | { |
---|
| 203 | $groupsExternal = unserialize($tmp); |
---|
| 204 | |
---|
| 205 | if(count($groupsExternal)) |
---|
| 206 | { |
---|
| 207 | foreach( $groupsExternal as $tmpExt ) |
---|
| 208 | { |
---|
| 209 | $group = explode(":",$tmpExt); |
---|
[1858] | 210 | $array_result = $this->ldap->getGroupsMemberUid( $group[0], $key ); |
---|
[1859] | 211 | @array_shift($array_result[0]['memberuid']); |
---|
[1864] | 212 | $array_uids_external = @array_merge($array_uids_external, $array_result[0]['memberuid']); |
---|
[1853] | 213 | unset($array_result); |
---|
[1780] | 214 | } |
---|
| 215 | |
---|
| 216 | for( $i = 0; $i < count( $array_uids_external ) ; $i+=50 ) |
---|
| 217 | { |
---|
| 218 | $partial_uids_external = array_slice($array_uids_external,$i,50); |
---|
| 219 | $filter_uid_external = implode(")(uid=",$partial_uids_external); |
---|
| 220 | $filter_uid_external = "(uid=". $filter_uid_external. ")"; |
---|
| 221 | $result[] = $this->ldap->getUsersLdapCatalog("cn=*".$pName."*", $filter_uid_external, $key ); |
---|
| 222 | } |
---|
[1875] | 223 | unset($array_uids_external); |
---|
[1780] | 224 | } |
---|
| 225 | } |
---|
| 226 | } |
---|
| 227 | } |
---|
[1875] | 228 | else |
---|
| 229 | { |
---|
| 230 | $result[] = $this->ldap->getUsersLdapCatalog("cn=*".$pName."*"); |
---|
| 231 | } |
---|
[1780] | 232 | } |
---|
| 233 | |
---|
| 234 | if ( is_array($result) ) |
---|
| 235 | { |
---|
| 236 | for( $i = 0; $i < count($result); $i++ ) |
---|
| 237 | if( is_array($result[$i]) ) |
---|
| 238 | $members = array_merge($members,$result[$i]); |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | if( count($members) > 150) |
---|
| 242 | { |
---|
| 243 | $ou = substr( $this->ou_User, strpos($this->ou_User, "=") + 1 ); |
---|
| 244 | for($i = 0 ; $i < count($members); $i++ ) |
---|
| 245 | { |
---|
| 246 | if( $ou == $members[$i]['ou'] ) |
---|
| 247 | $uids_org[] = $members[$i]; |
---|
| 248 | else |
---|
| 249 | if(isset($_SESSION['phpgw_info']['jabberit_messenger']['photo'])) |
---|
| 250 | unset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$members[$i]['ou']]); |
---|
| 251 | } |
---|
| 252 | return $uids_org; |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | return $members; |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | private final function strallpos($haystack, $needle, $offset = 0) |
---|
| 259 | { |
---|
| 260 | $result = array(); |
---|
| 261 | for($i = $offset; $i< strlen($haystack); $i++ ) |
---|
| 262 | { |
---|
| 263 | $pos = strpos($haystack,$needle,$i); |
---|
| 264 | if($pos !== FALSE) |
---|
| 265 | { |
---|
| 266 | $offset = $pos; |
---|
| 267 | if($offset >= $i) |
---|
| 268 | $result[] = $i = $offset; |
---|
| 269 | } |
---|
| 270 | } |
---|
| 271 | |
---|
| 272 | return $result; |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | public final function verifyAddNewContact($pUid) |
---|
| 276 | { |
---|
[1853] | 277 | $groupsLocked = explode(";",$_SESSION['phpgw_info']['jabberit_messenger']['groups_locked']); |
---|
| 278 | $gidNumbers = array(); |
---|
| 279 | $uid = $pUid['uid']; |
---|
| 280 | $uid_User = substr($this->dn_User, 0, strpos($this->dn_User, ",")); |
---|
| 281 | $uid_User = substr($uid_User, 4); |
---|
| 282 | |
---|
[1780] | 283 | foreach($groupsLocked as $tmp) |
---|
| 284 | { |
---|
| 285 | $groups = explode(":", $tmp); |
---|
| 286 | $gidNumbers[] = $groups[1]; |
---|
| 287 | } |
---|
[1853] | 288 | |
---|
[1780] | 289 | $filter_gid = implode(")(gidnumber=",$gidNumbers); |
---|
| 290 | $filter_gid = "(gidnumber=". $filter_gid. ")"; |
---|
[1853] | 291 | |
---|
| 292 | $result = $this->ldap->getGroupsMemberUid( $filter_gid, "localhost" ); |
---|
| 293 | |
---|
[1780] | 294 | if( $result && is_array($result) ) |
---|
| 295 | { |
---|
| 296 | array_shift($result); |
---|
| 297 | $i = 0; |
---|
| 298 | |
---|
| 299 | foreach($result as $value) |
---|
| 300 | { |
---|
| 301 | $Groups[$i]['dn'] = $value['dn']; |
---|
| 302 | $Groups[$i]['gidnumber'] = $value['gidnumber'][0]; |
---|
| 303 | if(array_key_exists('memberuid',$value)) |
---|
| 304 | { |
---|
| 305 | array_shift($value['memberuid']); |
---|
| 306 | $Groups[$i++]['memberuid'] = $value['memberuid']; |
---|
| 307 | } |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | $search = array(); |
---|
| 311 | $search_Gid = array(); |
---|
| 312 | |
---|
| 313 | // Verifica Uid em Grupo Bloqueado |
---|
| 314 | foreach($Groups as $value) |
---|
| 315 | { |
---|
| 316 | if( array_search( $uid , $value['memberuid'] ) !== false ) |
---|
| 317 | { |
---|
| 318 | $ou = substr($value['dn'],strpos($value['dn'], "ou=")); |
---|
| 319 | if( array_search($uid_User, $value['memberuid']) === false ) |
---|
| 320 | { |
---|
| 321 | $search[] = strtoupper(substr($ou, 0, strpos($ou, ",dc="))); |
---|
| 322 | $search_Gid[] = $value['gidnumber']; |
---|
| 323 | } |
---|
| 324 | } |
---|
| 325 | } |
---|
| 326 | } |
---|
| 327 | |
---|
| 328 | |
---|
| 329 | if( $this->groupsLocked() ) |
---|
| 330 | { |
---|
| 331 | if( count($search) > 0 ) |
---|
| 332 | { |
---|
| 333 | // Verifica permissões do grupo |
---|
| 334 | foreach($groupsLocked as $value) |
---|
| 335 | { |
---|
| 336 | $tpGroups = explode(":",$value); |
---|
| 337 | if( $tpGroups[1] == $search_Gid[0] ) |
---|
| 338 | { |
---|
| 339 | $ousTp = explode(",",$tpGroups[2]); |
---|
| 340 | $ou_User = strtoupper(trim($this->dn_User)); |
---|
| 341 | |
---|
| 342 | $posAll = $this->strallpos($ou_User, "OU=" ); |
---|
| 343 | $orgs = array(); |
---|
| 344 | |
---|
| 345 | for( $i = 0 ; $i < count($posAll); $i++ ) |
---|
| 346 | { |
---|
| 347 | $pos = strpos($ou_User, ","); |
---|
| 348 | $tmpString = substr($ou_User, $posAll[$i] + 3); |
---|
| 349 | $orgs[] = substr($tmpString, 0, strpos($tmpString, ",")); |
---|
| 350 | } |
---|
| 351 | |
---|
| 352 | $ou_User = implode("/", array_reverse($orgs)); |
---|
| 353 | |
---|
| 354 | if( array_search( $ou_User, $ousTp) !== false ) |
---|
| 355 | return "true"; |
---|
| 356 | } |
---|
| 357 | } |
---|
| 358 | return "false"; |
---|
| 359 | } |
---|
| 360 | else |
---|
| 361 | return "true"; |
---|
| 362 | } |
---|
| 363 | else |
---|
| 364 | { |
---|
| 365 | // Se Bloqueado verifica o Grupo |
---|
| 366 | if( count($search) > 0 ) |
---|
| 367 | { |
---|
| 368 | if( array_search($this->ou_User, $search) === false ) |
---|
| 369 | { |
---|
| 370 | // Verifica permissões do grupo |
---|
| 371 | foreach($groupsLocked as $value) |
---|
| 372 | { |
---|
| 373 | $tpGroups = explode(":",$value); |
---|
| 374 | |
---|
| 375 | if( $tpGroups[1] == $search_Gid[0] ) |
---|
| 376 | { |
---|
| 377 | $ousTp = explode(",",$tpGroups[2]); |
---|
| 378 | $ou_User = strtoupper(trim($this->dn_User)); |
---|
| 379 | |
---|
| 380 | $posAll = $this->strallpos($ou_User, "OU=" ); |
---|
| 381 | $orgs = array(); |
---|
| 382 | |
---|
| 383 | for( $i = 0 ; $i < count($posAll); $i++ ) |
---|
| 384 | { |
---|
| 385 | $pos = strpos($ou_User, ","); |
---|
| 386 | $tmpString = substr($ou_User, $posAll[$i] + 3); |
---|
| 387 | $orgs[] = substr($tmpString, 0, strpos($tmpString, ",")); |
---|
| 388 | } |
---|
| 389 | |
---|
| 390 | $ou_User = implode("/", array_reverse($orgs)); |
---|
| 391 | |
---|
| 392 | if( array_search( $ou_User, $ousTp) !== false ) |
---|
| 393 | return "true"; |
---|
| 394 | } |
---|
| 395 | } |
---|
| 396 | return "false"; |
---|
| 397 | } |
---|
| 398 | return "true"; |
---|
| 399 | } |
---|
| 400 | return "true"; |
---|
| 401 | } |
---|
| 402 | } |
---|
| 403 | } |
---|
| 404 | |
---|
| 405 | ?> |
---|