68 lines
5.5 KiB
PHP
68 lines
5.5 KiB
PHP
<?php
|
|
include 'auth.php';
|
|
$page_title = 'Quarantine - BastionGuard WebUI';
|
|
$active_page = 'quarantine.php';
|
|
|
|
$defaultQdir = '/var/lib/bastionguard-webui/quarantine';
|
|
$cfg = bg_read_json('quarantine.json', ['dir'=>$defaultQdir,'restore_dir'=>'/tmp/bastionguard-restore']);
|
|
// The privileged helper uses the shared quarantine directory. Keeping it fixed avoids
|
|
// PHP permission problems and makes restore/delete work even when files are owned by root.
|
|
$qdir = $defaultQdir;
|
|
$restoreDir = trim((string)($cfg['restore_dir'] ?? '/tmp/bastionguard-restore')) ?: '/tmp/bastionguard-restore';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
csrf_validate();
|
|
$action = $_POST['action'] ?? '';
|
|
if ($action === 'save-dir') {
|
|
$cfg['dir'] = $defaultQdir;
|
|
$cfg['restore_dir'] = trim($_POST['restore_dir'] ?? $restoreDir) ?: $restoreDir;
|
|
bg_write_json('quarantine.json', $cfg);
|
|
bg_flash('success', bg_language()==='en' ? 'Quarantine options saved.' : 'Opzioni quarantena salvate.');
|
|
bg_redirect('quarantine.php');
|
|
}
|
|
|
|
$file = basename((string)($_POST['file'] ?? ''));
|
|
if ($file === '' || $file === '.' || $file === '..') {
|
|
bg_flash('danger', bg_language()==='en' ? 'Invalid quarantine item.' : 'Elemento quarantena non valido.');
|
|
bg_redirect('quarantine.php');
|
|
}
|
|
|
|
if ($action === 'delete') {
|
|
$res = bg_quarantine_delete_item($file);
|
|
bg_flash(($res['code'] ?? 1) === 0 ? 'success' : 'danger', trim((string)($res['output'] ?? '')) ?: (($res['code'] ?? 1) === 0 ? 'Deleted.' : 'Deletion failed.'));
|
|
bg_redirect('quarantine.php');
|
|
}
|
|
|
|
if ($action === 'restore') {
|
|
$res = bg_quarantine_restore_item($file, $restoreDir);
|
|
bg_flash(($res['code'] ?? 1) === 0 ? 'success' : 'danger', trim((string)($res['output'] ?? '')) ?: (($res['code'] ?? 1) === 0 ? 'Restored.' : 'Restore failed.'));
|
|
bg_redirect('quarantine.php');
|
|
}
|
|
|
|
bg_redirect('quarantine.php');
|
|
}
|
|
|
|
$files = [];
|
|
if (is_dir($qdir)) {
|
|
foreach (scandir($qdir) ?: [] as $f) {
|
|
if ($f === '.' || $f === '..' || $f === '.metadata') continue;
|
|
$p = $qdir . '/' . $f;
|
|
if (!is_file($p)) continue;
|
|
$meta = bg_quarantine_metadata($qdir, $f);
|
|
$files[] = [
|
|
'name'=>$f,
|
|
'size'=>@filesize($p) ?: 0,
|
|
'mtime'=>@filemtime($p) ?: 0,
|
|
'original_path'=>(string)($meta['original_path'] ?? ''),
|
|
'quarantined_at'=>(string)($meta['quarantined_at'] ?? ''),
|
|
];
|
|
}
|
|
usort($files, function($a,$b){ return ($b['mtime'] <=> $a['mtime']); });
|
|
}
|
|
include 'includes/header.php'; include 'includes/sidebar.php';
|
|
$lang = bg_language();
|
|
?>
|
|
<div class="page-title"><div><h1><?= $lang==='en'?'Quarantine':'Quarantena' ?></h1><p><?= $lang==='en'?'Safe management of isolated files. Restore and deletion are executed through the privileged WebPanel helper, so they work even when files are owned by root.':'Gestione sicura dei file isolati. Ripristino ed eliminazione passano dall\'helper privilegiato WebPanel, quindi funzionano anche con file di proprietà root.' ?></p></div></div>
|
|
<div class="card mb-4"><div class="card-body"><form method="post" class="row g-2 align-items-end"><?php csrf_field(); ?><input type="hidden" name="action" value="save-dir"><div class="col-md-6"><label class="form-label"><?= $lang==='en'?'Quarantine folder':'Cartella quarantena' ?></label><input class="form-control" value="<?= bg_e($qdir) ?>" readonly><div class="form-text"><?= $lang==='en'?'Managed by /usr/local/sbin/bastionguard-webui-admin.':'Gestita da /usr/local/sbin/bastionguard-webui-admin.' ?></div></div><div class="col-md-4"><label class="form-label"><?= $lang==='en'?'Fallback restore folder':'Cartella ripristino fallback' ?></label><input class="form-control" name="restore_dir" value="<?= bg_e($restoreDir) ?>"><div class="form-text"><?= $lang==='en'?'Used only when the original path is unknown.':'Usata solo quando il percorso originale non è noto.' ?></div></div><div class="col-md-2"><button class="btn btn-outline-primary w-100"><?= bg_e(bg_t('save')) ?></button></div></form></div></div>
|
|
<div class="card"><div class="card-body"><h5><?= $lang==='en'?'Isolated files':'File isolati' ?></h5><?php if($files): ?><div class="table-responsive"><table class="table"><thead><tr><th><?= $lang==='en'?'Name':'Nome' ?></th><th><?= $lang==='en'?'Original path':'Percorso originale' ?></th><th><?= bg_e(bg_t('size')) ?></th><th><?= bg_e(bg_t('modified')) ?></th><th><?= bg_e(bg_t('actions')) ?></th></tr></thead><tbody><?php foreach($files as $f): ?><tr><td><strong><?= bg_e($f['name']) ?></strong></td><td><?= $f['original_path']!=='' ? '<code>'.bg_e($f['original_path']).'</code>' : '<span class="text-muted">'.($lang==='en'?'unknown':'sconosciuto').'</span>' ?></td><td><?= bg_e(bg_file_size($f['size'])) ?></td><td><?= $f['mtime'] ? bg_e(date('Y-m-d H:i:s',$f['mtime'])) : '-' ?></td><td><form method="post" class="d-inline"><?php csrf_field(); ?><input type="hidden" name="file" value="<?= bg_e($f['name']) ?>"><button class="btn btn-sm btn-success" name="action" value="restore"><?= $lang==='en'?'Restore':'Ripristina' ?></button> <button class="btn btn-sm btn-danger" name="action" value="delete" data-confirm="<?= $lang==='en'?'Permanently delete this file?':'Eliminare definitivamente questo file?' ?>"><?= bg_e(bg_t('delete')) ?></button></form></td></tr><?php endforeach; ?></tbody></table></div><?php else: ?><p class="text-muted"><?= $lang==='en'?'No files in quarantine.':'Nessun file in quarantena.' ?></p><?php endif; ?></div></div>
|
|
<?php include 'includes/footer.php'; ?>
|