diff --git a/lib/functions/froxlor/function.createAWStatsConf.php b/lib/functions/froxlor/function.createAWStatsConf.php index cc848f8b..4132b99a 100644 --- a/lib/functions/froxlor/function.createAWStatsConf.php +++ b/lib/functions/froxlor/function.createAWStatsConf.php @@ -38,7 +38,7 @@ function createAWStatsConf($logFile, $siteDomain, $hostAliases, $customerDocroot } // chown created folder, #258 makeChownWithNewStats($awstats_params); - + // weird but could happen... if (!is_dir(Settings::Get('system.awstats_conf'))) { safe_exec('mkdir -p '.escapeshellarg(Settings::Get('system.awstats_conf'))); @@ -62,9 +62,9 @@ function createAWStatsConf($logFile, $siteDomain, $hostAliases, $customerDocroot // File names $domain_file = makeCorrectFile(Settings::Get('system.awstats_conf').'/awstats.' . $siteDomain . '.conf'); - $model_file = FROXLOR_INSTALL_DIR.'/templates/misc/awstatsmodel/awstats.froxlor.model.conf'; + $model_file = FROXLOR_INSTALL_DIR.'/templates/misc/awstats/awstats.froxlor.model.conf'; $model_file = makeCorrectFile($model_file); - + // Test if the file exists if (file_exists($domain_file)) { // Check for the generated header - if this is a manual modification we won't update diff --git a/scripts/jobs/cron_traffic.inc.functions.php b/scripts/jobs/cron_traffic.inc.functions.php index db96b3b6..65882e76 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 -fTs ' . 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)) { @@ -98,6 +99,83 @@ function awstatsDoSingleDomain($domain, $outputdir) { } +function awstatsGenerateIndex($domain, $outputdir) { + + // Generation header + $header = "\n"; + + // Looking for {year}-{month} directories + $entries = array(); + foreach (scandir($outputdir) as $a) { + if (is_dir(makeCorrectDir($outputdir . '/' . $a)) && preg_match('/^[0-9]{4}-[0-9]{2}$/', $a)) { + array_push($entries, ''); + } + } + + // These are the variables we will replace + $regex = array( + '/\{SITE_DOMAIN\}/', + '/\{SELECT_ENTRIES\}/' + ); + + $replace = array( + $domain, + implode($entries) + ); + + // File names + $index_file = FROXLOR_INSTALL_DIR.'/templates/misc/awstats/index.html'; + $index_file = makeCorrectFile($index_file); + $nav_file = FROXLOR_INSTALL_DIR.'/templates/misc/awstats/nav.html'; + $nav_file = makeCorrectFile($nav_file); + + // Write the index file + { + // 'index.html' used to be a symlink + unlink(makeCorrectFile($outputdir . '/' . 'index.html')); + + $awstats_index_file = fopen(makeCorrectFile($outputdir . '/' . 'index.html'), 'w'); + $awstats_index_tpl = fopen($index_file, 'r'); + + // Write the header + fwrite($awstats_index_file, $header); + + // Write the configuration file + while (($line = fgets($awstats_index_tpl, 4096)) !== false) { + if (!preg_match('/^#/', $line) + && trim($line) != '' + ) { + fwrite($awstats_index_file, preg_replace($regex, $replace, $line)); + } + } + fclose($awstats_index_file); + fclose($awstats_index_tpl); + } + + // Write the nav file + { + $awstats_nav_file = fopen(makeCorrectFile($outputdir . '/' . 'nav.html'), 'w'); + $awstats_nav_tpl = fopen($nav_file, 'r'); + + // Write the header + fwrite($awstats_nav_file, $header); + + // Write the configuration file + while (($line = fgets($awstats_nav_tpl, 4096)) !== false) { + if (!preg_match('/^#/', $line) + && trim($line) != '' + ) { + fwrite($awstats_nav_file, preg_replace($regex, $replace, $line)); + } + } + fclose($awstats_nav_file); + fclose($awstats_nav_tpl); + } + + return; +} + + function callAwstatsGetTraffic($customerid, $outputdir, $usersdomainlist) { global $cronlog; diff --git a/templates/misc/awstatsmodel/awstats.froxlor.model.conf b/templates/misc/awstats/awstats.froxlor.model.conf similarity index 100% rename from templates/misc/awstatsmodel/awstats.froxlor.model.conf rename to templates/misc/awstats/awstats.froxlor.model.conf diff --git a/templates/misc/awstats/index.html b/templates/misc/awstats/index.html new file mode 100644 index 00000000..409f2152 --- /dev/null +++ b/templates/misc/awstats/index.html @@ -0,0 +1,18 @@ + + +
+ + +