diff --git a/scripts/jobs/cron_traffic.inc.functions.php b/scripts/jobs/cron_traffic.inc.functions.php index db96b3b6..1b148ce5 100644 --- a/scripts/jobs/cron_traffic.inc.functions.php +++ b/scripts/jobs/cron_traffic.inc.functions.php @@ -98,6 +98,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;