SF.net SVN: postfixadmin:[1042] trunk
Brought to you by:
christian_boltz,
gingerdog
From: <chr...@us...> - 2011-04-19 20:18:53
|
Revision: 1042 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=1042&view=rev Author: christian_boltz Date: 2011-04-19 20:18:46 +0000 (Tue, 19 Apr 2011) Log Message: ----------- Add support for domain-level quota (total quota for a domain) Based on a patch from W. Rossmann (W. Rossmann@SF), https://sourceforge.net/tracker/index.php?func=detail&aid=2974928&group_id=191583&atid=937966 with some modifications, cleanup and adoptions to trunk (especially templates) config.inc.php: - new config option $CONF['domain_quota'] to enable/disable domain-level quota (default: enabled) - new config option $CONF['domain_quota_default'] (default: 2 GB) functions.inc.php - check_quota(): - add code to check the quota sum on a domain - add optional parameter $username (to exclude that username from quota calculation, used by edit-mailbox) edit-domain.php, create-domain.php, admin_edit-domain.tpl, admin_create-domain.tpl: - add input field and handling for domain-level quota list-domain.php, overview-get.tpl, adminlistdomain.tpl: - display allocated and allowed domain quota - beautify quota and max_quota fields - display "unlimited" instead of "-1" edit-mailbox.php: - hand over username to check_quota() Modified Paths: -------------- trunk/config.inc.php trunk/create-domain.php trunk/edit-domain.php trunk/edit-mailbox.php trunk/functions.inc.php trunk/list-domain.php trunk/templates/admin_create-domain.tpl trunk/templates/admin_edit-domain.tpl trunk/templates/adminlistdomain.tpl trunk/templates/overview-get.tpl Modified: trunk/config.inc.php =================================================================== --- trunk/config.inc.php 2011-04-19 19:51:01 UTC (rev 1041) +++ trunk/config.inc.php 2011-04-19 20:18:46 UTC (rev 1042) @@ -182,10 +182,13 @@ $CONF['aliases'] = '10'; $CONF['mailboxes'] = '10'; $CONF['maxquota'] = '10'; +$CONF['domain_quota_default'] = '2048'; // Quota // When you want to enforce quota for your mailbox users set this to 'YES'. $CONF['quota'] = 'NO'; +// If you want to enforce domain-level quotas set this to 'YES'. +$CONF['domain_quota'] = 'YES'; // You can either use '1024000' or '1048576' $CONF['quota_multiplier'] = '1024000'; Modified: trunk/create-domain.php =================================================================== --- trunk/create-domain.php 2011-04-19 19:51:01 UTC (rev 1041) +++ trunk/create-domain.php 2011-04-19 20:18:46 UTC (rev 1042) @@ -46,7 +46,8 @@ 'fDescription' => array('type' => 'str', 'default' =>''), 'fAliases' => array('type' => 'int', 'default' => $CONF['aliases']), 'fMailboxes' => array('type' => 'int', 'default' => $CONF['mailboxes']), - 'fMaxquota' => array('type' => 'int', 'default' => $CONF['maxquota']), + 'fMaxquota' => array('type' => 'int', 'default' => $CONF['maxquota']), + 'fDomainquota' => array('type' => 'int', 'default' => $CONF['domain_quota_default']), 'fTransport' => array('type' => 'str', 'default' => $CONF['transport_default'], 'options' => $CONF['transport_options']), 'fDefaultaliases' => array('type' => 'str', 'default' => 'on', 'options' => array('on', 'off')), 'fBackupmx' => array('type' => 'str', 'default' => 'off', 'options' => array('on', 'off')) @@ -80,6 +81,7 @@ $tTransport = $fTransport; $tAliases = $fAliases; $tMaxquota = $fMaxquota; + $tDomainquota = $fDomainquota; $tMailboxes = $fMailboxes; $tDefaultaliases = $fDefaultaliases; $tBackupmx = $fBackupmx; @@ -96,6 +98,7 @@ $tAliases = $fAliases; $tMailboxes = $fMailboxes; if (isset ($_POST['fMaxquota'])) $tMaxquota = $fMaxquota; + if (isset ($_POST['fDomainquota'])) $tDomainquota = $fDomainquota; if (isset ($_POST['fTransport'])) $tTransport = $fTransport; if (isset ($_POST['fDefaultaliases'])) $tDefaultaliases = $fDefaultaliases; if (isset ($_POST['fBackupmx'])) $tBackupmx = $fBackupmx; @@ -108,6 +111,7 @@ $tAliases = $CONF['aliases']; $tMailboxes = $CONF['mailboxes']; $tMaxquota = $CONF['maxquota']; + $tDomainquota = $CONF['domain_quota_default']; if ($fBackupmx == "on") { @@ -120,7 +124,7 @@ $sqlBackupmx = db_get_boolean(false); } - $sql_query = "INSERT INTO $table_domain (domain,description,aliases,mailboxes,maxquota,transport,backupmx,created,modified) VALUES ('$fDomain','$fDescription',$fAliases,$fMailboxes,$fMaxquota,'$fTransport','$sqlBackupmx',NOW(),NOW())"; + $sql_query = "INSERT INTO $table_domain (domain,description,aliases,mailboxes,maxquota,quota,transport,backupmx,created,modified) VALUES ('$fDomain','$fDescription',$fAliases,$fMailboxes,$fMaxquota,$fDomainquota,'$fTransport','$sqlBackupmx',NOW(),NOW())"; $result = db_query($sql_query); if ($result['rows'] != 1) { @@ -150,7 +154,8 @@ $smarty->assign ('tDescription', $tDescription, false); $smarty->assign ('tAliases', $tAliases); $smarty->assign ('tMailboxes', $tMailboxes); -$smarty->assign ('tMaxquota', $tMaxquota,false); +$smarty->assign ('tDomainquota', $tDomainquota); +$smarty->assign ('tMaxquota', $tMaxquota,false); # TODO: why is sanitize disabled? Should be just integer... $smarty->assign ('select_options', select_options ($CONF ['transport_options'], array ($tTransport)),false); $smarty->assign ('tDefaultaliases', ($tDefaultaliases == 'on') ? ' checked="checked"' : ''); $smarty->assign ('tBackupmx', ($tBackupmx == 'on') ? ' checked="checked"' : ''); Modified: trunk/edit-domain.php =================================================================== --- trunk/edit-domain.php 2011-04-19 19:51:01 UTC (rev 1041) +++ trunk/edit-domain.php 2011-04-19 20:18:46 UTC (rev 1042) @@ -47,6 +47,7 @@ $tDescription = $domain_properties['description']; $tAliases = $domain_properties['aliases']; $tMailboxes = $domain_properties['mailboxes']; + $tDomainquota = $domain_properties['quota']; $tMaxquota = $domain_properties['maxquota']; $tTransport = $domain_properties['transport']; $tBackupmx = $domain_properties['backupmx']; @@ -66,6 +67,11 @@ } else { $fMaxquota = 0; } + if (isset ($_POST['fDomainquota'])) { + $fDomainquota = intval($_POST['fDomainquota']); + } else { + $fDomainquota = $CONF['domain_quota_default']; + } $fTransport = $CONF['transport_default']; if($CONF['transport'] != 'NO' && isset ($_POST['fTransport'])) { @@ -101,7 +107,7 @@ $sqltransport = "transport='$fTransport',"; } - $result = db_query ("UPDATE $table_domain SET description='$fDescription',aliases=$fAliases,mailboxes=$fMailboxes,maxquota=$fMaxquota,$sqltransport backupmx='$sqlBackupmx',active='$sqlActive',modified=NOW() WHERE domain='$domain'"); + $result = db_query ("UPDATE $table_domain SET description='$fDescription',aliases=$fAliases,mailboxes=$fMailboxes,maxquota=$fMaxquota,quota=$fDomainquota,$sqltransport backupmx='$sqlBackupmx',active='$sqlActive',modified=NOW() WHERE domain='$domain'"); if ($result['rows'] == 1) { header ("Location: list-domain.php"); @@ -118,6 +124,7 @@ $smarty->assign ('tAliases', $tAliases); $smarty->assign ('tMailboxes', $tMailboxes); $smarty->assign ('tMaxquota', $tMaxquota); +$smarty->assign ('tDomainquota', $tDomainquota); $smarty->assign ('select_options', select_options($CONF['transport_options'], array($tTransport)), false); if ($tBackupmx) $smarty->assign ('tBackupmx', ' checked="checked"'); if ($tActive) $smarty->assign ('tActive', ' checked="checked"'); Modified: trunk/edit-mailbox.php =================================================================== --- trunk/edit-mailbox.php 2011-04-19 19:51:01 UTC (rev 1041) +++ trunk/edit-mailbox.php 2011-04-19 20:18:46 UTC (rev 1042) @@ -117,7 +117,7 @@ } if ($CONF['quota'] == "YES") { - if (!check_quota ($fQuota, $fDomain)) + if (!check_quota ($fQuota, $fDomain, $fUsername)) { $error = 1; $tName = $fName; Modified: trunk/functions.inc.php =================================================================== --- trunk/functions.inc.php 2011-04-19 19:51:01 UTC (rev 1041) +++ trunk/functions.inc.php 2011-04-19 20:18:46 UTC (rev 1042) @@ -678,29 +678,53 @@ // Action: Checks if the user is creating a mailbox with the correct quota // Call: check_quota (string domain) // -function check_quota ($quota, $domain) -{ +function check_quota ($quota, $domain, $username="") { + global $CONF; + $rval = false; $limit = get_domain_properties ($domain); if ($limit['maxquota'] == 0) { - return true; + $rval = true; } if (($limit['maxquota'] < 0) and ($quota < 0)) { - return true; + $rval = true; } if (($limit['maxquota'] > 0) and ($quota == 0)) { - return false; + $rval = false; } if ($quota > $limit['maxquota']) { - return false; + $rval = false; } else { - return true; + $rval = true; } + + # TODO: detailed error message ("domain quota exceeded", "mailbox quota too big" etc.) via flash_error? Or "available quota: xxx MB"? + if (!$rval || $CONF['domain_quota'] != 'YES') { + return $rval; + } elseif ($limit['quota'] <= 0) { + $rval = true; + } else { + $table_mailbox = table_by_key('mailbox'); + $query = "SELECT SUM(quota) FROM $table_mailbox WHERE domain = '" . escape_string($domain) . "'"; + if ($username != "") { + $query .= " AND username != '" . escape_string($username) . "'"; + } + $result = db_query ($query); + $row = db_row ($result['result']); + $cur_quota_total = divide_quota($row[0]); # convert to MB + if ( ($quota + $cur_quota_total) > $limit['quota'] ) { + $rval = false; + } else { + $rval = true; + } + } + + return $rval; } Modified: trunk/list-domain.php =================================================================== --- trunk/list-domain.php 2011-04-19 19:51:01 UTC (rev 1041) +++ trunk/list-domain.php 2011-04-19 20:18:46 UTC (rev 1042) @@ -73,7 +73,7 @@ "; $query = " - SELECT $table_domain_fieldlist , COUNT( DISTINCT $table_mailbox.username ) AS mailbox_count + SELECT $table_domain_fieldlist , COUNT( DISTINCT $table_mailbox.username ) AS mailbox_count, SUM( $table_mailbox.quota ) AS total_quota FROM $table_domain LEFT JOIN $table_mailbox ON $table_domain.domain = $table_mailbox.domain $where @@ -103,6 +103,9 @@ while ($row = db_array ($result['result'])) { # add number of aliases to $domain_properties array. mailbox aliases do not count. $domain_properties [$row['domain']] ['alias_count'] = $row['alias_count'] - $domain_properties [$row['domain']] ['mailbox_count']; + $domain_properties [$row['domain']] ['total_quota'] = (int) divide_quota($domain_properties [$row['domain']] ['total_quota']); # convert to MB + if ($domain_properties [$row['domain']] ['quota'] == -1) $domain_properties [$row['domain']] ['quota'] = $PALANG['pOverview_unlimited']; + if ($domain_properties [$row['domain']] ['maxquota'] == -1) $domain_properties [$row['domain']] ['maxquota'] = $PALANG['pOverview_unlimited']; } $smarty->assign ('domain_properties', $domain_properties); Modified: trunk/templates/admin_create-domain.tpl =================================================================== --- trunk/templates/admin_create-domain.tpl 2011-04-19 19:51:01 UTC (rev 1041) +++ trunk/templates/admin_create-domain.tpl 2011-04-19 20:18:46 UTC (rev 1042) @@ -24,6 +24,13 @@ <td><input class="flat" type="text" name="fMailboxes" value="{$tMailboxes}" /></td> <td>{$PALANG.pAdminCreate_domain_mailboxes_text}</td> </tr> +{if $CONF.domain_quota===YES} + <tr> + <td>{$PALANG.pAdminEdit_domain_quota}:</td> + <td><input class="flat" type="text" name="fDomainquota" value="{$tDomainquota}" /></td> + <td>{$PALANG.pAdminCreate_domain_maxquota_text}</td> + </tr> +{/if} {if $CONF.quota===YES} <tr> <td>{$PALANG.pAdminCreate_domain_maxquota}:</td> Modified: trunk/templates/admin_edit-domain.tpl =================================================================== --- trunk/templates/admin_edit-domain.tpl 2011-04-19 19:51:01 UTC (rev 1041) +++ trunk/templates/admin_edit-domain.tpl 2011-04-19 20:18:46 UTC (rev 1042) @@ -24,6 +24,13 @@ <td><input class="flat" type="text" name="fMailboxes" value="{$tMailboxes}" /></td> <td>{$PALANG.pAdminEdit_domain_mailboxes_text}</td> </tr> +{if $CONF.domain_quota===YES} + <tr> + <td>{$PALANG.pAdminEdit_domain_quota}:</td> + <td><input class="flat" type="text" name="fDomainquota" value="{$tDomainquota}" /></td> + <td>{$PALANG.pAdminEdit_domain_maxquota_text}</td> + </tr> +{/if} {if $CONF.quota===YES} <tr> <td>{$PALANG.pAdminEdit_domain_maxquota}:</td> Modified: trunk/templates/adminlistdomain.tpl =================================================================== --- trunk/templates/adminlistdomain.tpl 2011-04-19 19:51:01 UTC (rev 1041) +++ trunk/templates/adminlistdomain.tpl 2011-04-19 20:18:46 UTC (rev 1042) @@ -14,7 +14,8 @@ <td>{$PALANG.pAdminList_domain_description}</td> <td>{$PALANG.pAdminList_domain_aliases}</td> <td>{$PALANG.pAdminList_domain_mailboxes}</td> - {if $CONF.quota==YES}<td>{$PALANG.pAdminList_domain_maxquota}</td>{/if} + {if $CONF.quota==YES}<td>{$PALANG.pOverview_get_quota}</td>{/if} + {if $CONF.domain_quota==YES}<td>{$PALANG.pAdminList_domain_quota}</td>{/if} {if $CONF.transport==YES}<td>{$PALANG.pAdminList_domain_transport}</td>{/if} <td>{$PALANG.pAdminList_domain_backupmx}</td> <td>{$PALANG.pAdminList_domain_modified}</td> @@ -28,6 +29,7 @@ <td>{$domain.alias_count} / {$domain.aliases}</td> <td>{$domain.mailbox_count} / {$domain.mailboxes}</td> {if $CONF.quota==YES}<td>{$domain.maxquota}</td>{/if} + {if $CONF.domain_quota===YES}<td>{$domain.total_quota} / {$domain.quota}</td>{/if} {if $CONF.transport==YES}<td>{$domain.transport}</td>{/if} <td>{$domain.backupmx}</td> <td>{$domain.modified}</td> Modified: trunk/templates/overview-get.tpl =================================================================== --- trunk/templates/overview-get.tpl 2011-04-19 19:51:01 UTC (rev 1041) +++ trunk/templates/overview-get.tpl 2011-04-19 20:18:46 UTC (rev 1042) @@ -16,6 +16,7 @@ <td>{$PALANG.pOverview_get_aliases}</td> <td>{$PALANG.pOverview_get_mailboxes}</td> {if $CONF.quota===YES}<td>{$PALANG.pOverview_get_quota}</td>{/if} + {if $CONF.domain_quota===YES}<td>{$PALANG.pAdminList_domain_quota}</td>{/if} </tr> {foreach from=$domain_properties item=domain} {#tr_hilightoff#} @@ -23,6 +24,7 @@ <td>{$domain.alias_count} / {$domain.aliases}</td> <td>{$domain.mailbox_count} / {$domain.mailboxes}</td> {if $CONF.quota===YES}<td>{$domain.maxquota}</td>{/if} + {if $CONF.domain_quota===YES}<td>{$domain.total_quota} / {$domain.quota}</td>{/if} </tr> {/foreach} </table> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |