query('SELECT id, system_account FROM users WHERE id NOT IN (SELECT user_id FROM new_account) AND todelete!=1;'); $update=$db->prepare('UPDATE disk_quota SET quota_size_used = ?, quota_files_used = ? WHERE user_id = ?;'); while($tmp=$stmt->fetch(PDO::FETCH_ASSOC)){ $quota = shell_exec('quota -pu ' . escapeshellarg($tmp['system_account'])); $quota_array = explode("\n", $quota); if(!empty($quota_array[2])){ $quota_size=(int) preg_replace('~^\s+[^\s]+\s+([^\s]+).*~', '$1', $quota_array[2]); $quota_files=(int) preg_replace('~^\s+[^\s]+\s+[^\s]+\s+[^\s]+\s+[^\s]+\s+[^\s]+\s+([^\s]+).*~', '$1', $quota_array[2]); $update->execute([$quota_size, $quota_files, $tmp['id']]); } } //delete tmp files older than 24 hours $stmt=$db->query('SELECT system_account FROM users;'); $all=$stmt->fetchAll(PDO::FETCH_ASSOC); foreach($all as $tmp){ exec('find '.escapeshellarg("/home/$tmp[system_account]/tmp").' -path '.escapeshellarg("/home/$tmp[system_account]/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_ASSOC); foreach($all as $tmp){ //check modification times if(filemtime("/home/$tmp[system_account]/data/")>$last_month){ continue; } if(filemtime("/home/$tmp[system_account]/www/")>$last_month){ continue; } $count_www=count(scandir("/home/$tmp[system_account]/www/")); //check data empty and www no more than 1 file if($count_www>3 || count(scandir("/home/$tmp[system_account]/data/"))>2){ continue; } //check www empty or index unmodified if($count_www===3){ if(!( ( file_exists("/home/$tmp[system_account]/www/index.hosting.html") && in_array(md5_file("/home/$tmp[system_account]/www/index.hosting.html"), INDEX_MD5S, true) ) || ( file_exists("/home/$tmp[system_account]/www/index.html") && in_array(md5_file("/home/$tmp[system_account]/www/index.html"), INDEX_MD5S, true) ) || ( file_exists("/home/$tmp[system_account]/www/index.htm") && in_array(md5_file("/home/$tmp[system_account]/www/index.htm"), INDEX_MD5S, true) ) || ( file_exists("/home/$tmp[system_account]/www/index.php") && in_array(md5_file("/home/$tmp[system_account]/www/index.php"), INDEX_MD5S, true) ) )){ continue; } } //no data found, safe to delete $del->execute([substr($tmp['id'], 0, 16)]); }