Commit d2c52bba authored by Dominik's avatar Dominik

fixed confusion about restoring mail/web-backup with same id

parent 053a837f
......@@ -53,7 +53,7 @@ class plugin_backuplist_mail extends plugin_base {
if(isset($_GET['backup_action'])) {
$backup_id = $app->functions->intval($_GET['backup_id']);
/*
if($_GET['backup_action'] == 'download' && $backup_id > 0) {
if($_GET['backup_action'] == 'download_mail' && $backup_id > 0) {
$sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_download' AND action_param = '$backup_id'";
$tmp = $app->db->queryOneRecord($sql);
if($tmp['number'] == 0) {
......@@ -73,8 +73,8 @@ class plugin_backuplist_mail extends plugin_base {
}
}
*/
if($_GET['backup_action'] == 'restore' && $backup_id > 0) {
$sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_restore' AND action_param = '$backup_id'";
if($_GET['backup_action'] == 'restore_mail' && $backup_id > 0) {
$sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_restore_mail' AND action_param = '$backup_id'";
$tmp = $app->db->queryOneRecord($sql);
if($tmp['number'] == 0) {
$message .= $wb['restore_info_txt'];
......
......@@ -26,8 +26,8 @@
<td>{tmpl_var name="filesize"}</td>
<td class="text-right">
<div class="buttons">
<button class="btn btn-default formbutton-default" type="button" onclick="confirm_action('mail/mail_user_edit.php?id={tmpl_var name='parent_id'}&next_tab=backup&backup_action=mailrestore&backup_id={tmpl_var name='backup_id'}','{tmpl_var name='restore_confirm_txt'}');">{tmpl_var name="restore_backup_txt"}</button>
<!-- <button class="btn btn-default formbutton-default" type="button" data-load-content="mail/mail_user_edit.php?id={tmpl_var name='parent_id'}&next_tab=backup&backup_action=maildownload&backup_id={tmpl_var name='backup_id'}">{tmpl_var name="download_backup_txt"}</button>
<button class="btn btn-default formbutton-default" type="button" onclick="confirm_action('mail/mail_user_edit.php?id={tmpl_var name='parent_id'}&next_tab=backup&backup_action=restore_mail&backup_id={tmpl_var name='backup_id'}','{tmpl_var name='restore_confirm_txt'}');">{tmpl_var name="restore_backup_txt"}</button>
<!-- <button class="btn btn-default formbutton-default" type="button" data-load-content="mail/mail_user_edit.php?id={tmpl_var name='parent_id'}&next_tab=backup&backup_action=download_mail&backup_id={tmpl_var name='backup_id'}">{tmpl_var name="download_backup_txt"}</button>
-->
</div>
</td>
......
......@@ -53,7 +53,8 @@ class backup_plugin {
//* Register for actions
$app->plugins->registerAction('backup_download', $this->plugin_name, 'backup_action');
$app->plugins->registerAction('backup_restore', $this->plugin_name, 'backup_action');
$app->plugins->registerAction('backup_mailrestore', $this->plugin_name, 'backup_action');
//$app->plugins->registerAction('backup_download_mail', $this->plugin_name, 'backup_action_mail');
$app->plugins->registerAction('backup_restore_mail', $this->plugin_name, 'backup_action_mail');
}
......@@ -63,9 +64,8 @@ class backup_plugin {
$backup_id = intval($data);
$backup = $app->dbmaster->queryOneRecord("SELECT * FROM web_backup WHERE backup_id = $backup_id");
$mail_backup = $app->dbmaster->queryOneRecord("SELECT * FROM mail_backup WHERE backup_id = $backup_id");
if(is_array($backup) && ($action_name != 'backup_mailrestore')) {
if(is_array($backup)) {
$app->uses('ini_parser,file,getconf,system');
......@@ -159,38 +159,62 @@ class backup_plugin {
} else {
$app->log('Backup directory not ready.', LOGLEVEL_DEBUG);
}
//* Restore a mail backup - florian@schaal-24.de
} elseif (is_array($mail_backup) && ($action_name == 'backup_mailrestore')) {
$app->uses('ini_parser,file,getconf');
} else {
$app->log('No backup with ID '.$backup_id.' found.', LOGLEVEL_DEBUG);
}
return 'ok';
}
//* Restore a mail backup - florian@schaal-24.de
public function backup_action_mail($action_name, $data) {
global $app, $conf;
$backup_id = intval($data);
$mail_backup = $app->dbmaster->queryOneRecord("SELECT * FROM mail_backup WHERE backup_id = $backup_id");
if (is_array($mail_backup) && $action_name == 'backup_restore_mail') {
$app->uses('ini_parser,file,getconf');
$server_config = $app->getconf->get_server_config($conf['server_id'], 'server');
$backup_dir = $server_config['backup_dir'];
$backup_dir_is_ready = true;
//* mount backup directory, if necessary
if( $server_config['backup_dir_is_mount'] == 'y' && !$app->system->mount_backup_dir($backup_dir) ) $backup_dir_is_ready = false;
if($backup_dir_is_ready){
$run_backups = true;
$backup_dir_mount_cmd = '/usr/local/ispconfig/server/scripts/backup_dir_mount.sh';
if( $server_config['backup_dir_is_mount'] == 'y' &&
is_file($backup_dir_mount_cmd) &&
is_executable($backup_dir_mount_cmd) &&
fileowner($backup_dir_mount_cmd) === 0
){
if(!$app->system->is_mounted($backup_dir)){
exec($backup_dir_mount_cmd);
sleep(1);
if(!$app->system->is_mounted($backup_dir)) $run_backups = false;
}
}
if($run_backups){
$mail_config = $app->getconf->get_server_config($conf['server_id'], 'mail');
$domain_rec = $app->db->queryOneRecord("SELECT * FROM mail_domain WHERE domain_id = ".intval($mail_backup['parent_domain_id']));
$backup_dir = $server_config['backup_dir'].'/mail'.$domain_rec['domain_id'];
$mail_backup_file = $backup_dir.'/'.$mail_backup['filename'];
$sql = "SELECT * FROM mail_user WHERE server_id = '".$conf['server_id']."' AND mailuser_id = ".intval($mail_backup['mailuser_id']);
$record = $app->db->queryOneRecord($sql);
//* strip mailbox from maildir
$domain_dir=explode('/',$record['maildir']);
$_temp=array_pop($domain_dir);unset($_temp);
$domain_dir=implode('/',$domain_dir);
if(!is_dir($domain_dir)) {
mkdir($domain_dir, 0700); //* never create the full path
chown($domain_dir, $mail_config['mailuser_name']);
chgrp($domain_dir, $mail_config['mailuser_group']);
}
if(file_exists($mail_backup_file) && $record['homedir'] != '' && $record['homedir'] != '/' && !stristr($mail_backup_file,'..') && !stristr($mail_backup_file,'etc') && $mail_config['homedir_path'] == $record['homedir'] && is_dir($domain_dir)) {
if($mail_backup['backup_mode'] == 'userzip') {
copy($mail_backup_file, $domain_dir.'/'.$mail_backup['filename']);
......@@ -223,7 +247,8 @@ class backup_plugin {
return 'ok';
}
} // end class
?>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment