diff --git a/.gitattributes b/.gitattributes index d20c56b1..26f15c85 100644 --- a/.gitattributes +++ b/.gitattributes @@ -528,8 +528,6 @@ src/fixperms.sh -text src/functions.sh -text src/functions_dns.sh -text src/functions_hosting.sh -text -src/mail_add -text -src/mail_del -text src/mail_deletion.sh -text src/mem_add -text src/mem_del -text diff --git a/src/mail_add b/src/mail_add deleted file mode 100755 index f6f6b3a0..00000000 --- a/src/mail_add +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/perl - -use strict; - -my ($mailname,$uid) = @ARGV; - -if (!$mailname || !$uid) { - print "Usage: mail_add \n"; - print " Create the mail for the alternc account having uid number \n"; - exit(1); -} - -$ENV{PATH} = ""; -delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; - -if (!($mailname =~ /^(([a-z0-9_\+\-][a-z0-9_\+\.\-]+)?\_[a-z0-9\.-]+)$/)) { - die "Email is incorrect."; -} -$mailname=$1; -if (!($uid =~ /^([0-9]+)$/)) { - die "uid is incorrect."; -} -$uid=$1; - -$< = $>; -$( = $); - -my $PTH="/var/alternc/mail/".substr($mailname,0,1)."/".$mailname; - -my @todo=( - $PTH, - $PTH."/Maildir", - $PTH."/Maildir/cur", - $PTH."/Maildir/new", - $PTH."/Maildir/tmp", - ); - -foreach(@todo) { - mkdir($_); - chown(33, $uid, $_); -} - -0; - diff --git a/src/mail_del b/src/mail_del deleted file mode 100755 index f590020a..00000000 --- a/src/mail_del +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/perl - -use strict; - -my ($mailname) = @ARGV; - -if (!$mailname) { - print "Usage: mail_del \n"; - print " Destroy pop account \n"; - exit(1); -} - -$ENV{PATH} = ""; -delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; - -if (!($mailname =~ /^([a-z0-9_\+-][a-z0-9_\+\.-]+\_[a-z0-9\.-]+)$/)) { - die "Email is incorrect."; -} -$mailname=$1; - -$< = $>; -$( = $); - -system("/bin/rm -rf '/var/alternc/mail/".substr($mailname,0,1)."/".$mailname."'"); - -0; - diff --git a/src/mail_deletion.sh b/src/mail_deletion.sh index 61023d0b..cd0297b2 100755 --- a/src/mail_deletion.sh +++ b/src/mail_deletion.sh @@ -14,11 +14,26 @@ for CONFIG_FILE in \ . "$CONFIG_FILE" done -#FIXME: do the lock +LOCK_FILE="/var/run/alternc/mail_deletion" #FIXME: this var should be define by local.sh ALTERNC_MAIL_LOC="/var/alternc/mail" +# Somes check before start operations +if [ `id -u` -ne 0 ]; then + log_error "must be launched as root" +elif [ -f "$LOCK_FILE" ]; then + process=$(ps f -p `cat "$LOCK_FILE"|tail -1`|tail -1|awk '{print $NF;}') + if [ "$(basename $process)" = "$(basename "$0")" ] ; then + log_error "last cron unfinished or stale lock file ($LOCK_FILE)." + else + rm "$LOCK_FILE" + fi +fi + +# We lock the application +echo $$ > "$LOCK_FILE" + # List the local addresses to DELETE # Foreach => Mark for deleting and start deleting the files # If process is interrupted, the row isn't deleted. We have to force it by reseting mail_action to 'DELETE' @@ -37,3 +52,5 @@ done # Delete if only if there isn't any mailbox refering to it mysql_query "DELETE FROM a using address a, mailbox m WHERE a.mail_action='DELETE' OR a.mail_action='DELETING' AND a.id != m.address_id;" +# Delete the lock +rm -f "$LOCK_FILE"