From 2604cb9fa6bc7a25714b96a5cd42ada0b79a2c57 Mon Sep 17 00:00:00 2001 From: Florian Schaal <florian@schaal-24.de> Date: Tue, 07 Jan 2014 08:53:10 -0500 Subject: [PATCH] remove backups when deleting a mail-domain or mail-user --- server/plugins-available/mail_plugin.inc.php | 61 ++++++++++++++++++++++++++++++ 1 files changed, 61 insertions(+), 0 deletions(-) diff --git a/server/plugins-available/mail_plugin.inc.php b/server/plugins-available/mail_plugin.inc.php index 5bf37d1..31500b1 100644 --- a/server/plugins-available/mail_plugin.inc.php +++ b/server/plugins-available/mail_plugin.inc.php @@ -317,12 +317,44 @@ $app->uses("getconf"); $mail_config = $app->getconf->get_server_config($conf['server_id'], 'mail'); + $maildir_path_deleted = false; $old_maildir_path = escapeshellcmd($data['old']['maildir']); if($old_maildir_path != $mail_config['homedir_path'] && strlen($old_maildir_path) > strlen($mail_config['homedir_path']) && !stristr($old_maildir_path, '//') && !stristr($old_maildir_path, '..') && !stristr($old_maildir_path, '*') && strlen($old_maildir_path) >= 10) { exec('rm -rf '.escapeshellcmd($old_maildir_path)); $app->log('Deleted the Maildir: '.$data['old']['maildir'], LOGLEVEL_DEBUG); + $maildir_path_deleted = true; } else { $app->log('Possible security violation when deleting the maildir: '.$data['old']['maildir'], LOGLEVEL_ERROR); + } + //* Delete the mail-backups + $server_config = $app->getconf->get_server_config($conf['server_id'], 'server'); + $backup_dir = $server_config['backup_dir']; + //* mount backup directory, if necessary + $mount_backup = true; + $server_config['backup_dir_mount_cmd'] = trim($server_config['backup_dir_mount_cmd']); + if($server_config['backup_dir'] != '' && $maildir_path_deleted) { + if($server_config['backup_dir_is_mount'] == 'y' && $server_config['backup_dir_mount_cmd'] != ''){ + if(!$app->system->is_mounted($backup_dir)){ + exec(escapeshellcmd($server_config['backup_dir_mount_cmd'])); + sleep(1); + if(!$app->system->is_mounted($backup_dir)) $mount_backup = false; + } + } + if($mount_backup){ + $sql = "SELECT * FROM mail_domain WHERE domain = '".explode("@",$data['old']['email'])[1]."'"; + $domain_rec = $app->db->queryOneRecord($sql); + $mail_backup_dir = $backup_dir.'/mail'.$domain_rec['domain_id']; + $mail_backup_files = 'mail'.$data['old']['mailuser_id']; + exec(escapeshellcmd('rm -f '.$mail_backup_dir.'/'.$mail_backup_files).'*'); + //* cleanup database + $sql = "DELETE FROM mail_backup WHERE server_id = ".$conf['server_id']." AND parent_domain_id = ".$domain_rec['domain_id']." AND mailuser_id = ".$data['old']['mailuser_id']; + $app->db->query($sql); + if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql); + + $app->log('Deleted the mail backups for: '.$data['old']['email'], LOGLEVEL_DEBUG); + + + } } } @@ -333,11 +365,13 @@ $app->uses("getconf"); $mail_config = $app->getconf->get_server_config($conf['server_id'], 'mail'); + $maildomain_path_deleted = false; //* Delete maildomain path $old_maildomain_path = escapeshellcmd($mail_config['homedir_path'].'/'.$data['old']['domain']); if($old_maildomain_path != $mail_config['homedir_path'] && !stristr($old_maildomain_path, '//') && !stristr($old_maildomain_path, '..') && !stristr($old_maildomain_path, '*') && !stristr($old_maildomain_path, '&') && strlen($old_maildomain_path) >= 10 && !empty($data['old']['domain'])) { exec('rm -rf '.escapeshellcmd($old_maildomain_path)); $app->log('Deleted the mail domain directory: '.$old_maildomain_path, LOGLEVEL_DEBUG); + $maildomain_path_deleted = true; } else { $app->log('Possible security violation when deleting the mail domain directory: '.$old_maildomain_path, LOGLEVEL_ERROR); } @@ -350,6 +384,33 @@ } else { $app->log('Possible security violation when deleting the mail domain mailfilter directory: '.$old_maildomain_path, LOGLEVEL_ERROR); } + + //* Delete the mail-backups + $server_config = $app->getconf->get_server_config($conf['server_id'], 'server'); + $backup_dir = $server_config['backup_dir']; + //* mount backup directory, if necessary + $mount_backup = true; + $server_config['backup_dir_mount_cmd'] = trim($server_config['backup_dir_mount_cmd']); + if($server_config['backup_dir'] != '' && $maildomain_path_deleted) { + if($server_config['backup_dir_is_mount'] == 'y' && $server_config['backup_dir_mount_cmd'] != ''){ + if(!$app->system->is_mounted($backup_dir)){ + exec(escapeshellcmd($server_config['backup_dir_mount_cmd'])); + sleep(1); + if(!$app->system->is_mounted($backup_dir)) $mount_backup = false; + } + } + if($mount_backup){ + $mail_backup_dir = $backup_dir.'/mail'.$data['old']['domain_id']; + exec(escapeshellcmd('rm -rf '.$mail_backup_dir)); + //* cleanup database + $sql = "DELETE FROM mail_backup WHERE server_id = ".$conf['server_id']." AND parent_domain_id = ".$data_old['domain_id']; + $app->db->query($sql); + if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql); + + $app->log('Deleted the mail backup directory: '.$mail_backup_dir, LOGLEVEL_DEBUG); + } + } + } function transport_update($event_name, $data) { -- Gitblit v1.9.1