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