mirror of
https://github.com/itflow-org/itflow
synced 2026-11-24 21:37:28 +00:00
Rebuild Maintenance > Backup on the Update page's pattern: a status card at the top says when the last backup was made, what kind and when the next scheduled one is due, or instead that one is being made, the last one failed and why, the last good one is over 7 days old, none has been made yet, a queued one is stuck because cron isn't running, or there is no encryption key, with Back up now and Database only under it, and the page reloads itself every 10 seconds while a backup is being made except while an exported master key is showing; the backups list uses the standard list plumbing with sortable headers on date, type, size and status and the standard pager, no longer stops at the newest 100, shows who made each backup or that the schedule did, when it was last downloaded and why one failed, and a row menu copies its path on the server and its SHA-256 checksum, deletes a finished backup, takes a queued one off the queue or removes a failed or missing one, with the card left out when there are no backups; the schedule and retention card shows whether the Backup cron job is on and at what time, with Turn on and Change the time using the Cron page's enable_cron_job handler and cron_edit window; an At a glance column has the last Full Backup and Database Only, the schedule, retention, how many are kept and their size, free space, cron status and the backup folder; the encryption key is masked behind the eye with a copy button; the master key export moves to a new ajax modal, admin/modals/backup/backup_master_key.php, which asks for the password and says an encrypted copy is filed with the backups and every agent is notified, where the old window said the key was not written anywhere; delete_backup in admin/post/backup.php words its audit entry and message by the backup's status; no new CSS or JS; changelog entries added to 26.11.8
This commit is contained in:
16
CHANGELOG.md
16
CHANGELOG.md
@@ -13,6 +13,16 @@ Update from Maintenance > Update — Queue Update hands the job to cron and it a
|
||||
- Invoices, quotes and recurring invoices: lines are added and changed on the page itself, and it no longer reloads each time. Under the lines there is one field in place of the row of boxes. Type a product's name or code and pick it - Enter takes the one picked out - and it goes on as a line at once, with its description, price and tax; on a quote it is billed as that product usually is, and on a recurring invoice counted per user or per device when that is how the product is set up. For a line that isn't one of your products, type what it is and press Enter, or pick Add at the bottom of the list. The new line's quantity is then ready to type over: Enter moves on to its price when it has none yet, and then back to the field for the next line.
|
||||
- Invoices, quotes and recurring invoices: click a line's name, description, quantity, price or tax to change it where it is. Enter, or clicking somewhere else, saves it; Escape puts it back; Tab goes on to the next. In a description Enter starts a new line, and Ctrl+Enter saves. Tax opens the list of rates. The line's amount, the totals, the amount due and the cards beside the page - balance, margin, hardware - follow as you go, and what you typed shows faded until it is saved. A line with no description shows where one goes while you are working on it. From the keyboard, Tab to any of them and press Enter. The Edit window is still in each line's menu, and is where a recurring invoice's line is set to count users, devices or license seats - a quantity that is counted can't be typed over.
|
||||
- Quotes: a line's menu has Billed - One time, Monthly, Quarterly or Yearly - so how often a line is billed changes in one click, and the line moves under its heading.
|
||||
- Backups: Maintenance > Backup is rebuilt so that its first line answers what you open it for - is this ITFlow backed up? The top of the page says when the last backup was made, what kind it was and when the next scheduled one is due. When something needs you, it says that instead: a backup is being made now, the last one didn't finish and why, there hasn't been one for a week, none has been made yet, or one has been waiting because cron isn't running. Back up now and Database only are right under it.
|
||||
- Backups: the page keeps itself up to date while a backup is being made, and shows it in the list as soon as it is done. It used to say it wouldn't refresh, and you reloaded to find out.
|
||||
- Backups: the list of backups works like every other list - it sorts by its headings and has pages - and says more about each one: who made it or that the schedule did, when it was last downloaded, and why one failed. A backup's menu copies its path on the server, which is what restoring from the command line asks for, and its SHA-256 checksum, for checking a copy kept somewhere else. A backup still waiting to be made can be taken off the queue.
|
||||
- Backups: the nightly backup is on the page. It shows whether the schedule is on and at what time, with Turn on and Change the time beside it, so there is no trip to Maintenance > Cron. Beside the page, At a glance has the last Full Backup and the last Database Only, how many backups are kept and the room they take, the free space left where they are kept, and whether cron is running.
|
||||
- Backups: the encryption key is hidden until you click the eye, with a button to copy it; it used to sit on the page in full for anyone looking at the screen. Exporting the master key opens a window that asks for your password and says what will happen before it does.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- Backups: the list showed only the newest 100. Older backups were still on the server, taking up room, with no way to download or delete them from the page. Every backup can now be reached.
|
||||
- Backups: the window for exporting the master key said the key "is not written anywhere". An encrypted copy is filed with the other backups; the window now says so, and that every agent is notified of the export.
|
||||
|
||||
### Developer Updates
|
||||
|
||||
@@ -23,6 +33,12 @@ Update from Maintenance > Update — Queue Update hands the job to cron and it a
|
||||
- A quantity or price is edited in a box laid over the number it replaces, which keeps its place unseen, so the columns don't move as a field opens; a name or description is edited in place of the text. The tax uses the select picker (`itflowSelect()`), opened from code under the line's tax. New in `css/itflow_custom.css`: `.itflow-line-field`, `.itflow-line-editor`, `.itflow-line-keep`, `.itflow-line-blank`, `.itflow-paper-add-field` and `tr.is-active`; the `.itflow-paper-add-grid` rules are gone. None of it prints.
|
||||
- `js/autocomplete.js` gains `pickFirst` (the first suggestion is picked out as the list opens, so Enter takes it) and `extra` / `onExtra` (a row under the list, always in view, for taking what was typed as it is - there when nothing matches too). Its list now opens above the field whenever it doesn't all fit below and there is more room above, as the select picker's does; it used to wait until under 120px was left. The asset form's operating system field is unchanged otherwise.
|
||||
- `getProductsForAutocomplete()` encodes with `JSON_HEX_TAG | JSON_HEX_AMP`, so a product's name or description can't end the `<script>` element it is written into.
|
||||
- `admin/backup.php` is rewritten on the pattern of `admin/update.php`: one `$state` - `nokey`, `working`, `stuck`, `failed`, `none`, `stale` or `current`, tried in that order - picks the hero card's icon, tone and title from `$hero`, and the rest of the page is plain cards. `stuck` is a queue more than 10 minutes old while the Backup cron job isn't running; `stale` is a last good backup older than 7 days, the age Debug's backup check warns at; a failure older than the last good backup isn't shown. While the state is `working` the card carries `data-itflow-reload-seconds="10"` and the page loads `js/auto_reload.js`, as the Update page does - but not while an exported master key is showing, which a reload would lose. No CSS or JavaScript is added.
|
||||
- The backups list uses the standard list plumbing: `$sort` and `$order` set before `inc_all_admin.php`, `SQL_CALC_FOUND_ROWS` with `$record_from` and `$record_to`, and `includes/filter_footer.php`. It sorts on `backup_created_at`, `backup_type`, `backup_size` and `backup_status` only, and any other `sort` falls back to the date. The card is left out when there are no backups, where the hero already says so. There is no search box: a backup has nothing to search by but its type and date, which the headings sort.
|
||||
- Turn on and Change the time are the Cron page's own - `post.php?enable_cron_job=<id>` and the `modals/cron/cron_edit.php` window - and both come back to the page they were used from. The retention form still posts `edit_backup_settings`; `queue_backup` and `backup_master_key` are unchanged.
|
||||
- The master key window is an ajax modal, `admin/modals/backup/backup_master_key.php`, in place of markup at the foot of the page. The encryption key field uses `data-toggle="password"` and the copy buttons `clipboardjs`, both already in `js/app.js`.
|
||||
- `delete_backup` (`admin/post/backup.php`) reads the row's status so that the audit log and the message say what happened: a `Pending` row is "took a queued Full Backup off the queue", a `Complete` one "Backup deleted.", and any other "Backup removed from the list."
|
||||
- Hooks for tests and scripts: `data-backup-state` on the hero, `data-backup-list` with `data-backup-id` and `data-backup-status` on each row, `data-backup-schedule` (`on` or `off`), `data-backup-glance`, `data-backup-folder`, `data-backup-key`, `data-backup-now`, `data-backup-cron-warning` and `data-backup-master-key`.
|
||||
|
||||
## [26.11.7]
|
||||
|
||||
|
||||
779
admin/backup.php
779
admin/backup.php
@@ -1,9 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Maintenance > Backup. One answer at the top - backed up, one being made, the last one
|
||||
* failed, none yet - with the buttons that take one. Under it the backups on this server,
|
||||
* then the schedule and how long backups are kept. Beside them: where backups stand at a
|
||||
* glance, the key they are encrypted with, how one is restored, and the credential vault's
|
||||
* master key.
|
||||
*
|
||||
* Nothing is built here. Back up now records a Pending row and asks the dispatcher for a
|
||||
* run (backupQueue()), and cron/backup.php builds it - so while one is on its way the page
|
||||
* reloads itself (js/auto_reload.js), as Maintenance > Update does. The handlers are
|
||||
* admin/post/backup.php; the schedule's own switch and time are the Backup job's, edited
|
||||
* in the Cron page's window (modals/cron/cron_edit.php), which comes back here.
|
||||
*/
|
||||
|
||||
// The list: newest first until a heading is clicked
|
||||
$sort = "backup_created_at";
|
||||
$order = "DESC";
|
||||
|
||||
require_once "includes/inc_all_admin.php";
|
||||
|
||||
$backup_key = backupEncryptionKey();
|
||||
$backup_dir = backupStorageDir();
|
||||
$csrf = $_SESSION['csrf_token'];
|
||||
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT config_enable_cron, config_cron_last_dispatch_at, config_backup_retention_days, config_backup_retention_count, config_backup_cron_type FROM settings WHERE company_id = 1"));
|
||||
|
||||
@@ -11,281 +30,559 @@ $config_enable_cron = intval($row['config_enable_cron']);
|
||||
$cron_last_dispatch_at = $row['config_cron_last_dispatch_at'];
|
||||
$config_backup_retention_days = intval($row['config_backup_retention_days']);
|
||||
$config_backup_retention_count = intval($row['config_backup_retention_count']);
|
||||
$config_backup_cron_type = $row['config_backup_cron_type'];
|
||||
$config_backup_cron_type = in_array($row['config_backup_cron_type'], backupUnattendedTypes(), true) ? $row['config_backup_cron_type'] : BACKUP_TYPE_FULL;
|
||||
|
||||
// Same heartbeat rule as Maintenance > Cron - archives are built by the dispatcher, so a dead
|
||||
// crontab means the buttons below queue work that never runs
|
||||
$cron_is_running = $cron_last_dispatch_at !== null && (time() - strtotime($cron_last_dispatch_at)) < 300;
|
||||
// Same heartbeat rule as Maintenance > Cron - backups are built by the dispatcher, so
|
||||
// without it the buttons below queue work that never runs
|
||||
$cron_heartbeat = $cron_last_dispatch_at !== null && (time() - strtotime($cron_last_dispatch_at)) < 300;
|
||||
$cron_is_running = $cron_heartbeat && $config_enable_cron === 1;
|
||||
|
||||
$backup_job = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT cron_job_enabled, cron_job_daily_at FROM cron_jobs WHERE cron_job_name = 'backup'"));
|
||||
$backup_job = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT cron_job_id, cron_job_enabled, cron_job_daily_at, cron_job_last_status, cron_job_last_run_at FROM cron_jobs WHERE cron_job_name = 'backup'"));
|
||||
$schedule_on = !empty($backup_job) && intval($backup_job['cron_job_enabled']) === 1;
|
||||
$schedule_time = substr((string) ($backup_job['cron_job_daily_at'] ?? ''), 0, 5);
|
||||
$backup_job_id = intval($backup_job['cron_job_id'] ?? 0);
|
||||
|
||||
$backups = mysqli_query($mysqli, "SELECT backup_created_at, backup_error, backup_id, backup_size, backup_source, backup_status,
|
||||
backup_type FROM backups ORDER BY backup_created_at DESC LIMIT 100");
|
||||
// The newest finished backup of each kind cron can make - the vault's key isn't a backup
|
||||
$latest = [];
|
||||
foreach (backupUnattendedTypes() as $type) {
|
||||
$latest[$type] = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT backup_type, backup_size, backup_source, backup_created_by, backup_created_at
|
||||
FROM backups WHERE backup_status = 'Complete' AND backup_type = '$type' ORDER BY backup_created_at DESC, backup_id DESC LIMIT 1"));
|
||||
}
|
||||
$last_good = null;
|
||||
foreach (array_filter($latest) as $candidate) {
|
||||
if (!$last_good || strtotime($candidate['backup_created_at']) > strtotime($last_good['backup_created_at'])) {
|
||||
$last_good = $candidate;
|
||||
}
|
||||
}
|
||||
$last_full = $latest[BACKUP_TYPE_FULL];
|
||||
|
||||
$pending_count = intval(mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT(*) AS c FROM backups WHERE backup_status IN ('Pending','Running')"))['c']);
|
||||
// A failure matters while nothing has worked since
|
||||
$last_failed = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT backup_type, backup_error, backup_created_at FROM backups
|
||||
WHERE backup_status = 'Failed' AND backup_type <> '" . BACKUP_TYPE_MASTER_KEY . "' ORDER BY backup_created_at DESC, backup_id DESC LIMIT 1"));
|
||||
if ($last_failed && $last_good && strtotime($last_failed['backup_created_at']) <= strtotime($last_good['backup_created_at'])) {
|
||||
$last_failed = null;
|
||||
}
|
||||
|
||||
?>
|
||||
// What is queued or being built
|
||||
$queue = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT(*) AS backups, COALESCE(SUM(backup_status = 'Running'), 0) AS started, MIN(backup_created_at) AS since, MIN(backup_type) AS type FROM backups WHERE backup_status IN ('Pending', 'Running')"));
|
||||
$queued = intval($queue['backups']);
|
||||
$started = intval($queue['started']) > 0;
|
||||
// Waiting longer than cron takes to come round, with the Backup job not at work, is stuck -
|
||||
// cron stopped, or the job died part way. The nightly job tidies it; no need to wait for that
|
||||
$job_at_work = ($backup_job['cron_job_last_status'] ?? '') === 'Running' && !empty($backup_job['cron_job_last_run_at'])
|
||||
&& strtotime($backup_job['cron_job_last_run_at']) > strtotime('-6 hours');
|
||||
$stuck = $queued > 0 && strtotime($queue['since']) < strtotime('-10 minutes') && !$job_at_work;
|
||||
|
||||
<?php
|
||||
// Shown once, immediately after an export, then dropped - it must not survive a refresh
|
||||
$kept = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT(*) AS backups, COALESCE(SUM(backup_size), 0) AS bytes FROM backups WHERE backup_status = 'Complete'"));
|
||||
$free_bytes = @disk_free_space($backup_dir);
|
||||
|
||||
/*
|
||||
* The one thing to say at the top. In this order, because each hides the ones after it:
|
||||
* no key to encrypt with, one on its way, a failure nothing has made up for, none at all,
|
||||
* one too old to count on, then all is well.
|
||||
*/
|
||||
$stale_days = 7; // the age Debug's backup check starts warning at
|
||||
if ($backup_key === '') {
|
||||
$state = 'nokey';
|
||||
} elseif ($queued > 0) {
|
||||
$state = $stuck ? 'stuck' : 'working';
|
||||
} elseif ($last_failed) {
|
||||
$state = 'failed';
|
||||
} elseif (!$last_good) {
|
||||
$state = 'none';
|
||||
} elseif (strtotime($last_good['backup_created_at']) < strtotime("-$stale_days days")) {
|
||||
$state = 'stale';
|
||||
} else {
|
||||
$state = 'current';
|
||||
}
|
||||
|
||||
$working_title = $queued === 1 ? 'Making a ' . backupTypeLabel((string) $queue['type']) . ($queue['type'] === BACKUP_TYPE_FULL ? '' : ' backup') : "Making $queued backups";
|
||||
$hero = [
|
||||
'nokey' => ['icon' => 'fa-key', 'tone' => 'danger', 'title' => "Backups can't be made yet"],
|
||||
'working' => ['icon' => 'fa-circle-notch fa-spin', 'tone' => 'primary', 'title' => $working_title],
|
||||
'stuck' => ['icon' => 'fa-hourglass-half', 'tone' => 'warning', 'title' => $started ? 'A backup stopped part way' : ($queued === 1 ? 'A backup is waiting to be made' : "$queued backups are waiting to be made")],
|
||||
'failed' => ['icon' => 'fa-exclamation-triangle', 'tone' => 'danger', 'title' => "The last backup didn't finish"],
|
||||
'none' => ['icon' => 'fa-life-ring', 'tone' => 'warning', 'title' => 'No backup yet'],
|
||||
'stale' => ['icon' => 'fa-history', 'tone' => 'warning', 'title' => 'The last backup is ' . ($last_good ? floor((time() - strtotime($last_good['backup_created_at'])) / 86400) : 0) . ' days old'],
|
||||
'current' => ['icon' => 'fa-check', 'tone' => 'success', 'title' => 'Backed up ' . ($last_good ? timeAgo($last_good['backup_created_at']) : '')],
|
||||
][$state];
|
||||
|
||||
// Shown once, straight after an export, then dropped - it must not survive a reload
|
||||
$master_key_reveal = '';
|
||||
if (!empty($_SESSION['backup_master_key_reveal'])) {
|
||||
$master_key_reveal = $_SESSION['backup_master_key_reveal'];
|
||||
unset($_SESSION['backup_master_key_reveal']);
|
||||
}
|
||||
|
||||
// The page reloads while a backup is on its way - but never out from under a key shown once
|
||||
$reload = $state === 'working' && $master_key_reveal === '';
|
||||
|
||||
// A time as "3 hours ago", with the date and time behind it
|
||||
$ago = function ($datetime) {
|
||||
return '<span title="' . escapeHtml($datetime) . '">' . escapeHtml(timeAgo($datetime)) . '</span>';
|
||||
};
|
||||
// Who a backup is down to, from its row
|
||||
$made_by = function ($backup) {
|
||||
if ($backup['backup_source'] === 'Cron') {
|
||||
return 'Scheduled';
|
||||
}
|
||||
if ($backup['backup_source'] === 'Adopted') {
|
||||
return 'Found on this server';
|
||||
}
|
||||
return (string) $backup['backup_created_by'] !== '' ? 'By ' . $backup['backup_created_by'] : 'By hand';
|
||||
};
|
||||
$schedule_text = $schedule_on ? "Every night at $schedule_time" : 'Off';
|
||||
// A type as it reads in a sentence - "a Full Backup", "a Database Only backup"
|
||||
$type_noun = function ($type) {
|
||||
return backupTypeLabel((string) $type) . ($type === BACKUP_TYPE_FULL ? '' : ($type === BACKUP_TYPE_MASTER_KEY ? ' export' : ' backup'));
|
||||
};
|
||||
|
||||
// The restore command, as this server runs it - the user that owns the files, in this folder
|
||||
$install_root = dirname(__DIR__);
|
||||
$file_owner = '';
|
||||
if (function_exists('posix_getpwuid')) {
|
||||
$file_owner = (string) (posix_getpwuid((int) @fileowner($install_root . '/scripts/restore_cli.php'))['name'] ?? '');
|
||||
}
|
||||
$shell_word = function ($word) {
|
||||
return preg_match('/^[A-Za-z0-9_\/.@%+=:,-]+$/', $word) ? $word : escapeshellarg($word);
|
||||
};
|
||||
$cli_command = "cd " . $shell_word($install_root) . "\n" . ($file_owner !== '' ? "sudo -u " . $shell_word($file_owner) . " " : '') . "php scripts/restore_cli.php \\\n --file=/path/to/backup.zip";
|
||||
|
||||
// The list - only these sort; an unknown column would take the page down
|
||||
$sortable_columns = [
|
||||
'backup_created_at' => "backup_created_at $order, backup_id $order",
|
||||
'backup_type' => "backup_type $order, backup_created_at DESC, backup_id DESC",
|
||||
'backup_size' => "backup_size $order, backup_created_at DESC, backup_id DESC",
|
||||
'backup_status' => "backup_status $order, backup_created_at DESC, backup_id DESC",
|
||||
];
|
||||
if (!isset($sortable_columns[$sort])) {
|
||||
$sort = 'backup_created_at';
|
||||
}
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS backup_id, backup_type, backup_file_name, backup_size, backup_sha256, backup_status, backup_error,
|
||||
backup_source, backup_created_by, backup_created_at, backup_downloaded_at
|
||||
FROM backups ORDER BY {$sortable_columns[$sort]} LIMIT $record_from, $record_to");
|
||||
|
||||
$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
|
||||
$sort_link = function ($column, $label) use ($url_query_strings_sort, $sort, $disp, $order_icon) {
|
||||
return '<a class="text-reset text-decoration-none" href="?' . escapeHtml($url_query_strings_sort) . '&sort=' . $column . '&order=' . $disp . '">'
|
||||
. $label . ($sort === $column ? " $order_icon" : '') . '</a>';
|
||||
};
|
||||
|
||||
$type_looks = [
|
||||
BACKUP_TYPE_FULL => ['icon' => 'fa-box-open', 'tone' => 'itflow-asset-tone-server'],
|
||||
BACKUP_TYPE_DATABASE => ['icon' => 'fa-database', 'tone' => 'itflow-asset-tone-network'],
|
||||
BACKUP_TYPE_MASTER_KEY => ['icon' => 'fa-key', 'tone' => 'itflow-asset-tone-phone'],
|
||||
];
|
||||
$status_looks = [
|
||||
'Complete' => ['label' => 'Complete', 'tone' => 'success'],
|
||||
'Pending' => ['label' => 'Queued', 'tone' => 'secondary'],
|
||||
'Running' => ['label' => 'Being made', 'tone' => 'primary'],
|
||||
'Failed' => ['label' => 'Failed', 'tone' => 'danger'],
|
||||
'Missing' => ['label' => 'Missing', 'tone' => 'warning'],
|
||||
];
|
||||
|
||||
?>
|
||||
<div class="alert alert-warning">
|
||||
<h5><i class="fas fa-fw fa-key me-2"></i>Master encryption key</h5>
|
||||
<p class="mb-2">Shown once. Refreshing this page will not show it again.</p>
|
||||
<input type="text" class="form-control font-monospace" value="<?= escapeHtml($master_key_reveal) ?>" readonly onclick="this.select();">
|
||||
|
||||
<?php if ($master_key_reveal !== '') { ?>
|
||||
<div class="alert alert-warning" data-backup-master-key>
|
||||
<h5 class="alert-heading"><i class="fas fa-fw fa-key me-2"></i>The credential vault's master key</h5>
|
||||
<p class="mb-2">Shown this once - it is gone when the page reloads. It opens every saved credential, so keep it the way you'd keep those.</p>
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control font-monospace" value="<?= escapeHtml($master_key_reveal) ?>" readonly aria-label="Master key">
|
||||
<button class="btn btn-dark clipboardjs" type="button" data-clipboard-text="<?= escapeHtml($master_key_reveal) ?>"><i class="far fa-fw fa-copy me-2"></i>Copy</button>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($backup_key === '') { ?>
|
||||
<div class="alert alert-danger">
|
||||
<h5><i class="fas fa-fw fa-exclamation-triangle me-2"></i>No backup encryption key</h5>
|
||||
ITFlow could not write a backup encryption key to <strong>config.php</strong>, so it cannot produce an encrypted backup.
|
||||
Make config.php writable by the web server user and reload this page, or add a line like
|
||||
<code>$config_backup_key = '<32 random characters>';</code> to it yourself.
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="row g-3">
|
||||
|
||||
<?php if (!$cron_is_running) { ?>
|
||||
<div class="alert alert-danger">
|
||||
<h5><i class="fas fa-fw fa-exclamation-triangle me-2"></i>Cron is not running</h5>
|
||||
Backups are built by the cron dispatcher, not by your browser. Until cron is running, anything you
|
||||
start here will sit in the queue. See <a href="cron.php">Maintenance > Cron</a>.
|
||||
</div>
|
||||
<?php } elseif ($config_enable_cron == 0) { ?>
|
||||
<div class="alert alert-warning">
|
||||
<i class="fas fa-fw fa-exclamation-circle me-2"></i>Cron is switched off in
|
||||
<a href="cron.php">Maintenance > Cron</a>.
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="col-lg-8">
|
||||
|
||||
<div class="card card-dark mb-3">
|
||||
<div class="card-header py-3">
|
||||
<h3 class="card-title"><i class="fas fa-fw fa-cloud-upload-alt me-2"></i>Create a Backup</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<!-- Where backups stand, and the buttons that take one -->
|
||||
<div class="card mb-3" data-backup-state="<?= $state ?>">
|
||||
<div class="card-body p-4"<?= $reload ? ' data-itflow-reload-seconds="10"' : '' ?>>
|
||||
<div class="d-flex align-items-start gap-3">
|
||||
<span class="itflow-asset-icon itflow-asset-icon-lg rounded-circle bg-<?= $hero['tone'] ?>-subtle text-<?= $hero['tone'] ?>-emphasis" aria-hidden="true"><i class="fas <?= $hero['icon'] ?>"></i></span>
|
||||
<div class="flex-grow-1 min-w-0">
|
||||
<h2 class="h4 mb-1"><?= escapeHtml($hero['title']) ?></h2>
|
||||
|
||||
<?php if ($pending_count > 0) { ?>
|
||||
<div class="alert alert-info">
|
||||
<i class="fas fa-fw fa-spinner me-2"></i><strong><?= $pending_count ?></strong> backup<?= $pending_count == 1 ? ' is' : 's are' ?>
|
||||
queued or building. You will get a notification when ready - this page does not refresh itself.
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php if ($state === 'nokey') { ?>
|
||||
<p class="mb-0 text-body-secondary">
|
||||
Every backup is encrypted, and ITFlow couldn't write an encryption key to <strong>config.php</strong>. Make config.php writable by the web server's user and reload this page, or add this line to it yourself:
|
||||
</p>
|
||||
<pre class="itflow-command bg-body-tertiary border rounded p-2 mt-2 mb-0 small"><code>$config_backup_key = '<?= escapeHtml(randomString(32)) ?>';</code></pre>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-4 mb-3">
|
||||
<div class="border rounded p-3 h-100 text-center">
|
||||
<i class="fas fa-fw fa-3x fa-box-open text-dark mb-3"></i>
|
||||
<h5>Full Backup</h5>
|
||||
<p class="text-muted small">The database and everything in the uploads folder. This is the one to keep.</p>
|
||||
<a class="btn btn-primary <?= $backup_key === '' ? 'disabled' : '' ?>" href="post.php?queue_backup=full&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-play me-2"></i>Start
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<div class="border rounded p-3 h-100 text-center">
|
||||
<i class="fas fa-fw fa-3x fa-database text-dark mb-3"></i>
|
||||
<h5>Database Only</h5>
|
||||
<p class="text-muted small">Just the SQL dump. Much smaller and much quicker, but no attachments or documents.</p>
|
||||
<a class="btn btn-primary <?= $backup_key === '' ? 'disabled' : '' ?>" href="post.php?queue_backup=database&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-play me-2"></i>Start
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 mb-3">
|
||||
<div class="border rounded p-3 h-100 text-center">
|
||||
<i class="fas fa-fw fa-3x fa-key text-dark mb-3"></i>
|
||||
<h5>Master Key</h5>
|
||||
<p class="text-muted small">The credential vault key. Only needed if every user password is lost - a normal restore recovers the vault on its own.</p>
|
||||
<button type="button" class="btn btn-secondary" data-bs-toggle="modal" data-bs-target="#masterKeyModal">
|
||||
<i class="fas fa-fw fa-key me-2"></i>Export
|
||||
</button>
|
||||
<?php } elseif ($state === 'working') { ?>
|
||||
<p class="mb-0 text-body-secondary">
|
||||
<?= $started ? 'Started' : 'Asked for' ?> <?= $ago($queue['since']) ?>. Cron builds <?= $queued === 1 ? 'it' : 'them' ?> in the background - a minute or two for most installs, longer with a lot uploaded.
|
||||
You can leave this page; you'll get a notification as each is ready.
|
||||
</p>
|
||||
|
||||
<?php } elseif ($state === 'stuck') { ?>
|
||||
<p class="mb-0 text-body-secondary">
|
||||
<?php if ($started) { ?>
|
||||
It started <?= $ago($queue['since']) ?> and never finished - the Backup job was stopped while it worked. Remove it in the list below and take another; <a href="cron.php">Maintenance > Cron</a> has what the job last said.
|
||||
<?php } elseif ($cron_is_running) { ?>
|
||||
Asked for <?= $ago($queue['since']) ?>, and the Backup job hasn't picked it up - <a href="cron.php">Maintenance > Cron</a> has what it last said. Cancel it in the list below and take another.
|
||||
<?php } else { ?>
|
||||
Asked for <?= $ago($queue['since']) ?>. It is made as soon as cron runs again.
|
||||
<?php } ?>
|
||||
</p>
|
||||
|
||||
<?php } elseif ($state === 'failed') { ?>
|
||||
<p class="mb-2 text-body-secondary">
|
||||
The <?= escapeHtml($type_noun($last_failed['backup_type'])) ?> started <?= $ago($last_failed['backup_created_at']) ?> stopped<?= (string) $last_failed['backup_error'] !== '' ? ':' : '.' ?>
|
||||
</p>
|
||||
<?php if ((string) $last_failed['backup_error'] !== '') { ?>
|
||||
<pre class="itflow-command bg-body-tertiary border rounded p-2 mb-2 small"><?= escapeHtml($last_failed['backup_error']) ?></pre>
|
||||
<?php } ?>
|
||||
<p class="mb-0 text-body-secondary">
|
||||
<?= $last_good ? 'The last one that worked was ' . $ago($last_good['backup_created_at']) . '.' : 'There is no backup that worked yet.' ?>
|
||||
Fix what stopped it and take another.
|
||||
</p>
|
||||
|
||||
<?php } elseif ($state === 'none') { ?>
|
||||
<p class="mb-0 text-body-secondary">
|
||||
Take a Full Backup now - the database and everything uploaded, in one encrypted file.
|
||||
<?= $schedule_on ? "After that, one is made every night at $schedule_time." : 'Then turn the schedule on below, and one is made every night.' ?>
|
||||
</p>
|
||||
|
||||
<?php } else { ?>
|
||||
<p class="mb-0 text-body-secondary">
|
||||
<?= escapeHtml(backupTypeLabel((string) $last_good['backup_type'])) ?>, <?= escapeHtml(backupFormatBytes($last_good['backup_size'])) ?> - <?= escapeHtml(lcfirst($made_by($last_good))) ?>.
|
||||
<?php if ($last_good['backup_type'] !== BACKUP_TYPE_FULL) { ?>
|
||||
<?= $last_full ? 'The last Full Backup, with everything uploaded, was ' . $ago($last_full['backup_created_at']) . '.' : "There's no Full Backup yet - attachments and documents aren't in a Database Only one." ?>
|
||||
<?php } ?>
|
||||
<?php if ($state === 'stale') { ?>
|
||||
<?= $schedule_on ? "One is due every night at $schedule_time, so something is stopping it." : 'The schedule is off, so the next one is whenever you take it.' ?>
|
||||
<?php } else { ?>
|
||||
<?= $schedule_on ? "The next scheduled one is at $schedule_time." : 'The schedule is off, so the next one is whenever you take it.' ?>
|
||||
<?php } ?>
|
||||
</p>
|
||||
<?php } ?>
|
||||
|
||||
<?php if (!in_array($state, ['nokey', 'working'], true)) { ?>
|
||||
<div class="d-flex flex-wrap gap-2 mt-3">
|
||||
<a class="btn btn-primary" href="post.php?queue_backup=full&csrf_token=<?= $csrf ?>" data-backup-now>
|
||||
<i class="fas fa-fw fa-box-open me-2"></i>Back up now
|
||||
</a>
|
||||
<a class="btn btn-outline-secondary" href="post.php?queue_backup=database&csrf_token=<?= $csrf ?>">
|
||||
<i class="fas fa-fw fa-database me-2"></i>Database only
|
||||
</a>
|
||||
</div>
|
||||
<p class="mb-0 mt-2 small text-body-secondary">
|
||||
<strong>Back up now</strong> makes a Full Backup: the database and every uploaded file. <strong>Database only</strong> is smaller and quicker, without attachments or documents.
|
||||
</p>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($state !== 'nokey' && !$cron_is_running) { ?>
|
||||
<div class="alert alert-warning mt-3 mb-0 small" data-backup-cron-warning>
|
||||
<i class="fas fa-fw fa-exclamation-circle me-1"></i>
|
||||
<?php if ($config_enable_cron !== 1) { ?>
|
||||
Cron is switched off, so no backup is made - scheduled or started here - until it's back on in <a href="cron.php" class="alert-link">Maintenance > Cron</a>.
|
||||
<?php } else { ?>
|
||||
Cron hasn't run in the last five minutes. Backups are built by cron, not by your browser, so one started here waits until it runs. Check <a href="cron.php" class="alert-link">Maintenance > Cron</a>.
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card card-dark mb-3">
|
||||
<div class="card-header py-3">
|
||||
<h3 class="card-title"><i class="fas fa-fw fa-archive me-2"></i>Backups</h3>
|
||||
</div>
|
||||
<div class="card-body p-0">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-borderless mb-0">
|
||||
<thead class="text-dark">
|
||||
<?php if ($num_rows[0] > 0) { // with none at all, the card above has said so ?>
|
||||
<!-- The backups on this server -->
|
||||
<div class="card mb-3">
|
||||
<div class="card-header py-3">
|
||||
<h3 class="card-title"><i class="fas fa-fw fa-archive me-2"></i>Backups</h3>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle mb-0" data-backup-list>
|
||||
<thead class="table-light text-nowrap">
|
||||
<tr>
|
||||
<th>Type</th>
|
||||
<th>Created</th>
|
||||
<th>Size</th>
|
||||
<th>Source</th>
|
||||
<th>Status</th>
|
||||
<th class="text-end">Action</th>
|
||||
<th class="ps-3"><?= $sort_link('backup_type', 'Backup') ?></th>
|
||||
<th class="d-none d-sm-table-cell"><?= $sort_link('backup_created_at', 'Made') ?></th>
|
||||
<th class="d-none d-sm-table-cell"><?= $sort_link('backup_size', 'Size') ?></th>
|
||||
<th><?= $sort_link('backup_status', 'Status') ?></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (mysqli_num_rows($backups) === 0) { ?>
|
||||
<tr><td colspan="6" class="text-center text-muted py-4">No backups yet.</td></tr>
|
||||
<?php } ?>
|
||||
<?php while ($backup = mysqli_fetch_assoc($backups)) {
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php while ($backup = mysqli_fetch_assoc($sql)) {
|
||||
$backup_id = intval($backup['backup_id']);
|
||||
$status = $backup['backup_status'];
|
||||
$type_label = backupTypeLabel((string) $backup['backup_type']);
|
||||
$type_as_noun = $type_noun($backup['backup_type']);
|
||||
$type_look = $type_looks[$backup['backup_type']] ?? ['icon' => 'fa-file-archive', 'tone' => 'itflow-asset-tone-other'];
|
||||
$status_look = $status_looks[$status] ?? ['label' => $status, 'tone' => 'secondary'];
|
||||
$made_at = substr((string) $backup['backup_created_at'], 0, 16);
|
||||
$backup_path = $status === 'Complete' ? backupResolvePath((string) $backup['backup_file_name']) : false;
|
||||
// A finished one is deleted, file and all; one still waiting is taken off the queue; the rest are only rows
|
||||
$remove = [
|
||||
'Complete' => ['Delete', 'Delete this backup?', "The $type_as_noun from $made_at is deleted from this server for good. A copy you've downloaded isn't touched."],
|
||||
'Pending' => ['Take off the queue', 'Take it off the queue?', "The $type_as_noun asked for at $made_at won't be made."],
|
||||
'Running' => ['Remove', 'Remove this backup?', "It's taken off this list, along with anything written so far."],
|
||||
][$status] ?? ['Remove', 'Remove it from the list?', "The $type_as_noun from $made_at is taken off this list. There is no file left to delete."];
|
||||
?>
|
||||
<tr data-backup-id="<?= $backup_id ?>" data-backup-status="<?= escapeHtml($status) ?>">
|
||||
<td class="ps-3">
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<span class="itflow-asset-icon <?= $type_look['tone'] ?> d-none d-sm-inline-flex" aria-hidden="true"><i class="fas <?= $type_look['icon'] ?>"></i></span>
|
||||
<div class="min-w-0">
|
||||
<div class="fw-semibold text-nowrap"><?= escapeHtml($type_label) ?></div>
|
||||
<div class="small text-body-secondary text-truncate"><?= escapeHtml($made_by($backup)) ?></div>
|
||||
<?php // On a phone the Made column goes, and its date sits here ?>
|
||||
<div class="small text-body-secondary text-nowrap d-sm-none"><?= escapeHtml($made_at) ?></div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="text-nowrap d-none d-sm-table-cell">
|
||||
<div><?= escapeHtml($made_at) ?></div>
|
||||
<div class="small text-body-secondary"><?= escapeHtml(timeAgo($backup['backup_created_at'])) ?></div>
|
||||
</td>
|
||||
<td class="d-none d-sm-table-cell text-nowrap"><?= $backup['backup_size'] > 0 ? escapeHtml(backupFormatBytes($backup['backup_size'])) : '<span class="text-body-secondary">—</span>' ?></td>
|
||||
<td>
|
||||
<span class="badge bg-<?= $status_look['tone'] ?>-subtle text-<?= $status_look['tone'] ?>-emphasis"><?php if ($status === 'Running') { ?><i class="fas fa-circle-notch fa-spin me-1"></i><?php } ?><?= escapeHtml($status_look['label']) ?></span>
|
||||
<?php if ($status === 'Failed' && (string) $backup['backup_error'] !== '') { ?>
|
||||
<div class="small text-danger-emphasis mt-1"><?= escapeHtml($backup['backup_error']) ?></div>
|
||||
<?php } elseif ($status === 'Missing') { ?>
|
||||
<div class="small text-body-secondary mt-1">Its file is no longer on this server</div>
|
||||
<?php } elseif ($status === 'Complete' && !empty($backup['backup_downloaded_at'])) { ?>
|
||||
<div class="small text-body-secondary mt-1" title="<?= escapeHtml($backup['backup_downloaded_at']) ?>"><i class="fas fa-fw fa-download me-1"></i>Downloaded <?= escapeHtml(timeAgo($backup['backup_downloaded_at'])) ?></div>
|
||||
<?php } ?>
|
||||
</td>
|
||||
<td class="text-end text-nowrap pe-3">
|
||||
<?php if ($status === 'Complete') { ?>
|
||||
<a class="btn btn-sm btn-light" href="backup_download.php?backup_id=<?= $backup_id ?>&csrf_token=<?= $csrf ?>" title="Download this backup">
|
||||
<i class="fas fa-fw fa-download"></i><span class="d-none d-md-inline ms-1">Download</span>
|
||||
</a>
|
||||
<?php } ?>
|
||||
<div class="dropdown dropstart d-inline-block">
|
||||
<button class="btn btn-sm btn-light" title="More actions" type="button" data-bs-toggle="dropdown"><i class="fas fa-fw fa-ellipsis-v"></i></button>
|
||||
<div class="dropdown-menu">
|
||||
<?php if ($backup_path !== false) { ?>
|
||||
<button type="button" class="dropdown-item clipboardjs" data-clipboard-text="<?= escapeHtml($backup_path) ?>" title="For restoring it from the command line"><i class="fas fa-fw fa-terminal text-secondary me-2"></i>Copy its path on this server</button>
|
||||
<?php } ?>
|
||||
<?php if ($status === 'Complete' && (string) $backup['backup_sha256'] !== '') { ?>
|
||||
<button type="button" class="dropdown-item clipboardjs" data-clipboard-text="<?= escapeHtml($backup['backup_sha256']) ?>" title="To check a copy is the same file"><i class="fas fa-fw fa-fingerprint text-secondary me-2"></i>Copy its SHA-256 checksum</button>
|
||||
<?php } ?>
|
||||
<?php if ($status === 'Complete') { ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<?php } ?>
|
||||
<a class="dropdown-item text-danger confirm-link" href="post.php?delete_backup=<?= $backup_id ?>&csrf_token=<?= $csrf ?>"
|
||||
data-confirm-title="<?= escapeHtml($remove[1]) ?>" data-confirm-text="<?= escapeHtml($remove[2]) ?>" data-confirm-button="<?= $status === 'Pending' ? 'Take it off' : $remove[0] ?>">
|
||||
<i class="fas fa-fw fa-<?= $status === 'Pending' ? 'ban' : 'trash' ?> me-2"></i><?= $remove[0] ?>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php require_once "../includes/filter_footer.php"; ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
$backup_id = intval($backup['backup_id']);
|
||||
$status = $backup['backup_status'];
|
||||
|
||||
$badge = 'secondary';
|
||||
if ($status === 'Complete') { $badge = 'success'; }
|
||||
if ($status === 'Failed') { $badge = 'danger'; }
|
||||
if ($status === 'Missing') { $badge = 'warning'; }
|
||||
if ($status === 'Running' || $status === 'Pending') { $badge = 'info'; }
|
||||
?>
|
||||
<tr>
|
||||
<td><?= escapeHtml(backupTypeLabel($backup['backup_type'])) ?></td>
|
||||
<td><?= escapeHtml($backup['backup_created_at']) ?></td>
|
||||
<td><?= $backup['backup_size'] > 0 ? escapeHtml(backupFormatBytes($backup['backup_size'])) : '-' ?></td>
|
||||
<td><?= escapeHtml($backup['backup_source']) ?></td>
|
||||
<td>
|
||||
<span class="badge text-bg-<?= $badge ?>"><?= escapeHtml($status) ?></span>
|
||||
<?php if (!empty($backup['backup_error'])) { ?>
|
||||
<br><small class="text-danger"><?= escapeHtml($backup['backup_error']) ?></small>
|
||||
<?php } ?>
|
||||
</td>
|
||||
<td class="text-end">
|
||||
<?php if ($status === 'Complete') { ?>
|
||||
<a class="btn btn-sm btn-primary" title="Download backup" href="backup_download.php?backup_id=<?= $backup_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-download"></i>
|
||||
<!-- The schedule, and how long backups are kept -->
|
||||
<div class="card mb-3">
|
||||
<div class="card-header py-3">
|
||||
<h3 class="card-title"><i class="fas fa-fw fa-clock me-2"></i>Schedule and retention</h3>
|
||||
</div>
|
||||
<div class="list-group list-group-flush border-bottom">
|
||||
<div class="list-group-item d-flex flex-wrap flex-md-nowrap align-items-center gap-3 py-3<?= $schedule_on ? '' : ' bg-warning-subtle' ?>" data-backup-schedule="<?= $schedule_on ? 'on' : 'off' ?>">
|
||||
<i class="fas fa-fw fa-<?= $schedule_on ? 'check-circle text-success' : 'pause-circle text-warning-emphasis' ?>" aria-hidden="true"></i>
|
||||
<div class="flex-grow-1 min-w-0">
|
||||
<?php if ($schedule_on) { ?>
|
||||
<div class="fw-semibold">A <?= escapeHtml($type_noun($config_backup_cron_type)) ?> is made every night at <?= escapeHtml($schedule_time) ?></div>
|
||||
<div class="small text-body-secondary">It's the Backup job in <a href="cron.php">Maintenance > Cron</a>.</div>
|
||||
<?php } else { ?>
|
||||
<div class="fw-semibold">Scheduled backups are off</div>
|
||||
<div class="small text-body-secondary">Backups are only made when someone starts one here. Turn the schedule on and one is made every night<?= $schedule_time !== '' ? " at $schedule_time" : '' ?>.</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php if ($backup_job_id) { ?>
|
||||
<?php // The Backup job's own switch and time (admin/post/cron.php) - both come back to this page ?>
|
||||
<div class="d-flex gap-2 flex-shrink-0">
|
||||
<?php if (!$schedule_on) { ?>
|
||||
<a class="btn btn-sm btn-primary" href="post.php?enable_cron_job=<?= $backup_job_id ?>&csrf_token=<?= $csrf ?>" data-backup-schedule-on>
|
||||
<i class="fas fa-fw fa-power-off me-1"></i>Turn on
|
||||
</a>
|
||||
<?php } ?>
|
||||
<a class="btn btn-sm btn-danger confirm-link" title="Delete backup" href="post.php?delete_backup=<?= $backup_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-trash"></i>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<button type="button" class="btn btn-sm btn-light border ajax-modal" data-modal-url="modals/cron/cron_edit.php?id=<?= $backup_job_id ?>" data-backup-schedule-edit>
|
||||
<i class="fas fa-fw fa-clock me-1"></i>Change the time
|
||||
</button>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $csrf ?>">
|
||||
|
||||
<div class="row g-3">
|
||||
<div class="col-md-4">
|
||||
<label class="form-label" for="backupCronType">The scheduled backup is a</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-box-open"></i></span>
|
||||
<select class="form-select" name="config_backup_cron_type" id="backupCronType">
|
||||
<?php foreach (backupUnattendedTypes() as $type) { ?>
|
||||
<option value="<?= $type ?>" <?= $config_backup_cron_type === $type ? 'selected' : '' ?>><?= escapeHtml(backupTypeLabel($type)) ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-text">Database Only leaves out attachments and documents.</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label" for="backupRetentionDays">Keep backups for</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-calendar-alt"></i></span>
|
||||
<input type="number" class="form-control" name="config_backup_retention_days" id="backupRetentionDays" min="0" max="36500" value="<?= $config_backup_retention_days ?>">
|
||||
<span class="input-group-text">days</span>
|
||||
</div>
|
||||
<div class="form-text">0 keeps them whatever their age.</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<label class="form-label" for="backupRetentionCount">Keep at most</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-layer-group"></i></span>
|
||||
<input type="number" class="form-control" name="config_backup_retention_count" id="backupRetentionCount" min="1" max="100000" value="<?= $config_backup_retention_count ?>">
|
||||
<span class="input-group-text">of each type</span>
|
||||
</div>
|
||||
<div class="form-text">The newest of each type is never removed.</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex flex-wrap align-items-center gap-3 mt-3">
|
||||
<button type="submit" name="edit_backup_settings" class="btn btn-primary"><i class="fas fa-fw fa-check me-2"></i>Save</button>
|
||||
<span class="small text-body-secondary">Older backups are removed by the nightly job, not by a backup itself - so one that fails never costs you the one before it.</span>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col-lg-4">
|
||||
|
||||
<!-- Where backups stand, at a glance -->
|
||||
<div class="card mb-3">
|
||||
<div class="card-header py-3">
|
||||
<h3 class="card-title"><i class="fas fa-fw fa-shield-alt me-2"></i>At a glance</h3>
|
||||
</div>
|
||||
<ul class="list-group list-group-flush small" data-backup-glance>
|
||||
<li class="list-group-item d-flex justify-content-between gap-3">
|
||||
<span class="text-body-secondary">Last Full Backup</span>
|
||||
<span class="text-end fw-semibold"><?= $last_full ? $ago($last_full['backup_created_at']) : '<span class="text-warning-emphasis">None yet</span>' ?></span>
|
||||
</li>
|
||||
<?php if ($latest[BACKUP_TYPE_DATABASE]) { ?>
|
||||
<li class="list-group-item d-flex justify-content-between gap-3">
|
||||
<span class="text-body-secondary">Last Database Only</span>
|
||||
<span class="text-end fw-semibold"><?= $ago($latest[BACKUP_TYPE_DATABASE]['backup_created_at']) ?></span>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card card-dark mb-3">
|
||||
<div class="card-header py-3">
|
||||
<h3 class="card-title"><i class="fas fa-fw fa-lock me-2"></i>Encryption Key</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="alert alert-warning mb-3">
|
||||
<i class="fas fa-fw fa-exclamation-triangle me-2"></i>
|
||||
<strong>Write this down and keep it somewhere other than this server.</strong>
|
||||
Every backup is encrypted with it, and without it a backup cannot be restored - not by you,
|
||||
not by anyone. It is stored in config.php and never in the database, which is what stops a
|
||||
stolen backup from carrying its own key.
|
||||
<li class="list-group-item d-flex justify-content-between gap-3">
|
||||
<span class="text-body-secondary">Schedule</span>
|
||||
<span class="text-end">
|
||||
<span class="fw-semibold<?= $schedule_on ? '' : ' text-warning-emphasis' ?>"><?= escapeHtml($schedule_text) ?></span>
|
||||
<?php if ($schedule_on) { ?><span class="d-block text-body-secondary"><?= escapeHtml(backupTypeLabel($config_backup_cron_type)) ?></span><?php } ?>
|
||||
</span>
|
||||
</li>
|
||||
<li class="list-group-item d-flex justify-content-between gap-3">
|
||||
<span class="text-body-secondary">Kept</span>
|
||||
<span class="text-end fw-semibold"><?= $config_backup_retention_days > 0 ? $config_backup_retention_days . ' day' . ($config_backup_retention_days === 1 ? '' : 's') . ', ' : '' ?><?= $config_backup_retention_count ?> of each type</span>
|
||||
</li>
|
||||
<li class="list-group-item d-flex justify-content-between gap-3">
|
||||
<span class="text-body-secondary">On this server</span>
|
||||
<span class="text-end fw-semibold"><?= intval($kept['backups']) ?> backup<?= intval($kept['backups']) === 1 ? '' : 's' ?><?= intval($kept['backups']) > 0 ? ', ' . escapeHtml(backupFormatBytes($kept['bytes'])) : '' ?></span>
|
||||
</li>
|
||||
<?php if ($free_bytes !== false && $free_bytes !== null) { ?>
|
||||
<li class="list-group-item d-flex justify-content-between gap-3">
|
||||
<span class="text-body-secondary">Free space</span>
|
||||
<?php // Room for the next one - less than twice the last full backup is cutting it fine ?>
|
||||
<span class="text-end fw-semibold<?= $last_full && $free_bytes < 2 * $last_full['backup_size'] ? ' text-danger-emphasis' : '' ?>"><?= escapeHtml(backupFormatBytes($free_bytes)) ?></span>
|
||||
</li>
|
||||
<?php } ?>
|
||||
<li class="list-group-item d-flex justify-content-between gap-3">
|
||||
<span class="text-body-secondary">Cron</span>
|
||||
<a href="cron.php" class="<?= $cron_is_running ? 'text-success-emphasis' : 'text-danger-emphasis' ?>">
|
||||
<i class="fas fa-fw fa-<?= $cron_is_running ? 'check-circle' : 'times-circle' ?> me-1"></i><?= $cron_is_running ? 'Running' : ($config_enable_cron !== 1 ? 'Switched off' : 'Not running') ?>
|
||||
</a>
|
||||
</li>
|
||||
<li class="list-group-item">
|
||||
<div class="text-body-secondary">Kept in</div>
|
||||
<code class="text-break text-body" data-backup-folder><?= escapeHtml($backup_dir) ?></code>
|
||||
<?php if (empty($config_backup_path)) { ?>
|
||||
<div class="text-body-secondary mt-1">Inside ITFlow's own folder. <code>$config_backup_path</code> in config.php keeps them somewhere else - another disk, or a mounted share.</div>
|
||||
<?php } ?>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<?php if ($backup_key !== '') { ?>
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control font-monospace" value="<?= escapeHtml($backup_key) ?>" readonly onclick="this.select();">
|
||||
<button class="btn btn-secondary clipboardjs" title="Copy backup key" type="button" data-clipboard-text="<?= escapeHtml($backup_key) ?>">
|
||||
<i class="far fa-fw fa-copy"></i>
|
||||
</button>
|
||||
<!-- The key every backup is encrypted with -->
|
||||
<div class="card mb-3">
|
||||
<div class="card-header py-3">
|
||||
<h3 class="card-title"><i class="fas fa-fw fa-lock me-2"></i>Encryption key</h3>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<p class="text-muted small mt-3 mb-0">
|
||||
Archives are AES-256 encrypted zips. <strong>7-Zip, WinZip, PeaZip and Keka</strong> can open them with this key.
|
||||
The <code>unzip</code> command, Windows Explorer and the macOS Archive Utility cannot - they do not support AES.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card card-dark mb-3">
|
||||
<div class="card-header py-3">
|
||||
<h3 class="card-title"><i class="fas fa-fw fa-clock me-2"></i>Scheduled Backups & Retention</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="post.php" method="POST" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
|
||||
<div class="row g-2">
|
||||
<div class="mb-3 col-md-4">
|
||||
<label>Scheduled backup type</label>
|
||||
<select class="form-select" name="config_backup_cron_type">
|
||||
<option <?= $config_backup_cron_type === 'full' ? 'selected' : '' ?> value="full">Full Backup</option>
|
||||
<option <?= $config_backup_cron_type === 'database' ? 'selected' : '' ?> value="database">Database Only</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3 col-md-4">
|
||||
<label>Keep backups for (days)</label>
|
||||
<input type="number" class="form-control" name="config_backup_retention_days" min="0" value="<?= intval($config_backup_retention_days) ?>">
|
||||
<small class="text-muted">0 disables age-based deletion.</small>
|
||||
</div>
|
||||
<div class="mb-3 col-md-4">
|
||||
<label>Keep at most (per type)</label>
|
||||
<input type="number" class="form-control" name="config_backup_retention_count" min="1" value="<?= intval($config_backup_retention_count) ?>">
|
||||
<small class="text-muted">Counted separately for each type. The newest of each is never deleted.</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" name="edit_backup_settings" class="btn btn-primary"><i class="fas fa-fw fa-check me-2"></i>Save</button>
|
||||
</form>
|
||||
|
||||
<hr>
|
||||
|
||||
<p class="mb-0">
|
||||
<?php if (!empty($backup_job) && intval($backup_job['cron_job_enabled']) === 1) { ?>
|
||||
<i class="fas fa-fw fa-check text-success me-2"></i>Scheduled backups run daily at
|
||||
<strong><?= escapeHtml(substr((string)$backup_job['cron_job_daily_at'], 0, 5)) ?></strong>.
|
||||
<?php } else { ?>
|
||||
<i class="fas fa-fw fa-times text-danger me-2"></i>Scheduled backups are switched off.
|
||||
<?php } ?>
|
||||
Turn them on or change the time in <a href="cron.php">Maintenance > Cron</a>.
|
||||
</p>
|
||||
<p class="text-muted small mt-2 mb-0">
|
||||
Old backups are removed by the nightly job, never by the backup itself, so a failed nightly
|
||||
cannot delete an archive that was never replaced.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card card-dark">
|
||||
<div class="card-header py-3">
|
||||
<h3 class="card-title"><i class="fas fa-fw fa-undo me-2"></i>Restoring</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p>Restoring replaces the database and the uploads folder with what is in the archive. It cannot be done from here, on purpose - a running install is the wrong place to be dropping its own tables from a browser.</p>
|
||||
<p class="mb-2"><strong>From the command line</strong> - the only option that works for large backups:</p>
|
||||
<pre class="bg-dark text-white p-2"><?= escapeHtml("php " . dirname(__DIR__) . "/scripts/restore_cli.php --file=/path/to/backup.zip") ?></pre>
|
||||
<p class="mb-0"><strong>From a browser</strong>, on a fresh install only, the setup wizard has a restore step at <code>/setup</code>. Once an install has users, that step closes itself.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal" id="masterKeyModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><i class="fas fa-fw fa-key me-2"></i>Export Master Key</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="POST" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<div class="modal-body">
|
||||
<div class="alert alert-warning">
|
||||
This key decrypts every credential in this install. It is shown on screen and is not written anywhere.
|
||||
<div class="card-body small">
|
||||
<p class="text-body-secondary">Every backup is encrypted with this key, and can't be opened or restored without it - not by you, not by anyone. <strong class="text-body">Keep a copy somewhere other than this server.</strong></p>
|
||||
<?php if ($backup_key !== '') { ?>
|
||||
<div class="input-group mb-2">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-key"></i></span>
|
||||
<input type="password" class="form-control font-monospace" data-toggle="password" value="<?= escapeHtml($backup_key) ?>" readonly autocomplete="off" aria-label="Backup encryption key" data-backup-key>
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-eye"></i></span>
|
||||
<button class="btn btn-light border clipboardjs" type="button" title="Copy the key" data-clipboard-text="<?= escapeHtml($backup_key) ?>"><i class="far fa-fw fa-copy"></i></button>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label>Confirm your account password</label>
|
||||
<input type="password" class="form-control" name="password" autocomplete="new-password" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="backup_master_key" class="btn btn-primary"><i class="fas fa-fw fa-key me-2"></i>Show Master Key</button>
|
||||
</div>
|
||||
</form>
|
||||
<?php } else { ?>
|
||||
<p class="text-danger-emphasis mb-2"><i class="fas fa-fw fa-exclamation-triangle me-1"></i>There isn't one yet - config.php couldn't be written.</p>
|
||||
<?php } ?>
|
||||
<p class="text-body-secondary mb-0">It is kept in config.php and never in the database, so a backup that gets out doesn't carry its own key.</p>
|
||||
<details class="mt-2">
|
||||
<summary class="text-body-secondary">Opening a backup by hand</summary>
|
||||
<p class="text-body-secondary mt-2 mb-0">A backup is an AES-256 encrypted zip. <strong>7-Zip, WinZip, PeaZip and Keka</strong> open it with this key. The <code>unzip</code> command, Windows Explorer and the macOS Archive Utility can't - they don't do AES.</p>
|
||||
</details>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Restoring - not from here -->
|
||||
<div class="card mb-3">
|
||||
<div class="card-header py-3">
|
||||
<h3 class="card-title"><i class="fas fa-fw fa-undo me-2"></i>Restoring</h3>
|
||||
</div>
|
||||
<div class="card-body small">
|
||||
<p class="text-body-secondary">Restoring replaces the database - and, from a Full Backup, everything uploaded - with what's in the backup. It isn't done from this page, on purpose: a running ITFlow shouldn't drop its own tables from a browser.</p>
|
||||
<p class="fw-semibold mb-1">From the command line</p>
|
||||
<div class="position-relative">
|
||||
<pre class="itflow-command bg-body-tertiary border rounded p-2 pe-5 mb-2"><code><?= escapeHtml($cli_command) ?></code></pre>
|
||||
<button type="button" class="btn btn-sm btn-link position-absolute top-0 end-0 clipboardjs" title="Copy" data-clipboard-text="<?= escapeHtml($cli_command) ?>"><i class="far fa-copy"></i></button>
|
||||
</div>
|
||||
<p class="text-body-secondary">Works for a backup of any size. Add <code>--inspect</code> to see what's in one without changing anything, and <code>--key=</code> for a backup from another server, which needs that server's key. A backup's menu copies its path.</p>
|
||||
<p class="fw-semibold mb-1">On a new server</p>
|
||||
<p class="text-body-secondary mb-0">The setup wizard at <code>/setup</code> offers to restore a backup before the first user exists - up to <?= escapeHtml(backupFormatBytes(backupMaxUploadBytes())) ?> here, the most PHP takes in one upload.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- The credential vault's own key - not part of a backup, and rarely needed -->
|
||||
<div class="card mb-3">
|
||||
<div class="card-header py-3">
|
||||
<h3 class="card-title"><i class="fas fa-fw fa-key me-2"></i>Credential vault key</h3>
|
||||
</div>
|
||||
<div class="card-body small">
|
||||
<p class="text-body-secondary">The master key that opens every saved credential. A restore brings the vault back by itself, as long as one user still knows their password - this is for when none does.</p>
|
||||
<button type="button" class="btn btn-sm btn-light border ajax-modal" data-modal-url="modals/backup/backup_master_key.php" data-backup-master-key-export>
|
||||
<i class="fas fa-fw fa-key me-2"></i>Export the master key
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="<?= staticFileUrl('/js/auto_reload.js') ?>"></script>
|
||||
|
||||
<?php
|
||||
require_once "../includes/footer.php";
|
||||
|
||||
45
admin/modals/backup/backup_master_key.php
Normal file
45
admin/modals/backup/backup_master_key.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Maintenance > Backup - export the credential vault's master key. It only exists unwrapped
|
||||
* inside a session, so the admin's own password is asked for again and is what unwraps it
|
||||
* (admin/post/backup.php, backup_master_key). The key is shown once on the page that
|
||||
* follows, and an encrypted copy is filed with the backups.
|
||||
*/
|
||||
|
||||
require_once '../../includes/modal_header.php';
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fas fa-fw fa-key me-2"></i>Export the master key</h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
|
||||
<div class="modal-body">
|
||||
<p class="fw-semibold mb-2">This key opens every credential saved in ITFlow.</p>
|
||||
<ul class="small mb-3 ps-3">
|
||||
<li>It is shown once, on the next page - copy it somewhere as safe as the credentials themselves.</li>
|
||||
<li>An encrypted copy is filed with the backups, opened with the backup encryption key.</li>
|
||||
<li>You only need it if every user's password is lost. A restored backup brings the vault back by itself.</li>
|
||||
<li>Exporting it is logged, and every agent gets a notification that you did.</li>
|
||||
</ul>
|
||||
|
||||
<label class="form-label" for="backupMasterKeyPassword">Your password <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-lock"></i></span>
|
||||
<input type="password" class="form-control" data-toggle="password" name="password" id="backupMasterKeyPassword" placeholder="To confirm it's you" autocomplete="current-password" required autofocus>
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-eye"></i></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="backup_master_key" class="btn btn-primary text-bold"><i class="fas fa-fw fa-key me-2"></i>Show the master key</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fas fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
require_once "../../../includes/modal_footer.php";
|
||||
@@ -43,13 +43,20 @@ if (isset($_GET['delete_backup'])) {
|
||||
|
||||
$backup_id = intval($_GET['delete_backup']);
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT backup_file_name, backup_type FROM backups WHERE backup_id = $backup_id");
|
||||
$sql = mysqli_query($mysqli, "SELECT backup_file_name, backup_type, backup_status FROM backups WHERE backup_id = $backup_id");
|
||||
|
||||
if (mysqli_num_rows($sql) === 1) {
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
backupDeleteById($mysqli, $backup_id);
|
||||
logAudit("Backup", "Delete", ($session_name ?? 'Unknown User') . " deleted backup " . escapeSql($row['backup_file_name']));
|
||||
flashAlert("Backup deleted.");
|
||||
|
||||
// One still waiting has no file yet - taking it off the queue is all there is to it
|
||||
if ($row['backup_status'] === 'Pending') {
|
||||
logAudit("Backup", "Delete", ($session_name ?? 'Unknown User') . " took a queued " . backupTypeLabel($row['backup_type']) . " off the queue");
|
||||
flashAlert(backupTypeLabel($row['backup_type']) . " taken off the queue.");
|
||||
} else {
|
||||
logAudit("Backup", "Delete", ($session_name ?? 'Unknown User') . " deleted backup " . escapeSql($row['backup_file_name']));
|
||||
flashAlert($row['backup_status'] === 'Complete' ? "Backup deleted." : "Backup removed from the list.");
|
||||
}
|
||||
} else {
|
||||
flashAlert("Backup not found.", 'error');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user