<?php
 
//---[ Author: Michele Brodoloni - [email protected]
 
//---[ Deletes all the content of the addressbook
 
//---[ This script is for php-cli. Use it with php -q <script_name>
 
 
    require("ldap_addressbook.class.php");
 
 
    $SUCCESS=0;
 
    $FAILURE=0;
 
    $ldap = new LDAP_addressBook("my.ldap.host","cn=admin","dc=example, dc=com","my_ldap_secret");
 
 
    if ($ldap->connect())
 
    {
 
        $list = $ldap->list_entries("dn");
 
        $n = count($list);
 
        echo("\n");
 
        for ($i=0; $i<$n; $i++)
 
        {
 
            $dn_to_delete = $list[$i]['dn'];
 
            echo "** deleting '$dn_to_delete' ... ";
 
            if ($ldap->delete_entry_by_dn($dn_to_delete)) 
 
            {
 
                echo "done\n";
 
                $SUCCESS++;
 
            } else {
 
                echo "ERROR\n";
 
                $FAILURE++;
 
            }
 
        }
 
        echo "\n";
 
        echo "Total records: $n\n".
 
              "Deleted: $SUCCESS\n".
 
              "Errors: $FAILURE\n\n";    
 
    } else {
 
        echo $ldap->show_error()."\n";
 
    }
 
    $ldap->disconnect();
 
    exit;
 
 
?>
 
 
 |