|
38 | 38 |
|
39 | 39 |
|
40 | 40 | // Load required base-classes |
41 | | -$app->uses('ini_parser,file,services'); |
| 41 | +$app->uses('ini_parser,file,services,getconf'); |
42 | 42 |
|
43 | 43 |
|
44 | 44 | ####################################################################################################### |
@@ -112,40 +112,80 @@ function setConfigVar( $filename, $varName, $varValue ) { |
112 | 112 | } |
113 | 113 |
|
114 | 114 |
|
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"]; |
116 | 116 | $records = $app->db->queryAllRecords($sql); |
117 | 117 |
|
118 | 118 | foreach($records as $rec) { |
119 | 119 | $yesterday = date("Ymd",time() - 86400); |
120 | 120 | $logfile = escapeshellcmd($rec["document_root"].'/log/'.$yesterday.'-access.log'); |
121 | 121 | if(!@is_file($logfile)) { |
122 | 122 | $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 | + } |
125 | 126 | } |
126 | | -} |
127 | 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'); |
| 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 | 133 |
|
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 | + } |
137 | 137 |
|
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 | + } |
143 | 143 |
|
144 | 144 |
|
145 | | -if(!@is_dir($statsdir)) mkdir($statsdir); |
| 145 | + if(!@is_dir($statsdir)) mkdir($statsdir); |
146 | 146 | exec("$webalizer -c $webalizer_conf -n $domain -s $domain -r $domain -q -T -p -o $statsdir $logfile"); |
147 | 147 | } |
148 | 148 |
|
| 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 | + |
149 | 189 | ####################################################################################################### |
150 | 190 | // Make the web logfiles directories world readable to enable ftp access |
151 | 191 | ####################################################################################################### |
|
0 commit comments