6.0.0-git
2024-04-19
Last Modified 2009-08-04 by Guest

Removing User Data

Using the removeUserData APIs

From dom.lalot at gmail com

#!/usr/bin/env php
<?php
@define('AUTH_HANDLER', true);
@define('HORDE_BASE', dirname(__FILE__));
# require_once HORDE_BASE . '/lib/base.php';
// Do CLI checks and environment setup first.
require_once HORDE_BASE . '/lib/core.php';
require_once 'Horde/CLI.php';
// Make sure no one runs this from the web.
if (!Horde_CLI::runningFromCLI()) {
    exit("Must be run from the command line\n");
}
// Load the CLI environment - make sure there's no time limit, init some
// variables, etc.
$cli = &Horde_CLI::singleton();
$cli->init();
// Include needed libraries.
require_once HORDE_BASE . '/lib/base.php';
// Authenticate as administrator.
if (!count($conf['auth']['admins'])) {
    exit("You must have at least one administrator configured to run the alarms.php script.\n");
}
$auth = &Auth::singleton($conf['auth']['driver']);
$auth->setAuth($conf['auth']['admins'][0], array());
require_once HORDE_BASE . '/lib/Horde/Auth.php';
global $conf;
require_once 'DB.php';
$db = &DB::connect($conf['sql']);
if (is_a($db, 'PEAR_Error')) {
    Horde::fatal($db, __FILE__, __LINE__);
}
$validusers=$auth->listUsers();
$valides=count($validusers);
if ($valides==0){
   echo "Can't list users, your auth driver has no listusers capability\n";
   exit;
}
echo "$valides valid users found\n";
$valides=array();
foreach($validusers as $value){
   $valides[$value]=1;
}
// Looking at prefs to get most of old user data
$db->setOption('portability', DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_ERRORS);
$result = $db->query('SELECT pref_uid FROM horde_prefs WHERE 1');
if (is_a($result, 'PEAR_Error')) {
   $cli->message($result->toString(), 'cli.error');
   exit;
}

$uid = array();
while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
   $login=$row['pref_uid'];
    $uid[$login] = $login;
}
$total=count($uid);
echo "$total data user found\n";
echo "Exit without removing data, change the script please\n";
exit; # Drop this line if you want to remove data

//now compare valid and data found and purge
foreach ($uid as $value) {
   if (!array_key_exists($value,$valides)){
      echo "Not Found $value\n";
      Auth::removeUserData($value);
      $supp++;
   }
}
echo "suppressed $supp\n";
?>

A stand-alone script

From Bill Graham:
http://www2.hurleybulldogs.com/billsblog/?p=21

Stand-alone Perl scripts that remove user data from all Horde applications

By Didi Rieder <adrieder at sbox dot tugraz dot at>

The attached perl scripts help you to remove user data form all applications in your horde system.
One script does that by connecting to your mySQL database and the other uses XMLRPC to call a Horde API method.

The SQL solution will be much faster when one needs to bulk remove users and it does not need patching of the
non CVS horde API.

SQL driven

Required Perl modules:
DBI (download from CPAN)
DBD::mysql (download from CPAN)
HordeSQL.pm (attached)

Script file:
removeHordeUserSQL.pl (attached)

Usage:
Edit the script file and provide the connection parameters in the HordeSQL->new() method.
Then run the script as follows:
removeHordeUserSQL.pl <user|userfile> [realm]
the first argument is the user you want to remove, or a file that contains a list of users that should be removed (one user each line).
You can optionally provide a second argument which is interpreted as realm and gets added to each user that is to be removed.
>

XMLRPC & API driven

Required Perl modules:
SOAP::Lite (download from CPAN)
HordeXMLRPC.pm (attached)

Script file:
removeHordeUserXMLRPC.pl (attached)

Usage:
Edit the script file and provide the connection parameters in the HordeXMLRPC->new() method.
Then run the script as follows:
removeHordeUserXMLRPC.pl <user|userfile> [realm]
the first argument is the user you want to remove, or a file that contains a list of users that should be removed (one user each line).
You can optionally provide a second argument which is interpreted as realm and gets added to each user that is to be removed.

Note: At this time you need to patch the horde API in order to add the removeUserDataFromAllApplications() method which is used by the
perl script: Patch (The patch is not needed if you are running an up to date CVS version of Horde or a Horde version 3.3.5 or newer.)