head	1.49;
access;
symbols
	TIGRIS_1_1_0RC2:1.33.6.2
	TIGRIS_1_1_0RC1:1.33.6.2
	TIGRIS_1_1:1.33.6.2.0.2
	TIGRIS_1_0_8:1.33.6.2
	TIGRIS_1_0_8RC3:1.33.6.2
	TIGRIS_1_0_8RC2:1.33.6.2
	TIGRIS_1_0_8RC1:1.33.6.2
	TIGRIS_1_0_7:1.33.6.1
	TIGRIS_1_0_7RC3:1.33.6.1
	TIGRIS_1_0_7RC2:1.33.6.1
	TIGRIS_1_0_7RC1:1.33.6.1
	TIGRIS_1_0_6:1.33.6.1
	TIGRIS_1_0_6RC5:1.33.6.1
	TIGRIS_1_0_6RC4:1.33.6.1
	TIGRIS_1_0_6RC3:1.33.6.1
	TIGRIS_1_0_6RC2:1.33.6.1
	TIGRIS_1_0_6RC1:1.33.6.1
	TIGRIS_1_0_5:1.33.6.1
	TIGRIS_1_0_5RC6:1.33.6.1
	TIGRIS_1_0_5RC5:1.33.6.1
	TIGRIS_1_0_5RC4:1.33.6.1
	TIGRIS_1_0_5RC3:1.33.6.1
	TIGRIS_1_0_5RC2:1.33.6.1
	TIGRIS_1_0_5RC1:1.33.6.1
	TIGRIS_1_0_4:1.33.6.1
	TIGRIS_1_0_3:1.33.6.1
	TIGRIS_1_0_2:1.33.6.1
	TIGRIS_1_0_1:1.33
	TIGRIS_1_0:1.33.0.6
	TIGRIS_1_0_0:1.33
	TIGRIS_1_0_0_RC1:1.33.0.2
	dlr:1.1.1
	TIGRIS_0_9_2_4:1.32
	TIGRIS_0_9_2_3:1.32
	HELM_PEER_PORT_BRANCH:1.1.1.2
	TURBINE_PEER:1.32
	TIGRIS_0_9_2_1:1.32
	TIGRIS_0_9_2:1.32.0.2
	TIGRIS_0_9_0:1.22.0.2
	TIGRIS_0_8_4:1.21.0.2
	NEWHELM:1.1.1.1
	TIGRIS_NOV_12_2000:1.1.1
	TIGRIS_SEP_13_2000:1.9.0.2;
locks; strict;
comment	@# @;


1.49
date	2001.08.11.16.03.52;	author kmaples;	state Exp;
branches;
next	1.48;

1.48
date	2001.07.31.18.03.44;	author kmaples;	state Exp;
branches;
next	1.47;

1.47
date	2001.07.30.18.07.19;	author kmaples;	state Exp;
branches;
next	1.46;

1.46
date	2001.07.07.01.20.13;	author edk;	state Exp;
branches;
next	1.45;

1.45
date	2001.06.05.22.36.18;	author kmaples;	state Exp;
branches;
next	1.44;

1.44
date	2001.05.10.20.05.15;	author kmaples;	state Exp;
branches;
next	1.43;

1.43
date	2001.05.08.22.28.20;	author kmaples;	state Exp;
branches;
next	1.42;

1.42
date	2001.04.25.17.14.58;	author kmaples;	state Exp;
branches;
next	1.41;

1.41
date	2001.04.24.04.35.38;	author kmaples;	state Exp;
branches;
next	1.40;

1.40
date	2001.04.20.17.40.27;	author kmaples;	state Exp;
branches;
next	1.39;

1.39
date	2001.04.20.00.02.50;	author kmaples;	state Exp;
branches;
next	1.38;

1.38
date	2001.04.19.05.48.33;	author kmaples;	state Exp;
branches;
next	1.37;

1.37
date	2001.04.19.05.37.02;	author kmaples;	state Exp;
branches;
next	1.36;

1.36
date	2001.04.18.02.02.58;	author kmaples;	state Exp;
branches;
next	1.35;

1.35
date	2001.04.17.04.44.54;	author kmaples;	state Exp;
branches;
next	1.34;

1.34
date	2001.04.07.00.02.14;	author kmaples;	state Exp;
branches;
next	1.33;

1.33
date	2001.03.24.01.32.19;	author stack;	state Exp;
branches
	1.33.6.1;
next	1.32;

1.32
date	2001.01.15.20.54.40;	author kmaples;	state Exp;
branches;
next	1.31;

1.31
date	2001.01.15.19.14.20;	author kmaples;	state Exp;
branches;
next	1.30;

1.30
date	2001.01.13.02.04.52;	author kmaples;	state Exp;
branches;
next	1.29;

1.29
date	2001.01.12.02.14.18;	author kmaples;	state Exp;
branches;
next	1.28;

1.28
date	2001.01.10.22.00.23;	author kmaples;	state Exp;
branches;
next	1.27;

1.27
date	2001.01.09.03.57.03;	author kmaples;	state Exp;
branches;
next	1.26;

1.26
date	2001.01.05.23.31.11;	author kmaples;	state Exp;
branches;
next	1.25;

1.25
date	2001.01.04.18.25.33;	author kmaples;	state Exp;
branches;
next	1.24;

1.24
date	2000.12.28.01.48.09;	author kmaples;	state Exp;
branches;
next	1.23;

1.23
date	2000.12.27.22.57.44;	author kmaples;	state Exp;
branches;
next	1.22;

1.22
date	2000.12.20.20.43.56;	author kmaples;	state Exp;
branches;
next	1.21;

1.21
date	2000.11.28.22.00.23;	author kmaples;	state Exp;
branches;
next	1.20;

1.20
date	2000.11.28.18.39.27;	author kmaples;	state Exp;
branches;
next	1.19;

1.19
date	2000.11.16.21.58.53;	author kmaples;	state Exp;
branches;
next	1.18;

1.18
date	2000.11.16.20.42.13;	author kmaples;	state Exp;
branches;
next	1.17;

1.17
date	2000.11.16.05.46.52;	author kmaples;	state Exp;
branches;
next	1.16;

1.16
date	2000.11.16.04.39.04;	author kmaples;	state Exp;
branches;
next	1.15;

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

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

1.13
date	2000.09.18.20.03.31;	author kmaples;	state dead;
branches;
next	1.12;

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

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

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

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

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

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

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

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

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

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

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

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

1.1.1.1
date	2000.11.12.21.17.20;	author dlr;	state Exp;
branches;
next	1.1.1.2;

1.1.1.2
date	2001.02.21.00.35.49;	author dlr;	state Exp;
branches;
next	;

1.33.6.1
date	2001.04.24.04.57.10;	author jrobbins;	state Exp;
branches;
next	1.33.6.2;

1.33.6.2
date	2001.07.07.01.17.43;	author edk;	state Exp;
branches;
next	;


desc
@@


1.49
log
@Issue number: 4544
Removing unnecessary IZ code from the bridge.
@
text
@# ================================================================
# Copyright (c) 2000 CollabNet.  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 CollabNet (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 CollabNet.
#
# 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 CollabNet.
#


################################################################
# Name:              ParentChildArgumentBridge.pl
# Original Author:   kmaples@@collab.net
# $Id: ParentChildArgumentBridge.pl.in,v 1.48 2001/07/31 18:03:44 kmaples Exp $
#
# This library defines the interface between 'parent' script, and 
# 'child' script by negotiating the arguments of each.
#
#---------------------------------------------------------------

# This is a work-around for the fact that the current working directory
# doesn't really have any meaning to the calling servlet - so we have
# to call child scripts based on their relation to the sandbox:
my $SCRIPT_PATH;
    
BEGIN { 
    # Init the path, and include the lib for logging functions:
    $SCRIPT_PATH = '__SANDBOX__/helm/perl/scripts'; 

    require "$SCRIPT_PATH/LogFunctions.pl"
    or die "Require failed: $!\n";
}

#-------------------
sub perform {
#-------------------
    # Syntax: perform(action);
    # Defines the interface between the parent scripts and the child scripts
    # by maping values from @@ARGV to the args needed by the child scripts.

    my $action = shift;

    # From now on, we'll use '--named' arguments:

    use Getopt::Long;

    # And now, the args and their values: 

    # --domain_name         helm:HELM_DOMAIN.NAME
    # --project_name        helm:HELM_PROJECT.NAME
    # --project_id          helm:HELM_PROJECT.PROJECT_ID
    # --brand_name          --ignore---
    # --description         helm:HELM_PROJECT.SHORT_DESCRIPTION
    # --module_name         --hardcoded, e.g., 'www' --
    # --module_description  --hardcoded--
    # --is_web              --hardcoded--
    # --is_public          helm:HELM_PROJECT.IS_PRIVATE

    ## Init the vars used to hold the options: 
    foreach($domain_name, $project_name, $project_id, $brand_name,
        $description, $module_name, $module_description, $is_web, $is_public,
        $new_project_name){

        $_ ||= '';
    }


    GetOptions(

      'domain_name=s'        => \$domain_name,        
      'project_name=s'       => \$project_name,       
      'project_id=i'         => \$project_id,         
      'brand_name=s'         => \$brand_name,         
      'description=s'        => \$description,        
      'module_name=s'        => \$module_name,        
      'module_description=s' => \$module_description, 
      'is_web=s'             => \$is_web,             
      'is_public:s'          => \$is_public,             

      # Replacement values:  

      'new_project_name=s'   => \$new_project_name,
    );

    $htdoc_root         = $ENV{'HTDOC_ROOT'};
    $sandbox            = $ENV{'SANDBOX'};

    my $project_database;   # This is the 'translated' database name, after
                            # accounting for project id. 

    my $multiple_dbs;       # DB setting.

    ## Scary, scary ... havent figured out exactly how I want to do this yet,
    ## but I need to set mysql root values for the issuezilla-project-create
    ## script:

    $ENV{DATABASE_ROOTUSER} = '__DATABASE_ADMIN_USER__' || '';
    $ENV{DATABASE_ROOTPASS} = '__DATABASE_ADMIN_PASSWORD__' || '';
    $ENV{DATABASE_PORT}     = '__DATABASE_PORT__' || '';    
    $ENV{DATABASE_HOST}     = '__DATABASE_HOST__' || '';    

    ## Terrible, terrible hack:  if $action is an issuezilla thing, we
    ## need to determine which database to talk to.  This reqires 
    ## checking which mode issuezilla is in (one or many issue databases).
    ## So we do the same thing which happens with issuezilla at run-time:
    ## set the environmental for HTTP_PROJECT_ID (this would normally be
    ## set by SecureNoodle in the http headers), read in issuezilla's 
    ## 'localconfig' file, and then swipe the value it sets for the 
    ## database name.  Then we set $ENV{DATABASE_NAME} so that the children 
    ## use the correct DB:
    
    if($action =~ m/^issuezilla/){
        my $izconfig = $sandbox . '/issuezilla/localconfig';

        $ENV{HTTP_HELM_HELM_PROJECT_PROJECT_ID} = $project_id;

        put_debug("  Set HTTP_HELM_HELM_PROJECT_PROJECT_ID to $ENV{HTTP_HELM_HELM_PROJECT_PROJECT_ID}\n");

        unless( do "$izconfig" ){
           put_error("FAILED: $action - unable to find issuezilla config file\n");
           return(0);
        }

        ## Since we just sourced it in, set a variable to hold the 
        ## single/multiple db flag.  This may be examined by the scripts 
        ## which manage user accounts, as their behavior differs depending.

        $multiple_dbs = $::use_project_id_database || 0;  

        if($multiple_dbs){
            put_debug("  Database flag set to MULTIPLE\n");
        } else {
            put_debug("  Database flag set to SINGLE\n");
        }

        ## if we're in single-db mode, we'll only use this information
        ## during user creation (so that sites can assign default initial
        ## perms based on registered user); we don't do updates after
        ## the initial creation to allow people to manage IZ from w/in 
        ## IZ's own interface.

        ## Now set the database:  
        $project_database = $::db_name;        
        put_debug("  Setting project database to $project_database\n");
    }

    ## This holds arrays of values for each action.
    ## The idea here is to abstract these into something static which
    ## can be stored in one place and shared amongst related functions.

    my %action_to_args = (

    'apache-project-add'     
            => [$htdoc_root, $project_name],
    'apache-project-delete'  
            => [$htdoc_root, $project_name],
    'apache-project-edit'
            => [$htdoc_root, $project_name, $new_project_name],

    'cvs-module-add'     
            => [$sandbox, $htdoc_root, $project_name, $domain_name, $brand_name, $module_name, $module_description, $is_web],
    'cvs-module-delete'  
            => [$sandbox, $htdoc_root, $project_name, $domain_name, $brand_name, $module_name, $is_web],
    'cvs-module-edit'    
            => [$sandbox, $htdoc_root, $project_name, $domain_name, $brand_name, $module_name, $module_description, $is_web],

    'cvs-project-add'    
            => [$sandbox, $project_name],
    'cvs-project-delete'     
            => [$sandbox, $project_name],
    'cvs-project-edit'
            => [$sandbox, $project_name, $new_project_name],

    'issuezilla-project-add'
            => [    $sandbox, $project_name, $project_database, 
                    $is_public, $multiple_dbs],
    'issuezilla-project-delete'
            => [    $sandbox, $project_name, $project_database, 
                    $multiple_dbs],
    'issuezilla-project-edit'
            => [    $sandbox, $project_name, $project_database,
                    $is_public, $multiple_dbs, 
                    $new_project_name],

    'issuezilla-module-add'
            => [    $project_name, $project_database, 
                    $module_name, $module_description,
                    $multiple_dbs],
    'issuezilla-module-delete'
            => [    $project_name, $project_database, 
                    $module_name, $module_description,
                    $multiple_dbs],
    );
 
    my $cmd     = 'unix command line';
    my $ret     = 0;
 
    # No point in continuing if the action wasn't defined: 
    return(0) unless $action_to_args{$action};

    # Nasty sharp pointy things: this just retrieves the arg list
    # stored in the hashtable for this particular action:   
    my @@args = @@{ $action_to_args{$action} };
 
    # A safe system call.  Note: DON'T use backticks for something
    # like this, or you'll likely lose all of the child's diagnostic
    # messages:
    $ret = system("$SCRIPT_PATH/$action",@@args);
    
    # invert success here - the system will return '0' for true, '1'
    # for false - note that we're returning a diagnostic message,
    # as logging of 'die' conditions are the responsibility of the
    # called rather than the caller:
    if($ret == 0){
        put_log("EXECUTED: $action @@args\n");
        return(1);
    } else {
        put_log("FAILED: $action @@args\n");
        return(0);
    }
}
# Alpha and Omega:
BEGIN {
    $ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin";

    unless($ENV{'SANDBOX'}){
        put_error("FATAL: SANDBOX not set; exiting.\n");
        exit(1); 
    }

    # Open the logfile for logging at the beginning of execution.
    # The primary reason for this is to 'die' before doing anything
    # that we won't be able to log, and opening the log filehandle
    # in the beginning ensures this.

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

    # Autoflush buffer:
    $| = 1;

    # This needs to be established dynamically; I don't know the
    # preferred method for arriving at this value:
    my $logdir   = '__SANDBOX__/log/debug/';
    my $logfile  = $logdir . 'HelmPerlScripts.log';

    my $logfilter = 'LogFilter';    
    # Set the loglevel depending on whether or not this is a 
    # production environment:  
    my $loglevel  = ('__IN_PRODUCTION__' eq 'true') ? 'error' : 'debug'; 

    # Send the output to the log filter: 
    unless(open(STDOUT, "| $SCRIPT_PATH/$logfilter --logfile=$logfile --loglevel=$loglevel") 
        && (open(STDERR, ">&STDOUT"))){
        die "Can't open handle for logging: $!\n";
    }

    # This is all in order to print a nice header for the log
    # entry:

    my $time   = time();
    my $date   = localtime($time);
    my $header = "[$date]\n[$$] START: $::script_name " . join(' ',@@ARGV) . "\n";

    put_log($header);
}
END {
    # Note that because END blocks are executed from bottom to top,
    # this block should appear BEFORE any other END blocks trying
    # to print to the same filehandle.  This might seem unnecessary,
    # but since we did point these at a file, we really ought to
    # clean up after ourselves:

    my $footer = "[$$] END: $::script_name\n\n";

    put_log($footer);
   
    # Note that closing filehandles at this point will cause listening pids
    # - like the log filter, if being used - to hang.  So just leave without
    # saying anything.  
}

# return true:
1;


@


1.48
log
@Issue number: 4544
Removed unnecessary args; fixed the name of the default subcomponent owner
to simply 'issues@@{project}'
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.47 2001/07/30 18:07:19 kmaples Exp $
a94 3
    # --issues_realname     joist:User.name
    # --issues_username     joist:User.loginID
    # --issues_role         'super|admin|devel|observ'
d99 1
a99 2
        $issues_realname, $issues_username, $issues_role, $new_project_name,
        $new_issues_username,){
a115 3
      'issues_realname=s'    => \$issues_realname,    
      'issues_username=s'    => \$issues_username,    
      'issues_role=s'        => \$issues_role,        
a119 1
      'new_issues_username=s'=> \$new_issues_username,
a129 8
    ## These numbers correspond to the bit sets of permissions
    ## in issuezilla ('SELECT * FROM groups' to view them):
    my $observer_user  = "0";
    my $developer_user = "96";
    my $admin_user     = "127";
    ## Unused, but this represents the highest bitset a user can have:
    my $super_user     = "9223372036854775807";

a172 13
        # Now evaluate and set the user's role:      

        if($issues_role      =~ m/^super/){
            $issues_role = $super_user;
        } elsif($issues_role =~ m/^admin/){ 
            $issues_role = $admin_user;
        } elsif($issues_role =~ m/^devel/){
            $issues_role = $developer_user;
        } else {
            # Default to the observer, then:
            $issues_role = $observer_user;
        }

a181 15
    }

    ## This is largely for sandboxing - if the prefix var is sent in env.sh at
    ## install time, then this gets prepended to the email addresses:
    my $iz_mail_pfx = '__MAIL_PREFIX__' || '';
    
    ## And this, therefore, requires refactoring from the child scripts
    ## as the logic is repeated in the child scripts:
    if($iz_mail_pfx){ 
        ## Horrible - this is so list inserts make sense in sandboxes:  
        $ENV{MAIL_PREFIX} = $iz_mail_pfx;
     
        my @@tmp = split(':', $issues_username);
        foreach(@@tmp){ $_ = $iz_mail_pfx . $_ }
        $issues_username = join(':',@@tmp); 
@


1.47
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
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.46 2001/07/07 01:20:13 edk Exp $
d267 2
a268 2
            => [    $sandbox, $project_name, $project_database, 
                    $domain_name, $module_name, $module_description,
d271 2
a272 2
            => [    $sandbox, $project_name, $project_database, 
                    $domain_name, $module_name, $module_description,
@


1.46
log
@for issuezilla-user-add, in single db mode, pass along the permissions
specified ... they'll only be used on user creation (not updates) anyway.
this means that they'll be created in IZ with whatever permissions
registered users has.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.45 2001/06/05 22:36:18 kmaples Exp $
d257 1
a257 1
                    $domain_name, $is_public, $multiple_dbs],
d260 1
a260 1
                    $domain_name, $multiple_dbs],
d263 1
a263 1
                    $domain_name, $is_public, $multiple_dbs, 
a273 14
    'issuezilla-user-add'
            => [    $project_name, $project_database, $domain_name,
                    $issues_realname, $issues_username, $issues_role,
                    $multiple_dbs ],
    'issuezilla-user-edit'
            => [    $project_name, $project_database, $domain_name, 
                    $issues_realname, $issues_username, 
                    $new_issues_username, $issues_role, $multiple_dbs],
    'issuezilla-user-delete'
            => [    $project_name, $project_database, $domain_name, 
                    $issues_username, $multiple_dbs],
    'issuezilla-user-disableall'
            => [    $project_database, $multiple_dbs  ],

@


1.45
log
@Issue number: 4242
Completely removing IZ's password and LDAP code.  This is in advance of
more signifigant changes to persuade IZ to obtain permission information
directly from Helm.

This is a large-scale cleanup of code which is useless to IZ, since it
obtains the information it uses for authentication from Helm in any event.
Password information was merely dummy strings that acted as placeholders
in the profiles table; as of now, it is sufficient to have an entry in
the profiles table (non-disabled, of course) for access.

Related changes can be found in issuezilla/
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.44 2001/05/10 20:05:15 kmaples Exp $
d202 5
a206 8
        ## Now, if we're in single-db mode, disregard all the hard
        ## work we just went to and flatten the roles, since everyone
        ## but the admins are observers, and it's left to the admins
        ## to manually manage their users through IZ:

        if(!$multiple_dbs && ( $issues_role < $admin_user )){
            $issues_role = $observer_user;
        }
@


1.44
log
@Syncing unimplemented functions.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.43 2001/05/08 22:28:20 kmaples Exp $
a144 7

    ## Terrible hack requiring refactoring:  this is now a static identifier 
    ## used to create a bogus password entry so that helm doesn't have to be
    ## consulted ... since 'localconfig' is already being read in below, I need
    ## to move the identifier there so that this needen't be duplicated:

    $ENV{ISSUZILLA_PASSWORD} = 'password'; 
@


1.43
log
@Fixes to facilitate operation under Perl 5.6
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.42 2001/04/25 17:14:58 kmaples Exp $
d102 2
a103 1
        $issues_realname, $issues_username, $issues_role, $new_project_name){
d119 1
a119 1
      'is_public:s'         => \$is_public,             
d127 1
d290 2
a291 2
                    $issues_realname, $issues_username, $issues_role,
                    $multiple_dbs],
@


1.42
log
@Added a filter and some shared logging routine to quiet the output of the
scripts in production.  Lines which do not explicitly use the routines are
interpreted as debug.

Changed the arguments (unimplemented) from 'is_private' to 'is_public' to
conform with helm.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.41 2001/04/24 04:35:38 kmaples Exp $
d217 1
a217 1
        $project_database = $db_name;        
@


1.41
log
@Specified is_private as optional for the time being
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.40 2001/04/20 17:40:27 kmaples Exp $
d58 12
d94 1
a94 1
    # --is_private          helm:HELM_PROJECT.IS_PRIVATE
d101 1
a101 1
        $description, $module_name, $module_description, $is_web, $is_private,
d118 1
a118 1
      'is_private:s'         => \$is_private,             
d175 1
a175 1
        print "  Set HTTP_HELM_HELM_PROJECT_PROJECT_ID to $ENV{HTTP_HELM_HELM_PROJECT_PROJECT_ID}\n";
d178 1
a178 1
           print "FAILED: $action - unable to find issuezilla config file\n";
d189 1
a189 1
            print "  Database flag set to MULTIPLE\n";
d191 1
a191 1
            print "  Database flag set to SINGLE\n";
d218 1
a218 1
        print "  Setting project database to $project_database\n";
d265 1
a265 1
                    $domain_name, $is_private, $multiple_dbs],
d271 1
a271 1
                    $domain_name, $is_private, $multiple_dbs, 
a303 5
    # This is a work-around for the fact that the current working directory
    # doesn't really have any meaning to the calling servlet - so we have
    # to call child scripts based on their relation to the sandbox:
    my $script_path = $ENV{'SANDBOX'} . '/helm/perl/scripts';
    
d311 1
a311 1
    $ret = system("$script_path/$action",@@args);
d318 1
a318 1
        print "EXECUTED: $action @@args\n";
d321 1
a321 1
        print "FAILED: $action @@args\n";
d330 1
a330 1
        print "FATAL: SANDBOX not set; exiting.\n";
a346 1

d350 1
a350 5
    my $logfile  = 'HelmPerlScripts.log';
    
    # Store copies of the filehandles, for restoration in the END:
    open(OUTCOPY, ">&STDOUT") or die "Can't copy stdout: $!\n";
    open(ERRCOPY, ">&STDERR") or die "Can't copy stderr: $!\n";
d352 8
a359 2
    # Thanks to ms, a replacement for the code commented out below:
    unless(open(STDOUT, ">> $logdir" . "$logfile") && (open(STDERR, ">&STDOUT"))){
d370 1
a370 1
    print $header;
d381 5
a385 12
    print $footer;
    
    # Close out and restore STDOUT, STDERR;
    close STDOUT;
    close STDERR;

    open(STDOUT, ">&OUTCOPY") or die "Can't reopen stdout: $!\n";
    open(STDERR, ">&ERRCOPY") or die "Can't reopen stderr: $!\n";

    # Close out the backup filehandles:
    close OUTCOPY;
    close ERRCOPY;
@


1.40
log
@Fixed filehandle manipulation so that the stdout of children is once again
bound to the logfile.  This implementation should facilitate a logging
filter (in process).
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.39 2001/04/20 00:02:50 kmaples Exp $
d106 1
a106 1
      'is_private=s'         => \$is_private,             
@


1.39
log
@Cleaned up some potential problems with the tigris user; modified how the
bridge redirects stdout and stderr to the logfile in advance of setting up
some proper debugging.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.38 2001/04/19 05:48:33 kmaples Exp $
d271 1
a271 1
	        => [    $project_name, $project_database, $domain_name,
d345 4
d351 2
a352 2
    unless(open LOG, ">> $logdir" . "$logfile"){
    	die "Can't open handle for logging: $!\n";
a353 21
    
    # Alias the relevant filehandles to the logfile:
    *STDOUT=\*LOG;
    *STDERR=\*LOG;
    
#    # If this program is called by another program, we'll send STDOUT
#    # and SDTERR to the logfile - this way the children's messages will
#    # stick with the parent's logs.  Conversely, if this is called
#    # interactively (on the command line), we'll send it to both the 
#    # terminal and the logfile:
#    if(!(-t STDIN && -t STDOUT)){
#        # Point STDOUT and STDERR to the logfile, or bail out:
#        unless(open(STDOUT,">> $logdir" . "$logfile") && open(STDERR,">&STDOUT")){
#            die "Can't open handle for logging: $!\n";
#        }
#    } else {
#        # Point STDOUT and STDERR to the logfile, or bail out:
#        unless(open(STDOUT,"| tee -a $logdir" . "$logfile") && open(STDERR,">&STDOUT")){
#            die "Can't open handle for logging: $!\n";
#        }
#    }
d375 10
a384 2
    # Close out the filehandle we've been using:
    close(LOG) or die "Couldn't close logging filehandle: $!\n";   
@


1.38
log
@Ooops.  Accidentally checked in some depricated code
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.36 2001/04/18 02:02:58 kmaples Exp $
a339 5
    # If this program is called by another program, we'll send STDOUT
    # and SDTERR to the logfile - this way the children's messages will
    # stick with the parent's logs.  Conversely, if this is called
    # interactively (on the command line), we'll send it to both the 
    # terminal and the logfile:
a343 1

d346 3
a348 10
    if(!(-t STDIN && -t STDOUT)){
        # Point STDOUT and STDERR to the logfile, or bail out:
        unless(open(STDOUT,">> $logdir" . "$logfile") && open(STDERR,">&STDOUT")){
            die "Can't open handle for logging: $!\n";
        }
    } else {
        # Point STDOUT and STDERR to the logfile, or bail out:
        unless(open(STDOUT,"| tee -a $logdir" . "$logfile") && open(STDERR,">&STDOUT")){
            die "Can't open handle for logging: $!\n";
        }
d350 21
d392 2
a393 5
    # I haven't figured out why this is the case, but if 'tee' is 
    # used, trying to close these causes the program to hang while
    # waiting for an eof.  Just bugging out seems to work, though.
#    close(STDOUT) or die "Couldn't close logging handle STDOUT: $!\n";
#    close(STDERR) or die "Couldn't close logging handle STDERR: $!\n";
@


1.37
log
@For some reason, the code to get a lock no longer functions.  This has only
been a problem since the peer port, but nonetheless, this code isn't terribly
important, since only one process is making calls to this code.
@
text
@a57 1
# Globals for this file:
a59 16
sub print_log {
#-------------------
# print_log(0, "This is an urgent message!");
# print_log(1, "This is mostly for debug..");

	my $thislevel = shift;
	my $string    = shift;
	
	my $LOGLEVEL = ('__IN_PRODUCTION__'  =~ m/true/) ? 0 : 1;
	
	return unless $thislevel <= $LOGLEVEL;
	print $string;
	
	return;
}
#-------------------
d163 1
a163 1
        print_log(1, "  Set HTTP_HELM_HELM_PROJECT_PROJECT_ID to $ENV{HTTP_HELM_HELM_PROJECT_PROJECT_ID}\n");
d166 1
a166 1
           print_log(0, "FAILED: $action - unable to find issuezilla config file\n");
d177 1
a177 1
            print_log(1, "  Database flag set to MULTIPLE\n");
d179 1
a179 1
            print_log(1, "  Database flag set to SINGLE\n");
d206 1
a206 1
        print_log(1, "  Setting project database to $project_database\n");
d311 1
a311 1
        print_log(0, "EXECUTED: $action @@args\n");
d314 1
a314 1
        print_log(0, "FAILED: $action @@args\n");
a363 4
    # This shouldn't really be necessary, but it couldn't hurt:
    select(STDERR); $| = 1;
    select(STDOUT); $| = 1;

d371 1
a371 1
    print_log(0, $header);
d382 1
a382 1
    print_log(0, $footer);
@


1.36
log
@Undoing yesterday's commit - my hastiness to implement some sort of logging
level notion into these scripts caused me great pain.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.34 2001/04/07 00:02:14 kmaples Exp $
d58 1
d61 16
d180 1
a180 1
        print "  Set HTTP_HELM_HELM_PROJECT_PROJECT_ID to $ENV{HTTP_HELM_HELM_PROJECT_PROJECT_ID}\n";
d183 1
a183 1
           print "FAILED: $action - unable to find issuezilla config file\n";
d194 1
a194 1
            print "  Database flag set to MULTIPLE\n";
d196 1
a196 1
            print "  Database flag set to SINGLE\n";
d223 1
a223 1
        print "  Setting project database to $project_database\n";
d328 1
a328 1
        print "EXECUTED: $action @@args\n";
d331 1
a331 1
        print "FAILED: $action @@args\n";
a384 9
    # This might appear odd, but since STDOUT is now a filehandle
    # for the logfile, try to get a lock on it, or bail out:
    unless(flock(STDOUT, 2|4)){ # Ask nice first.
        sleep 1;
        unless(flock(STDOUT, 2)){
            die "Unable to lock logfile: $!\n";
        }
   }

d392 1
a392 1
    print $header;
d403 1
a403 1
    print $footer;
@


1.35
log
@Scripts now use IN_PRODUCTION to determine logging level
@
text
@a57 1
# Globals for this file:
a59 16
sub print_log {
#-------------------
# print_log(0, "This is an urgent message!");
# print_log(1, "This is mostly for debug..");

    my $thislevel = shift;
    my $string    = shift;
    
    my $LOGLEVEL = ('__IN_PRODUCTION__'  =~ m/true/) ? 0 : 1;
    
    return unless $thislevel <= $LOGLEVEL;
    print $string;
    
    return;
}
#-------------------
d163 1
a163 1
        print_log(1, "  Set HTTP_HELM_HELM_PROJECT_PROJECT_ID to $ENV{HTTP_HELM_HELM_PROJECT_PROJECT_ID}\n");
d166 1
a166 1
           print_log(0, "FAILED: $action - unable to find issuezilla config file\n");
d177 1
a177 1
            print_log(1, "  Database flag set to MULTIPLE\n");
d179 1
a179 1
            print_log(1, "  Database flag set to SINGLE\n");
d206 1
a206 1
        print_log(1, "  Setting project database to $project_database\n");
d271 1
a271 1
            => [    $project_name, $project_database, $domain_name,
d311 1
a311 1
        print_log(0, "EXECUTED: $action @@args\n");
d314 1
a314 1
        print_log(0, "FAILED: $action @@args\n");
d384 1
a384 1
    print_log(0, $header);
d395 1
a395 1
    print_log(0, $footer);
a405 1

@


1.34
log
@Added preliminary support for 'is_private'
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.33 2001/03/24 01:32:19 stack Exp $
d58 1
d61 16
d180 1
a180 1
        print "  Set HTTP_HELM_HELM_PROJECT_PROJECT_ID to $ENV{HTTP_HELM_HELM_PROJECT_PROJECT_ID}\n";
d183 1
a183 1
           print "FAILED: $action - unable to find issuezilla config file\n";
d194 1
a194 1
            print "  Database flag set to MULTIPLE\n";
d196 1
a196 1
            print "  Database flag set to SINGLE\n";
d223 1
a223 1
        print "  Setting project database to $project_database\n";
d288 1
a288 1
	        => [    $project_name, $project_database, $domain_name,
d328 1
a328 1
        print "EXECUTED: $action @@args\n";
d331 1
a331 1
        print "FAILED: $action @@args\n";
d401 1
a401 1
    print $header;
d412 1
a412 1
    print $footer;
d423 1
@


1.33
log
@Made the following changes:

-- Made an access, error, and debug subdir in $SANDBOX/log dir.
-- Made apache log hits in access_log in the $SANDBOX/log/access subdir.
-- Made apache log errors to error_log in $SANDBOX/log/error subdir.
-- All other logs, those w/o a distinct 'access' or 'error' character, now
go into the $SANDBOX/log/debug subdir (WebMacro.log, Turbine.log, etc.).

Reason for this relocation of logs (From Brian):

Ops needs an extremely reliable way to roll logs off of the production
servers, even before a site is in production; being able to write scripts
that assume that "all logs in *access* need to be kept forever", and "all
logs in *debug* and *error* are temporary and cullable within some set
amount of time" is mandatory.  This way we don't have to adjust the
rollover script every time apps-dev wants to have another app start
logging - just log it into the right place and we'll roll it away.

IZ2313

PR:
Obtained from:
Submitted by:
Reviewed by:
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.32 2001/01/15 20:54:40 kmaples Exp $
d82 1
d89 1
a89 1
        $description, $module_name, $module_description, $is_web,
d106 1
d253 1
a253 1
                    $domain_name, $multiple_dbs],
d259 2
a260 1
                    $domain_name, $multiple_dbs, $new_project_name],
@


1.33.6.1
log
@removed code which caused this script to lock up
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.33 2001/03/24 01:32:19 stack Exp $
d364 9
@


1.33.6.2
log
@pass along the permissions specified ... they'll only be used on user
creation (not updates) anyway.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.33.6.1 2001/04/24 04:57:10 jrobbins Exp $
d193 8
a200 5
        ## if we're in single-db mode, we'll only use this information
        ## during user creation (so that sites can assign default initial
        ## perms based on registered user); we don't do updates after
        ## the initial creation to allow people to manage IZ from w/in 
        ## IZ's own interface.
@


1.32
log
@Uncommented logging lines.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.31 2001/01/15 19:14:20 kmaples Exp $
d345 1
a345 1
    my $logdir   = '__SANDBOX__/log/';
@


1.31
log
@Sending all output to logfile whilst I try to resolve some problems with
initial logging
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.30 2001/01/13 02:04:52 kmaples Exp $
d349 1
a349 1
#    if(!(-t STDIN && -t STDOUT)){
d354 6
a359 6
#    } else {
#        # Point STDOUT and STDERR to the logfile, or bail out:
#        unless(open(STDOUT,"| tee -a $logdir" . "$logfile") && open(STDERR,">&STDOUT")){
#            die "Can't open handle for logging: $!\n";
#        }
#    }
@


1.30
log
@First furtive attempts to support remote databases.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.29 2001/01/12 02:14:18 kmaples Exp $
d345 1
a345 1
    my $logdir   = $ENV{'SANDBOX'} . '/log/';
d349 1
a349 1
    if(!(-t STDIN && -t STDOUT)){
d354 6
a359 6
    } else {
        # Point STDOUT and STDERR to the logfile, or bail out:
        unless(open(STDOUT,"| tee -a $logdir" . "$logfile") && open(STDERR,">&STDOUT")){
            die "Can't open handle for logging: $!\n";
        }
    }
@


1.29
log
@Less is more.  Refactored logging into shared lib., log stuff performed
from the command line as well as automatically.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.28 2001/01/10 22:00:23 kmaples Exp $
d143 2
@


1.28
log
@Changes to prevent 'disable all' to be invoked in single-db mode
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.27 2001/01/09 03:57:03 kmaples Exp $
a57 13
# This is a hack to make sandbox exposed to the calling scripts for 
# logging purposes:
#-------------------
sub get_sandbox {
#-------------------
    return($ENV{'SANDBOX'});
}
#-------------------
sub get_htdoc_root {
#-------------------
    return($ENV{'HTDOC_ROOT'});
}

d312 85
@


1.27
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
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.26 2001/01/05 23:31:11 kmaples Exp $
d290 1
a290 1
            => [    $project_database  ],
@


1.26
log
@It may or may not be a good idea, but here it is - the ability to edit
(rename) projects.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.25 2001/01/04 18:25:33 kmaples Exp $
d289 3
@


1.25
log
@Out with the unnecessary, in with the preparatory.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.24 2000/12/28 01:48:09 kmaples Exp $
d238 1
d240 1
a240 1
            => [$sandbox, $htdoc_root, $project_name, $domain_name, $brand_name, $description],
d242 4
a245 1
            => [$htdoc_root, $project_name, $domain_name, $brand_name],
d266 4
@


1.24
log
@Implemented the following changes to support single-db installations of
IZ based on conversations with CC - these changes only apply to elements
in issuezilla.  When IZ is in single-db mode:

* Users are added if the do not exist
* User roles are flattened to either 'observer' or 'admin'
* User accounts are NOT updated with new permissions if they already exist
* User accounts are NOT deleted
* Projects are NOT deleted

The presumption in most/all of these cases is that the admin will be
responsible for manually performing these functions through IZs interface.
All of these changes are to prevent helm updates from inadvertently trashing
users' priviliges in one project when they are changed in another project,
since in single-db mode there's no provision for differentiation.  I
expect to refine this in the near-future.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.23 2000/12/27 22:57:44 kmaples Exp $
d102 1
a102 1
        $issues_realname, $issues_username, $issues_role){
d122 3
d248 1
d250 1
a250 1
            => [$sandbox, $htdoc_root, $project_name, $domain_name, $brand_name],
d252 3
a254 1
            => [$sandbox, $htdoc_root, $project_name, $domain_name, $brand_name],
@


1.23
log
@Framework changes to recognize whether database type is set to single or
multiple.  This implements no changes in the behavior of the scripts, only
changes in the framework.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.22 2000/12/20 20:43:56 kmaples Exp $
a136 1

a139 13
#    if($issues_role =~ m/^super/){
#        $issues_role = $super_user;
#    } elsif($issues_role =~ m/^admin/){ 

    if($issues_role =~ m/^admin/){ 
        $issues_role = $admin_user;
    } elsif($issues_role =~ m/^devel/){
        $issues_role = $developer_user;
    } else {
	# Default to the observer, then:
        $issues_role = $observer_user;
    }

d175 1
d181 2
a182 1
        if(multiple_dbs){
d187 23
a209 1
        
@


1.22
log
@I told edk I would, and so I did; the perl project creation scripts now use
posix-style named args.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.21 2000/11/28 22:00:23 kmaples Exp $
d127 5
a131 3
    my $project_database;                  # This is the 'translated' database name, after
                                           # accounting for project id. 
 
d189 12
d225 1
a225 1
        'apache-project-add'     
d227 1
a227 1
        'apache-project-delete'  
d229 1
a229 1
        'cvs-module-add'     
d231 1
a231 1
        'cvs-module-delete'  
d233 1
a233 1
        'cvs-module-edit'    
d235 1
a235 1
        'cvs-project-add'    
d237 1
a237 1
        'cvs-project-delete'     
d240 25
a264 14
        'issuezilla-project-add'
            => [$sandbox, $project_name, $project_database, $domain_name],
        'issuezilla-project-delete'
            => [$sandbox, $project_name, $project_database, $domain_name],
        'issuezilla-module-add'
            => [$sandbox, $project_name, $project_database, $domain_name, $module_name, $module_description],
        'issuezilla-module-delete'
            => [$sandbox, $project_name, $project_database, $domain_name, $module_name, $module_description],
	'issuezilla-user-add'
	    => [$project_name, $project_database, $domain_name, $issues_realname, $issues_username, $issues_role],
        'issuezilla-user-edit'
            => [$project_name, $project_database, $domain_name, $issues_realname, $issues_username, $issues_role],
        'issuezilla-user-delete'
            => [$project_name, $project_database, $domain_name, $issues_username],
@


1.21
log
@Disabled 'superuser' in issuezilla; Leonard and I decided that it was
irrelevant (as opposed to admin).
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.20 2000/11/28 18:39:27 kmaples Exp $
d81 42
a122 1
    # Arguments:
a125 12
    $domain_name        = $ARGV[0]  || ''; # helm:HELM_DOMAIN.NAME
    $project_name       = $ARGV[1]  || ''; # helm:HELM_PROJECT.NAME
    $project_id         = $ARGV[2]  || ''; # helm:HELM_PROJECT.PROJECT_ID
    $brand_name         = $ARGV[3]  || ''; # --ignore---
    $description        = $ARGV[4]  || ''; # helm:HELM_PROJECT.SHORT_DESCRIPTION
    $module_name        = $ARGV[5]  || ''; # --hardcoded, e.g., 'www' --
    $module_description = $ARGV[6]  || ''; # --hardcoded
    $is_web             = $ARGV[7]  || ''; # --hardcoded
    $issues_realname    = $ARGV[8]  || ''; # joist:User.name
    $issues_username    = $ARGV[9]  || ''; # joist:User.loginID
    $issues_role        = $ARGV[10] || ''; # --translation; this should be ('admin'|'user');
                                           # former is project creator, latter is added user
@


1.20
log
@Modifications to differentiate between superuser, admin, developer and
observer.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.19 2000/11/16 21:58:53 kmaples Exp $
d106 2
d110 5
a114 3
    if($issues_role =~ m/^super/){
        $issues_role = $super_user;
    } elsif($issues_role =~ m/^admin/){ 
@


1.19
log
@Tweaking emailing when MAIL_PREFIX is set.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.18 2000/11/16 20:42:13 kmaples Exp $
d101 13
a113 7
    ## This is the IZ-specific translation to the bitvalues IZ uses to determine
    ## privileges: 
    my $superusergroupset = "9223372036854775807";
    my $averageusergroupset = "96";	 	

    if($issues_role =~ m/admin/){ 
        $issues_role = $superusergroupset;
d115 2
a116 1
        $issues_role = $averageusergroupset;
@


1.18
log
@Changed username construction from MAIL_PREFIX.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.17 2000/11/16 05:46:52 kmaples Exp $
d158 3
@


1.17
log
@Typo in communicating the mail prefix.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.16 2000/11/16 04:39:04 kmaples Exp $
d159 1
a159 1
        foreach(@@tmp){ $_ = join('-',$iz_mail_pfx, $_); }
@


1.16
log
@Fixing user add.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.15 2000/11/16 00:38:49 kmaples Exp $
d159 1
a159 1
        foreach(@@tmp){ join('-',$iz_mail_pfx, $_); }
@


1.15
log
@Changed presumptive mailing addresses to be <user>@@<project>.<domain>
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.14 2000/11/13 19:51:38 kmaples Exp $
d149 12
@


1.14
log
@Deprecated by .in file from newhelm.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.5 2000/11/01 20:28:31 kmaples Exp $
d180 1
a180 1
	    => [$project_database, $domain_name, $issues_realname, $issues_username, $issues_role],
d182 1
a182 1
            => [$project_database, $domain_name, $issues_realname, $issues_username, $issues_role],
d184 1
a184 1
            => [$project_database, $domain_name, $issues_username],
@


1.13
log
@Some refactoring, and deprecated the use of the '.in' file in favor of
environmentals (which were being used as such anyway).
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.12 2000/09/13 22:49:12 kmaples Exp $
d63 1
a63 1
    return "__SANDBOX__";
d68 1
a68 1
    return "__HTDOC_ROOT__";
d76 2
a77 4
    # really just a passthrough for '_perform()', but defines the 
    # interface between the parent scripts and the child scripts
    # by defining the hashes that map value 'token' to @@ARGV, and 
    # 'action' token to the list of args it takes/requires.
d79 1
a79 1
	my $action = shift;
a81 22
    # This replaces the arbitrary assignment of args to tokens, and is
    # shared by all scripts of this kind.  Keys are then mapped to the
    # corresponding element lists specified in the %action_to_args
    # hash, which in turn specifies which of these args gets passed
    # to the 'child' scripts.  NOTE: numbering starts from $ARGV[4] to
    # account for the first four args which are being set at installation
    # time.  At some point, it is expected that they will be passed
    # in as args as well by the calling servlet:

    my %arg_values = (
        'htdoc_root'         => $ENV{'HTDOC_ROOT'} || get_htdoc_root(),
        'sandbox'            => $ENV{'SANDBOX'} || get_sandbox(),
        'domain_name'        => $ARGV[0]  || '',
        'project_name'       => $ARGV[1]  || '',
        'brand_name'         => $ARGV[2]  || '',
        'description'        => $ARGV[3]  || '',
        'module_name'        => $ARGV[4]  || '',
        'module_description' => $ARGV[5]  || '',
        'is_web'             => $ARGV[6]  || '',
        'was_web'            => $ARGV[7]  || '',
        'is_private'         => $ARGV[8]  || '',
    );
d83 69
a151 2
    ## This holds arrays of tokens for each action which map to the
    ## command-line arguments put into the %arg_values hash.
a153 2
    ## Note that the presence of a token here in the value side of the
    ## hash means that it is implicitly required:
d157 1
a157 1
            => ['sandbox', 'htdoc_root', 'project_name', 'domain_name', 'brand_name', 'description'],
d159 1
a159 1
            => ['htdoc_root', 'project_name', 'domain_name', 'brand_name'],
d161 1
a161 1
            => ['sandbox', 'htdoc_root', 'project_name', 'domain_name', 'brand_name', 'module_name', 'module_description', 'is_web', 'is_private'],
d163 1
a163 1
            => ['sandbox', 'htdoc_root', 'project_name', 'domain_name', 'brand_name', 'module_name', 'is_web'],
d165 1
a165 1
            => ['sandbox', 'htdoc_root', 'project_name', 'domain_name', 'brand_name', 'module_name', 'is_web', 'was_web', 'is_private'],
d167 1
a167 1
            => ['sandbox', 'htdoc_root', 'project_name', 'domain_name', 'brand_name', 'is_private'],
d169 16
a184 9
            => ['sandbox', 'htdoc_root', 'project_name', 'domain_name', 'brand_name'],
        'bugzilla-project-add'
            => [],
        'bugzilla-project-delete'
            => [],
        'bugzilla-module-add'
            => [],
	'bugzilla-module-delete'
	    => [],
d186 1
a186 10
    
    return(_perform($action, \%arg_values, \%action_to_args));
}
#-------------------
sub _perform {
#-------------------
    # Syntax:  _perform(action, \%arg_values, \%action_to_args));
    # Returns: 1 or 0

    my ($function, $elements_ref, $act_ref) = @@_;
d189 3
d197 5
a201 18


    # Nasty sharp pointy things: this just retrieves the original list
    # stored in the hashtable:
    my @@args = @@{ $act_ref->{$function} };

    # Now we replace those keys with their values as declared:
    foreach(@@args){
        # bail out if no value defined for 'required' key:
        my $current_value = $elements_ref->{$_};
        unless(defined($current_value)){
            print "WARNING: No value was set for '$_' token.\n";
            return(0);
        }
        # replace the key w/ its actual value:
        $_ = $current_value;
    }

d205 2
a206 2
    $ret = system("$script_path/$function",@@args);

d212 1
a212 1
        print "EXECUTED: $function @@args\n";
d215 1
a215 1
        print "FAILED: $function @@args\n";
d222 1
@


1.12
log
@Bad hash declarations removed.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.11 2000/09/13 22:33:46 kmaples Exp $
@


1.11
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: ParentChildArgumentBridge.pl.in,v 1.10 2000/09/13 21:55:36 kmaples Exp $
a93 4
       'database_name => '',
       'database_name => '',
       'database_name => '',

@


1.10
log
@Set PATH in child scripts to suppress -T warnings.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.9 2000/09/12 16:28:06 kmaples Exp $
d70 1
@


1.9
log
@Stubs for bugzilla-related functions
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.8 2000/09/11 19:52:16 kmaples Exp $
d93 4
@


1.8
log
@Fixed call to 'child' scripts to use an absolute path derived from SANDBOX
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.7 2000/09/11 19:35:40 kmaples Exp $
d128 8
@


1.7
log
@Changed scripts to set PATH; HTDOC_ROOT and SANDBOX are being taken from ENV
again - this was in order to overcome a problem with the calling servlet not
knowing what it's CWD was, thus causing 'require' statments to fail.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.6 2000/09/08 20:52:02 kmaples Exp $
d142 6
d167 1
a167 1
    $ret = system("./$function",@@args);
@


1.6
log
@Not everybody has . in their path.  Fixed system call to account for this.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.5 2000/09/08 20:38:18 kmaples Exp $
d93 11
a103 11
        'htdoc_root'         => get_htdoc_root(),
        'sandbox'            => get_sandbox(),
        'domain_name'        => $ARGV[2]  || '',
        'project_name'       => $ARGV[3]  || '',
        'brand_name'         => $ARGV[4]  || '',
        'description'        => $ARGV[5]  || '',
        'module_name'        => $ARGV[6]  || '',
        'module_description' => $ARGV[7]  || '',
        'is_web'             => $ARGV[8]  || '',
        'was_web'            => $ARGV[9]  || '',
        'is_private'         => $ARGV[10] || '',
@


1.5
log
@As long as we're using a hack here to expose vars from tokens, I thought I'd
be consistent; this defines two routines 'get_sandbox()' and 'get_htdoc_root()'
which return their respective values from the tokens, and everything else
gets values for these from the routines.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.4 2000/09/08 20:21:37 kmaples Exp $
d161 1
a161 1
    $ret = system($function,@@args);
@


1.4
log
@Changed SANDBOX to come from function in ParentChildArgumentBridge.pl so
that logging would function properly
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.3 2000/09/07 03:12:41 kmaples Exp $
d65 5
d93 2
a94 2
        'htdoc_root'         => '__HTDOC_ROOT__',
        'sandbox'            => '__SANDBOX__',
@


1.3
log
@Brought apache-project-delete into agreement with the current definition
of adding/deleting projects with respect to apache (e.g., existence of
directory under HTDOC_ROOT for project)
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.2 2000/09/06 18:56:47 kmaples Exp $
d57 8
@


1.2
log
@Removed depricated tokens APACHE_HOST_IP and APACHE_HELM_CONF from the arg list; adjusted child scripts accordingly.  Introduced new test harness (work in progress).
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.1 2000/09/05 20:06:38 kmaples Exp $
d104 1
a104 1
            => ['sandbox', 'htdoc_root', 'project_name', 'domain_name', 'brand_name'],
@


1.1
log
@Refactored common hash definitions, subroutine definition into new library
@
text
@d51 1
a51 1
# $Id: $
a79 2
        'apache_host_ip'     => '__APACHE_HOST_IP__',
        'apache_helm_conf'   => '__APACHE_HELM_CONF__',
d82 9
a90 9
        'domain_name'        => $ARGV[4]  || '',
        'project_name'       => $ARGV[5]  || '',
        'brand_name'         => $ARGV[6]  || '',
        'description'        => $ARGV[7]  || '',
        'module_name'        => $ARGV[8]  || '',
        'module_description' => $ARGV[9]  || '',
        'is_web'             => $ARGV[10] || '',
        'was_web'            => $ARGV[11] || '',
        'is_private'         => $ARGV[12] || '',
d102 1
a102 1
            => ['sandbox', 'apache_host_ip', 'apache_helm_conf', 'htdoc_root', 'project_name', 'domain_name', 'brand_name', 'description'],
d104 1
a104 1
            => ['sandbox', 'apache_helm_conf', 'htdoc_root', 'project_name', 'domain_name', 'brand_name'],
@


1.1.1.1
log
@Merging newhelm tree into helm, as per IZ issue #557.  Previous major version of helm is tagged TIGRIS_NOV_11_2000.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.5 2000/11/01 20:28:31 kmaples Exp $
a57 14
# This is a hack to make sandbox exposed to the calling scripts for 
# logging purposes:
#-------------------
sub get_sandbox {
#-------------------
    return($ENV{'SANDBOX'});
}
#-------------------
sub get_htdoc_root {
#-------------------
    return($ENV{'HTDOC_ROOT'});
}


d62 4
a65 2
    # Defines the interface between the parent scripts and the child scripts
    # by maping values from @@ARGV to the args needed by the child scripts.
d67 1
a67 1
    my $action = shift;
d70 24
d95 2
a96 69
    $htdoc_root         = $ENV{'HTDOC_ROOT'};
    $sandbox            = $ENV{'SANDBOX'};
    $domain_name        = $ARGV[0]  || ''; # helm:HELM_DOMAIN.NAME
    $project_name       = $ARGV[1]  || ''; # helm:HELM_PROJECT.NAME
    $project_id         = $ARGV[2]  || ''; # helm:HELM_PROJECT.PROJECT_ID
    $brand_name         = $ARGV[3]  || ''; # --ignore---
    $description        = $ARGV[4]  || ''; # helm:HELM_PROJECT.SHORT_DESCRIPTION
    $module_name        = $ARGV[5]  || ''; # --hardcoded, e.g., 'www' --
    $module_description = $ARGV[6]  || ''; # --hardcoded
    $is_web             = $ARGV[7]  || ''; # --hardcoded
    $issues_realname    = $ARGV[8]  || ''; # joist:User.name
    $issues_username    = $ARGV[9]  || ''; # joist:User.loginID
    $issues_role        = $ARGV[10] || ''; # --translation; this should be ('admin'|'user');
                                           # former is project creator, latter is added user

    my $project_database;                  # This is the 'translated' database name, after
                                           # accounting for project id. 
 
    ## This is the IZ-specific translation to the bitvalues IZ uses to determine
    ## privileges: 
    my $superusergroupset = "9223372036854775807";
    my $averageusergroupset = "96";	 	

    if($issues_role =~ m/admin/){ 
        $issues_role = $superusergroupset;
    } else {
        $issues_role = $averageusergroupset;
    }

    ## Terrible hack requiring refactoring:  this is now a static identifier 
    ## used to create a bogus password entry so that helm doesn't have to be
    ## consulted ... since 'localconfig' is already being read in below, I need
    ## to move the identifier there so that this needen't be duplicated:

    $ENV{ISSUZILLA_PASSWORD} = 'password'; 

    ## Scary, scary ... havent figured out exactly how I want to do this yet,
    ## but I need to set mysql root values for the issuezilla-project-create
    ## script:

    $ENV{DATABASE_ROOTUSER} = '__DATABASE_ADMIN_USER__' || '';
    $ENV{DATABASE_ROOTPASS} = '__DATABASE_ADMIN_PASSWORD__' || '';

    ## Terrible, terrible hack:  if $action is an issuezilla thing, we
    ## need to determine which database to talk to.  This reqires 
    ## checking which mode issuezilla is in (one or many issue databases).
    ## So we do the same thing which happens with issuezilla at run-time:
    ## set the environmental for HTTP_PROJECT_ID (this would normally be
    ## set by SecureNoodle in the http headers), read in issuezilla's 
    ## 'localconfig' file, and then swipe the value it sets for the 
    ## database name.  Then we set $ENV{DATABASE_NAME} so that the children 
    ## use the correct DB:
    
    if($action =~ m/^issuezilla/){
        my $izconfig = $sandbox . '/issuezilla/localconfig';

        $ENV{HTTP_HELM_HELM_PROJECT_PROJECT_ID} = $project_id;

        print "  Set HTTP_HELM_HELM_PROJECT_PROJECT_ID to $ENV{HTTP_HELM_HELM_PROJECT_PROJECT_ID}\n";

        unless( do "$izconfig" ){
           print "FAILED: $action - unable to find issuezilla config file\n";
           return(0);
        }
        $project_database = $db_name;        
        print "  Setting project database to $project_database\n";
    }

    ## This holds arrays of values for each action.
d99 2
d104 1
a104 1
            => [$sandbox, $htdoc_root, $project_name, $domain_name, $brand_name, $description],
d106 1
a106 1
            => [$htdoc_root, $project_name, $domain_name, $brand_name],
d108 1
a108 1
            => [$sandbox, $htdoc_root, $project_name, $domain_name, $brand_name, $module_name, $module_description, $is_web],
d110 1
a110 1
            => [$sandbox, $htdoc_root, $project_name, $domain_name, $brand_name, $module_name, $is_web],
d112 1
a112 1
            => [$sandbox, $htdoc_root, $project_name, $domain_name, $brand_name, $module_name, $module_description, $is_web],
d114 1
a114 1
            => [$sandbox, $htdoc_root, $project_name, $domain_name, $brand_name],
d116 10
a125 1
            => [$sandbox, $htdoc_root, $project_name, $domain_name, $brand_name],
d127 1
a127 16
        'issuezilla-project-add'
            => [$sandbox, $project_name, $project_database, $domain_name],
        'issuezilla-project-delete'
            => [$sandbox, $project_name, $project_database, $domain_name],
        'issuezilla-module-add'
            => [$sandbox, $project_name, $project_database, $domain_name, $module_name, $module_description],
        'issuezilla-module-delete'
            => [$sandbox, $project_name, $project_database, $domain_name, $module_name, $module_description],
	'issuezilla-user-add'
	    => [$project_database, $domain_name, $issues_realname, $issues_username, $issues_role],
        'issuezilla-user-edit'
            => [$project_database, $domain_name, $issues_realname, $issues_username, $issues_role],
        'issuezilla-user-delete'
            => [$project_database, $domain_name, $issues_username],
    );
 
d130 17
a146 13
 
    # No point in continuing if the action wasn't defined: 
    return(0) unless $action_to_args{$action};

    # This is a work-around for the fact that the current working directory
    # doesn't really have any meaning to the calling servlet - so we have
    # to call child scripts based on their relation to the sandbox:
    my $script_path = $ENV{'SANDBOX'} . '/helm/perl/scripts';
    
    # Nasty sharp pointy things: this just retrieves the arg list
    # stored in the hashtable for this particular action:   
    my @@args = @@{ $action_to_args{$action} };
 
d150 2
a151 2
    $ret = system("$script_path/$action",@@args);
    
d157 1
a157 1
        print "EXECUTED: $action @@args\n";
d160 1
a160 1
        print "FAILED: $action @@args\n";
a166 1

@


1.1.1.2
log
@Replacing the HEAD with the HELM_PEER_PORT_BRANCH.
@
text
@d51 1
a51 1
# $Id: ParentChildArgumentBridge.pl.in,v 1.32 2001/01/15 20:54:40 kmaples Exp $
d58 13
d81 1
a81 45
    # From now on, we'll use '--named' arguments:

    use Getopt::Long;

    # And now, the args and their values: 

    # --domain_name         helm:HELM_DOMAIN.NAME
    # --project_name        helm:HELM_PROJECT.NAME
    # --project_id          helm:HELM_PROJECT.PROJECT_ID
    # --brand_name          --ignore---
    # --description         helm:HELM_PROJECT.SHORT_DESCRIPTION
    # --module_name         --hardcoded, e.g., 'www' --
    # --module_description  --hardcoded--
    # --is_web              --hardcoded--
    # --issues_realname     joist:User.name
    # --issues_username     joist:User.loginID
    # --issues_role         'super|admin|devel|observ'

    ## Init the vars used to hold the options: 
    foreach($domain_name, $project_name, $project_id, $brand_name,
        $description, $module_name, $module_description, $is_web,
        $issues_realname, $issues_username, $issues_role, $new_project_name){

        $_ ||= '';
    }


    GetOptions(

      'domain_name=s'        => \$domain_name,        
      'project_name=s'       => \$project_name,       
      'project_id=i'         => \$project_id,         
      'brand_name=s'         => \$brand_name,         
      'description=s'        => \$description,        
      'module_name=s'        => \$module_name,        
      'module_description=s' => \$module_description, 
      'is_web=s'             => \$is_web,             
      'issues_realname=s'    => \$issues_realname,    
      'issues_username=s'    => \$issues_username,    
      'issues_role=s'        => \$issues_role,        

      # Replacement values:  

      'new_project_name=s'   => \$new_project_name,
    );
d85 12
d98 7
a104 2
    my $project_database;   # This is the 'translated' database name, after
                            # accounting for project id. 
d106 5
a110 9
    my $multiple_dbs;       # DB setting.

    ## These numbers correspond to the bit sets of permissions
    ## in issuezilla ('SELECT * FROM groups' to view them):
    my $observer_user  = "0";
    my $developer_user = "96";
    my $admin_user     = "127";
    ## Unused, but this represents the highest bitset a user can have:
    my $super_user     = "9223372036854775807";
a124 2
    $ENV{DATABASE_PORT}     = '__DATABASE_PORT__' || '';    
    $ENV{DATABASE_HOST}     = '__DATABASE_HOST__' || '';    
a146 36

        ## Since we just sourced it in, set a variable to hold the 
        ## single/multiple db flag.  This may be examined by the scripts 
        ## which manage user accounts, as their behavior differs depending.

        $multiple_dbs = $::use_project_id_database || 0;  

        if($multiple_dbs){
            print "  Database flag set to MULTIPLE\n";
        } else {
            print "  Database flag set to SINGLE\n";
        }

        # Now evaluate and set the user's role:      

        if($issues_role      =~ m/^super/){
            $issues_role = $super_user;
        } elsif($issues_role =~ m/^admin/){ 
            $issues_role = $admin_user;
        } elsif($issues_role =~ m/^devel/){
            $issues_role = $developer_user;
        } else {
            # Default to the observer, then:
            $issues_role = $observer_user;
        }

        ## Now, if we're in single-db mode, disregard all the hard
        ## work we just went to and flatten the roles, since everyone
        ## but the admins are observers, and it's left to the admins
        ## to manually manage their users through IZ:

        if(!$multiple_dbs && ( $issues_role < $admin_user )){
            $issues_role = $observer_user;
        }

        ## Now set the database:  
a150 15
    ## This is largely for sandboxing - if the prefix var is sent in env.sh at
    ## install time, then this gets prepended to the email addresses:
    my $iz_mail_pfx = '__MAIL_PREFIX__' || '';
    
    ## And this, therefore, requires refactoring from the child scripts
    ## as the logic is repeated in the child scripts:
    if($iz_mail_pfx){ 
        ## Horrible - this is so list inserts make sense in sandboxes:  
        $ENV{MAIL_PREFIX} = $iz_mail_pfx;
     
        my @@tmp = split(':', $issues_username);
        foreach(@@tmp){ $_ = $iz_mail_pfx . $_ }
        $issues_username = join(':',@@tmp); 
    }

d156 5
a160 9

    'apache-project-add'     
            => [$htdoc_root, $project_name],
    'apache-project-delete'  
            => [$htdoc_root, $project_name],
    'apache-project-edit'
            => [$htdoc_root, $project_name, $new_project_name],

    'cvs-module-add'     
d162 1
a162 1
    'cvs-module-delete'  
d164 1
a164 1
    'cvs-module-edit'    
d166 19
a184 40

    'cvs-project-add'    
            => [$sandbox, $project_name],
    'cvs-project-delete'     
            => [$sandbox, $project_name],
    'cvs-project-edit'
            => [$sandbox, $project_name, $new_project_name],

    'issuezilla-project-add'
            => [    $sandbox, $project_name, $project_database, 
                    $domain_name, $multiple_dbs],
    'issuezilla-project-delete'
            => [    $sandbox, $project_name, $project_database, 
                    $domain_name, $multiple_dbs],
    'issuezilla-project-edit'
            => [    $sandbox, $project_name, $project_database,
                    $domain_name, $multiple_dbs, $new_project_name],

    'issuezilla-module-add'
            => [    $sandbox, $project_name, $project_database, 
                    $domain_name, $module_name, $module_description,
                    $multiple_dbs],
    'issuezilla-module-delete'
            => [    $sandbox, $project_name, $project_database, 
                    $domain_name, $module_name, $module_description,
                    $multiple_dbs],
    'issuezilla-user-add'
	        => [    $project_name, $project_database, $domain_name,
                    $issues_realname, $issues_username, $issues_role,
                    $multiple_dbs ],
    'issuezilla-user-edit'
            => [    $project_name, $project_database, $domain_name, 
                    $issues_realname, $issues_username, $issues_role,
                    $multiple_dbs],
    'issuezilla-user-delete'
            => [    $project_name, $project_database, $domain_name, 
                    $issues_username, $multiple_dbs],
    'issuezilla-user-disableall'
            => [    $project_database, $multiple_dbs  ],

a217 85
}
# Alpha and Omega:
BEGIN {
    $ENV{'PATH'} = "/bin:/usr/bin:/usr/local/bin";

    unless($ENV{'SANDBOX'}){
        print "FATAL: SANDBOX not set; exiting.\n";
        exit(1); 
    }

    # Open the logfile for logging at the beginning of execution.
    # The primary reason for this is to 'die' before doing anything
    # that we won't be able to log, and opening the log filehandle
    # in the beginning ensures this.

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

    # Autoflush buffer:
    $| = 1;

    # If this program is called by another program, we'll send STDOUT
    # and SDTERR to the logfile - this way the children's messages will
    # stick with the parent's logs.  Conversely, if this is called
    # interactively (on the command line), we'll send it to both the 
    # terminal and the logfile:

    # This needs to be established dynamically; I don't know the
    # preferred method for arriving at this value:
    my $logdir   = '__SANDBOX__/log/';

    my $logfile  = 'HelmPerlScripts.log';

    if(!(-t STDIN && -t STDOUT)){
        # Point STDOUT and STDERR to the logfile, or bail out:
        unless(open(STDOUT,">> $logdir" . "$logfile") && open(STDERR,">&STDOUT")){
            die "Can't open handle for logging: $!\n";
        }
    } else {
        # Point STDOUT and STDERR to the logfile, or bail out:
        unless(open(STDOUT,"| tee -a $logdir" . "$logfile") && open(STDERR,">&STDOUT")){
            die "Can't open handle for logging: $!\n";
        }
    }

    # This shouldn't really be necessary, but it couldn't hurt:
    select(STDERR); $| = 1;
    select(STDOUT); $| = 1;

    # This might appear odd, but since STDOUT is now a filehandle
    # for the logfile, try to get a lock on it, or bail out:
    unless(flock(STDOUT, 2|4)){ # Ask nice first.
        sleep 1;
        unless(flock(STDOUT, 2)){
            die "Unable to lock logfile: $!\n";
        }
   }

    # This is all in order to print a nice header for the log
    # entry:

    my $time   = time();
    my $date   = localtime($time);
    my $header = "[$date]\n[$$] START: $::script_name " . join(' ',@@ARGV) . "\n";

    print $header;
}
END {
    # Note that because END blocks are executed from bottom to top,
    # this block should appear BEFORE any other END blocks trying
    # to print to the same filehandle.  This might seem unnecessary,
    # but since we did point these at a file, we really ought to
    # clean up after ourselves:

    my $footer = "[$$] END: $::script_name\n\n";

    print $footer;
    
    # I haven't figured out why this is the case, but if 'tee' is 
    # used, trying to close these causes the program to hang while
    # waiting for an eof.  Just bugging out seems to work, though.
#    close(STDOUT) or die "Couldn't close logging handle STDOUT: $!\n";
#    close(STDERR) or die "Couldn't close logging handle STDERR: $!\n";
@


