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