From 9bbdb1b3b9e0d1442c6d57a941afe0163d8e4233 Mon Sep 17 00:00:00 2001 From: Marcus van Dam Date: Mon, 1 Jun 2015 14:55:43 +0200 Subject: [PATCH] Feature #545: Include the awstatsGenerateIndex in cronjob. Seperate the awstats updates output directory from the awstats static output directory. Switch to zero padded months. Symlink current month to 'current' directory (force needed to update the link if it already exists) --- scripts/jobs/cron_traffic.inc.functions.php | 27 +++++++++++---------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/scripts/jobs/cron_traffic.inc.functions.php b/scripts/jobs/cron_traffic.inc.functions.php index 1b148ce5..e708e750 100644 --- a/scripts/jobs/cron_traffic.inc.functions.php +++ b/scripts/jobs/cron_traffic.inc.functions.php @@ -26,10 +26,11 @@ function awstatsDoSingleDomain($domain, $outputdir) { if (file_exists($domainconfig)) { - $outputdir = makeCorrectDir($outputdir . '/' . $domain); + $outputdir = makeCorrectDir($outputdir . '/' . $domain); + $staticOutputdir = makeCorrectDir($outputdir . '/' . date('Y') . '-' . date('m')); - if (!is_dir($outputdir)) { - safe_exec('mkdir -p ' . escapeshellarg($outputdir)); + if (!is_dir($staticOutputdir)) { + safe_exec('mkdir -p ' . escapeshellarg($staticOutputdir)); } //check for correct path of awstats_buildstaticpages.pl @@ -42,19 +43,19 @@ function awstatsDoSingleDomain($domain, $outputdir) { exit; } - $cronlog->logAction(CRON_ACTION, LOG_INFO, "Running awstats_buildstaticpages.pl for domain '".$domain."' (Output: '".$outputdir."')"); - safe_exec($awbsp.' -awstatsprog='.escapeshellarg($awprog).' -update -month=' . date('n') . ' -year=' . date('Y') . ' -config=' . $domain . ' -dir='.escapeshellarg($outputdir)); + $cronlog->logAction(CRON_ACTION, LOG_INFO, "Running awstats_buildstaticpages.pl for domain '".$domain."' (Output: '".$staticOutputdir."')"); + safe_exec($awbsp.' -awstatsprog='.escapeshellarg($awprog).' -update -month=' . date('m') . ' -year=' . date('Y') . ' -config=' . $domain . ' -dir='.escapeshellarg($staticOutputdir)); - // index file is saved like 'awstats.[domain].html', - // so link a index.html to it - $original_index = makeCorrectFile($outputdir.'/awstats.'.$domain.'.html'); - $new_index = makeCorrectFile($outputdir.'/index.html'); - if (!file_exists($new_index)) { - safe_exec('ln -s '.escapeshellarg($original_index).' '.escapeshellarg($new_index)); - } + // update our awstats index files + awstatsGenerateIndex($domain, $outputdir); + + // the default selection is 'current', + // so link the latest dir to it + $new_current = makeCorrectFile($outputdir . '/current'); + safe_exec('ln -fs ' . escapeshellarg($staticOutputdir) . ' ' . escapeshellarg($new_current)); //statistics file looks like: 'awstats[month][year].[domain].txt' - $file = makeCorrectFile($outputdir.'/awstats'.date('mY', time()).'.'.$domain.'.txt'); + $file = makeCorrectFile($staticOutputdir.'/awstats'.date('mY', time()).'.'.$domain.'.txt'); $cronlog->logAction(CRON_ACTION, LOG_INFO, "Gathering traffic information from '".$file."'"); if (file_exists($file)) {