Run /tmp cleaner on all accounts + prevent deleting empty accounts recently modified
This commit is contained in:
@ -6,15 +6,29 @@ try{
|
|||||||
die('No Connection to MySQL database!');
|
die('No Connection to MySQL database!');
|
||||||
}
|
}
|
||||||
|
|
||||||
//delete unused accounts older than 30 days
|
//delete tmp files older than 24 hours
|
||||||
$del=$db->prepare('UPDATE users SET todelete=1 WHERE id=?;');
|
$stmt=$db->query('SELECT system_account FROM users;');
|
||||||
$stmt=$db->prepare('SELECT system_account, id FROM users WHERE dateadded<?;');
|
|
||||||
$stmt->execute([time()-60*60*24*30]);
|
|
||||||
$all=$stmt->fetchAll(PDO::FETCH_NUM);
|
$all=$stmt->fetchAll(PDO::FETCH_NUM);
|
||||||
foreach($all as $tmp){
|
foreach($all as $tmp){
|
||||||
//delete tmp files older than 24 hours
|
exec('find '.escapeshellarg("/home/$tmp[0]/tmp").' -path '.escapeshellarg("/home/$tmp[0]/tmp/*").' -cmin +1440 -delete');
|
||||||
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 /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;
|
continue;
|
||||||
}
|
}
|
||||||
$count_www=count(scandir("/home/$tmp[0]/www/"));
|
$count_www=count(scandir("/home/$tmp[0]/www/"));
|
||||||
@ -31,4 +45,3 @@ foreach($all as $tmp){
|
|||||||
//no data found, safe to delete
|
//no data found, safe to delete
|
||||||
$del->execute([substr($tmp[1], 0, 16)]);
|
$del->execute([substr($tmp[1], 0, 16)]);
|
||||||
}
|
}
|
||||||
exec("find /var/www/tmp -path '/var/www/tmp/*' -cmin +1440 -delete");
|
|
||||||
|
Reference in New Issue
Block a user