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