SF.net SVN: postfixadmin:[518] trunk
Brought to you by:
christian_boltz,
gingerdog
From: <Gin...@us...> - 2009-01-15 12:53:56
|
Revision: 518 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=518&view=rev Author: GingerDog Date: 2009-01-15 11:38:11 +0000 (Thu, 15 Jan 2009) Log Message: ----------- 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! Modified Paths: -------------- trunk/DOCUMENTS/DOVECOT.txt trunk/DOCUMENTS/POSTFIX_CONF.txt trunk/config.inc.php trunk/functions.inc.php trunk/list-virtual.php trunk/templates/list-virtual.php Modified: trunk/DOCUMENTS/DOVECOT.txt =================================================================== --- trunk/DOCUMENTS/DOVECOT.txt 2009-01-15 11:25:54 UTC (rev 517) +++ trunk/DOCUMENTS/DOVECOT.txt 2009-01-15 11:38:11 UTC (rev 518) @@ -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 +----------------- -# auth_passdb specifies user passwords -auth_passdb = mysql /etc/dovecot/dovecot-mysql.conf +default_mail_env = maildir:/usr/local/virtual/%u/ +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 @@ # 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. +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: + +$CONF['used_quotas'] = 'YES'; +$CONF['quota'] = 'YES'; Modified: trunk/DOCUMENTS/POSTFIX_CONF.txt =================================================================== --- trunk/DOCUMENTS/POSTFIX_CONF.txt 2009-01-15 11:25:54 UTC (rev 517) +++ trunk/DOCUMENTS/POSTFIX_CONF.txt 2009-01-15 11:38:11 UTC (rev 518) @@ -18,6 +18,15 @@ 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 @@ 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 Modified: trunk/config.inc.php =================================================================== --- trunk/config.inc.php 2009-01-15 11:25:54 UTC (rev 517) +++ trunk/config.inc.php 2009-01-15 11:38:11 UTC (rev 518) @@ -68,6 +68,7 @@ 'mailbox' => 'mailbox', 'vacation' => 'vacation', 'vacation_notification' => 'vacation_notification', + 'quota' => 'quota', ); // Site Admin @@ -333,7 +334,16 @@ // // 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; // Modified: trunk/functions.inc.php =================================================================== --- trunk/functions.inc.php 2009-01-15 11:25:54 UTC (rev 517) +++ trunk/functions.inc.php 2009-01-15 11:38:11 UTC (rev 518) @@ -714,7 +714,7 @@ { 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_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: */ Modified: trunk/list-virtual.php =================================================================== --- trunk/list-virtual.php 2009-01-15 11:25:54 UTC (rev 517) +++ trunk/list-virtual.php 2009-01-15 11:38:11 UTC (rev 518) @@ -139,7 +139,10 @@ if ($CONF['vacation_control_admin'] == 'YES') { - $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"; + 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 { Modified: trunk/templates/list-virtual.php =================================================================== --- trunk/templates/list-virtual.php 2009-01-15 11:25:54 UTC (rev 517) +++ trunk/templates/list-virtual.php 2009-01-15 11:38:11 UTC (rev 518) @@ -296,6 +296,8 @@ } else { + if ($CONF['used_quotas'] == 'YES') + print divide_quota ($tMailbox[$i]['current']).'/'; print divide_quota ($tMailbox[$i]['quota']); } print "</td>\n"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |