Run /tmp cleaner on all accounts + prevent deleting empty accounts recently modified

This commit is contained in:
Daniel Winzen
2019-10-20 18:39:31 +02:00
parent c31c909b7c
commit 4cd17049f0

View File

@ -6,15 +6,29 @@ try{
die('No Connection to MySQL database!');
}
//delete unused accounts older than 30 days
$del=$db->prepare('UPDATE users SET todelete=1 WHERE id=?;');
$stmt=$db->prepare('SELECT system_account, id FROM users WHERE dateadded<?;');
$stmt->execute([time()-60*60*24*30]);
//delete tmp files older than 24 hours
$stmt=$db->query('SELECT system_account FROM users;');
$all=$stmt->fetchAll(PDO::FETCH_NUM);
foreach($all as $tmp){
//delete tmp files older than 24 hours
exec("find /home/$tmp[0]/tmp -path '/home/$tmp[0]/tmp/*' -cmin +1440 -delete");
if(filemtime("/home/$tmp[0]")>time()-60*60*24*30){
exec('find '.escapeshellarg("/home/$tmp[0]/tmp").' -path '.escapeshellarg("/home/$tmp[0]/tmp/*").' -cmin +1440 -delete');
}
exec("find /var/www/tmp -path '/var/www/tmp/*' -cmin +1440 -delete");
//delete unused accounts older than 30 days
$last_month=time()-60*60*24*30;
$del=$db->prepare('UPDATE users SET todelete=1 WHERE id=?;');
$stmt=$db->prepare('SELECT system_account, id FROM users WHERE dateadded<?;');
$stmt->execute([$last_month]);
$all=$stmt->fetchAll(PDO::FETCH_NUM);
foreach($all as $tmp){
//check modification times
if(filemtime("/home/$tmp[0]/")>$last_month){
continue;
}
if(filemtime("/home/$tmp[0]/data/")>$last_month){
continue;
}
if(filemtime("/home/$tmp[0]/www/")>$last_month){
continue;
}
$count_www=count(scandir("/home/$tmp[0]/www/"));
@ -31,4 +45,3 @@ foreach($all as $tmp){
//no data found, safe to delete
$del->execute([substr($tmp[1], 0, 16)]);
}
exec("find /var/www/tmp -path '/var/www/tmp/*' -cmin +1440 -delete");