diff --git a/server/lib/classes/cron.d/150-goaccess.inc.php b/server/lib/classes/cron.d/150-goaccess.inc.php index fe9e565f5fa304d0efca51d22a7a373f3fe678bc..87c9642b4ecf5f83bdf69c70e5a07cfddd62cefc 100644 --- a/server/lib/classes/cron.d/150-goaccess.inc.php +++ b/server/lib/classes/cron.d/150-goaccess.inc.php @@ -2,6 +2,7 @@ /* Copyright (c) 2013, Marius Cramer, pixcept KG +Copyright (c) 2020, Michael Seevogel All rights reserved. Redistribution and use in source and binary forms, with or without modification, @@ -59,17 +60,25 @@ class cronjob_goaccess extends cronjob { $web_config = $app->getconf->get_server_config($conf['server_id'], 'web'); - $goaccess_conf_dir = '/etc/'; - $goaccess_conf_main = $goaccess_conf_dir . 'goaccess.conf'; + $goaccess_conf_locs = array('/etc/goaccess.conf', '/etc/goaccess/goaccess.conf'); + $count = 0; + + foreach($goaccess_conf_locs as $goa_loc) { + if(is_file($goa_loc) && (filesize($goa_loc) > 0)) { + $goaccess_conf_main = $goa_loc; + break; + } else { + $count++; + if($count == 2) { + $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); + } + } + } - if(!file_exists($goaccess_conf_main) || !isset($goaccess_conf_main)) - { - $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); - } /* Check wether the goaccess binary is in path */ - system('type goaccess', $retval); - if ($retval === 0) { + system("type goaccess 2>&1>/dev/null", $retval); + if ($retval === 0) { foreach($records as $rec) { $yesterday = date('Ymd', strtotime("-1 day", time())); @@ -121,7 +130,6 @@ class cronjob_goaccess extends cronjob { } - if(!@is_dir($statsdir)) mkdir($statsdir); $username = escapeshellcmd($rec['system_user']); $groupname = escapeshellcmd($rec['system_group']); @@ -171,30 +179,38 @@ class cronjob_goaccess extends cronjob { if (substr($file, 0, 1) != "." && !is_dir("$statsdir"."/"."$file") && substr($file, 0, 1) != "w" && substr($file, 0, 1) != "i") copy("$statsdir"."/"."$file", "$statsdirold"."$file"); } } - - $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); - - if(!is_file($rec['document_root']."/".$web_folder."/stats/index.php")) { - if(file_exists("/usr/local/ispconfig/server/conf-custom/goaccess_index.php.master")) { - copy("/usr/local/ispconfig/server/conf-custom/goaccess_index.php.master", $rec['document_root']."/".$web_folder."/stats/index.php"); - } else { - copy("/usr/local/ispconfig/server/conf/goaccess_index.php.master", $rec['document_root']."/".$web_folder."/stats/index.php"); + + + $output = shell_exec('goaccess --help'); + + if(preg_match('/keep-db-files/', $output)) { + $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); + + if(!is_file($rec['document_root']."/".$web_folder."/stats/index.php")) { + if(file_exists("/usr/local/ispconfig/server/conf-custom/goaccess_index.php.master")) { + copy("/usr/local/ispconfig/server/conf-custom/goaccess_index.php.master", $rec['document_root']."/".$web_folder."/stats/index.php"); + } else { + copy("/usr/local/ispconfig/server/conf/goaccess_index.php.master", $rec['document_root']."/".$web_folder."/stats/index.php"); + } } - } - $app->log('Created GoAccess statistics for ' . $domain, LOGLEVEL_DEBUG); - + $app->log('Created GoAccess statistics for ' . $domain, LOGLEVEL_DEBUG); + if(is_file($rec['document_root']."/".$web_folder."/stats/index.php")) { + chown($rec['document_root']."/".$web_folder."/stats/index.php", $rec['system_user']); + chgrp($rec['document_root']."/".$web_folder."/stats/index.php", $rec['system_group']); + } + + $app->system->exec_safe('chown -R ?:? ?', $username, $groupname, $statsdir); - if(is_file($rec['document_root']."/".$web_folder."/stats/index.php")) { - chown($rec['document_root']."/".$web_folder."/stats/index.php", $rec['system_user']); - chgrp($rec['document_root']."/".$web_folder."/stats/index.php", $rec['system_group']); + } else { + $app->log("Stats not generated. The GoAccess binary was not compiled with btree support. Please recompile/reinstall GoAccess with btree support!", LOGLEVEL_ERROR); } - $app->system->exec_safe('chown -R ?:? ?', $username, $groupname, $statsdir); + unset($output); } } else { - $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); + $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); } parent::onRunJob(); diff --git a/server/plugins-available/apache2_plugin.inc.php b/server/plugins-available/apache2_plugin.inc.php index 1bebab55f4e1bdd3c332b494e0c3536e5acfc679..aecab199cd8e3275f0627435c4880e54cbc381a6 100644 --- a/server/plugins-available/apache2_plugin.inc.php +++ b/server/plugins-available/apache2_plugin.inc.php @@ -2986,8 +2986,21 @@ class apache2_plugin { $web_folder = $data['new']['web_folder']; if($data['new']['type'] == 'vhost') $web_folder = 'web'; - $goaccess_conf_dir = '/etc/'; - $goaccess_conf_main = $goaccess_conf_dir.'goaccess.conf'; + $goaccess_conf_locs = array('/etc/goaccess.conf', '/etc/goaccess/goaccess.conf'); + $count = 0; + + foreach($goaccess_conf_locs as $goa_loc) { + if(is_file($goa_loc) && (filesize($goa_loc) > 0)) { + $goaccess_conf_main = $goa_loc; + break; + } else { + $count++; + if($count == 2) { + $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); + } + } + } + if(!is_dir($data['new']['document_root']."/" . $web_folder . "/stats/")) mkdir($data['new']['document_root']."/" . $web_folder . "/stats/.db"); $goaccess_conf = escapeshellcmd($data['new']['document_root'].'/log/goaccess.conf'); diff --git a/server/plugins-available/nginx_plugin.inc.php b/server/plugins-available/nginx_plugin.inc.php index d02811ad93198aa22b7b9dc9492d19541ebb9495..3c59011cbb8c80dcf62e6deb1d7c5eb1d3258bfb 100644 --- a/server/plugins-available/nginx_plugin.inc.php +++ b/server/plugins-available/nginx_plugin.inc.php @@ -2541,13 +2541,25 @@ class nginx_plugin { $web_folder = $data['new']['web_folder']; if($data['new']['type'] == 'vhost') $web_folder = 'web'; - $goaccess_conf_dir = '/etc/'; - $goaccess_conf_main = $goaccess_conf_dir.'goaccess.conf'; + $goaccess_conf_locs = array('/etc/goaccess.conf', '/etc/goaccess/goaccess.conf'); + $count = 0; + + foreach($goaccess_conf_locs as $goa_loc) { + if(is_file($goa_loc) && (filesize($goa_loc) > 0)) { + $goaccess_conf_main = $goa_loc; + break; + } else { + $count++; + if($count == 2) { + $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); + } + } + } + if(!is_dir($data['new']['document_root']."/" . $web_folder . "/stats/")) mkdir($data['new']['document_root']."/" . $web_folder . "/stats/.db"); $goaccess_conf = escapeshellcmd($data['new']['document_root'].'/log/goaccess.conf'); - /* In case that you use a different log format, you should use a custom goaccess.conf which you'll have to put into /usr/local/ispconfig/server/conf-custom/. By default the originaly with GoAccess shipped goaccess.conf from /etc/ will be used along with the log-format value COMBINED.