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