From 7e8e28fc9050ada9ab33daa76670e1f71e9d90a5 Mon Sep 17 00:00:00 2001 From: Marcus van Dam Date: Mon, 1 Jun 2015 13:09:43 +0200 Subject: [PATCH 1/5] Move to a generic awstats template directory We need this generic directory for future changes in Feature #545. Some line-ending cleanup included. --- lib/functions/froxlor/function.createAWStatsConf.php | 6 +++--- .../{awstatsmodel => awstats}/awstats.froxlor.model.conf | 0 2 files changed, 3 insertions(+), 3 deletions(-) rename templates/misc/{awstatsmodel => awstats}/awstats.froxlor.model.conf (100%) 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/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 From 2017bc9cf68990a1ba77930ad27483705bf74d9f Mon Sep 17 00:00:00 2001 From: Marcus van Dam Date: Mon, 1 Jun 2015 14:06:05 +0200 Subject: [PATCH 2/5] Feature #545: New index.html and nav.html templates These templates should later provide the navigation and index for the per month based awstats. --- templates/misc/awstats/index.html | 18 +++++++++++ templates/misc/awstats/nav.html | 51 +++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 templates/misc/awstats/index.html create mode 100644 templates/misc/awstats/nav.html 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 @@ + + + + + + AWStats for {SITE_DOMAIN} + + + + + + + + <body> + </body> + + + diff --git a/templates/misc/awstats/nav.html b/templates/misc/awstats/nav.html new file mode 100644 index 00000000..a549c8f8 --- /dev/null +++ b/templates/misc/awstats/nav.html @@ -0,0 +1,51 @@ + + + + + + Navigation + + + + + +
+ Select period + +
+ + From f6cdc0575beb50c5814b39e76d39880a256c36e3 Mon Sep 17 00:00:00 2001 From: Marcus van Dam Date: Mon, 1 Jun 2015 14:45:20 +0200 Subject: [PATCH 3/5] Feature #545: function to deploy the index and nav templates Should deploy the html files with its template variables replaced into the awstats root. --- scripts/jobs/cron_traffic.inc.functions.php | 77 +++++++++++++++++++++ 1 file changed, 77 insertions(+) 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; From 9bbdb1b3b9e0d1442c6d57a941afe0163d8e4233 Mon Sep 17 00:00:00 2001 From: Marcus van Dam Date: Mon, 1 Jun 2015 14:55:43 +0200 Subject: [PATCH 4/5] 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)) { From 83e904c9f771f886c2f3592bcc3d5c00ad611f20 Mon Sep 17 00:00:00 2001 From: Marcus van Dam Date: Mon, 1 Jun 2015 16:24:45 +0200 Subject: [PATCH 5/5] Feature #545: Prevent `ln` from linking withing the current symlink. --- scripts/jobs/cron_traffic.inc.functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/jobs/cron_traffic.inc.functions.php b/scripts/jobs/cron_traffic.inc.functions.php index e708e750..65882e76 100644 --- a/scripts/jobs/cron_traffic.inc.functions.php +++ b/scripts/jobs/cron_traffic.inc.functions.php @@ -52,7 +52,7 @@ function awstatsDoSingleDomain($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)); + safe_exec('ln -fTs ' . escapeshellarg($staticOutputdir) . ' ' . escapeshellarg($new_current)); //statistics file looks like: 'awstats[month][year].[domain].txt' $file = makeCorrectFile($staticOutputdir.'/awstats'.date('mY', time()).'.'.$domain.'.txt');