Lock sur mail deletion
This commit is contained in:
parent
dbfcac73e9
commit
1c23ff759a
|
@ -528,8 +528,6 @@ src/fixperms.sh -text
|
||||||
src/functions.sh -text
|
src/functions.sh -text
|
||||||
src/functions_dns.sh -text
|
src/functions_dns.sh -text
|
||||||
src/functions_hosting.sh -text
|
src/functions_hosting.sh -text
|
||||||
src/mail_add -text
|
|
||||||
src/mail_del -text
|
|
||||||
src/mail_deletion.sh -text
|
src/mail_deletion.sh -text
|
||||||
src/mem_add -text
|
src/mem_add -text
|
||||||
src/mem_del -text
|
src/mem_del -text
|
||||||
|
|
44
src/mail_add
44
src/mail_add
|
@ -1,44 +0,0 @@
|
||||||
#!/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;
|
|
||||||
|
|
27
src/mail_del
27
src/mail_del
|
@ -1,27 +0,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"
|
. "$CONFIG_FILE"
|
||||||
done
|
done
|
||||||
|
|
||||||
#FIXME: do the lock
|
LOCK_FILE="/var/run/alternc/mail_deletion"
|
||||||
|
|
||||||
#FIXME: this var should be define by local.sh
|
#FIXME: this var should be define by local.sh
|
||||||
ALTERNC_MAIL_LOC="/var/alternc/mail"
|
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
|
# List the local addresses to DELETE
|
||||||
# Foreach => Mark for deleting and start deleting the files
|
# 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'
|
# 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
|
# 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;"
|
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"
|
||||||
|
|
Loading…
Reference in New Issue