Files
dokuwiki-plugin-botmon/cleanup.php
2025-09-03 23:20:56 +02:00

28 lines
727 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<h1>BotMon Cleanup Script</h1>
<ul><?php
// exclude the following two dates:
$today = gmdate('Y-m-d');
$yesterday = gmdate('Y-m-d', time() - 86400);
// scan the log directory and delete all files except for today and yesterday:
$dir = scandir('logs');
foreach($dir as $file) {
$fName = pathinfo($file, PATHINFO_BASENAME);
$bName = strtok($fName, '.');
echo "<li>File “{$fName} ";
if ($bName == '' || $bName == 'logfiles') {
echo " <em>ignored</em></li>";
} else if ($bName == $today || $bName == $yesterday) {
echo " <em>skipped</em></li>";
} else {
if (unlink('logs/' . $file)) {
echo "deleted.</li>";
} else {
echo " <strong>not deleted!</strong></li>";
}
}
}
?></ul>