| | |
| | | $email_parts = explode('@',$data['new']['email']); |
| | | $webdomain = $app->db->queryOneRecord("SELECT domain_id, server_id, system_user, parent_domain_id FROM web_domain WHERE domain = '".$app->db->quote($email_parts[1])."'"); |
| | | if ($webdomain) { |
| | | while ($webdomain['parent_domain_id'] != 0) { |
| | | while (($webdomain['system_user'] == null) && ($webdomain['parent_domain_id'] != 0)) { |
| | | $webdomain = $app->db->queryOneRecord("SELECT domain_id, server_id, system_user, parent_domain_id FROM web_domain WHERE domain_id = '".$webdomain['parent_domain_id']."'"); |
| | | } |
| | | $app->log($data['new']['server_id'].' == '.$webdomain['server_id'],LOGLEVEL_DEBUG); |
| | |
| | | $maildomain_path .= '/Maildir'; |
| | | } |
| | | |
| | | //* When the mail user dir exists but it is not a valid maildir, remove it |
| | | //* When the mail user dir exists but it is not a valid maildir, move it to corrupted maildir folder |
| | | if(!empty($maildomain_path) && is_dir($maildomain_path) && !is_dir($maildomain_path.'/new') && !is_dir($maildomain_path.'/cur')) { |
| | | exec("su -c 'rm -rf ".escapeshellcmd($data['new']['maildir'])."' vmail"); |
| | | $app->log('Removed invalid maildir and rebuild it: '.escapeshellcmd($data['new']['maildir']), LOGLEVEL_WARN); |
| | | if(!is_dir($mail_config['homedir_path'].'/corrupted/'.$data['new']['mailuser_id'])) $app->system->mkdirpath($mail_config['homedir_path'].'/corrupted/'.$data['new']['mailuser_id'], 0700, $mail_config['mailuser_name'], $mail_config['mailuser_group']); |
| | | exec("su -c 'mv -f ".escapeshellcmd($data['new']['maildir'])." ".$mail_config['homedir_path'].'/corrupted/'.$data['new']['mailuser_id']."' vmail"); |
| | | $app->log('Moved invalid maildir to corrupted Maildirs folder: '.escapeshellcmd($data['new']['maildir']), LOGLEVEL_WARN); |
| | | } |
| | | |
| | | //* Create the maildir, if it doesn not exist, set permissions, set quota. |
| | |
| | | unset($tmp_basepath_parts[count($tmp_basepath_parts)-1]); |
| | | $base_path = implode('/', $tmp_basepath_parts); |
| | | |
| | | //* Set the email-uid and gid if not given -> in case of changed settings again setting here |
| | | if (($data['new']['uid'] == -1) || ($data['new']['gid'] == -1)) { |
| | | $app->log('Setting uid and gid automatically',LOGLEVEL_DEBUG); |
| | | if ($mail_config["mailbox_virtual_uidgid_maps"] == 'y') { |
| | | $app->log('Map uid to linux-user',LOGLEVEL_DEBUG); |
| | | $email_parts = explode('@',$data['new']['email']); |
| | | $webdomain = $app->db->queryOneRecord("SELECT domain_id, server_id, system_user, parent_domain_id FROM web_domain WHERE domain = '".$app->db->quote($email_parts[1])."'"); |
| | | if ($webdomain) { |
| | | while ($webdomain['parent_domain_id'] != 0) { |
| | | $webdomain = $app->db->queryOneRecord("SELECT domain_id, server_id, system_user, parent_domain_id FROM web_domain WHERE domain_id = '".$webdomain['parent_domain_id']."'"); |
| | | } |
| | | $app->log($data['new']['server_id'].' == '.$webdomain['server_id'],LOGLEVEL_DEBUG); |
| | | |
| | | // only if web and mailserver are identical |
| | | if ($data['new']['server_id'] == $webdomain['server_id']) { |
| | | $data['new']['uid'] = $app->system->getuid($webdomain['system_user']); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // if nothing set before -> use standard mailuser uid and gid vmail |
| | | if ($data['new']['uid'] == -1) $data['new']['uid'] = $mail_config["mailuser_uid"]; |
| | | if ($data['new']['gid'] == -1) $data['new']['gid'] = $mail_config["mailuser_gid"]; |
| | | $app->log('Mailuser uid: '.$data['new']['uid'].', gid: '.$data['new']['gid'],LOGLEVEL_DEBUG); |
| | | |
| | | // update DB if values changed |
| | | $app->db->query("UPDATE mail_user SET uid = ".$data['new']['uid'].", gid = ".$data['new']['gid']." WHERE mailuser_id = ".$data['new']['mailuser_id']); |
| | | |
| | | $user = $app->system->getuser($data['new']['uid']); |
| | | $group = $app->system->getgroup($data['new']['gid']); |
| | | |
| | |
| | | $maildomain_path .= '/Maildir'; |
| | | } |
| | | |
| | | //* When the mail user dir exists but it is not a valid maildir, remove it |
| | | //* When the mail user dir exists but it is not a valid maildir, move it to corrupted maildir folder |
| | | if(!empty($maildomain_path) && is_dir($maildomain_path) && !is_dir($maildomain_path.'/new') && !is_dir($maildomain_path.'/cur')) { |
| | | exec("su -c 'rm -rf ".escapeshellcmd($data['new']['maildir'])."' vmail"); |
| | | $app->log('Removed invalid maildir and rebuild it: '.escapeshellcmd($data['new']['maildir']), LOGLEVEL_WARN); |
| | | if(!is_dir($mail_config['homedir_path'].'/corrupted/'.$data['new']['mailuser_id'])) $app->system->mkdirpath($mail_config['homedir_path'].'/corrupted/'.$data['new']['mailuser_id'], 0700, $mail_config['mailuser_name'], $mail_config['mailuser_group']); |
| | | exec("su -c 'mv -f ".escapeshellcmd($data['new']['maildir'])." ".$mail_config['homedir_path'].'/corrupted/'.$data['new']['mailuser_id']."' vmail"); |
| | | $app->log('Moved invalid maildir to corrupted Maildirs folder: '.escapeshellcmd($data['new']['maildir']), LOGLEVEL_WARN); |
| | | } |
| | | |
| | | //* Create the maildir, if it doesn not exist, set permissions, set quota. |
| | |
| | | //* 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 && $server_config['backup_delete'] == 'y') { |
| | | 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; |
| | | } |
| | | } |
| | | //* mount backup directory, if necessary |
| | | if( $server_config['backup_dir_is_mount'] == 'y' && !$app->system->mount_backup_dir($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_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); |
| | | $sql = "DELETE FROM mail_backup WHERE server_id = ? AND parent_domain_id = ? AND mailuser_id = ?"; |
| | | $app->db->query($sql, $conf['server_id'], $domain_rec['domain_id'], $data['old']['mailuser_id']); |
| | | if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql, $conf['server_id'], $domain_rec['domain_id'], $data['old']['mailuser_id']); |
| | | |
| | | $app->log('Deleted the mail backups for: '.$data['old']['email'], LOGLEVEL_DEBUG); |
| | | |
| | | |
| | | } |
| | | } |
| | | } |
| | |
| | | //* 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 && $server_config['backup_delete'] == 'y'){ |
| | | 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; |
| | | } |
| | | } |
| | | //* mount backup directory, if necessary |
| | | if( $server_config['backup_dir_is_mount'] == 'y' && !$app->system->mount_backup_dir($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); |
| | | $sql = "DELETE FROM mail_backup WHERE server_id = ? AND parent_domain_id = ? AND mailuser_id = ?"; |
| | | $app->db->query($sql, $conf['server_id'], $domain_rec['domain_id'], $data['old']['mailuser_id']); |
| | | if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql, $conf['server_id'], $domain_rec['domain_id'], $data['old']['mailuser_id']); |
| | | |
| | | $app->log('Deleted the mail backup directory: '.$mail_backup_dir, LOGLEVEL_DEBUG); |
| | | } |