Commit 1c23ff75 authored by Alan Garcia's avatar Alan Garcia
Browse files

Lock sur mail deletion

parent dbfcac73
......@@ -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
......
#!/usr/bin/perl
use strict;
my ($mailname,$uid) = @ARGV;
if (!$mailname || !$uid) {
print "Usage: mail_add <mailname> <uid>\n";
print " Create the mail <mailname> for the alternc account having uid number <uid>\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;
#!/usr/bin/perl
use strict;
my ($mailname) = @ARGV;
if (!$mailname) {
print "Usage: mail_del <mailname>\n";
print " Destroy pop account <mailname>\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;
......@@ -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"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment