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.