head	1.13;
access;
symbols
	TIGRIS_1_1_0RC2:1.12
	TIGRIS_1_1_0RC1:1.12
	TIGRIS_1_1:1.12.0.4
	TIGRIS_1_0_8:1.12
	TIGRIS_1_0_8RC3:1.12
	TIGRIS_1_0_8RC2:1.12
	TIGRIS_1_0_8RC1:1.12
	TIGRIS_1_0_7:1.12
	TIGRIS_1_0_7RC3:1.12
	TIGRIS_1_0_7RC2:1.12
	TIGRIS_1_0_7RC1:1.12
	TIGRIS_1_0_6:1.12
	TIGRIS_1_0_6RC5:1.12
	TIGRIS_1_0_6RC4:1.12
	TIGRIS_1_0_6RC3:1.12
	TIGRIS_1_0_6RC2:1.12
	TIGRIS_1_0_6RC1:1.12
	TIGRIS_1_0_5:1.12
	TIGRIS_1_0_5RC6:1.12
	TIGRIS_1_0_5RC5:1.12
	TIGRIS_1_0_5RC4:1.12
	TIGRIS_1_0_5RC3:1.12
	TIGRIS_1_0_5RC2:1.12
	TIGRIS_1_0_5RC1:1.12
	TIGRIS_1_0_4:1.12
	TIGRIS_1_0_3:1.12
	TIGRIS_1_0_2:1.12
	TIGRIS_1_0_1:1.12
	TIGRIS_1_0:1.12.0.6
	TIGRIS_1_0_0:1.12
	TIGRIS_1_0_0_RC1:1.12.0.2
	dlr:1.1.1
	TIGRIS_0_9_2_4:1.10
	TIGRIS_0_9_2_3:1.10
	HELM_PEER_PORT_BRANCH:1.1.1.2
	TURBINE_PEER:1.10
	TIGRIS_0_9_2_1:1.10
	TIGRIS_0_9_2:1.10.0.10
	TIGRIS_0_9_0:1.10.0.8
	TIGRIS_0_8_4:1.10.0.6
	NEWHELM:1.1.1.1
	TIGRIS_NOV_12_2000:1.1.1
	OLDHELM:1.10.0.4
	TIGRIS_NOV_11_2000:1.10
	TIGRIS_SEP_13_2000:1.10.0.2
	TIGRIS_BASELINE:1.10;
locks; strict;
comment	@# @;


1.13
date	2001.08.14.21.57.24;	author edk;	state dead;
branches;
next	1.12;

1.12
date	2001.02.09.00.41.01;	author edk;	state Exp;
branches;
next	1.11;

1.11
date	2001.02.09.00.20.24;	author edk;	state Exp;
branches;
next	1.10;

1.10
date	2000.07.20.21.19.49;	author ed;	state Exp;
branches
	1.10.12.1;
next	1.9;

1.9
date	2000.07.18.03.11.34;	author ed;	state Exp;
branches;
next	1.8;

1.8
date	2000.07.13.23.15.38;	author ed;	state Exp;
branches;
next	1.7;

1.7
date	2000.07.13.08.36.24;	author ed;	state Exp;
branches;
next	1.6;

1.6
date	2000.07.13.03.25.47;	author ed;	state Exp;
branches;
next	1.5;

1.5
date	2000.05.02.21.55.49;	author manoj;	state Exp;
branches;
next	1.4;

1.4
date	2000.05.02.18.15.37;	author jrobbins;	state Exp;
branches;
next	1.3;

1.3
date	2000.05.01.21.35.30;	author jrobbins;	state Exp;
branches;
next	1.2;

1.2
date	2000.02.03.04.21.34;	author jrobbins;	state Exp;
branches;
next	1.1;

1.1
date	2000.01.30.03.22.37;	author jrobbins;	state Exp;
branches
	1.1.1.1;
next	;

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

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

1.10.12.1
date	2001.02.17.19.01.45;	author leonardr;	state Exp;
branches;
next	;


desc
@@


1.13
log
@remove obsolete/non-functional scripts
@
text
@# ================================================================
# 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.
#


# Helm/QmailLists.pm
# --------------------
# Update/create mailing lists using ezmlm-idx (the qmail mailing list
# utility).
#
# Note that qmail must be set up correctly; see Helm::QmailAlias for
# more information on the requirements.
#
# We create mailing lists as both project-list@@domain.org and
# list@@project.domain.org. The cute thing is that due to the way
# qmail expands aliases, they both expand to .qmail-project-list, so
# we don't worry too much.
#
# For domain-wide lists, we use the NULL project in the table
# (project_mlists).

package Helm::QmailLists;

use Helm::Updater;
@@ISA = qw(Helm::Updater);

use strict;
use Helm::Config;
use Helm::TableSync;

use Helm::QmailUtils;

# the option columns, and the letter option they refer to
my @@options = (['archived', 'a'],
	    ['digest', 'd'],
	    ['prefix', 'f'],
	    ['guard_archive', 'g'],
	    ['indexed', 'i'],
	    ['kill_opt', 'k'],
	    ['list_subs', 'l'],
	    ['message_moderation', 'm'],
	    ['new_text_file', 'n'],
	    ['public', 'p'],
	    ['request_address', 'q'],
	    ['remote_admin', 'r'],
	    ['sub_moderation', 's'],
	    ['trailer', 't'],
	    ['user_posts_only', 'u'],
	    ['address_restriction', 'w'],
	    ['extra', 'x']);
my @@optcols = map { $_->[0]; } @@options;
my @@optswitches = map { $_->[1]; } @@options;

sub user {
    my ($class, $db) = @@_;
    return $db->config('qmail_user');
}

# update Helm::QmailLists $db;
sub update {
    my ($class, $db) = @@_;
    my $home = Helm::QmailUtils::home($db);

    my $ts = new Helm::TableSync($db, 'project_mlists', [qw(list project)],
				   "$home/tigris-ezmlm", \&_ezmlm_map);
    $ts->check($home, \&_ezmlm_add, \&_ezmlm_del, \&_ezmlm_check,
	       ['owner', 'sublist', @@optcols]);
}

# _ezmlm_map($home, $db, $cols)
sub _ezmlm_map {
    my ($home, $db, $cols) = @@_;
    my ($list, $project) = @@$cols;

    # lowercase project and list
    $list = lc($list);
    $project = lc($project);

    # www is a special project -- it shouldn't appear w/ mailing lists
    if ($project eq "www") {
        $project = undef;
    }

    return $project ? "$home/$project-$list" : "$home/$list";
}

# _ezmlm_make($db, $home, $list, $project, $switches, $owner, $sublist, @@opts)
# Run the ezmlm-make program, for creating or updating a mailing list.
# $switches is a string with any initial options, such as -e to edit
# $xcols should be a reference to a list of the values for owner, sublist,
# and then the options listed in @@options, in order.
sub _ezmlm_make {
    my ($db, $home, $list, $project, $switches, $owner, $sublist, @@opts) = @@_;

    # this is hackish, but works: if $switches eq "", then we're creating
    # the list -- we'll want to add the mhonarc archiver
    my $add_archiver_flag = $switches eq '';
    
    # pertinent config info
    my ($edir, $domain) = ($db->config('ezmlm_bindir'),
			   $db->config('domain_dns'));


    # Set up the switches
    for (my $i = 0; $i < @@optswitches; $i++) {
	# On is lowercase, off is uppercase
	if ($opts[$i] && $opts[$i] eq 'Y') {
	    $switches .= " -\l$optswitches[$i]";
	} else {
	    $switches .= " -\u$optswitches[$i]";
	}
    }
    $switches .= " -0 $sublist" if ($sublist);
    $switches .= " -5 $owner" if ($owner);

    # make project and list lower case, 'since that's how qmail will look for
    # them
    $project = lc($project);
    $list = lc($list);

    # www is a special project -- it shouldn't appear w/ mailing lists
    # (except to mhonarc, which we'll use later)
    my $saved_project = $project;
    if ($project eq "www") {
        $project = undef;
    }

    # Call ezmlm-make to create the list. Note that we'd better have
    # permission, but that's not quite our problem yet.
    my $lname = $project ? "$project-$list" : $list;
    my $dname = $project ? "$project.$domain" : $domain;
    my $rcfile = "-C $home/ezmlmrc";
    my $cmd = "$edir/ezmlm-make $rcfile $switches $home/$lname " .
	"$home/.qmail-$lname $lname $domain";
    print "QmailLists _ezmlm_make: <tt>$cmd</tt>\n";
    system($cmd)
	== 0 or die "There should be some kind of error here: $!\n";
    if ($add_archiver_flag) {
        # we do this specialliy because we want to include www for mhonarc/
        # the web archives, but not otherwise.  it's very hackish.
        my $archiver_lname = $saved_project ? "$saved_project-$list" : $list;
        $cmd = "$edir/ezmlm-sub $home/$lname archive-$archiver_lname\@@$domain";
        print "Adding qmail archiver: <tt>$cmd</tt>\n";
        system($cmd) == 0 or warn "adding qmail archiver failed: $!\n";
    }
    # deal with msgsize
    if ($list eq 'cvs') {
        unlink "$home/$lname/msgsize";
    } else {
        open (OUT, ">$home/$lname/msgsize");
        print OUT "400000:2\n";
        close OUT;
    }
}

# _ezmlm_add($home, $db, $cols, $dir, [$project]);
sub _ezmlm_add {
    my ($home, $db, $cols, $dir, $xcols) = @@_;
    my ($list, $project) = (@@$cols);
    my ($owner, $sublist, @@opts) = @@$xcols;

    _ezmlm_make($db, $home, $list, $project, "", $owner, $sublist, @@opts);

    # add stuff for mhonarc -- note that the web archive is the one place where
    # $project eq 'www' isn't treated differently
    my $htdocs_dir = $db->config('apache_htdocs');
    my $project_dir = "$htdocs_dir/$project/www";
    open(OUT, ">>$project_dir/.cvsignore");
    print OUT " $project-$list\n";
    close OUT;
    my $archive_dir = "$project_dir/$project-$list";
    mkdir $archive_dir, 0755;
    symlink("$archive_dir", "$archive_dir/current")
        or warn "symlink failed: $!";
}


# _ezmlm_check
# Re-run make on the mailing list.
sub _ezmlm_check {
    my ($home, $db, $cols, $dir, $xcols) = @@_;
    my ($list, $project) = (@@$cols);
    my ($owner, $sublist, @@opts) = @@$xcols;
    
    # ezmlm-make is an expensive operation, and we only want to run it
    # if there have been changes. So we parse the config file to verify
    # this.
    my $changed = 0;

    open CONFIG, "$dir/config" or die "Could not open $dir/config: $!\n";
    while (my $line = <CONFIG>) {
	chomp $line;
	if ($line =~ /^F:/) {
	    # Check each of the switches to see if the option has changed
	    for (my $i = 0; $i < @@optswitches; $i++) {
		# On is lowercase, off is uppercase
		my $curr = ($opts[$i] && $opts[$i] eq 'Y')
		    ? "\l$optswitches[$i]" : "\u$optswitches[$i]";
		if ($line !~ $curr) {
		    $changed = $curr;
		    last;
		}
	    }
	    
	} elsif ($line =~ /^0:(.*)$/) {
	    if ((!$1 && $sublist) || ($1 && !$sublist)
		|| ($1 && $sublist && ($1 ne $sublist))) {
		$changed = "sublist";
		last;
	    }	    
	} elsif ($line =~ /^5:(.*)$/) {
	    if ((!$1 && $owner) || ($1 && !$owner)
		|| ($1 && $owner && ($1 ne $owner))) {
		$changed = "owner $1-$owner";
		last;
	    }
	}
    }
    close CONFIG;

    # Run ezmlm-make, and it will update the mailing list
    _ezmlm_make($db, $home, $list, $project, "-e", $owner, $sublist, @@opts)
	if $changed;
}

# _ezmlm_del($home, $db, $cols_ref, $dir)
# Doesn't ezmlm have a delete-list mechanism? Is this the best
# way to do this???
#
# Of course, one might ask if we should be deleting lists at all,
# given that you lose the archive and all other sorts of things,
# but I won't bother with that question right about now.
sub _ezmlm_del {
    my ($home, $db, $cols_ref, $dir) = @@_;
    my ($list, $project) = @@$cols_ref;

    # www is a special project -- it shouldn't appear w/ mailing lists
    if ($project eq "www") {
        $project = undef;
    }

    my $lname = $project ? "$project-$list" : $list;

    # Technically we could do this straight Perl, but this is easier.
    system("/bin/rm -rf $dir");

    # gotta love taint perl.  bleah.  for some reason, it thinks this unclean.
    if ($home!~ m/\.\./ && $home =~ m@@^(/[a-zA-Z0-9/_\.]*/[a-zA-Z0-9/_\.]*)$@@) {
        my $clean_home = $1;
        $lname =~ m/^(.*)$/;
        $lname = $1;
        system("/bin/rm -f $clean_home/.qmail-$lname*") if $lname ne '';
    } else {
        warn "didn't remove .qmail files\n";
        print "didn't remove .qmail files\n";
    }
}

# We don't do anything particular when a project is removed or added
# (everything *in* the project should have been removed first)

sub add_project {}
sub del_project {}
@


1.12
log
@handle lowercasing more completely; do it before dealing w/ 'www'
@
text
@@


1.11
log
@lowercase project and list name so they'll work if they're upper case
@
text
@d117 4
d158 5
a168 5

    # make project and list lower case, 'since that's how qmail will look for
    # them
    $project = lc($project);
    $list = lc($list);
@


1.10
log
@update .cvsignore as per niel's description.  this will probably
be replaced with another mechanism soon...
@
text
@d161 5
@


1.10.12.1
log
@Ported changes from head.
@
text
@a116 4
    # lowercase project and list
    $list = lc($list);
    $project = lc($project);

a152 5

    # make project and list lower case, 'since that's how qmail will look for
    # them
    $project = lc($project);
    $list = lc($list);
@


1.9
log
@fix a problem jrobbins pointed out: the archiver address needs to take
the www special case into account.  lightly tested.
@
text
@d200 5
a204 1
    my $archive_dir = "$htdocs_dir/$project/www/$project-$list";
@


1.8
log
@i have no clue why taint perl sometimes considers these clean and
sometimes considers them unclean.  actually, i generally have no idea
why they'd be unclean -- they come from mysql (i think), though, and
clearly we shouldn't trust anything we get from mysql.
@
text
@d155 2
d172 4
a175 1
        $cmd = "$edir/ezmlm-sub $home/$lname archive-$lname\@@$domain";
@


1.7
log
@avoid deleting mhonarc archive directory
@
text
@d274 3
a276 1
        system("/bin/rm -f $clean_home/.qmail-$lname*");
@


1.6
log
@treat www as a special project -- so you can have mailing lists which
aren't associated with a specific project.  also, create the mhonarc
directory, and add the archiver alias when we create the mailing list.
@
text
@a260 11
    # remove stuff for mhonarc -- note that the web archive is the one place
    # where $project eq 'www' isn't treated differently
    my $htdocs_dir = $db->config('apache_htdocs');
    # gotta love taint perl.  bleah.  for some reason, it thinks this unclean.
    $project =~ m/(.*)/;
    $project = $1;
    $list =~ m/(.*)/;
    $list = $1;
    my $archive_dir = "$htdocs_dir/$project/www/$project-$list";
    system("/bin/rm -f -r $archive_dir");

@


1.5
log
@Fix typo
@
text
@d116 6
d133 4
d154 5
d169 13
d191 8
d260 17
d281 9
a289 1
    system("/bin/rm -f $home/.qmail-$lname*");
@


1.4
log
@made non-vhost mailing list address the "main" address, this is needed
to make confirm messages work for non-vhost users
@
text
@d150 1
a150 1
	"$home/.qmail-$lname $lname $doman";
@


1.3
log
@Now uses a config file in $SANDBOX/tigrisq/ezmlmrc
This allows me to add -T option to ezmlm-reject, allowing optional
vhosting
And add a reply-to header
@
text
@d150 1
a150 1
	"$home/.qmail-$lname $list $dname";
@


1.2
log
@Added tigris.org license
PR:
Obtained from:
Submitted by:
Reviewed by:
@
text
@d148 2
a149 1
    my $cmd = "$edir/ezmlm-make $switches $home/$lname " .
@


1.1
log
@initial checkin
@
text
@d1 46
a46 1
# Copyright (c) 2000 Collab.Net, Inc.
@


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
@d1 1
a1 46
# ================================================================
# 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.
#

a70 6

    # www is a special project -- it shouldn't appear w/ mailing lists
    if ($project eq "www") {
        $project = undef;
    }

a81 4
    # this is hackish, but works: if $switches eq "", then we're creating
    # the list -- we'll want to add the mhonarc archiver
    my $add_archiver_flag = $switches eq '';
    
a98 7
    # www is a special project -- it shouldn't appear w/ mailing lists
    # (except to mhonarc, which we'll use later)
    my $saved_project = $project;
    if ($project eq "www") {
        $project = undef;
    }

d103 2
a104 3
    my $rcfile = "-C $home/ezmlmrc";
    my $cmd = "$edir/ezmlm-make $rcfile $switches $home/$lname " .
	"$home/.qmail-$lname $lname $domain";
a107 16
    if ($add_archiver_flag) {
        # we do this specialliy because we want to include www for mhonarc/
        # the web archives, but not otherwise.  it's very hackish.
        my $archiver_lname = $saved_project ? "$saved_project-$list" : $list;
        $cmd = "$edir/ezmlm-sub $home/$lname archive-$archiver_lname\@@$domain";
        print "Adding qmail archiver: <tt>$cmd</tt>\n";
        system($cmd) == 0 or warn "adding qmail archiver failed: $!\n";
    }
    # deal with msgsize
    if ($list eq 'cvs') {
        unlink "$home/$lname/msgsize";
    } else {
        open (OUT, ">$home/$lname/msgsize");
        print OUT "400000:2\n";
        close OUT;
    }
a116 12

    # add stuff for mhonarc -- note that the web archive is the one place where
    # $project eq 'www' isn't treated differently
    my $htdocs_dir = $db->config('apache_htdocs');
    my $project_dir = "$htdocs_dir/$project/www";
    open(OUT, ">>$project_dir/.cvsignore");
    print OUT " $project-$list\n";
    close OUT;
    my $archive_dir = "$project_dir/$project-$list";
    mkdir $archive_dir, 0755;
    symlink("$archive_dir", "$archive_dir/current")
        or warn "symlink failed: $!";
a177 6

    # www is a special project -- it shouldn't appear w/ mailing lists
    if ($project eq "www") {
        $project = undef;
    }

d182 1
a182 11

    # gotta love taint perl.  bleah.  for some reason, it thinks this unclean.
    if ($home!~ m/\.\./ && $home =~ m@@^(/[a-zA-Z0-9/_\.]*/[a-zA-Z0-9/_\.]*)$@@) {
        my $clean_home = $1;
        $lname =~ m/^(.*)$/;
        $lname = $1;
        system("/bin/rm -f $clean_home/.qmail-$lname*") if $lname ne '';
    } else {
        warn "didn't remove .qmail files\n";
        print "didn't remove .qmail files\n";
    }
@


1.1.1.2
log
@Replacing the HEAD with the HELM_PEER_PORT_BRANCH.
@
text
@a116 4
    # lowercase project and list
    $list = lc($list);
    $project = lc($project);

a152 5

    # make project and list lower case, 'since that's how qmail will look for
    # them
    $project = lc($project);
    $list = lc($list);
@


