[903] | 1 | <?php |
---|
| 2 | define('PHPGW_INCLUDE_ROOT','../'); |
---|
| 3 | define('PHPGW_API_INC','../phpgwapi/inc'); |
---|
| 4 | include_once(PHPGW_API_INC.'/class.common.inc.php'); |
---|
| 5 | |
---|
| 6 | class ldap_functions |
---|
| 7 | { |
---|
| 8 | var $ldap; |
---|
| 9 | var $ldap_write; |
---|
| 10 | var $current_config; |
---|
| 11 | |
---|
| 12 | function ldap_functions() |
---|
| 13 | { |
---|
| 14 | $GLOBALS['phpgw_info']['server'] = $_SESSION['phpgw_info']['expresso']['server']; |
---|
| 15 | $this->current_config = $_SESSION['phpgw_info']['expresso']['expressoAdmin']; |
---|
| 16 | $common = new common(); |
---|
| 17 | $this->ldap = $common->ldapConnect(); |
---|
| 18 | //Para haver escrita em diretorio escravo eh necessario que se faca login na api com a opcao de seguir referrals. Foi feita aqui a divisao entre escrita e leitura pois a leitura ldap fica bem mais lenta quando configurada para seguir referrals. |
---|
| 19 | if($GLOBALS['phpgw_info']['server']['diretorioescravo']) |
---|
| 20 | { |
---|
| 21 | $this->ldap_write = $common->ldapConnect("","","",true); |
---|
| 22 | } |
---|
| 23 | else |
---|
| 24 | { |
---|
| 25 | $this->ldap_write = $this->ldap; |
---|
| 26 | } |
---|
| 27 | } |
---|
| 28 | function validate_fields($params) |
---|
| 29 | { |
---|
| 30 | $params = unserialize($params['attributes']); |
---|
| 31 | $type = $params['type']; |
---|
| 32 | $context = $GLOBALS['phpgw_info']['server']['ldap_context']; |
---|
| 33 | $uid = $params['uid']; |
---|
| 34 | $mail = $params['mail']; |
---|
| 35 | $mailalternateaddress = $params['mailalternateaddress']; |
---|
| 36 | |
---|
| 37 | $result['status'] = true; |
---|
| 38 | |
---|
| 39 | if ($_SESSION['phpgw_info']['expresso']['global_denied_users'][$uid]) |
---|
| 40 | { |
---|
| 41 | $result['status'] = false; |
---|
| 42 | $result['msg'] = 'Este LOGIN nᅵo pode ser usado pois ᅵ uma conta de sistema.'; |
---|
| 43 | return $result; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | if (($type == 'create_user') || ($type == 'rename_user')) |
---|
| 47 | { |
---|
| 48 | // UID |
---|
| 49 | $filter = "(&(|(phpgwAccountType=u)(phpgwAccountType=l))(uid=$uid))"; |
---|
| 50 | $justthese = array("uid"); |
---|
| 51 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 52 | $count_entries = ldap_count_entries($this->ldap,$search); |
---|
| 53 | if ($count_entries > 0) |
---|
| 54 | { |
---|
| 55 | $result['status'] = false; |
---|
| 56 | $result['msg'] = 'LOGIN jᅵ esta sendo usado.'; |
---|
| 57 | return $result; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | // GRUPOS |
---|
| 61 | $filter = "(&(phpgwAccountType=g)(cn=$uid))"; |
---|
| 62 | $justthese = array("cn"); |
---|
| 63 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 64 | $count_entries = ldap_count_entries($this->ldap,$search); |
---|
| 65 | if ($count_entries > 0) |
---|
| 66 | { |
---|
| 67 | $result['status'] = false; |
---|
| 68 | $result['msg'] = 'LOGIN do usuᅵrio jᅵ esta sendo usado por um grupo.'; |
---|
| 69 | return $result; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | // UID em outras organizaᅵᅵes |
---|
| 73 | //Quando tento retirar as organizaᅵᅵes pelo expressoAdmin dᅵ este erro. |
---|
| 74 | $filter = "(ou=*)"; |
---|
| 75 | $justthese = array("ou"); |
---|
| 76 | $search = ldap_list($this->ldap, $context, $filter, $justthese); |
---|
| 77 | $entries = ldap_get_entries($this->ldap,$search); |
---|
| 78 | foreach ($entries as $index=>$org) |
---|
| 79 | { |
---|
| 80 | $organization = $org['ou'][0]; |
---|
| 81 | $organization = strtolower($organization); |
---|
| 82 | |
---|
| 83 | $filter = "(&(|(phpgwAccountType=u)(phpgwAccountType=l))(uid=$organization-$uid))"; |
---|
| 84 | $justthese = array("uid"); |
---|
| 85 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 86 | $count_entries = ldap_count_entries($this->ldap,$search); |
---|
| 87 | if ($count_entries > 0) |
---|
| 88 | { |
---|
| 89 | $result['status'] = false; |
---|
| 90 | $result['msg'] = 'LOGIN jᅵ esta sendo usado por outro usuᅵrio em outra organizaᅵᅵo.'; |
---|
| 91 | return $result; |
---|
| 92 | } |
---|
| 93 | } |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | if ($type == 'rename_user') |
---|
| 97 | { |
---|
| 98 | return $result; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | // MAIL |
---|
| 102 | $filter = "(&(|(phpgwAccountType=u)(phpgwAccountType=l))(|(mail=$mail)(mailalternateaddress=$mail)))"; |
---|
| 103 | $justthese = array("mail", "uid"); |
---|
| 104 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 105 | $entries = ldap_get_entries($this->ldap,$search); |
---|
| 106 | if ($entries['count'] == 1){ |
---|
| 107 | if ($entries[0]['uid'][0] != $uid){ |
---|
| 108 | $result['status'] = false; |
---|
| 109 | $result['msg'] = 'E-MAIL estᅵ sendo usado por 1 usuᅵrio: ' . $entries[0]['uid'][0]; |
---|
| 110 | //ldap_close($this->ldap); |
---|
| 111 | return $result; |
---|
| 112 | } |
---|
| 113 | } |
---|
| 114 | else if ($entries['count'] > 1){ |
---|
| 115 | $result['status'] = false; |
---|
| 116 | $result['msg'] = 'E-MAIL estᅵ sendo usado por de 2 ou mais usuᅵrios.'; |
---|
| 117 | //ldap_close($this->ldap); |
---|
| 118 | return $result; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | // MAILAlternateAddress |
---|
| 122 | $filter = "(&(|(phpgwAccountType=u)(phpgwAccountType=l))(|(mail=$mailalternateaddress)(mailalternateaddress=$mailalternateaddress)))"; |
---|
| 123 | $justthese = array("mail", "uid"); |
---|
| 124 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 125 | $entries = ldap_get_entries($this->ldap,$search); |
---|
| 126 | if ($entries['count'] == 1){ |
---|
| 127 | if ($entries[0]['uid'][0] != $uid){ |
---|
| 128 | $result['status'] = false; |
---|
| 129 | $result['msg'] = "E-MAIL alternativo estᅵ sendo usado por 1 usuᅵrio: " . $entries[0]['uid'][0]; |
---|
| 130 | //ldap_close($this->ldap); |
---|
| 131 | return $result; |
---|
| 132 | } |
---|
| 133 | } |
---|
| 134 | else if ($entries['count'] > 1){ |
---|
| 135 | $result['status'] = false; |
---|
| 136 | $result['msg'] = 'E-MAIL alternativo estᅵ sendo usado por 2 ou mais usuᅵrios.'; |
---|
| 137 | return $result; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | return $result; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | function validate_fields_group($params) |
---|
| 144 | { |
---|
| 145 | $context = $GLOBALS['phpgw_info']['server']['ldap_context']; |
---|
| 146 | $cn = $params['cn']; |
---|
| 147 | $result['status'] = true; |
---|
| 148 | |
---|
| 149 | if ($_SESSION['phpgw_info']['expresso']['global_denied_groups'][$cn]) |
---|
| 150 | { |
---|
| 151 | $result['status'] = false; |
---|
| 152 | $result['msg'] = 'Este nome de grupo nᅵo pode ser usado pois ᅵ um grupo de sistema.'; |
---|
| 153 | return $result; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | // CN |
---|
| 157 | $filter = "(&(phpgwAccountType=g)(cn=$cn))"; |
---|
| 158 | $justthese = array("cn"); |
---|
| 159 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 160 | $count_entries = ldap_count_entries($this->ldap,$search); |
---|
| 161 | if ($count_entries > 0) |
---|
| 162 | { |
---|
| 163 | $result['status'] = false; |
---|
| 164 | $result['msg'] = 'NOME do grupo jᅵ estᅵ sendo usado.'; |
---|
| 165 | return $result; |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | // UID |
---|
| 169 | $filter = "(&(|(phpgwAccountType=u)(phpgwAccountType=l))(uid=$cn))"; |
---|
| 170 | $justthese = array("uid"); |
---|
| 171 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 172 | $count_entries = ldap_count_entries($this->ldap,$search); |
---|
| 173 | if ($count_entries > 0) |
---|
| 174 | { |
---|
| 175 | $result['status'] = false; |
---|
| 176 | $result['msg'] = 'NOME do grupo jᅵ esta sendo usado por um usuᅵrio.'; |
---|
| 177 | return $result; |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | return $result; |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | function validate_fields_maillist($params) |
---|
| 184 | { |
---|
| 185 | $context = $GLOBALS['phpgw_info']['server']['ldap_context']; |
---|
| 186 | $uid = $params['uid']; |
---|
| 187 | $mail = $params['mail']; |
---|
| 188 | $result['status'] = true; |
---|
| 189 | |
---|
| 190 | if ($_SESSION['phpgw_info']['expresso']['global_denied_users'][$uid]) |
---|
| 191 | { |
---|
| 192 | $result['status'] = false; |
---|
| 193 | $result['msg'] = 'Este LOGIN nᅵo pode ser usado pois ᅵ uma conta de sistema.'; |
---|
| 194 | return $result; |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | // UID |
---|
| 198 | $filter = "(&(phpgwAccountType=l)(uid=$uid))"; |
---|
| 199 | $justthese = array("uid"); |
---|
| 200 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 201 | $count_entries = ldap_count_entries($this->ldap,$search); |
---|
| 202 | if ($count_entries > 0) |
---|
| 203 | { |
---|
| 204 | $result['status'] = false; |
---|
| 205 | $result['msg'] = 'LOGIN da lista jᅵ estᅵ sendo usado.'; |
---|
| 206 | return $result; |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | // MAIL |
---|
| 210 | /* |
---|
| 211 | $filter = "(&(|(phpgwAccountType=u)(phpgwAccountType=l))(|(mail=$mail)(mailalternateaddress=$mail)))"; |
---|
| 212 | $justthese = array("mail"); |
---|
| 213 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 214 | $count_entries = ldap_count_entries($this->ldap,$search); |
---|
| 215 | if ($count_entries > 0) |
---|
| 216 | { |
---|
| 217 | $result['status'] = false; |
---|
| 218 | $result['msg'] = 'E-MAIL da lista jᅵ estᅵ sendo usado.'; |
---|
| 219 | return $result; |
---|
| 220 | }*/ |
---|
| 221 | |
---|
| 222 | return $result; |
---|
| 223 | } |
---|
| 224 | |
---|
| 225 | //Busca usuᅵrios de um contexto e jᅵ retorna as options do select; |
---|
| 226 | function get_available_users($params) |
---|
| 227 | { |
---|
| 228 | $context = $params['context']; |
---|
| 229 | $recursive = $params['recursive']; |
---|
| 230 | $justthese = array("cn", "uidNumber"); |
---|
| 231 | $filter="(phpgwAccountType=u)"; |
---|
| 232 | |
---|
| 233 | if ($recursive == 'true') |
---|
| 234 | $groups_list=ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 235 | else |
---|
| 236 | $groups_list=ldap_list($this->ldap, $context, $filter, $justthese); |
---|
| 237 | |
---|
| 238 | $entries = ldap_get_entries($this->ldap, $groups_list); |
---|
| 239 | |
---|
| 240 | for ($i=0; $i<$entries["count"]; $i++){ |
---|
| 241 | $u_tmp[$entries[$i]["uidnumber"][0]] = $entries[$i]["cn"][0]; |
---|
| 242 | } |
---|
| 243 | |
---|
| 244 | if (count($u_tmp)) |
---|
| 245 | natcasesort($u_tmp); |
---|
| 246 | |
---|
| 247 | $i = 0; |
---|
| 248 | $users = array(); |
---|
| 249 | |
---|
| 250 | if (count($u_tmp)) |
---|
| 251 | { |
---|
| 252 | foreach ($u_tmp as $uidnumber => $cn) |
---|
| 253 | { |
---|
| 254 | $options .= "<option value=$uidnumber>$cn</option>"; |
---|
| 255 | } |
---|
| 256 | unset($u_tmp); |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | return $options; |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | //Busca usuᅵrios de um contexto e jᅵ retorna as options do select; |
---|
| 263 | /* |
---|
| 264 | function get_available_users_and_maillist($params) |
---|
| 265 | { |
---|
| 266 | $context = $params['context']; |
---|
| 267 | $recursive = $params['recursive']; |
---|
| 268 | $justthese = array("cn", "uidNumber"); |
---|
| 269 | $filter="(|(phpgwAccountType=u)(phpgwAccountType=l))"; |
---|
| 270 | |
---|
| 271 | if ($recursive == 'true') |
---|
| 272 | $groups_list=ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 273 | else |
---|
| 274 | $groups_list=ldap_list($this->ldap, $context, $filter, $justthese); |
---|
| 275 | |
---|
| 276 | $entries = ldap_get_entries($this->ldap, $groups_list); |
---|
| 277 | |
---|
| 278 | for ($i=0; $i<$entries["count"]; $i++){ |
---|
| 279 | $u_tmp[$entries[$i]["uidnumber"][0]] = $entries[$i]["cn"][0]; |
---|
| 280 | } |
---|
| 281 | |
---|
| 282 | if (count($u_tmp)) |
---|
| 283 | natcasesort($u_tmp); |
---|
| 284 | |
---|
| 285 | $i = 0; |
---|
| 286 | $users = array(); |
---|
| 287 | |
---|
| 288 | if (count($u_tmp)) |
---|
| 289 | { |
---|
| 290 | foreach ($u_tmp as $uidnumber => $cn) |
---|
| 291 | { |
---|
| 292 | $options .= "<option value=$uidnumber>$cn</option>"; |
---|
| 293 | } |
---|
| 294 | unset($u_tmp); |
---|
| 295 | } |
---|
| 296 | |
---|
| 297 | return $options; |
---|
| 298 | } |
---|
| 299 | */ |
---|
| 300 | |
---|
| 301 | //Busca usuᅵrios e listas de um contexto e jᅵ retorna as options do select; |
---|
| 302 | function get_available_users_and_maillist($params) |
---|
| 303 | { |
---|
| 304 | |
---|
| 305 | $context = $params['context']; |
---|
| 306 | $recursive = $params['recursive']; |
---|
| 307 | |
---|
| 308 | //Usado para retirar a prï¿œpria lista das possibilidades de inclusï¿œo. |
---|
| 309 | $denied_uidnumber = $params['denied_uidnumber']; |
---|
| 310 | |
---|
| 311 | $justthese = array("cn", "uidNumber"); |
---|
| 312 | $users_filter="(phpgwAccountType=u)"; |
---|
| 313 | $lists_filter = $denied_uidnumber == '' ? "(phpgwAccountType=l)" : "(&(phpgwAccountType=l)(!(uidnumber=$denied_uidnumber)))"; |
---|
| 314 | |
---|
| 315 | $users = Array(); |
---|
| 316 | $lists = Array(); |
---|
| 317 | |
---|
| 318 | if ($recursive == 'true') |
---|
| 319 | { |
---|
| 320 | $lists_search = ldap_search($this->ldap, $context, $lists_filter, $justthese); |
---|
| 321 | $users_search = ldap_search($this->ldap, $context, $users_filter, $justthese); |
---|
| 322 | } |
---|
| 323 | else |
---|
| 324 | { |
---|
| 325 | $lists_search = ldap_list($this->ldap, $context, $lists_filter, $justthese); |
---|
| 326 | $users_search = ldap_list($this->ldap, $context, $users_filter, $justthese); |
---|
| 327 | } |
---|
| 328 | |
---|
| 329 | $lists_entries = ldap_get_entries($this->ldap, $lists_search); |
---|
| 330 | for ($i=0; $i<$lists_entries["count"]; $i++) |
---|
| 331 | { |
---|
| 332 | $l_tmp[$lists_entries[$i]["uidnumber"][0]] = $lists_entries[$i]["cn"][0]; |
---|
| 333 | } |
---|
| 334 | |
---|
| 335 | if (count($l_tmp)) |
---|
| 336 | natcasesort($l_tmp); |
---|
| 337 | |
---|
| 338 | $i = 0; |
---|
| 339 | $lists = array(); |
---|
| 340 | |
---|
| 341 | $options .= '<option value="-1" disabled>------------------------------ Listas ------------------------------ </option>'."\n"; |
---|
| 342 | if (count($l_tmp)) |
---|
| 343 | { |
---|
| 344 | foreach ($l_tmp as $uidnumber => $cn) |
---|
| 345 | { |
---|
| 346 | $options .= "<option value=$uidnumber>$cn</option>"; |
---|
| 347 | } |
---|
| 348 | unset($l_tmp); |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | $users_entries = ldap_get_entries($this->ldap, $users_search); |
---|
| 352 | for ($i=0; $i<$users_entries["count"]; $i++) |
---|
| 353 | { |
---|
| 354 | $u_tmp[$users_entries[$i]["uidnumber"][0]] = $users_entries[$i]["cn"][0]; |
---|
| 355 | } |
---|
| 356 | |
---|
| 357 | if (count($u_tmp)) |
---|
| 358 | natcasesort($u_tmp); |
---|
| 359 | |
---|
| 360 | $i = 0; |
---|
| 361 | $users = array(); |
---|
| 362 | |
---|
| 363 | $options .= '<option value="-1" disabled>----------------------------- Usuarios ---------------------------- </option>'."\n"; |
---|
| 364 | if (count($u_tmp)) |
---|
| 365 | { |
---|
| 366 | foreach ($u_tmp as $uidnumber => $cn) |
---|
| 367 | { |
---|
| 368 | $options .= "<option value=$uidnumber class='line-above'>$cn</option>"; |
---|
| 369 | } |
---|
| 370 | unset($u_tmp); |
---|
| 371 | } |
---|
| 372 | |
---|
| 373 | return $options; |
---|
| 374 | } |
---|
| 375 | |
---|
| 376 | //Funcao que busca apenas os usuarios de um contexto e ja retorna as options do select; |
---|
| 377 | function get_available_users_only($params) |
---|
| 378 | { |
---|
| 379 | |
---|
| 380 | $context = $params['context']; |
---|
| 381 | $recursive = $params['recursive']; |
---|
| 382 | $filtro = $params['filtro']; |
---|
| 383 | |
---|
| 384 | $justthese = array("cn", "uidNumber"); |
---|
| 385 | // $users_filter="(phpgwAccountType=u)"; |
---|
| 386 | $users_filter="(&(phpgwAccountType=u)(cn=*$filtro*))"; |
---|
| 387 | |
---|
| 388 | $users = Array(); |
---|
| 389 | |
---|
| 390 | if ($recursive == 'true') |
---|
| 391 | { |
---|
| 392 | $users_search = ldap_search($this->ldap, $context, $users_filter, $justthese); |
---|
| 393 | } |
---|
| 394 | else |
---|
| 395 | { |
---|
| 396 | $users_search = ldap_list($this->ldap, $context, $users_filter, $justthese); |
---|
| 397 | } |
---|
| 398 | |
---|
| 399 | $users_entries = ldap_get_entries($this->ldap, $users_search); |
---|
| 400 | for ($i=0; $i<$users_entries["count"]; $i++) |
---|
| 401 | { |
---|
| 402 | $u_tmp[$users_entries[$i]["uidnumber"][0]] = $users_entries[$i]["cn"][0]; |
---|
| 403 | } |
---|
| 404 | |
---|
| 405 | if (count($u_tmp)) |
---|
| 406 | natcasesort($u_tmp); |
---|
| 407 | |
---|
| 408 | $i = 0; |
---|
| 409 | $users = array(); |
---|
| 410 | |
---|
| 411 | $options .= '<option value="-1" disabled>----------------------------- Usuarios ---------------------------- </option>'."\n"; |
---|
| 412 | if (count($u_tmp)) |
---|
| 413 | { |
---|
| 414 | foreach ($u_tmp as $uidnumber => $cn) |
---|
| 415 | { |
---|
| 416 | $options .= "<option value=$uidnumber class='line-above'>$cn</option>"; |
---|
| 417 | } |
---|
| 418 | unset($u_tmp); |
---|
| 419 | } |
---|
| 420 | |
---|
| 421 | return $options; |
---|
| 422 | } |
---|
| 423 | |
---|
| 424 | |
---|
| 425 | |
---|
| 426 | |
---|
| 427 | function search_users_only($params) |
---|
| 428 | { |
---|
| 429 | |
---|
| 430 | $context = $params['context']; |
---|
| 431 | $filtro = $params['filtro']; |
---|
| 432 | $tipo = $params['tipo']; |
---|
| 433 | // $recursive = $params['recursive']; |
---|
| 434 | |
---|
| 435 | $justthese = array("cn", "uidNumber", "mail"); |
---|
| 436 | |
---|
| 437 | if($tipo == "adm_maillist") |
---|
| 438 | { |
---|
| 439 | $users_filter="(&(phpgwAccountType=u)(phpgwAccountStatus=A)(|(cn=*$filtro*)(mail=*$filtro*)))"; |
---|
| 440 | } |
---|
| 441 | else |
---|
| 442 | { |
---|
| 443 | $users_filter="(&(phpgwAccountStatus=A)(|(cn=*$filtro*)(mail=*$filtro*)))"; |
---|
| 444 | } |
---|
| 445 | |
---|
| 446 | $users = Array(); |
---|
| 447 | |
---|
| 448 | // if ($recursive == 'true') |
---|
| 449 | // { |
---|
| 450 | $users_search = ldap_search($this->ldap, $context, $users_filter, $justthese); |
---|
| 451 | // } |
---|
| 452 | // else |
---|
| 453 | // { |
---|
| 454 | // $users_search = ldap_list($this->ldap, $context, $users_filter, $justthese); |
---|
| 455 | // } |
---|
| 456 | |
---|
| 457 | $users_entries = ldap_get_entries($this->ldap, $users_search); |
---|
| 458 | for ($i=0; $i<$users_entries["count"]; $i++) |
---|
| 459 | { |
---|
| 460 | $u_tmp[$users_entries[$i]["uidnumber"][0]] = $users_entries[$i]["cn"][0] . " [" .$users_entries[$i]["mail"][0] . "]"; |
---|
| 461 | } |
---|
| 462 | |
---|
| 463 | if(count($u_tmp) == 0) { |
---|
| 464 | $options .= '<option value="-1" disabled>------ USUARIO INVALIDO OU NAO CRIADO NO EXPRESSO ------</option>'."\n"; |
---|
| 465 | } |
---|
| 466 | |
---|
| 467 | if (count($u_tmp)) |
---|
| 468 | natcasesort($u_tmp); |
---|
| 469 | |
---|
| 470 | $i = 0; |
---|
| 471 | $users = array(); |
---|
| 472 | |
---|
| 473 | $options .= '<option value="-1" disabled>----------------------------- Usuarios ---------------------------- </option>'."\n"; |
---|
| 474 | if (count($u_tmp)) |
---|
| 475 | { |
---|
| 476 | foreach ($u_tmp as $uidnumber => $cn) |
---|
| 477 | { |
---|
| 478 | $options .= "<option value=$uidnumber class='line-above'>$cn</option>"; |
---|
| 479 | } |
---|
| 480 | |
---|
| 481 | unset($u_tmp); |
---|
| 482 | } |
---|
| 483 | |
---|
| 484 | return $options; |
---|
| 485 | } |
---|
| 486 | |
---|
| 487 | |
---|
| 488 | function get_available_groups($params) |
---|
| 489 | { |
---|
| 490 | $context = $params['context']; |
---|
| 491 | $justthese = array("cn", "gidNumber"); |
---|
| 492 | $groups_list=ldap_search($this->ldap, $context, ("(phpgwAccountType=g)"), $justthese); |
---|
| 493 | ldap_sort($this->ldap, $groups_list, "cn"); |
---|
| 494 | $entries = ldap_get_entries($this->ldap, $groups_list); |
---|
| 495 | $options = ''; |
---|
| 496 | for ($i=0; $i<$entries['count']; $i++) |
---|
| 497 | { |
---|
| 498 | $options .= "<option value=" . $entries[$i]['gidnumber'][0] . ">" . $entries[$i]['cn'][0] . "</option>"; |
---|
| 499 | } |
---|
| 500 | return $options; |
---|
| 501 | } |
---|
| 502 | |
---|
| 503 | function get_available_maillists($params) |
---|
| 504 | { |
---|
| 505 | $context = $params['context']; |
---|
| 506 | $justthese = array("uid","mail","uidNumber"); |
---|
| 507 | $maillists=ldap_search($this->ldap, $context, ("(phpgwAccountType=l)"), $justthese); |
---|
| 508 | ldap_sort($this->ldap, $maillists, "uid"); |
---|
| 509 | |
---|
| 510 | $entries = ldap_get_entries($this->ldap, $maillists); |
---|
| 511 | |
---|
| 512 | $options = ''; |
---|
| 513 | for ($i=0; $i<$entries['count']; $i++) |
---|
| 514 | { |
---|
| 515 | $options .= "<option value=" . $entries[$i]['uidnumber'][0] . ">" . $entries[$i]['uid'][0] . " </option>"; |
---|
| 516 | } |
---|
| 517 | return $options; |
---|
| 518 | } |
---|
| 519 | |
---|
| 520 | function ldap_add_entry($dn, $entry) |
---|
| 521 | { |
---|
| 522 | $result = array(); |
---|
| 523 | if (!@ldap_add ($this->ldap_write, $dn, $entry )) |
---|
| 524 | { |
---|
| 525 | $result['status'] = false; |
---|
| 526 | $result['msg'] = "Erro na funcao ldap_functions->ldap_add_entry ($dn).\nRetorno do servidor:" . ldap_error($this->ldap_write); |
---|
| 527 | } |
---|
| 528 | else |
---|
| 529 | $result['status'] = true; |
---|
| 530 | return $result; |
---|
| 531 | } |
---|
| 532 | |
---|
| 533 | function ldap_save_photo($dn, $pathphoto, $photo_exist=false) |
---|
| 534 | { |
---|
| 535 | $fd = fopen($pathphoto, "r"); |
---|
| 536 | $fsize = filesize($pathphoto); |
---|
| 537 | $jpegStr = fread($fd, $fsize); |
---|
| 538 | fclose ($fd); |
---|
| 539 | $attrs['jpegPhoto'] = $jpegStr; |
---|
| 540 | |
---|
| 541 | if ($photo_exist) |
---|
| 542 | $res = @ldap_mod_replace($this->ldap_write, $dn, $attrs); |
---|
| 543 | else |
---|
| 544 | $res = @ldap_mod_add($this->ldap_write, $dn, $attrs); |
---|
| 545 | |
---|
| 546 | if ($res) |
---|
| 547 | { |
---|
| 548 | $result['status'] = true; |
---|
| 549 | } |
---|
| 550 | else |
---|
| 551 | { |
---|
| 552 | $result['status'] = false; |
---|
| 553 | $result['msg'] = "Erro na funcao ldap_functions->ldap_save_photo ($dn).\nRetorno do servidor:" . ldap_error($this->ldap_write); |
---|
| 554 | } |
---|
| 555 | return $result; |
---|
| 556 | } |
---|
| 557 | |
---|
| 558 | function ldap_remove_photo($dn) |
---|
| 559 | { |
---|
| 560 | $attrs['jpegPhoto'] = array(); |
---|
| 561 | $res = ldap_mod_del($this->ldap_write, $dn, $attrs); |
---|
| 562 | if ($res) |
---|
| 563 | { |
---|
| 564 | $result['status'] = true; |
---|
| 565 | } |
---|
| 566 | else |
---|
| 567 | { |
---|
| 568 | $result['status'] = false; |
---|
| 569 | $result['msg'] = "Erro na funcao ldap_functions->ldap_remove_photo ($dn).\nRetorno do servidor:" . ldap_error($this->ldap_write); |
---|
| 570 | } |
---|
| 571 | return $result; |
---|
| 572 | } |
---|
| 573 | |
---|
| 574 | // Pode receber tanto um ï¿œnico memberUid quanto um array de memberUid's |
---|
| 575 | function add_user2group($gidNumber, $memberUid) |
---|
| 576 | { |
---|
| 577 | $filter = "(&(phpgwAccountType=g)(gidNumber=$gidNumber))"; |
---|
| 578 | $justthese = array("dn"); |
---|
| 579 | $search = ldap_search($this->ldap_write, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 580 | $entry = ldap_get_entries($this->ldap_write, $search); |
---|
| 581 | $group_dn = $entry[0]['dn']; |
---|
| 582 | $attrs['memberUid'] = $memberUid; |
---|
| 583 | |
---|
| 584 | $res = @ldap_mod_add($this->ldap_write, $group_dn, $attrs); |
---|
| 585 | |
---|
| 586 | if ($res) |
---|
| 587 | { |
---|
| 588 | $result['status'] = true; |
---|
| 589 | } |
---|
| 590 | else |
---|
| 591 | { |
---|
| 592 | $result['status'] = false; |
---|
| 593 | $result['msg'] = "Erro na funcao ldap_functions->add_user2group ($memberUid).\nRetorno do servidor:" . ldap_error($this->ldap_write); |
---|
| 594 | } |
---|
| 595 | return $result; |
---|
| 596 | } |
---|
| 597 | |
---|
| 598 | function remove_user2group($gidNumber, $memberUid) |
---|
| 599 | { |
---|
| 600 | $filter = "(&(phpgwAccountType=g)(gidNumber=$gidNumber))"; |
---|
| 601 | $justthese = array("dn"); |
---|
| 602 | $search = ldap_search($this->ldap_write, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 603 | $entry = ldap_get_entries($this->ldap_write, $search); |
---|
| 604 | $group_dn = $entry[0]['dn']; |
---|
| 605 | $attrs['memberUid'] = $memberUid; |
---|
| 606 | $res = @ldap_mod_del($this->ldap_write, $group_dn, $attrs); |
---|
| 607 | |
---|
| 608 | /*echo 'usuarios recebidos para remocao no ldap'; |
---|
| 609 | echo '<pre>'; |
---|
| 610 | print_r($memberUid);*/ |
---|
| 611 | |
---|
| 612 | if ($res) |
---|
| 613 | { |
---|
| 614 | $result['status'] = true; |
---|
| 615 | } |
---|
| 616 | else |
---|
| 617 | { |
---|
| 618 | $result['status'] = false; |
---|
| 619 | $result['msg'] = "Erro na funcao ldap_functions->remove_user2group ($memberUid).\nRetorno do servidor:" . ldap_error($this->ldap_write); |
---|
| 620 | } |
---|
| 621 | return $result; |
---|
| 622 | } |
---|
| 623 | |
---|
| 624 | function add_user2maillist($uidNumber, $mail) |
---|
| 625 | { |
---|
| 626 | $filter = "(&(phpgwAccountType=l)(uidNumber=$uidNumber))"; |
---|
| 627 | $justthese = array("dn"); |
---|
| 628 | $search = ldap_search($this->ldap_write, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 629 | $entry = ldap_get_entries($this->ldap_write, $search); |
---|
| 630 | $group_dn = $entry[0]['dn']; |
---|
| 631 | echo "teste..."; |
---|
| 632 | |
---|
| 633 | $attrs['mailForwardingAddress'] = $mail; |
---|
| 634 | $res = ldap_mod_add($this->ldap_write, $group_dn, $attrs); |
---|
| 635 | |
---|
| 636 | if ($res) |
---|
| 637 | { |
---|
| 638 | $result['status'] = true; |
---|
| 639 | } |
---|
| 640 | else |
---|
| 641 | { |
---|
| 642 | $result['status'] = false; |
---|
| 643 | $result['msg'] = "Erro na funcao ldap_functions->add_user2maillist ($mail).\nRetorno do servidor:" . ldap_error($this->ldap_write); |
---|
| 644 | } |
---|
| 645 | return $result; |
---|
| 646 | } |
---|
| 647 | |
---|
| 648 | function add_user2maillist_adm($uidNumber, $mail) |
---|
| 649 | { |
---|
| 650 | $result['msg'] = "Entre adiciona adm"; |
---|
| 651 | $filter = "(&(phpgwAccountType=l)(uidNumber=$uidNumber))"; |
---|
| 652 | $justthese = array("dn"); |
---|
| 653 | $search = ldap_search($this->ldap_write, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 654 | $entry = ldap_get_entries($this->ldap_write, $search); |
---|
| 655 | $group_dn = $entry[0]['dn']; |
---|
| 656 | |
---|
| 657 | $attrs['admlista'] = $mail; |
---|
| 658 | $res = ldap_mod_add($this->ldap_write, $group_dn, $attrs); |
---|
| 659 | |
---|
| 660 | if ($res) |
---|
| 661 | { |
---|
| 662 | $result['status'] = true; |
---|
| 663 | } |
---|
| 664 | else |
---|
| 665 | { |
---|
| 666 | $result['status'] = false; |
---|
| 667 | $result['msg'] = "Erro na funcao ldap_functions->add_user2maillist ($mail).\nRetorno do servidor:" . ldap_error($this->ldap_write); |
---|
| 668 | } |
---|
| 669 | return $result; |
---|
| 670 | } |
---|
| 671 | |
---|
| 672 | |
---|
| 673 | |
---|
| 674 | function add_user2maillist_scl($dn, $array_emails) |
---|
| 675 | { |
---|
| 676 | $attrs['naomoderado'] = $array_emails; |
---|
| 677 | $res = @ldap_mod_add($this->ldap_write, $dn, $attrs); |
---|
| 678 | if ($res) |
---|
| 679 | { |
---|
| 680 | $result['status'] = true; |
---|
| 681 | } |
---|
| 682 | else |
---|
| 683 | { |
---|
| 684 | $result['status'] = false; |
---|
| 685 | $result['msg'] = "Erro na funcao ldap_functions->add_user2maillist_scl ($dn).\n\nRetorno do servidor:" . ldap_error($this->ldap_write); |
---|
| 686 | } |
---|
| 687 | return $result; |
---|
| 688 | } |
---|
| 689 | |
---|
| 690 | function remove_user2maillist($uidNumber, $mail) |
---|
| 691 | { |
---|
| 692 | $filter = "(&(phpgwAccountType=l)(uidNumber=$uidNumber))"; |
---|
| 693 | $justthese = array("dn"); |
---|
| 694 | $search = ldap_search($this->ldap_write, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 695 | $entry = ldap_get_entries($this->ldap_write, $search); |
---|
| 696 | $group_dn = $entry[0]['dn']; |
---|
| 697 | $attrs['mailForwardingAddress'] = $mail; |
---|
| 698 | $res = @ldap_mod_del($this->ldap_write, $group_dn, $attrs); |
---|
| 699 | |
---|
| 700 | if ($res) |
---|
| 701 | { |
---|
| 702 | $result['status'] = true; |
---|
| 703 | } |
---|
| 704 | else |
---|
| 705 | { |
---|
| 706 | $result['status'] = false; |
---|
| 707 | $result['msg'] = "Erro na funcao ldap_functions->remove_user2maillist ($mail).\n\nRetorno do servidor:" . ldap_error($this->ldap_write); |
---|
| 708 | } |
---|
| 709 | return $result; |
---|
| 710 | } |
---|
| 711 | |
---|
| 712 | function remove_user2maillist_adm($uidNumber, $mail) |
---|
| 713 | { |
---|
| 714 | $filter = "(&(phpgwAccountType=l)(uidNumber=$uidNumber))"; |
---|
| 715 | $justthese = array("dn"); |
---|
| 716 | $search = ldap_search($this->ldap_write, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 717 | $entry = ldap_get_entries($this->ldap_write, $search); |
---|
| 718 | $group_dn = $entry[0]['dn']; |
---|
| 719 | $attrsAdm['admlista'] = $mail; |
---|
| 720 | $res = @ldap_mod_del($this->ldap_write, $group_dn, $attrsAdm); |
---|
| 721 | if ($res) |
---|
| 722 | { |
---|
| 723 | $result['status'] = true; |
---|
| 724 | } |
---|
| 725 | else |
---|
| 726 | { |
---|
| 727 | $result['status'] = false; |
---|
| 728 | $result['msg'] = "Erro na funcao ldap_functions->remove_user2maillist ($mail).\n\nRetorno do servidor:" . ldap_error($this->ldap_write); |
---|
| 729 | } |
---|
| 730 | return $result; |
---|
| 731 | } |
---|
| 732 | |
---|
| 733 | function remove_user2maillist_scl($dn, $array_emails) |
---|
| 734 | { |
---|
| 735 | $attrs['mailSenderAddress'] = $array_emails; |
---|
| 736 | $res = @ldap_mod_del($this->ldap_write, $dn, $attrs); |
---|
| 737 | |
---|
| 738 | if ($res) |
---|
| 739 | { |
---|
| 740 | $result['status'] = true; |
---|
| 741 | } |
---|
| 742 | else |
---|
| 743 | { |
---|
| 744 | $result['status'] = false; |
---|
| 745 | $result['msg'] = "Erro na funcao ldap_functions->remove_user2maillist_scp ($dn).\n\nRetorno do servidor:" . ldap_error($this->ldap_write); |
---|
| 746 | } |
---|
| 747 | return $result; |
---|
| 748 | } |
---|
| 749 | |
---|
| 750 | function replace_user2maillists($new_mail, $old_mail) |
---|
| 751 | { |
---|
| 752 | $filter = "(&(phpgwAccountType=l)(mailforwardingaddress=$old_mail))"; |
---|
| 753 | $justthese = array("dn"); |
---|
| 754 | $search = ldap_search($this->ldap_write, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 755 | $entries = ldap_get_entries($this->ldap_write, $search); |
---|
| 756 | $result['status'] = true; |
---|
| 757 | for ($i=0; $i<$entries['count']; $i++) |
---|
| 758 | { |
---|
| 759 | $attrs['mailforwardingaddress'] = $old_mail; |
---|
| 760 | $res1 = @ldap_mod_del($this->ldap_write, $entries[$i]['dn'], $attrs); |
---|
| 761 | $attrs['mailforwardingaddress'] = $new_mail; |
---|
| 762 | $res2 = @ldap_mod_add($this->ldap_write, $entries[$i]['dn'], $attrs); |
---|
| 763 | |
---|
| 764 | if ((!$res1) || (!$res2)) |
---|
| 765 | { |
---|
| 766 | $result['status'] = false; |
---|
| 767 | $result['msg'] = "Erro na funcao ldap_functions->replace_user2maillists ($old_mail).\nRetorno do servidor:" . ldap_error($this->ldap_write); |
---|
| 768 | } |
---|
| 769 | } |
---|
| 770 | return $result; |
---|
| 771 | } |
---|
| 772 | |
---|
| 773 | function get_user_info($uidnumber, $context, $serpro=false) |
---|
| 774 | { |
---|
| 775 | if ($serpro) |
---|
| 776 | $filter="(&(objectclass=".$GLOBALS['phpgw_info']['server']['atributousuarios'].")(uidNumber=".$uidnumber."))"; |
---|
| 777 | else |
---|
| 778 | $filter="(&(phpgwAccountType=u)(uidNumber=".$uidnumber."))"; |
---|
| 779 | //Precisa identificar cada atributo, pois em alguns ldaps os atributos nao sao devolvidos se nao fores explicitamente identificados na pesquisa |
---|
| 780 | $justthese = array("dn","ou","uid","uidnumber","gidnumber","departmentnumber","givenname","sn","telephonenumber","mobile","pager","phpgwaccountstatus","phpgwaccountvisible","accountstatus","mail","defaultmembermoderation","admlista","listPass","listPass","mailalternateaddress","mailforwardingaddress","deliverymode","userpasswordrfc2617","cn","objectclass",$GLOBALS['phpgw_info']['server']['atributoexpiracao']); |
---|
| 781 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 782 | //$search = ldap_search($this->ldap, $context, $filter); |
---|
| 783 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 784 | |
---|
| 785 | //Pega o dn do setor do usuario. |
---|
| 786 | $entry[0]['dn'] = strtolower($entry[0]['dn']); |
---|
| 787 | $sector_dn_array = explode(",", $entry[0]['dn']); |
---|
| 788 | for($i=1; $i<count($sector_dn_array); $i++) |
---|
| 789 | $sector_dn .= $sector_dn_array[$i] . ','; |
---|
| 790 | //Retira ultimo pipe. |
---|
| 791 | $sector_dn = substr($sector_dn,0,(strlen($sector_dn) - 1)); |
---|
| 792 | |
---|
| 793 | $result['dn'] = $entry[0]['dn']; |
---|
| 794 | $result['ou'] = $entry[0]['ou'][0]; |
---|
| 795 | $result['context'] = $sector_dn; |
---|
| 796 | $result['uid'] = $entry[0]['uid'][0]; |
---|
| 797 | $result['uidnumber'] = $entry[0]['uidnumber'][0]; |
---|
| 798 | $result['gidnumber'] = $entry[0]['gidnumber'][0]; |
---|
| 799 | $result['departmentnumber'] = $entry[0]['departmentnumber'][0]; |
---|
| 800 | $result['givenname'] = $entry[0]['givenname'][0]; |
---|
| 801 | $result['sn'] = $entry[0]['sn'][0]; |
---|
| 802 | $result['telephonenumber'] = $entry[0]['telephonenumber'][0]; |
---|
| 803 | $result['mobile'] = $entry[0]['mobile'][0]; |
---|
| 804 | $result['pager'] = $entry[0]['pager'][0]; |
---|
| 805 | $result['phpgwaccountstatus'] = $entry[0]['phpgwaccountstatus'][0]; |
---|
| 806 | $result['phpgwaccountvisible'] = $entry[0]['phpgwaccountvisible'][0]; |
---|
| 807 | $result['accountstatus'] = $entry[0]['accountstatus'][0]; |
---|
| 808 | $result['mail'] = $entry[0]['mail'][0]; |
---|
| 809 | $result['defaultMemberModeration'] = $entry[0]['defaultmembermoderation'][0]; |
---|
| 810 | $result['admlista'] = $entry[0]['admlista'][0]; |
---|
| 811 | $result['listPass'] = $entry[0]['listPass'][0]; |
---|
| 812 | $result['mailalternateaddress'] = $entry[0]['mailalternateaddress'][0]; |
---|
| 813 | $result['mailforwardingaddress']= $entry[0]['mailforwardingaddress'][0]; |
---|
| 814 | $result['deliverymode'] = $entry[0]['deliverymode'][0]; |
---|
| 815 | $result['userPasswordRFC2617'] = $entry[0]['userpasswordrfc2617'][0]; |
---|
| 816 | $result['cn'] = $entry[0]['cn'][0]; |
---|
| 817 | $result['phpgwaccount'] = false; |
---|
| 818 | if(isset($GLOBALS['phpgw_info']['server']['atributoexpiracao'])) |
---|
| 819 | $result[$GLOBALS['phpgw_info']['server']['atributoexpiracao']] = $entry[0][$GLOBALS['phpgw_info']['server']['atributoexpiracao']][0]; |
---|
| 820 | else |
---|
| 821 | $result['phpgwaccountexpires'] = $entry[0]['phpgwaccountexpires'][0]; |
---|
| 822 | //objectclass phpgwaccount |
---|
| 823 | foreach ($entry[0]['objectclass'] as $objectclass) |
---|
| 824 | { |
---|
| 825 | if (strcasecmp($objectclass, 'phpgwaccount') == 0) |
---|
| 826 | $result['phpgwaccount'] = true; |
---|
| 827 | } |
---|
| 828 | //Photo |
---|
| 829 | if ($entry[0]['jpegphoto']['count'] == 1) |
---|
| 830 | $result['photo_exist'] = 'true'; |
---|
| 831 | |
---|
| 832 | // Samba |
---|
| 833 | for ($i=0; $i<$entry[0]['objectclass']['count']; $i++) |
---|
| 834 | { |
---|
| 835 | if ($entry[0]['objectclass'][$i] == 'sambaSamAccount') |
---|
| 836 | $result['sambaUser'] = true; |
---|
| 837 | } |
---|
| 838 | if (($this->current_config['expressoAdmin_samba_support'] == 'true') && ($result['sambaUser'])) |
---|
| 839 | { |
---|
| 840 | $result['sambaaccflags'] = $entry[0]['sambaacctflags'][0]; |
---|
| 841 | $result['sambalogonscript'] = $entry[0]['sambalogonscript'][0]; |
---|
| 842 | $result['homedirectory'] = $entry[0]['homedirectory'][0]; |
---|
| 843 | $a_tmp = explode("-", $entry[0]['sambasid'][0]); |
---|
| 844 | array_pop($a_tmp); |
---|
| 845 | $result['sambasid'] = implode("-", $a_tmp); |
---|
| 846 | } |
---|
| 847 | |
---|
| 848 | // MailLists |
---|
| 849 | $justthese = array("uid","mail","uidnumber"); |
---|
| 850 | $filter="(&(phpgwAccountType=l)(mailforwardingaddress=".$result['mail']."))"; |
---|
| 851 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 852 | ldap_sort($this->ldap, $search, "uid"); |
---|
| 853 | $entries = ldap_get_entries($this->ldap, $search); |
---|
| 854 | |
---|
| 855 | for ($i=0; $i<$entries['count']; $i++) |
---|
| 856 | { |
---|
| 857 | $result['maillists_info'][$i]['uidnumber'] = $entries[$i]['uidnumber'][0]; |
---|
| 858 | $result['maillists_info'][$i]['uid'] = $entries[$i]['uid'][0]; |
---|
| 859 | $result['maillists_info'][$i]['mail'] = $entries[$i]['mail'][0]; |
---|
| 860 | $result['maillists'][] = $entries[$i]['uidnumber'][0]; |
---|
| 861 | } |
---|
| 862 | |
---|
| 863 | // Groups |
---|
| 864 | $justthese = array("gidnumber","cn"); |
---|
| 865 | $filter="(&(phpgwAccountType=g)(memberuid=".$result['uid']."))"; |
---|
| 866 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 867 | ldap_sort($this->ldap, $search, "cn"); |
---|
| 868 | $entries = ldap_get_entries($this->ldap, $search); |
---|
| 869 | for ($i=0; $i<$entries['count']; $i++) |
---|
| 870 | { |
---|
| 871 | $result['groups_ldap'][ $entries[$i]['gidnumber'][0] ] = $entries[$i]['cn'][0]; |
---|
| 872 | $result['groups'][ $entries[$i]['gidnumber'][0] ] = $entries[$i]['gidnumber'][0]; |
---|
| 873 | $result['groups_info'][ $entries[$i]['gidnumber'][0] ] = $entries[$i]['gidnumber'][0]; |
---|
| 874 | } |
---|
| 875 | return $result; |
---|
| 876 | } |
---|
| 877 | |
---|
| 878 | function get_group_info($gidnumber, $context) |
---|
| 879 | { |
---|
| 880 | $filter="(&(phpgwAccountType=g)(gidNumber=".$gidnumber."))"; |
---|
| 881 | $search = ldap_search($this->ldap, $context, $filter); |
---|
| 882 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 883 | |
---|
| 884 | //Pega o dn do setor do grupo. |
---|
| 885 | $entry[0]['dn'] = strtolower($entry[0]['dn']); |
---|
| 886 | $sector_dn_array = explode(",", $entry[0]['dn']); |
---|
| 887 | for($i=1; $i<count($sector_dn_array); $i++) |
---|
| 888 | $sector_dn .= $sector_dn_array[$i] . ','; |
---|
| 889 | //Retira ultimo pipe. |
---|
| 890 | $sector_dn = substr($sector_dn,0,(strlen($sector_dn) - 1)); |
---|
| 891 | |
---|
| 892 | $result['context'] = $sector_dn; |
---|
| 893 | $result['cn'] = $entry[0]['cn'][0]; |
---|
| 894 | $result['description'] = $entry[0]['description'][0]; |
---|
| 895 | $result['gidnumber'] = $entry[0]['gidnumber'][0]; |
---|
| 896 | $result['phpgwaccountvisible'] = $entry[0]['phpgwaccountvisible'][0]; |
---|
| 897 | $result['email'] = $entry[0]['mail'][0]; |
---|
| 898 | |
---|
| 899 | //MemberUid |
---|
| 900 | for ($i=0; $i<$entry[0]['memberuid']['count']; $i++) |
---|
| 901 | { |
---|
| 902 | $justthese = array("cn","uid","uidnumber"); |
---|
| 903 | |
---|
| 904 | // Montagem dinamica do filtro |
---|
| 905 | $filter="(&(phpgwAccountType=u)(|"; |
---|
| 906 | for ($k=0; (($k<10) && ($i<$entry[0]['memberuid']['count'])); $k++) |
---|
| 907 | { |
---|
| 908 | $filter .= "(uid=".$entry[0]['memberuid'][$i].")"; |
---|
| 909 | $i++; |
---|
| 910 | } |
---|
| 911 | $i--; |
---|
| 912 | $filter .= "))"; |
---|
| 913 | |
---|
| 914 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 915 | $user_entry = ldap_get_entries($this->ldap, $search); |
---|
| 916 | |
---|
| 917 | for ($j=0; $j<$user_entry['count']; $j++) |
---|
| 918 | { |
---|
| 919 | $result['memberuid_info'][$user_entry[$j]['uid'][0]]['cn'] = $user_entry[$j]['cn'][0]; |
---|
| 920 | $result['memberuid_info'][$user_entry[$j]['uid'][0]]['uidnumber'] = $user_entry[$j]['uidnumber'][0]; |
---|
| 921 | $result['memberuid_info'][$user_entry[$j]['uid'][0]]['type'] = 'u'; |
---|
| 922 | } |
---|
| 923 | } |
---|
| 924 | |
---|
| 925 | // Retira o count do array |
---|
| 926 | array_shift($entry[0]['memberuid']); |
---|
| 927 | |
---|
| 928 | // Checamos e-mails que nï¿œo fazem parte do expresso. |
---|
| 929 | // Criamos um array temporario |
---|
| 930 | $tmp_array = array(); |
---|
| 931 | foreach ($result['memberuid_info'] as $uid => $user_data) |
---|
| 932 | { |
---|
| 933 | $tmp_array[] = $uid; |
---|
| 934 | } |
---|
| 935 | |
---|
| 936 | // Vemos a diferenï¿œa |
---|
| 937 | $array_diff = array_diff($entry[0]['memberuid'], $tmp_array); |
---|
| 938 | |
---|
| 939 | // Incluimos no resultado |
---|
| 940 | foreach ($array_diff as $index=>$uid) |
---|
| 941 | { |
---|
| 942 | $result['memberuid_info'][$uid]['cn'] = $uid; |
---|
| 943 | } |
---|
| 944 | |
---|
| 945 | // Samba |
---|
| 946 | for ($i=0; $i<$entry[0]['objectclass']['count']; $i++) |
---|
| 947 | { |
---|
| 948 | if ($entry[0]['objectclass'][$i] == 'sambaGroupMapping') |
---|
| 949 | $result['sambaGroup'] = true; |
---|
| 950 | |
---|
| 951 | $a_tmp = explode("-", $entry[0]['sambasid'][0]); |
---|
| 952 | array_pop($a_tmp); |
---|
| 953 | $result['sambasid'] = implode("-", $a_tmp); |
---|
| 954 | } |
---|
| 955 | |
---|
| 956 | return $result; |
---|
| 957 | } |
---|
| 958 | |
---|
| 959 | function get_maillist_info($uidnumber, $context) |
---|
| 960 | { |
---|
| 961 | $filter="(&(phpgwAccountType=l)(uidNumber=".$uidnumber."))"; |
---|
| 962 | $search = ldap_search($this->ldap, $context, $filter); |
---|
| 963 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 964 | |
---|
| 965 | //Pega o dn do setor do usuario. |
---|
| 966 | $entry[0]['dn'] = strtolower($entry[0]['dn']); |
---|
| 967 | $sector_dn_array = explode(",", $entry[0]['dn']); |
---|
| 968 | for($i=1; $i<count($sector_dn_array); $i++) |
---|
| 969 | $sector_dn .= $sector_dn_array[$i] . ','; |
---|
| 970 | //Retira ultimo pipe. |
---|
| 971 | $sector_dn = substr($sector_dn,0,(strlen($sector_dn) - 1)); |
---|
| 972 | |
---|
| 973 | $result['context'] = $sector_dn; |
---|
| 974 | $result['uidnumber'] = $entry[0]['uidnumber'][0]; |
---|
| 975 | $result['uid'] = $entry[0]['uid'][0]; |
---|
| 976 | $result['cn'] = $entry[0]['cn'][0]; |
---|
| 977 | $result['admlista'] = $entry[0]['admlista'][0]; |
---|
| 978 | $result['defaultMemberModeration'] = $entry[0]['defaultmembermoderation'][0]; |
---|
| 979 | $result['listPass'] = $entry[0]['listPass'][0]; |
---|
| 980 | $result['mail'] = $entry[0]['mail'][0]; |
---|
| 981 | $result['accountStatus'] = $entry[0]['accountstatus'][0]; |
---|
| 982 | $result['accountAdm'] = $entry[0]['accountAdm'][0]; |
---|
| 983 | $result['phpgwAccountVisible'] = $entry[0]['phpgwaccountvisible'][0]; |
---|
| 984 | $result['description'] = $entry[0]['description'][0]; |
---|
| 985 | |
---|
| 986 | //Members |
---|
| 987 | for ($i=0; $i<$entry[0]['mailforwardingaddress']['count']; $i++) |
---|
| 988 | { |
---|
| 989 | $justthese = array("cn", "uidnumber", "uid", "phpgwaccounttype", "mail"); |
---|
| 990 | |
---|
| 991 | // Montagem dinamica do filtro |
---|
| 992 | $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=l))(|"; |
---|
| 993 | for ($k=0; (($k<10) && ($i<$entry[0]['mailforwardingaddress']['count'])); $k++) |
---|
| 994 | { |
---|
| 995 | $filter .= "(mail=".$entry[0]['mailforwardingaddress'][$i].")"; |
---|
| 996 | $i++; |
---|
| 997 | } |
---|
| 998 | $i--; |
---|
| 999 | $filter .= "))"; |
---|
| 1000 | |
---|
| 1001 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1002 | $user_entry = ldap_get_entries($this->ldap, $search); |
---|
| 1003 | |
---|
| 1004 | for ($j=0; $j<$user_entry['count']; $j++) |
---|
| 1005 | { |
---|
| 1006 | $result['members_info'][$user_entry[$j]['uidnumber'][0]]['uid'] = $user_entry[$j]['uid'][0]; |
---|
| 1007 | $result['members_info'][$user_entry[$j]['uidnumber'][0]]['cn'] = $user_entry[$j]['cn'][0]; |
---|
| 1008 | $result['members_info'][$user_entry[$j]['uidnumber'][0]]['type'] = $user_entry[$j]['phpgwaccounttype'][0]; |
---|
| 1009 | $result['members_info'][$user_entry[$j]['uidnumber'][0]]['mail'] = $user_entry[$j]['mail'][0]; |
---|
| 1010 | $result['members'][] = $user_entry[$j]['uidnumber'][0]; |
---|
| 1011 | } |
---|
| 1012 | } |
---|
| 1013 | |
---|
| 1014 | // Retira o count do array |
---|
| 1015 | array_shift($entry[0]['mailforwardingaddress']); |
---|
| 1016 | |
---|
| 1017 | // Checamos e-mails que nï¿œo fazem parte do expresso. |
---|
| 1018 | // Criamos um array temporario |
---|
| 1019 | $tmp_array = array(); |
---|
| 1020 | foreach ($result['members_info'] as $uid => $user_data) |
---|
| 1021 | { |
---|
| 1022 | $tmp_array[] = $user_data['mail']; |
---|
| 1023 | } |
---|
| 1024 | |
---|
| 1025 | // Vemos a diferenï¿œa |
---|
| 1026 | $array_diff = array_diff($entry[0]['mailforwardingaddress'], $tmp_array); |
---|
| 1027 | |
---|
| 1028 | // Incluimos no resultado |
---|
| 1029 | foreach ($array_diff as $index=>$mailforwardingaddress) |
---|
| 1030 | { |
---|
| 1031 | $result['members_info'][$mailforwardingaddress]['uid'] = $mailforwardingaddress; |
---|
| 1032 | //$result['members_info'][$mailforwardingaddress]['cn'] = 'E-Mail nao encontrado'; |
---|
| 1033 | $result['members_info'][$mailforwardingaddress]['cn'] = ''; |
---|
| 1034 | $result['members_info'][$mailforwardingaddress]['mailforwardingaddress'] = $mailforwardingaddress; |
---|
| 1035 | $result['members'][] = $mailforwardingaddress; |
---|
| 1036 | } |
---|
| 1037 | return $result; |
---|
| 1038 | } |
---|
| 1039 | |
---|
| 1040 | function get_adm_maillist_info($uidnumber, $context) // Funcao que coleta as informacoes dos administradores de listas no LDAP |
---|
| 1041 | { |
---|
| 1042 | $filter="(&(phpgwAccountType=l)(uidNumber=".$uidnumber."))"; |
---|
| 1043 | $search = ldap_search($this->ldap, $context, $filter); |
---|
| 1044 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 1045 | |
---|
| 1046 | //Pega o dn do setor do usuario. |
---|
| 1047 | $entry[0]['dn'] = strtolower($entry[0]['dn']); |
---|
| 1048 | $sector_dn_array = explode(",", $entry[0]['dn']); |
---|
| 1049 | for($i=1; $i<count($sector_dn_array); $i++) |
---|
| 1050 | $sector_dn .= $sector_dn_array[$i] . ','; |
---|
| 1051 | //Retira ultimo pipe. |
---|
| 1052 | $sector_dn = substr($sector_dn,0,(strlen($sector_dn) - 1)); |
---|
| 1053 | |
---|
| 1054 | $result['context'] = $sector_dn; |
---|
| 1055 | $result['uidnumber'] = $entry[0]['uidnumber'][0]; |
---|
| 1056 | $result['uid'] = $entry[0]['uid'][0]; |
---|
| 1057 | $result['cn'] = $entry[0]['cn'][0]; |
---|
| 1058 | $result['listPass'] = $entry[0]['listPass'][0]; |
---|
| 1059 | $result['mail'] = $entry[0]['mail'][0]; |
---|
| 1060 | $result['accountStatus'] = $entry[0]['accountstatus'][0]; |
---|
| 1061 | $result['accountAdm'] = $entry[0]['accountAdm'][0]; |
---|
| 1062 | $result['phpgwAccountVisible'] = $entry[0]['phpgwaccountvisible'][0]; |
---|
| 1063 | $result['description'] = $entry[0]['description'][0]; |
---|
| 1064 | |
---|
| 1065 | //Members |
---|
| 1066 | for ($i=0; $i<$entry[0]['admlista']['count']; $i++) |
---|
| 1067 | { |
---|
| 1068 | $justthese = array("cn", "uidnumber", "uid", "phpgwaccounttype", "mail", "admlista"); |
---|
| 1069 | |
---|
| 1070 | // Montagem dinamica do filtro |
---|
| 1071 | $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=l))(|"; |
---|
| 1072 | for ($k=0; (($k<10) && ($i<$entry[0]['admlista']['count'])); $k++) |
---|
| 1073 | { |
---|
| 1074 | $filter .= "(mail=".$entry[0]['admlista'][$i].")"; |
---|
| 1075 | $i++; |
---|
| 1076 | } |
---|
| 1077 | $i--; |
---|
| 1078 | $filter .= "))"; |
---|
| 1079 | |
---|
| 1080 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1081 | $user_entry = ldap_get_entries($this->ldap, $search); |
---|
| 1082 | |
---|
| 1083 | for ($j=0; $j<$user_entry['count']; $j++) |
---|
| 1084 | { |
---|
| 1085 | $result['members_info'][$user_entry[$j]['uidnumber'][0]]['uid'] = $user_entry[$j]['uid'][0]; |
---|
| 1086 | $result['members_info'][$user_entry[$j]['uidnumber'][0]]['cn'] = $user_entry[$j]['cn'][0]; |
---|
| 1087 | $result['members_info'][$user_entry[$j]['uidnumber'][0]]['type'] = $user_entry[$j]['phpgwaccounttype'][0]; |
---|
| 1088 | $result['members_info'][$user_entry[$j]['uidnumber'][0]]['mail'] = $user_entry[$j]['mail'][0]; |
---|
| 1089 | $result['members'][] = $user_entry[$j]['uidnumber'][0]; |
---|
| 1090 | } |
---|
| 1091 | } |
---|
| 1092 | |
---|
| 1093 | // Retira o count do array |
---|
| 1094 | array_shift($entry[0]['admlista']); |
---|
| 1095 | |
---|
| 1096 | // Checamos e-mails que nï¿œo fazem parte do expresso. |
---|
| 1097 | // Criamos um array temporario |
---|
| 1098 | $tmp_array = array(); |
---|
| 1099 | foreach ($result['members_info'] as $uid => $user_data) |
---|
| 1100 | { |
---|
| 1101 | $tmp_array[] = $user_data['mail']; |
---|
| 1102 | } |
---|
| 1103 | |
---|
| 1104 | // Vemos a diferenï¿œa |
---|
| 1105 | $array_diff = array_diff($entry[0]['admlista'], $tmp_array); |
---|
| 1106 | |
---|
| 1107 | // Incluimos no resultado |
---|
| 1108 | foreach ($array_diff as $index=>$admlista) |
---|
| 1109 | { |
---|
| 1110 | $result['members_info'][$admlista]['uid'] = $admlista; |
---|
| 1111 | //$result['members_info'][$admlista]['cn'] = 'E-Mail nao encontrado'; |
---|
| 1112 | $result['members_info'][$admlista]['cn'] = ''; |
---|
| 1113 | $result['members_info'][$admlista]['admlista'] = $admlista; |
---|
| 1114 | $result['members'][] = $admlista; |
---|
| 1115 | } |
---|
| 1116 | return $result; |
---|
| 1117 | } |
---|
| 1118 | |
---|
| 1119 | |
---|
| 1120 | function get_maillist_scl_info($uidnumber, $context) |
---|
| 1121 | { |
---|
| 1122 | $filter="(&(phpgwAccountType=l)(uidNumber=".$uidnumber."))"; |
---|
| 1123 | $search = ldap_search($this->ldap, $context, $filter); |
---|
| 1124 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 1125 | |
---|
| 1126 | //Pega o dn do setor do usuario. |
---|
| 1127 | $entry[0]['dn'] = strtolower($entry[0]['dn']); |
---|
| 1128 | $sector_dn_array = explode(",", $entry[0]['dn']); |
---|
| 1129 | for($i=1; $i<count($sector_dn_array); $i++) |
---|
| 1130 | $sector_dn .= $sector_dn_array[$i] . ','; |
---|
| 1131 | //Retira ultimo pipe. |
---|
| 1132 | $sector_dn = substr($sector_dn,0,(strlen($sector_dn) - 1)); |
---|
| 1133 | |
---|
| 1134 | $result['dn'] = $entry[0]['dn']; |
---|
| 1135 | $result['context'] = $sector_dn; |
---|
| 1136 | $result['uidnumber'] = $entry[0]['uidnumber'][0]; |
---|
| 1137 | $result['uid'] = $entry[0]['uid'][0]; |
---|
| 1138 | $result['cn'] = $entry[0]['cn'][0]; |
---|
| 1139 | $result['mail'] = $entry[0]['mail'][0]; |
---|
| 1140 | $result['accountStatus'] = $entry[0]['accountstatus'][0]; |
---|
| 1141 | $result['accountAdm'] = $entry[0]['accountAdm'][0]; |
---|
| 1142 | $result['phpgwAccountVisible'] = $entry[0]['phpgwaccountvisible'][0]; |
---|
| 1143 | $result['accountRestrictive'] = $entry[0]['accountrestrictive'][0]; |
---|
| 1144 | $result['participantCanSendMail'] = $entry[0]['participantcansendmail'][0]; |
---|
| 1145 | $result['description'] = $entry[0]['description'][0]; |
---|
| 1146 | |
---|
| 1147 | //Senders |
---|
| 1148 | //for ($i=0; $i<$entry[0]['mailsenderaddress']['count']; $i++) |
---|
| 1149 | //Recupera a relacao de usuario nao moderados no Mailman (podem enviar e-mails para uma lista de e-mail sem precisar da |
---|
| 1150 | //autorizacao do moderador; |
---|
| 1151 | for ($i=0; $i<$entry[0]['naomoderado']['count']; $i++) |
---|
| 1152 | { |
---|
| 1153 | $justthese = array("cn", "uidnumber", "uid", "mail"); |
---|
| 1154 | $filter="(&(phpgwAccountType=u)(mail=".$entry[0]['naomoderado'][$i]."))"; |
---|
| 1155 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1156 | $user_entry = ldap_get_entries($this->ldap, $search); |
---|
| 1157 | |
---|
| 1158 | $result['senders_info'][$user_entry[0]['uidnumber'][0]]['uid'] = $user_entry[0]['uid'][0]; |
---|
| 1159 | $result['senders_info'][$user_entry[0]['uidnumber'][0]]['cn'] = $user_entry[0]['cn'][0]; |
---|
| 1160 | $result['senders_info'][$user_entry[0]['uidnumber'][0]]['mail'] = $user_entry[0]['mail'][0]; |
---|
| 1161 | $result['members'][] = $user_entry[0]['uidnumber'][0]; |
---|
| 1162 | } |
---|
| 1163 | |
---|
| 1164 | return $result; |
---|
| 1165 | } |
---|
| 1166 | |
---|
| 1167 | function group_exist($gidnumber) |
---|
| 1168 | { |
---|
| 1169 | $justthese = array("cn"); |
---|
| 1170 | $filter="(&(phpgwAccountType=g)(gidNumber=".$gidnumber."))"; |
---|
| 1171 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1172 | |
---|
| 1173 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 1174 | if ($entry['count'] == 0) |
---|
| 1175 | return false; |
---|
| 1176 | else |
---|
| 1177 | return true; |
---|
| 1178 | } |
---|
| 1179 | |
---|
| 1180 | function gidnumbers2cn($gidnumbers, $context) |
---|
| 1181 | { |
---|
| 1182 | $result = array(); |
---|
| 1183 | if (count($gidnumbers)) |
---|
| 1184 | { |
---|
| 1185 | $justthese = array("cn"); |
---|
| 1186 | $i = 0; |
---|
| 1187 | foreach ($gidnumbers as $gidnumber) |
---|
| 1188 | { |
---|
| 1189 | $filter="(&(phpgwAccountType=g)(gidNumber=".$gidnumber."))"; |
---|
| 1190 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1191 | |
---|
| 1192 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 1193 | if ($entry['count'] == 0) |
---|
| 1194 | $result['groups_info'][$i]['cn'] = '_Grupo existe no BD mas nï¿œo no LDAP'; |
---|
| 1195 | else |
---|
| 1196 | $result['groups_info'][$i]['cn'] = $entry[0]['cn'][0]; |
---|
| 1197 | $result['groups_info'][$i]['gidnumber'] = $gidnumber; |
---|
| 1198 | |
---|
| 1199 | if (!strpos(strtolower($entry[0]['dn']), strtolower($context))) |
---|
| 1200 | $result['groups_info'][$i]['group_disabled'] = 'true'; |
---|
| 1201 | else |
---|
| 1202 | $result['groups_info'][$i]['group_disabled'] = 'false'; |
---|
| 1203 | |
---|
| 1204 | $i++; |
---|
| 1205 | } |
---|
| 1206 | } |
---|
| 1207 | return $result; |
---|
| 1208 | } |
---|
| 1209 | |
---|
| 1210 | function uidnumber2uid($uidnumber) |
---|
| 1211 | { |
---|
| 1212 | $justthese = array("uid"); |
---|
| 1213 | $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=l))(uidNumber=".$uidnumber."))"; |
---|
| 1214 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1215 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 1216 | return $entry[0]['uid'][0]; |
---|
| 1217 | } |
---|
| 1218 | |
---|
| 1219 | function uid2uidnumber($uid) |
---|
| 1220 | { |
---|
| 1221 | $justthese = array("uidnumber"); |
---|
| 1222 | $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=l))(uid=".$uid."))"; |
---|
| 1223 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1224 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 1225 | return $entry[0]['uidnumber'][0]; |
---|
| 1226 | } |
---|
| 1227 | |
---|
| 1228 | function uidnumber2mail($uidnumber) |
---|
| 1229 | { |
---|
| 1230 | $justthese = array("mail"); |
---|
| 1231 | $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=l))(uidNumber=".$uidnumber."))"; |
---|
| 1232 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1233 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 1234 | return $entry[0]['mail'][0]; |
---|
| 1235 | } |
---|
| 1236 | |
---|
| 1237 | |
---|
| 1238 | function change_user_context($dn, $newrdn, $newparent) |
---|
| 1239 | { |
---|
| 1240 | if (!ldap_rename ( $this->ldap_write, $dn, $newrdn, $newparent, true )) |
---|
| 1241 | { |
---|
| 1242 | $return['status'] = false; |
---|
| 1243 | $return['msg'] = 'Erro em ldap_funcitons->change_user_context: ' . ldap_error($this->ldap_write); |
---|
| 1244 | } |
---|
| 1245 | else |
---|
| 1246 | $return['status'] = true; |
---|
| 1247 | return $return; |
---|
| 1248 | } |
---|
| 1249 | |
---|
| 1250 | function replace_user_attributes($dn, $ldap_mod_replace) |
---|
| 1251 | { |
---|
| 1252 | if (!@ldap_mod_replace ( $this->ldap_write, $dn, $ldap_mod_replace )) |
---|
| 1253 | { |
---|
| 1254 | $return['status'] = false; |
---|
| 1255 | $return['msg'] = 'Erro em ldap_funcitons->replace_user_attributes: ' . ldap_error($this->ldap_write); |
---|
| 1256 | } |
---|
| 1257 | else |
---|
| 1258 | $return['status'] = true; |
---|
| 1259 | return $return; |
---|
| 1260 | } |
---|
| 1261 | |
---|
| 1262 | function add_user_attributes($dn, $ldap_add) |
---|
| 1263 | { |
---|
| 1264 | if (!@ldap_mod_add ( $this->ldap_write, $dn, $ldap_add )) |
---|
| 1265 | { |
---|
| 1266 | $return['status'] = false; |
---|
| 1267 | $return['msg'] = 'Erro em ldap_funcitons->add_user_attributes: ' . ldap_error($this->ldap_write); |
---|
| 1268 | } |
---|
| 1269 | else |
---|
| 1270 | $return['status'] = true; |
---|
| 1271 | |
---|
| 1272 | return $return; |
---|
| 1273 | } |
---|
| 1274 | |
---|
| 1275 | function remove_user_attributes($dn, $ldap_remove) |
---|
| 1276 | { |
---|
| 1277 | if (!@ldap_mod_del ( $this->ldap_write, $dn, $ldap_remove )) |
---|
| 1278 | { |
---|
| 1279 | $return['status'] = false; |
---|
| 1280 | $return['msg'] = 'Erro em ldap_funcitons->remove_user_attributes: ' . ldap_error($this->ldap_write); |
---|
| 1281 | } |
---|
| 1282 | else |
---|
| 1283 | $return['status'] = true; |
---|
| 1284 | |
---|
| 1285 | return $return; |
---|
| 1286 | } |
---|
| 1287 | |
---|
| 1288 | function set_user_password($uid, $password) |
---|
| 1289 | { |
---|
| 1290 | $justthese = array("userPassword"); |
---|
| 1291 | $filter="(&(phpgwAccountType=u)(uid=".$uid."))"; |
---|
| 1292 | $search = ldap_search($this->ldap_write, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1293 | $entry = ldap_get_entries($this->ldap_write, $search); |
---|
| 1294 | $dn = $entry[0]['dn']; |
---|
| 1295 | $userPassword = $entry[0]['userpassword'][0]; |
---|
| 1296 | $ldap_mod_replace['userPassword'] = $password; |
---|
| 1297 | $this->replace_user_attributes($dn, $ldap_mod_replace); |
---|
| 1298 | return $userPassword; |
---|
| 1299 | } |
---|
| 1300 | |
---|
| 1301 | function set_user_expires($uid, $expires) |
---|
| 1302 | { |
---|
| 1303 | $justthese = array(" "); |
---|
| 1304 | $filter="(&(phpgwAccountType=u)(uid=".$uid."))"; |
---|
| 1305 | $search = ldap_search($this->ldap_write, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1306 | $entry = ldap_get_entries($this->ldap_write, $search); |
---|
| 1307 | $dn = $entry[0]['dn']; |
---|
| 1308 | if(isset($GLOBALS['phpgw_info']['server']['atributoexpiracao'])) |
---|
| 1309 | { |
---|
| 1310 | if(substr($GLOBALS['phpgw_info']['server']['atributoexpiracao'],-1,1)=="Z") |
---|
| 1311 | { |
---|
| 1312 | ###quando a data de expiracao estah no formato yyyymmddhhmmssZ |
---|
| 1313 | $ldap_mod_replace[$GLOBALS['phpgw_info']['server']['atributoexpiracao']] = strftime("%Y%m%d%H%M%SZ", $expires); |
---|
| 1314 | } |
---|
| 1315 | else |
---|
| 1316 | { |
---|
| 1317 | ###Outro atributo ldap que, assim como o phpgwaccounttype, tambem contem hora em formato unix |
---|
| 1318 | $ldap_mod_replace[$GLOBALS['phpgw_info']['server']['atributoexpiracao']] = $expires; |
---|
| 1319 | } |
---|
| 1320 | } |
---|
| 1321 | else |
---|
| 1322 | { |
---|
| 1323 | $ldap_mod_replace['phpgwaccountexpires'] = $expires; |
---|
| 1324 | } |
---|
| 1325 | //$ldap_mod_replace['phpgwaccountexpires'] = $expires; |
---|
| 1326 | $this->replace_user_attributes($dn, $ldap_mod_replace); |
---|
| 1327 | return true; |
---|
| 1328 | } |
---|
| 1329 | |
---|
| 1330 | function delete_user($user_info) |
---|
| 1331 | { |
---|
| 1332 | $return['status'] = true; |
---|
| 1333 | |
---|
| 1334 | // GROUPS |
---|
| 1335 | $attrs = array(); |
---|
| 1336 | $attrs['memberUid'] = $user_info['uid']; |
---|
| 1337 | if (count($user_info['groups_info'])) |
---|
| 1338 | { |
---|
| 1339 | foreach ($user_info['groups_info'] as $group_info) |
---|
| 1340 | { |
---|
| 1341 | $gidnumber = $group_info['gidnumber']; |
---|
| 1342 | $justthese = array("dn"); |
---|
| 1343 | $filter="(&(phpgwAccountType=g)(gidnumber=".$gidnumber."))"; |
---|
| 1344 | $search = ldap_search($this->ldap_write, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1345 | $entry = ldap_get_entries($this->ldap_write, $search); |
---|
| 1346 | $dn = $entry[0]['dn']; |
---|
| 1347 | |
---|
| 1348 | if (!@ldap_mod_del($this->ldap_write, $dn, $attrs)) |
---|
| 1349 | { |
---|
| 1350 | $return['status'] = false; |
---|
| 1351 | $return['msg'] .= 'Erro em ldap_funcitons->delete_user, grupos: ' . ldap_error($this->ldap_write); |
---|
| 1352 | } |
---|
| 1353 | } |
---|
| 1354 | } |
---|
| 1355 | |
---|
| 1356 | // MAILLISTS |
---|
| 1357 | $attrs = array(); |
---|
| 1358 | $attrs['mailForwardingAddress'] = $user_info['mail']; |
---|
| 1359 | if (count($user_info['maillists_info'])) |
---|
| 1360 | { |
---|
| 1361 | foreach ($user_info['maillists_info'] as $maillists_info) |
---|
| 1362 | { |
---|
| 1363 | $uidnumber = $maillists_info['uidnumber']; |
---|
| 1364 | $justthese = array("dn"); |
---|
| 1365 | $filter="(&(phpgwAccountType=l)(uidnumber=".$uidnumber."))"; |
---|
| 1366 | $search = ldap_search($this->ldap_write, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1367 | $entry = ldap_get_entries($this->ldap_write, $search); |
---|
| 1368 | $dn = $entry[0]['dn']; |
---|
| 1369 | |
---|
| 1370 | if (!@ldap_mod_del($this->ldap_write, $dn, $attrs)) |
---|
| 1371 | { |
---|
| 1372 | $return['status'] = false; |
---|
| 1373 | $return['msg'] .= 'Erro em ldap_funcitons->delete_user, listas de email: ' . ldap_error($this->ldap_write); |
---|
| 1374 | } |
---|
| 1375 | } |
---|
| 1376 | } |
---|
| 1377 | |
---|
| 1378 | // UID |
---|
| 1379 | $dn = "uid=" . $user_info['uid'] . "," . $user_info['context']; |
---|
| 1380 | if (!@ldap_delete($this->ldap_write, $dn)) |
---|
| 1381 | { |
---|
| 1382 | $return['status'] = false; |
---|
| 1383 | $return['msg'] .= 'Erro em ldap_funcitons->delete_user, listas de email: ' . ldap_error($this->ldap_write); |
---|
| 1384 | } |
---|
| 1385 | |
---|
| 1386 | return $return; |
---|
| 1387 | } |
---|
| 1388 | function delete_user_group($user,$groups) |
---|
| 1389 | { |
---|
| 1390 | $return['status'] = true; |
---|
| 1391 | $attrs = array(); |
---|
| 1392 | $attrs['memberUid'] = $user['uid']; |
---|
| 1393 | if ($groups['groups']) |
---|
| 1394 | { |
---|
| 1395 | foreach ($groups['groups'] as $gidnumber) |
---|
| 1396 | { |
---|
| 1397 | $justthese = array("dn"); |
---|
| 1398 | $filter="(&(phpgwAccountType=g)(gidnumber=".$gidnumber."))"; |
---|
| 1399 | $search = ldap_search($this->ldap_write, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1400 | $entry = ldap_get_entries($this->ldap_write, $search); |
---|
| 1401 | $dn = $entry[0]['dn']; |
---|
| 1402 | if (!@ldap_mod_del($this->ldap_write, $dn, $attrs)) |
---|
| 1403 | { |
---|
| 1404 | $return['status'] = false; |
---|
| 1405 | $return['msg'] .= 'Erro em ldap_funcitons->delete_user, grupos: ' . ldap_error($this->ldap_write); |
---|
| 1406 | } |
---|
| 1407 | } |
---|
| 1408 | } |
---|
| 1409 | return $return; |
---|
| 1410 | } |
---|
| 1411 | function delete_maillist($uidnumber) |
---|
| 1412 | { |
---|
| 1413 | $return['status'] = true; |
---|
| 1414 | |
---|
| 1415 | $justthese = array("dn"); |
---|
| 1416 | $filter="(&(phpgwAccountType=l)(uidnumber=".$uidnumber."))"; |
---|
| 1417 | $search = ldap_search($this->ldap_write, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1418 | $entry = ldap_get_entries($this->ldap_write, $search); |
---|
| 1419 | $dn = $entry[0]['dn']; |
---|
| 1420 | |
---|
| 1421 | if (!@ldap_delete($this->ldap_write, $dn)) |
---|
| 1422 | { |
---|
| 1423 | $return['status'] = false; |
---|
| 1424 | $return['msg'] .= 'Erro em ldap_funcitons->delete_maillist, listas de email: ' . ldap_error($this->ldap_write); |
---|
| 1425 | } |
---|
| 1426 | |
---|
| 1427 | return $return; |
---|
| 1428 | } |
---|
| 1429 | |
---|
| 1430 | function delete_group($gidnumber) |
---|
| 1431 | { |
---|
| 1432 | $return['status'] = true; |
---|
| 1433 | |
---|
| 1434 | $justthese = array("dn"); |
---|
| 1435 | $filter="(&(phpgwAccountType=g)(gidnumber=".$gidnumber."))"; |
---|
| 1436 | $search = ldap_search($this->ldap_write, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1437 | $entry = ldap_get_entries($this->ldap_write, $search); |
---|
| 1438 | $dn = $entry[0]['dn']; |
---|
| 1439 | |
---|
| 1440 | if (!@ldap_delete($this->ldap_write, $dn)) |
---|
| 1441 | { |
---|
| 1442 | $return['status'] = false; |
---|
| 1443 | $return['msg'] .= 'Erro em ldap_funcitons->delete_maillist, listas de email: ' . ldap_error($this->ldap_write); |
---|
| 1444 | } |
---|
| 1445 | |
---|
| 1446 | return $return; |
---|
| 1447 | } |
---|
| 1448 | |
---|
| 1449 | |
---|
| 1450 | function rename_uid($uid, $new_uid) |
---|
| 1451 | { |
---|
| 1452 | $return['status'] = true; |
---|
| 1453 | |
---|
| 1454 | $justthese = array("dn"); |
---|
| 1455 | $filter="(&(phpgwAccountType=u)(uid=".$uid."))"; |
---|
| 1456 | $search = ldap_search($this->ldap_write, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1457 | $entry = ldap_get_entries($this->ldap_write, $search); |
---|
| 1458 | $dn = $entry[0]['dn']; |
---|
| 1459 | |
---|
| 1460 | $explode_dn = ldap_explode_dn($dn, 0); |
---|
| 1461 | $rdn = "uid=" . $new_uid; |
---|
| 1462 | |
---|
| 1463 | $parent = array(); |
---|
| 1464 | for ($j=1; $j<(count($explode_dn)-1); $j++) |
---|
| 1465 | $parent[] = $explode_dn[$j]; |
---|
| 1466 | $parent = implode(",", $parent); |
---|
| 1467 | |
---|
| 1468 | $return['new_dn'] = $rdn . ',' . $parent; |
---|
| 1469 | |
---|
| 1470 | if (!@ldap_rename($this->ldap_write, $dn, $rdn, $parent, false)) |
---|
| 1471 | { |
---|
| 1472 | $return['status'] = false; |
---|
| 1473 | $return['msg'] .= 'Erro em ldap_funcitons->rename_uid: ' . ldap_error($this->ldap_write); |
---|
| 1474 | } |
---|
| 1475 | |
---|
| 1476 | //Grupos |
---|
| 1477 | $justthese = array("dn"); |
---|
| 1478 | $filter="(&(phpgwAccountType=g)(memberuid=".$uid."))"; |
---|
| 1479 | $search = ldap_search($this->ldap_write, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1480 | $entry = ldap_get_entries($this->ldap_write, $search); |
---|
| 1481 | $array_mod_add['memberUid'] = $new_uid; |
---|
| 1482 | $array_mod_del['memberUid'] = $uid; |
---|
| 1483 | |
---|
| 1484 | for ($i=0; $i<=$entry['count']; $i++) |
---|
| 1485 | { |
---|
| 1486 | $dn = $entry[$i]['dn']; |
---|
| 1487 | @ldap_mod_add ( $this->ldap_write, $dn, $array_mod_add); |
---|
| 1488 | @ldap_mod_del ( $this->ldap_write, $dn, $array_mod_del); |
---|
| 1489 | } |
---|
| 1490 | return $return; |
---|
| 1491 | } |
---|
| 1492 | |
---|
| 1493 | function rename_cn($cn, $new_cn) |
---|
| 1494 | { |
---|
| 1495 | $return['status'] = true; |
---|
| 1496 | |
---|
| 1497 | $justthese = array("dn"); |
---|
| 1498 | $filter="(&(phpgwAccountType=g)(uid=".$cn."))"; |
---|
| 1499 | $search = ldap_search($this->ldap_write, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1500 | $entry = ldap_get_entries($this->ldap_write, $search); |
---|
| 1501 | $dn = $entry[0]['dn']; |
---|
| 1502 | |
---|
| 1503 | $explode_dn = ldap_explode_dn($dn, 0); |
---|
| 1504 | $rdn = "cn=" . $new_cn; |
---|
| 1505 | |
---|
| 1506 | $parent = array(); |
---|
| 1507 | for ($j=1; $j<(count($explode_dn)-1); $j++) |
---|
| 1508 | $parent[] = $explode_dn[$j]; |
---|
| 1509 | $parent = implode(",", $parent); |
---|
| 1510 | |
---|
| 1511 | $return['new_dn'] = $rdn . ',' . $parent; |
---|
| 1512 | |
---|
| 1513 | if (!@ldap_rename($this->ldap_write, $dn, $rdn, $parent, false)) |
---|
| 1514 | { |
---|
| 1515 | $return['status'] = false; |
---|
| 1516 | } |
---|
| 1517 | |
---|
| 1518 | return $return; |
---|
| 1519 | } |
---|
| 1520 | /* |
---|
| 1521 | function rename_departmentnumber($old_dp, $new_dp) |
---|
| 1522 | { |
---|
| 1523 | $return['status'] = true; |
---|
| 1524 | |
---|
| 1525 | $justthese = array("dn"); |
---|
| 1526 | $filter="(&(phpgwAccountType=u)(departmentnumber=".$old_dp."))"; |
---|
| 1527 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1528 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 1529 | |
---|
| 1530 | for ($i=0; $i<=$entry['count']; $i++) |
---|
| 1531 | { |
---|
| 1532 | $dn = strtolower($entry[$i]['dn']); |
---|
| 1533 | $ldap_mod_replace = array(); |
---|
| 1534 | $ldap_mod_replace['departmentnumber'] = $new_dp; |
---|
| 1535 | @ldap_mod_replace ( $this->ldap, $dn, $ldap_mod_replace); |
---|
| 1536 | //if (!@ldap_mod_replace ( $this->ldap, $dn, $ldap_mod_replace)) |
---|
| 1537 | //{ |
---|
| 1538 | // $return['status'] = false; |
---|
| 1539 | // $return['msg'] .= 'Erro em ldap_funcitons->rename_departmentnumber: ' . ldap_error($this->ldap); |
---|
| 1540 | //} |
---|
| 1541 | } |
---|
| 1542 | return $return; |
---|
| 1543 | } |
---|
| 1544 | */ |
---|
| 1545 | /* |
---|
| 1546 | function get_sambadomains($context) |
---|
| 1547 | { |
---|
| 1548 | $return['status'] = true; |
---|
| 1549 | $return['sambaDomains'] = array(); |
---|
| 1550 | |
---|
| 1551 | $justthese = array("sambaSID","sambaDomainName"); |
---|
| 1552 | $filter="(objectClass=sambaDomain)"; |
---|
| 1553 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 1554 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 1555 | |
---|
| 1556 | for ($i=0; $i<$entry['count']; $i++) |
---|
| 1557 | { |
---|
| 1558 | $return['sambaDomains'][$i]['samba_domain_sid'] = $entry[$i]['sambasid'][0]; |
---|
| 1559 | $return['sambaDomains'][$i]['samba_domain_name'] = $entry[$i]['sambadomainname'][0]; |
---|
| 1560 | $return['sambaDomains'][$i]['samba_domain_dn'] = $entry[$i]['dn']; |
---|
| 1561 | } |
---|
| 1562 | |
---|
| 1563 | return $return; |
---|
| 1564 | } |
---|
| 1565 | */ |
---|
| 1566 | function exist_sambadomains($context, $sambaDomainName) |
---|
| 1567 | { |
---|
| 1568 | $justthese = array("dn"); |
---|
| 1569 | $filter="(&(objectClass=sambaDomain)(sambaDomainName=$sambaDomainName))"; |
---|
| 1570 | $search = ldap_search($this->ldap_write, $context, $filter, $justthese); |
---|
| 1571 | $entry = ldap_get_entries($this->ldap_write, $search); |
---|
| 1572 | |
---|
| 1573 | if ($entry['count']) |
---|
| 1574 | return true; |
---|
| 1575 | else |
---|
| 1576 | return false; |
---|
| 1577 | } |
---|
| 1578 | |
---|
| 1579 | // Primeiro nilvel de organizaᅵᅵo. |
---|
| 1580 | function exist_sambadomains_in_context($params) |
---|
| 1581 | { |
---|
| 1582 | $dn = $GLOBALS['phpgw_info']['server']['ldap_context']; |
---|
| 1583 | $array_dn = ldap_explode_dn ( $dn, 0 ); |
---|
| 1584 | |
---|
| 1585 | $context = $params['context']; |
---|
| 1586 | $array_context = ldap_explode_dn ( $context, 0 ); |
---|
| 1587 | |
---|
| 1588 | // Pego o setor no caso do contexto ser um sub-setor. |
---|
| 1589 | if (($array_dn['count']+1) < ($array_context['count'])) |
---|
| 1590 | { |
---|
| 1591 | // inverto o array_dn para poder retirar o count |
---|
| 1592 | $array_dn_reverse = array_reverse ( $array_dn, false ); |
---|
| 1593 | |
---|
| 1594 | //retiro o count |
---|
| 1595 | array_pop($array_dn_reverse); |
---|
| 1596 | |
---|
| 1597 | //incluo o setor no dn |
---|
| 1598 | array_push ( $array_dn_reverse, $array_context[ $array_context['count'] - 1 - $array_dn['count']]); |
---|
| 1599 | |
---|
| 1600 | // Volto a ordem natural |
---|
| 1601 | $array_dn = array_reverse ( $array_dn_reverse, false ); |
---|
| 1602 | |
---|
| 1603 | // Implodo |
---|
| 1604 | $context = implode ( ",", $array_dn ); |
---|
| 1605 | } |
---|
| 1606 | |
---|
| 1607 | $justthese = array("dn","sambaDomainName"); |
---|
| 1608 | $filter="(objectClass=sambaDomain)"; |
---|
| 1609 | $search = ldap_list($this->ldap_write, $context, $filter, $justthese); |
---|
| 1610 | $entry = ldap_get_entries($this->ldap_write, $search); |
---|
| 1611 | |
---|
| 1612 | for ($i=0; $i<$entry['count']; $i++) |
---|
| 1613 | { |
---|
| 1614 | $return['sambaDomains'][$i] = $entry[$i]['sambadomainname'][0]; |
---|
| 1615 | } |
---|
| 1616 | |
---|
| 1617 | if ($entry['count']) |
---|
| 1618 | $return['status'] = true; |
---|
| 1619 | else |
---|
| 1620 | $return['status'] = false; |
---|
| 1621 | |
---|
| 1622 | return $return; |
---|
| 1623 | } |
---|
| 1624 | |
---|
| 1625 | function add_sambadomain($sambadomainname, $sambasid, $context) |
---|
| 1626 | { |
---|
| 1627 | $result = array(); |
---|
| 1628 | |
---|
| 1629 | $dn = "sambaDomainName=$sambadomainname,$context"; |
---|
| 1630 | $entry['sambaSID'] = $sambasid; |
---|
| 1631 | $entry['objectClass'] = 'sambaDomain'; |
---|
| 1632 | $entry['sambaAlgorithmicRidBase'] = '1000'; |
---|
| 1633 | $entry['sambaDomainName'] = $sambadomainname; |
---|
| 1634 | |
---|
| 1635 | if (!@ldap_add ( $this->ldap_write, $dn, $entry )) |
---|
| 1636 | { |
---|
| 1637 | $return['status'] = false; |
---|
| 1638 | $return['msg'] = "Erro na funcao ldap_functions->add_sambadomain ($dn).\nRetorno do servidor: " . ldap_error($this->ldap_write); |
---|
| 1639 | } |
---|
| 1640 | else |
---|
| 1641 | $return['status'] = true; |
---|
| 1642 | |
---|
| 1643 | return $return; |
---|
| 1644 | } |
---|
| 1645 | |
---|
| 1646 | function delete_sambadomain($sambadomainname) |
---|
| 1647 | { |
---|
| 1648 | $return['status'] = true; |
---|
| 1649 | $filter="(sambaDomainName=$sambadomainname)"; |
---|
| 1650 | $search = ldap_search($this->ldap_write, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter); |
---|
| 1651 | $entry = ldap_get_entries($this->ldap_write, $search); |
---|
| 1652 | |
---|
| 1653 | if ($entry['count'] != 0) |
---|
| 1654 | { |
---|
| 1655 | $dn = $entry[0]['dn']; |
---|
| 1656 | |
---|
| 1657 | if (!@ldap_delete($this->ldap_write, $dn)) |
---|
| 1658 | { |
---|
| 1659 | $return['status'] = false; |
---|
| 1660 | $return['msg'] .= "Erro em ldap_functions->delete_sambadomain ($sambadomainname).\nRetorno do servidor: " . ldap_error($this->ldap_write); |
---|
| 1661 | } |
---|
| 1662 | } |
---|
| 1663 | |
---|
| 1664 | return $return; |
---|
| 1665 | } |
---|
| 1666 | } |
---|
| 1667 | //Geracao de senha criptografada pro Mailman |
---|
| 1668 | |
---|
| 1669 | function encriptar($string) |
---|
| 1670 | { |
---|
| 1671 | $key='expresso-livre'; |
---|
| 1672 | $result = ''; |
---|
| 1673 | for($i=1; $i<=strlen($string); $i++) |
---|
| 1674 | { |
---|
| 1675 | $char = substr($string, $i-1, 1); |
---|
| 1676 | $keychar = substr($key, ($i % strlen($key))-1, 1); |
---|
| 1677 | $char = chr(ord($char)+ord($keychar)); |
---|
| 1678 | $result.=$char; |
---|
| 1679 | } |
---|
| 1680 | return $result; |
---|
| 1681 | } |
---|
| 1682 | |
---|
| 1683 | ?> |
---|