diff --git a/api.php b/api.php index 62d117f..9bfe912 100644 --- a/api.php +++ b/api.php @@ -39,7 +39,7 @@ Db::connect (DBHOST, DBUSER, DBPASS, DBNAME); $json = file_get_contents('php://input'); $obj = json_decode($json, true); $logManager->write("[API] Rest API request body \n" . $json, LogRecordType::INFO); -$logManager->write("[API] Rest API request body -> decodet to json \n" . var_export($obj), LogRecordType::INFO); +//$logManager->write("[API] Rest API request body -> decodet to json \n" . var_dump($obj), LogRecordType::INFO); //zabespecit proti Ddosu if (isset($obj['user']) && $obj['user'] != ''){ @@ -71,9 +71,11 @@ if (DEBUGMOD != 1) { //automationExecution try { + AutomationManager::executeAll(); $fallbackManager = new FallbackManager(RANGES); $fallbackManager->check(); - AutomationManager::executeAll(); + LogKeeper::purge(LOGTIMOUT); + die(); } catch (\Exception $e) { $logManager->write("[Automation] Something happen during automation execution", LogRecordType::ERROR); } diff --git a/app/class/LogManager.php b/app/class/LogManager.php index 5d2d984..95f82f4 100644 --- a/app/class/LogManager.php +++ b/app/class/LogManager.php @@ -9,6 +9,25 @@ class LogRecordType{ const INFO = 'info'; } +class LogKeeper +{ + function purge($days){ + $todayFileName = date("Y-m-d").'.log'; + $seconds = $days * 86400; + + $logFiles = scandir('./app/logs/'); + foreach ($logFiles as $key => $file) { + if (in_array($file,array(".","..", ".gitkeep", $todayFileName))) + { + continue; + } + if (filemtime($file) > $seconds) { + unlink('./app/logs/'.$file); + } + } + } +} + class LogManager {