From 4cd17049f04c8e948c460322b2155ee71f826b35 Mon Sep 17 00:00:00 2001 From: Daniel Winzen Date: Sun, 20 Oct 2019 18:39:31 +0200 Subject: [PATCH] Run /tmp cleaner on all accounts + prevent deleting empty accounts recently modified --- var/www/find_old.php | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/var/www/find_old.php b/var/www/find_old.php index 1a38d91..0f2c6dd 100644 --- a/var/www/find_old.php +++ b/var/www/find_old.php @@ -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 dateaddedexecute([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 dateaddedexecute([$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");