SF.net SVN: postfixadmin: [373] trunk
Brought to you by:
christian_boltz,
gingerdog
From: <chr...@us...> - 2008-05-25 21:19:50
|
Revision: 373 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=373&view=rev Author: christian_boltz Date: 2008-05-25 14:19:58 -0700 (Sun, 25 May 2008) Log Message: ----------- Applied patch from Michiel van Baak (mvanbaak) https://sourceforge.net/tracker/index.php?func=detail&aid=1923030&group_id=191583&atid=937966 - added quota parameter in mailbox_postcreation() hook - new hook to update the quota after editing a mailbox Modifications to the patch: - made $quota an required parameter in the mailbox_postedit and mailbox_postcreation functions - the scripts always get the quota as 4th parameter. In case $quota is <= 0, it is set to 0. config.inc.php: - new option $CONF['mailbox_postedit_script'] edit-mailbox.php: - call mailbox_postedit() after editing the mailbox functions.inc.php: - added $quota parameter to mailbox_postcreation() - new function mailbox_postedit() create-mailbox.php: - added $quota parameter on mailbox_postcreation() call Modified Paths: -------------- trunk/config.inc.php trunk/create-mailbox.php trunk/edit-mailbox.php trunk/functions.inc.php Modified: trunk/config.inc.php =================================================================== --- trunk/config.inc.php 2008-05-25 20:49:40 UTC (rev 372) +++ trunk/config.inc.php 2008-05-25 21:19:58 UTC (rev 373) @@ -282,6 +282,13 @@ // $CONF['mailbox_postcreation_script']='sudo -u courier /usr/local/bin/postfixadmin-mailbox-postcreation.sh'; // Optional: +// Script to run after alteration of mailboxes. +// Note that this may fail if PHP is run in "safe mode", or if +// operating system features (such as SELinux) or limitations +// prevent the web-server from executing external scripts. +// $CONF['mailbox_postedit_script']='sudo -u courier /usr/local/bin/postfixadmin-mailbox-postedit.sh'; + +// Optional: // Script to run after deletion of mailboxes. // Note that this may fail if PHP is run in "safe mode", or if // operating system features (such as SELinux) or limitations Modified: trunk/create-mailbox.php =================================================================== --- trunk/create-mailbox.php 2008-05-25 20:49:40 UTC (rev 372) +++ trunk/create-mailbox.php 2008-05-25 21:19:58 UTC (rev 373) @@ -263,7 +263,7 @@ */ $result = db_query ("INSERT INTO $table_mailbox (username,password,name,maildir,quota,domain,created,modified,active) VALUES ('$fUsername','$password','$fName','$maildir','$quota','$fDomain',NOW(),NOW(),'$sqlActive')"); - if ($result['rows'] != 1 || !mailbox_postcreation($fUsername,$fDomain,$maildir)) + if ($result['rows'] != 1 || !mailbox_postcreation($fUsername,$fDomain,$maildir, $quota)) { $tDomain = $fDomain; $tMessage .= $PALANG['pCreate_mailbox_result_error'] . "<br />($fUsername)<br />"; Modified: trunk/edit-mailbox.php =================================================================== --- trunk/edit-mailbox.php 2008-05-25 20:49:40 UTC (rev 372) +++ trunk/edit-mailbox.php 2008-05-25 21:19:58 UTC (rev 373) @@ -153,7 +153,7 @@ $formvars['active']=$sqlActive; $result = db_update ('mailbox', "username='$fUsername' AND domain='$fDomain'", $formvars, array('modified')); - if ($result != 1) { + if ($result != 1 || !mailbox_postedit($fUsername,$fDomain,$maildir, $quota)) { $tMessage = $PALANG['pEdit_mailbox_result_error']; } else { Modified: trunk/functions.inc.php =================================================================== --- trunk/functions.inc.php 2008-05-25 20:49:40 UTC (rev 372) +++ trunk/functions.inc.php 2008-05-25 21:19:58 UTC (rev 373) @@ -1713,7 +1713,7 @@ Called after a mailbox has been created in the DBMS. Returns: boolean. */ -function mailbox_postcreation($username,$domain,$maildir) +function mailbox_postcreation($username,$domain,$maildir,$quota) { if (empty($username) || empty($domain) || empty($maildir)) { @@ -1729,7 +1729,9 @@ $cmdarg1=escapeshellarg($username); $cmdarg2=escapeshellarg($domain); $cmdarg3=escapeshellarg($maildir); - $command=$CONF[$confpar]." $cmdarg1 $cmdarg2 $cmdarg3"; + if ($quota <= 0) $quota = 0; + $cmdarg4=escapeshellarg($quota); + $command=$CONF[$confpar]." $cmdarg1 $cmdarg2 $cmdarg3 $cmdarg4"; $retval=0; $output=array(); $firstline=''; @@ -1745,6 +1747,44 @@ } /* + Called after a mailbox has been altered in the DBMS. + Returns: boolean. + */ +function mailbox_postedit($username,$domain,$maildir,$quota) +{ + if (empty($username) || empty($domain) || empty($maildir)) + { + trigger_error('In '.__FUNCTION__.': empty username, domain and/or maildir parameter',E_USER_ERROR); + return FALSE; + } + + global $CONF; + $confpar='mailbox_postedit_script'; + + if (!isset($CONF[$confpar]) || empty($CONF[$confpar])) return TRUE; + + $cmdarg1=escapeshellarg($username); + $cmdarg2=escapeshellarg($domain); + $cmdarg3=escapeshellarg($maildir); + if ($quota <= 0) $quota = 0; + $cmdarg4=escapeshellarg($quota); + $command=$CONF[$confpar]." $cmdarg1 $cmdarg2 $cmdarg3 $cmdarg4"; + $retval=0; + $output=array(); + $firstline=''; + $firstline=exec($command,$output,$retval); + if (0!=$retval) + { + error_log("Running $command yielded return value=$retval, first line of output=$firstline"); + print '<p>WARNING: Problems running mailbox postedit script!</p>'; + return FALSE; + } + + return TRUE; +} + + +/* Called after a mailbox has been deleted in the DBMS. Returns: boolean. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |