Admin, ru.php fr.php

This commit is contained in:
Oleg Barykin committed 2026-03-05 11:12:24 +01:00
1 parent d81efe93b1
commit 1deb30fcd1
3 files changed
+39 -17

No files matched your search

+37 -17
View File
@@ -1,17 +1,39 @@
<?php
declare (strict_types = 1);
/**
* clean_uploads.php
* Compatible:
* - accès direct /admin/tools/clean_uploads.php
* - inclusion via /admin/index.php?page=clean_uploads
* Outil admin destructif : suppression des fichiers orphelins dans /public/uploads
*/
// Si APP_HTDOCS n'existe pas, c'est qu'on n'est pas passé par le bootstrap admin
if (! defined('APP_HTDOCS')) {
require_once __DIR__ . '/../../public/includes/init_admin.php';
require_once __DIR__ . '/../../public/includes/init_admin.php'; // ✅ impose admin + strict super-admin + CSRF
// Anti-cache (évite de conserver un token / résultat en cache)
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Pragma: no-cache');
// Reauth (10 min) avant action destructive
$mustReauth = static function (int $ttl = 600): bool {
$t = (int) ($_SESSION['admin_reauth_at'] ?? 0);
return ($t === 0 || (time() - $t) > $ttl);
};
if ($mustReauth()) {
$qs = http_build_query([
'page' => 'reauth',
'redir' => ($_SERVER['REQUEST_URI'] ?? 'index.php?page=clean_uploads'),
]);
header('Location: ?' . $qs);
exit;
}
// Durcir PDO
if (! isset($pdo) || ! ($pdo instanceof PDO)) {
http_response_code(500);
exit('PDO introuvable (DB non initialisée).');
}
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
// Dossier uploads (chez toi: htdocs/public/uploads/)
$uploadDir = rtrim(APP_HTDOCS, '/\\') . '/public/uploads/';
if (! is_dir($uploadDir)) {
@@ -74,20 +96,19 @@
foreach ($files as $f) {
if ($f === '.' || $f === '..') {
continue;
if ($f[0] === '.') {
continue;
}
}
// ignore fichiers système fréquents
if ($f === '.DS_Store' || $f === 'Thumbs.db' || $f === '.htaccess') {
if ($f !== '' && $f[0] === '.') {
continue;
}
// ignore fichiers cachés (.htaccess, .DS_Store, etc.)
// ignore fichiers système fréquents (si tu veux garder explicite)
if ($f === 'Thumbs.db') {
continue;
}
$full = $uploadDir . $f;
// uniquement les fichiers (pas sous-dossiers)
if (! is_file($full)) {
continue;
}
@@ -185,8 +206,7 @@
code{background:#f6f6f6;padding:2px 6px;border-radius:6px}
.muted{color:#666}
.row{display:flex;gap:12px;flex-wrap:wrap;align-items:center}
.btn{display:inline-block;padding:10px 14px;border-radius:10px;border:1px solid #ccc;background:#fff;cursor:pointer}
.btn-danger{border-color:#e3a4a4;background:#fff1f1}
.btn:disabled{opacity:.5;cursor:not-allowed}
</style>
</head>