Почтовый сервер в связке Postfix, Dovecot — различия между версиями

Материал из megapuper
Перейти к: навигация, поиск
Строка 156: Строка 156:
 
<spoiler>
 
<spoiler>
 
<?php
 
<?php
−
/**
 
−
* Postfix Admin
 
−
*
 
−
* LICENSE
 
−
* This source file is subject to the GPL license that is bundled with 
 
−
* this package in the file LICENSE.TXT.
 
−
*
 
−
* Further details on the project are available at http://postfixadmin.sf.net
 
−
*
 
−
* @version $Id: config.inc.php 1694 2014-10-07 16:11:49Z christian_boltz $
 
−
* @license GNU GPL v2 or later.
 
−
*
 
−
* File: config.inc.php
 
−
* Contains configuration options.
 
−
*/
 
  
−
/*****************************************************************
 
−
*  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
−
* You have to set $CONF['configured'] = true; before the
 
−
* application will run!
 
−
* Doing this implies you have changed this file as required.
 
−
* i.e. configuring database etc; specifying setup.php password etc.
 
−
*/
 
 
$CONF['configured'] = true;
 
$CONF['configured'] = true;
  
Строка 184: Строка 162:
 
// To create the hash, visit setup.php in a browser and type a password into the field,
 
// To create the hash, visit setup.php in a browser and type a password into the field,
 
// on submission it will be echoed out to you as a hashed value.
 
// on submission it will be echoed out to you as a hashed value.
−
$CONF['setup_password'] = 'ad33d6e7b55b7709b3987d83efd7c300:a11934abc5fbe70e1d61e711f1ba2dc7b77f0b47';
+
$CONF['setup_password'] = 'пароль установки';
  
 
// Language config
 
// Language config
Строка 193: Строка 171:
 
// Set to the function name you want to use as hook function (see language_hook example function below)
 
// Set to the function name you want to use as hook function (see language_hook example function below)
 
$CONF['language_hook'] = '';
 
$CONF['language_hook'] = '';
−
 
−
/*
 
−
    language_hook example function
 
−
 
−
    Called if $CONF['language_hook'] == '<name_of_the_function>'
 
−
    Allows to add or override $PALANG interface texts.
 
−
 
−
    If you add new texts, please always prefix them with 'x_' (for example
 
−
    $PALANG['x_mytext'] = 'foo') to avoid they clash with texts that might be
 
−
    added to languages/*.lang in future versions of PostfixAdmin.
 
−
 
−
    Please also make sure that all your added texts are included in all
 
−
    sections - that includes all 'case "XY":' sections and the 'default:'
 
−
    section (for users that don't have any of the languages specified
 
−
    in the 'case "XY":' section).
 
−
    Usually the 'default:' section should contain english text.
 
−
 
−
    If you modify an existing text/translation, please consider to report it
 
−
    to the bugtracker on http://sf.net/projects/postfixadmin so that all users
 
−
    can benefit from the corrected text/translation.
 
−
 
−
    Returns: modified $PALANG array
 
−
*/
 
−
/*
 
−
function language_hook($PALANG, $language) {
 
−
    switch ($language) {
 
−
        case "de":
 
−
            $PALANG['x_whatever'] = 'foo';
 
−
            break;
 
−
        case "fr":
 
−
            $PALANG['x_whatever'] = 'bar';
 
−
            break;
 
−
        default:
 
−
            $PALANG['x_whatever'] = 'foobar';
 
−
    }
 
−
 
−
    return $PALANG;
 
−
}
 
−
*/
 
  
 
// Database Config
 
// Database Config
Строка 242: Строка 181:
 
$CONF['database_password'] = 'q';
 
$CONF['database_password'] = 'q';
 
$CONF['database_name'] = 'postfix';
 
$CONF['database_name'] = 'postfix';
−
// If you need to specify a different port for a MYSQL database connection, use e.g.
 
−
//  $CONF['database_host'] = '172.30.33.66:3308';
 
−
// If you need to specify a different port for POSTGRESQL database connection
 
−
//  uncomment and change the following
 
−
// $CONF['database_port'] = '5432';
 
  
 
// Here, if you need, you can customize table names.
 
// Here, if you need, you can customize table names.
Строка 267: Строка 201:
  
 
// Site Admin
 
// Site Admin
−
// Define the Site Admin's email address below.
 
−
// This will be used to send emails from to create mailboxes and
 
−
// from Send Email / Broadcast message pages.
 
−
// Leave blank to send email from the logged-in Admin's Email address.
 
 
$CONF['admin_email'] = 'postmaster@megapuper.ru';
 
$CONF['admin_email'] = 'postmaster@megapuper.ru';
  
 
// Mail Server
 
// Mail Server
−
// Hostname (FQDN) of your mail server.
 
−
// This is used to send email to Postfix in order to create mailboxes.
 
 
$CONF['smtp_server'] = '127.0.0.1';
 
$CONF['smtp_server'] = '127.0.0.1';
 
$CONF['smtp_port'] = '25';
 
$CONF['smtp_port'] = '25';
  
 
// Encrypt
 
// Encrypt
−
// In what way do you want the passwords to be crypted?
 
−
// md5crypt = internal postfix admin md5
 
−
// md5 = md5 sum of the password
 
−
// system = whatever you have set as your PHP system default
 
−
// cleartext = clear text passwords (ouch!)
 
−
// mysql_encrypt = useful for PAM integration
 
−
// authlib = support for courier-authlib style passwords
 
−
// dovecot:CRYPT-METHOD = use dovecotpw -s 'CRYPT-METHOD'. Example: dovecot:CRAM-MD5
 
−
//  (WARNING: don't use dovecot:* methods that include the username in the hash - you won't be able to login to PostfixAdmin in this case)
 
 
$CONF['encrypt'] = 'cleartext';
 
$CONF['encrypt'] = 'cleartext';
−
 
−
// In what flavor should courier-authlib style passwords be encrypted?
 
−
// md5 = {md5} + base64 encoded md5 hash
 
−
// md5raw = {md5raw} + plain encoded md5 hash
 
−
// SHA = {SHA} + base64-encoded sha1 hash
 
−
// crypt = {crypt} + Standard UNIX DES-encrypted with 2-character salt
 
−
$CONF['authlib_default_flavor'] = 'md5raw';
 
−
 
−
// If you use the dovecot encryption method: where is the dovecotpw binary located?
 
−
// for dovecot 1.x
 
−
// $CONF['dovecotpw'] = "/usr/sbin/dovecotpw";
 
−
// for dovecot 2.x (dovecot 2.0.0 - 2.0.7 is not supported!)
 
−
//$CONF['dovecotpw'] = "/usr/sbin/doveadm pw";
 
  
 
// Password validation
 
// Password validation
 
// New/changed passwords will be validated using all regular expressions in the array.
 
// New/changed passwords will be validated using all regular expressions in the array.
 
// If a password doesn't match one of the regular expressions, the corresponding
 
// If a password doesn't match one of the regular expressions, the corresponding
−
// about the regular expression syntax.
+
// error message from $PALANG (see languages/) will be displayed.
 
// If you need custom error messages, you can add them using $CONF['language_hook'].
 
// If you need custom error messages, you can add them using $CONF['language_hook'].
 
// If a $PALANG text contains a %s, you can add its value after the $PALANG key
 
// If a $PALANG text contains a %s, you can add its value after the $PALANG key
Строка 319: Строка 225:
  
 
// Generate Password
 
// Generate Password
−
// Generate a random password for a mailbox or admin and display it.
 
−
// If you want to automagically generate passwords set this to 'YES'.
 
 
$CONF['generate_password'] = 'NO';
 
$CONF['generate_password'] = 'NO';
  
 
// Show Password
 
// Show Password
−
// Always show password after adding a mailbox or admin.
 
−
// If you want to always see what password was set set this to 'YES'.
 
 
$CONF['show_password'] = 'NO';
 
$CONF['show_password'] = 'NO';
  
Строка 331: Строка 233:
 
// Set the number of entries that you would like to see
 
// Set the number of entries that you would like to see
 
// in one page.
 
// in one page.
−
$CONF['page_size'] = '20';
+
$CONF['page_size'] = '50';
  
 
// Default Aliases
 
// Default Aliases
−
// The default aliases that need to be created for all domains.
 
−
// You can specify the target address in two ways:
 
−
// a) a full mail address
 
−
// b) only a localpart ('postmaster' => 'admin') - the alias target will point to the same domain
 
 
//$CONF['default_aliases'] = array (
 
//$CONF['default_aliases'] = array (
 
//    'abuse' => 'abuse@change-this-to-your.domain.tld',
 
//    'abuse' => 'abuse@change-this-to-your.domain.tld',
Строка 346: Строка 244:
  
 
// Mailboxes
 
// Mailboxes
−
// If you want to store the mailboxes per domain set this to 'YES'.
 
−
// Examples:
 
 
//  YES: /usr/local/virtual/domain.tld/username@domain.tld
 
//  YES: /usr/local/virtual/domain.tld/username@domain.tld
 
//  NO:  /usr/local/virtual/username@domain.tld
 
//  NO:  /usr/local/virtual/username@domain.tld
 
$CONF['domain_path'] = 'YES';
 
$CONF['domain_path'] = 'YES';
 
// If you don't want to have the domain in your mailbox set this to 'NO'.
 
// If you don't want to have the domain in your mailbox set this to 'NO'.
−
// Examples:
 
 
//  YES: /usr/local/virtual/domain.tld/username@domain.tld
 
//  YES: /usr/local/virtual/domain.tld/username@domain.tld
 
//  NO:  /usr/local/virtual/domain.tld/username
 
//  NO:  /usr/local/virtual/domain.tld/username
Строка 358: Строка 253:
 
$CONF['domain_in_mailbox'] = 'NO';
 
$CONF['domain_in_mailbox'] = 'NO';
 
// If you want to define your own function to generate a maildir path set this to the name of the function.
 
// If you want to define your own function to generate a maildir path set this to the name of the function.
−
// Notes:
 
 
//  - this configuration directive will override both domain_path and domain_in_mailbox
 
//  - this configuration directive will override both domain_path and domain_in_mailbox
 
//  - the maildir_name_hook() function example is present below, commented out
 
//  - the maildir_name_hook() function example is present below, commented out
Строка 364: Строка 258:
 
$CONF['maildir_name_hook'] = 'NO';
 
$CONF['maildir_name_hook'] = 'NO';
  
−
/*
 
−
    maildir_name_hook example function
 
−
 
−
    Called when creating a mailbox if $CONF['maildir_name_hook'] == '<name_of_the_function>'
 
−
    - allows for customized maildir paths determined by a custom function
 
−
    - the example below will prepend a single-character directory to the
 
−
      beginning of the maildir, splitting domains more or less evenly over
 
−
      36 directories for improved filesystem performance with large numbers
 
−
      of domains.
 
−
 
−
    Returns: maildir path
 
−
    ie. I/example.com/user/
 
−
*/
 
−
/*
 
−
function maildir_name_hook($domain, $user) {
 
−
    $chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 
−
 
−
    $dir_index = hexdec(substr(md5($domain), 28)) % strlen($chars);
 
−
    $dir = substr($chars, $dir_index, 1);
 
−
    return sprintf("%s/%s/%s/", $dir, $domain, $user);
 
−
}
 
−
*/
 
−
 
−
/* 
 
−
    *_struct_hook - change, add or remove fields
 
−
 
−
    If you need additional fields or want to change or remove existing fields,
 
−
    you can write a hook function to modify $struct in the *Handler classes.
 
−
 
−
    The edit form will automatically be updated according to the modified
 
−
    $struct. The list page is not yet updated automatically.
 
−
 
−
    You can define one hook function per class, named like the primary database
 
−
    table of that class.
 
−
    The hook function is called with $struct as parameter and must return the
 
−
    modified $struct.
 
−
 
−
    Note: Adding a field to $struct adds the handling of this field in
 
−
    PostfixAdmin, but it does not create it in the database. You have to do
 
−
    that yourself.
 
−
    Please follow the naming policy for custom database fields and tables on
 
−
    http://sourceforge.net/apps/mediawiki/postfixadmin/index.php?title=Custom_fields
 
−
    to avoid clashes with future versions of PostfixAdmin.
 
−
 
−
    See initStruct() in the *Handler class for the default $struct.
 
−
    See pacol() in functions.inc.php for the available flags on each column.
 
−
   
 
−
    Example:
 
−
 
−
    function x_struct_admin_modify($struct) {
 
−
        $struct['superadmin']['editable'] = 0;          # make the 'superadmin' flag read-only
 
−
        $struct['superadmin']['display_in_form'] = 0;  # don't display the 'superadmin' flag in edit form
 
−
        $struct['x_newfield'] = pacol( [...] );        # additional field 'x_newfield'
 
−
        return $struct; # important!
 
−
    }
 
−
    $CONF['admin_struct_hook'] = 'x_struct_admin_modify';
 
−
*/
 
 
$CONF['admin_struct_hook']          = '';
 
$CONF['admin_struct_hook']          = '';
 
$CONF['domain_struct_hook']        = '';
 
$CONF['domain_struct_hook']        = '';

Версия 17:16, 22 апреля 2015

При установке будем ориентироваться на этот мануал: http://dummyluck.com/page/pochtovyi_server_nastroika_opisanie
Настройку будем производить для сервера с одним доменом. Система FreeBSD 10.1


1. Подготовка. прописываем хостнейм /etc/rc.conf
hostname="mail.megapuper.ru"


делаем изменения в хостах /etc/hosts

127.0.0.1         localhost
109.172.52.114	  megapuper.ru
109.172.52.114    mail.megapuper.ru


создаём пользователя и группу vmail

# pw groupadd vmail -g 5000
# pw useradd vmail -g vmail -s /sbin/nologin -u 5000


сразу отключаем sendmail
/etc/rc.conf

sendmail_enable="NO"
sendmail_submit_enable="NO"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="NO"

/etc/periodic.conf

daily_clean_hoststat_enable="NO"
daily_status_mail_rejects_enable="NO"
daily_status_include_submit_mailq="NO"
daily_submit_queuerun="NO"


2. Ставим Nginx, MySQL, PHP, PHP-extension. Этот web-сервер будет использоваться для postfixadmin.

Здесь коротко, ибо уже тыщу раз ставилось)


Nginx cтавим из пакетов

# pkg install nginx


основной конфиг /usr/local/etc/nginx/nginx.conf

user www;
worker_processes  2;
pid        /var/run/nginx.pid;
events {
worker_connections  1024;
}

http {
     access_log    /var/log/nginx/access.log;
     error_log     /var/log/nginx/error.log;

     include       /usr/local/etc/nginx/mime.types;
     default_type  application/octet-stream;

     sendfile on;
     tcp_nopush on;
     tcp_nodelay on;
     keepalive_timeout  65;
     client_max_body_size 5m;
     server_names_hash_bucket_size 64;
     types_hash_max_size 2048;
     types_hash_bucket_size 64;
     include /usr/local/etc/nginx/conf/*.conf;
}


конфиг виртуального хоста /usr/local/etc/nginx/conf/postfix.conf

server {
        listen 80;
        server_name postfix.megapuper.ru;

root /usr/local/www/postfix;
        index index.php index.html index.htm;

        access_log /var/log/nginx/postfix.access.log;
        error_log  /var/log/nginx/postfix.error.log;

location / {
#        try_files $uri $uri/ /index.php?$uri&$args;
        }

location ~ \.php$ {
    fastcgi_pass   127.0.0.1:10000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
    fastcgi_intercept_errors on;
    include fastcgi_params;
        }
    }


PHP и нужные PHP-extension тоже ставим из пакетов

# pkg install php55
# pkg install php55-* (пригодятся php55-ctype php55-dom php55-gd php55-hash php55-iconv php55-imap php55-json php55-mbstring php55-mcrypt php55-mysql php55-mysqli php55-session php55-xml)


конфиг php-fpm /usr/local/etc/php-fpm.conf

[global]
error_log = /var/log/php/php-fpm.log
pid = /var/run/php-fpm.pid
log_level = notice
include=/usr/local/etc/php/*.conf


конфиг для виртуального хоста /usr/local/etc/php/postfix.conf

[postfix]
prefix = /usr/local/www/$pool
listen = 127.0.0.1:10000
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0660
user = www
group = www
pm = dynamic
pm.max_children = 4
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 100
;pm.status_path = /status/php-fpm/$pool
request_terminate_timeout = 0
request_slowlog_timeout = 1m
slowlog = /var/log/php/$pool.slow.log
catch_workers_output = yes


MySQL тоже из пакетов

# pkg install mysql56-server


простенький конфиг /etc/my.cnf

[mysqld]
bind-address=127.0.0.1

в конфигах. где используется подключение к базе указываем хост 127.0.0.1

После этого имеем готовый web-сервер можно переходить к установке postfixadmin


3. Установка PostfixAdmin

Скачиваем последнюю версию отсюда http://sourceforge.net/projects/postfixadmin/ и заливаем на web-сервер


создаём базу и даём права пользователю

> create database postfix character set utf8 collate utf8_general_ci;
> grant all on postfix.* to postfix@127.0.0.1 identified by 'пароль';


Правим основной конфиг postfixadmin config.inc.php Spoiler






6. Устанавливаем Postfix.


7. Устанавливаем Dovecot.