Additional modifications to domain/user/Maildir email file structure
- Added email settings' option to specify Maildir directory (depending on postfix version this is ./Maildir/, .maildir/ or, optionally, one can choose to leave Maildir file structure directly on user's directory. - Fixed database 'insert' command to describe the new structure using specified Maildir directory into new accounts. - Fixed maildirExists function to the new file structure - Fixed older bug that email exclusions that were scheduled (task 7) were not being displayed on overview. - Added entries on 'english' language file for the new entries on panel - Changed task id 6 (delete customer) behavior on scrips/jobs/cron_tasks.php to assure email account is owned to mail uid/gid and the target is an actual directory before zapping it. - Fixed task id 7 (delete customer mail data) behavior on script above to correctly fill and find Maildir and also do additional paranoid checks before zapping the mail account directory. Notice this is not the same from above directory-wise: here we erase a single account's data, while in task id a entire customer set of accounts and domains are eliminated.
This commit is contained in:
@@ -51,6 +51,15 @@ return array(
|
|||||||
'default' => '/var/customers/mail/',
|
'default' => '/var/customers/mail/',
|
||||||
'save_method' => 'storeSettingField',
|
'save_method' => 'storeSettingField',
|
||||||
),
|
),
|
||||||
|
'system_vmail_maildirname' => array(
|
||||||
|
'label' => $lng['serversettings']['vmail_maildirname'],
|
||||||
|
'settinggroup' => 'system',
|
||||||
|
'varname' => 'vmail_maildirname',
|
||||||
|
'type' => 'string',
|
||||||
|
'string_type' => 'dir',
|
||||||
|
'default' => 'Maildir',
|
||||||
|
'save_method' => 'storeSettingField',
|
||||||
|
),
|
||||||
'panel_sendalternativemail' => array(
|
'panel_sendalternativemail' => array(
|
||||||
'label' => $lng['serversettings']['sendalternativemail'],
|
'label' => $lng['serversettings']['sendalternativemail'],
|
||||||
'settinggroup' => 'panel',
|
'settinggroup' => 'panel',
|
||||||
@@ -95,4 +104,4 @@ return array(
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -440,12 +440,37 @@ elseif($page == 'accounts')
|
|||||||
}
|
}
|
||||||
$email_user=substr($email_full,0,strrpos($email_full,"@"));
|
$email_user=substr($email_full,0,strrpos($email_full,"@"));
|
||||||
$email_domain=substr($email_full,strrpos($email_full,"@")+1);
|
$email_domain=substr($email_full,strrpos($email_full,"@")+1);
|
||||||
|
$maildirname=trim($settings['system']['vmail_maildirname']);
|
||||||
|
// Add trailing slash to Maildir if needed
|
||||||
|
$maildirpath=$maildirname;
|
||||||
|
if (!empty($maildirname) and substr($maildirname,-1) != "/") $maildirpath.="/";
|
||||||
|
|
||||||
$db->query("INSERT INTO `" . TABLE_MAIL_USERS . "` (`customerid`, `email`, `username`, " . ($settings['system']['mailpwcleartext'] == '1' ? '`password`, ' : '') . " `password_enc`, `homedir`, `maildir`, `uid`, `gid`, `domainid`, `postfix`, `quota`, `imap`, `pop3`) VALUES ('" . (int)$userinfo['customerid'] . "', '" . $db->escape($email_full) . "', '" . $db->escape($username) . "', " . ($settings['system']['mailpwcleartext'] == '1' ? "'" . $db->escape($password) . "'," : '') . " ENCRYPT('" . $db->escape($password) . "'), '" . $db->escape($settings['system']['vmail_homedir']) . "', '" . $db->escape($userinfo['loginname'] . '/' . $email_domain . "/" . $email_user . '/Maildir/') . "', '" . (int)$settings['system']['vmail_uid'] . "', '" . (int)$settings['system']['vmail_gid'] . "', '" . (int)$result['domainid'] . "', 'y', '" . (int)$quota . "', '" . (int)$userinfo['imap'] . "', '" . (int)$userinfo['pop3'] . "')");
|
$db->query("INSERT INTO `" . TABLE_MAIL_USERS .
|
||||||
|
"` (`customerid`, `email`, `username`, " . ($settings['system']['mailpwcleartext'] == '1' ? '`password`, ' : '') . " `password_enc`, `homedir`, `maildir`, `uid`, `gid`, `domainid`, `postfix`, `quota`, `imap`, `pop3`) ".
|
||||||
|
"VALUES (".
|
||||||
|
"'" . (int)$userinfo['customerid'] . "', ".
|
||||||
|
"'" . $db->escape($email_full) . "', ".
|
||||||
|
"'" . $db->escape($username) . "', " .
|
||||||
|
($settings['system']['mailpwcleartext'] == '1' ? "'" . $db->escape($password) . "', " : '') .
|
||||||
|
"ENCRYPT('" . $db->escape($password) . "'), ".
|
||||||
|
"'" . $db->escape($settings['system']['vmail_homedir']) . "', '" . $db->escape($userinfo['loginname'] . '/' . $email_domain . "/" . $email_user . "/" . $maildirpath) . "', ".
|
||||||
|
"'" . (int)$settings['system']['vmail_uid'] . "', ".
|
||||||
|
"'" . (int)$settings['system']['vmail_gid'] . "', ".
|
||||||
|
"'" . (int)$result['domainid'] . "', ".
|
||||||
|
"'y', ".
|
||||||
|
"'" . (int)$quota . "', ".
|
||||||
|
"'" . (int)$userinfo['imap'] . "', ".
|
||||||
|
"'" . (int)$userinfo['pop3'] . "')");
|
||||||
$popaccountid = $db->insert_id();
|
$popaccountid = $db->insert_id();
|
||||||
$result['destination'].= ' ' . $email_full;
|
$result['destination'].= ' ' . $email_full;
|
||||||
$db->query("UPDATE `" . TABLE_MAIL_VIRTUAL . "` SET `destination` = '" . $db->escape(makeCorrectDestination($result['destination'])) . "', `popaccountid` = '" . (int)$popaccountid . "' WHERE `customerid`='" . (int)$userinfo['customerid'] . "' AND `id`='" . (int)$id . "'");
|
$db->query("UPDATE `" . TABLE_MAIL_VIRTUAL . "` SET ".
|
||||||
$db->query("UPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET `email_accounts_used`=`email_accounts_used`+1, `email_quota_used`=`email_quota_used`+" . (int)$quota . " WHERE `customerid`='" . (int)$userinfo['customerid'] . "'");
|
"`destination` = '" . $db->escape(makeCorrectDestination($result['destination'])) . "', ".
|
||||||
|
"`popaccountid` = '" . (int)$popaccountid . "' ".
|
||||||
|
"WHERE `customerid`='" . (int)$userinfo['customerid'] . "' AND `id`='" . (int)$id . "'");
|
||||||
|
$db->query("UPDATE `" . TABLE_PANEL_CUSTOMERS . "` SET ".
|
||||||
|
"`email_accounts_used`=`email_accounts_used`+1, ".
|
||||||
|
"`email_quota_used`=`email_quota_used`+" . (int)$quota . " ".
|
||||||
|
"WHERE `customerid`='" . (int)$userinfo['customerid'] . "'");
|
||||||
$log->logAction(USR_ACTION, LOG_INFO, "added email account for '" . $email_full . "'");
|
$log->logAction(USR_ACTION, LOG_INFO, "added email account for '" . $email_full . "'");
|
||||||
$replace_arr = array(
|
$replace_arr = array(
|
||||||
'EMAIL' => $email_full,
|
'EMAIL' => $email_full,
|
||||||
|
|||||||
@@ -30,7 +30,10 @@ function maildirExists($result = null)
|
|||||||
{
|
{
|
||||||
$loginname = getCustomerDetail($result['customerid'], 'loginname');
|
$loginname = getCustomerDetail($result['customerid'], 'loginname');
|
||||||
if($loginname !== false) {
|
if($loginname !== false) {
|
||||||
$maildir = makeCorrectDir($settings['system']['vmail_homedir'] .'/'. $loginname .'/'. $result['email_full']);
|
$email_user=substr($result['email_full'],0,strrpos($result['email_full'],"@"));
|
||||||
|
$email_domain=substr($result['email_full'],strrpos($result['email_full'],"@")+1);
|
||||||
|
$maildirname=trim($settings['system']['vmail_maildirname']);
|
||||||
|
$maildir = makeCorrectDir($settings['system']['vmail_homedir'] .'/'. $loginname .'/'. $email_domain .'/'. $email_user . (!empty($maildirname)?'/'.$maildirname:''));
|
||||||
if(@file_exists($maildir)) {
|
if(@file_exists($maildir)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -209,6 +209,10 @@ function getOutstandingTasks()
|
|||||||
$task_desc = $lng['tasks']['deleting_customerfiles'];
|
$task_desc = $lng['tasks']['deleting_customerfiles'];
|
||||||
$task_desc = str_replace('%loginname%', $loginname, $task_desc);
|
$task_desc = str_replace('%loginname%', $loginname, $task_desc);
|
||||||
}
|
}
|
||||||
|
elseif($row['type'] == '7')
|
||||||
|
{
|
||||||
|
$task_desc = $lng['tasks']['remove_emailacc_files'];
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* Set FS - quota
|
* Set FS - quota
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1917,3 +1917,7 @@ $lng['panel']['cancel'] = 'Cancel';
|
|||||||
$lng['admin']['delete_statistics'] = 'Delete Statistics';
|
$lng['admin']['delete_statistics'] = 'Delete Statistics';
|
||||||
$lng['admin']['speciallogwarning'] = 'WARNING: By changing this setting you will lose all your old statistics for this domain. If you are 100% sure you wish to change this type "'.$lng['admin']['delete_statistics'].'" in the field below and click the "'.$lng['panel']['delete'].'" button.<br /><br />';
|
$lng['admin']['speciallogwarning'] = 'WARNING: By changing this setting you will lose all your old statistics for this domain. If you are 100% sure you wish to change this type "'.$lng['admin']['delete_statistics'].'" in the field below and click the "'.$lng['panel']['delete'].'" button.<br /><br />';
|
||||||
|
|
||||||
|
// ADDED IN 0.9.28-svn2
|
||||||
|
$lng['serversettings']['vmail_maildirname']['title'] = 'Maildir name';
|
||||||
|
$lng['serversettings']['vmail_maildirname']['description'] = 'Maildir directory into user\'s account. Normally \'Maildir\', in some implementations \'.maildir\', and directly into user\'s directory if left blank.';
|
||||||
|
$lng['tasks']['remove_emailacc_files'] = 'Delete customer e-mail data.';
|
||||||
|
|||||||
@@ -310,7 +310,6 @@ while($row = $db->fetch_array($result_tasks))
|
|||||||
safe_exec('rm -rf '.escapeshellarg($backupdir));
|
safe_exec('rm -rf '.escapeshellarg($backupdir));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* remove maildir
|
* remove maildir
|
||||||
*/
|
*/
|
||||||
@@ -318,7 +317,10 @@ while($row = $db->fetch_array($result_tasks))
|
|||||||
|
|
||||||
if($maildir != '/'
|
if($maildir != '/'
|
||||||
&& $maildir != $settings['system']['vmail_homedir']
|
&& $maildir != $settings['system']['vmail_homedir']
|
||||||
&& substr($maildir, 0, strlen($settings['system']['vmail_homedir'])) == $settings['system']['vmail_homedir'])
|
&& substr($maildir, 0, strlen($settings['system']['vmail_homedir'])) == $settings['system']['vmail_homedir']
|
||||||
|
&& is_dir($maildir)
|
||||||
|
&& fileowner($maildir) == $settings['system']['vmail_uid']
|
||||||
|
&& filegroup($maildir) == $settings['system']['vmail_gid'])
|
||||||
{
|
{
|
||||||
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Running: rm -rf ' . escapeshellarg($maildir));
|
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Running: rm -rf ' . escapeshellarg($maildir));
|
||||||
safe_exec('rm -rf '.escapeshellarg($maildir));
|
safe_exec('rm -rf '.escapeshellarg($maildir));
|
||||||
@@ -388,11 +390,24 @@ while($row = $db->fetch_array($result_tasks))
|
|||||||
/*
|
/*
|
||||||
* remove specific maildir
|
* remove specific maildir
|
||||||
*/
|
*/
|
||||||
$maildir = makeCorrectDir($settings['system']['vmail_homedir'] .'/'. $row['data']['loginname'] .'/'. $row['data']['email']);
|
$email_full = $row['data']['email'];
|
||||||
|
if (empty($email_full)) {
|
||||||
|
$cronlog->logAction(CRON_ACTION, LOG_ERROR, 'FATAL: Task7 asks to delete a email account but email field is empty!');
|
||||||
|
}
|
||||||
|
$email_user=substr($email_full,0,strrpos($email_full,"@"));
|
||||||
|
$email_domain=substr($email_full,strrpos($email_full,"@")+1);
|
||||||
|
$maildirname=trim($settings['system']['vmail_maildirname']);
|
||||||
|
// Add trailing slash to Maildir if needed
|
||||||
|
$maildirpath=$maildirname;
|
||||||
|
if (!empty($maildirname) and substr($maildirname,-1) != "/") $maildirpath.="/";
|
||||||
|
$maildir = makeCorrectDir($settings['system']['vmail_homedir'] .'/'. $row['data']['loginname'] .'/'. $email_domain .'/'. $email_user .'/'. $maildirpath);
|
||||||
|
|
||||||
if($maildir != '/'
|
if($maildir != '/' && !empty($maildir) && !empty($email_full)
|
||||||
&& $maildir != $settings['system']['vmail_homedir']
|
&& $maildir != $settings['system']['vmail_homedir']
|
||||||
&& substr($maildir, 0, strlen($settings['system']['vmail_homedir'])) == $settings['system']['vmail_homedir'])
|
&& substr($maildir, 0, strlen($settings['system']['vmail_homedir'])) == $settings['system']['vmail_homedir']
|
||||||
|
&& is_dir($maildir)
|
||||||
|
&& fileowner($maildir) == $settings['system']['vmail_uid']
|
||||||
|
&& filegroup($maildir) == $settings['system']['vmail_gid'])
|
||||||
{
|
{
|
||||||
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Running: rm -rf ' . escapeshellarg($maildir));
|
$cronlog->logAction(CRON_ACTION, LOG_NOTICE, 'Running: rm -rf ' . escapeshellarg($maildir));
|
||||||
safe_exec('rm -rf '.escapeshellarg($maildir));
|
safe_exec('rm -rf '.escapeshellarg($maildir));
|
||||||
|
|||||||
Reference in New Issue
Block a user