Skip to content

Commit 0358863

Browse files
committed
Fixed: FS#876 - Webalizer stats working only for first domain...
1 parent 1ab4008 commit 0358863

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

server/cron_daily.php

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,59 @@
8787
// Create webalizer statistics
8888
#######################################################################################################
8989

90+
function setConfigVar( $filename, $varName, $varValue ) {
91+
if($lines = @file($filename)) {
92+
$out = '';
93+
$found = 0;
94+
foreach($lines as $line) {
95+
list($key, $value) = split("[\t= ]+", $line, 2);
96+
if($key == $varName) {
97+
$out .= $varName." ".$varValue."\n";
98+
$found = 1;
99+
} else {
100+
$out .= $line;
101+
}
102+
}
103+
if($found == 0) {
104+
//* add \n if the last line does not end with \n or \r
105+
if(substr($out,-1) != "\n" && substr($out,-1) != "\r") $out .= "\n";
106+
//* add the new line at the end of the file
107+
if($append == 1) $out .= $varName." ".$varValue."\n";
108+
}
109+
110+
file_put_contents($filename,$out);
111+
}
112+
}
113+
90114

91115
$sql = "SELECT domain_id, domain, document_root FROM web_domain WHERE server_id = ".$conf["server_id"];
92116
$records = $app->db->queryAllRecords($sql);
117+
93118
foreach($records as $rec) {
94119
$yesterday = date("Ymd",time() - 86400);
95120
$logfile = escapeshellcmd($rec["document_root"].'/log/'.$yesterday.'-access.log');
96121
if(!@is_file($logfile)) {
97122
$logfile = escapeshellcmd($rec["document_root"].'/log/'.$yesterday.'-access.log.gz');
98-
if(!@is_file($logfile)) {
99-
continue;
100-
}
123+
if(!@is_file($logfile)) {
124+
continue;
101125
}
102-
$domain = escapeshellcmd($rec["domain"]);
103-
$statsdir = escapeshellcmd($rec["document_root"].'/web/stats');
104-
$webalizer = '/usr/bin/webalizer';
105-
$webalizer_conf = '/etc/webalizer/webalizer.conf';
106-
if(!@is_dir($statsdir)) mkdir($statsdir);
126+
}
127+
128+
$domain = escapeshellcmd($rec["domain"]);
129+
$statsdir = escapeshellcmd($rec["document_root"].'/web/stats');
130+
$webalizer = '/usr/bin/webalizer';
131+
$webalizer_conf_main = '/etc/webalizer/webalizer.conf';
132+
$webalizer_conf = escapeshellcmd($rec["document_root"].'/log/webalizer.conf');
133+
134+
if(!@is_file($webalizer_conf)) {
135+
exec("cp $webalizer_conf_main $webalizer_conf");
136+
137+
setConfigVar($webalizer_conf, 'Incremental', 'yes');
138+
setConfigVar($webalizer_conf, 'IncrementalName', $logdir.'/webalizer.current');
139+
setConfigVar($webalizer_conf, 'HistoryName', $logdir.'/webalizer.hist');
140+
}
141+
142+
if(!@is_dir($statsdir)) mkdir($statsdir);
107143
exec("$webalizer -c $webalizer_conf -n $domain -s $domain -r $domain -q -T -p -o $statsdir $logfile");
108144
}
109145

0 commit comments

Comments
 (0)