Roundcube + Vacation - Notification d'absence

De Le Wiki du Forum-Debian.fr
Aller à la navigation Aller à la recherche

Vacation - Notification d'absence

Préparation du plugin

A force de nombreux tests et de lecture, j'ai réussi à faire installation de l'autoreply et du plugin vacation de roundcube. Pour commencer, récupérez le plugin vacation vacation-1.9.9.zip

et installez les paquets perl manquants à vacation pour le bon fonctionnement apt-get install libmail-sender-perl libdbd-mysql-perl libemail-valid-perl libmime-perl liblog-log4perl-perl liblog-dispatch-perl libgetopt-argvfile-perl libmime-charset-perl libmime-encwords-perl

Une fois l'archive récupérée, décompressez là dans le répertoire des plugins de roundcube et activez le plugin

unzip vacation-1.9.9.zip -d /var/www/roundcubemail/plugins/

j'en profite pour lui donner les bons droits chown -R www-data.www-data vacation

Pour l'activer // ---------------------------------- // PLUGINS // ----------------------------------

// List of active plugins (in plugins/ directory) $rcmail_config['plugins'] = array('managesieve','vacation');

Le plugin souffre d'un petit bug d'affichage facile à régler. Ouvrez le fichier /vacation/skins/default/vacation.css et remplacez

  1. pagecontent {

width: 800px; }

par

  1. pagecontent {

width: 800px; position: absolute; bottom: 20px; left: 20px; right: 20px; top: 85px; }

Modification des tables

Passons aux tables "vacation" et "vacation_notification" qui vont recevoir les datas du plugin vacation

On se connecte en root sur la base postfix pour supprimer les tables "vacation" et "vacation_notification" actuelles de la base postfix pour les remplacer par celles fournies dans vacation/extra/virtual_vacation

on se connecte au serveur mysql mysql -u root -p passord : xxxxxx

use postfix


DROP TABLES vacation_notification; DROP TABLES vacation;


CREATE TABLE `vacation` (

 `email` varchar(255) NOT NULL,
 `subject` varchar(255) CHARACTER SET utf8 NOT NULL,
 `body` text CHARACTER SET utf8 NOT NULL,
 `cache` text NOT NULL,
 `domain` varchar(255) NOT NULL,
 `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
 `active` tinyint(1) NOT NULL DEFAULT '1',
 PRIMARY KEY (`email`),
 KEY `email` (`email`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Postfix Admin - Virtual Vacation';

CREATE TABLE `vacation_notification` (

 `on_vacation` varchar(255) CHARACTER SET latin1 NOT NULL,
 `notified` varchar(255) CHARACTER SET latin1 NOT NULL,
 `notified_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
 PRIMARY KEY (`on_vacation`,`notified`),
 CONSTRAINT `vacation_notification_pkey` FOREIGN KEY (`on_vacation`) REFERENCES `vacation` (`email`) ON DELETE CASCADE

) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Postfix Admin - Virtual Vacation Notifications';


ALTER TABLE `vacation_notification`
   ->   ADD CONSTRAINT `vacation_notification_ibfk_1` FOREIGN KEY (`on_vacation`) REFERENCES `vacation` (`email`) ON DELETE CASCADE;

Création de l'espace de travail

Pour que cela fonctionne, nous allons créer un utilisateur dédié à "vacation" avec * comme mot de passe ainsi que son espace de travail

groupadd -r -g 30000 vacation useradd -g vacation -u 30000 vacation -d /var/spool/vacation -m -s /sbin/nologin

mkdir /var/spool/vacation

On copie dedans le script vacation.pl

cp /vacation/extra/virtual_vacation/vacation.pl /var/spool/vacation/vacation.pl

Et on donne les bons droits chown -R vacation:vacation /var/spool/vacation/ && chmod 700 /var/spool/vacation/vacation.pl

ouvrez le ficher vacation.pl pour le paramétrer

vi /var/spool/vacation/vacation.pl

et renseignez les variables comprises entre

  1. =========== begin configuration ===========

our $db_type = 'mysql';

  1. leave empty for connection via UNIX socket

our $db_host = 'localhost';

  1. connection details

our $db_username = mon-user our $db_password = 'mon-password'; our $db_name = 'postfix';

our $vacation_domain = 'autoreply.mon-domaine';

  1. smtp server used to send vacation e-mails

our $smtp_server = 'smtp-mon-fai'; our $smtp_server_port = 25;

  1. path to logfile, when empty logging is supressed
  2. change to e.g. /dev/null if you want nothing logged.
  3. if we can't write to this, and $log_to_file is 1 (below) the script will abort.

our $logfile='/var/log/vacation.log';

  1. 2 = debug + info, 1 = info only, 0 = error only

our $log_level = 2;

  1. Whether to log to file or not, 0 = do not write to a log file

our $log_to_file = 1;

  1. =========== end configuration ===========

créer le fichier : /etc/mail/postfixadmin/vacation.conf ou dans /etc/postfixadmin/vacation.conf et intégrer les variables d’accès à la base de données (j'avoue ne pas comprendre pourquoi)

$db_type = 'mysql'; $db_host = 'localhost'; $db_username = 'mon-user'; $db_password = 'mon-password'; $db_name = 'postfix';

Maintenant, nous allons relier tout ce beau monde. Ici on ne s'occupe que du driver "virtuel"

Faites une copie de sauvegarde du fichier de configuration cp /var/www/roudcubemail/plugins/vacation/config.ini /var/www/roudcubemail/plugins/vacation/config.ini.sos

ouvrez le vi /var/www/roudcubemail/plugins/vacation/config.ini

commentez toutes les lignes, et rajoutez à la fin les lignes suivantes [default] driver = "virtual" subject = "Default subject" body = "default.txt" transport = "autoreply.mon-domaine" dbase = "postfix" always_keep_message = true dsn = "mysql://mon-user:mon-password@localhost/postfix" select_query = "SELECT goto FROM %m.alias WHERE address='%e' AND goto='%g'" insert_query = "INSERT INTO %m.alias (domain,address,goto) VALUES ('%i','%e','%g')" delete_query = "DELETE FROM %m.alias WHERE address='%e'"

Mise à jour de postfix

Passons maintenant a postfix. Ouvrez le fichier /etc/postfix/master.cf et rajoutez la ligne suivante vacation unix - n n - - pipe

 flags=Rq user=vacation:vacation argv=/var/spool/vacation/vacation.pl -f ${sender} -- ${recipient}

Activez la ligne smtp et rajoutez les directives suivantes

smtp inet n - - - 1 smtpd

   -o content_filter=amavis:[127.0.0.1]:10024
   -o receive_override_options=no_address_mappings

Allez dans le répertoire /etc/postfix et créez le fichier de la table transport vi /etc/postfix/transport

rajoutez dedans autoreply.mon-domaine vacation:

et recréez la database : postmap /etc/postfix/transport

Ouvrez le fichier vi /etc/postfix/main.cf et rajoutez la ligne :

transport_maps = hash:/etc/postfix/transport

et pour éviter de recevoir les nofifications en double vacation_destination_recipient_limit = 1

on réinitialise le tout par un bon vieux /etc/init.d/postfix restart

La partie postfix est terminée, passons maintenant à postfixadmin

Mise à jour de postfixadmin

Ouvrez le fichier : vi /var/www/postfixadmin/config.inc.php et modifier les variables suivantes. remplacez $CONF['vacation'] = 'NO' par $CONF['vacation'] = 'YES';

renseignez votre non de domaine $CONF['vacation_domain'] = 'autoreply.mon-domain';

Test & Vérification

1- connectez-vous sur postfixadmin avec votre login et password

  clicquez sur "réponse automatique" et valider avec le bouton "absence"

2- allez sur l'onglet vacation dans roudcube, cochez "Send a notification" on remplit "Autoreply subject" , "Autoreply message"

  et on garde une copie du mail en cochant "Keep a copy of the mail" et on sauvegarde le tout.

3- on s'envoie un mail de l'extérieur pour tester le tout

log de mail.log Jul 5 09:24:23 facteur postfix/smtpd[3083]: connect from mtaweb11.services.sfr.fr[93.17.128.28] Jul 5 09:24:23 facteur postgrey[2623]: action=pass, reason=triplet found, client_name=mtaweb11.services.sfr.fr, client_address=93.17.128.28, sender=mon-client@sfr.fr, recipient=gilles@mon-domaine Jul 5 09:24:23 facteur postfix/smtpd[3083]: C58E717EA8: client=mtaweb11.services.sfr.fr[93.17.128.28] Jul 5 09:24:24 facteur postfix/cleanup[3086]: C58E717EA8: message-id=<7759106.51521309843492192.JavaMail.www@wsfrf1112> Jul 5 09:24:24 facteur postfix/qmgr[2870]: C58E717EA8: from=<mon-client@sfr.fr>, size=1077, nrcpt=1 (queue active) Jul 5 09:24:24 facteur postfix/smtpd[3083]: disconnect from mtaweb11.services.sfr.fr[93.17.128.28] Jul 5 09:24:25 facteur postfix/smtpd[3090]: connect from localhost.localdomain[127.0.0.1] Jul 5 09:24:25 facteur postfix/smtpd[3090]: E313417EA9: client=localhost.localdomain[127.0.0.1] Jul 5 09:24:25 facteur postfix/cleanup[3086]: E313417EA9: message-id=<7759106.51521309843492192.JavaMail.www@wsfrf1112> Jul 5 09:24:25 facteur postfix/qmgr[2870]: E313417EA9: from=<mon-client@sfr.fr>, size=1539, nrcpt=2 (queue active) Jul 5 09:24:25 facteur postfix/smtp[3087]: C58E717EA8: to=<gilles@mon-domaine>, relay=127.0.0.1[127.0.0.1]:10024, delay=2.2, delays=0.25/0.01/0.01/1.9, dsn=2.0.0, status=sent (250 2.0.0 Ok, id=02304-01, from MTA([127.0.0.1]:10025): 250 2.0.0 Ok: queued as E313417EA9) Jul 5 09:24:25 facteur postfix/qmgr[2870]: C58E717EA8: removed Jul 5 09:24:26 facteur postfix/pipe[3091]: E313417EA9: to=<gilles@mon-domaine>, relay=dovecot, delay=0.08, delays=0.01/0.03/0/0.04, dsn=2.0.0, status=sent (delivered via dovecot service) Jul 5 09:24:28 facteur postfix/pipe[3092]: E313417EA9: to=<gilles@mon-domaine@autoreply.mon-domaine>, orig_to=<gilles@mon-domaine>, relay=vacation, delay=2.7, delays=0.01/0.03/0/2.6, dsn=2.0.0, status=sent (delivered via vacation service) Jul 5 09:24:28 facteur postfix/qmgr[2870]: E313417EA9: removed Jul 5 09:24:41 facteur postfix/smtpd[3044]: timeout after END-OF-MESSAGE from localhost.localdomain[127.0.0.1] Jul 5 09:24:41 facteur postfix/smtpd[3044]: disconnect from localhost.localdomain[127.0.0.1]

log de vacation.log 2011/07/05 09:24:26 DEBUG> /var/spool/vacation/vacation.pl:544 main:: - Script argument SMTP recipient is : '"gilles@mon-domaine"@autoreply.mon-domaine' and smtp_sender : 'mon-client@sfr.fr' 2011/07/05 09:24:26 DEBUG> /var/spool/vacation/vacation.pl:574 main:: - Converted autoreply mailbox back to normal style - from "gilles@mon-domaine"@autoreply.mon-domaine to "gilles@mon-domaine" 2011/07/05 09:24:26 DEBUG> /var/spool/vacation/vacation.pl:584 main:: - Email headers have to: '"Gilles Gilles (mon-domaine)" <gilles@mon-domaine>' and From: 'mon-client <mon-client@sfr.fr>' 2011/07/05 09:24:26 DEBUG> /var/spool/vacation/vacation.pl:327 main::find_real_address - Found 'gilles@mon-domaine' has vacation active 2011/07/05 09:24:26 DEBUG> /var/spool/vacation/vacation.pl:610 main:: - Attempting to send vacation response for: <7759106.51521309843492192.JavaMail.www@wsfrf1112> to: mon-client@sfr.fr, gilles@mon-domaine, gilles@mon-domaine (test_mode = 0) 2011/07/05 09:24:26 DEBUG> /var/spool/vacation/vacation.pl:417 main::send_vacation_email - Asked to send vacation reply to gilles@mon-domaine thanks to <7759106.51521309843492192.JavaMail.www@wsfrf1112> 2011/07/05 09:24:26 DEBUG> /var/spool/vacation/vacation.pl:429 main::send_vacation_email - Will send vacation response for <7759106.51521309843492192.JavaMail.www@wsfrf1112>: FROM: gilles@mon-domaine (orig_to: gilles@mon-domaine), TO: mon-client@sfr.fr; VACATION SUBJECT: absent cause vacances ; VACATION BODY: Bonjour

Pour tous renseignements, adressez-vous à:

Cordialement GC. 2011/07/05 09:24:28 DEBUG> /var/spool/vacation/vacation.pl:465 main::send_vacation_email - Vacation response sent to mon-client@sfr.fr, from gilles@mon-domaine