Wydrukuj tę dokumentację


Przygotowanie zaplecza MailZu

Powstał program (WebUI) do przepuszczania maili z kwarantanny do użytkownika.

Instalacja w systemie

Z wykorzystaniem własnego repozytorium pakietów należy zainstalować paczkę:

pkg install -y security/mailzu

Jako silnik bazy danych na kwarantannę jest wykorzystany PostgreSQL.

Baza danych

Utworzenie bazy danych:

createuser -U postgres -SDR -PE mxcleaner
createdb -U postgres -O mxcleaner -E UTF8 mxclcentre

/!\ Zmiana dla PostgreSQL w wersji 9.x: zmienił się format dla bytea. Aby działało poprawnie, należy w pliku postgresql.conf ustawić następującą zmienną:

bytea_output = 'escape'                 # hex, escape

Po wykonaniu zmian należy wykonać restart serwera PostgreSQL:

service postgresql restart

Wyłuskanie schematu bazy danych z dokumentacji

Nie ma oddzielnie schematu bazy danych. Tak więc należy wyłuskać go z dokumentacji /usr/local/share/doc/amavisd-new/README.sql-pg.

Instalacja schematu w bazie danych

psql -U mxcleaner mxclcentre < /var/tmp/_mailzu.sql

(!) UPDATE 26.01.2011: Trzeba dodać następującą funkcję do bazy danych, aby poprawnie działało podsumowanie kwarantanny (symulacja funckji z mySQL):

CREATE OR REPLACE FUNCTION from_unixtime(unixts integer)
  RETURNS timestamp without time zone AS
$BODY$SELECT CAST('epoch' As timestamp) + ($1 * INTERVAL '1 second') $BODY$
  LANGUAGE 'sql' IMMUTABLE;

Konfiguracja amavisd

Do konfiguracji amavisd.conf należy dodać następujące elementy:

# --- zapisywanie kwarantanny w bazie danych ---------------------------------
#
@storage_sql_dsn = (
      ['DBI:Pg:database=<DATABASE>;host=127.0.0.1;port=5432', '<USER>',
       '<PASSWORD>'
]);
$sql_allow_8bit_address = 1;

$inet_socket_port = [10024,9998]; 

# --- przypisanie si/e do wszystkich interfejs/ow, aby dobrze dzia/la/l MailZu
#
$inet_socket_bind = undef;

# --- policy bank ------------------------------------------------------------
#
$interface_policy{'9998'} = 'AM.PDP';
$policy_bank{'AM.PDP'} = {
    protocol => 'AM.PDP',
    inet_acl => [qw( 127.0.0.1 <IP_1> <IP_2> )],
};

$virus_quarantine_method = 'sql:';
$banned_files_quarantine_method = 'sql:';
$spam_quarantine_method         = 'sql:';

$virus_quarantine_to = 'virus-quarantine';    # traditional local quarantine
$spam_quarantine_to = 'spam-quarantine';
$banned_quarantine_to = 'banned-quarantine';

Po wykonaniu zmian (trzeba wpisać w odpowiednich miejscach), należy wykonać restart amavisd:

service amavisd restart

Konfiguracja mailzu

Aplikacja mailzu (PHP) wymaga nieco poprawek (wynikające z nowych wersji PHP) oraz konfiguracji.

Polonizacja

Zostały wykonane tłumaczenia (prawie) całego interfejsu mailzu. W tym celu należy wgrać poniższe pliki:

do katalogu lang/:

cp -p /root/mailzu/pl.* /usr/local/www/mailzu/lang/

(!) Może z czasem pojawi się polska wersja mailzu, ale na razie trzeba posiłkować się pracą wtps0na:

Patchowanie

Dodatkowo konieczne jest dodanie kilku patchy, aby aplikacja działała poprawnie:

cd /usr/local/www/mailzu/

# p/etla po wszsytkich patchach wgranych do katalogu tymczasowego
for f in `ls /root/mailzu/patch*`; do patch -p0 < $f; done

config/config.php

Poniższy wynika polecenia diff może posłużyć do wykonania zmian dla nowej instancji mailzu:

--- /usr/local/www/mailzu/config/config.php.sample      2007-06-14 21:00:15.000000000 +0200
+++ /usr/local/www/mailzu/config/config.php     2016-09-28 15:31:26.021805000 +0200
@@ -76,23 +76,23 @@ $conf['amavisd']['spam_release_port'] =
        ifx    -> Informix
        fbsql  -> FrontBase
 */
-$conf['db']['dbType'] = 'mysql';
+$conf['db']['dbType'] = 'pgsql';

 // Database user who can access the amavisd database
-$conf['db']['dbUser'] = 'user';
+$conf['db']['dbUser'] = 'mxcleaner';

 // Password for above user to access the amavisd database
-$conf['db']['dbPass'] = 'pass';
+$conf['db']['dbPass'] = '<HASLO>';

 // Name of database
-$conf['db']['dbName'] = 'dbname';
+$conf['db']['dbName'] = 'mxclcentre';

 // Database host specification (hostname[:port]) [localhost]
-$conf['db']['hostSpec'] = 'hostname.example.com:3306';
+$conf['db']['hostSpec'] = '127.0.0.1:5432';

 // If using the bytea or BLOB mail_text quarantine type set to
 // True. Since amavisd-2.4.4.
-$conf['db']['binquar'] = false;
+$conf['db']['binquar'] = true;

 /**********
 * Authentication Settings
@@ -114,13 +114,13 @@ $conf['auth']['serverType'] = 'ldap';

 /*** LDAP Authentication Settings ***/
 // List of LDAP servers
-$conf['auth']['ldap_hosts'] = array( 'ldaphost.example.com' );
+$conf['auth']['ldap_hosts'] = array( '127.0.0.1' );
 // if set to true, LDAP connection over SSL (PHP 4.0.4 minimum)
 // if set to false or not set, unencrypted LDAP connection on port 389
 $conf['auth']['ldap_ssl'] = false;

 // LDAP base dn, e.g. 'dc=example,dc=com'
-$conf['auth']['ldap_basedn'] = 'dc=example,dc=org';
+$conf['auth']['ldap_basedn'] = 'ou=smtpd,dc=mojadomena,dc=local';

 // LDAP attribute used for the RDN to identify a person
 // For instance if the DN for a given user is uid=joesmith,ou=people,dc=example,dc=com
@@ -143,7 +143,7 @@ $conf['auth']['ldap_name'] = 'givenName'
 // LDAP mail attribute(s) used as the final recipient address
 // Could be the actual mail attribute or another attribute
 // (in the latter case look for the "%m" token in the ldap query filter in amavisd.conf)
-$conf['auth']['ldap_mailAttr'] = array('mailRoutingAddress');
+$conf['auth']['ldap_mailAttr'] = array('mail', 'mailAlternateAddress');

 // If $conf['auth']['ldap_login'] is different from 'uid', we need to determine
 // corresponding 'uid' by binding anonymously or with the user defined below.
@@ -262,10 +262,10 @@ $conf['auth']['imap_hosts'] = array( 'im
        imapcert -> use the Secure Socket Layer to encrypt the session,
                    do not validate certificates from TLS/SSL server, needed if server uses self-signed certificates
 */
-$conf['auth']['imap_type'] = 'imapssl';
+$conf['auth']['imap_type'] = 'imap';

 // Domain name part of the email address, (e.g.: example.com)
-$conf['auth']['imap_domain_name'] = 'example.com';
+$conf['auth']['imap_domain_name'] = '127.0.0.1';


 /**
@@ -291,12 +291,12 @@ $conf['auth']['imap_domain_name'] = 'exa
 // List of Super Admins
 // Super Admins can do anything mail admins can plus
 // change settings
-$conf['auth']['s_admins'] = array ('user1', 'user2');
+$conf['auth']['s_admins'] = array ('wtps0nx', 'admin');

 // List of Mail Admins
 // Mail Admins can see other users' spam and attachments
 // and can perform any action on them
-$conf['auth']['m_admins'] = array ();
+$conf['auth']['m_admins'] = array ('wtps0nx', 'admin');

 // User login restriction (Does not affect admins)
 // If set to true, users will not be able to login. This is if you do
@@ -327,7 +327,7 @@ $conf['ui']['welcome'] = 'Welcome to Mai

 // The full url to the root directory of MailZu
 // Please do not include the trailing slash
-$conf['app']['weburi'] = 'https://mailzuhost.example.com/mailzu';
+$conf['app']['weburi'] = 'https://<NAZWA_HOSTA_WWW>/mq';

 // How to send email ['mail']
 /* Options are:
@@ -336,11 +336,11 @@ $conf['app']['weburi'] = 'https://mailzu
         'sendmail' for sendmail
         'qmail' for qmail MTA
 */
-$conf['app']['emailType'] = 'mail';
+$conf['app']['emailType'] = 'sendmail';

 // SMTP email host address []
 // This is only required if emailType is SMTP
-$conf['app']['smtpHost'] = '';
+$conf['app']['smtpHost'] = 'localhost.bsdserwis.com';

 // SMTP port [25]
 // This is only required if emailType is SMTP
@@ -348,7 +348,7 @@ $conf['app']['smtpPort'] = 25;

 // Path to sendmail ['/usr/sbin/sendmail']
 // This only needs to be set if the emailType is 'sendmail'
-$conf['app']['sendmailPath'] = '/usr/sbin/sendmail';
+$conf['app']['sendmailPath'] = '/usr/local/sbin/sendmail';

 // Path to qmail ['/var/qmail/bin/sendmail']
 // This only needs to be set if the emailType is 'qmail'
@@ -363,7 +363,7 @@ $conf['recipient_delimiter'] = '';
 // The email addresses of the support staff and/or administrator
 // An email is sent to these addresses when a user reports an error
 // or clicks the "Email Administrator" link
-$conf['app']['adminEmail'] = array('support@example.com');
+$conf['app']['adminEmail'] = array('postmaster@<__DOMENA__>');

 // Email admin upon Release Request
 // When users try to release a banned file a request is sent to an
@@ -398,7 +398,7 @@ $conf['app']['searchOnly'] = 1;

 // The default language code.  This must be included in the language list in
 // langs.php
-$conf['app']['defaultLanguage'] = 'en_US';
+$conf['app']['defaultLanguage'] = 'pl';

 // Display the choice for language selection during the login screen if set to 1
 // Otherwise set it to 0
@@ -417,18 +417,18 @@ $conf['app']['timeFormat'] = 12;

 // Title of application ['MailZu']
 // Will be used for page titles and in 'From' field of email responses
-$conf['app']['title'] = 'MailZu';
+$conf['app']['title'] = 'Kwarantanna poczty dla __FIRMA__';

 // If we should log system activity or not [0]
 // Can be 0 (for no) and 1 (for yes)
 $conf['app']['use_log'] = 1;

 // If we should log additional debug information
-$conf['app']['debug'] = 0;
+$conf['app']['debug'] = 1;

 // Directory/file for log ['/var/log/mailzu.log']
 // Specify as /directory/filename.extension
-$conf['app']['logfile'] = '/var/log/mailzu.log';
+$conf['app']['logfile'] = '/var/log/mailzu/mailzu.log';

 // Maximum number of messages displayed per page
 $conf['app']['displaySizeLimit'] = 50;
@@ -446,7 +446,7 @@ $conf['app']['allowViruses'] = 0;

 // Allow users to search by Mailid
 // $conf['app']['allowMailid'] = 0
-$conf['app']['allowMailid'] = 0;
+$conf['app']['allowMailid'] = 1;

 include_once('init.php');
 ?>

Należy także wykonać katalog do trzymania wersji konfiguracji:

cd /usr/local/www/mailzu/config/
mkdir -p RCS

Ustawienie uprawnień

Po wykonaniu konfiguracji, należy ustawić uprawnienia do plików:

cd /usr/local/www/mailzu/
find ./  -exec chgrp www {} \;
find ./ -type f -exec chmod 0040 {} \;
find ./ -type d -exec chmod 0050 {} \;
cd config/
chmod 0240 config.php
chmod 0750 RCS/
chmod 0050 /usr/local/www/mailzu/scripts/mz_db_clean.pl

A potem to już pozostaje jedynie zabezpieczyć konfigurację przed zmianami. :-)

Konfiguracja Apache'a

Konfiguracja Apache'a sprowadza się do wykonania aliasu, aby udostępnić MailZu:

Alias /mq/ "/usr/local/www/mailzu/"

Definicja katalogu jest zapisana w pliku 016-mailzu.conf utrzymywanego w repozytorium konfiguracji.

Po wykonaniu zmian, trzeba przeładować konfigurację Apache'a:

apachectl graceful

Skrypty pomocnicze

W istniejącej instalacji były poprawnie zaaplikowane łatki do w/wplików. W tym celu powstał szybki jednolinijkowiec pozwalający na wykonanie plików patchy:

for f in `find -s ./ -type f -name '*.orig'`; do n=`echo $f|sed -e 's/.orig//'`; p=`echo $n|sed -e 's|./||;s|/|__|g'`; diff -udp $f $n > /root/mailzu/patch-$p; done


{i}  (c) 2004 - 2026 BSD Serwis Krzysztof Stryjek. W przypadku błędów, poprawek proszę kontaktować się z administratorem wiki.

MailZu (ostatnio edytowane 2024-09-28 10:04:48 przez wtps0n)