script
This commit is contained in:
parent
ba535e6056
commit
d066719017
18
cron/purge.sh
Executable file
18
cron/purge.sh
Executable file
|
@ -0,0 +1,18 @@
|
|||
#!/bin/bash
|
||||
#Gnieark https://blog-du-grouik.tinad.fr 2017
|
||||
#GNU GPL V2 license
|
||||
#inactivate alias olders than on
|
||||
MYSQLPATH="/usr/bin/mysql"
|
||||
MYSQLDB="postfix"
|
||||
MYSQLUSER="postfix"
|
||||
MYSQLPWD="******"
|
||||
TTL="3600"
|
||||
|
||||
$MYSQLPATH -u $MYSQLDB -p$MYSQLPWD << EOF
|
||||
UPDATE alias
|
||||
SET active='0'
|
||||
WHERE DOMAIN='tinad.fr'
|
||||
AND active = '1'
|
||||
AND created < (UNIX_TIMESTAMP() - $TTL)
|
||||
AND temporary='1';
|
||||
EOF
|
73
execute/genalias.sh
Executable file
73
execute/genalias.sh
Executable file
|
@ -0,0 +1,73 @@
|
|||
#!/bin/bash
|
||||
#Gnieark https://blog-du-grouik.tinad.fr 2017
|
||||
#GNU GPL V2 license
|
||||
#
|
||||
#This script generate the random alias: Create it on postfix bdd
|
||||
#
|
||||
#First and only param is the mail "GOTO"
|
||||
|
||||
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
echo "Error, argument missing. usage: $0 mail@domaine.com"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
MYSQLPATH="/usr/bin/mysql"
|
||||
MYSQLDB="postfix"
|
||||
MYSQLUSER="postfix"
|
||||
MYSQLPWD="******"
|
||||
OPENSSLPATH="/usr/bin/openssl"
|
||||
DOMAIN="tinad.fr"
|
||||
LOGGERPATH="/usr/bin/logger"
|
||||
#escape mail:
|
||||
printf -v MAIL "%q" "$1"
|
||||
|
||||
#Check if the sender is already knowed on the database
|
||||
EXISTS=`$MYSQLPATH -B -u $MYSQLUSER -p$MYSQLPWD -D $MYSQLDB --disable-column-names -e "SELECT count(*) FROM alias WHERE goto='$MAIL'"`
|
||||
|
||||
if [ $EXISTS -eq 0 ]; then
|
||||
#unknowed user *************************************************
|
||||
#Generate random string for the alias. If already exists, retry.
|
||||
COUNT=1
|
||||
while [ $COUNT -gt 0 ]; do
|
||||
#gererate random
|
||||
RD=$($OPENSSLPATH rand -base64 8)
|
||||
#Delete = char at the end of string
|
||||
PART=${RD::-1}
|
||||
COUNT=`$MYSQLPATH -B -u $MYSQLUSER -p$MYSQLPWD -D $MYSQLDB --disable-column-names -e "SELECT count(*) FROM alias WHERE address='$PART@$DOMAIN'"`
|
||||
done
|
||||
ALIASFULL=$PART@$DOMAIN
|
||||
|
||||
#Feed the database
|
||||
$MYSQLPATH -u $MYSQLUSER -p$MYSQLPWD $MYSQLDB << EOF
|
||||
INSERT INTO alias(address,goto,domain,created,modified,active,temporary) VALUES
|
||||
('$PART@$DOMAIN',
|
||||
'$MAIL',
|
||||
'$DOMAIN',
|
||||
NOW(),
|
||||
NOW(),
|
||||
'1',
|
||||
'1'
|
||||
);
|
||||
EOF
|
||||
|
||||
else
|
||||
#user is already knowed, simply reactivate his alias************
|
||||
$MYSQLPATH -u $MYSQLUSER -p$MYSQLPWD $MYSQLDB << EOF
|
||||
UPDATE alias SET
|
||||
modified=NOW(),
|
||||
active='1'
|
||||
WHERE goto='$MAIL'
|
||||
AND temporary='1';
|
||||
EOF
|
||||
#get his alias
|
||||
ALIASFULL=`$MYSQLPATH -B -u $MYSQLUSER -p$MYSQLPWD -D $MYSQLDB --disable-column-names -e "SELECT address FROM alias WHERE goto='$MAIL'"`
|
||||
|
||||
fi
|
||||
|
||||
printf "Hi, Your requested alias is $ALIASFULL, You will receive all mails sending to this alias during one hour from now. Thanks for using this service."
|
||||
|
||||
$LOGGERPATH -i -p genalias.info "Activate alias $ALIASFULL FOR $MAIL"
|
||||
exit 0
|
||||
|
14
global.sieve
Normal file
14
global.sieve
Normal file
|
@ -0,0 +1,14 @@
|
|||
require ["vnd.dovecot.execute","variables","fileinto", "envelope", "subaddress","vacation","vacation-seconds"];
|
||||
if envelope :detail "to" "spam"{
|
||||
fileinto "Spam";
|
||||
}
|
||||
if header :contains ["to", "cc"]
|
||||
[
|
||||
"alias@tinad.fr"
|
||||
]{
|
||||
if address :matches "from" "*" { set "from" "${1}"; }
|
||||
if execute :output "response" "genalias.sh" [ "${from}" ]{
|
||||
vacation :seconds 1801 "${response}";
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user