Skip to content

Commit 6b4966d

Browse files
committed
fixed GoAccess config detection
1 parent fa064a7 commit 6b4966d

File tree

3 files changed

+71
-30
lines changed

3 files changed

+71
-30
lines changed

server/lib/classes/cron.d/150-goaccess.inc.php

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
/*
44
Copyright (c) 2013, Marius Cramer, pixcept KG
5+
Copyright (c) 2020, Michael Seevogel
56
All rights reserved.
67
78
Redistribution and use in source and binary forms, with or without modification,
@@ -59,17 +60,25 @@ public function onRunJob() {
5960

6061
$web_config = $app->getconf->get_server_config($conf['server_id'], 'web');
6162

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+
}
6477

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-
}
6978

7079
/* 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) {
7382

7483
foreach($records as $rec) {
7584
$yesterday = date('Ymd', strtotime("-1 day", time()));
@@ -121,7 +130,6 @@ public function onRunJob() {
121130
}
122131

123132

124-
125133
if(!@is_dir($statsdir)) mkdir($statsdir);
126134
$username = escapeshellcmd($rec['system_user']);
127135
$groupname = escapeshellcmd($rec['system_group']);
@@ -171,30 +179,38 @@ public function onRunJob() {
171179
if (substr($file, 0, 1) != "." && !is_dir("$statsdir"."/"."$file") && substr($file, 0, 1) != "w" && substr($file, 0, 1) != "i") copy("$statsdir"."/"."$file", "$statsdirold"."$file");
172180
}
173181
}
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+
}
182195
}
183-
}
184196

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);
187204

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);
191207
}
192208

193-
$app->system->exec_safe('chown -R ?:? ?', $username, $groupname, $statsdir);
209+
unset($output);
194210

195211
}
196212
} 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);
198214
}
199215

200216
parent::onRunJob();

server/plugins-available/apache2_plugin.inc.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2986,8 +2986,21 @@ private function goaccess_update ($data, $web_config) {
29862986
$web_folder = $data['new']['web_folder'];
29872987
if($data['new']['type'] == 'vhost') $web_folder = 'web';
29882988

2989-
$goaccess_conf_dir = '/etc/';
2990-
$goaccess_conf_main = $goaccess_conf_dir.'goaccess.conf';
2989+
$goaccess_conf_locs = array('/etc/goaccess.conf', '/etc/goaccess/goaccess.conf');
2990+
$count = 0;
2991+
2992+
foreach($goaccess_conf_locs as $goa_loc) {
2993+
if(is_file($goa_loc) && (filesize($goa_loc) > 0)) {
2994+
$goaccess_conf_main = $goa_loc;
2995+
break;
2996+
} else {
2997+
$count++;
2998+
if($count == 2) {
2999+
$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);
3000+
}
3001+
}
3002+
}
3003+
29913004

29923005
if(!is_dir($data['new']['document_root']."/" . $web_folder . "/stats/")) mkdir($data['new']['document_root']."/" . $web_folder . "/stats/.db");
29933006
$goaccess_conf = escapeshellcmd($data['new']['document_root'].'/log/goaccess.conf');

server/plugins-available/nginx_plugin.inc.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,13 +2541,25 @@ private function goaccess_update ($data, $web_config) {
25412541
$web_folder = $data['new']['web_folder'];
25422542
if($data['new']['type'] == 'vhost') $web_folder = 'web';
25432543

2544-
$goaccess_conf_dir = '/etc/';
2545-
$goaccess_conf_main = $goaccess_conf_dir.'goaccess.conf';
2544+
$goaccess_conf_locs = array('/etc/goaccess.conf', '/etc/goaccess/goaccess.conf');
2545+
$count = 0;
2546+
2547+
foreach($goaccess_conf_locs as $goa_loc) {
2548+
if(is_file($goa_loc) && (filesize($goa_loc) > 0)) {
2549+
$goaccess_conf_main = $goa_loc;
2550+
break;
2551+
} else {
2552+
$count++;
2553+
if($count == 2) {
2554+
$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);
2555+
}
2556+
}
2557+
}
2558+
25462559

25472560
if(!is_dir($data['new']['document_root']."/" . $web_folder . "/stats/")) mkdir($data['new']['document_root']."/" . $web_folder . "/stats/.db");
25482561
$goaccess_conf = escapeshellcmd($data['new']['document_root'].'/log/goaccess.conf');
25492562

2550-
25512563
/*
25522564
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/.
25532565
By default the originaly with GoAccess shipped goaccess.conf from /etc/ will be used along with the log-format value COMBINED.

0 commit comments

Comments
 (0)