merge patch for dovecot quota viewing - see https://sourceforge.net/tracker/index.php?func=detail&aid=2060309&group_id=191583&atid=937966 - thank you shario; sorry it took so long to merge!

git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@518 a1433add-5e2c-0410-b055-b7f2511e0802
postfixadmin-2.3
David Goodwin 16 years ago
parent c4250c42b0
commit 049a9ecc96

@ -1,41 +1,50 @@
#
# Dovecot configuration for Postfix Admin
# Written by: Massimo <AndyCapp> Danieli
# Originally written by: Massimo <AndyCapp> Danieli
# Revised by: Sampsa Hario <shario> for Dovecot v1.0
#
1. Dovecot setup
-----------------
More complete Dovecot documentation:
dovecot.conf relevant part for postfixadmin setup
http://wiki.dovecot.org/Quota
http://wiki.dovecot.org/Quota/Dict
http://www.opensourcehowto.org/how-to/mysql/mysql-users-postfixadmin-postfix-dovecot--squirrelmail-with-userprefs-stored-in-mysql.html
Here are the relevant parts of Dovecot v1.0.x configuration for Postfixadmin setup.
Please refer to Dovecot documentation for complete information.
default_mail_env = maildir:/usr/local/virtual/%u/
The setup gets userdb and passdb info from MySQL as well as quotas, and
uses dict backend to store used quotas as key=value pairs so that they can
be viewed real-time in Postfixadmin.
# auth_userdb specifies maildir location and user/group ID to use
auth_userdb = mysql /etc/dovecot/dovecot-mysql.conf
1. Dovecot setup
-----------------
default_mail_env = maildir:/usr/local/virtual/%u/
# auth_passdb specifies user passwords
auth_passdb = mysql /etc/dovecot/dovecot-mysql.conf
auth default {
userdb sql {
# Path for SQL configuration file, see doc/dovecot-sql-example.conf
args = /etc/dovecot-mysql.conf
}
passdb sql {
# Path for SQL configuration file, see doc/dovecot-sql-example.conf
args = /etc/dovecot-mysql.conf
}
}
# Valid UID range for users, defaults to 500 and above.
first_valid_uid = 1001 # Change this to your postifx UID
first_valid_uid = 1001 # Change this to your postfix UID
2. Dovecot mysql setup
----------------------
Below you'll find the relevant part of dovecot-mysql.conf file regarding our setup
Things you may need to change are db_password, uid and gid
Below you'll find the relevant part of dovecot-mysql.conf file regarding our
setup. Things you may need to change are db_password, uid and gid:
db_host = localhost
db_port = 3306
# Default sock for Debian sarge
db_unix_socket = /var/run/mysqld/mysqld.sock
db = postfix
db_user = postfix
db_passwd = postfix
db_client_flags = 0
connect = host=localhost dbname=postfix user=postfix password=postfix
# Default password scheme.
# depends on your $CONF['encrypt'] setting:
@ -44,12 +53,80 @@ db_client_flags = 0
# cleartext -> PLAIN
default_pass_scheme = MD5-CRYPT
# Query to retrieve password.
# Query to retrieve password. user can be used to retrieve username in other
# formats also.
password_query = SELECT password FROM mailbox WHERE username = '%u'
password_query = SELECT username AS user,password FROM mailbox WHERE username = '%u' AND active='1'
# Query to retrieve user information.
user_query = SELECT maildir, 1001 AS uid, 1001 AS gid FROM mailbox WHERE username = '%u'
user_query = SELECT maildir, 1001 AS uid, 1001 AS gid FROM mailbox WHERE username = '%u' AND active='1'
NB! The GID and UID are for postfix user and group ID, NOT MySQL user and group ID.
3. Dovecot v1.0 quota support (optional)
----------------------------------------
Please note that you need to use Dovecot's own local delivery agent to
enforce and update quotas. Then you can view real-time used quotas in
Postfixadmin.
Add to dovecot.conf:
## IMAP quota
protocol imap {
quota = dict:storage=200000 proxy::quota
}
## POP quota
protocol pop3 {
mail_plugins = quota
}
## Local Delivery Agent
protocol lda {
mail_plugins = quota
}
## Dictionary DB proxy
dict {
quota = mysql:/etc/dovecot-dict-quota.conf
}
## Default quota values
plugin {
quota = dict:storage=200000 proxy::quota
}
Change dovecot-mysql.conf to return quota values:
user_query = SELECT maildir, 1001 AS uid, 1001 AS gid, CONCAT('dict:storage=',floor(quota/1000),' proxy::quota') as quota FROM mailbox WHERE username = '%u'
Create file dovecot-dict-quota.conf:
driver = mysql
connect = host=localhost dbname=postfix user=postfix password=postfix
default_pass_scheme = MD5-CRYPT
table = quota
select_field = current
where_field = path
username_field = username
Create database in Mysql:
create table quota (
username varchar(255) not null,
path varchar(100) not null,
current integer,
primary key (username, path)
);
Enable quota support in Postfixadmin config.inc.php:
NB The GID and UID are for postfix user and group ID, NOT MySQL user and group ID.
$CONF['used_quotas'] = 'YES';
$CONF['quota'] = 'YES';

@ -18,6 +18,15 @@ virtual_mailbox_maps =
proxy:mysql:/etc/postfix/sql/mysql_virtual_mailbox_maps.cf,
proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf
# Additional for quota support
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = Sorry, the user's maildir has overdrawn his
diskspace quota, please try again later.
virtual_overquota_bounce = yes
Where you chose to store the .cf files doesn't really matter, but they will
have database passwords stored in plain text so they should be readable only
by user postfix, or in a directory only accessible to user postfix.
@ -84,6 +93,15 @@ hosts = localhost
dbname = postfix
query = SELECT CONCAT(domain,'/',maildir) FROM mailbox,alias_domain WHERE alias_domain.alias_domain = '%d' and mailbox.username = CONCAT('%u', '@', alias_domain.target_domain) AND mailbox.active = 1
# For quota support
mysql-virtual-mailbox-limit-maps.cf:
user = postfix
password = password
hosts = localhost
dbname = postfix
query = SELECT quota FROM mailbox WHERE username='%s' AND active = '1'
-------------------------
More information - HowTo docs that use PostfixAdmin

@ -68,6 +68,7 @@ $CONF['database_tables'] = array (
'mailbox' => 'mailbox',
'vacation' => 'vacation',
'vacation_notification' => 'vacation_notification',
'quota' => 'quota',
);
// Site Admin
@ -333,6 +334,15 @@ $CONF['domain_postcreation_script']='sudo -u courier /usr/local/bin/postfixadmin
//
// Specify '' for Dovecot and 'INBOX.' for Courier.
$CONF['create_mailbox_subdirs_prefix']='INBOX.';
// Optional:
// Show used quotas from Dovecot dictionary backend in virtual
// mailbox listing.
// See: DOCUMENTATION/DOVECOT.txt
// http://wiki.dovecot.org/Quota/Dict
//
// $CONF['used_quotas'] = 'YES';
//
// Normally, the TCP port number does not have to be specified.
// $CONF['create_mailbox_subdirs_hostport']=143;

@ -714,7 +714,7 @@ function divide_quota ($quota)
{
global $CONF;
if ($quota == -1) return $quota;
$value = $quota / $CONF['quota_multiplier'];
$value = round($quota / $CONF['quota_multiplier'],2);
return $value;
}
@ -2257,4 +2257,5 @@ $table_log = table_by_key ('log');
$table_mailbox = table_by_key ('mailbox');
$table_vacation = table_by_key ('vacation');
$table_vacation_notification = table_by_key('vacation_notification');
$table_quota = table_by_key ('quota');
/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */

@ -139,6 +139,9 @@ if ($result['rows'] > 0)
if ($CONF['vacation_control_admin'] == 'YES')
{
if ($CONF['used_quotas'] == 'YES')
$query = "SELECT $table_mailbox.*, $table_vacation.active AS v_active, $table_quota.current FROM $table_mailbox LEFT JOIN $table_vacation ON $table_mailbox.username=$table_vacation.email LEFT JOIN $table_quota ON $table_mailbox.username=$table_quota.username WHERE $table_mailbox.domain='$fDomain' AND $table_quota.path='quota/storage' ORDER BY $table_mailbox.username LIMIT $page_size OFFSET $fDisplay";
else
$query = "SELECT $table_mailbox.*, $table_vacation.active AS v_active FROM $table_mailbox LEFT JOIN $table_vacation ON $table_mailbox.username=$table_vacation.email WHERE $table_mailbox.domain='$fDomain' ORDER BY $table_mailbox.username LIMIT $page_size OFFSET $fDisplay";
}
else

@ -296,6 +296,8 @@ if (sizeof ($tMailbox) > 0) {
}
else
{
if ($CONF['used_quotas'] == 'YES')
print divide_quota ($tMailbox[$i]['current']).'/';
print divide_quota ($tMailbox[$i]['quota']);
}
print "</td>\n";

Loading…
Cancel
Save