Merge pull request #240 from m4rcu5/master
access to stats from previous months with awstats, fixes #545
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 = "<!-- GENERATED BY FROXLOR -->\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, '<option value="' . $a . '">' . $a . '</option>');
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
18
templates/misc/awstats/index.html
Normal file
18
templates/misc/awstats/index.html
Normal file
@@ -0,0 +1,18 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
|
||||
<title>AWStats for {SITE_DOMAIN}</title>
|
||||
</head>
|
||||
|
||||
<frameset cols="*" rows="45,*" frameborder=0>
|
||||
<frame id="topFrame" name="topFrame" noresize="noresize" scrolling="no" src="nav.html" title="topFrame">
|
||||
<frame id="mainFrame" name="mainFrame" src="current/awstats.{SITE_DOMAIN}.html" title="mainFrame">
|
||||
|
||||
<noframes>
|
||||
<body>
|
||||
</body>
|
||||
</noframes>
|
||||
</frameset>
|
||||
</html>
|
||||
51
templates/misc/awstats/nav.html
Normal file
51
templates/misc/awstats/nav.html
Normal file
@@ -0,0 +1,51 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
|
||||
<title>Navigation</title>
|
||||
<style type="text/css">
|
||||
/* Include some of the Froxlor Theming */
|
||||
html,body {
|
||||
margin: 0;
|
||||
height: 100%;
|
||||
font: 12px/18px 'Lucida Grande','Lucida Sans Unicode',Helvetica,Arial,Verdana,sans-serif;
|
||||
color: #444;
|
||||
text-align: center;
|
||||
background: none repeat scroll 0% 0% rgba(240, 242, 244, 0.85);
|
||||
border-bottom: 1px solid #DDD;
|
||||
box-sizing: border-box;
|
||||
-webkit-font-smoothing: subpixel-antialiased;
|
||||
}
|
||||
select {
|
||||
padding: 6px 4px 7px 24px;
|
||||
color: #333;
|
||||
border: 1px solid #d9d9d9;
|
||||
margin: 5px 5px 5px 0;
|
||||
border-radius: 3px;
|
||||
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAcAAAAECAYAAABCxiV9AAAKTWlDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAABjTnY93WFNpFsa/e296oSVEOpdeQ5UQQKSEKiBFuijEJEAoIYQEFLsiKqgoKtIUQUYFHHB0KDJWRLEwIDbsAzIIqOPgKKKiskH3WX1259mdnfeP8/2e8533FAAofoFCUQasBEC6SCoJ8/VEo2NiUXwPgAER4IAtAFxeljhogU84kMvfm4NmyYvAV0EAvLk9EwG4wfQLQVHw/0mZJ5ZI5W1C5GzPF2Tx5Jwn57QcqXgmPy5n+pLUGYYxMyyRLyhntRlO+sKWn2u+sPsM89NFfDnP7Czmp/NnuFPOm7JlAjkjgXLOzxYKcuR8U86GabJ0oZzfznjTBdwsADCUmbxUwEuWs42cKZLwMI6c5wBAoCR9w0u+YalgqXTmKE6GeJlEmJQsRU15ZqitkxMb9RPkpAmkUmYIl5fKlfBRTka6mCtaBsCXmz9LJSvM1xP19+awbJ1YLKadlS34qv/6+RcVHROLfqFXoQCSPxCj+2vuz+oyagBgTwCAbP+aW1IGQOsGANTufc0Z7gdAMQ+Alt5v7mHIt0WTpVKxs7V1Tk6OlVDAs+IlfzPnfxb8BX0zz2qmHcvWicVi2lnZol6CRK4sTYqG+XqivIy0DJkEzRJzeQKUiWbJc9/0+NvGP9/DMkyQKJAIRHJHpFCQIxQloZwMEV8oFWaIUKEIlU/717BvOvxN278pW279DLTaT4AebwWUeukA+a0bYGhkgMTtk/9A0TGx6OeaQGIkCJG/Uboj6QJu1j9bQP/ZFS6aCVnCpM8+Tlg4ypNJsr/8YWYCFpCAIqADdaADDIApYAI74AhcgDvwBvNAMAgHMWAx4IFkkA4kIAesAGtBPigE28Fu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aOxB259r3X922NzMbqJkZT4VFwVHb06Q8JP9w+FnCs4zj7eOOPRj9WNtOaC1qglmUt463JrQNtMW19J+ad6Gh3aW/+yeqnQyf1TlacUj1VdJp0Ou/09JncMxNnxWefn0s6N9QR33H/fPT5m52hnT0XAi5cuuhz8XyXR9eZS66XTl52vnziCvtK61XW1ZZuh+7mnx1+bu5h9bT0Ova2XXO61t43p+/0dbfr52543bh40//m1Vvzb/Xdjrh9pz+uf+AO/87o3bS7L+9l35u6v+YB9kHBQ6WHJY+0HtX8YvZL0wBr4NSg12D34wWP7w/xhp79mvXrh+G8J9QnJSO6I3WjdqMnx3zGrj1d+HT4mfjZ1PP835R/q3xh+uLH391/7x6PHh9+KXk5/ceWV+qvDr2e/bpjImTi0Zv0N1OTBW/V3x5+x37X9T7q/chUzgf8h9KPZh/bPwV8ejCdPj39DwOY8/wRO+xuAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1MAAA6mAAADqYAAAXb5JfxUYAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAjSURBVBjTY+jo6PiPCzMACQkckhIgSWwKQHwGmCSyAgmYGADwzD0hSwpvYwAAAABJRU5ErkJggg==) no-repeat 9px;
|
||||
min-width: 170px;
|
||||
text-indent: 0.01px;
|
||||
text-overflow: '';
|
||||
-webkit-appearance: none;
|
||||
-moz-appearance: none;
|
||||
appearance: none;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
function change_page() {
|
||||
top.mainFrame.location= document.periodForm.periodSelect.value + '/awstats.{SITE_DOMAIN}.html';
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<form action="#" id="periodForm" method="get" name="periodForm">
|
||||
<b>Select period</b>
|
||||
<select name="periodSelect" onchange="change_page()">
|
||||
<option value="current">Current</option>
|
||||
{SELECT_ENTRIES}
|
||||
</select>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user