diff --git a/functions.inc.php b/functions.inc.php index c3dfc7cf..3fa1ef0a 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -1606,104 +1606,6 @@ function table_by_key ($table_key) { -/* - Called after a mailbox has been deleted in the DBMS. - Returns: boolean. - */ -function mailbox_postdeletion($username,$domain) { - $cmd = Config::read('mailbox_postdeletion_script'); - - if ( empty($cmd) ) { - return true; - } - - if (empty($username) || empty($domain)) { - print '

Warning: empty username and/or domain parameter.

'; - return false; - } - - $cmdarg1=escapeshellarg($username); - $cmdarg2=escapeshellarg($domain); - $command = "$cmd $cmdarg1 $cmdarg2"; - $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 postdeletion script!

'; - return FALSE; - } - - return TRUE; -} - -/* - Called after a domain has been added in the DBMS. - Returns: boolean. - */ -# TODO: move to DomainHandler -# TODO: replace "print" with $this->errormsg (or infomsg?) -function domain_postcreation($domain) { - $script=Config::read('domain_postcreation_script'); - - if (empty($script)) { - return true; - } - - if (empty($domain)) { - print '

Warning: empty domain parameter.

'; - return false; - } - - $cmdarg1=escapeshellarg($domain); - $command= "$script $cmdarg1"; - $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 domain postcreation script!

'; - return FALSE; - } - - return TRUE; -} - -/* - Called after a domain has been deleted in the DBMS. - Returns: boolean. - */ -# TODO: move to DomainHandler (after moving the delete code there) -# TODO: replace "print" with $this->errormsg (or infomsg?) -function domain_postdeletion($domain) { - $script=Config::read('domain_postdeletion_script'); - - if (empty($script)) { - return true; - } - - if (empty($domain)) { - print '

Warning: empty domain parameter.

'; - return false; - } - - $cmdarg1=escapeshellarg($domain); - $command= "$script $cmdarg1"; - $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 domain postdeletion script!

'; - return FALSE; - } - - return TRUE; -} - /* Called after an alias_domain has been deleted in the DBMS. Returns: boolean. diff --git a/model/DomainHandler.php b/model/DomainHandler.php index a6831fba..ffb25617 100644 --- a/model/DomainHandler.php +++ b/model/DomainHandler.php @@ -122,7 +122,7 @@ class DomainHandler extends PFAHandler { } if ($this->new) { - if (!domain_postcreation($this->id)) { + if (!$this->domain_postcreation()) { $this->errormsg[] = Config::lang('pAdminCreate_domain_error'); } } else { @@ -174,7 +174,7 @@ class DomainHandler extends PFAHandler { # finally delete the domain db_delete($this->db_table, $this->id_field, $this->id); - if ( !domain_postdeletion($this->id) ) { + if ( !$this->domain_postdeletion() ) { $this->error_msg[] = $PALANG['domain_postdel_failed']; } @@ -194,5 +194,69 @@ class DomainHandler extends PFAHandler { public function _formatted_mailboxes($item) { return $item['mailbox_count'] . ' / ' . $item['mailboxes']; } public function _formatted_quota ($item) { return $item['total_quota'] . ' / ' . $item['quota'] ; } + /** + * Called after a domain has been added + * + * @return boolean + */ + protected function domain_postcreation() { + $script=Config::read('domain_postcreation_script'); + + if (empty($script)) { + return true; + } + + if (empty($this->id)) { + $this->errormsg[] = 'Empty domain parameter in domain_postcreation'; + return false; + } + + $cmdarg1=escapeshellarg($this->id); + $command= "$script $cmdarg1"; + $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"); + $this->errormsg[] = 'Problems running domain postcreation script!'; + return FALSE; + } + + return TRUE; + } + + /** + * Called after a domain has been deleted + * + * @return boolean + */ + protected function domain_postdeletion() { + $script=Config::read('domain_postdeletion_script'); + + if (empty($script)) { + return true; + } + + if (empty($this->id)) { + $this->errormsg[] = 'Empty domain parameter in domain_postdeletion'; + return false; + } + + $cmdarg1=escapeshellarg($this->id); + $command= "$script $cmdarg1"; + $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"); + $this->errormsg[] = 'Problems running domain postdeletion script!'; + return FALSE; + } + + return TRUE; + } + } /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */ diff --git a/model/MailboxHandler.php b/model/MailboxHandler.php index e52dd8a5..7ee8dcdb 100644 --- a/model/MailboxHandler.php +++ b/model/MailboxHandler.php @@ -292,8 +292,7 @@ class MailboxHandler extends PFAHandler { db_delete('alias', 'address', $this->id); db_delete($this->db_table, $this->id_field, $this->id); # finally delete the mailbox - list(/*NULL*/,$domain) = explode('@', $this->id); - if ( !mailbox_postdeletion($username,$domain) ) { + if ( !$this->mailbox_postdeletion() ) { $this->error_msg[] = 'Mailbox postdeletion failed!'; # TODO: make translateable } @@ -552,6 +551,44 @@ class MailboxHandler extends PFAHandler { return TRUE; } + /** + * Called after a mailbox has been deleted + * + * @return boolean true on success, false on failure + * also adds a detailed error message to $this->errormsg[] + */ + protected function mailbox_postdeletion() { + $cmd = Config::read('mailbox_postdeletion_script'); + + if ( empty($cmd) ) { + return true; + } + + list(/*NULL*/,$domain) = explode('@', $this->id); + + if (empty($this->id) || empty($domain)) { + $this->errormsg[] = 'Empty username and/or domain parameter in mailbox_postdeletion'; + return false; + } + + $cmdarg1=escapeshellarg($this->id); + $cmdarg2=escapeshellarg($domain); + $command = "$cmd $cmdarg1 $cmdarg2"; + $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"); + $this->errormsg[] = 'Problems running mailbox postdeletion script!'; + return FALSE; + } + + return TRUE; + } + + + /** * Called by storemore() after a mailbox has been created. * Immediately returns, unless configuration indicates