recreate_webalizer_stats.php 1.42 KB
Newer Older
1 2
<?php

3
//######################################################################################################
4
// Re-Create webalizer statistics
5
//######################################################################################################
6 7 8 9 10


$sql = "SELECT domain_id, domain, document_root FROM web_domain WHERE server_id = ".$conf["server_id"];
$records = $app->db->queryAllRecords($sql);
foreach($records as $rec) {
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
	$domain = escapeshellcmd($rec["domain"]);
	$logdir = escapeshellcmd($rec["document_root"].'/log');
	$statsdir = escapeshellcmd($rec["document_root"].'/web/stats');
	$webalizer = '/usr/bin/webalizer';

	$webalizer_conf_main = '/etc/webalizer/webalizer.conf';
	$webalizer_conf = escapeshellcmd($rec["document_root"].'/log/webalizer.conf');
	exec("rm -rf $webalizer_conf");
	if(!@is_file($webalizer_conf)) {
		exec("cp $webalizer_conf_main $webalizer_conf");

		setConfigVar($webalizer_conf, 'Incremental', 'yes');
		setConfigVar($webalizer_conf, 'IncrementalName', $logdir.'/webalizer.current');
		setConfigVar($webalizer_conf, 'HistoryName', $logdir.'/webalizer.hist');
	}
26

27
	if(!@is_dir($statsdir)) mkdir($statsdir);
28 29


30 31
	echo "Remove stats dir $statsdir ...\n";
	exec("rm -rf $statsdir/*");
32

33 34 35
	echo "Re-Create stats for $domain...\n";
	exec("for logfile in $logdir/*access*; do\n$webalizer -c $webalizer_conf -n $domain -s $domain -r $domain -q -T -p -o $statsdir ".'$logfile'."\ndone");
	echo "done.\n";
36 37 38
}

die("finished.\n");
39
?>