Skip to content

Commit

Permalink
Initial Import in SourceForge
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1 a1433add-5e2c-0410-b055-b7f2511e0802
  • Loading branch information
Mischa Peters committed Mar 24, 2007
0 parents commit 85dc57b
Show file tree
Hide file tree
Showing 152 changed files with 21,000 additions and 0 deletions.
52 changes: 52 additions & 0 deletions ADDITIONS/README.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#
# Postfix Admin ADDITIONS
#

BEFORE YOU START
----------------

**** ALL THESE SCRIPTS ARE CREATED BY THIRD PARTIES ****
**** THEY ARE AS IS, USE AT YOUR OWN RISK! ****

ADDITIONS
---------

In this directory you will find additional scripts that are build by others.

- change_password.tgz
by George Vieira <george at citadelcomputer dot com dot au>
SquirrelMail plugin to change your passwor

- cleanupdirs.pl
by jared bell <jared at beol dot net>
Displays a list of mailboxes that need to be deleted

- mailbox_remover.pl
by Petr Znojemsky
Deletes all unused mailboxes

- mkeveryone.pl
by Joshua Preston
Generate an 'everybody' alias for a domain.

- pfa_maildir_cleanup.pl
by Stephen Fulton <sfulton at esoteric dot ca>
Deletes all unused mailboxes

- postfixadmin-0.3-1.4.tar.gz
by Florian Kimmerl <info at spacekoeln dot de>
The Postfixadmin SquirrelMail plugin let users change their virtual alias,
vacation status/message and password.

- virtualmaildel.php
by George Vieira <george at citadelcomputer dot com dot au>
Deletes all unused mailboxes

- postfixadmin-mailbox-postcreation.sh
- postfixadmin-mailbox-postdeletion.sh
- postfixadmin-domain-postdeletion.sh
by Troels Arvin <troels@arvin.dk>
Examples of scripts relevant to the optional
$CONF['mailbox_postcreation_script'],
$CONF['mailbox_postdeletion_script'] and
$CONF['domain_postdeletion_script'] configuration options.
Binary file added ADDITIONS/change_password.tgz
Binary file not shown.
103 changes: 103 additions & 0 deletions ADDITIONS/cleanupdirs.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/perl -w

################################################################################
#
# cleanupdirs 1.2 by jared bell <jared@beol.net>
#
# display/remove maildir & domains directory tree's not listed in the postfix
# mysql database. currently setup for use with postfixadmin, but can be
# adapted. edit settings where it says 'change settings as needed.' by default
# this program will display a list of directories which need deleted, nothing
# is actually deleted. to change this behavior, look into the command line
# arguments.
#
# command line arguments:
# --delete
# force automatic deletion of directories. instead of displaying a list
# of deleted directories, they will be logged in the specified logfile.
# --print
# display deleted directories as well as log them. only valid when
# '--delete' has been specified.
#
# settings:
# $root_path = "/home/vmail";
# if maildir is '/home/vmail/domain.tld/user' then '/home/vmail' is the
# $root_path. if your maildirs are '/home/vmail/user@domain.tld' then
# this program will need to be modified in order to work right.
# $logfile = "/var/log/removed_maildirs.log";
# the logfile to use when $delete_old_dirs is set to 1
# $db_* = "*";
# sets the host, port, database, user and pass to your mysql server
#
# version history:
# 1.2 - removed uneeded settings. added '--print' command line argument
# 1.1 - added '--delete' command line argument
# 1.0 - initial release
#
################################################################################

use strict;
use DBI;
use File::Path;
use Getopt::Long;

### change settings as needed, see notes above #################################
my $root_path = "/home/vmail";
my $logfile = "/var/log/removed_maildirs.log";
my $db_hostname = "localhost";
my $db_port = "3306";
my $db_database = "postfix";
my $db_username = "someuser";
my $db_password = "somepass";
################################################################################

### begin program ##############################################################
my(@dirs_to_delete, $logfile_open);
my $delete_old_dirs = 0; # do not delete by default, use cmdline to change this
my $print_also = 0; # also print items when deleting, use cmdline to change this
GetOptions ('delete' => \$delete_old_dirs, 'print' => \$print_also);
my $conn_info = "DBI:mysql:database=$db_database;hostname=$db_hostname;port=$db_port";
my $dbh = DBI->connect($conn_info, $db_username, $db_password)
or die $DBI::errstr;
opendir DOMAINDIR, $root_path
or die "Unable to access directory '$root_path' ($!)";
foreach my $domain_dir (sort readdir DOMAINDIR) {
next if $domain_dir =~ /^\./; # skip dotted dirs
my $full_domain_dir = "$root_path/$domain_dir";
opendir USERDIR, $full_domain_dir
or die "Unable to access directory '$full_domain_dir' ($!)";
foreach my $user_dir (sort readdir USERDIR) {
next if $user_dir =~ /^\./; # skip dotted dirs
push @dirs_to_delete, "$full_domain_dir/$user_dir"
if &check_dir("SELECT maildir FROM mailbox WHERE maildir = ?",
"$domain_dir/$user_dir/"); # end slash needed for checkdir
}
push @dirs_to_delete, $full_domain_dir
if &check_dir("SELECT domain FROM domain WHERE domain = ?", $domain_dir);
}
closedir USERDIR;
closedir DOMAINDIR;
$dbh->disconnect;
if (@dirs_to_delete) {
foreach my $to_delete (@dirs_to_delete) {
if ($delete_old_dirs == 1) {
$logfile_open = open LOGFILE, ">> $logfile"
or die "Unable to append logfile '$logfile' ($!)"
unless $logfile_open;
rmtree $to_delete;
print LOGFILE localtime() . " Deleting directory '$to_delete'\n";
print localtime() . " Deleting directory '$to_delete'\n"
if $print_also;
} else {
print localtime() . " Need to delete directory '$to_delete'\n";
}
}
}
close LOGFILE if $logfile_open;
sub check_dir {
my($query, $dir) = @_;
my $sth = $dbh->prepare($query);
my $num_rows = $sth->execute($dir);
$sth->finish;
($num_rows eq "0E0") ? 1 : 0;
}
66 changes: 66 additions & 0 deletions ADDITIONS/mailbox_remover.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/perl
#
# by Petr Znojemsky (c) 2004
# Mailbox remover 0.1a 23/10/2004 - the very first version for MySQL
# removes maildirs from disk when they are not found in a database
# Run program and read the $logfile before uncommenting the "rmtree" line!
# All your maildirs or other directories could be accidentally removed.
# Use it at own risk. No warranties!

use DBI;
use File::Path;

##########
# Set these variables according to your configuration
$maildir_path="/var/mail/virtual/";
$logfile="/var/log/mail/removed_maildirs";

# database information
$host="localhost";
$port="3306";
$userid="postfix";
$passwd="postfix";
$db="postfix";
############

$connectionInfo="DBI:mysql:database=$db;$host:$port";
# make connection to database
$dbh = DBI->connect($connectionInfo,$userid,$passwd);
# prepare and execute query
$query = "SELECT username FROM mailbox";
$sth = $dbh->prepare($query);
$sth->execute();
# assign fields to variables
$sth->bind_columns(\$username);
# output computer list to the browser
while($sth->fetch()) {
push(@usernames, $username);
}
$sth->finish();
# disconnect from database
$dbh->disconnect;

# store maildir list to @directories
opendir(DIRHANDLE, $maildir_path) || die "Cannot open dir $maildir_path: $!";
foreach $name (sort readdir(DIRHANDLE))
{
push (@directories, $name);
}
closedir(DIRHANDLE);
# eliminate "." and ".." from the maildir list
($dot, $doubledot, @directories) = @directories;


# compare two arrays and erase maildirs not found in database
foreach $maildir (@directories)
{
if ((grep { $_ eq $maildir} @usernames)==0)
{
# username not found, delete maildir.
# Please read $logfile before uncommenting following line!
# rmtree($maildir_path.$maildir);
open(INFO, ">>$logfile") || die "Cannot write to the logfile: $logfile.";
print INFO localtime()." Maildir ".$maildir_path.$maildir." has been deleted.\n";
close(INFO);
}
}
167 changes: 167 additions & 0 deletions ADDITIONS/mkeveryone.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#!/usr/bin/perl
#
# Generate an 'everybody' alias for a domain.
#
# Create the file /etc/mkeveryone.conf
# chmod 640 /etc/mkeveryone.conf
# Example of mkeveryone.conf
#
# userid=postfix
# passwd=postfix
# db=postfix
# host=localhost
# port=3306
# domain=domain.tld
# target=everybody@domain.tld
# ignore=vacation@domain.tld
# ignore=spam@domain.tld
# ignore=newsletter@domain.tld
# ignore=root@domain.tld
#
# Save this file in, for example, /usr/local/sbin/mkeveryone.pl
# chmod 750 /usr/local/sbin/mkeveryone.pl
#
# Run the script!
#
use DBI;
use Time::Local;
use POSIX qw(EAGAIN);
use Fcntl;
use IO;
use IO::File;

my $timeNow=time();

my $DATFILE = "/etc/mkeveryone.conf";
my $FILEHANDLE = "";

# database information
my $db="postfix";
my $host="localhost";
my $port="3306";
my $userid="postfix";
my $passwd="postfix";
my $domain="domain.tld";
my $target="everyone@$domain";
my @ignore;
my @dest;

open (FILEHANDLE, $DATFILE);

while ( $LINE = <FILEHANDLE> ) {

if ( length $LINE > 0 ) {
chomp $LINE;

$RETURNCODE = 0;

SWITCH: {

$LINE =~ /^ignore/i and do {
$LINE =~ s/^ignore// && $LINE =~ s/=// && $LINE =~ s/^ //g;
@ignore = (@ignore,$LINE);
};

$LINE =~ /^userid/i and do {
# Userid found.";
$LINE =~ s/^userid// && $LINE =~ s/=// && $LINE =~ s/^ //g;
$userid = $LINE;
};

$LINE =~ /^passwd/i and do {
# Passwd found.";
$LINE =~ s/^passwd// && $LINE =~ s/=// && $LINE =~ s/^ //g;
$passwd = $LINE;
};

$LINE =~ /^db/i and do {
# Database found.";
$LINE =~ s/^db// && $LINE =~ s/=// && $LINE =~ s/^ //g;
$db = $LINE;
};

$LINE =~ /^host/i and do {
# Database host found.";
$LINE =~ s/^host// && $LINE =~ s/=// && $LINE =~ s/^ //g;
$host = $LINE;
};

$LINE =~ /^port/i and do {
# Database host found.";
$LINE =~ s/^port// && $LINE =~ s/=// && $LINE =~ s/^ //g;
$port = $LINE;
};

$LINE =~ /^target/i and do {
# Database host found.";
$LINE =~ s/^target// && $LINE =~ s/=// && $LINE =~ s/^ //g;
$target = $LINE;
};

$LINE =~ /^domain/i and do {
# Database host found.";
$LINE =~ s/^domain// && $LINE =~ s/=// && $LINE =~ s/^ //g;
$domain = $LINE;
};
}
}
}

print "Connecting to database $db on $host:$port...\n\r";

print "Target email address is $target...\n\r";

my $connectionInfo="DBI:mysql:database=$db;$host:$port";

# make connection to database
$dbh = DBI->connect($connectionInfo,$userid,$passwd);

# Delete the old message...prepare and execute query
$query = "SELECT username FROM mailbox WHERE domain='$domain';";
$sth = $dbh->prepare($query);
$sth->execute();

# assign fields to variables
$sth->bind_columns(\$username);

my $ign="false";
while($sth->fetch()) {
$ign = "false";

foreach $ignored ( @ignore ) {
if ( $username eq $ignored ){
$ign = "true";
}
}

if ( $ign eq "false" ) {
@dest = (@dest,$username);
}
}

# Delete the old aliases...prepare and execute query
$query = "DELETE FROM alias WHERE address='$target';";
$sth = $dbh->prepare($query);
$sth->execute();

print "Record deleted from the database.\r\n";

$sth->finish();

$goto = join(",",@dest);
print "$goto\n\r\n\r";


# Insert the new message...prepare and execute query
$query = "INSERT INTO alias (address,goto,domain,created,modified) VALUES ('$target','$goto','$domain',now(),now());";

$sth = $dbh->prepare($query);
$sth->execute();

print "Record added to the database.\r\n";

$sth->finish();

# disconnect from databse
$dbh->disconnect;

Loading

0 comments on commit 85dc57b

Please sign in to comment.