From 57ca2d7110bfbdb375e07b20792de9303e95bb1e Mon Sep 17 00:00:00 2001 From: Michael Seevogel Date: Fri, 28 Aug 2020 15:37:26 +0200 Subject: [PATCH 1/5] small adjustments and some clean up of the GoAccess code --- server/lib/classes/cron.d/150-goaccess.inc.php | 9 ++------- server/plugins-available/apache2_plugin.inc.php | 4 ++-- server/plugins-available/nginx_plugin.inc.php | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/server/lib/classes/cron.d/150-goaccess.inc.php b/server/lib/classes/cron.d/150-goaccess.inc.php index 8f397c819a..8b7e257c10 100644 --- a/server/lib/classes/cron.d/150-goaccess.inc.php +++ b/server/lib/classes/cron.d/150-goaccess.inc.php @@ -144,7 +144,7 @@ class cronjob_goaccess extends cronjob { if(!@is_dir($statsdir)) $app->system->mkdirpath($statsdir, 0755, $username, $groupname); - $goa_db_dir = $docroot.'/'.$web_folder.'/stats/.db/'; + $goa_db_dir = $docroot.'/log/goaccess_db'; $output_html = $docroot.'/'.$web_folder.'/stats/goaindex.html'; if(!@is_dir($goa_db_dir)) $app->system->mkdirpath($goa_db_dir); @@ -177,11 +177,6 @@ class cronjob_goaccess extends cronjob { $app->system->mkdirpath($statsdirold, 0755, $username, $groupname); } - // don't rotate db files per month - //rename($goa_db_dir, $statsdirold.'db'); - //mkdir($goa_db_dir); - - $files = scandir($statsdir); foreach ($files as $file) { @@ -204,7 +199,7 @@ class cronjob_goaccess extends cronjob { * For versions prior 1.4 you need GoAccess with btree support compiled! */ - $cust_lang = $conf['language']."_".strtoupper($conf['language']); + $cust_lang = $conf['language']."_".strtoupper($conf['language'])."UTF-8"; if(version_compare($goaccess_version,1.4) >= 0) { $app->system->exec_safe("LANG=? goaccess -f ? --config-file ? --restore --persist --db-path=? --output=?", $cust_lang, $logfile, $goaccess_conf, $goa_db_dir, $output_html); diff --git a/server/plugins-available/apache2_plugin.inc.php b/server/plugins-available/apache2_plugin.inc.php index f11476b402..4a88c0d874 100644 --- a/server/plugins-available/apache2_plugin.inc.php +++ b/server/plugins-available/apache2_plugin.inc.php @@ -3079,8 +3079,8 @@ class apache2_plugin { } } - if(!is_dir($data['new']['document_root']."/" . $web_folder . "/stats/.db")) $app->system->mkdirpath($data['new']['document_root'] . "/" . $web_folder . "/stats/.db"); - $goaccess_conf = $data['new']['document_root'].'/log/goaccess.conf'; + if(!is_dir($data['new']['document_root'] . "/log/goaccess_db")) $app->system->mkdirpath($data['new']['document_root'] . "/log/goaccess_db"); + $goaccess_conf = $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/. diff --git a/server/plugins-available/nginx_plugin.inc.php b/server/plugins-available/nginx_plugin.inc.php index 4b20a03391..f2626b83ba 100644 --- a/server/plugins-available/nginx_plugin.inc.php +++ b/server/plugins-available/nginx_plugin.inc.php @@ -2604,7 +2604,7 @@ class nginx_plugin { } } - if(!is_dir($data['new']['document_root']."/" . $web_folder . "/stats/.db")) $app->system->mkdirpath($data['new']['document_root'] . "/" . $web_folder . "/stats/.db"); + if(!is_dir($data['new']['document_root'] . "/log/goaccess_db")) $app->system->mkdirpath($data['new']['document_root'] . "/log/goaccess_db"); $goaccess_conf = $data['new']['document_root'].'/log/goaccess.conf'; /* -- GitLab From 81444a91108ee0b8c6f83156a4b09643646c1bdc Mon Sep 17 00:00:00 2001 From: Michael Seevogel Date: Fri, 28 Aug 2020 16:14:12 +0200 Subject: [PATCH 2/5] updating the website title by the cronjob shouldn't be necessary as it should get updated by the server plugin --- server/lib/classes/cron.d/150-goaccess.inc.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/server/lib/classes/cron.d/150-goaccess.inc.php b/server/lib/classes/cron.d/150-goaccess.inc.php index 8b7e257c10..255d646b0b 100644 --- a/server/lib/classes/cron.d/150-goaccess.inc.php +++ b/server/lib/classes/cron.d/150-goaccess.inc.php @@ -130,14 +130,6 @@ class cronjob_goaccess extends cronjob { unset($content); } - /* Update the primary domain name in the title, it could occasionally change */ - if(is_file($goaccess_conf) && (filesize($goaccess_conf) > 0)) { - $content = $app->system->file_get_contents($goaccess_conf, true); - $content = preg_replace('/^(#)?html-report-title(.*)/m', "html-report-title $domain", $content); - $app->system->file_put_contents($goaccess_conf, $content, true); - unset($content); - } - $username = $rec['system_user']; $groupname = $rec['system_group']; $docroot = $rec['document_root']; -- GitLab From 64055d9ac0d13908a76be5e0991b914a9be0f47d Mon Sep 17 00:00:00 2001 From: Michael Seevogel Date: Mon, 31 Aug 2020 17:11:31 +0200 Subject: [PATCH 3/5] try to get utf-8 working --- server/conf/goaccess_index.php.master | 2 + .../lib/classes/cron.d/150-goaccess.inc.php | 56 ++++++++++++++++--- 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/server/conf/goaccess_index.php.master b/server/conf/goaccess_index.php.master index d0a8bf3c84..07a2c0292d 100644 --- a/server/conf/goaccess_index.php.master +++ b/server/conf/goaccess_index.php.master @@ -1,4 +1,5 @@ function load_content(url){var iframe = document.getElementById(\"content\");iframe.src = url;}\n"; @@ -60,6 +61,7 @@ foreach ($goaprev as $key => $value) $goaccessindex = 'goaindex.html'; $html = "\n\n\nStats\n"; +$html .= "\n"; $html .= "\n\n\n"; diff --git a/server/lib/classes/cron.d/150-goaccess.inc.php b/server/lib/classes/cron.d/150-goaccess.inc.php index 255d646b0b..75e5952759 100644 --- a/server/lib/classes/cron.d/150-goaccess.inc.php +++ b/server/lib/classes/cron.d/150-goaccess.inc.php @@ -56,7 +56,7 @@ class cronjob_goaccess extends cronjob { // Create goaccess statistics //###################################################################################################### - $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 = ?"; + $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 = ?"; $records = $app->db->queryAllRecords($sql, $conf['server_id']); $web_config = $app->getconf->get_server_config($conf['server_id'], 'web'); @@ -187,12 +187,49 @@ class cronjob_goaccess extends cronjob { /* - * GoAccess removed with 1.4 btree support and supports from this version on only "In-Memory with On-Disk Persitance Storage". - * For versions prior 1.4 you need GoAccess with btree support compiled! + * GoAccess removed with 1.4 B+Tree support and supports from this version on only "In-Memory with On-Disk Persistance Storage". + * For versions prior 1.4 you need GoAccess with B+Tree support compiled! */ - - $cust_lang = $conf['language']."_".strtoupper($conf['language'])."UTF-8"; + + $sql_user = "SELECT client_id FROM sys_group WHERE groupid = ?"; + $rec_user = $app->db->queryOneRecord($sql_user, $rec['sys_groupid']); + $lang_query = "SELECT country,language FROM client WHERE client_id = ?"; + $lang_user = $app->db->queryOneRecord($lang_query, $rec_user['client_id']); + $cust_lang = $lang_user['language']."_".strtoupper($lang_user['language']).".UTF-8"; + + switch($lang_user['language']) + { + case 'en': + $cust_lang = 'en_UK.UTF-8'; + break; + case 'br': + $cust_lang = 'pt_BR.UTF-8'; + break; + case 'ca': + $cust_lang = 'en_CA.UTF-8'; + break; + case 'ja': + $cust_lang = 'ja_JP.UTF-8'; + break; + case 'ar': + $cust_lang = 'es_AR.UTF-8'; + break; + case 'el': + $cust_lang = 'el_GR.UTF-8'; + break; + case 'se': + $cust_lang = 'sv_SE.UTF-8'; + break; + case 'dk': + $cust_lang = 'da_DK.UTF-8'; + break; + case 'cz': + $cust_lang = 'cs_CZ.UTF-8'; + break; + } + + echo $cust_lang ."\n\n"; if(version_compare($goaccess_version,1.4) >= 0) { $app->system->exec_safe("LANG=? goaccess -f ? --config-file ? --restore --persist --db-path=? --output=?", $cust_lang, $logfile, $goaccess_conf, $goa_db_dir, $output_html); } else { @@ -201,11 +238,16 @@ class cronjob_goaccess extends cronjob { if($match[0] == "keep-db-files") { $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); } else { - $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); + $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); } unset($output); } + unset($cust_lang); + unset($sql_user); + unset($rec_user); + unset($lang_query); + unset($lang_user); if(!is_file($rec['document_root']."/".$web_folder."/stats/index.php")) { if(file_exists("/usr/local/ispconfig/server/conf-custom/goaccess_index.php.master")) { @@ -224,7 +266,7 @@ class cronjob_goaccess extends cronjob { $app->system->exec_safe('chown -R ?:? ?', $username, $groupname, $statsdir); } } 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_ERROR); + $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); } } -- GitLab From a1391774335b2d6e21e6ad277bbba8b8e3200e72 Mon Sep 17 00:00:00 2001 From: Michael Seevogel Date: Tue, 1 Sep 2020 11:19:10 +0200 Subject: [PATCH 4/5] fixed utf8 by adding appropriate files directive to htaccess --- server/conf/goaccess_index.php.master | 3 +-- server/lib/classes/cron.d/150-goaccess.inc.php | 10 ++++------ server/plugins-available/apache2_plugin.inc.php | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/server/conf/goaccess_index.php.master b/server/conf/goaccess_index.php.master index 07a2c0292d..ecb91c7a9c 100644 --- a/server/conf/goaccess_index.php.master +++ b/server/conf/goaccess_index.php.master @@ -1,5 +1,4 @@ function load_content(url){var iframe = document.getElementById(\"content\");iframe.src = url;}\n"; @@ -61,7 +60,7 @@ foreach ($goaprev as $key => $value) $goaccessindex = 'goaindex.html'; $html = "\n\n\nStats\n"; -$html .= "\n"; +$html .= "\n"; $html .= "\n\n\n"; diff --git a/server/lib/classes/cron.d/150-goaccess.inc.php b/server/lib/classes/cron.d/150-goaccess.inc.php index 75e5952759..c0ef85f9a6 100644 --- a/server/lib/classes/cron.d/150-goaccess.inc.php +++ b/server/lib/classes/cron.d/150-goaccess.inc.php @@ -191,8 +191,7 @@ class cronjob_goaccess extends cronjob { * For versions prior 1.4 you need GoAccess with B+Tree support compiled! */ - - $sql_user = "SELECT client_id FROM sys_group WHERE groupid = ?"; + $sql_user = "SELECT client_id FROM sys_group WHERE groupid = ?"; $rec_user = $app->db->queryOneRecord($sql_user, $rec['sys_groupid']); $lang_query = "SELECT country,language FROM client WHERE client_id = ?"; $lang_user = $app->db->queryOneRecord($lang_query, $rec_user['client_id']); @@ -204,16 +203,16 @@ class cronjob_goaccess extends cronjob { $cust_lang = 'en_UK.UTF-8'; break; case 'br': - $cust_lang = 'pt_BR.UTF-8'; + $cust_lang = 'pt_PT.UTF-8'; break; case 'ca': - $cust_lang = 'en_CA.UTF-8'; + $cust_lang = 'en_US.UTF-8'; break; case 'ja': $cust_lang = 'ja_JP.UTF-8'; break; case 'ar': - $cust_lang = 'es_AR.UTF-8'; + $cust_lang = 'es_ES.UTF-8'; break; case 'el': $cust_lang = 'el_GR.UTF-8'; @@ -229,7 +228,6 @@ class cronjob_goaccess extends cronjob { break; } - echo $cust_lang ."\n\n"; if(version_compare($goaccess_version,1.4) >= 0) { $app->system->exec_safe("LANG=? goaccess -f ? --config-file ? --restore --persist --db-path=? --output=?", $cust_lang, $logfile, $goaccess_conf, $goa_db_dir, $output_html); } else { diff --git a/server/plugins-available/apache2_plugin.inc.php b/server/plugins-available/apache2_plugin.inc.php index 4a88c0d874..70976a6500 100644 --- a/server/plugins-available/apache2_plugin.inc.php +++ b/server/plugins-available/apache2_plugin.inc.php @@ -1893,7 +1893,7 @@ class apache2_plugin { if($data['new']['stats_type'] != '') { if(!is_dir($data['new']['document_root'].'/' . $web_folder . '/stats')) $app->system->mkdir($data['new']['document_root'].'/' . $web_folder . '/stats'); - $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"; + $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\nAddDefaultCharset UTF-8\n\n"; $app->system->file_put_contents($data['new']['document_root'].'/' . $web_folder . '/stats/.htaccess', $ht_file); $app->system->chmod($data['new']['document_root'].'/' . $web_folder . '/stats/.htaccess', 0755); unset($ht_file); -- GitLab From 2ceb6ebc025915dcc1849edddab81a4c0c82cde0 Mon Sep 17 00:00:00 2001 From: Michael Seevogel Date: Tue, 1 Sep 2020 14:19:19 +0200 Subject: [PATCH 5/5] relocated comment --- server/lib/classes/cron.d/150-goaccess.inc.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/server/lib/classes/cron.d/150-goaccess.inc.php b/server/lib/classes/cron.d/150-goaccess.inc.php index c0ef85f9a6..7bdbbeb03b 100644 --- a/server/lib/classes/cron.d/150-goaccess.inc.php +++ b/server/lib/classes/cron.d/150-goaccess.inc.php @@ -186,11 +186,6 @@ class cronjob_goaccess extends cronjob { } - /* - * GoAccess removed with 1.4 B+Tree support and supports from this version on only "In-Memory with On-Disk Persistance Storage". - * For versions prior 1.4 you need GoAccess with B+Tree support compiled! - */ - $sql_user = "SELECT client_id FROM sys_group WHERE groupid = ?"; $rec_user = $app->db->queryOneRecord($sql_user, $rec['sys_groupid']); $lang_query = "SELECT country,language FROM client WHERE client_id = ?"; @@ -228,6 +223,12 @@ class cronjob_goaccess extends cronjob { break; } + + /* + * GoAccess removed with 1.4 B+Tree support and supports from this version on only "In-Memory with On-Disk Persistance Storage". + * For versions prior 1.4 you need GoAccess with B+Tree support compiled! + */ + if(version_compare($goaccess_version,1.4) >= 0) { $app->system->exec_safe("LANG=? goaccess -f ? --config-file ? --restore --persist --db-path=? --output=?", $cust_lang, $logfile, $goaccess_conf, $goa_db_dir, $output_html); } else { -- GitLab