Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > ISPConfig 3 > Tips/Tricks/Mods

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 3rd March 2011, 22:25
8omas 8omas is offline
Senior Member
 
Join Date: Jan 2011
Posts: 140
Thanks: 16
Thanked 35 Times in 26 Posts
Default Awstats anytime update

Below is a cut off, of the default cron file of ISPConfig 3.
Till, can we use it to update awstats, as frequently as we want?

My replacements:
- I removed every logrotate action you had and everything else, that had to do with modifying files
- I erased every yesterday variable and I used the default access.log for each website
- I tested it.

As I see after the tests, when I run it , then the stats REPLACED and updated for today. When the real cron runs every night, then the stats created with the above script, replaced again bringing us back to the state that ISPConfig wants. If (after 00:30) I run the script again, then the stats replaced again, but actually only the 'new' day is modified.

I think it works. Can I have your opinion?


Code:
<?php
require('/usr/local/ispconfig/server/lib/config.inc.php');
require('/usr/local/ispconfig/server/lib/app.inc.php');

set_time_limit(0);

// make sure server_id is always an int
$conf['server_id'] = intval($conf['server_id']);


// Load required base-classes
$app->uses('ini_parser,file,services,getconf');


#######################################################################################################
// Create awstats statistics
#######################################################################################################
$sql = "SELECT domain_id, domain, document_root FROM web_domain WHERE stats_type = 'awstats' AND server_id = ".$conf['server_id'];
$records = $app->db->queryAllRecords($sql);

$web_config = $app->getconf->get_server_config($conf['server_id'], 'web');

foreach($records as $rec) {
        $logfile = escapeshellcmd($rec['document_root'].'/log/access.log');

        $domain = escapeshellcmd($rec['domain']);
        $statsdir = escapeshellcmd($rec['document_root'].'/web/stats');
        $awstats_pl = $web_config['awstats_pl'];
        $awstats_buildstaticpages_pl = $web_config['awstats_buildstaticpages_pl'];
        
        $awstats_conf_dir = $web_config['awstats_conf_dir'];
        $awstats_website_conf_file = $web_config['awstats_conf_dir'].'/awstats.'.$domain.'.conf';
        
        if(is_file($awstats_website_conf_file)) unlink($awstats_website_conf_file);
        
        if(!is_file($awstats_website_conf_file)) {
                $awstats_conf_file_content = 'Include "'.$awstats_conf_dir.'/awstats.conf"
LogFile="/var/log/ispconfig/httpd/'.$domain.'/access.log"
SiteDomain="'.$domain.'"

HostAliases="www.'.$domain.' localhost 127.0.0.1"';
                file_put_contents($awstats_website_conf_file,$awstats_conf_file_content);
        }

        if(!@is_dir($statsdir)) mkdir($statsdir);

        // awstats_buildstaticpages.pl -update -config=mydomain.com -lang=en -dir=/var/www/domain.com/web/stats -awstatsprog=/path/to/awstats.pl
        $command = "$awstats_buildstaticpages_pl -update -config='$domain' -lang=en -dir='$statsdir' -awstatsprog='$awstats_pl'";

        if($awstats_pl != '' && $awstats_buildstaticpages_pl != '' && fileowner($awstats_pl) == 0 && fileowner($awstats_buildstaticpages_pl) == 0) {
                exec($command);
                rename($rec['document_root'].'/web/stats/awstats.'.$domain.'.html',$rec['document_root'].'/web/stats/index.html');
                $app->log('Created awstats statistics with command: '.$command,LOGLEVEL_DEBUG);
        } else {
                $app->log("No awstats statistics created. Either $awstats_pl or $awstats_buildstaticpages_pl is not owned by root user.",LOGLEVEL_WARN);
        }

}

die("finished.\n");
?>
I named the file as /usr/local/ispconfig/server/mycron.php and I can run it as
Code:
/usr/bin/php -q /usr/local/ispconfig/server/mycron.php

Last edited by 8omas; 3rd March 2011 at 22:32.
Reply With Quote
The Following User Says Thank You to 8omas For This Useful Post:
falko (4th March 2011)
Sponsored Links
 

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
My Centos is terribly slow Galled Server Operation 9 7th December 2010 15:31
Vhosts...conf not synced to changes crypted General 50 24th April 2010 00:54
The system is currently updating the configuration files. warlock General 8 21st February 2009 18:15
High Availability Samba cluster - DRBD + Heartbeat djalex Server Operation 58 25th May 2007 19:38
HotSaNIC domino Tips/Tricks/Mods 23 6th November 2006 05:19


All times are GMT +2. The time now is 19:30.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.