|
2 | 2 |
|
3 | 3 | /* |
4 | 4 | Copyright (c) 2013, Marius Cramer, pixcept KG |
| 5 | +Copyright (c) 2020, Michael Seevogel |
5 | 6 | All rights reserved. |
6 | 7 |
|
7 | 8 | Redistribution and use in source and binary forms, with or without modification, |
@@ -59,17 +60,25 @@ public function onRunJob() { |
59 | 60 |
|
60 | 61 | $web_config = $app->getconf->get_server_config($conf['server_id'], 'web'); |
61 | 62 |
|
62 | | - $goaccess_conf_dir = '/etc/'; |
63 | | - $goaccess_conf_main = $goaccess_conf_dir . 'goaccess.conf'; |
| 63 | + $goaccess_conf_locs = array('/etc/goaccess.conf', '/etc/goaccess/goaccess.conf'); |
| 64 | + $count = 0; |
| 65 | + |
| 66 | + foreach($goaccess_conf_locs as $goa_loc) { |
| 67 | + if(is_file($goa_loc) && (filesize($goa_loc) > 0)) { |
| 68 | + $goaccess_conf_main = $goa_loc; |
| 69 | + break; |
| 70 | + } else { |
| 71 | + $count++; |
| 72 | + if($count == 2) { |
| 73 | + $app->log("No GoAccess base config found. Make sure that GoAccess is installed and that the goaccess.conf does exist in /etc or /etc/goaccess", LOGLEVEL_ERROR); |
| 74 | + } |
| 75 | + } |
| 76 | + } |
64 | 77 |
|
65 | | - if(!file_exists($goaccess_conf_main) || !isset($goaccess_conf_main)) |
66 | | - { |
67 | | - $app->log("No GoAccess base config found. Make sure that GoAccess is installed and that the goaccess.conf does exist in ".$goaccess_conf_dir.".", LOGLEVEL_WARN); |
68 | | - } |
69 | 78 |
|
70 | 79 | /* Check wether the goaccess binary is in path */ |
71 | | - system('type goaccess', $retval); |
72 | | - if ($retval === 0) { |
| 80 | + system("type goaccess 2>&1>/dev/null", $retval); |
| 81 | + if ($retval === 0) { |
73 | 82 |
|
74 | 83 | foreach($records as $rec) { |
75 | 84 | $yesterday = date('Ymd', strtotime("-1 day", time())); |
@@ -121,7 +130,6 @@ public function onRunJob() { |
121 | 130 | } |
122 | 131 |
|
123 | 132 |
|
124 | | - |
125 | 133 | if(!@is_dir($statsdir)) mkdir($statsdir); |
126 | 134 | $username = escapeshellcmd($rec['system_user']); |
127 | 135 | $groupname = escapeshellcmd($rec['system_group']); |
@@ -171,30 +179,38 @@ public function onRunJob() { |
171 | 179 | if (substr($file, 0, 1) != "." && !is_dir("$statsdir"."/"."$file") && substr($file, 0, 1) != "w" && substr($file, 0, 1) != "i") copy("$statsdir"."/"."$file", "$statsdirold"."$file"); |
172 | 180 | } |
173 | 181 | } |
174 | | - |
175 | | - $app->system->exec_safe("goaccess -f ? --config-file ? --load-from-disk --keep-db-files --db-path=? --output=?", $logfile, $goaccess_conf, $goa_db_dir, $output_html); |
176 | | - |
177 | | - if(!is_file($rec['document_root']."/".$web_folder."/stats/index.php")) { |
178 | | - if(file_exists("/usr/local/ispconfig/server/conf-custom/goaccess_index.php.master")) { |
179 | | - copy("/usr/local/ispconfig/server/conf-custom/goaccess_index.php.master", $rec['document_root']."/".$web_folder."/stats/index.php"); |
180 | | - } else { |
181 | | - copy("/usr/local/ispconfig/server/conf/goaccess_index.php.master", $rec['document_root']."/".$web_folder."/stats/index.php"); |
| 182 | + |
| 183 | + |
| 184 | + $output = shell_exec('goaccess --help'); |
| 185 | + |
| 186 | + if(preg_match('/keep-db-files/', $output)) { |
| 187 | + $app->system->exec_safe("goaccess -f ? --config-file ? --load-from-disk --keep-db-files --db-path=? --output=?", $logfile, $goaccess_conf, $goa_db_dir, $output_html); |
| 188 | + |
| 189 | + if(!is_file($rec['document_root']."/".$web_folder."/stats/index.php")) { |
| 190 | + if(file_exists("/usr/local/ispconfig/server/conf-custom/goaccess_index.php.master")) { |
| 191 | + copy("/usr/local/ispconfig/server/conf-custom/goaccess_index.php.master", $rec['document_root']."/".$web_folder."/stats/index.php"); |
| 192 | + } else { |
| 193 | + copy("/usr/local/ispconfig/server/conf/goaccess_index.php.master", $rec['document_root']."/".$web_folder."/stats/index.php"); |
| 194 | + } |
182 | 195 | } |
183 | | - } |
184 | 196 |
|
185 | | - $app->log('Created GoAccess statistics for ' . $domain, LOGLEVEL_DEBUG); |
186 | | - |
| 197 | + $app->log('Created GoAccess statistics for ' . $domain, LOGLEVEL_DEBUG); |
| 198 | + if(is_file($rec['document_root']."/".$web_folder."/stats/index.php")) { |
| 199 | + chown($rec['document_root']."/".$web_folder."/stats/index.php", $rec['system_user']); |
| 200 | + chgrp($rec['document_root']."/".$web_folder."/stats/index.php", $rec['system_group']); |
| 201 | + } |
| 202 | + |
| 203 | + $app->system->exec_safe('chown -R ?:? ?', $username, $groupname, $statsdir); |
187 | 204 |
|
188 | | - if(is_file($rec['document_root']."/".$web_folder."/stats/index.php")) { |
189 | | - chown($rec['document_root']."/".$web_folder."/stats/index.php", $rec['system_user']); |
190 | | - chgrp($rec['document_root']."/".$web_folder."/stats/index.php", $rec['system_group']); |
| 205 | + } else { |
| 206 | + $app->log("Stats not generated. The GoAccess binary was not compiled with btree support. Please recompile/reinstall GoAccess with btree support!", LOGLEVEL_ERROR); |
191 | 207 | } |
192 | 208 |
|
193 | | - $app->system->exec_safe('chown -R ?:? ?', $username, $groupname, $statsdir); |
| 209 | + unset($output); |
194 | 210 |
|
195 | 211 | } |
196 | 212 | } else { |
197 | | - $app->log("Stats not generated. The GoAccess binary couldn't be found. Make sure that GoAccess is installed and that it is in \$PATH", LOGLEVEL_WARN); |
| 213 | + $app->log("Stats not generated. The GoAccess binary couldn't be found. Make sure that GoAccess is installed and that it is in \$PATH", LOGLEVEL_ERROR); |
198 | 214 | } |
199 | 215 |
|
200 | 216 | parent::onRunJob(); |
|
0 commit comments