= ($MIN_DAYS - 1)) { CheckDay($dayDir, "$year$month$day"); } } } rmdir($monthDir); } } rmdir($yearDir); } } } CheckLocations(); echo "\nDone\n\n"; if( $log ) { fwrite($log, "Archived: $archiveCount\nDeleted: $deleted\nKept: $kept\n" . gmdate('r') . "\n");; fclose($log); } if ($lock) { fclose($lock); } /** * Clean up the relay directory of old tests * */ function CheckRelay() { $dirs = scandir('./results/relay'); $keys = parse_ini_file('./settings/keys.ini'); foreach($dirs as $key) { if ($key != '.' && $key != '..') { $keydir = "./results/relay/$key"; if (is_dir($keydir)) { if (array_key_exists($key, $keys)) { echo "\rChecking relay tests for $key"; $years = scandir($keydir); foreach( $years as $year ) { if ($year != '.' && $year != '..') { $yearDir = "$keydir/$year"; if (is_numeric($year)) { if (ElapsedDays($year, 1, 1) < 10) { $months = scandir($yearDir); foreach( $months as $month ) { if ($month != '.' && $month != '..') { $monthDir = "$yearDir/$month"; if (is_numeric($month)) { if (ElapsedDays($year, $month, 1) < 10) { $days = scandir($monthDir); foreach( $days as $day ) { if ($day != '.' && $day != '..') { $dayDir = "$monthDir/$day"; if (is_numeric($day)) { if (ElapsedDays($year, $month, $day) >= 10) { delTree($dayDir); } } else { if (is_file($dayDir)) { unlink($dayDir); } else { delTree($dayDir); } } } } } else { delTree($monthDir); } } else { if (is_file($monthDir)) { unlink($monthDir); } else { delTree($monthDir); } } } } } else { delTree($yearDir); } } else { if (is_file($yearDir)) { unlink($yearDir); } else { delTree($yearDir); } } } } } else { delTree($keydir); } } else { unlink($keydir); } } } } /** * Recursively scan the old directory for tests * * @param mixed $path */ function CheckOldDir($path) { $oldDirs = scandir($path); foreach( $oldDirs as $oldDir ) { if( $oldDir != '.' && $oldDir != '..' ) { // see if it is a test or a higher-level directory if( is_file("$path/$oldDir/testinfo.ini") ) CheckTest("$path/$oldDir", $oldDir); else CheckOldDir("$path/$oldDir"); } } rmdir($path); } /** * Recursively check within a given day * * @param mixed $dir * @param mixed $baseID * @param mixed $archived */ function CheckDay($dir, $baseID) { $tests = scandir($dir); foreach( $tests as $test ) { if( $test != '.' && $test != '..' ) { // see if it is a test or a higher-level directory if( is_file("$dir/$test/testinfo.ini") ) CheckTest("$dir/$test", "{$baseID}_$test"); else CheckDay("$dir/$test", "{$baseID}_$test"); } } rmdir($dir); } /** * Check the given log file for all tests that match * * @param mixed $logFile * @param mixed $match */ function CheckTest($testPath, $id) { global $archiveCount; global $deleted; global $kept; global $log; global $MIN_DAYS; $logLine = "$id : "; echo "\rArc:$archiveCount, Del:$deleted, Kept:$kept, Checking:" . str_pad($id,45); $elapsed = TestLastAccessed($id); if( $elapsed >= $MIN_DAYS ) { $delete = true; if (ArchiveTest($id) ) { $archiveCount++; $logLine .= "Archived"; if (!VerifyArchive($id) && $elapsed < 60) { $delete = false; } } else if ($elapsed < 60) { $delete = false; } if ($delete) { delTree("$testPath/"); $deleted++; $logLine .= " Deleted"; } else { $kept++; } } else { $logLine .= "Last Accessed $elapsed days"; $kept++; } if( $log ) { $logLine .= "\n"; fwrite($log, $logLine); } } /** * Calculate how many days have passed since the given day */ function ElapsedDays($year, $month, $day) { global $now; global $UTC; $date = DateTime::createFromFormat('ymd', "$year$month$day", $UTC); $daytime = $date->getTimestamp(); $elapsed = max($now - $daytime, 0) / 86400; return $elapsed; } /** * For any locations that haven't connected in at least 2 hours, go through and delete any tests in the work queue * */ function CheckLocations() { $locations = parse_ini_file('./settings/locations.ini', true); BuildLocations($locations); $deleted = false; echo "\n"; for ($i = 1; array_key_exists($i, $locations['locations']); $i++) { $group = &$locations[$locations['locations'][$i]]; for ($j = 1; array_key_exists($j, $group); $j++) { if (!array_key_exists('relayServer', $loc[$group[$j]])) { $name = $locations[$group[$j]]['location']; $location = GetTesters($name); $workdir = $locations[$name]['localDir']; $elapsed = -1; if (isset($location) && array_key_exists('elapsed', $location)) $elapsed = $location['elapsed']; if ($elapsed < 0 || $elapsed > 120) { if (strlen($workdir)){ if (is_dir($workdir)) { echo "$elapsed minutes : $name - $workdir\n"; delTree($workdir); rmdir($workdir); $deleted = true; } } } } } } // nuke all of the queue files if we had to delete something if ($deleted) { $files = scandir('./tmp'); foreach ($files as $file) { if (stripos($file, '.queue') !== false) { unlink("./tmp/$file"); } } } } ?>