[2] | 1 | <?php |
---|
| 2 | define('PHPGW_INCLUDE_ROOT','../'); |
---|
| 3 | define('PHPGW_API_INC','../phpgwapi/inc'); |
---|
| 4 | include_once(PHPGW_API_INC.'/class.common.inc.php'); |
---|
[63] | 5 | include_once('class.functions.inc.php'); |
---|
[2] | 6 | |
---|
| 7 | class ldap_functions |
---|
| 8 | { |
---|
| 9 | var $ldap; |
---|
| 10 | var $current_config; |
---|
[63] | 11 | var $functions; |
---|
[2] | 12 | |
---|
| 13 | function ldap_functions(){ |
---|
| 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(); |
---|
[63] | 18 | $this->functions = new functions; |
---|
[2] | 19 | } |
---|
| 20 | |
---|
| 21 | function validate_fields($params) |
---|
| 22 | { |
---|
[63] | 23 | $result['status'] = true; |
---|
[2] | 24 | $params = unserialize($params['attributes']); |
---|
| 25 | $type = $params['type']; |
---|
| 26 | $context = $GLOBALS['phpgw_info']['server']['ldap_context']; |
---|
| 27 | $uid = $params['uid']; |
---|
| 28 | $mail = $params['mail']; |
---|
| 29 | $mailalternateaddress = $params['mailalternateaddress']; |
---|
[63] | 30 | |
---|
[23] | 31 | if ($_SESSION['phpgw_info']['expresso']['global_denied_users'][$uid]) |
---|
| 32 | { |
---|
| 33 | $result['status'] = false; |
---|
| 34 | $result['msg'] = 'Este LOGIN não pode ser usado pois é uma conta de sistema.'; |
---|
| 35 | return $result; |
---|
| 36 | } |
---|
| 37 | |
---|
[2] | 38 | if (($type == 'create_user') || ($type == 'rename_user')) |
---|
| 39 | { |
---|
| 40 | // UID |
---|
| 41 | $filter = "(&(|(phpgwAccountType=u)(phpgwAccountType=l))(uid=$uid))"; |
---|
| 42 | $justthese = array("uid"); |
---|
| 43 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 44 | $count_entries = ldap_count_entries($this->ldap,$search); |
---|
| 45 | if ($count_entries > 0) |
---|
| 46 | { |
---|
| 47 | $result['status'] = false; |
---|
| 48 | $result['msg'] = 'LOGIN já esta sendo usado.'; |
---|
| 49 | return $result; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | // GRUPOS |
---|
| 53 | $filter = "(&(phpgwAccountType=g)(cn=$uid))"; |
---|
| 54 | $justthese = array("cn"); |
---|
| 55 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 56 | $count_entries = ldap_count_entries($this->ldap,$search); |
---|
| 57 | if ($count_entries > 0) |
---|
| 58 | { |
---|
| 59 | $result['status'] = false; |
---|
| 60 | $result['msg'] = 'LOGIN do usuário já esta sendo usado por um grupo.'; |
---|
| 61 | return $result; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | // UID em outras organizações |
---|
| 65 | //Quando tento retirar as organizações pelo expressoAdmin dá este erro. |
---|
| 66 | $filter = "(ou=*)"; |
---|
| 67 | $justthese = array("ou"); |
---|
| 68 | $search = ldap_list($this->ldap, $context, $filter, $justthese); |
---|
| 69 | $entries = ldap_get_entries($this->ldap,$search); |
---|
| 70 | foreach ($entries as $index=>$org) |
---|
| 71 | { |
---|
| 72 | $organization = $org['ou'][0]; |
---|
| 73 | $organization = strtolower($organization); |
---|
| 74 | |
---|
| 75 | $filter = "(&(|(phpgwAccountType=u)(phpgwAccountType=l))(uid=$organization-$uid))"; |
---|
| 76 | $justthese = array("uid"); |
---|
| 77 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 78 | $count_entries = ldap_count_entries($this->ldap,$search); |
---|
| 79 | if ($count_entries > 0) |
---|
| 80 | { |
---|
| 81 | $result['status'] = false; |
---|
| 82 | $result['msg'] = 'LOGIN já esta sendo usado por outro usuário em outra organização.'; |
---|
| 83 | return $result; |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | if ($type == 'rename_user') |
---|
| 89 | { |
---|
| 90 | return $result; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | // MAIL |
---|
| 94 | $filter = "(&(|(phpgwAccountType=u)(phpgwAccountType=l))(|(mail=$mail)(mailalternateaddress=$mail)))"; |
---|
| 95 | $justthese = array("mail", "uid"); |
---|
| 96 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 97 | $entries = ldap_get_entries($this->ldap,$search); |
---|
| 98 | if ($entries['count'] == 1){ |
---|
| 99 | if ($entries[0]['uid'][0] != $uid){ |
---|
| 100 | $result['status'] = false; |
---|
| 101 | $result['msg'] = 'E-MAIL está sendo usado por 1 usuário: ' . $entries[0]['uid'][0]; |
---|
| 102 | //ldap_close($this->ldap); |
---|
| 103 | return $result; |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | else if ($entries['count'] > 1){ |
---|
| 107 | $result['status'] = false; |
---|
| 108 | $result['msg'] = 'E-MAIL está sendo usado por de 2 ou mais usuários.'; |
---|
| 109 | //ldap_close($this->ldap); |
---|
| 110 | return $result; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | // MAILAlternateAddress |
---|
| 114 | $filter = "(&(|(phpgwAccountType=u)(phpgwAccountType=l))(|(mail=$mailalternateaddress)(mailalternateaddress=$mailalternateaddress)))"; |
---|
| 115 | $justthese = array("mail", "uid"); |
---|
| 116 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 117 | $entries = ldap_get_entries($this->ldap,$search); |
---|
| 118 | if ($entries['count'] == 1){ |
---|
| 119 | if ($entries[0]['uid'][0] != $uid){ |
---|
| 120 | $result['status'] = false; |
---|
| 121 | $result['msg'] = "E-MAIL alternativo está sendo usado por 1 usuário: " . $entries[0]['uid'][0]; |
---|
| 122 | //ldap_close($this->ldap); |
---|
| 123 | return $result; |
---|
| 124 | } |
---|
| 125 | } |
---|
| 126 | else if ($entries['count'] > 1){ |
---|
| 127 | $result['status'] = false; |
---|
| 128 | $result['msg'] = 'E-MAIL alternativo está sendo usado por 2 ou mais usuários.'; |
---|
| 129 | return $result; |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | return $result; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | function validate_fields_group($params) |
---|
| 136 | { |
---|
| 137 | $context = $GLOBALS['phpgw_info']['server']['ldap_context']; |
---|
| 138 | $cn = $params['cn']; |
---|
| 139 | $result['status'] = true; |
---|
| 140 | |
---|
[23] | 141 | if ($_SESSION['phpgw_info']['expresso']['global_denied_groups'][$cn]) |
---|
| 142 | { |
---|
| 143 | $result['status'] = false; |
---|
| 144 | $result['msg'] = 'Este nome de grupo não pode ser usado pois é um grupo de sistema.'; |
---|
| 145 | return $result; |
---|
| 146 | } |
---|
| 147 | |
---|
[2] | 148 | // CN |
---|
| 149 | $filter = "(&(phpgwAccountType=g)(cn=$cn))"; |
---|
| 150 | $justthese = array("cn"); |
---|
| 151 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 152 | $count_entries = ldap_count_entries($this->ldap,$search); |
---|
| 153 | if ($count_entries > 0) |
---|
| 154 | { |
---|
| 155 | $result['status'] = false; |
---|
| 156 | $result['msg'] = 'NOME do grupo já está sendo usado.'; |
---|
| 157 | return $result; |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | // UID |
---|
| 161 | $filter = "(&(|(phpgwAccountType=u)(phpgwAccountType=l))(uid=$cn))"; |
---|
| 162 | $justthese = array("uid"); |
---|
| 163 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 164 | $count_entries = ldap_count_entries($this->ldap,$search); |
---|
| 165 | if ($count_entries > 0) |
---|
| 166 | { |
---|
| 167 | $result['status'] = false; |
---|
| 168 | $result['msg'] = 'NOME do grupo já esta sendo usado por um usuário.'; |
---|
| 169 | return $result; |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | return $result; |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | function validate_fields_maillist($params) |
---|
| 176 | { |
---|
| 177 | $context = $GLOBALS['phpgw_info']['server']['ldap_context']; |
---|
| 178 | $uid = $params['uid']; |
---|
| 179 | $mail = $params['mail']; |
---|
| 180 | $result['status'] = true; |
---|
| 181 | |
---|
[23] | 182 | if ($_SESSION['phpgw_info']['expresso']['global_denied_users'][$uid]) |
---|
| 183 | { |
---|
| 184 | $result['status'] = false; |
---|
| 185 | $result['msg'] = 'Este LOGIN não pode ser usado pois é uma conta de sistema.'; |
---|
| 186 | return $result; |
---|
| 187 | } |
---|
| 188 | |
---|
[2] | 189 | // UID |
---|
| 190 | $filter = "(&(phpgwAccountType=l)(uid=$uid))"; |
---|
| 191 | $justthese = array("uid"); |
---|
| 192 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 193 | $count_entries = ldap_count_entries($this->ldap,$search); |
---|
| 194 | if ($count_entries > 0) |
---|
| 195 | { |
---|
| 196 | $result['status'] = false; |
---|
| 197 | $result['msg'] = 'LOGIN da lista já está sendo usado.'; |
---|
| 198 | return $result; |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | // MAIL |
---|
| 202 | /* |
---|
| 203 | $filter = "(&(|(phpgwAccountType=u)(phpgwAccountType=l))(|(mail=$mail)(mailalternateaddress=$mail)))"; |
---|
| 204 | $justthese = array("mail"); |
---|
| 205 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 206 | $count_entries = ldap_count_entries($this->ldap,$search); |
---|
| 207 | if ($count_entries > 0) |
---|
| 208 | { |
---|
| 209 | $result['status'] = false; |
---|
| 210 | $result['msg'] = 'E-MAIL da lista já está sendo usado.'; |
---|
| 211 | return $result; |
---|
| 212 | }*/ |
---|
| 213 | |
---|
| 214 | return $result; |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | //Busca usuários de um contexto e já retorna as options do select; |
---|
| 218 | function get_available_users($params) |
---|
| 219 | { |
---|
| 220 | $context = $params['context']; |
---|
| 221 | $recursive = $params['recursive']; |
---|
| 222 | $justthese = array("cn", "uidNumber"); |
---|
| 223 | $filter="(phpgwAccountType=u)"; |
---|
| 224 | |
---|
| 225 | if ($recursive == 'true') |
---|
| 226 | $groups_list=ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 227 | else |
---|
| 228 | $groups_list=ldap_list($this->ldap, $context, $filter, $justthese); |
---|
| 229 | |
---|
| 230 | $entries = ldap_get_entries($this->ldap, $groups_list); |
---|
| 231 | |
---|
| 232 | for ($i=0; $i<$entries["count"]; $i++){ |
---|
| 233 | $u_tmp[$entries[$i]["uidnumber"][0]] = $entries[$i]["cn"][0]; |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | if (count($u_tmp)) |
---|
| 237 | natcasesort($u_tmp); |
---|
| 238 | |
---|
| 239 | $i = 0; |
---|
| 240 | $users = array(); |
---|
| 241 | |
---|
| 242 | if (count($u_tmp)) |
---|
| 243 | { |
---|
| 244 | foreach ($u_tmp as $uidnumber => $cn) |
---|
| 245 | { |
---|
| 246 | $options .= "<option value=$uidnumber>$cn</option>"; |
---|
| 247 | } |
---|
| 248 | unset($u_tmp); |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | return $options; |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | //Busca usuários de um contexto e já retorna as options do select; |
---|
[23] | 255 | /* |
---|
[2] | 256 | function get_available_users_and_maillist($params) |
---|
| 257 | { |
---|
| 258 | $context = $params['context']; |
---|
| 259 | $recursive = $params['recursive']; |
---|
| 260 | $justthese = array("cn", "uidNumber"); |
---|
| 261 | $filter="(|(phpgwAccountType=u)(phpgwAccountType=l))"; |
---|
| 262 | |
---|
| 263 | if ($recursive == 'true') |
---|
| 264 | $groups_list=ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 265 | else |
---|
| 266 | $groups_list=ldap_list($this->ldap, $context, $filter, $justthese); |
---|
| 267 | |
---|
| 268 | $entries = ldap_get_entries($this->ldap, $groups_list); |
---|
| 269 | |
---|
| 270 | for ($i=0; $i<$entries["count"]; $i++){ |
---|
| 271 | $u_tmp[$entries[$i]["uidnumber"][0]] = $entries[$i]["cn"][0]; |
---|
| 272 | } |
---|
| 273 | |
---|
| 274 | if (count($u_tmp)) |
---|
| 275 | natcasesort($u_tmp); |
---|
| 276 | |
---|
| 277 | $i = 0; |
---|
| 278 | $users = array(); |
---|
| 279 | |
---|
| 280 | if (count($u_tmp)) |
---|
| 281 | { |
---|
| 282 | foreach ($u_tmp as $uidnumber => $cn) |
---|
| 283 | { |
---|
| 284 | $options .= "<option value=$uidnumber>$cn</option>"; |
---|
| 285 | } |
---|
| 286 | unset($u_tmp); |
---|
| 287 | } |
---|
| 288 | |
---|
| 289 | return $options; |
---|
| 290 | } |
---|
[23] | 291 | */ |
---|
[2] | 292 | |
---|
[23] | 293 | //Busca usuários e listas de um contexto e já retorna as options do select; |
---|
| 294 | function get_available_users_and_maillist($params) |
---|
| 295 | { |
---|
| 296 | $context = $params['context']; |
---|
| 297 | $recursive = $params['recursive']; |
---|
| 298 | |
---|
| 299 | //Usado para retirar a própria lista das possibilidades de inclusão. |
---|
| 300 | $denied_uidnumber = $params['denied_uidnumber']; |
---|
| 301 | |
---|
| 302 | $justthese = array("cn", "uidNumber"); |
---|
[46] | 303 | $users_filter="(phpgwAccountType=u)"; |
---|
[23] | 304 | $lists_filter = $denied_uidnumber == '' ? "(phpgwAccountType=l)" : "(&(phpgwAccountType=l)(!(uidnumber=$denied_uidnumber)))"; |
---|
| 305 | |
---|
| 306 | $users = Array(); |
---|
| 307 | $lists = Array(); |
---|
| 308 | |
---|
| 309 | if ($recursive == 'true') |
---|
| 310 | { |
---|
| 311 | $lists_search = ldap_search($this->ldap, $context, $lists_filter, $justthese); |
---|
| 312 | $users_search = ldap_search($this->ldap, $context, $users_filter, $justthese); |
---|
| 313 | } |
---|
| 314 | else |
---|
| 315 | { |
---|
| 316 | $lists_search = ldap_list($this->ldap, $context, $lists_filter, $justthese); |
---|
| 317 | $users_search = ldap_list($this->ldap, $context, $users_filter, $justthese); |
---|
| 318 | } |
---|
| 319 | |
---|
| 320 | $lists_entries = ldap_get_entries($this->ldap, $lists_search); |
---|
| 321 | for ($i=0; $i<$lists_entries["count"]; $i++) |
---|
| 322 | { |
---|
| 323 | $l_tmp[$lists_entries[$i]["uidnumber"][0]] = $lists_entries[$i]["cn"][0]; |
---|
| 324 | } |
---|
| 325 | |
---|
| 326 | if (count($l_tmp)) |
---|
| 327 | natcasesort($l_tmp); |
---|
| 328 | |
---|
| 329 | $i = 0; |
---|
| 330 | $lists = array(); |
---|
| 331 | |
---|
| 332 | $options .= '<option value="-1" disabled>------------------------------ Listas ------------------------------ </option>'."\n"; |
---|
| 333 | if (count($l_tmp)) |
---|
| 334 | { |
---|
| 335 | foreach ($l_tmp as $uidnumber => $cn) |
---|
| 336 | { |
---|
| 337 | $options .= "<option value=$uidnumber>$cn</option>"; |
---|
| 338 | } |
---|
| 339 | unset($l_tmp); |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | $users_entries = ldap_get_entries($this->ldap, $users_search); |
---|
| 343 | for ($i=0; $i<$users_entries["count"]; $i++) |
---|
| 344 | { |
---|
| 345 | $u_tmp[$users_entries[$i]["uidnumber"][0]] = $users_entries[$i]["cn"][0]; |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | if (count($u_tmp)) |
---|
| 349 | natcasesort($u_tmp); |
---|
| 350 | |
---|
| 351 | $i = 0; |
---|
| 352 | $users = array(); |
---|
| 353 | |
---|
| 354 | $options .= '<option value="-1" disabled>----------------------------- Usuários ---------------------------- </option>'."\n"; |
---|
| 355 | if (count($u_tmp)) |
---|
| 356 | { |
---|
| 357 | foreach ($u_tmp as $uidnumber => $cn) |
---|
| 358 | { |
---|
| 359 | $options .= "<option value=$uidnumber class='line-above'>$cn</option>"; |
---|
| 360 | } |
---|
| 361 | unset($u_tmp); |
---|
| 362 | } |
---|
| 363 | |
---|
| 364 | return $options; |
---|
| 365 | } |
---|
| 366 | |
---|
[2] | 367 | function get_available_groups($params) |
---|
| 368 | { |
---|
| 369 | $context = $params['context']; |
---|
| 370 | $justthese = array("cn", "gidNumber"); |
---|
| 371 | $groups_list=ldap_list($this->ldap, $context, ("(phpgwAccountType=g)"), $justthese); |
---|
| 372 | ldap_sort($this->ldap, $groups_list, "cn"); |
---|
| 373 | |
---|
| 374 | $entries = ldap_get_entries($this->ldap, $groups_list); |
---|
[33] | 375 | |
---|
| 376 | $options = ''; |
---|
| 377 | for ($i=0; $i<$entries['count']; $i++) |
---|
| 378 | { |
---|
| 379 | $options .= "<option value=" . $entries[$i]['gidnumber'][0] . ">" . $entries[$i]['cn'][0] . "</option>"; |
---|
| 380 | } |
---|
| 381 | |
---|
| 382 | return $options; |
---|
[2] | 383 | } |
---|
| 384 | |
---|
| 385 | function get_available_maillists($params) |
---|
| 386 | { |
---|
| 387 | $context = $params['context']; |
---|
| 388 | $justthese = array("uid","mail","uidNumber"); |
---|
| 389 | $maillists=ldap_list($this->ldap, $context, ("(phpgwAccountType=l)"), $justthese); |
---|
| 390 | ldap_sort($this->ldap, $maillists, "uid"); |
---|
| 391 | |
---|
| 392 | $entries = ldap_get_entries($this->ldap, $maillists); |
---|
[33] | 393 | |
---|
| 394 | $options = ''; |
---|
| 395 | for ($i=0; $i<$entries['count']; $i++) |
---|
| 396 | { |
---|
| 397 | $options .= "<option value=" . $entries[$i]['uidnumber'][0] . ">" . $entries[$i]['uid'][0] . " (" . $entries[$i]['mail'][0] . ")" . "</option>"; |
---|
| 398 | } |
---|
| 399 | return $options; |
---|
[2] | 400 | } |
---|
| 401 | |
---|
| 402 | function ldap_add_entry($dn, $entry) |
---|
| 403 | { |
---|
| 404 | $result = array(); |
---|
| 405 | if (!@ldap_add ( $this->ldap, $dn, $entry )) |
---|
| 406 | { |
---|
| 407 | $result['status'] = false; |
---|
| 408 | $result['msg'] = "Erro na funcao ldap_functions->ldap_add_entry ($dn).\nRetorno do servidor:" . ldap_error($this->ldap); |
---|
| 409 | } |
---|
| 410 | else |
---|
| 411 | $result['status'] = true; |
---|
| 412 | |
---|
| 413 | return $result; |
---|
| 414 | } |
---|
| 415 | |
---|
| 416 | function ldap_save_photo($dn, $pathphoto, $photo_exist=false) |
---|
| 417 | { |
---|
| 418 | $fd = fopen($pathphoto, "r"); |
---|
| 419 | $fsize = filesize($pathphoto); |
---|
| 420 | $jpegStr = fread($fd, $fsize); |
---|
| 421 | fclose ($fd); |
---|
| 422 | $attrs['jpegPhoto'] = $jpegStr; |
---|
| 423 | |
---|
| 424 | if ($photo_exist) |
---|
| 425 | $res = @ldap_mod_replace($this->ldap, $dn, $attrs); |
---|
| 426 | else |
---|
| 427 | $res = @ldap_mod_add($this->ldap, $dn, $attrs); |
---|
| 428 | |
---|
| 429 | if ($res) |
---|
| 430 | { |
---|
| 431 | $result['status'] = true; |
---|
| 432 | } |
---|
| 433 | else |
---|
| 434 | { |
---|
| 435 | $result['status'] = false; |
---|
[23] | 436 | $result['msg'] = "Erro na funcao ldap_functions->ldap_save_photo ($dn).\nRetorno do servidor:" . ldap_error($this->ldap); |
---|
[2] | 437 | } |
---|
| 438 | |
---|
| 439 | return $result; |
---|
| 440 | } |
---|
| 441 | |
---|
| 442 | function ldap_remove_photo($dn) |
---|
| 443 | { |
---|
| 444 | $attrs['jpegPhoto'] = array(); |
---|
| 445 | $res = ldap_mod_del($this->ldap, $dn, $attrs); |
---|
| 446 | |
---|
| 447 | if ($res) |
---|
| 448 | { |
---|
| 449 | $result['status'] = true; |
---|
| 450 | } |
---|
| 451 | else |
---|
| 452 | { |
---|
| 453 | $result['status'] = false; |
---|
[23] | 454 | $result['msg'] = "Erro na funcao ldap_functions->ldap_remove_photo ($dn).\nRetorno do servidor:" . ldap_error($this->ldap); |
---|
[2] | 455 | } |
---|
| 456 | |
---|
| 457 | return $result; |
---|
| 458 | } |
---|
| 459 | |
---|
| 460 | // Pode receber tanto um único memberUid quanto um array de memberUid's |
---|
| 461 | function add_user2group($gidNumber, $memberUid) |
---|
| 462 | { |
---|
| 463 | $filter = "(&(phpgwAccountType=g)(gidNumber=$gidNumber))"; |
---|
| 464 | $justthese = array("dn"); |
---|
| 465 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 466 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 467 | $group_dn = $entry[0]['dn']; |
---|
| 468 | $attrs['memberUid'] = $memberUid; |
---|
| 469 | |
---|
| 470 | $res = @ldap_mod_add($this->ldap, $group_dn, $attrs); |
---|
| 471 | |
---|
| 472 | if ($res) |
---|
| 473 | { |
---|
| 474 | $result['status'] = true; |
---|
| 475 | } |
---|
| 476 | else |
---|
| 477 | { |
---|
| 478 | $result['status'] = false; |
---|
[23] | 479 | $result['msg'] = "Erro na funcao ldap_functions->add_user2group ($memberUid).\nRetorno do servidor:" . ldap_error($this->ldap); |
---|
[2] | 480 | } |
---|
| 481 | return $result; |
---|
| 482 | } |
---|
| 483 | |
---|
| 484 | function remove_user2group($gidNumber, $memberUid) |
---|
| 485 | { |
---|
| 486 | $filter = "(&(phpgwAccountType=g)(gidNumber=$gidNumber))"; |
---|
| 487 | $justthese = array("dn"); |
---|
| 488 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 489 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 490 | $group_dn = $entry[0]['dn']; |
---|
| 491 | $attrs['memberUid'] = $memberUid; |
---|
| 492 | $res = @ldap_mod_del($this->ldap, $group_dn, $attrs); |
---|
| 493 | |
---|
| 494 | /*echo 'usuarios recebidos para remocao no ldap'; |
---|
| 495 | echo '<pre>'; |
---|
| 496 | print_r($memberUid);*/ |
---|
| 497 | |
---|
| 498 | if ($res) |
---|
| 499 | { |
---|
| 500 | $result['status'] = true; |
---|
| 501 | } |
---|
| 502 | else |
---|
| 503 | { |
---|
| 504 | $result['status'] = false; |
---|
[23] | 505 | $result['msg'] = "Erro na funcao ldap_functions->remove_user2group ($memberUid).\nRetorno do servidor:" . ldap_error($this->ldap); |
---|
[2] | 506 | } |
---|
| 507 | return $result; |
---|
| 508 | } |
---|
| 509 | |
---|
| 510 | function add_user2maillist($uidNumber, $mail) |
---|
| 511 | { |
---|
| 512 | $filter = "(&(phpgwAccountType=l)(uidNumber=$uidNumber))"; |
---|
| 513 | $justthese = array("dn"); |
---|
| 514 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 515 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 516 | $group_dn = $entry[0]['dn']; |
---|
| 517 | $attrs['mailForwardingAddress'] = $mail; |
---|
| 518 | $res = @ldap_mod_add($this->ldap, $group_dn, $attrs); |
---|
| 519 | |
---|
| 520 | if ($res) |
---|
| 521 | { |
---|
| 522 | $result['status'] = true; |
---|
| 523 | } |
---|
| 524 | else |
---|
| 525 | { |
---|
| 526 | $result['status'] = false; |
---|
[23] | 527 | $result['msg'] = "Erro na funcao ldap_functions->add_user2maillist ($mail).\nRetorno do servidor:" . ldap_error($this->ldap); |
---|
[2] | 528 | } |
---|
| 529 | return $result; |
---|
| 530 | } |
---|
[23] | 531 | |
---|
| 532 | function add_user2maillist_scl($dn, $array_emails) |
---|
| 533 | { |
---|
| 534 | $attrs['mailSenderAddress'] = $array_emails; |
---|
| 535 | $res = @ldap_mod_add($this->ldap, $dn, $attrs); |
---|
| 536 | |
---|
| 537 | if ($res) |
---|
| 538 | { |
---|
| 539 | $result['status'] = true; |
---|
| 540 | } |
---|
| 541 | else |
---|
| 542 | { |
---|
| 543 | $result['status'] = false; |
---|
| 544 | $result['msg'] = "Erro na funcao ldap_functions->add_user2maillist_scp ($dn).\n\nRetorno do servidor:" . ldap_error($this->ldap); |
---|
| 545 | } |
---|
| 546 | return $result; |
---|
| 547 | } |
---|
| 548 | |
---|
[2] | 549 | function remove_user2maillist($uidNumber, $mail) |
---|
| 550 | { |
---|
| 551 | $filter = "(&(phpgwAccountType=l)(uidNumber=$uidNumber))"; |
---|
| 552 | $justthese = array("dn"); |
---|
| 553 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 554 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 555 | $group_dn = $entry[0]['dn']; |
---|
| 556 | $attrs['mailForwardingAddress'] = $mail; |
---|
| 557 | $res = @ldap_mod_del($this->ldap, $group_dn, $attrs); |
---|
| 558 | |
---|
| 559 | if ($res) |
---|
| 560 | { |
---|
| 561 | $result['status'] = true; |
---|
| 562 | } |
---|
| 563 | else |
---|
| 564 | { |
---|
| 565 | $result['status'] = false; |
---|
[23] | 566 | $result['msg'] = "Erro na funcao ldap_functions->remove_user2maillist ($mail).\n\nRetorno do servidor:" . ldap_error($this->ldap); |
---|
[2] | 567 | } |
---|
| 568 | return $result; |
---|
| 569 | } |
---|
[23] | 570 | |
---|
| 571 | function remove_user2maillist_scl($dn, $array_emails) |
---|
| 572 | { |
---|
| 573 | $attrs['mailSenderAddress'] = $array_emails; |
---|
| 574 | $res = @ldap_mod_del($this->ldap, $dn, $attrs); |
---|
| 575 | |
---|
| 576 | if ($res) |
---|
| 577 | { |
---|
| 578 | $result['status'] = true; |
---|
| 579 | } |
---|
| 580 | else |
---|
| 581 | { |
---|
| 582 | $result['status'] = false; |
---|
| 583 | $result['msg'] = "Erro na funcao ldap_functions->remove_user2maillist_scp ($dn).\n\nRetorno do servidor:" . ldap_error($this->ldap); |
---|
| 584 | } |
---|
| 585 | return $result; |
---|
| 586 | } |
---|
| 587 | |
---|
[2] | 588 | function replace_user2maillists($new_mail, $old_mail) |
---|
| 589 | { |
---|
| 590 | $filter = "(&(phpgwAccountType=l)(mailforwardingaddress=$old_mail))"; |
---|
| 591 | $justthese = array("dn"); |
---|
| 592 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 593 | $entries = ldap_get_entries($this->ldap, $search); |
---|
| 594 | $result['status'] = true; |
---|
| 595 | for ($i=0; $i<$entries['count']; $i++) |
---|
| 596 | { |
---|
| 597 | $attrs['mailforwardingaddress'] = $old_mail; |
---|
| 598 | $res1 = @ldap_mod_del($this->ldap, $entries[$i]['dn'], $attrs); |
---|
| 599 | $attrs['mailforwardingaddress'] = $new_mail; |
---|
| 600 | $res2 = @ldap_mod_add($this->ldap, $entries[$i]['dn'], $attrs); |
---|
| 601 | |
---|
| 602 | if ((!$res1) || (!$res2)) |
---|
| 603 | { |
---|
| 604 | $result['status'] = false; |
---|
[23] | 605 | $result['msg'] = "Erro na funcao ldap_functions->replace_user2maillists ($old_mail).\nRetorno do servidor:" . ldap_error($this->ldap); |
---|
[2] | 606 | } |
---|
| 607 | } |
---|
| 608 | |
---|
| 609 | return $result; |
---|
| 610 | } |
---|
| 611 | |
---|
| 612 | function get_user_info($uidnumber, $context) |
---|
| 613 | { |
---|
| 614 | $filter="(&(phpgwAccountType=u)(uidNumber=".$uidnumber."))"; |
---|
| 615 | $search = ldap_search($this->ldap, $context, $filter); |
---|
| 616 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 617 | |
---|
| 618 | //Pega o dn do setor do usuario. |
---|
| 619 | $entry[0]['dn'] = strtolower($entry[0]['dn']); |
---|
| 620 | $sector_dn_array = explode(",", $entry[0]['dn']); |
---|
| 621 | for($i=1; $i<count($sector_dn_array); $i++) |
---|
| 622 | $sector_dn .= $sector_dn_array[$i] . ','; |
---|
| 623 | //Retira ultimo pipe. |
---|
| 624 | $sector_dn = substr($sector_dn,0,(strlen($sector_dn) - 1)); |
---|
| 625 | |
---|
| 626 | $result['context'] = $sector_dn; |
---|
| 627 | $result['uid'] = $entry[0]['uid'][0]; |
---|
| 628 | $result['uidnumber'] = $entry[0]['uidnumber'][0]; |
---|
| 629 | $result['gidnumber'] = $entry[0]['gidnumber'][0]; |
---|
| 630 | $result['departmentnumber'] = $entry[0]['departmentnumber'][0]; |
---|
| 631 | $result['givenname'] = $entry[0]['givenname'][0]; |
---|
| 632 | $result['sn'] = $entry[0]['sn'][0]; |
---|
| 633 | $result['telephonenumber'] = $entry[0]['telephonenumber'][0]; |
---|
| 634 | $result['phpgwaccountstatus'] = $entry[0]['phpgwaccountstatus'][0]; |
---|
| 635 | $result['phpgwaccountvisible'] = $entry[0]['phpgwaccountvisible'][0]; |
---|
| 636 | $result['accountstatus'] = $entry[0]['accountstatus'][0]; |
---|
| 637 | $result['mail'] = $entry[0]['mail'][0]; |
---|
| 638 | $result['mailalternateaddress'] = $entry[0]['mailalternateaddress'][0]; |
---|
| 639 | $result['mailforwardingaddress']= $entry[0]['mailforwardingaddress'][0]; |
---|
| 640 | $result['deliverymode'] = $entry[0]['deliverymode'][0]; |
---|
[46] | 641 | $result['userPasswordRFC2617'] = $entry[0]['userpasswordrfc2617'][0]; |
---|
[2] | 642 | |
---|
| 643 | //Photo |
---|
| 644 | if ($entry[0]['jpegphoto']['count'] == 1) |
---|
| 645 | $result['photo_exist'] = 'true'; |
---|
| 646 | |
---|
| 647 | // Samba |
---|
| 648 | for ($i=0; $i<$entry[0]['objectclass']['count']; $i++) |
---|
| 649 | { |
---|
| 650 | if ($entry[0]['objectclass'][$i] == 'sambaSamAccount') |
---|
| 651 | $result['sambaUser'] = true; |
---|
| 652 | } |
---|
| 653 | if (($this->current_config['expressoAdmin_samba_support'] == 'true') && ($result['sambaUser'])) |
---|
| 654 | { |
---|
| 655 | $result['sambaaccflags'] = $entry[0]['sambaacctflags'][0]; |
---|
| 656 | $result['sambalogonscript'] = $entry[0]['sambalogonscript'][0]; |
---|
| 657 | $result['homedirectory'] = $entry[0]['homedirectory'][0]; |
---|
[27] | 658 | $a_tmp = explode("-", $entry[0]['sambasid'][0]); |
---|
| 659 | array_pop($a_tmp); |
---|
| 660 | $result['sambasid'] = implode("-", $a_tmp); |
---|
[2] | 661 | } |
---|
[63] | 662 | |
---|
| 663 | // Verifica o acesso do gerente aos atributos corporativos |
---|
| 664 | if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'manipulate_corporative_information')) |
---|
| 665 | { |
---|
| 666 | $result['corporative_information_employeenumber']= $entry[0]['employeenumber'][0]; |
---|
| 667 | $result['corporative_information_cpf'] = $entry[0]['cpf'][0]; |
---|
| 668 | $result['corporative_information_rg'] = $entry[0]['rg'][0]; |
---|
| 669 | $result['corporative_information_rguf'] = $entry[0]['rguf'][0]; |
---|
| 670 | } |
---|
[2] | 671 | |
---|
| 672 | // MailLists |
---|
| 673 | $justthese = array("uid","mail","uidnumber"); |
---|
| 674 | $filter="(&(phpgwAccountType=l)(mailforwardingaddress=".$result['mail']."))"; |
---|
| 675 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 676 | ldap_sort($this->ldap, $search, "uid"); |
---|
| 677 | $entries = ldap_get_entries($this->ldap, $search); |
---|
| 678 | for ($i=0; $i<$entries['count']; $i++) |
---|
| 679 | { |
---|
| 680 | $result['maillists_info'][$i]['uidnumber'] = $entries[$i]['uidnumber'][0]; |
---|
| 681 | $result['maillists_info'][$i]['uid'] = $entries[$i]['uid'][0]; |
---|
| 682 | $result['maillists_info'][$i]['mail'] = $entries[$i]['mail'][0]; |
---|
| 683 | $result['maillists'][] = $entries[$i]['uidnumber'][0]; |
---|
| 684 | } |
---|
| 685 | |
---|
[9] | 686 | // Groups |
---|
| 687 | $justthese = array("gidnumber","cn"); |
---|
| 688 | $filter="(&(phpgwAccountType=g)(memberuid=".$result['uid']."))"; |
---|
[16] | 689 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
[9] | 690 | ldap_sort($this->ldap, $search, "cn"); |
---|
| 691 | $entries = ldap_get_entries($this->ldap, $search); |
---|
| 692 | for ($i=0; $i<$entries['count']; $i++) |
---|
| 693 | { |
---|
| 694 | $result['groups_ldap'][ $entries[$i]['gidnumber'][0] ] = $entries[$i]['cn'][0]; |
---|
| 695 | } |
---|
| 696 | |
---|
[2] | 697 | return $result; |
---|
| 698 | } |
---|
| 699 | |
---|
| 700 | function get_group_info($gidnumber, $context) |
---|
| 701 | { |
---|
| 702 | $filter="(&(phpgwAccountType=g)(gidNumber=".$gidnumber."))"; |
---|
| 703 | $search = ldap_search($this->ldap, $context, $filter); |
---|
| 704 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 705 | |
---|
| 706 | //Pega o dn do setor do grupo. |
---|
| 707 | $entry[0]['dn'] = strtolower($entry[0]['dn']); |
---|
| 708 | $sector_dn_array = explode(",", $entry[0]['dn']); |
---|
| 709 | for($i=1; $i<count($sector_dn_array); $i++) |
---|
| 710 | $sector_dn .= $sector_dn_array[$i] . ','; |
---|
| 711 | //Retira ultimo pipe. |
---|
| 712 | $sector_dn = substr($sector_dn,0,(strlen($sector_dn) - 1)); |
---|
| 713 | |
---|
| 714 | $result['context'] = $sector_dn; |
---|
| 715 | $result['cn'] = $entry[0]['cn'][0]; |
---|
| 716 | $result['description'] = $entry[0]['description'][0]; |
---|
| 717 | $result['gidnumber'] = $entry[0]['gidnumber'][0]; |
---|
[23] | 718 | $result['phpgwaccountvisible'] = $entry[0]['phpgwaccountvisible'][0]; |
---|
[46] | 719 | $result['email'] = $entry[0]['mail'][0]; |
---|
[2] | 720 | |
---|
| 721 | //MemberUid |
---|
| 722 | for ($i=0; $i<$entry[0]['memberuid']['count']; $i++) |
---|
| 723 | { |
---|
| 724 | $justthese = array("cn","uid","uidnumber"); |
---|
[24] | 725 | |
---|
| 726 | // Montagem dinamica do filtro |
---|
| 727 | $filter="(&(phpgwAccountType=u)(|"; |
---|
| 728 | for ($k=0; (($k<10) && ($i<$entry[0]['memberuid']['count'])); $k++) |
---|
| 729 | { |
---|
| 730 | $filter .= "(uid=".$entry[0]['memberuid'][$i].")"; |
---|
| 731 | $i++; |
---|
| 732 | } |
---|
| 733 | $i--; |
---|
| 734 | $filter .= "))"; |
---|
| 735 | |
---|
[2] | 736 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 737 | $user_entry = ldap_get_entries($this->ldap, $search); |
---|
| 738 | |
---|
[24] | 739 | for ($j=0; $j<$user_entry['count']; $j++) |
---|
[2] | 740 | { |
---|
[24] | 741 | $result['memberuid_info'][$user_entry[$j]['uid'][0]]['cn'] = $user_entry[$j]['cn'][0]; |
---|
| 742 | $result['memberuid_info'][$user_entry[$j]['uid'][0]]['uidnumber'] = $user_entry[$j]['uidnumber'][0]; |
---|
| 743 | $result['memberuid_info'][$user_entry[$j]['uid'][0]]['type'] = 'u'; |
---|
[2] | 744 | } |
---|
| 745 | } |
---|
| 746 | |
---|
[24] | 747 | // Retira o count do array |
---|
| 748 | array_shift($entry[0]['memberuid']); |
---|
| 749 | |
---|
| 750 | // Checamos e-mails que não fazem parte do expresso. |
---|
| 751 | // Criamos um array temporario |
---|
| 752 | $tmp_array = array(); |
---|
| 753 | foreach ($result['memberuid_info'] as $uid => $user_data) |
---|
| 754 | { |
---|
| 755 | $tmp_array[] = $uid; |
---|
| 756 | } |
---|
| 757 | |
---|
| 758 | // Vemos a diferença |
---|
| 759 | $array_diff = array_diff($entry[0]['memberuid'], $tmp_array); |
---|
| 760 | |
---|
| 761 | // Incluimos no resultado |
---|
| 762 | foreach ($array_diff as $index=>$uid) |
---|
| 763 | { |
---|
| 764 | $result['memberuid_info'][$uid]['cn'] = $uid; |
---|
| 765 | } |
---|
| 766 | |
---|
[2] | 767 | // Samba |
---|
| 768 | for ($i=0; $i<$entry[0]['objectclass']['count']; $i++) |
---|
| 769 | { |
---|
| 770 | if ($entry[0]['objectclass'][$i] == 'sambaGroupMapping') |
---|
| 771 | $result['sambaGroup'] = true; |
---|
[33] | 772 | |
---|
| 773 | $a_tmp = explode("-", $entry[0]['sambasid'][0]); |
---|
| 774 | array_pop($a_tmp); |
---|
| 775 | $result['sambasid'] = implode("-", $a_tmp); |
---|
[2] | 776 | } |
---|
[24] | 777 | |
---|
[2] | 778 | return $result; |
---|
| 779 | } |
---|
| 780 | |
---|
| 781 | function get_maillist_info($uidnumber, $context) |
---|
| 782 | { |
---|
| 783 | $filter="(&(phpgwAccountType=l)(uidNumber=".$uidnumber."))"; |
---|
| 784 | $search = ldap_search($this->ldap, $context, $filter); |
---|
| 785 | $entry = ldap_get_entries($this->ldap, $search); |
---|
[24] | 786 | |
---|
[2] | 787 | //Pega o dn do setor do usuario. |
---|
| 788 | $entry[0]['dn'] = strtolower($entry[0]['dn']); |
---|
| 789 | $sector_dn_array = explode(",", $entry[0]['dn']); |
---|
| 790 | for($i=1; $i<count($sector_dn_array); $i++) |
---|
| 791 | $sector_dn .= $sector_dn_array[$i] . ','; |
---|
| 792 | //Retira ultimo pipe. |
---|
| 793 | $sector_dn = substr($sector_dn,0,(strlen($sector_dn) - 1)); |
---|
[24] | 794 | |
---|
[2] | 795 | $result['context'] = $sector_dn; |
---|
| 796 | $result['uidnumber'] = $entry[0]['uidnumber'][0]; |
---|
| 797 | $result['uid'] = $entry[0]['uid'][0]; |
---|
| 798 | $result['cn'] = $entry[0]['cn'][0]; |
---|
| 799 | $result['mail'] = $entry[0]['mail'][0]; |
---|
| 800 | $result['accountStatus'] = $entry[0]['accountstatus'][0]; |
---|
| 801 | $result['phpgwAccountVisible'] = $entry[0]['phpgwaccountvisible'][0]; |
---|
[24] | 802 | |
---|
[2] | 803 | //Members |
---|
| 804 | for ($i=0; $i<$entry[0]['mailforwardingaddress']['count']; $i++) |
---|
| 805 | { |
---|
[24] | 806 | $justthese = array("cn", "uidnumber", "uid", "phpgwaccounttype", "mail"); |
---|
| 807 | |
---|
| 808 | // Montagem dinamica do filtro |
---|
| 809 | $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=l))(|"; |
---|
| 810 | for ($k=0; (($k<10) && ($i<$entry[0]['mailforwardingaddress']['count'])); $k++) |
---|
| 811 | { |
---|
| 812 | $filter .= "(mail=".$entry[0]['mailforwardingaddress'][$i].")"; |
---|
| 813 | $i++; |
---|
| 814 | } |
---|
| 815 | $i--; |
---|
| 816 | $filter .= "))"; |
---|
| 817 | |
---|
[2] | 818 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 819 | $user_entry = ldap_get_entries($this->ldap, $search); |
---|
[24] | 820 | |
---|
| 821 | for ($j=0; $j<$user_entry['count']; $j++) |
---|
[2] | 822 | { |
---|
[24] | 823 | $result['members_info'][$user_entry[$j]['uidnumber'][0]]['uid'] = $user_entry[$j]['uid'][0]; |
---|
| 824 | $result['members_info'][$user_entry[$j]['uidnumber'][0]]['cn'] = $user_entry[$j]['cn'][0]; |
---|
| 825 | $result['members_info'][$user_entry[$j]['uidnumber'][0]]['type'] = $user_entry[$j]['phpgwaccounttype'][0]; |
---|
| 826 | $result['members_info'][$user_entry[$j]['uidnumber'][0]]['mail'] = $user_entry[$j]['mail'][0]; |
---|
| 827 | $result['members'][] = $user_entry[$j]['uidnumber'][0]; |
---|
[2] | 828 | } |
---|
| 829 | } |
---|
[24] | 830 | |
---|
| 831 | // Retira o count do array |
---|
| 832 | array_shift($entry[0]['mailforwardingaddress']); |
---|
| 833 | |
---|
| 834 | // Checamos e-mails que não fazem parte do expresso. |
---|
| 835 | // Criamos um array temporario |
---|
| 836 | $tmp_array = array(); |
---|
| 837 | foreach ($result['members_info'] as $uid => $user_data) |
---|
| 838 | { |
---|
| 839 | $tmp_array[] = $user_data['mail']; |
---|
| 840 | } |
---|
| 841 | |
---|
| 842 | // Vemos a diferença |
---|
| 843 | $array_diff = array_diff($entry[0]['mailforwardingaddress'], $tmp_array); |
---|
| 844 | |
---|
| 845 | // Incluimos no resultado |
---|
| 846 | foreach ($array_diff as $index=>$mailforwardingaddress) |
---|
| 847 | { |
---|
| 848 | $result['members_info'][$mailforwardingaddress]['uid'] = $mailforwardingaddress; |
---|
| 849 | $result['members_info'][$mailforwardingaddress]['cn'] = 'E-Mail nao encontrado'; |
---|
| 850 | $result['members_info'][$mailforwardingaddress]['mailforwardingaddress'] = $mailforwardingaddress; |
---|
| 851 | $result['members'][] = $mailforwardingaddress; |
---|
| 852 | } |
---|
| 853 | return $result; |
---|
[2] | 854 | } |
---|
| 855 | |
---|
[23] | 856 | function get_maillist_scl_info($uidnumber, $context) |
---|
| 857 | { |
---|
| 858 | $filter="(&(phpgwAccountType=l)(uidNumber=".$uidnumber."))"; |
---|
| 859 | $search = ldap_search($this->ldap, $context, $filter); |
---|
| 860 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 861 | |
---|
| 862 | //Pega o dn do setor do usuario. |
---|
| 863 | $entry[0]['dn'] = strtolower($entry[0]['dn']); |
---|
| 864 | $sector_dn_array = explode(",", $entry[0]['dn']); |
---|
| 865 | for($i=1; $i<count($sector_dn_array); $i++) |
---|
| 866 | $sector_dn .= $sector_dn_array[$i] . ','; |
---|
| 867 | //Retira ultimo pipe. |
---|
| 868 | $sector_dn = substr($sector_dn,0,(strlen($sector_dn) - 1)); |
---|
| 869 | |
---|
| 870 | $result['dn'] = $entry[0]['dn']; |
---|
| 871 | $result['context'] = $sector_dn; |
---|
| 872 | $result['uidnumber'] = $entry[0]['uidnumber'][0]; |
---|
| 873 | $result['uid'] = $entry[0]['uid'][0]; |
---|
| 874 | $result['cn'] = $entry[0]['cn'][0]; |
---|
| 875 | $result['mail'] = $entry[0]['mail'][0]; |
---|
| 876 | $result['accountStatus'] = $entry[0]['accountstatus'][0]; |
---|
| 877 | $result['phpgwAccountVisible'] = $entry[0]['phpgwaccountvisible'][0]; |
---|
| 878 | $result['accountRestrictive'] = $entry[0]['accountrestrictive'][0]; |
---|
| 879 | $result['participantCanSendMail'] = $entry[0]['participantcansendmail'][0]; |
---|
| 880 | |
---|
| 881 | //Senders |
---|
| 882 | for ($i=0; $i<$entry[0]['mailsenderaddress']['count']; $i++) |
---|
| 883 | { |
---|
| 884 | $justthese = array("cn", "uidnumber", "uid", "mail"); |
---|
| 885 | $filter="(&(phpgwAccountType=u)(mail=".$entry[0]['mailsenderaddress'][$i]."))"; |
---|
| 886 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 887 | $user_entry = ldap_get_entries($this->ldap, $search); |
---|
| 888 | |
---|
| 889 | $result['senders_info'][$user_entry[0]['uidnumber'][0]]['uid'] = $user_entry[0]['uid'][0]; |
---|
| 890 | $result['senders_info'][$user_entry[0]['uidnumber'][0]]['cn'] = $user_entry[0]['cn'][0]; |
---|
| 891 | $result['senders_info'][$user_entry[0]['uidnumber'][0]]['mail'] = $user_entry[0]['mail'][0]; |
---|
| 892 | $result['members'][] = $user_entry[0]['uidnumber'][0]; |
---|
| 893 | } |
---|
| 894 | |
---|
| 895 | return $result; |
---|
| 896 | } |
---|
| 897 | |
---|
[11] | 898 | function group_exist($gidnumber) |
---|
| 899 | { |
---|
| 900 | $justthese = array("cn"); |
---|
| 901 | $filter="(&(phpgwAccountType=g)(gidNumber=".$gidnumber."))"; |
---|
| 902 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 903 | |
---|
| 904 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 905 | if ($entry['count'] == 0) |
---|
| 906 | return false; |
---|
| 907 | else |
---|
| 908 | return true; |
---|
| 909 | } |
---|
| 910 | |
---|
[2] | 911 | function gidnumbers2cn($gidnumbers, $context) |
---|
| 912 | { |
---|
[32] | 913 | $result = array(); |
---|
[2] | 914 | if (count($gidnumbers)) |
---|
| 915 | { |
---|
| 916 | $justthese = array("cn"); |
---|
| 917 | $i = 0; |
---|
| 918 | foreach ($gidnumbers as $gidnumber) |
---|
| 919 | { |
---|
| 920 | $filter="(&(phpgwAccountType=g)(gidNumber=".$gidnumber."))"; |
---|
| 921 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 922 | |
---|
| 923 | $entry = ldap_get_entries($this->ldap, $search); |
---|
[11] | 924 | if ($entry['count'] == 0) |
---|
| 925 | $result['groups_info'][$i]['cn'] = '_Grupo existe no BD mas não no LDAP'; |
---|
| 926 | else |
---|
| 927 | $result['groups_info'][$i]['cn'] = $entry[0]['cn'][0]; |
---|
[2] | 928 | $result['groups_info'][$i]['gidnumber'] = $gidnumber; |
---|
| 929 | |
---|
| 930 | if (!strpos(strtolower($entry[0]['dn']), strtolower($context))) |
---|
| 931 | $result['groups_info'][$i]['group_disabled'] = 'true'; |
---|
| 932 | else |
---|
| 933 | $result['groups_info'][$i]['group_disabled'] = 'false'; |
---|
| 934 | |
---|
| 935 | $i++; |
---|
| 936 | } |
---|
| 937 | } |
---|
| 938 | return $result; |
---|
| 939 | } |
---|
| 940 | |
---|
| 941 | function uidnumber2uid($uidnumber) |
---|
| 942 | { |
---|
| 943 | $justthese = array("uid"); |
---|
| 944 | $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=l))(uidNumber=".$uidnumber."))"; |
---|
| 945 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 946 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 947 | return $entry[0]['uid'][0]; |
---|
| 948 | } |
---|
| 949 | |
---|
| 950 | function uidnumber2mail($uidnumber) |
---|
| 951 | { |
---|
| 952 | $justthese = array("mail"); |
---|
| 953 | $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=l))(uidNumber=".$uidnumber."))"; |
---|
| 954 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 955 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 956 | return $entry[0]['mail'][0]; |
---|
| 957 | } |
---|
| 958 | |
---|
| 959 | |
---|
| 960 | function change_user_context($dn, $newrdn, $newparent) |
---|
| 961 | { |
---|
| 962 | if (!ldap_rename ( $this->ldap, $dn, $newrdn, $newparent, true )) |
---|
| 963 | { |
---|
| 964 | $return['status'] = false; |
---|
| 965 | $return['msg'] = 'Erro em ldap_funcitons->change_user_context: ' . ldap_error($this->ldap); |
---|
| 966 | } |
---|
| 967 | else |
---|
| 968 | $return['status'] = true; |
---|
| 969 | |
---|
| 970 | return $return; |
---|
| 971 | } |
---|
| 972 | |
---|
| 973 | function replace_user_attributes($dn, $ldap_mod_replace) |
---|
| 974 | { |
---|
| 975 | if (!@ldap_mod_replace ( $this->ldap, $dn, $ldap_mod_replace )) |
---|
| 976 | { |
---|
| 977 | $return['status'] = false; |
---|
| 978 | $return['msg'] = 'Erro em ldap_funcitons->replace_user_attributes: ' . ldap_error($this->ldap); |
---|
| 979 | } |
---|
| 980 | else |
---|
| 981 | $return['status'] = true; |
---|
| 982 | |
---|
| 983 | return $return; |
---|
| 984 | } |
---|
| 985 | |
---|
| 986 | function add_user_attributes($dn, $ldap_add) |
---|
| 987 | { |
---|
| 988 | if (!@ldap_mod_add ( $this->ldap, $dn, $ldap_add )) |
---|
| 989 | { |
---|
| 990 | $return['status'] = false; |
---|
| 991 | $return['msg'] = 'Erro em ldap_funcitons->add_user_attributes: ' . ldap_error($this->ldap); |
---|
| 992 | } |
---|
| 993 | else |
---|
| 994 | $return['status'] = true; |
---|
| 995 | |
---|
| 996 | return $return; |
---|
| 997 | } |
---|
| 998 | |
---|
| 999 | function remove_user_attributes($dn, $ldap_remove) |
---|
| 1000 | { |
---|
| 1001 | if (!@ldap_mod_del ( $this->ldap, $dn, $ldap_remove )) |
---|
| 1002 | { |
---|
| 1003 | $return['status'] = false; |
---|
| 1004 | $return['msg'] = 'Erro em ldap_funcitons->remove_user_attributes: ' . ldap_error($this->ldap); |
---|
| 1005 | } |
---|
| 1006 | else |
---|
| 1007 | $return['status'] = true; |
---|
| 1008 | |
---|
| 1009 | return $return; |
---|
| 1010 | } |
---|
| 1011 | |
---|
| 1012 | function set_user_password($uid, $password) |
---|
| 1013 | { |
---|
| 1014 | $justthese = array("userPassword"); |
---|
| 1015 | $filter="(&(phpgwAccountType=u)(uid=".$uid."))"; |
---|
| 1016 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1017 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 1018 | $dn = $entry[0]['dn']; |
---|
| 1019 | $userPassword = $entry[0]['userpassword'][0]; |
---|
| 1020 | $ldap_mod_replace['userPassword'] = $password; |
---|
| 1021 | $this->replace_user_attributes($dn, $ldap_mod_replace); |
---|
| 1022 | return $userPassword; |
---|
| 1023 | } |
---|
| 1024 | |
---|
| 1025 | function delete_user($user_info) |
---|
| 1026 | { |
---|
| 1027 | $return['status'] = true; |
---|
| 1028 | |
---|
| 1029 | // GROUPS |
---|
| 1030 | $attrs = array(); |
---|
| 1031 | $attrs['memberUid'] = $user_info['uid']; |
---|
| 1032 | if (count($user_info['groups_info'])) |
---|
| 1033 | { |
---|
| 1034 | foreach ($user_info['groups_info'] as $group_info) |
---|
| 1035 | { |
---|
| 1036 | $gidnumber = $group_info['gidnumber']; |
---|
| 1037 | $justthese = array("dn"); |
---|
| 1038 | $filter="(&(phpgwAccountType=g)(gidnumber=".$gidnumber."))"; |
---|
| 1039 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1040 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 1041 | $dn = $entry[0]['dn']; |
---|
| 1042 | |
---|
| 1043 | if (!@ldap_mod_del($this->ldap, $dn, $attrs)) |
---|
| 1044 | { |
---|
| 1045 | $return['status'] = false; |
---|
| 1046 | $return['msg'] .= 'Erro em ldap_funcitons->delete_user, grupos: ' . ldap_error($this->ldap); |
---|
| 1047 | } |
---|
| 1048 | } |
---|
| 1049 | } |
---|
| 1050 | |
---|
| 1051 | // MAILLISTS |
---|
| 1052 | $attrs = array(); |
---|
| 1053 | $attrs['mailForwardingAddress'] = $user_info['mail']; |
---|
| 1054 | if (count($user_info['maillists_info'])) |
---|
| 1055 | { |
---|
| 1056 | foreach ($user_info['maillists_info'] as $maillists_info) |
---|
| 1057 | { |
---|
| 1058 | $uidnumber = $maillists_info['uidnumber']; |
---|
| 1059 | $justthese = array("dn"); |
---|
| 1060 | $filter="(&(phpgwAccountType=l)(uidnumber=".$uidnumber."))"; |
---|
| 1061 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1062 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 1063 | $dn = $entry[0]['dn']; |
---|
| 1064 | |
---|
| 1065 | if (!@ldap_mod_del($this->ldap, $dn, $attrs)) |
---|
| 1066 | { |
---|
| 1067 | $return['status'] = false; |
---|
| 1068 | $return['msg'] .= 'Erro em ldap_funcitons->delete_user, listas de email: ' . ldap_error($this->ldap); |
---|
| 1069 | } |
---|
| 1070 | } |
---|
| 1071 | } |
---|
| 1072 | |
---|
| 1073 | // UID |
---|
| 1074 | $dn = "uid=" . $user_info['uid'] . "," . $user_info['context']; |
---|
| 1075 | if (!@ldap_delete($this->ldap, $dn)) |
---|
| 1076 | { |
---|
| 1077 | $return['status'] = false; |
---|
| 1078 | $return['msg'] .= 'Erro em ldap_funcitons->delete_user, listas de email: ' . ldap_error($this->ldap); |
---|
| 1079 | } |
---|
| 1080 | |
---|
| 1081 | return $return; |
---|
| 1082 | } |
---|
| 1083 | |
---|
| 1084 | function delete_maillist($uidnumber) |
---|
| 1085 | { |
---|
| 1086 | $return['status'] = true; |
---|
| 1087 | |
---|
| 1088 | $justthese = array("dn"); |
---|
| 1089 | $filter="(&(phpgwAccountType=l)(uidnumber=".$uidnumber."))"; |
---|
| 1090 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1091 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 1092 | $dn = $entry[0]['dn']; |
---|
| 1093 | |
---|
| 1094 | if (!@ldap_delete($this->ldap, $dn)) |
---|
| 1095 | { |
---|
| 1096 | $return['status'] = false; |
---|
| 1097 | $return['msg'] .= 'Erro em ldap_funcitons->delete_maillist, listas de email: ' . ldap_error($this->ldap); |
---|
| 1098 | } |
---|
| 1099 | |
---|
| 1100 | return $return; |
---|
| 1101 | } |
---|
| 1102 | |
---|
| 1103 | function delete_group($gidnumber) |
---|
| 1104 | { |
---|
| 1105 | $return['status'] = true; |
---|
| 1106 | |
---|
| 1107 | $justthese = array("dn"); |
---|
| 1108 | $filter="(&(phpgwAccountType=g)(gidnumber=".$gidnumber."))"; |
---|
| 1109 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1110 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 1111 | $dn = $entry[0]['dn']; |
---|
| 1112 | |
---|
| 1113 | if (!@ldap_delete($this->ldap, $dn)) |
---|
| 1114 | { |
---|
| 1115 | $return['status'] = false; |
---|
| 1116 | $return['msg'] .= 'Erro em ldap_funcitons->delete_maillist, listas de email: ' . ldap_error($this->ldap); |
---|
| 1117 | } |
---|
| 1118 | |
---|
| 1119 | return $return; |
---|
| 1120 | } |
---|
| 1121 | |
---|
| 1122 | |
---|
| 1123 | function rename_uid($uid, $new_uid) |
---|
| 1124 | { |
---|
| 1125 | $return['status'] = true; |
---|
| 1126 | |
---|
| 1127 | $justthese = array("dn"); |
---|
| 1128 | $filter="(&(phpgwAccountType=u)(uid=".$uid."))"; |
---|
| 1129 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1130 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 1131 | $dn = $entry[0]['dn']; |
---|
| 1132 | |
---|
| 1133 | $explode_dn = ldap_explode_dn($dn, 0); |
---|
| 1134 | $rdn = "uid=" . $new_uid; |
---|
| 1135 | |
---|
| 1136 | $parent = array(); |
---|
| 1137 | for ($j=1; $j<(count($explode_dn)-1); $j++) |
---|
| 1138 | $parent[] = $explode_dn[$j]; |
---|
| 1139 | $parent = implode(",", $parent); |
---|
| 1140 | |
---|
| 1141 | $return['new_dn'] = $rdn . ',' . $parent; |
---|
| 1142 | |
---|
| 1143 | if (!@ldap_rename($this->ldap, $dn, $rdn, $parent, false)) |
---|
| 1144 | { |
---|
| 1145 | $return['status'] = false; |
---|
| 1146 | $return['msg'] .= 'Erro em ldap_funcitons->rename_uid: ' . ldap_error($this->ldap); |
---|
| 1147 | } |
---|
| 1148 | |
---|
| 1149 | //Grupos |
---|
| 1150 | $justthese = array("dn"); |
---|
| 1151 | $filter="(&(phpgwAccountType=g)(memberuid=".$uid."))"; |
---|
| 1152 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1153 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 1154 | $array_mod_add['memberUid'] = $new_uid; |
---|
| 1155 | $array_mod_del['memberUid'] = $uid; |
---|
| 1156 | |
---|
| 1157 | for ($i=0; $i<=$entry['count']; $i++) |
---|
| 1158 | { |
---|
| 1159 | $dn = $entry[$i]['dn']; |
---|
| 1160 | @ldap_mod_add ( $this->ldap, $dn, $array_mod_add); |
---|
| 1161 | @ldap_mod_del ( $this->ldap, $dn, $array_mod_del); |
---|
| 1162 | } |
---|
| 1163 | return $return; |
---|
| 1164 | } |
---|
| 1165 | |
---|
| 1166 | function rename_cn($cn, $new_cn) |
---|
| 1167 | { |
---|
| 1168 | $return['status'] = true; |
---|
| 1169 | |
---|
| 1170 | $justthese = array("dn"); |
---|
| 1171 | $filter="(&(phpgwAccountType=g)(uid=".$cn."))"; |
---|
| 1172 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1173 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 1174 | $dn = $entry[0]['dn']; |
---|
| 1175 | |
---|
| 1176 | $explode_dn = ldap_explode_dn($dn, 0); |
---|
| 1177 | $rdn = "cn=" . $new_cn; |
---|
| 1178 | |
---|
| 1179 | $parent = array(); |
---|
| 1180 | for ($j=1; $j<(count($explode_dn)-1); $j++) |
---|
| 1181 | $parent[] = $explode_dn[$j]; |
---|
| 1182 | $parent = implode(",", $parent); |
---|
| 1183 | |
---|
| 1184 | $return['new_dn'] = $rdn . ',' . $parent; |
---|
| 1185 | |
---|
| 1186 | if (!@ldap_rename($this->ldap, $dn, $rdn, $parent, false)) |
---|
| 1187 | { |
---|
| 1188 | $return['status'] = false; |
---|
| 1189 | } |
---|
| 1190 | |
---|
| 1191 | return $return; |
---|
| 1192 | } |
---|
[33] | 1193 | /* |
---|
[2] | 1194 | function rename_departmentnumber($old_dp, $new_dp) |
---|
| 1195 | { |
---|
| 1196 | $return['status'] = true; |
---|
| 1197 | |
---|
| 1198 | $justthese = array("dn"); |
---|
| 1199 | $filter="(&(phpgwAccountType=u)(departmentnumber=".$old_dp."))"; |
---|
| 1200 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); |
---|
| 1201 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 1202 | |
---|
| 1203 | for ($i=0; $i<=$entry['count']; $i++) |
---|
| 1204 | { |
---|
| 1205 | $dn = strtolower($entry[$i]['dn']); |
---|
| 1206 | $ldap_mod_replace = array(); |
---|
| 1207 | $ldap_mod_replace['departmentnumber'] = $new_dp; |
---|
| 1208 | @ldap_mod_replace ( $this->ldap, $dn, $ldap_mod_replace); |
---|
[33] | 1209 | //if (!@ldap_mod_replace ( $this->ldap, $dn, $ldap_mod_replace)) |
---|
| 1210 | //{ |
---|
| 1211 | // $return['status'] = false; |
---|
| 1212 | // $return['msg'] .= 'Erro em ldap_funcitons->rename_departmentnumber: ' . ldap_error($this->ldap); |
---|
| 1213 | //} |
---|
[2] | 1214 | } |
---|
| 1215 | return $return; |
---|
| 1216 | } |
---|
[33] | 1217 | */ |
---|
| 1218 | /* |
---|
| 1219 | function get_sambadomains($context) |
---|
| 1220 | { |
---|
| 1221 | $return['status'] = true; |
---|
| 1222 | $return['sambaDomains'] = array(); |
---|
| 1223 | |
---|
| 1224 | $justthese = array("sambaSID","sambaDomainName"); |
---|
| 1225 | $filter="(objectClass=sambaDomain)"; |
---|
| 1226 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 1227 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 1228 | |
---|
| 1229 | for ($i=0; $i<$entry['count']; $i++) |
---|
| 1230 | { |
---|
| 1231 | $return['sambaDomains'][$i]['samba_domain_sid'] = $entry[$i]['sambasid'][0]; |
---|
| 1232 | $return['sambaDomains'][$i]['samba_domain_name'] = $entry[$i]['sambadomainname'][0]; |
---|
| 1233 | $return['sambaDomains'][$i]['samba_domain_dn'] = $entry[$i]['dn']; |
---|
| 1234 | } |
---|
| 1235 | |
---|
| 1236 | return $return; |
---|
| 1237 | } |
---|
| 1238 | */ |
---|
| 1239 | function exist_sambadomains($context, $sambaDomainName) |
---|
| 1240 | { |
---|
| 1241 | $justthese = array("dn"); |
---|
| 1242 | $filter="(&(objectClass=sambaDomain)(sambaDomainName=$sambaDomainName))"; |
---|
| 1243 | $search = ldap_search($this->ldap, $context, $filter, $justthese); |
---|
| 1244 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 1245 | |
---|
| 1246 | if ($entry['count']) |
---|
| 1247 | return true; |
---|
| 1248 | else |
---|
| 1249 | return false; |
---|
| 1250 | } |
---|
[27] | 1251 | |
---|
[33] | 1252 | // Primeiro nilvel de organização. |
---|
| 1253 | function exist_sambadomains_in_context($params) |
---|
| 1254 | { |
---|
| 1255 | $dn = $GLOBALS['phpgw_info']['server']['ldap_context']; |
---|
| 1256 | $array_dn = ldap_explode_dn ( $dn, 0 ); |
---|
| 1257 | |
---|
| 1258 | $context = $params['context']; |
---|
| 1259 | $array_context = ldap_explode_dn ( $context, 0 ); |
---|
| 1260 | |
---|
| 1261 | // Pego o setor no caso do contexto ser um sub-setor. |
---|
| 1262 | if (($array_dn['count']+1) < ($array_context['count'])) |
---|
| 1263 | { |
---|
| 1264 | // inverto o array_dn para poder retirar o count |
---|
| 1265 | $array_dn_reverse = array_reverse ( $array_dn, false ); |
---|
| 1266 | |
---|
| 1267 | //retiro o count |
---|
| 1268 | array_pop($array_dn_reverse); |
---|
| 1269 | |
---|
| 1270 | //incluo o setor no dn |
---|
| 1271 | array_push ( $array_dn_reverse, $array_context[ $array_context['count'] - 1 - $array_dn['count']]); |
---|
| 1272 | |
---|
| 1273 | // Volto a ordem natural |
---|
| 1274 | $array_dn = array_reverse ( $array_dn_reverse, false ); |
---|
| 1275 | |
---|
| 1276 | // Implodo |
---|
| 1277 | $context = implode ( ",", $array_dn ); |
---|
| 1278 | } |
---|
| 1279 | |
---|
| 1280 | $justthese = array("dn","sambaDomainName"); |
---|
| 1281 | $filter="(objectClass=sambaDomain)"; |
---|
| 1282 | $search = ldap_list($this->ldap, $context, $filter, $justthese); |
---|
| 1283 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 1284 | |
---|
| 1285 | for ($i=0; $i<$entry['count']; $i++) |
---|
| 1286 | { |
---|
| 1287 | $return['sambaDomains'][$i] = $entry[$i]['sambadomainname'][0]; |
---|
| 1288 | } |
---|
| 1289 | |
---|
| 1290 | if ($entry['count']) |
---|
| 1291 | $return['status'] = true; |
---|
| 1292 | else |
---|
| 1293 | $return['status'] = false; |
---|
| 1294 | |
---|
| 1295 | return $return; |
---|
| 1296 | } |
---|
| 1297 | |
---|
[27] | 1298 | function add_sambadomain($sambadomainname, $sambasid, $context) |
---|
| 1299 | { |
---|
| 1300 | $result = array(); |
---|
| 1301 | |
---|
| 1302 | $dn = "sambaDomainName=$sambadomainname,$context"; |
---|
| 1303 | $entry['sambaSID'] = $sambasid; |
---|
| 1304 | $entry['objectClass'] = 'sambaDomain'; |
---|
| 1305 | $entry['sambaAlgorithmicRidBase'] = '1000'; |
---|
| 1306 | $entry['sambaDomainName'] = $sambadomainname; |
---|
| 1307 | |
---|
| 1308 | if (!@ldap_add ( $this->ldap, $dn, $entry )) |
---|
| 1309 | { |
---|
| 1310 | $return['status'] = false; |
---|
| 1311 | $return['msg'] = "Erro na funcao ldap_functions->add_sambadomain ($dn).\nRetorno do servidor: " . ldap_error($this->ldap); |
---|
| 1312 | } |
---|
| 1313 | else |
---|
| 1314 | $return['status'] = true; |
---|
| 1315 | |
---|
| 1316 | return $return; |
---|
| 1317 | } |
---|
| 1318 | |
---|
| 1319 | function delete_sambadomain($sambadomainname) |
---|
| 1320 | { |
---|
| 1321 | $return['status'] = true; |
---|
| 1322 | $filter="(sambaDomainName=$sambadomainname)"; |
---|
| 1323 | $search = ldap_search($this->ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter); |
---|
| 1324 | $entry = ldap_get_entries($this->ldap, $search); |
---|
| 1325 | |
---|
| 1326 | if ($entry['count'] != 0) |
---|
| 1327 | { |
---|
| 1328 | $dn = $entry[0]['dn']; |
---|
| 1329 | |
---|
| 1330 | if (!@ldap_delete($this->ldap, $dn)) |
---|
| 1331 | { |
---|
| 1332 | $return['status'] = false; |
---|
| 1333 | $return['msg'] .= "Erro em ldap_funcitons->delete_sambadomain ($sambadomainname).\nRetorno do servidor: " . ldap_error($this->ldap); |
---|
| 1334 | } |
---|
| 1335 | } |
---|
| 1336 | |
---|
| 1337 | return $return; |
---|
| 1338 | } |
---|
[2] | 1339 | } |
---|
| 1340 | ?> |
---|