Speaking of hacks, I did something similar although mine runs as a cron  job.  
It checks for any users that don't have a .qmail-user or .qmail-user-default 
file and creates one from a template.  There's rudimentary support for 
replacing some part of the template with the username.

Anyway, it's attached and there's some comments at the top that tell you how 
to use it.  It's definitely a hack so don't complain if it breaks everything 
on your system :).

   Cheers,
      --alex


On Friday 13 June 2003 02:15 pm, Ryan Summers wrote:
> <html><div style='background-color:'><DIV></DIV>
> <P>Perhaps this is a strange request, but here goes...</P>
> <P>It would be nice to have a template .qmail file that gets coppied into
> the vpopmail user's directory&nbsp;when creating a new user.&nbsp; This
> would work sort of like how useradd&nbsp;takes /etc/skel and copies those
> files into the&nbsp;new user's home dir.</P> <P>Reason for this?</P>
> <P>I want to be able to use the .qmail file to&nbsp;call a script that
> filters spam (using&nbsp;the spamassassin spamc/spamd)&nbsp;<BR><BR>Perhaps
> there's a better way to do this using qmail (filtering at the queue level
> perhaps)?&nbsp; Any suggestions are more than welcome.</P> <P>Anyways, the
> .qmail file will work for now.&nbsp; I was able to hack the user.c
> addusernow() function so that it copies a .qmail file into the new user's
> directory.&nbsp; If anybody is interested in how I did this let me know...
> its a pretty ugly hack though.</P> <P>Ryan / Plastic Portal</P>
> <DIV></DIV>
> <P>M&amp;M Recordings <A
> href="http://www.mmrecordings.com";>http://www.mmrecordings.com</A></P>
> <DIV></DIV></div><br clear=all><hr>Tired of spam? Get <a
> href="http://g.msn.com/8HMVENUS/2734??PS=";>advanced junk mail
> protection</a> with MSN 8.</html>

-- 
_________________________
Alex Griffiths
[EMAIL PROTECTED]
#!/usr/bin/perl
#
# This program is presented WITHOUT ANY WARRANTY.  It will most likely break your system!
# If you use this in a production environment you're insane.  Don't complain
# if you have problems, although fixes, improvements, and comments are appreciated.
#
# This program is free software; it may be redistributed and/or modified  under the terms
# of the GNU General Public License as published by the Free Software Foundation.  You can view
# the GPL at http://www.fsf.org/licenses/gpl.txt.
#
# WHAT IT DOES
# ---- -- ----
# Creates .qmail-<user>[-default] files for any users that don't have them.
#
# Requires vpopmail and qmail, it determines if there's a user by looking for subdirectories
# in the domain directory.  It would be nicer if it used DBI to query MySQL.
#
# This script is designed to be run from within "cron" as the user vpopmail.
# If the script finds a user that doesn't have either a .qmail-<user> file
# or a .qmail-<user>-default file it will create them by copying the templates in
# ~vpopmail/domains/<domain>/qmail-user or ~vpopmail/domains/<domain>/qmail-user-default.
# It will replace the string "USER" in the each template with the username that the file is
# being created for.
#
# On my system I have the following in both qmail-user and qmail-user-default:
#
#	| /home/vpopmail/bin/vdelivermail '' /home/vpopmail/domains/example.com/USER/
#
# Alex Griffiths <[EMAIL PROTECTED]>

use File::Basename;
$vpopmailBin = "~vpopmail/bin";

# Get a list of domains
@domains = `$vpopmailBin/vdominfo -d`;

# Loop on the domains and see what users are there
foreach (@domains) {
	chomp ($_);
	$vdir = $_;

	# Get the users
	while (<$vdir/*>) {
		chomp;
		if (!-d $_) {
			next;
		}
		$user = basename $_;

		# Does the .qmail-user file exist?
		$UserFile = "$vdir/.qmail-$user";
		if (!-e $UserFile) {
			# It's not there so let's create it if a default exists
			$qUser = "$vdir/qmail-user";
			if (-e $qUser) {
				open USER, "$qUser";
				open NEWUSER, ">$UserFile";
				while (<USER>) {
					$LINE = $_;
					$LINE =~ s/USER/$user/;
					print NEWUSER "$LINE";
				}
				close USER;
				close NEWUSER;
			}
		}

		# Now we do the .qmail-user-default file.
		$UserFile = $UserFile . -default;
		print "$UserFile\n";
		if (!-e $UserFile) {
			# It's not there so let's create it if a default exists
			$qUser = "$vdir/qmail-user-default";
			if (-e $qUser) {
				open USER, "$qUser";
				open NEWUSER, ">$UserFile";
				while (<USER>) {
					$LINE = $_;
					$LINE =~ s/USER/$user/;
					print NEWUSER "$LINE";
				}
				close USER;
				close NEWUSER;
			}
		}
	}
}

Reply via email to