Skip to content
Snippets Groups Projects
Commit f7577711 authored by Falko Timme's avatar Falko Timme Committed by Patrick Anders
Browse files

- Made sure SQL backups from servers that differ from the server where the...

- Made sure SQL backups from servers that differ from the server where the website is on can be restored. A download of the backup is not possible in such a case, therefore I hide the "Download" button.

Conflicts:
	interface/lib/classes/plugin_backuplist.inc.php
parent 8173c6f2
No related branches found
No related tags found
No related merge requests found
...@@ -67,13 +67,16 @@ class plugin_backuplist extends plugin_base { ...@@ -67,13 +67,16 @@ class plugin_backuplist extends plugin_base {
} }
if($_GET['backup_action'] == 'download' && $backup_id > 0) { if($_GET['backup_action'] == 'download' && $backup_id > 0) {
$server_id = $this->form->dataRecord['server_id'];
$backup = $app->db->queryOneRecord("SELECT * FROM web_backup WHERE backup_id = ".$backup_id);
if($backup['server_id'] > 0) $server_id = $backup['server_id'];
$sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_download' AND action_param = '$backup_id'"; $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); $tmp = $app->db->queryOneRecord($sql);
if($tmp['number'] == 0) { if($tmp['number'] == 0) {
$message .= $wb['download_info_txt']; $message .= $wb['download_info_txt'];
$sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " . $sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
"VALUES (". "VALUES (".
(int)$this->form->dataRecord['server_id'] . ", " . (int)$server_id . ", " .
time() . ", " . time() . ", " .
"'backup_download', " . "'backup_download', " .
"'".$backup_id."', " . "'".$backup_id."', " .
...@@ -86,13 +89,16 @@ class plugin_backuplist extends plugin_base { ...@@ -86,13 +89,16 @@ class plugin_backuplist extends plugin_base {
} }
} }
if($_GET['backup_action'] == 'restore' && $backup_id > 0) { if($_GET['backup_action'] == 'restore' && $backup_id > 0) {
$server_id = $this->form->dataRecord['server_id'];
$backup = $app->db->queryOneRecord("SELECT * FROM web_backup WHERE backup_id = ".$backup_id);
if($backup['server_id'] > 0) $server_id = $backup['server_id'];
$sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_restore' AND action_param = '$backup_id'"; $sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_restore' AND action_param = '$backup_id'";
$tmp = $app->db->queryOneRecord($sql); $tmp = $app->db->queryOneRecord($sql);
if($tmp['number'] == 0) { if($tmp['number'] == 0) {
$message .= $wb['restore_info_txt']; $message .= $wb['restore_info_txt'];
$sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " . $sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
"VALUES (". "VALUES (".
(int)$this->form->dataRecord['server_id'] . ", " . (int)$server_id . ", " .
time() . ", " . time() . ", " .
"'backup_restore', " . "'backup_restore', " .
"'".$backup_id."', " . "'".$backup_id."', " .
...@@ -108,8 +114,26 @@ class plugin_backuplist extends plugin_base { ...@@ -108,8 +114,26 @@ class plugin_backuplist extends plugin_base {
} }
//* Get the data //* Get the data
$server_ids = array();
$web = $app->db->queryOneRecord("SELECT server_id FROM web_domain WHERE domain_id = ".$app->functions->intval($this->form->id)); $web = $app->db->queryOneRecord("SELECT server_id FROM web_domain WHERE domain_id = ".$app->functions->intval($this->form->id));
$sql = "SELECT * FROM web_backup WHERE parent_domain_id = ".$app->functions->intval($this->form->id)." AND server_id = ".$app->functions->intval($web['server_id'])." ORDER BY tstamp DESC, backup_type ASC"; $databases = $app->db->queryAllRecords("SELECT server_id FROM web_database WHERE parent_domain_id = ".$app->functions->intval($this->form->id));
if($app->functions->intval($web['server_id']) > 0) $server_ids[] = $app->functions->intval($web['server_id']);
if(is_array($databases) && !empty($databases)){
foreach($databases as $database){
if($app->functions->intval($database['server_id']) > 0) $server_ids[] = $app->functions->intval($database['server_id']);
}
}
$server_ids = array_unique($server_ids);
$web = $app->db->queryOneRecord("SELECT server_id FROM web_domain WHERE domain_id = ".$app->functions->intval($this->form->id));
$databases = $app->db->queryAllRecords("SELECT server_id FROM web_database WHERE parent_domain_id = ".$app->functions->intval($this->form->id));
if($app->functions->intval($web['server_id']) > 0) $server_ids[] = $app->functions->intval($web['server_id']);
if(is_array($databases) && !empty($databases)){
foreach($databases as $database){
if($app->functions->intval($database['server_id']) > 0) $server_ids[] = $app->functions->intval($database['server_id']);
}
}
$server_ids = array_unique($server_ids);
$sql = "SELECT * FROM web_backup WHERE parent_domain_id = ".$app->functions->intval($this->form->id)." AND server_id IN (".implode(',', $server_ids).") ORDER BY tstamp DESC, backup_type ASC";
$records = $app->db->queryAllRecords($sql); $records = $app->db->queryAllRecords($sql);
$bgcolor = "#FFFFFF"; $bgcolor = "#FFFFFF";
...@@ -122,6 +146,9 @@ class plugin_backuplist extends plugin_base { ...@@ -122,6 +146,9 @@ class plugin_backuplist extends plugin_base {
$rec['date'] = date($app->lng('conf_format_datetime'), $rec['tstamp']); $rec['date'] = date($app->lng('conf_format_datetime'), $rec['tstamp']);
$rec['backup_type'] = $wb[('backup_type_'.$rec['backup_type'])]; $rec['backup_type'] = $wb[('backup_type_'.$rec['backup_type'])];
$rec['download_available'] = true;
if($rec['server_id'] != $web['server_id']) $rec['download_available'] = false;
$records_new[] = $rec; $records_new[] = $rec;
} }
......
...@@ -30,7 +30,9 @@ ...@@ -30,7 +30,9 @@
<td class="tbl_col_buttons"> <td class="tbl_col_buttons">
<div class="buttons"> <div class="buttons">
<button class="button iconstxt icoRestore" type="button" onclick="confirm_action('sites/web_domain_edit.php?id={tmpl_var name='parent_id'}&next_tab=backup&backup_action=restore&backup_id={tmpl_var name='backup_id'}','{tmpl_var name='restore_confirm_txt'}');"><span>{tmpl_var name="restore_backup_txt"}</span></button> <button class="button iconstxt icoRestore" type="button" onclick="confirm_action('sites/web_domain_edit.php?id={tmpl_var name='parent_id'}&next_tab=backup&backup_action=restore&backup_id={tmpl_var name='backup_id'}','{tmpl_var name='restore_confirm_txt'}');"><span>{tmpl_var name="restore_backup_txt"}</span></button>
<tmpl_if name="download_available">
<button class="button iconstxt icoDownload" type="button" onclick="loadContent('sites/web_domain_edit.php?id={tmpl_var name='parent_id'}&next_tab=backup&backup_action=download&backup_id={tmpl_var name='backup_id'}');"><span>{tmpl_var name="download_backup_txt"}</span></button> <button class="button iconstxt icoDownload" type="button" onclick="loadContent('sites/web_domain_edit.php?id={tmpl_var name='parent_id'}&next_tab=backup&backup_action=download&backup_id={tmpl_var name='backup_id'}');"><span>{tmpl_var name="download_backup_txt"}</span></button>
</tmpl_if>
</div> </div>
</td> </td>
</tr> </tr>
......
...@@ -68,7 +68,7 @@ class backup_plugin { ...@@ -68,7 +68,7 @@ class backup_plugin {
$app->uses('ini_parser,file,getconf,system'); $app->uses('ini_parser,file,getconf,system');
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$backup['parent_domain_id']); $web = $app->dbmaster->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$backup['parent_domain_id']);
$server_config = $app->getconf->get_server_config($conf['server_id'], 'server'); $server_config = $app->getconf->get_server_config($conf['server_id'], 'server');
$backup_dir = $server_config['backup_dir'].'/web'.$web['domain_id']; $backup_dir = $server_config['backup_dir'].'/web'.$web['domain_id'];
...@@ -80,7 +80,7 @@ class backup_plugin { ...@@ -80,7 +80,7 @@ class backup_plugin {
//* Make backup available for download //* Make backup available for download
if($action_name == 'backup_download') { if($action_name == 'backup_download') {
//* Copy the backup file to the backup folder of the website //* Copy the backup file to the backup folder of the website
if(file_exists($backup_dir.'/'.$backup['filename']) && !stristr($backup_dir.'/'.$backup['filename'], '..') && !stristr($backup_dir.'/'.$backup['filename'], 'etc')) { if(file_exists($backup_dir.'/'.$backup['filename']) && file_exists($web['document_root'].'/backup/') && !stristr($backup_dir.'/'.$backup['filename'], '..') && !stristr($backup_dir.'/'.$backup['filename'], 'etc')) {
copy($backup_dir.'/'.$backup['filename'], $web['document_root'].'/backup/'.$backup['filename']); copy($backup_dir.'/'.$backup['filename'], $web['document_root'].'/backup/'.$backup['filename']);
chgrp($web['document_root'].'/backup/'.$backup['filename'], $web['system_group']); chgrp($web['document_root'].'/backup/'.$backup['filename'], $web['system_group']);
$app->log('cp '.$backup_dir.'/'.$backup['filename'].' '.$web['document_root'].'/backup/'.$backup['filename'], LOGLEVEL_DEBUG); $app->log('cp '.$backup_dir.'/'.$backup['filename'].' '.$web['document_root'].'/backup/'.$backup['filename'], LOGLEVEL_DEBUG);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment