Skip to content

Commit 362000c

Browse files
author
Till Brehm
committed
Merge branch 'goaccess-adjustments' into 'stable-3.1'
Goaccess adjustments See merge request ispconfig/ispconfig3!1124
2 parents 3b6793d + 2ceb6eb commit 362000c

File tree

4 files changed

+56
-27
lines changed

4 files changed

+56
-27
lines changed

server/conf/goaccess_index.php.master

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ foreach ($goaprev as $key => $value)
6060
$goaccessindex = 'goaindex.html';
6161

6262
$html = "<!DOCTYPE html>\n<html>\n<head>\n<title>Stats</title>\n";
63+
$html .= "<meta charset=\"UTF-8\">\n";
6364
$html .= "<style>\nhtml,body {margin:0px;padding:0px;width:100%;height:100%;background-color: #ccc;}\n";
6465
$html .= "#header\n{\nwidth:100%;margin:0px auto;\nheight:20px;\nposition:fixed;\npadding:4px;\ntext-align:center;\n}\n";
6566
$html .= "iframe {width:100%;height:95%;margin:0px;margin-top:40px;border:0px;padding:0px;}\n</style>\n</head>\n<body>\n";

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

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function onRunJob() {
5656
// Create goaccess statistics
5757
//######################################################################################################
5858

59-
$sql = "SELECT domain_id, domain, document_root, web_folder, type, system_user, system_group, parent_domain_id FROM web_domain WHERE (type = 'vhost' or type = 'vhostsubdomain' or type = 'vhostalias') and stats_type = 'goaccess' AND server_id = ?";
59+
$sql = "SELECT domain_id, sys_groupid, domain, document_root, web_folder, type, system_user, system_group, parent_domain_id FROM web_domain WHERE (type = 'vhost' or type = 'vhostsubdomain' or type = 'vhostalias') and stats_type = 'goaccess' AND server_id = ?";
6060
$records = $app->db->queryAllRecords($sql, $conf['server_id']);
6161

6262
$web_config = $app->getconf->get_server_config($conf['server_id'], 'web');
@@ -130,21 +130,13 @@ public function onRunJob() {
130130
unset($content);
131131
}
132132

133-
/* Update the primary domain name in the title, it could occasionally change */
134-
if(is_file($goaccess_conf) && (filesize($goaccess_conf) > 0)) {
135-
$content = $app->system->file_get_contents($goaccess_conf, true);
136-
$content = preg_replace('/^(#)?html-report-title(.*)/m', "html-report-title $domain", $content);
137-
$app->system->file_put_contents($goaccess_conf, $content, true);
138-
unset($content);
139-
}
140-
141133
$username = $rec['system_user'];
142134
$groupname = $rec['system_group'];
143135
$docroot = $rec['document_root'];
144136

145137
if(!@is_dir($statsdir)) $app->system->mkdirpath($statsdir, 0755, $username, $groupname);
146138

147-
$goa_db_dir = $docroot.'/'.$web_folder.'/stats/.db/';
139+
$goa_db_dir = $docroot.'/log/goaccess_db';
148140
$output_html = $docroot.'/'.$web_folder.'/stats/goaindex.html';
149141
if(!@is_dir($goa_db_dir)) $app->system->mkdirpath($goa_db_dir);
150142

@@ -177,11 +169,6 @@ public function onRunJob() {
177169
$app->system->mkdirpath($statsdirold, 0755, $username, $groupname);
178170
}
179171

180-
// don't rotate db files per month
181-
//rename($goa_db_dir, $statsdirold.'db');
182-
//mkdir($goa_db_dir);
183-
184-
185172
$files = scandir($statsdir);
186173

187174
foreach ($files as $file) {
@@ -199,12 +186,48 @@ public function onRunJob() {
199186
}
200187

201188

202-
/*
203-
* GoAccess removed with 1.4 btree support and supports from this version on only "In-Memory with On-Disk Persitance Storage".
204-
* For versions prior 1.4 you need GoAccess with btree support compiled!
205-
*/
206-
207-
$cust_lang = $conf['language']."_".strtoupper($conf['language']);
189+
$sql_user = "SELECT client_id FROM sys_group WHERE groupid = ?";
190+
$rec_user = $app->db->queryOneRecord($sql_user, $rec['sys_groupid']);
191+
$lang_query = "SELECT country,language FROM client WHERE client_id = ?";
192+
$lang_user = $app->db->queryOneRecord($lang_query, $rec_user['client_id']);
193+
$cust_lang = $lang_user['language']."_".strtoupper($lang_user['language']).".UTF-8";
194+
195+
switch($lang_user['language'])
196+
{
197+
case 'en':
198+
$cust_lang = 'en_UK.UTF-8';
199+
break;
200+
case 'br':
201+
$cust_lang = 'pt_PT.UTF-8';
202+
break;
203+
case 'ca':
204+
$cust_lang = 'en_US.UTF-8';
205+
break;
206+
case 'ja':
207+
$cust_lang = 'ja_JP.UTF-8';
208+
break;
209+
case 'ar':
210+
$cust_lang = 'es_ES.UTF-8';
211+
break;
212+
case 'el':
213+
$cust_lang = 'el_GR.UTF-8';
214+
break;
215+
case 'se':
216+
$cust_lang = 'sv_SE.UTF-8';
217+
break;
218+
case 'dk':
219+
$cust_lang = 'da_DK.UTF-8';
220+
break;
221+
case 'cz':
222+
$cust_lang = 'cs_CZ.UTF-8';
223+
break;
224+
}
225+
226+
227+
/*
228+
* GoAccess removed with 1.4 B+Tree support and supports from this version on only "In-Memory with On-Disk Persistance Storage".
229+
* For versions prior 1.4 you need GoAccess with B+Tree support compiled!
230+
*/
208231

209232
if(version_compare($goaccess_version,1.4) >= 0) {
210233
$app->system->exec_safe("LANG=? goaccess -f ? --config-file ? --restore --persist --db-path=? --output=?", $cust_lang, $logfile, $goaccess_conf, $goa_db_dir, $output_html);
@@ -214,11 +237,16 @@ public function onRunJob() {
214237
if($match[0] == "keep-db-files") {
215238
$app->system->exec_safe("LANG=? goaccess -f ? --config-file ? --load-from-disk --keep-db-files --db-path=? --output=?", $cust_lang, $logfile, $goaccess_conf, $goa_db_dir, $output_html);
216239
} else {
217-
$app->log("Stats not generated. The GoAccess binary was not compiled with btree support. Please recompile/reinstall GoAccess with btree support, or install GoAccess version >= 1.4!", LOGLEVEL_ERROR);
240+
$app->log("Stats couldn't be generated. The GoAccess binary wasn't compiled with B+Tree support. Please recompile/reinstall GoAccess with B+Tree support, or install GoAccess version >= 1.4! (recommended)", LOGLEVEL_ERROR);
218241
}
219242
unset($output);
220243
}
244+
221245
unset($cust_lang);
246+
unset($sql_user);
247+
unset($rec_user);
248+
unset($lang_query);
249+
unset($lang_user);
222250

223251
if(!is_file($rec['document_root']."/".$web_folder."/stats/index.php")) {
224252
if(file_exists("/usr/local/ispconfig/server/conf-custom/goaccess_index.php.master")) {
@@ -237,7 +265,7 @@ public function onRunJob() {
237265
$app->system->exec_safe('chown -R ?:? ?', $username, $groupname, $statsdir);
238266
}
239267
} else {
240-
$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);
268+
$app->log("Stats couldn't be generated. The GoAccess binary couldn't be found. Make sure that GoAccess is installed and that it is in \$PATH", LOGLEVEL_ERROR);
241269
}
242270

243271
}

server/plugins-available/apache2_plugin.inc.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,7 +1894,7 @@ function update($event_name, $data) {
18941894

18951895
if($data['new']['stats_type'] != '') {
18961896
if(!is_dir($data['new']['document_root'].'/' . $web_folder . '/stats')) $app->system->mkdir($data['new']['document_root'].'/' . $web_folder . '/stats');
1897-
$ht_file = "AuthType Basic\nAuthName \"Members Only\"\nAuthUserFile ".$data['new']['document_root']."/web/stats/.htpasswd_stats\nrequire valid-user\nDirectoryIndex index.html index.php\nHeader unset Content-Security-Policy";
1897+
$ht_file = "AuthType Basic\nAuthName \"Members Only\"\nAuthUserFile ".$data['new']['document_root']."/web/stats/.htpasswd_stats\nrequire valid-user\nDirectoryIndex index.html index.php\nHeader unset Content-Security-Policy\n<Files \"goaindex.html\">\nAddDefaultCharset UTF-8\n</Files>\n";
18981898
$app->system->file_put_contents($data['new']['document_root'].'/' . $web_folder . '/stats/.htaccess', $ht_file);
18991899
$app->system->chmod($data['new']['document_root'].'/' . $web_folder . '/stats/.htaccess', 0755);
19001900
unset($ht_file);
@@ -3080,8 +3080,8 @@ private function goaccess_update ($data, $web_config) {
30803080
}
30813081
}
30823082

3083-
if(!is_dir($data['new']['document_root']."/" . $web_folder . "/stats/.db")) $app->system->mkdirpath($data['new']['document_root'] . "/" . $web_folder . "/stats/.db");
3084-
$goaccess_conf = $data['new']['document_root'].'/log/goaccess.conf';
3083+
if(!is_dir($data['new']['document_root'] . "/log/goaccess_db")) $app->system->mkdirpath($data['new']['document_root'] . "/log/goaccess_db");
3084+
$goaccess_conf = $data['new']['document_root'].'/log/goaccess.conf';
30853085

30863086
/*
30873087
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/.

server/plugins-available/nginx_plugin.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2605,7 +2605,7 @@ private function goaccess_update ($data, $web_config) {
26052605
}
26062606
}
26072607

2608-
if(!is_dir($data['new']['document_root']."/" . $web_folder . "/stats/.db")) $app->system->mkdirpath($data['new']['document_root'] . "/" . $web_folder . "/stats/.db");
2608+
if(!is_dir($data['new']['document_root'] . "/log/goaccess_db")) $app->system->mkdirpath($data['new']['document_root'] . "/log/goaccess_db");
26092609
$goaccess_conf = $data['new']['document_root'].'/log/goaccess.conf';
26102610

26112611
/*

0 commit comments

Comments
 (0)