Accéder au contenu.
Menu Sympa

fr - Re: [sympa-fr] supprimer un utilisateur

Objet : Pour les administrateurs de serveurs de listes utilisant le logiciel Sympa

Archives de la liste

Chronologique Discussions  
  • From: Foudil Bretel <adresse@cachée>
  • To: adresse@cachée
  • Subject: Re: [sympa-fr] supprimer un utilisateur
  • Date: Fri, 23 Aug 2002 17:34:30 +0200

Merci pour les réponses.
Pour ceux que ça interesse, j'ai bricolé un script pour supprimer
complètement
un utilisateur.
J'espère n'avoir rien oublié d'important.

Cordialement
Foudil
#!/usr/local/bin/perl

## FB020823
## script pour supprimer un utilisateur du service Sympa :
## - verification pas present dans fichiers de conf, c-a-d ni owner|moderateur
## - suppr de ses abonnements
## - suppr de son compte


use lib '/home/sympa/bin';

use DBI;
use Conf;

die "usage : del_user.pl <user\@host>" unless ($#ARGV == 0);

$user_login = lc($ARGV[0]);
chomp $user_login;

## Load sympa config
unless (&Conf::load('/etc/sympa/sympa.conf')) {
die 'config_error';
}

$expl_dir = $Conf{'home'};
$db_type = $Conf{'db_type'};
$db_name = $Conf{'db_name'};
$db_host = $Conf{'db_host'};
$db_user = $Conf{'db_user'};
$db_passwd = $Conf{'db_passwd'};

%date_func = ('Pg' => '\'epoch\'::datetime + \'%d sec\'',
'mysql' => 'FROM_UNIXTIME(%d)');


### verification pas present dans fichiers de conf, c-a-d ni owner|moderateur
unless (-d $expl_dir) {
die "expl dir not found : $expl_dir";
}

my @tmp_lists = `grep -i " $user_login" $expl_dir/*/config`;
foreach $j (@tmp_lists) {
$j =~ /([\w-\.]+)\/config:/;
$involved_lists[$i++] = $1;
}
if (@tmp_lists) {
print "$user_login is the modeartor|owner of the following list(s) :\n";
foreach $l (@involved_lists) { print "$l\n"; }
print "Please, remove moderator|owner first.\nUser not deleted.\n\n";
exit 1;
}

# warning
print "You are about to delete the account and the subscriptions of
$user_login.\nOk [o|N]? ";
my $rep = <STDIN>;
unless ($rep =~ /^(oui|o|yes|y)$/) { print "nothing done.\n"; exit; }


### suppr de ses abonnements


## Connect to Database
unless ($dbh = DBI->connect("DBI:$db_type:dbname=$db_name;host=$db_host",
$db_user, $db_passwd)) {
die "Can't connect to Database :", $DBI::errstr;
}
## prepare statment
my $sth = $dbh->prepare('SELECT * from subscriber_table where user_subscriber
= ?')
or die "Couldn't prepare statement: " .
$dbh->errstr;

my @data;
$sth->execute($user_login) # Execute the query
or die "Couldn't execute statement: " . $sth->errstr;

# Read the matching records and print them out
while (@data = $sth->fetchrow_array()) {
my $listname = $data[0];
print "found in $listname\n";
}

$sth->finish;

if ($sth->rows == 0) {
print "No subscriptions found for $user_login.\n";
} else {
my $rv = $dbh->do("DELETE from subscriber_table where user_subscriber =
'$user_login'")
or die "Can't execute $statement: $dbh->errstr";
print "Subscriptions deleted.\n";
}


### suppr de son compte

my $rv = $dbh->do("DELETE from user_table where email_user = '$user_login'")
or die "Can't execute $statement: $dbh->errstr";

if ($rv == 0) {
print "No account found for $user_login\n";
}
else {
print "User account deleted.\n";
}


## Disconnect
$dbh->disconnect;









Archives gérées par MHonArc 2.6.19+.

Haut de le page