Guía técnica · 4 min read · Jan 03, 2026

Guía de Mailscanner/Exim Gateway Con Communigate PRO - Página 3

FuzzyOCR

Almacenaremos los hashes de las imágenes en una base de datos mysql para mejorar el rendimiento de modo que las imágenes que ya hemos escaneado no se escaneen de nuevo, ya que el OCR es una actividad que consume muchos recursos.

Crear Base de Datos MySQL

El script sql crea la base de datos y las tablas y añade un usuario fuzzyocr con la contraseña fuzzyocr:

mysql -p < /usr/local/src/devel/FuzzyOcr.mysql

Cambia la contraseña:

mysqladmin -u fuzzyocr -p fuzzyocr password

Configuración Básica

Edita /etc/mail/spamassassin/FuzzyOCR.cf y establece las opciones básicas:

focr_path_bin /usr/bin:/usr/local/bin  

focr_minimal_scanset 1  

focr_autosort_scanset 1  

focr_enable_image_hashing 3  

focr_logfile /tmp/FuzzyOcr.log

Hacer que FuzzyOCR Use la Base de Datos

Edita el archivo /etc/mail/spamassassin/FuzzyOCR.cf y añade:

focr_mysql_db FuzzyOcr  

focr_mysql_hash Hash  

focr_mysql_safe Safe  

focr_mysql_user fuzzyocr  

focr_mysql_pass password  

focr_mysql_host localhost  

focr_mysql_port 3306  

focr_mysql_socket /var/lib/mysql/mysql.sock

Configurar Razor

Registra tu sistema razor:

razor-admin -register

Configurar Clamav

Configuración Base

Esta instalación de clamav utilizará tanto las firmas oficiales como las firmas de sanesecurity que se utilizan para combatir el spam de imágenes y pdf, así como los ataques de phishing.

Añade el usuario clamav al grupo exim:

usermod -G exim clamav

Configura clamd para escuchar en el socket unix:

LocalSocket /var/run/clamav/clamd.socket

Configura clamd para que se inicie al arrancar:

chkconfig --level 345 clamd on

SELinux

Para que clamav pueda funcionar en modo de aplicación forzada, necesitamos añadir algunos módulos de política localizados. La política de ejemplo es la siguiente:

module clamlocal 1.0;
require {
        class dir { add_name read remove_name search write };
        class file { create getattr lock read write append };
        type clamd_t;
        type clamd_var_log_t;
        type logwatch_t;
        type proc_t;
        type sysctl_kernel_t;
        type var_spool_t;
        type var_t;
        type var_log_t;
        role system_r;
};
allow clamd_t proc_t:file { getattr read };
allow clamd_t sysctl_kernel_t:dir search;
allow clamd_t sysctl_kernel_t:file read;
allow clamd_t var_spool_t:dir read;
allow clamd_t var_spool_t:file { getattr read };
allow clamd_t var_t:dir { add_name read remove_name write };
allow clamd_t var_t:file { create getattr lock read write };
allow logwatch_t clamd_var_log_t:dir { read search };
allow clamd_t var_log_t:file append;
allow clamd_t var_t:dir { read write };

El módulo se puede descargar de http://www.topdog-software.com/files/clamlocal.te.gz.

Construye e instala el módulo:

wget http://www.topdog-software.com/files/clamlocal.te.gz  
gunzip clamlocal.te.gz  
checkmodule -M -m -o clamlocal.mod clamlocal.te  
semodule_package -o clamlocal.pp -m clamlocal.mod  
semodule -i clamlocal.pp

Configurar Mailwatch

Parche para Versión Mejorada

Este parche hace que mailwatch libere mensajes a través de mailfeeder reinyectando el mensaje real a través del servidor smtp para que aparezca como el mensaje original que se envió, a diferencia de la liberación predeterminada de mailwatch que envía el correo liberado como un archivo adjunto desde la cuenta del postmaster.

wget http://www.topdog-software.com/files/mailwatch_release.patch.gz  
gunzip mailwatch_release.patch.gz  
cd /var/www/html  
patch -i ../mailwatch_release.patch

Configurar el Directorio Base

Dado que estamos instalando mailwatch en /var/www/html en lugar de /var/www/html/mailscanner, necesitamos hacer modificaciones en el archivo de configuración conf.php para reflejar esto:

define(MAILWATCH_HOME, '/var/www/html');

Configurar para Base de Datos

Establece las siguientes opciones en conf.php:

define(DB_TYPE, 'mysql');
define(DB_USER, 'mailwatch');
define(DB_PASS, 'password');
define(DB_HOST, 'localhost:/var/lib/mysql/mysql.sock');
define(DB_NAME, 'mailscanner');

Cuarentena

Establece esto en el archivo conf.php:

define(QUARANTINE_USE_FLAG, true);
define(QUARANTINE_DAYS_TO_KEEP, 30);

Instala el script de limpieza de cuarentena

cp /usr/local/src/mailwatch-1.0.4/tools/quarantine_maint.php /usr/local/bin/  
chmod +x /usr/local/bin/quarantine_maint.php  
ln -s /usr/local/bin/quarantine_maint.php /etc/cron.daily

Desactiva el script cron instalado por mailscanner /etc/cron.daily/clean.quarantine

$disabled = 1;

SELinux

Para que mailwatch funcione en modo de aplicación forzada, necesitamos instalar un módulo de política selinux personalizado. La fuente del módulo es la siguiente:

module mailwatch 1.0;

require {
        class dir { getattr read search };
        class file { getattr read execute execute_no_trans ioctl };
        class lnk_file { read getattr };
        class tcp_socket name_connect;
        type spamc_exec_t;
        type clamd_t;
        type getty_t;
        type hostname_exec_t;
        type initrc_t;
        type unconfined_t;
        type var_spool_t;
        type etc_mail_t;
        type ls_exec_t;
        type smtp_port_t;
        type spamassassin_exec_t;
        type httpd_sys_content_t;
        type httpd_t;
        type mysqld_t;
        type lib_t;
};

allow httpd_t clamd_t:dir getattr;
allow httpd_t hostname_exec_t:file getattr;
allow httpd_t var_spool_t:dir read;
allow httpd_t var_spool_t:file { getattr ioctl read };
allow httpd_t spamc_exec_t:file { execute execute_no_trans getattr read ioctl };
allow httpd_t etc_mail_t:dir { search getattr read };
allow httpd_t etc_mail_t:file { getattr read ioctl };
allow httpd_t etc_mail_t:lnk_file { getattr read };
allow httpd_t hostname_exec_t:file { execute read execute_no_trans };
allow httpd_t unconfined_t:dir { getattr search read };
allow httpd_t unconfined_t:file { read };
allow httpd_t initrc_t:dir { getattr search read };
allow httpd_t initrc_t:file read;
allow httpd_t ls_exec_t:file { execute read getattr execute_no_trans };
allow httpd_t spamassassin_exec_t:file { execute getattr read execute_no_trans ioctl };
allow mysqld_t httpd_sys_content_t:dir { getattr read search };
allow mysqld_t httpd_sys_content_t:file { read getattr };
allow httpd_t smtp_port_t:tcp_socket name_connect;
allow httpd_t lib_t:file execute_no_trans;

La fuente del módulo se puede descargar de http://www.topdog-software.com/files/mailwatch.te.gz.

Construye e instala el módulo:

wget http://www.topdog-software.com/files/mailwatch.te.gz  
gunzip mailwatch.te.gz  
checkmodule -M -m -o mailwatch.mod mailwatch.te  
semodule_package -o mailwatch.pp -m mailwatch.mod  
semodule -i mailwatch.pp

GeoIP

Conéctate a tu servidor http://hostname/ inicia sesión, haz clic en el menú “Herramientas/Enlaces” ? “Actualizar base de datos GeoIP” y haz clic en “Ejecutar ahora”.

Monitor de Cola de Correo

Instala el script de monitoreo:

cp /usr/local/src/mailwatch-1.0.4/mailq.php /usr/local/bin  
chmod +x /usr/local/bin/mailq.php  
crontab -e  
0-59 * * * * /usr/local/bin/mailq.php

Edita para el nuevo diseño de directorio:

if(flock($fl, LOCK_EX + LOCK_NB)) {
 require "/var/www/html/functions.php";

``
Share: X/Twitter LinkedIn

Recibe nuevas publicaciones en tu bandeja de entrada.

No spam. Cancela la suscripción en cualquier momento.