head	1.16;
access;
symbols
	TIGRIS_NOV_12_2000:1.15
	OLDHELM:1.15.0.2
	TIGRIS_NOV_11_2000:1.15
	TIGRIS_SEP_13_2000:1.3.0.2
	TIGRIS_BASELINE:1.13;
locks; strict;
comment	@# @;


1.16
date	2000.11.14.02.25.03;	author kmaples;	state dead;
branches;
next	1.15;

1.15
date	2000.10.05.18.50.02;	author kmaples;	state Exp;
branches;
next	1.14;

1.14
date	2000.09.27.19.00.58;	author kmaples;	state Exp;
branches;
next	1.13;

1.13
date	2000.09.27.00.27.19;	author kmaples;	state Exp;
branches;
next	1.12;

1.12
date	2000.09.26.05.51.17;	author kmaples;	state Exp;
branches;
next	1.11;

1.11
date	2000.09.21.19.29.10;	author kmaples;	state Exp;
branches;
next	1.10;

1.10
date	2000.09.21.19.18.44;	author kmaples;	state Exp;
branches;
next	1.9;

1.9
date	2000.09.20.23.05.22;	author kmaples;	state Exp;
branches;
next	1.8;

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

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

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

1.5
date	2000.09.15.03.51.10;	author kmaples;	state Exp;
branches;
next	1.4;

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

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

1.2
date	2000.05.17.00.02.17;	author manoj;	state dead;
branches;
next	1.1;

1.1
date	2000.04.29.00.04.10;	author jrobbins;	state Exp;
branches;
next	;


desc
@@


1.16
log
@Changed the way that child scripts are called in order to return the number
or the (child) script which failed (if any).  Currently returns 0 or the
number of the first script in the sequence to fail.  Removed leftovers from
merge.
@
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: bugzilla-project-add,v 1.15 2000/10/05 18:50:02 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";
# Detaint the args by brute force:
@@ARGV = detaint_array(@@ARGV);


# Process arguments
my $sandbox            = $ARGV[0] || '';
my $project_name       = $ARGV[1] || '';
my $domain_name        = $ARGV[2] || ''; 
my $bugs_password      = $ARGV[3] || '';

# Some email address for bugzilla:
my $login_name = "$project_name-bugs\@@$domain_name";
my $realname   = "$project_name bugs mailing list";

# 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 $dbname         = $ENV{DATABASE_NAME}     || '';
my $dbuser         = $ENV{DATABASE_USER}     || '';
my $dbpass         = $ENV{DATABASE_PASSWORD} || '';

# 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);
}

my $dbc = "DBI:mysql:$dbname";
my $CONN = DBI->connect($dbc, $dbuser, $dbpass);

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

# Do the sql quoting for the values we're gonna play with:
foreach($project_name, $domain_name, $bugs_password, $login_name, $realname){
    $_ = $CONN->quote( $_ );
}

# One: test and insert in the 'products' table:
print "$script_name: checking for previous record in 'products' table\n";

$command = qq[
    SELECT * FROM products WHERE
    product     = $project_name AND
    description = $project_name    
    LIMIT 1
];

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

if($ret && $ret ne '0E0'){
    print "$script_name: record found\n";
} else {
    print "$script_name: performing insert\n";
    $command = qq[

    INSERT INTO products SET 
    	product      = $project_name, 
	description  = $project_name, 
	milestoneurl = '',
	disallownew  =  0
    ];

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

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

# Two: test and insert in the 'profiles' table:
print "$script_name: checking for previous record in 'profiles' table\n";

$command = qq[
    SELECT * FROM profiles WHERE
    login_name     = $login_name
    LIMIT 1
];

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

if($ret && $ret ne '0E0'){
    print "$script_name: record found\n";
} else {
    print "$script_name: performing insert\n";

    $command = qq[
    	INSERT INTO profiles SET 
    	login_name     = $login_name,
        password       = $bugs_password,
    	cryptpassword  = PASSWORD($bugs_password),
    	realname       = $realname,
    	groupset       = 0,
    	emailnotification = 'All'
    ];

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

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

# Three: test and insert in the 'versions' table:
print "$script_name: checking for previous record in 'versions' table\n";

$command = qq[
    SELECT * FROM versions WHERE
    value   = 'current' AND
    program = $project_name
    LIMIT 1
];

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

if($ret && $ret ne '0E0'){
    print "$script_name: record found\n";
} else {
    print "$script_name: performing insert\n";
    $command = qq[

    INSERT INTO versions SET
	value   = 'current',
	program = $project_name
    ];

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

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

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

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


# 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.15
log
@Because last week I was an idiot who didn't understand sql ... not much has
changed, but this week I realized things didn't need to be as hard as I was
making them.  All better now.
@
text
@d51 1
a51 1
# $Id: bugzilla-project-add,v 1.14 2000/09/27 19:00:58 kmaples Exp $
@


1.14
log
@Because sometimes your hack isn't as clever as you thought it was ... changed
the way in which the number of columns in each table is determined before
inserts are performed so that it does it the hard way - selects the table
description, then iterates over the rows in the description.  Reliable, but
ugly; this addresses problems that would occur if the schema had been changed
and there was no previously existing data in the table.
@
text
@d51 1
a51 1
# $Id: bugzilla-project-add,v 1.13 2000/09/27 00:27:19 kmaples Exp $
a81 1
my ($products_index, $profiles_index, $versions_index) = (0,0,0);
a117 22
# Get some column counts:  We know that the bugzilla schema may
# change out from under us, so we want to start out by finding 
# how many columns each table has:

# Products:
$command = qq[show columns from products];
$select = $CONN->prepare($command);
$ret    = $select->execute;
while(my (@@foo) = $select->fetchrow_array){ $products_index++; }

# Profiles:
$command = qq[show columns from profiles];
$select = $CONN->prepare($command);
$ret    = $select->execute;
while(my (@@foo) = $select->fetchrow_array){ $profiles_index++; }

# Versions:
$command = qq[show columns from versions];
$select = $CONN->prepare($command);
$ret    = $select->execute;
while(my (@@foo) = $select->fetchrow_array){ $versions_index++; }
# Now get on with checking for previous records, and performing inserts:
d137 5
a141 3
    INSERT INTO products VALUES
    ($project_name, $project_name, '', 0

a143 9
    # Oohh, this is a hack.  We currently know of 4 columns, but
    # this is for bugzilla 2.6 - and we know that there are more
    # cols. in later versions, so we have to do this for each 
    # insert:
    for(1 .. ($products_index - 4)){
        $command .= q[,''];
    }
    $command .= ')';

d170 1
d172 7
a178 10

    INSERT INTO profiles VALUES (
    '',
    $login_name,
    $bugs_password,
    PASSWORD($bugs_password),
    $realname,
    0,
    'All'

a180 6
    # Same hack as above:
    for(1 .. ($profiles_index - 7)){
        $command .= q[,''];
    }
    $command .= ')';

d210 3
a212 3
    INSERT INTO versions VALUES
    ('current',$project_name

a213 8

    # We are blessed enough that the 'versions' table doesn't appear
    # to have changed ... nonetheless, the hack:
    for(1 .. ($versions_index - 2)){
        $command .= q[,''];
    }
    $command .= ')';

@


1.13
log
@Added tests for number of columns before performing inserts, and padding out
the insert to match that number.  This is to avoid a potential problem in
upgrading to newer versions of bugzilla where the schema has been changed,
which meant that inserts of fixed-length would have choked.  Fixed a bug in
bugzilla-module-delete which was preventing some deletes from occuring.
@
text
@d51 1
a51 1
# $Id: bugzilla-project-add,v 1.12 2000/09/26 05:51:17 kmaples Exp $
d82 1
a82 1
my ($products_index, $profiles_index, $versions_index);
d119 22
a152 1
$products_index = $#{ [$select->fetchrow_array] };
d169 2
a170 2
    for(0 .. ($products_index - 4)){
	$command .= q[,''];
a194 1
$profiles_index = $#{ [$select->fetchrow_array] };
d214 1
a214 1
    for(0 .. ($profiles_index - 7)){
a240 1
$versions_index = $#{ [$select->fetchrow_array] };
d255 1
a255 1
    for(0 .. ($versions_index - 2)){
@


1.12
log
@Rewrote bugzilla-project-add to use DBI; misc. bugfixes around conversion
to DBI in related scripts.
@
text
@d51 1
a51 1
# $Id: bugzilla-project-add,v 1.11 2000/09/21 19:29:10 kmaples Exp $
d82 2
a83 1

d126 1
d131 1
d140 1
a140 1
    ($project_name, $project_name, '', 0)
d144 9
d169 1
d174 1
d182 8
a189 1
    INSERT INTO profiles SET
d191 1
a191 6
    login_name    = $login_name,
    password      = $bugs_password,
    cryptpassword = PASSWORD($bugs_password),
    realname      = $realname,
    groupset      = 0,
    emailnotification = 'All'
d193 5
a197 1
    ];
d216 1
d221 1
d230 1
a230 1
    ('current',$project_name)
d233 8
@


1.11
log
@Added print statements for log files
@
text
@d51 1
a51 1
# $Id: bugzilla-project-add,v 1.10 2000/09/21 19:18:44 kmaples Exp $
d59 1
d73 10
a97 1

d104 45
a148 8
# Ultimately, this command is going to be wrapped in double-quotes
# as it's passed on the command line, so we need to escape both
# types of quotes - the first to appease mysql, the second to
# prevent premature termination of the command:

foreach($project_name, $domain_name, $bugs_password){
    $_ =~ s/'/\\'/g;
    $_ =~ s/"/\\"/g;
d151 16
a166 3
# Build the sql statment - do NOT use double-quotes here:
my $command = qq[
    INSERT INTO products VALUES ('$project_name', '$project_name', '', 0);
a168 6
    login_name='$project_name-bugs\@@$domain_name.com',
    password='$bugs_password',
    cryptpassword=PASSWORD('$bugs_password'),
    realname='$project_name bugs mailing list',
    groupset=0,
    emailnotification='All';
d170 18
a187 2
    INSERT INTO versions VALUES ('current','$project_name');
];
d189 2
a190 2
# compress whitespace:
$command =~ s/\s+/ /g;
d192 5
a196 6
# This approach is abandoned in favor of the safer use of 'system':
#
# my $string = qq[mysql -u$dbuser -p$dbpass $dbname -e "$command"];
#
# system($string) == 0
#   or die "$script_name: Unable to execute mysql command: $!\n";
d198 2
a199 1
my $mysql_bin = `which mysql`; chomp $mysql_bin;
d201 20
a220 1
print "$script_name: doing mysql insert\n";
d222 3
a224 2
system($mysql_bin,"-u$dbuser","-p$dbpass","$dbname",'-e',$command) == 0
    or die "$script_name: Unable to execute mysql command: $!\n";
@


1.10
log
@Fixed quoting, changed the system() call to mysql, and specified PASSWORD()
be performed on the password (coincidentally).
@
text
@d51 1
a51 1
# $Id: bugzilla-project-add,v 1.9 2000/09/20 23:05:22 kmaples Exp $
d130 2
@


1.9
log
@Fixed typo - forgot to escape '@@' in string
@
text
@d51 1
a51 1
# $Id: bugzilla-project-add,v 1.8 2000/09/20 22:59:21 kmaples Exp $
d94 9
d111 1
a111 1
    cryptpassword='$bugs_password',
d122 6
a127 2
# escape double-quotes:
$command =~ s/"/\\"/g;
d129 1
a129 1
my $string = qq[mysql -u$dbuser -p$dbpass $dbname -e "$command"];
d131 2
a132 3
print "$script_name: performing mysql insert\n";
system($string) == 0 
	or die "$script_name: Unable to execute mysql command: $!\n";
@


1.8
log
@Modifications to get info for database access via environmentals; amended
the @@ARGV list to include a 'bugs_password' to be passed in.
@
text
@d51 1
a51 1
# $Id: bugzilla-project-add,v 1.7 2000/09/18 23:49:09 kmaples Exp $
d100 1
a100 1
    login_name='$project_name-bugs@@$domain_name.com',
@


1.7
log
@Converted pseudocode to mysql command.  Both of these are currently 'short-
circuited' while under development - they both exit before any real code would
be executed.  They're also blunt instruments - at the moment, they just
put together a sql statment to pass to mysql on the command line (it isn't
yet clear if it's worth going to the trouble of loading DBI and establishing
a real connection to the database, considering that neither script executes
more than three statements - all inserts).
@
text
@d51 1
a51 1
# $Id: bugzilla-project-add,v 1.6 2000/09/18 21:47:54 kmaples Exp $
d70 1
d75 3
a77 4
my $dbname         = '';
my $dbuser         = '';
my $dbpass         = '';
my $bugs_password  = '';
d88 5
a92 3
# Short-circut while developing this:
exit;

d118 1
@


1.6
log
@Preparatory work for bugzilla components
@
text
@d51 1
a51 1
# $Id: bugzilla-project-add,v 1.5 2000/09/15 03:51:10 kmaples Exp $
d74 4
d88 27
a114 13
# Rough mysql instructions:
# 
# INSERT INTO products VALUES ("PROJECTNAME", "PROJECTNAME", "", 0);
# 
# INSERT INTO profiles SET
# login_name="$project_name-bugs@@$domain_name",
# password="xxxxxxx",
# cryptpassword=PASSOWRD("xxxxxx"),
# realname="bugs mailing list for project $project_name",
# groupset=0,
# emailnotification="All";
#
# INSERT INTO versions VALUES ("current","$project_name");
d116 2
@


1.5
log
@Fixed regex to display script name in logfiles.
@
text
@d51 1
a51 1
# $Id: bugzilla-project-add,v 1.4 2000/09/13 22:33:46 kmaples Exp $
d67 7
d84 13
@


1.4
log
@Added crude subroutine to all child scripts to detaint @@ARGV.  At the moment,
this isn't doing any real detainting - just spitting the args back out to get
around warnings setuid generates.  Complications with the scripts' knowledge
of it's own working dir when it's called prevent the effective use of 'require'
in the child scripts, thus the redundancy of code in the children (for the time
being)
@
text
@d51 1
a51 1
# $Id: bugzilla-project-add,v 1.3 2000/09/12 16:28:06 kmaples Exp $
d71 1
a71 1
$script_name =~ s/^.*\/([\w]+)$/$1/;
@


1.3
log
@Stubs for bugzilla-related functions
@
text
@d51 1
a51 1
# $Id: $
d60 6
d84 16
@


1.2
log
@These functions will be performed by the servlets.
@
text
@d1 1
a1 1
#!/usr/bin/perl -w
d50 2
a51 2
# bugzilla-project-add
# $Id: bugzilla-project-add,v 1.1 2000/04/29 00:04:10 jrobbins Exp $
d53 4
a56 1
# Provide functions related to configuring the bugzilla bug tracking tool
d60 17
a77 6
# Process arguments
my $sandbox      = $ARGV[0];
my $project_name = $ARGV[1];
my $domain_name  = $ARGV[2];
my $brand_name   = $ARGV[3];
my $description  = $ARGV[4];
a78 1
print "bugzilla: add product for $project_name in domain $domain_name\n";
@


1.1
log
@initial checkin
@
text
@d51 1
a51 1
# $Id: bugzilla.pm,v 1.1 2000/03/24 20:33:58 jrobbins Exp $
@

