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
postfixadmin-2.3
Christian Boltz 17 years ago
parent fd7a445cb7
commit add0c86cad

@ -281,6 +281,13 @@ $CONF['show_custom_colors']=array("lightgreen","lightblue");
// prevent the web-server from executing external scripts. // prevent the web-server from executing external scripts.
// $CONF['mailbox_postcreation_script']='sudo -u courier /usr/local/bin/postfixadmin-mailbox-postcreation.sh'; // $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: // Optional:
// Script to run after deletion of mailboxes. // Script to run after deletion of mailboxes.
// Note that this may fail if PHP is run in "safe mode", or if // Note that this may fail if PHP is run in "safe mode", or if

@ -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')"); $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; $tDomain = $fDomain;
$tMessage .= $PALANG['pCreate_mailbox_result_error'] . "<br />($fUsername)<br />"; $tMessage .= $PALANG['pCreate_mailbox_result_error'] . "<br />($fUsername)<br />";

@ -153,7 +153,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
$formvars['active']=$sqlActive; $formvars['active']=$sqlActive;
$result = db_update ('mailbox', "username='$fUsername' AND domain='$fDomain'", $formvars, array('modified')); $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']; $tMessage = $PALANG['pEdit_mailbox_result_error'];
} }
else { else {

@ -1713,7 +1713,7 @@ function table_by_pos ($pos)
Called after a mailbox has been created in the DBMS. Called after a mailbox has been created in the DBMS.
Returns: boolean. Returns: boolean.
*/ */
function mailbox_postcreation($username,$domain,$maildir) function mailbox_postcreation($username,$domain,$maildir,$quota)
{ {
if (empty($username) || empty($domain) || empty($maildir)) if (empty($username) || empty($domain) || empty($maildir))
{ {
@ -1729,7 +1729,9 @@ function mailbox_postcreation($username,$domain,$maildir)
$cmdarg1=escapeshellarg($username); $cmdarg1=escapeshellarg($username);
$cmdarg2=escapeshellarg($domain); $cmdarg2=escapeshellarg($domain);
$cmdarg3=escapeshellarg($maildir); $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; $retval=0;
$output=array(); $output=array();
$firstline=''; $firstline='';
@ -1744,6 +1746,44 @@ function mailbox_postcreation($username,$domain,$maildir)
return TRUE; 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 '<p>WARNING: Problems running mailbox postedit script!</p>';
return FALSE;
}
return TRUE;
}
/* /*
Called after a mailbox has been deleted in the DBMS. Called after a mailbox has been deleted in the DBMS.
Returns: boolean. Returns: boolean.

Loading…
Cancel
Save