Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.25 KB | None | 0 0
  1. <?php
  2. header("Content-type: text/plain");
  3. header("Content-Disposition: attachment; filename=seznam_mailboxu.csv");
  4.  
  5. $ldap_server = 'ldap://pdcsrvdnc01.xxxx.cz';
  6. $auth_user = 'ldap';
  7. $auth_pass = 'xxxx';
  8. $base_dn = "OU=Uživatelé,DC=xxxx,DC=cz";
  9. $filter = "(&(objectClass=user)(kerio-Mail-AccountEnabled=1))";
  10.  
  11. if (!($connect = ldap_connect ($ldap_server))) {
  12.     die("Could not connect to ldap server");
  13. }
  14.  
  15. if (!($bind = ldap_bind ($connect, $auth_user . '@xxxx.cz', $auth_pass))) {
  16.     die('Unable to bind to server.');
  17. }
  18.  
  19. if (!($search = ldap_search ($connect, $base_dn, $filter))) {
  20.     die("Unable to search ldap server");
  21. }
  22.  
  23. $number_returned = ldap_count_entries ($connect, $search);
  24. $info = ldap_get_entries ($connect, $search);
  25.  
  26. for ($i=0; $i<$number_returned; $i++) {
  27.     $name = strtr(strtr($info[$i]['cn'][0], ' ', '-'), 'áäčďéěëíµňôóöŕřšťúůüýžÁÄČĎÉĚËÍĄŇÓÖÔŘŔŠŤÚŮÜÝŽ', 'aacdeeeilnooorrstuuuyzaacdeeelinooorrstuuuyz');
  28.     $n .= $info[$i]['cn'][0]. ';';
  29.     for ($j=0; $j<count($info[$i]['member']); $j++) {
  30.         $arr = explode(',', $info[$i]['member'][$j]);
  31.         $n .=  substr($arr[0], 3);
  32.     }
  33.     $n .= $info[$i]['l'][0]. ';';
  34.     $n .= $info[$i]['samaccountname'][0]. '@xxxx.cz;';
  35.     // zalomit radek
  36.  
  37. }
  38.  
  39. echo $n;
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement