mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2024-09-19 19:22:14 +02:00
functions.inc.php, DomainHandler, MailboxHandler:
- move mailbox_postdeletion() to MailboxHandler - move domain_postcreation() and domain_postdeletion() to DomainHandler - adopt those functions for usage inside the *Handler (replace print with $this->errormsg etc.) git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1579 a1433add-5e2c-0410-b055-b7f2511e0802
This commit is contained in:
parent
9decae80e9
commit
2bf5df92ea
@ -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 '<p>Warning: empty username and/or domain parameter.</p>';
|
||||
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 '<p>WARNING: Problems running mailbox postdeletion script!</p>';
|
||||
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 '<p>Warning: empty domain parameter.</p>';
|
||||
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 '<p>WARNING: Problems running domain postcreation script!</p>';
|
||||
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 '<p>Warning: empty domain parameter.</p>';
|
||||
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 '<p>WARNING: Problems running domain postdeletion script!</p>';
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
Called after an alias_domain has been deleted in the DBMS.
|
||||
Returns: boolean.
|
||||
|
@ -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: */
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user