[382] | 1 | <?php |
---|
[417] | 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 | \***************************************************************************/ |
---|
[382] | 12 | |
---|
[417] | 13 | |
---|
[382] | 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; |
---|
[697] | 21 | private $ou_User; |
---|
[895] | 22 | private $serverJabber; |
---|
[697] | 23 | |
---|
[977] | 24 | function __construct() |
---|
[382] | 25 | { |
---|
| 26 | $this->ldap = new ldap_im(); |
---|
[697] | 27 | $this->db = new db_im(); |
---|
| 28 | |
---|
| 29 | // (OU) User |
---|
| 30 | $this->ou_User = $_SESSION['phpgw_info']['jabberit_messenger']['account_dn']; |
---|
| 31 | $this->ou_User = substr($this->ou_User,strpos($this->ou_User, "ou=")); |
---|
| 32 | $this->ou_User = strtoupper(substr($this->ou_User, 0, strpos($this->ou_User, ",dc="))); |
---|
[895] | 33 | |
---|
| 34 | // Server Name Jabber |
---|
| 35 | $this->serverJabber = $_SESSION['phpgw_info']['jabberit_messenger']['name_jabberit']; |
---|
[1160] | 36 | |
---|
[382] | 37 | } |
---|
| 38 | |
---|
[558] | 39 | private final function groupsLocked() |
---|
| 40 | { |
---|
| 41 | $memberShip = array(); |
---|
| 42 | $groupsLocked = explode(";",$_SESSION['phpgw_info']['jabberit_messenger']['groups_locked']); |
---|
| 43 | |
---|
| 44 | foreach($_SESSION['phpgw_info']['jabberit_messenger']['membership'] as $tmp) |
---|
| 45 | $memberShip[] = $tmp['account_name']; |
---|
[598] | 46 | |
---|
[558] | 47 | foreach($groupsLocked as $tmp) |
---|
| 48 | { |
---|
| 49 | $groups = explode(":", $tmp); |
---|
[697] | 50 | if( array_search($groups[1], $memberShip) !== False ) |
---|
| 51 | { |
---|
| 52 | $_SESSION['phpgw_info']['jabberit_messenger']['organizationsGroupsLocked'] = $groups[2]; |
---|
[558] | 53 | return true; |
---|
[697] | 54 | } |
---|
[558] | 55 | } |
---|
| 56 | |
---|
| 57 | return false; |
---|
| 58 | } |
---|
| 59 | |
---|
[382] | 60 | public final function list_contacts($param) |
---|
| 61 | { |
---|
[946] | 62 | $order = array(); |
---|
| 63 | $ou_User = substr($this->ou_User, (strpos($this->ou_User,"=")+1)); |
---|
| 64 | $return = '<empty/>'; |
---|
| 65 | $users = $this->users_auth_im($param['name']); |
---|
[895] | 66 | |
---|
[382] | 67 | if (!is_array($users) && trim($users) === 'Many Results') |
---|
| 68 | return "<error>Many Results</error>"; |
---|
| 69 | |
---|
[977] | 70 | // Hosts Jabber |
---|
| 71 | $hostsJabber = unserialize($_SESSION['phpgw_info']['jabberit_messenger']['map_org_realm_jabberit']); |
---|
[1160] | 72 | |
---|
[382] | 73 | if( is_array($users) ) |
---|
| 74 | { |
---|
[946] | 75 | for($i = 0; $i < count($users); $i++) |
---|
[895] | 76 | { |
---|
[977] | 77 | if( is_array($hostsJabber) ) |
---|
[895] | 78 | { |
---|
[977] | 79 | foreach($hostsJabber as $itens) |
---|
[895] | 80 | { |
---|
[1160] | 81 | if( trim($users[$i]['ou']) === trim($itens['org']) && strpos($users[$i]['jid'],"@") === false ) |
---|
[946] | 82 | { |
---|
[1160] | 83 | $users[$i]['jid'] = $users[$i]['jid']."@".$itens['jabberName']; |
---|
[946] | 84 | } |
---|
[895] | 85 | } |
---|
| 86 | } |
---|
[1160] | 87 | |
---|
| 88 | if( strpos($users[$i]['jid'],"@") === false ) |
---|
| 89 | { |
---|
| 90 | $users[$i]['jid'] = $users[$i]['jid']."@".$this->serverJabber; |
---|
| 91 | } |
---|
[895] | 92 | } |
---|
[946] | 93 | |
---|
[382] | 94 | foreach($users as $tmp) |
---|
| 95 | { |
---|
[946] | 96 | if ( !array_key_exists($tmp['ou'], $order) ) |
---|
| 97 | $order[$tmp['ou']] = array(); |
---|
[382] | 98 | |
---|
[946] | 99 | $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>'; |
---|
[382] | 100 | } |
---|
| 101 | |
---|
| 102 | ksort($order); |
---|
| 103 | |
---|
| 104 | $return = '<uids>'; |
---|
| 105 | foreach ( $order as $key => $val ) |
---|
| 106 | $return .= '<'.$key.'>'.implode('',$val).'</'.$key.'>'; |
---|
| 107 | $return .= '</uids>'; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | return $return; |
---|
| 111 | } |
---|
[697] | 112 | |
---|
[551] | 113 | private final function users_auth_im($pName) |
---|
| 114 | { |
---|
| 115 | $array_uids = $this->db->get_accounts_acl(); |
---|
[988] | 116 | $members = array(); |
---|
[697] | 117 | $result = array(); |
---|
[988] | 118 | |
---|
[987] | 119 | for( $i = 0; $i < count($array_uids) ; $i+=50 ) |
---|
| 120 | { |
---|
| 121 | $partial_uids = array_slice($array_uids,$i,50); |
---|
| 122 | $filter_uid = implode(")(uidnumber=",$partial_uids); |
---|
| 123 | $filter_uid = "(uidnumber=". $filter_uid. ")"; |
---|
| 124 | |
---|
| 125 | if( $this->groupsLocked() ) |
---|
| 126 | { |
---|
| 127 | $orgs[] = $this->ou_User; |
---|
| 128 | $orgsGroupsLocked = explode(",", $_SESSION['phpgw_info']['jabberit_messenger']['organizationsGroupsLocked']); |
---|
| 129 | |
---|
| 130 | foreach( $orgsGroupsLocked as $tmp ) |
---|
[697] | 131 | { |
---|
[987] | 132 | if( $tmp != "" ) |
---|
| 133 | $orgs[] = "OU=". $tmp; |
---|
[697] | 134 | } |
---|
[987] | 135 | |
---|
| 136 | $orgs = array_unique($orgs); |
---|
[697] | 137 | |
---|
[988] | 138 | foreach( $orgs as $orgB ) |
---|
| 139 | $result[] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*", $filter_uid, $orgB ); |
---|
[987] | 140 | } |
---|
| 141 | else |
---|
[988] | 142 | $result[] = $this->ldap->getUsersLdapRoot("cn=*".$pName."*", $filter_uid); |
---|
[987] | 143 | } |
---|
[1160] | 144 | |
---|
| 145 | if( !$this->groupsLocked() ) |
---|
[988] | 146 | $result[] = $this->ldap->getUsersLdapCatalog("cn=*".$pName."*"); |
---|
[987] | 147 | |
---|
[697] | 148 | if ( is_array($result) ) |
---|
| 149 | { |
---|
[946] | 150 | for( $i = 0; $i < count($result); $i++ ) |
---|
| 151 | if( is_array($result[$i]) ) |
---|
| 152 | $members = array_merge($members,$result[$i]); |
---|
[697] | 153 | } |
---|
[946] | 154 | |
---|
| 155 | if( count($members) > 150) |
---|
[697] | 156 | { |
---|
[946] | 157 | $ou = substr( $this->ou_User, strpos($this->ou_User, "=") + 1 ); |
---|
| 158 | for($i = 0 ; $i < count($members); $i++ ) |
---|
| 159 | { |
---|
| 160 | if( $ou == $members[$i]['ou'] ) |
---|
| 161 | $uids_org[] = $members[$i]; |
---|
| 162 | else |
---|
| 163 | if(isset($_SESSION['phpgw_info']['jabberit_messenger']['photo'])) |
---|
| 164 | unset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$members[$i]['ou']]); |
---|
| 165 | } |
---|
| 166 | return $uids_org; |
---|
[697] | 167 | } |
---|
[977] | 168 | |
---|
[946] | 169 | return $members; |
---|
[551] | 170 | } |
---|
[697] | 171 | |
---|
| 172 | public final function verifyAddNewContact($pUid) |
---|
| 173 | { |
---|
| 174 | $groupsLocked = explode(";",$_SESSION['phpgw_info']['jabberit_messenger']['groups_locked']); |
---|
| 175 | $gidNumbers = array(); |
---|
| 176 | $uid = $pUid['uid']; |
---|
| 177 | |
---|
| 178 | foreach($groupsLocked as $tmp) |
---|
| 179 | { |
---|
| 180 | $groups = explode(":", $tmp); |
---|
| 181 | $gidNumbers[] = $groups[1]; |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | $filter_gid = implode(")(gidnumber=",$gidNumbers); |
---|
| 185 | $filter_gid = "(gidnumber=". $filter_gid. ")"; |
---|
| 186 | |
---|
[946] | 187 | $result = $this->ldap->getGroupsMemberUid($filter_gid); |
---|
[697] | 188 | |
---|
| 189 | if( $result && is_array($result) ) |
---|
| 190 | { |
---|
| 191 | array_shift($result); |
---|
| 192 | $i = 0; |
---|
| 193 | |
---|
| 194 | foreach($result as $value) |
---|
| 195 | { |
---|
| 196 | $Groups[$i]['dn'] = $value['dn']; |
---|
| 197 | $Groups[$i]['gidnumber'] = $value['gidnumber'][0]; |
---|
| 198 | if(array_key_exists('memberuid',$value)) |
---|
| 199 | { |
---|
| 200 | array_shift($value['memberuid']); |
---|
| 201 | $Groups[$i++]['memberuid'] = $value['memberuid']; |
---|
| 202 | } |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | $search = array(); |
---|
| 206 | $search_Gid = array(); |
---|
| 207 | |
---|
| 208 | // Verifica Uid em Grupo Bloqueado |
---|
| 209 | foreach($Groups as $value) |
---|
| 210 | { |
---|
| 211 | if( array_search( $uid , $value['memberuid'] ) !== false ) |
---|
| 212 | { |
---|
| 213 | $ou = substr($value['dn'],strpos($value['dn'], "ou=")); |
---|
| 214 | $search[] = strtoupper(substr($ou, 0, strpos($ou, ",dc="))); |
---|
| 215 | $search_Gid[] = $value['gidnumber']; |
---|
| 216 | } |
---|
| 217 | } |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | if( $this->groupsLocked() ) |
---|
| 221 | { |
---|
| 222 | if( count($search) > 0 ) |
---|
| 223 | { |
---|
| 224 | // Verifica permissões do grupo |
---|
| 225 | foreach($groupsLocked as $value) |
---|
| 226 | { |
---|
| 227 | $tpGroups = explode(":",$value); |
---|
| 228 | if( $tpGroups[1] == $search_Gid[0] ) |
---|
| 229 | { |
---|
| 230 | $ousTp = explode(",",$tpGroups[2]); |
---|
| 231 | $ou_User = substr($this->ou_User,3); |
---|
| 232 | |
---|
| 233 | if( array_search( $ou_User, $ousTp) !== false ) |
---|
| 234 | return "true"; |
---|
| 235 | } |
---|
| 236 | } |
---|
| 237 | return "false"; |
---|
| 238 | } |
---|
| 239 | else |
---|
| 240 | return "true"; |
---|
| 241 | } |
---|
| 242 | else |
---|
| 243 | { |
---|
| 244 | // Se Bloqueado verifica o Grupo |
---|
| 245 | if( count($search) > 0 ) |
---|
| 246 | { |
---|
| 247 | if( array_search($this->ou_User, $search) === false ) |
---|
| 248 | { |
---|
| 249 | // Verifica permissões do grupo |
---|
| 250 | foreach($groupsLocked as $value) |
---|
| 251 | { |
---|
| 252 | $tpGroups = explode(":",$value); |
---|
| 253 | if( $tpGroups[1] == $search_Gid[0] ) |
---|
| 254 | { |
---|
| 255 | $ousTp = explode(",",$tpGroups[2]); |
---|
| 256 | $ou_User = substr($this->ou_User,3); |
---|
| 257 | |
---|
| 258 | if( array_search( $ou_User, $ousTp) !== false ) |
---|
| 259 | return "true"; |
---|
| 260 | } |
---|
| 261 | } |
---|
| 262 | return "false"; |
---|
| 263 | } |
---|
| 264 | return "true"; |
---|
| 265 | } |
---|
| 266 | return "true"; |
---|
| 267 | } |
---|
| 268 | } |
---|
[382] | 269 | } |
---|
[946] | 270 | |
---|
[697] | 271 | ?> |
---|