From d3f3bd955a9a0d0331c0b8ef9e5d664b1c8297bc Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Sun, 18 Jan 2009 12:03:14 +0000 Subject: [PATCH 1/5] adding file from Jose Nilton - produces report of quota usage etc git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@529 a1433add-5e2c-0410-b055-b7f2511e0802 --- ADDITIONS/quota_usage.pl | 140 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 ADDITIONS/quota_usage.pl diff --git a/ADDITIONS/quota_usage.pl b/ADDITIONS/quota_usage.pl new file mode 100644 index 00000000..3cd7d30f --- /dev/null +++ b/ADDITIONS/quota_usage.pl @@ -0,0 +1,140 @@ +#!/usr/bin/perl +# vim:ts=4:sw=4:et +# +# Contributed to Postfixadmin by Jose Nilton +# +# See also : http://www.russelldare.net/media/perl/dirsizeSource.pdf +# License: GPL v2. + +# Usage: +# perl quota_usage.pl --list or +# perl quota_usage.pl --addmysql for add mysql database postfix +# +# Requires: perl perl-DBD-mysql perl-DBD (may be named differently depending on your platform). +# and the 'du' binary in $ENV{'PATH'} (see below). +# +# You will need to modify the postfix DATABASE to add a quota_usage column. +# Mysql: +# ALTER TABLE mailbox ADD quota_usage INT(11) NOT NULL DEFAULT '0' AFTER modified, +# ADD quota_usage_date DATE NOT NULL DEFAULT '0000-00-00' AFTER quota_usage; +# PostgreSQL: +# ALTER TABLE mailbox ADD COLUMN quota_usage INTEGER NOT NULL DEFAULT 0; +# ALTER TABLE mailbox ADD COLUMN quota_usage_date DATE NOT NULL DEFAULT current_date; +# + +use strict; +use warnings; +use File::Path; +use DBI; +use Getopt::Long; + +##EDIT## +my $db_host = 'localhost'; +my $db_database = 'postfix'; +my $db_user = 'postfix'; +my $db_password = '123456'; +my $root_path = '/home/vmail'; +# Pg or mysql +my $db_type = 'Pg'; +##END EDIT## + +$ENV{'PATH'} = "/sbin:/bin:/usr/sbin:/usr/bin"; +my($domain_dir, $full_domain_dir, $user_dir, $usage, $email, $sql, $dbh); + +GetOptions ('list' => \&list_quota_usage, 'addmysql' => \&insert_to_db); + +sub list_quota_usage { + opendir(DOMAINDIR, $root_path) or die ("Unable to access directory '$root_path' ($!)"); + + foreach $domain_dir (sort readdir DOMAINDIR) { + next if $domain_dir =~ /^\./; # skip dotted dirs + $full_domain_dir = "$root_path/$domain_dir"; #print "$full_domain_dir\n"; + + opendir(USERDIR, $full_domain_dir) or die ("Unable to access directory '$full_domain_dir' ($!)"); + foreach $user_dir (sort readdir USERDIR) { + next if $user_dir =~ /^\./; # skip dotted dirs + $email = "$user_dir\@$domain_dir"; + + my $i = `du -0 --summarize $full_domain_dir/$user_dir`; + ($usage) = split(" ", $i); + + if ($usage < 100) { + $usage = 0; + } elsif ($usage < 1000) { + $usage = 1; + } else { + $usage = $usage + 500; + $usage = int $usage / 1000; + } + + list_out(); + } + } + close(DOMAINDIR); + close(USERDIR); +} + + +sub insert_to_db { + opendir(DOMAINDIR, $root_path) or die ("Unable to access directory '$root_path' ($!)"); + + $dbh = DBI->connect("DBI:$db_type:database=$db_database;host=$db_host", $db_user, $db_password) or die ("cannot connect the database"); + execSql("UPDATE mailbox set quota_usage = 0"); + + + foreach $domain_dir (sort readdir DOMAINDIR) { + next if $domain_dir =~ /^\./; # skip dotted dirs + $full_domain_dir = "$root_path/$domain_dir"; #print "$full_domain_dir\n"; + + opendir(USERDIR, $full_domain_dir) or die ("Unable to access directory '$full_domain_dir' ($!)"); + foreach $user_dir (sort readdir USERDIR) { + next if $user_dir =~ /^\./; # skip dotted dirs + $email = "$user_dir\@$domain_dir"; + + my $i = `du -0 --summarize $full_domain_dir/$user_dir`; + ($usage) = split(" ", $i); + + if ($usage < 100) { + $usage = 0; + } elsif ($usage < 1000) { + $usage = 1; + } else { + $usage = $usage + 500; + $usage = int $usage / 1000; + } + + execSql("UPDATE mailbox set quota_usage = $usage, quota_usage_date = CAST(NOW() AS DATE) WHERE username = '$email'"); +#list_out(); #Debug + } + + } + + close(DOMAINDIR); + close(USERDIR); + +} + + +sub execSql { + my $sql = shift; + my $ex; + $ex = $dbh->do($sql) or die ("error when running $sql"); +} + +sub list_out { +format STDOUT_TOP = +Report of Quota Used +-------------------------- +EMAIL QUOTA USED +------------------------------------------------------------------ +. + + +format = +@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<< +$email, "$usage\bMB" +. + + write; +} + From 26416700104d10675354782995d5b32bab1b21b5 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Tue, 20 Jan 2009 11:49:03 +0000 Subject: [PATCH 2/5] updating tests git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@531 a1433add-5e2c-0410-b055-b7f2511e0802 --- .../tests/teodor-smtp-envelope-headers.txt | 21 ++++++++++++++ VIRTUAL_VACATION/tests/test.sh | 28 ++++++++++++++----- 2 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 VIRTUAL_VACATION/tests/teodor-smtp-envelope-headers.txt diff --git a/VIRTUAL_VACATION/tests/teodor-smtp-envelope-headers.txt b/VIRTUAL_VACATION/tests/teodor-smtp-envelope-headers.txt new file mode 100644 index 00000000..e4633bbf --- /dev/null +++ b/VIRTUAL_VACATION/tests/teodor-smtp-envelope-headers.txt @@ -0,0 +1,21 @@ +X-Original-To: david@example.org +Delivered-To: david@example.org +X-Virus-Scanned: amavisd-new at mx.ro +From: "Teodor Iacob" +To: +Subject: estsgf +Date: Mon, 19 Jan 2009 14:49:17 +0200 +X-Mailer: Microsoft Office Outlook 11 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 +Thread-Index: Acl6NFZyC+AImZ1WQSS0cPUO/Y2FqA== +X-BRO-MailScanner-Information: Please contact the ISP for more information +X-BRO-MailScanner-ID: n0JCoUwB014357 +X-BRO-MailScanner: Found to be clean +X-MailScanner-From: david@example.org +X-BRO-MailScanner-Watermark: 1232974231.00027@11VRmWFJ18WRflEdvrILlQ + +dsgsgfsgfg + +-- + +Teodor Iacob diff --git a/VIRTUAL_VACATION/tests/test.sh b/VIRTUAL_VACATION/tests/test.sh index b324c519..ca61d5c8 100644 --- a/VIRTUAL_VACATION/tests/test.sh +++ b/VIRTUAL_VACATION/tests/test.sh @@ -14,6 +14,7 @@ export PGUSER=dg export PGDATABASE=postfix export PGHOST=pgsqlserver + echo "DELETE FROM vacation WHERE email = 'david@example.org'" | psql # First time around, there should be no vacation record for david@example.org, so these should all not cause mail to be sent. @@ -21,15 +22,29 @@ echo "DELETE FROM vacation WHERE email = 'david@example.org'" | psql echo echo "NONE OF THESE SHOULD RESULT IN MAIL BEING SENT" echo -cat mailing-list.txt | perl ../vacation.pl -t yes -f fw-general-return-20540-david=example.org@lists.zend.com -- david\#example.org@autoreply.example.org -cat test-email.txt | perl ../vacation.pl -t yes -f david1@example.org -- david\#example.org@autoreply.example.org -cat spam.txt | perl ../vacation.pl -t yes -f mary@ccr.org -- david\#example.org@autoreply.example.org -cat asterisk-email.txt | perl ../vacation.pl -t yes -f www-data@palepurple.net -- david\#example.org@autoreply.example.org -cat facebook.txt | perl ../vacation.pl -t yes -f notification+meynbxsa@facebookmail.com -- david\#example.org@autoreply.example.org -cat mail-myself.txt | perl ../vacation.pl -t yes -f david@example.org -- david\#example.org@autoreply.example.org + +#echo "On: mailing-list.txt:" +# cat mailing-list.txt | perl ../vacation.pl -t yes -f fw-general-return-20540-david=example.org@lists.zend.com -- david\#example.org@autoreply.example.org +echo "On: test-email.txt:" +cat test-email.txt | perl ../vacation.pl -t yes -f david1@example.org -- david\#example.org@autoreply.example.org +echo "On: spam.txt:" +cat spam.txt | perl ../vacation.pl -t yes -f mary@ccr.org -- david\#example.org@autoreply.example.org +echo "On: asterisk-email.txt:" +cat asterisk-email.txt | perl ../vacation.pl -t yes -f www-data@palepurple.net -- david\#example.org@autoreply.example.org +# do not reply to facebook +echo "On: facebook.txt:" +cat facebook.txt | perl ../vacation.pl -t yes -f notification+meynbxsa@facebookmail.com -- david\#example.org@autoreply.example.org +# do not send yourself a vacation notice. +echo "On: mail-myself.txt:" +cat mail-myself.txt | perl ../vacation.pl -t yes -f david@example.org -- david\#example.org@autoreply.example.org +# do not send yourself a vacation notice. +echo "On: teodor-smtp-envelope-headers.txt:" +cat teodor-smtp-envelope-headers.txt | perl ../vacation.pl -t yes -f david@example.org -- david\#example.org@autoreply.example.org + echo "INSERT INTO vacation (email, subject, body, created, active, domain) VALUES ('david@example.org', 'I am on holiday', 'Yeah, that is right', NOW(), true, 'example.org')" | psql + echo echo "VACATION TURNED ON " echo @@ -46,4 +61,3 @@ cat facebook.txt | perl ../vacation.pl -t yes -f notification+meynbxsa@facebookm echo " * Mailing myself - should not send vacation message" cat mail-myself.txt | perl ../vacation.pl -t yes -f david@example.org -- david\#example.org@autoreply.example.org echo -echo From cf2a995e1361a8999248c334cd13faaaad994bb4 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Tue, 20 Jan 2009 11:53:54 +0000 Subject: [PATCH 3/5] vacation.pl: make it strip/discover addresses better, slightly better logging, stop it requiring a messageid git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@532 a1433add-5e2c-0410-b055-b7f2511e0802 --- VIRTUAL_VACATION/vacation.pl | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/VIRTUAL_VACATION/vacation.pl b/VIRTUAL_VACATION/vacation.pl index 7fac0565..08a3f04a 100644 --- a/VIRTUAL_VACATION/vacation.pl +++ b/VIRTUAL_VACATION/vacation.pl @@ -152,6 +152,7 @@ use Log::Log4perl qw(get_logger :levels); my ($from, $to, $cc, $replyto , $subject, $messageid, $lastheader, $smtp_sender, $smtp_recipient, %opts, $spam, $test_mode, $logger); $subject=''; +$messageid='unknown'; # Setup a logger... # @@ -391,7 +392,7 @@ sub send_vacation_email { 'Message' => encode_base64($body) ); if($test_mode == 1) { - $logger->info("** TEST MODE ** : Vacation response sent to $to from $from subject $subject - NOT sent\n"); + $logger->info("** TEST MODE ** : Vacation response sent to $to from $from subject $subject (not) sent\n"); $logger->info(%mail); return 0; } @@ -410,13 +411,28 @@ sub strip_address { } my @ok; $logger = get_logger(); - for (split(/,\s*/, lc($arg))) { - my $temp = Email::Valid->address($_); + my @list; + @list = $arg =~ m/([\w\.\-\']+\@[\w\.\-]+\w+)/g; + foreach(@list) { + #$logger->debug("Checking: $_"); + my $temp = Email::Valid->address( -address => $_, -mxcheck => 0); if($temp) { push(@ok, $temp); } + else { + $logger->debug("Email not valid : $Email::Valid::Details"); + } + } + # remove duplicates + my %seen = (); + my @uniq; + my $item; + foreach $item (@ok) { + push(@uniq, $item) unless $seen{$item}++ } - my $result = join(", ", @ok); + + my $result = join(", ", @uniq); + #$logger->debug("Result: $result"); return $result; } @@ -459,6 +475,7 @@ sub check_and_clean_from_address { $cc = ''; $replyto = ''; +$logger->debug("Script argument SMTP recipient is : '$smtp_recipient' and smtp_sender : '$smtp_sender'"); while () { last if (/^$/); if (/^\s+(.*)/ and $lastheader) { $$lastheader .= " $1"; next; } @@ -495,7 +512,7 @@ if(!$from || !$to || !$messageid || !$smtp_sender || !$smtp_recipient) { $logger->info("One of from=$from, to=$to, messageid=$messageid, smtp sender=$smtp_sender, smtp recipient=$smtp_recipient empty"); exit(0); } - +$logger->debug("Email headers have to: '$to' and From: '$from'"); $to = strip_address($to); $from = lc ($from); $from = check_and_clean_from_address($from); From 6589f8bc22616510d01cda3b0abe4e8fefb79abb Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Tue, 20 Jan 2009 11:54:34 +0000 Subject: [PATCH 4/5] mail-myself.txt: test stuff git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@533 a1433add-5e2c-0410-b055-b7f2511e0802 --- VIRTUAL_VACATION/tests/mail-myself.txt | 43 ++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 VIRTUAL_VACATION/tests/mail-myself.txt diff --git a/VIRTUAL_VACATION/tests/mail-myself.txt b/VIRTUAL_VACATION/tests/mail-myself.txt new file mode 100644 index 00000000..5f233bfd --- /dev/null +++ b/VIRTUAL_VACATION/tests/mail-myself.txt @@ -0,0 +1,43 @@ +Return-Path: +X-Original-To: david@example.org +Delivered-To: david@example.org +Received: by mail.palepurple.co.uk (Postfix, from userid 1007) + id 83AE0894CF8; Tue, 5 Aug 2008 20:15:53 +0100 (BST) +Received: from localhost (localhost [127.0.0.1]) + by mail.palepurple.co.uk (Postfix) with ESMTP id 4A249894CF9 + for ; Tue, 5 Aug 2008 20:15:53 +0100 (BST) +X-Virus-Scanned: by Amavis+SpamAssassin+ClamAV and more at palepurple.co.uk +X-Spam-Score: -2.836 +X-Spam-Level: +X-Spam-Status: No, score=-2.836 tagged_above=-99 required=5 tests=[AWL=-0.237, + BAYES_00=-2.599] +Received: from mail.palepurple.co.uk ([127.0.0.50]) + by localhost (oak.palepurple.co.uk [127.0.0.50]) (amavisd-new, port 10024) + with ESMTP id gHB1TKpjKIKX for ; + Tue, 5 Aug 2008 20:15:50 +0100 (BST) +Received: from irc.palepurple.co.uk (irc.palepurple.co.uk [89.16.169.131]) + by mail.palepurple.co.uk (Postfix) with ESMTP id CAF82894CF8 + for ; Tue, 5 Aug 2008 20:15:50 +0100 (BST) +Received: by irc.palepurple.co.uk (Postfix, from userid 1000) + id 8869450146; Tue, 5 Aug 2008 20:15:50 +0100 (BST) +Date: Tue, 5 Aug 2008 20:15:50 +0100 +From: David Goodwin +To: david@example.org, fred@example.org, barney@example.org, rover@example.org, + roger@example.org +Subject: test email +Message-ID: <20080805191549.GA27905@codepoets.co.uk> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +X-GnuPG-Key-URL: http://codepoets.co.uk/files/pubkey.txt +X-PGP-Key: 0x117957A6 +User-Agent: Mutt/1.5.13 (2006-08-11) +Content-Length: 136 +Lines: 7 + +hello world; this is in plain text only. + +-- +David Goodwin + +[ http://www.codepoets.co.uk ] From 2d34a4ca70a8b160a3c72186b2990fd52cbf06b8 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Tue, 20 Jan 2009 12:00:46 +0000 Subject: [PATCH 5/5] update docs a litt;e add revision to .pl file git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@535 a1433add-5e2c-0410-b055-b7f2511e0802 --- VIRTUAL_VACATION/INSTALL.TXT | 9 +++++---- VIRTUAL_VACATION/vacation.pl | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/VIRTUAL_VACATION/INSTALL.TXT b/VIRTUAL_VACATION/INSTALL.TXT index 0959f10b..95fa8ea5 100644 --- a/VIRTUAL_VACATION/INSTALL.TXT +++ b/VIRTUAL_VACATION/INSTALL.TXT @@ -101,21 +101,22 @@ Execute "postfix reload" to complete the change. ------------------- The database table should have already been created for you, by running -the 'upgrade.php' script. +the 'upgrade.php' script when installing Postfixadmin. If security is an issue for you, read ../DOCUMENTS/Security.txt -6. Edit filter.pl +6. Edit vacation.pl ----------------- -The perl filter.pl script needs minor modification to know which database +The perl vacation.pl script needs minor modification to know which database you are using, and also how to connect to the database. Namely : Change any variables starting with '$db_' and '$db_type' to either 'mysql' or 'pgsql'. - +Change the $vacation_domain variable to match what you entered in your /etc/postfix/transport +file. What do these files do? ----------------------- diff --git a/VIRTUAL_VACATION/vacation.pl b/VIRTUAL_VACATION/vacation.pl index 08a3f04a..903c7a1d 100644 --- a/VIRTUAL_VACATION/vacation.pl +++ b/VIRTUAL_VACATION/vacation.pl @@ -1,6 +1,7 @@ #!/usr/bin/perl -w # # Virtual Vacation 4.0 +# $Revision$ # Originally by Mischa Peters # # Copyright (c) 2002 - 2005 High5!