Skip to content

Commit 3d06bad

Browse files
committed
- 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.
1 parent ebe5df7 commit 3d06bad

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

interface/lib/classes/plugin_backuplist.inc.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,16 @@ function onShow() {
6767
}
6868

6969
if($_GET['backup_action'] == 'download' && $backup_id > 0) {
70+
$server_id = $this->form->dataRecord['server_id'];
71+
$backup = $app->db->queryOneRecord("SELECT * FROM web_backup WHERE backup_id = ".$backup_id);
72+
if($backup['server_id'] > 0) $server_id = $backup['server_id'];
7073
$sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_download' AND action_param = '$backup_id'";
7174
$tmp = $app->db->queryOneRecord($sql);
7275
if($tmp['number'] == 0) {
7376
$message .= $wb['download_info_txt'];
7477
$sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
7578
"VALUES (".
76-
(int)$this->form->dataRecord['server_id'] . ", " .
79+
(int)$server_id . ", " .
7780
time() . ", " .
7881
"'backup_download', " .
7982
"'".$backup_id."', " .
@@ -86,13 +89,16 @@ function onShow() {
8689
}
8790
}
8891
if($_GET['backup_action'] == 'restore' && $backup_id > 0) {
92+
$server_id = $this->form->dataRecord['server_id'];
93+
$backup = $app->db->queryOneRecord("SELECT * FROM web_backup WHERE backup_id = ".$backup_id);
94+
if($backup['server_id'] > 0) $server_id = $backup['server_id'];
8995
$sql = "SELECT count(action_id) as number FROM sys_remoteaction WHERE action_state = 'pending' AND action_type = 'backup_restore' AND action_param = '$backup_id'";
9096
$tmp = $app->db->queryOneRecord($sql);
9197
if($tmp['number'] == 0) {
9298
$message .= $wb['restore_info_txt'];
9399
$sql = "INSERT INTO sys_remoteaction (server_id, tstamp, action_type, action_param, action_state, response) " .
94100
"VALUES (".
95-
(int)$this->form->dataRecord['server_id'] . ", " .
101+
(int)$server_id . ", " .
96102
time() . ", " .
97103
"'backup_restore', " .
98104
"'".$backup_id."', " .
@@ -110,9 +116,13 @@ function onShow() {
110116
//* Get the data
111117
$server_ids = array();
112118
$web = $app->db->queryOneRecord("SELECT server_id FROM web_domain WHERE domain_id = ".$app->functions->intval($this->form->id));
113-
$database = $app->db->queryOneRecord("SELECT server_id FROM web_database WHERE parent_domain_id = ".$app->functions->intval($this->form->id));
119+
$databases = $app->db->queryAllRecords("SELECT server_id FROM web_database WHERE parent_domain_id = ".$app->functions->intval($this->form->id));
114120
if($app->functions->intval($web['server_id']) > 0) $server_ids[] = $app->functions->intval($web['server_id']);
115-
if($app->functions->intval($database['server_id']) > 0) $server_ids[] = $app->functions->intval($database['server_id']);
121+
if(is_array($databases) && !empty($databases)){
122+
foreach($databases as $database){
123+
if($app->functions->intval($database['server_id']) > 0) $server_ids[] = $app->functions->intval($database['server_id']);
124+
}
125+
}
116126
$server_ids = array_unique($server_ids);
117127
$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";
118128
$records = $app->db->queryAllRecords($sql);
@@ -127,6 +137,9 @@ function onShow() {
127137

128138
$rec['date'] = date($app->lng('conf_format_datetime'), $rec['tstamp']);
129139
$rec['backup_type'] = $wb[('backup_type_'.$rec['backup_type'])];
140+
141+
$rec['download_available'] = true;
142+
if($rec['server_id'] != $web['server_id']) $rec['download_available'] = false;
130143

131144
$records_new[] = $rec;
132145
}

interface/web/sites/templates/web_backup_list.htm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ <h3><tmpl_var name="list_head_txt"></h3>
2828
<td class="tbl_col_buttons">
2929
<div class="buttons">
3030
<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>
31+
<tmpl_if name="download_available">
3132
<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>
33+
</tmpl_if>
3234
</div>
3335
</td>
3436
</tr>

server/plugins-available/backup_plugin.inc.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function backup_action($action_name, $data) {
6767

6868
$app->uses('ini_parser,file,getconf,system');
6969

70-
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$backup['parent_domain_id']);
70+
$web = $app->dbmaster->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$backup['parent_domain_id']);
7171
$server_config = $app->getconf->get_server_config($conf['server_id'], 'server');
7272
$backup_dir = $server_config['backup_dir'].'/web'.$web['domain_id'];
7373

@@ -100,7 +100,7 @@ public function backup_action($action_name, $data) {
100100
//* Make backup available for download
101101
if($action_name == 'backup_download') {
102102
//* Copy the backup file to the backup folder of the website
103-
if(file_exists($backup_dir.'/'.$backup['filename']) && !stristr($backup_dir.'/'.$backup['filename'], '..') && !stristr($backup_dir.'/'.$backup['filename'], 'etc')) {
103+
if(file_exists($backup_dir.'/'.$backup['filename']) && file_exists($web['document_root'].'/backup/') && !stristr($backup_dir.'/'.$backup['filename'], '..') && !stristr($backup_dir.'/'.$backup['filename'], 'etc')) {
104104
copy($backup_dir.'/'.$backup['filename'], $web['document_root'].'/backup/'.$backup['filename']);
105105
chgrp($web['document_root'].'/backup/'.$backup['filename'], $web['system_group']);
106106
$app->log('cp '.$backup_dir.'/'.$backup['filename'].' '.$web['document_root'].'/backup/'.$backup['filename'], LOGLEVEL_DEBUG);

0 commit comments

Comments
 (0)