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