Skip to content

Commit 58c2101

Browse files
committed
Implemented: FS#903 - Awstats instead Webalizer
1 parent 379a4b6 commit 58c2101

File tree

2 files changed

+101
-19
lines changed

2 files changed

+101
-19
lines changed

server/cron_daily.php

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939

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

4343

4444
#######################################################################################################
@@ -112,40 +112,80 @@ function setConfigVar( $filename, $varName, $varValue ) {
112112
}
113113

114114

115-
$sql = "SELECT domain_id, domain, document_root FROM web_domain WHERE server_id = ".$conf["server_id"];
115+
$sql = "SELECT domain_id, domain, document_root FROM web_domain WHERE stats_type = 'webalizer' AND server_id = ".$conf["server_id"];
116116
$records = $app->db->queryAllRecords($sql);
117117

118118
foreach($records as $rec) {
119119
$yesterday = date("Ymd",time() - 86400);
120120
$logfile = escapeshellcmd($rec["document_root"].'/log/'.$yesterday.'-access.log');
121121
if(!@is_file($logfile)) {
122122
$logfile = escapeshellcmd($rec["document_root"].'/log/'.$yesterday.'-access.log.gz');
123-
if(!@is_file($logfile)) {
124-
continue;
123+
if(!@is_file($logfile)) {
124+
continue;
125+
}
125126
}
126-
}
127127

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');
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');
133133

134-
if(!@is_file($webalizer_conf)) {
135-
exec("cp $webalizer_conf_main $webalizer_conf");
136-
}
134+
if(!@is_file($webalizer_conf)) {
135+
exec("cp $webalizer_conf_main $webalizer_conf");
136+
}
137137

138-
if(@is_file($webalizer_conf)) {
139-
setConfigVar($webalizer_conf, 'Incremental', 'yes');
140-
setConfigVar($webalizer_conf, 'IncrementalName', $statsdir.'/webalizer.current');
141-
setConfigVar($webalizer_conf, 'HistoryName', $statsdir.'/webalizer.hist');
142-
}
138+
if(@is_file($webalizer_conf)) {
139+
setConfigVar($webalizer_conf, 'Incremental', 'yes');
140+
setConfigVar($webalizer_conf, 'IncrementalName', $statsdir.'/webalizer.current');
141+
setConfigVar($webalizer_conf, 'HistoryName', $statsdir.'/webalizer.hist');
142+
}
143143

144144

145-
if(!@is_dir($statsdir)) mkdir($statsdir);
145+
if(!@is_dir($statsdir)) mkdir($statsdir);
146146
exec("$webalizer -c $webalizer_conf -n $domain -s $domain -r $domain -q -T -p -o $statsdir $logfile");
147147
}
148148

149+
#######################################################################################################
150+
// Create awstats statistics
151+
#######################################################################################################
152+
153+
$sql = "SELECT domain_id, domain, document_root FROM web_domain WHERE stats_type = 'awstats' AND server_id = ".$conf["server_id"];
154+
$records = $app->db->queryAllRecords($sql);
155+
156+
$web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
157+
158+
foreach($records as $rec) {
159+
$yesterday = date("Ymd",time() - 86400);
160+
$logfile = escapeshellcmd($rec["document_root"].'/log/'.$yesterday.'-access.log');
161+
if(!@is_file($logfile)) {
162+
$logfile = escapeshellcmd($rec["document_root"].'/log/'.$yesterday.'-access.log.gz');
163+
if(!@is_file($logfile)) {
164+
continue;
165+
}
166+
}
167+
168+
$domain = escapeshellcmd($rec["domain"]);
169+
$statsdir = escapeshellcmd($rec["document_root"].'/web/stats');
170+
$awstats_pl = $web_config['awstats_pl'];
171+
$awstats_updateall_pl = $web_config['awstats_updateall_pl'];
172+
173+
174+
if(!@is_dir($statsdir)) mkdir($statsdir);
175+
176+
// awstats_buildstaticpages.pl -update -config=mydomain.com -lang=en -dir=/var/www/domain.com/web/stats -awstatsprog=/path/to/awstats.pl
177+
$command = "$awstats_updateall_pl -update -config='$domain' -lang=en -dir='$statsdir' -awstatsprog='$awstats_pl'";
178+
179+
if($awstats_pl != '' && $awstats_updateall_pl != '' && fileowner($awstats_pl) == 0 && fileowner($awstats_updateall_pl) == 0) {
180+
exec($command);
181+
$app->log("Created awstats statistics with command: $command",LOGLEVEL_DEBUG);
182+
} else {
183+
$app->log("No awstats statistics created. Either $awstats_pl or $awstats_updateall_pl is not owned by root user.",LOGLEVEL_WARN);
184+
}
185+
186+
}
187+
188+
149189
#######################################################################################################
150190
// Make the web logfiles directories world readable to enable ftp access
151191
#######################################################################################################

server/plugins-available/apache2_plugin.inc.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,11 @@ function update($event_name,$data) {
838838
unset($htp_file);
839839
}
840840
}
841+
842+
//* Create awstats configuration
843+
if($data["new"]["stats_type"] == 'awstats' && $data["new"]["type"] == "vhost") {
844+
$this->awstats_update($data,$web_config);
845+
}
841846

842847

843848
if($apache_chrooted) {
@@ -942,6 +947,11 @@ function delete($event_name,$data) {
942947
$command .= ' '.$data["old"]["system_user"];
943948
exec($command);
944949
if($apache_chrooted) $this->_exec("chroot ".escapeshellcmd($web_config['website_basedir'])." ".$command);
950+
951+
//* Remove the awstats configuration file
952+
if($data["old"]["stats_type"] == 'awstats') {
953+
$this->awstats_delete($data,$web_config);
954+
}
945955

946956
}
947957
}
@@ -1196,6 +1206,38 @@ private function _patchVhostWebdav($fileName, $webdavRoot) {
11961206
file_put_contents($fileName, $output);
11971207

11981208
}
1209+
1210+
//* Update the awstats configuration file
1211+
private function awstats_update ($data,$web_config) {
1212+
global $app;
1213+
1214+
if(!@is_file($awstats_conf_dir."/awstats.".$data["new"]["domain"].".conf") || ($data["old"]["domain"] != '' && $data["new"]["domain"] != $data["old"]["domain"])) {
1215+
if ( @is_file($awstats_conf_dir."/awstats.".$data["old"]["domain"].".conf") ) {
1216+
unlink($awstats_conf_dir."/awstats.".$data["old"]["domain"].".conf");
1217+
}
1218+
1219+
$content = '';
1220+
$content .= "Include '".$awstats_conf_dir."/awstats.conf'\n";
1221+
$content .= "LogFile='/var/log/ispconfig/httpd/".$data["new"]["domain"]."/access.log'\n";
1222+
$content .= "SiteDomain='".$data["new"]["domain"]."'\n";
1223+
$content .= "HostAliases='www.".$data["new"]["domain"]." localhost 127.0.0.1'\n";
1224+
1225+
file_put_contents($awstats_conf_dir.'/awstats.'.$data["new"]["domain"].'.conf',$content);
1226+
$app->log("Created awstats config file: ".$awstats_conf_dir.'/awstats.'.$data["new"]["domain"].'.conf',LOGLEVEL_DEBUG);
1227+
}
1228+
}
1229+
1230+
//* Delete the awstats configuration file
1231+
private function awstats_delete ($data,$web_config) {
1232+
global $app;
1233+
1234+
$awstats_conf_dir = $web_config['awstats_conf_dir'];
1235+
1236+
if ( @is_file($awstats_conf_dir."/awstats.".$data["old"]["domain"].".conf") ) {
1237+
unlink($awstats_conf_dir."/awstats.".$data["old"]["domain"].".conf");
1238+
$app->log("Removed awstats config file: ".$awstats_conf_dir.'/awstats.'.$data["old"]["domain"].'.conf',LOGLEVEL_DEBUG);
1239+
}
1240+
}
11991241

12001242
//* Wrapper for exec function for easier debugging
12011243
private function _exec($command) {

0 commit comments

Comments
 (0)