head	1.9;
access;
symbols
	TIGRIS_1_1_0RC2:1.5.8.1
	TIGRIS_1_1_0RC1:1.5.8.1
	TIGRIS_1_1:1.5.8.1.0.2
	TIGRIS_1_0_8:1.5.8.1
	TIGRIS_1_0_8RC3:1.5.8.1
	TIGRIS_1_0_8RC2:1.5.8.1
	TIGRIS_1_0_8RC1:1.5.8.1
	TIGRIS_1_0_7:1.5.8.1
	TIGRIS_1_0_7RC3:1.5.8.1
	TIGRIS_1_0_7RC2:1.5.8.1
	TIGRIS_1_0_7RC1:1.5.8.1
	TIGRIS_1_0_6:1.5.8.1
	TIGRIS_1_0_6RC5:1.5.8.1
	TIGRIS_1_0_6RC4:1.5.8.1
	TIGRIS_1_0_6RC3:1.5.8.1
	TIGRIS_1_0_6RC2:1.5.8.1
	TIGRIS_1_0_6RC1:1.5.8.1
	TIGRIS_1_0_5:1.5
	TIGRIS_1_0_5RC6:1.5
	TIGRIS_1_0_5RC5:1.5
	TIGRIS_1_0_5RC4:1.5
	TIGRIS_1_0_5RC3:1.5
	TIGRIS_1_0_5RC2:1.5
	TIGRIS_1_0_5RC1:1.5
	TIGRIS_1_0_4:1.5
	TIGRIS_1_0_3:1.5
	TIGRIS_1_0_2:1.5
	TIGRIS_1_0_1:1.5
	TIGRIS_1_0:1.5.0.8
	TIGRIS_1_0_0:1.5
	TIGRIS_1_0_0_RC1:1.5.0.4
	dlr:1.1.1
	TIGRIS_0_9_2_4:1.5
	TIGRIS_0_9_2_3:1.5
	HELM_PEER_PORT_BRANCH:1.1.1.1
	TURBINE_PEER:1.5
	TIGRIS_0_9_2_1:1.5
	TIGRIS_0_9_2:1.5.0.2;
locks; strict;
comment	@# @;


1.9
date	2001.07.30.18.07.19;	author kmaples;	state dead;
branches;
next	1.8;

1.8
date	2001.05.31.00.21.37;	author kmaples;	state Exp;
branches;
next	1.7;

1.7
date	2001.04.18.02.02.58;	author kmaples;	state Exp;
branches;
next	1.6;

1.6
date	2001.04.17.04.44.54;	author kmaples;	state Exp;
branches;
next	1.5;

1.5
date	2001.01.17.00.52.40;	author kmaples;	state Exp;
branches
	1.5.8.1;
next	1.4;

1.4
date	2001.01.13.02.04.52;	author kmaples;	state Exp;
branches;
next	1.3;

1.3
date	2001.01.12.21.34.04;	author kmaples;	state Exp;
branches;
next	1.2;

1.2
date	2001.01.10.22.00.23;	author kmaples;	state Exp;
branches;
next	1.1;

1.1
date	2001.01.09.03.57.03;	author kmaples;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2001.02.21.00.36.20;	author dlr;	state Exp;
branches;
next	;

1.5.8.1
date	2001.05.31.01.29.28;	author kmaples;	state Exp;
branches;
next	;


desc
@@


1.9
log
@Issue number: 4544, 4242
Making the world a better place by removing the scripts the taskrunner
used to need to run to create IZ users.
@
text
@#!/usr/bin/perl

# ================================================================
# Copyright (c) 2000 Collab.Net.  All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# 
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 
# 3. The end-user documentation included with the redistribution, if
# any, must include the following acknowlegement: "This product includes
# software developed by Collab.Net (http://www.Collab.Net/)."
# Alternately, this acknowlegement may appear in the software itself, if
# and wherever such third-party acknowlegements normally appear.
# 
# 4. The hosted project names must not be used to endorse or promote
# products derived from this software without prior written
# permission. For written permission, please contact info@@collab.net.
# 
# 5. Products derived from this software may not use the "Tigris" name
# nor may "Tigris" appear in their names without prior written
# permission of Collab.Net.
# 
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# ====================================================================
# 
# This software consists of voluntary contributions made by many
# individuals on behalf of Collab.Net.
#

# 
# $Id: issuezilla-user-disableall,v 1.8 2001/05/31 00:21:37 kmaples Exp $
# --------------------
# 

# Flush buffer, just in case:
$| = 1;

use strict;
use DBI;

# For the sake of -T:
$ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin";

# Process arguments
my $dbname             = $ARGV[0] || '';
my $multiple_dbs       = $ARGV[1] || '';

# List of users:
my @@usernames;

# Vars to handle disabling - since we don't really delete the users,
# we disable them in two ways - through IZ (disabled text), and through
# helm (prefix) - the latter effectively moving the user aside.
my $disabled_text = 'This account has been disabled.';
my $disabled_pfx  = 'ex-';

# String for current sql statement
my $command;

# Placeholder vars for db work:
my ($select, $ret);

# NOTE - this script requires the info necessary to connect
# to the correct DB, e.g., username/password, DB name, etc.

my $dbuser          = $ENV{DATABASE_USER}     || '';
my $dbpass          = $ENV{DATABASE_PASSWORD} || '';

# The 'issues' mailing list is a special user - it doesn't really
# have an account in helm, so it would be inappropriate to 
# disable it: 
my $mail_pfx    = $ENV{MAIL_PREFIX} || '';
my $maillistusr = $mail_pfx . 'issues@@';

#print qq[matching string is '$maillistusr'];

# Grab just the filename portion of this script to use as a 
# log identifier:
my $script_name = $0;
$script_name =~ s/^.*\/([^\/]+)$/  $1/;

#---------------------------------------------------------------
# MAIN
#---------------------------------------------------------------

# Fail if we don't have what we need to talk to the database:
unless($dbname && $dbuser && $dbpass){
    print "$script_name: envrionmentals for DB access not set\n";
    exit(1);
}

# In single-db mode, users need to be administered through IZ's
# UI:
unless($multiple_dbs){
    print "$script_name: database mode SINGLE; no action\n";
    exit(0);
}  

## This to silence db errors:
my %atr = (
    PrintError => 0,
    RaiseError => 0,
);

my $dbc = join(':',"DBI:mysql:$dbname",$ENV{DATABASE_HOST},$ENV{DATABASE_PORT});
my $CONN = DBI->connect($dbc, $dbuser, $dbpass, \%atr);

# Check for a good connection:
unless( $CONN =~ m/HASH/){
    print "$script_name: no connection to database: $!\n";
    exit(1);
}

# Quote the constants:
$disabled_text = $CONN->quote( $disabled_text );

print "$script_name: disabling all accounts in $dbname\n";
    
$command = qq[
    UPDATE profiles SET
    login_name     = concat('$disabled_pfx', login_name),
    disabledtext   = $disabled_text
    WHERE
    login_name  NOT LIKE '$maillistusr%'
    AND
    login_name  NOT LIKE '$disabled_pfx%'
];

$select = $CONN->prepare($command);
$ret    = $select->execute;

unless($ret){
    print "$script_name: unable to perform update: $!\n";
    $CONN->disconnect;
    exit(1);
}

print "$script_name: accounts disabled\n";

# Clean up and leave quietly:
$select->finish();
$CONN->disconnect;

#---------------------------------------------------------------
# END MAIN
#---------------------------------------------------------------


@


1.8
log
@Issue number: 4242
Optimizing sql to reduce the number of db hits incurred when this script is
invoked.
@
text
@d50 1
a50 1
# $Id: issuezilla-user-disableall,v 1.7 2001/04/18 02:02:58 kmaples Exp $
@


1.7
log
@Undoing yesterday's commit - my hastiness to implement some sort of logging
level notion into these scripts caused me great pain.
@
text
@d50 1
a50 1
# $Id: issuezilla-user-disableall,v 1.5 2001/01/17 00:52:40 kmaples Exp $
a53 2
#TODO: if in single-db mode, prohibit this operation

a61 2
# Detaint the args by brute force:
@@ARGV = detaint_array(@@ARGV);
d133 5
a137 1
# Get the list of users to operate on:
d139 7
a145 1
    SELECT login_name FROM profiles
d151 4
a154 10
while(my (@@record) = $select->fetchrow_array){
    if( $record[0] =~ m/^$maillistusr/){
        print "$script_name: found '$maillistusr', skipping\n";    
        next;
    }
    if( $record[0] =~ m/^$disabled_pfx/){
        print "$script_name: found disabled acct. '$record[0]', skipping\n";        
        next;
    }
    push(@@usernames,$record[0]);
d157 1
a157 30
# Quote the constants:
$disabled_text = $CONN->quote( $disabled_text );

for(0 .. $#usernames){
    # Some email address for issuezilla:
    my $login_name          = $usernames[$_];
    my $disabled_login_name = $disabled_pfx . $login_name;

    # Do the sql quoting for the values we're gonna play with:
    $login_name          = $CONN->quote( $login_name );
    $disabled_login_name = $CONN->quote( $disabled_login_name );
    
    $command = qq[
        UPDATE profiles SET
        login_name     = $disabled_login_name,
        disabledtext   = $disabled_text
        WHERE
        login_name     = $login_name
    ];
    
    $select = $CONN->prepare($command);
    $ret    = $select->execute;
    
    unless($ret){
        print "$script_name: unable to perform update: $!\n";
        $CONN->disconnect;
        exit(1);
    }
    print "$script_name: disabled account $login_name\n";
}
a166 17

# A crude attempt to overcome data tainting in perl:
#-------------------
sub detaint_array {
#-------------------
    my @@unclean = @@_;
    my @@clean = ();

    foreach(@@unclean){
        # We don't really have rules for this, so at the moment
        # this acts as a passthrough:
        $_ =~ m/^(.*)$/;
        push(@@clean,$1);
    }

    return(@@clean);
}
@


1.6
log
@Scripts now use IN_PRODUCTION to determine logging level
@
text
@a54 4
my $scripts_dir = $ENV{'SANDBOX'} . '/helm/perl/scripts';

require "$scripts_dir/ParentChildArgumentBridge.pl"
    or die "Require failed: $!\n";
d98 1
a98 1
#print_log(1, qq[matching string is '$maillistusr']);
d111 1
a111 1
    print_log(1, "$script_name: envrionmentals for DB access not set\n");
d118 1
a118 1
    print_log(1, "$script_name: database mode SINGLE; no action\n");
d133 1
a133 1
    print_log(1, "$script_name: no connection to database: $!\n");
d147 1
a147 1
        print_log(1, "$script_name: found '$maillistusr', skipping\n");
d151 1
a151 1
        print_log(1, "$script_name: found disabled acct. '$record[0]', skipping\n");
d181 1
a181 1
        print_log(1, "$script_name: unable to perform update: $!\n");
d185 1
a185 1
    print_log(1, "$script_name: disabled account $login_name\n");
@


1.5
log
@Quieted no database warning
@
text
@d50 1
a50 1
# $Id: issuezilla-user-disableall,v 1.4 2001/01/13 02:04:52 kmaples Exp $
d55 4
d102 1
a102 1
#print qq[matching string is '$maillistusr'];
d115 1
a115 1
    print "$script_name: envrionmentals for DB access not set\n";
d122 1
a122 1
    print "$script_name: database mode SINGLE; no action\n";
d137 1
a137 1
    print "$script_name: no connection to database: $!\n";
d151 1
a151 1
        print "$script_name: found '$maillistusr', skipping\n";    
d155 1
a155 1
        print "$script_name: found disabled acct. '$record[0]', skipping\n";        
d185 1
a185 1
        print "$script_name: unable to perform update: $!\n";
d189 1
a189 1
    print "$script_name: disabled account $login_name\n";
@


1.5.8.1
log
@Issue number: 4242
Reviewed by:  stack@@collab.net
Porting to branch several changes to the scripts which manipulate iz
users to reduce the number of db hits per operation.
@
text
@d50 1
a50 1
# $Id: issuezilla-user-disableall,v 1.8 2001/05/31 00:21:37 kmaples Exp $
d54 2
d64 2
d137 1
a137 5
# Quote the constants:
$disabled_text = $CONN->quote( $disabled_text );

print "$script_name: disabling all accounts in $dbname\n";
    
d139 1
a139 7
    UPDATE profiles SET
    login_name     = concat('$disabled_pfx', login_name),
    disabledtext   = $disabled_text
    WHERE
    login_name  NOT LIKE '$maillistusr%'
    AND
    login_name  NOT LIKE '$disabled_pfx%'
d145 10
a154 4
unless($ret){
    print "$script_name: unable to perform update: $!\n";
    $CONN->disconnect;
    exit(1);
d157 30
a186 1
print "$script_name: accounts disabled\n";
d196 17
@


1.4
log
@First furtive attempts to support remote databases.
@
text
@d50 1
a50 1
# $Id: issuezilla-user-disableall,v 1.3 2001/01/12 21:34:04 kmaples Exp $
d98 1
a98 1
print qq[matching string is '$maillistusr'];
d122 6
d129 1
a129 1
my $CONN = DBI->connect($dbc, $dbuser, $dbpass);
@


1.3
log
@I mean 'unless'!  I swear!
@
text
@d50 1
a50 1
# $Id: issuezilla-user-disableall,v 1.2 2001/01/10 22:00:23 kmaples Exp $
d122 1
a122 1
my $dbc = "DBI:mysql:$dbname";
@


1.2
log
@Changes to prevent 'disable all' to be invoked in single-db mode
@
text
@d50 1
a50 1
# $Id: issuezilla-user-disableall,v 1.1 2001/01/09 03:57:03 kmaples Exp $
d117 1
a117 1
if($multiple_dbs){
@


1.1
log
@Added scripts to disable all users in a given project (database).  This is
a prelude to re-synchronizing with Helm's user table (which will re-enable
accounts with their current permissions).
@
text
@d50 1
a50 1
# $Id: $
d54 2
d69 1
d114 7
@


1.1.1.1
log
@Replacing the HEAD with the HELM_PEER_PORT_BRANCH.
@
text
@d50 1
a50 1
# $Id: issuezilla-user-disableall,v 1.5 2001/01/17 00:52:40 kmaples Exp $
a53 2
#TODO: if in single-db mode, prohibit this operation

a66 1
my $multiple_dbs       = $ARGV[1] || '';
d95 1
a95 1
#print qq[matching string is '$maillistusr'];
d112 2
a113 15
# In single-db mode, users need to be administered through IZ's
# UI:
unless($multiple_dbs){
    print "$script_name: database mode SINGLE; no action\n";
    exit(0);
}  

## This to silence db errors:
my %atr = (
    PrintError => 0,
    RaiseError => 0,
);

my $dbc = join(':',"DBI:mysql:$dbname",$ENV{DATABASE_HOST},$ENV{DATABASE_PORT});
my $CONN = DBI->connect($dbc, $dbuser, $dbpass, \%atr);
@


