From a0c557c405ab32095ef35e851c5ed1d37519a7e3 Mon Sep 17 00:00:00 2001 From: "Michael Kaufmann (d00p)" Date: Tue, 2 Mar 2010 22:03:55 +0000 Subject: [PATCH] - check for existing awstats-configuration-directory and model-file, fixes #45 --- scripts/jobs/cron_tasks.php | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/scripts/jobs/cron_tasks.php b/scripts/jobs/cron_tasks.php index 1fefba6c..fab32ff2 100644 --- a/scripts/jobs/cron_tasks.php +++ b/scripts/jobs/cron_tasks.php @@ -55,14 +55,33 @@ while($row = $db->fetch_array($result_tasks)) { $awstatsclean['header'] = "## GENERATED BY FROXLOR\n"; $awstatsclean['path'] = '/etc/awstats'; - $awstatsclean['dir'] = dir($awstatsclean['path']); - while($awstatsclean['entry'] = $awstatsclean['dir']->read()) { - $awstatsclean['fullentry'] = $awstatsclean['path'].'/'.$awstatsclean['entry']; - $awstatsclean['fh'] = fopen($awstatsclean['fullentry'], 'r'); - $awstatsclean['headerRead'] = fgets($awstatsclean['fh'], strlen($awstatsclean['header'])+1); - fclose($awstatsclean['fh']); - if($awstatsclean['headerRead'] == $awstatsclean['header']) { - @unlink($awstatsclean['fullentry']); + + /** + * dont do anyting if the directory not exists + * (e.g. awstats not installed yet or whatever) + * fixes #45 + */ + if (is_dir($awstatsclean['dir'])) + { + $awstatsclean['dir'] = dir($awstatsclean['path']); + while($awstatsclean['entry'] = $awstatsclean['dir']->read()) { + $awstatsclean['fullentry'] = $awstatsclean['path'].'/'.$awstatsclean['entry']; + /** + * dont do anything if the file does not exist + */ + if (file_exists($awstatsclean['fullentry'])) + { + $awstatsclean['fh'] = fopen($awstatsclean['fullentry'], 'r'); + $awstatsclean['headerRead'] = fgets($awstatsclean['fh'], strlen($awstatsclean['header'])+1); + fclose($awstatsclean['fh']); + if($awstatsclean['headerRead'] == $awstatsclean['header']) { + @unlink($awstatsclean['fullentry']); + } + } + else + { + $cronlog->logAction(CRON_ACTION, LOG_WARNING, "File '".$awstatsclean['fullentry']."' could not be found, please check if you followed all the instructions on the configuration page"); + } } } unset($awstatsclean);