From add0c86cadc1d79f7dca0b6fc13a3280454de69b Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Sun, 25 May 2008 21:19:58 +0000 Subject: [PATCH] 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 git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@373 a1433add-5e2c-0410-b055-b7f2511e0802 --- config.inc.php | 7 +++++++ create-mailbox.php | 2 +- edit-mailbox.php | 2 +- functions.inc.php | 44 ++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/config.inc.php b/config.inc.php index 3f2a5610..e23b9112 100644 --- a/config.inc.php +++ b/config.inc.php @@ -281,6 +281,13 @@ $CONF['show_custom_colors']=array("lightgreen","lightblue"); // prevent the web-server from executing external scripts. // $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 diff --git a/create-mailbox.php b/create-mailbox.php index cc22cca4..cb25ec43 100644 --- a/create-mailbox.php +++ b/create-mailbox.php @@ -263,7 +263,7 @@ TODO: this is the start of /create-mailbox code segment that was originally used */ $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'] . "
($fUsername)
"; diff --git a/edit-mailbox.php b/edit-mailbox.php index 3138c9cb..a22642e7 100644 --- a/edit-mailbox.php +++ b/edit-mailbox.php @@ -153,7 +153,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") $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 { diff --git a/functions.inc.php b/functions.inc.php index 2263bf96..8c770ddf 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -1713,7 +1713,7 @@ function table_by_pos ($pos) 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 @@ function mailbox_postcreation($username,$domain,$maildir) $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=''; @@ -1744,6 +1746,44 @@ function mailbox_postcreation($username,$domain,$maildir) return TRUE; } +/* + 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 '

WARNING: Problems running mailbox postedit script!

'; + return FALSE; + } + + return TRUE; +} + + /* Called after a mailbox has been deleted in the DBMS. Returns: boolean.