summaryrefslogtreecommitdiffstats
path: root/modules-available/backup
diff options
context:
space:
mode:
authorSimon Rettberg2023-03-02 16:07:01 +0100
committerSimon Rettberg2023-03-02 16:07:01 +0100
commitd7f11c6543bfff777df7bd533e1d04ff8a48b81c (patch)
tree0c6b4a7eafc482d75ef19b407b22578691e2a7da /modules-available/backup
parent[backup] Add UI for monthly automatic backup + password support (diff)
downloadslx-admin-d7f11c6543bfff777df7bd533e1d04ff8a48b81c.tar.gz
slx-admin-d7f11c6543bfff777df7bd533e1d04ff8a48b81c.tar.xz
slx-admin-d7f11c6543bfff777df7bd533e1d04ff8a48b81c.zip
[backup] Check supplied backup file before trying to apply
This saves us from aborting midway and doing a reboot
Diffstat (limited to 'modules-available/backup')
-rw-r--r--modules-available/backup/page.inc.php40
-rw-r--r--modules-available/backup/templates/_page.html7
-rw-r--r--modules-available/backup/templates/restore.html10
-rw-r--r--modules-available/backup/templates/task-error.html6
4 files changed, 47 insertions, 16 deletions
diff --git a/modules-available/backup/page.inc.php b/modules-available/backup/page.inc.php
index 04cb82b4..67be584f 100644
--- a/modules-available/backup/page.inc.php
+++ b/modules-available/backup/page.inc.php
@@ -32,7 +32,12 @@ class Page_Backup extends Page
{
if ($this->action === 'restore') { // TODO: We're in post mode, redirect with all the taskids first...
Render::addTemplate('restore', $this->templateData);
+ } elseif (($taskid = Request::get('errtaskid', false, 'string')) !== false) {
+ Render::addTemplate('task-error', ['taskid' => $taskid]);
} else {
+ // Normal page
+ $title = Property::get('page-title-prefix', '');
+ $bgcolor = Property::get('logo-background', '');
$lastBackup = (int)Property::get(BackupRestore::PROP_LAST_BACKUP, 0);
if ($lastBackup === 0) {
$lastBackup = false;
@@ -40,6 +45,8 @@ class Page_Backup extends Page
$lastBackup = date('d.m.Y', $lastBackup);
}
$params = [
+ 'id_color' => $bgcolor,
+ 'id_prefix' => $title,
'last_backup' => $lastBackup,
'autoBackupEnabled_checked' => Property::get(BackupRestore::PROP_AUTO_BACKUP_MODE, BackupRestore::BACKUP_MODE_OFF)
!= BackupRestore::BACKUP_MODE_OFF ? 'checked' : '',
@@ -56,6 +63,7 @@ class Page_Backup extends Page
if (empty($password)) {
$password = null;
}
+ EventLog::info('Creating backup on ' . Property::getServerIp());
$task = Taskmanager::submit('BackupRestore', [
'mode' => 'backup',
'password' => $password,
@@ -66,9 +74,7 @@ class Page_Backup extends Page
}
$task = Taskmanager::waitComplete($task, 60000);
if (!Taskmanager::isFinished($task) || !isset($task['data']['backupFile'])) {
- file_put_contents('/tmp/bwlp-backup-error-' . time() . '.txt', json_encode($task['data']));
- Taskmanager::addErrorMessage($task);
- Util::redirect('?do=Backup');
+ Util::redirect('?do=backup&errtaskid=' . $task['id']);
}
while ((@ob_get_level()) > 0)
@ob_end_clean();
@@ -110,11 +116,27 @@ class Page_Backup extends Page
Message::addError('upload-failed', Util::uploadErrorString($_FILES['backupfile']['error']));
Util::redirect('?do=Backup');
}
+ $password = trim(Request::post('passwd', '', 'string'));
+ if (empty($password)) {
+ $password = null;
+ }
$tempfile = '/tmp/bwlp-' . mt_rand(1, 100000) . '-' . crc32($_SERVER['REMOTE_ADDR']) . '.tgz';
if (!move_uploaded_file($_FILES['backupfile']['tmp_name'], $tempfile)) {
Message::addError('main.error-write', $tempfile);
Util::redirect('?do=Backup');
}
+ copy($tempfile, $tempfile . '2');
+ // Check if correct password first etc.
+ $task = Taskmanager::submit('BackupRestore', [
+ 'mode' => 'test',
+ 'password' => $password,
+ 'backupFile' => $tempfile . '2',
+ ]);
+ $task = Taskmanager::waitComplete($task, 5000);
+ @unlink($tempfile . '2');
+ if (Taskmanager::isFailed($task)) {
+ Util::redirect('?do=backup&errtaskid=' . $task['id']);
+ }
// Got uploaded file, now shut down all the daemons etc.
$parent = Trigger::stopDaemons(null, $this->templateData);
// Unmount store
@@ -128,13 +150,8 @@ class Page_Backup extends Page
$this->templateData['mountid'] = $task['id'];
$parent = $task['id'];
}
- EventLog::info('Creating backup on ' . Property::getServerIp());
- $password = trim(Request::post('passwd', '', 'string'));
- if (empty($password)) {
- $password = null;
- }
// Finally run restore
- $task = Taskmanager::submit('BackupRestore', array(
+ $task = Taskmanager::submit('BackupRestore', [
'mode' => 'restore',
'password' => $password,
'backupFile' => $tempfile,
@@ -142,7 +159,7 @@ class Page_Backup extends Page
'failOnParentFail' => false,
'restoreOpenslx' => Request::post('restore_openslx', 'off') === 'on',
'restoreDozmod' => Request::post('restore_dozmod', 'off') === 'on',
- ));
+ ]);
if (isset($task['id'])) {
$this->templateData['restoreid'] = $task['id'];
$parent = $task['id'];
@@ -163,8 +180,9 @@ class Page_Backup extends Page
));
// Leave this comment so the i18n scanner finds it:
// Message::addSuccess('restore-done');
- if (isset($task['id']))
+ if (isset($task['id'])) {
$this->templateData['rebootid'] = $task['id'];
+ }
}
private function config()
diff --git a/modules-available/backup/templates/_page.html b/modules-available/backup/templates/_page.html
index 52dd7e72..2fb89b18 100644
--- a/modules-available/backup/templates/_page.html
+++ b/modules-available/backup/templates/_page.html
@@ -30,8 +30,8 @@
<input type="hidden" name="token" value="{{token}}">
<input type="hidden" name="action" value="restore">
<div class="panel panel-default">
- <div class="panel-heading">{{lang_restore}}</div>
- <div class="panel-body {{perms.restore.disabled}}">
+ <div class="panel-heading">{{lang_restoreHeading}}{{#id_prefix}} – <b>{{.}}</b>{{/id_prefix}}</div>
+ <div class="panel-body {{perms.restore.disabled}}" {{#id_color}}style="border:5px solid {{.}}"{{/id_color}}>
<p>{{lang_restoreDescription}}</p>
<label for="file-out">{{lang_restoreFileLabel}}</label>
<div class="input-group upload-ex">
@@ -68,7 +68,8 @@
</div>
<button {{perms.restore.disabled}} class="btn btn-primary pull-right" type="submit">
<span class="glyphicon glyphicon-open"></span>
- {{lang_restore}}
+ {{lang_restoreButton}}
+ {{#id_prefix}} – {{.}}{{/id_prefix}}
</button>
</div>
</div>
diff --git a/modules-available/backup/templates/restore.html b/modules-available/backup/templates/restore.html
index c9c19d2b..3e57a3ee 100644
--- a/modules-available/backup/templates/restore.html
+++ b/modules-available/backup/templates/restore.html
@@ -20,6 +20,7 @@
<script type="text/javascript">
var slxDotInterval = false;
+ var restoreSuccess = false;
function restoreCb(task)
{
if (!task || !task.statusCode)
@@ -28,6 +29,7 @@
$('#restorefailed').show('slow');
}
if (task.statusCode === 'TASK_ERROR' || task.statusCode === 'TASK_FINISHED') {
+ restoreSuccess = (task.statusCode === 'TASK_FINISHED');
startRebootPoll();
}
}
@@ -48,14 +50,18 @@
}
$('#dots').text($('#dots').text() + '..');
slxTimeoutId = setTimeout(rebootPoll, 3500);
- $.ajax({url: "index.php?do=Main", timeout: 3000}).success(function(data, textStatus, jqXHR) {
+ $.ajax({url: "?do=main", timeout: 3000}).success(function(data, textStatus, jqXHR) {
if (textStatus !== "success" && textStatus !== "notmodified")
return;
if (data.indexOf('Status: DB running') === -1)
return;
clearTimeout(slxTimeoutId);
setTimeout(function() {
- window.location.replace("index.php?do=Main&message[]=success%7Cbackup.restore-done");
+ if (restoreSuccess) {
+ window.location.replace("?do=main&message[]=success%7Cbackup.restore-done");
+ } else {
+ window.location.replace("?do=main");
+ }
}, 3500);
});
}
diff --git a/modules-available/backup/templates/task-error.html b/modules-available/backup/templates/task-error.html
new file mode 100644
index 00000000..56837799
--- /dev/null
+++ b/modules-available/backup/templates/task-error.html
@@ -0,0 +1,6 @@
+<div class="panel panel-default">
+ <div class="panel-heading panel-danger">{{lang_error}}</div>
+ <div class="panel-body">
+ <div data-tm-id="{{taskid}}" data-tm-log="messages">{{lang_checkingArchive}}</div>
+ </div>
+</div>