Skip to content

Commit 73d3a22

Browse files
committed
misc adjustments
1 parent 81d93e4 commit 73d3a22

File tree

4 files changed

+159
-107
lines changed

4 files changed

+159
-107
lines changed
16 KB
Binary file not shown.

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

Lines changed: 60 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function onBeforeRun() {
5151
public function onRunJob() {
5252
global $app, $conf;
5353

54+
5455
//######################################################################################################
5556
// Create goaccess statistics
5657
//######################################################################################################
@@ -76,7 +77,7 @@ public function onRunJob() {
7677
}
7778

7879

79-
/* Check wether the goaccess binary is in path */
80+
/* Check if goaccess binary is in path */
8081
system("type goaccess 2>&1>/dev/null", $retval);
8182
if ($retval === 0) {
8283

@@ -113,40 +114,43 @@ public function onRunJob() {
113114
*/
114115

115116
if(file_exists("/usr/local/ispconfig/server/conf-custom/goaccess.conf.master") && (!file_exists($goaccess_conf))) {
116-
copy("/usr/local/ispconfig/server/conf-custom/goaccess.conf.master", $goaccess_conf);
117+
$app->system->copy("/usr/local/ispconfig/server/conf-custom/goaccess.conf.master", $goaccess_conf);
117118
} elseif(!file_exists($goaccess_conf)) {
118119
/*
119120
By default the goaccess.conf should get copied by the webserver plugin but in case it wasn't, or it got deleted by accident we gonna copy it again to the destination dir.
120121
Also there was no /usr/local/ispconfig/server/conf-custom/goaccess.conf.master, so we gonna use /etc/goaccess.conf as the base conf.
121122
*/
122-
copy($goaccess_conf_main, $goaccess_conf);
123-
file_put_contents($goaccess_conf, preg_replace('/^(#)?log-format COMBINED/m', "log-format COMBINED", file_get_contents($goaccess_conf)));
123+
124+
$app->system->copy($goaccess_conf_main, $goaccess_conf);
125+
$content = $app->system->file_get_contents($goaccess_conf, true);
126+
$content = preg_replace('/^(#)?log-format COMBINED/m', "log-format COMBINED", $content);
127+
$app->system->file_put_contents($goaccess_conf, $content, true);
128+
unset($content);
124129
}
125130

126131
/* Update the primary domain name in the title, it could occasionally change */
127132
if(is_file($goaccess_conf) && (filesize($goaccess_conf) > 0)) {
128-
$goaccess_content = file_get_contents($goaccess_conf);
129-
file_put_contents($goaccess_conf, preg_replace('/^(#)?html-report-title(.*)?/m', "html-report-title $domain", file_get_contents($goaccess_conf)));
130-
unset($goaccess_content);
133+
$content = $app->system->file_get_contents($goaccess_conf, true);
134+
$content = preg_replace('/^(#)?html-report-title(.*)/m', "html-report-title $domain", $content);
135+
$app->system->file_put_contents($goaccess_conf, $content, true);
136+
unset($content);
131137
}
132138

139+
$username = $rec['system_user'];
140+
$groupname = $rec['system_group'];
141+
$docroot = $rec['document_root'];
133142

134-
135-
if(!@is_dir($statsdir)) mkdir($statsdir);
136-
$username = $rec['system_user'];
137-
$groupname = $rec['system_group'];
138-
$docroot = $rec['document_root'];
143+
if(!@is_dir($statsdir)) $app->system->mkdirpath($statsdir, 0755, $username, $groupname);
139144

140145
$goa_db_dir = $docroot.'/'.$web_folder.'/stats/.db/';
141146
$output_html = $docroot.'/'.$web_folder.'/stats/goaindex.html';
142-
if(!@is_dir($goa_db_dir)) mkdir($goa_db_dir);
147+
if(!@is_dir($goa_db_dir)) $app->system->mkdirpath($goa_db_dir, 0755, $username, $groupname);
143148

144149
if(is_link('/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log')) unlink('/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log');
145150
symlink($logfile, '/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log');
146151

147152

148-
chown($statsdir, $username);
149-
chgrp($statsdir, $groupname);
153+
$app->system->exec_safe('chown -R ?:? ?', $username, $groupname, $statsdir);
150154

151155
$goamonth = date("n");
152156
$goayear = date("Y");
@@ -159,7 +163,6 @@ public function onRunJob() {
159163
}
160164
}
161165

162-
163166
if (date("d") == 2) {
164167
$goamonth = date("m")-1;
165168
if (date("m") == 1) {
@@ -170,7 +173,7 @@ public function onRunJob() {
170173
$statsdirold = $statsdir."/".$goayear."-".$goamonth."/";
171174

172175
if(!is_dir($statsdirold)) {
173-
mkdir($statsdirold);
176+
$app->system->mkdirpath($statsdirold, 0755, $username, $groupname);
174177
}
175178

176179
// don't rotate db files per month
@@ -180,39 +183,57 @@ public function onRunJob() {
180183
$files = scandir($statsdir);
181184

182185
foreach ($files as $file) {
183-
if (substr($file, 0, 1) != "." && !is_dir("$statsdir"."/"."$file") && substr($file, 0, 1) != "w" && substr($file, 0, 1) != "i") copy("$statsdir"."/"."$file", "$statsdirold"."$file");
186+
if (substr($file, 0, 1) != "." && !is_dir("$statsdir"."/"."$file") && substr($file, 0, 1) != "w" && substr($file, 0, 1) != "i") $app->system->copy("$statsdir"."/"."$file", "$statsdirold"."$file");
184187
}
185188
}
186189

190+
// Get the GoAccess version
191+
$match = array();
187192

188-
$output = shell_exec('goaccess --help');
189-
190-
if(preg_match('/keep-db-files/', $output)) {
191-
$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);
192-
193-
if(!is_file($rec['document_root']."/".$web_folder."/stats/index.php")) {
194-
if(file_exists("/usr/local/ispconfig/server/conf-custom/goaccess_index.php.master")) {
195-
copy("/usr/local/ispconfig/server/conf-custom/goaccess_index.php.master", $rec['document_root']."/".$web_folder."/stats/index.php");
196-
} else {
197-
copy("/usr/local/ispconfig/server/conf/goaccess_index.php.master", $rec['document_root']."/".$web_folder."/stats/index.php");
198-
}
199-
}
193+
$goaccess_version = $app->system->system_safe('goaccess --version 2>&1');
200194

201-
$app->log('Created GoAccess statistics for ' . $domain, LOGLEVEL_DEBUG);
202-
if(is_file($rec['document_root']."/".$web_folder."/stats/index.php")) {
203-
chown($rec['document_root']."/".$web_folder."/stats/index.php", $rec['system_user']);
204-
chgrp($rec['document_root']."/".$web_folder."/stats/index.php", $rec['system_group']);
205-
}
195+
if(preg_match('/[0-9]\.[0-9]{1,2}/', $goaccess_version, $match)) {
196+
$goaccess_version = $match[0];
197+
}
206198

207-
$app->system->exec_safe('chown -R ?:? ?', $username, $groupname, $statsdir);
208199

200+
/*
201+
* GoAccess removed with 1.4 btree support and supports from this version on only "In-Memory with On-Disk Persitance Storage".
202+
* For versions prior 1.4 you need GoAccess with btree support compiled!
203+
*/
204+
205+
$cust_lang = $conf['language']."_".strtoupper($conf['language']);
206+
207+
if(version_compare($goaccess_version,1.4) >= 0) {
208+
$app->system->exec_safe("LANG=? goaccess -f ? --config-file ? --restore --persist --db-path=? --output=?", $cust_lang, $logfile, $goaccess_conf, $goa_db_dir, $output_html);
209209
} else {
210-
$app->log("Stats not generated. The GoAccess binary was not compiled with btree support. Please recompile/reinstall GoAccess with btree support!", LOGLEVEL_ERROR);
210+
$output = $app->system->system_safe('goaccess --help');
211+
if(preg_match('/keep-db-files/', $output)) {
212+
$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);
213+
} else {
214+
$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);
215+
}
216+
unset($output);
211217
}
218+
unset($cust_lang);
219+
220+
if(!is_file($rec['document_root']."/".$web_folder."/stats/index.php")) {
221+
if(file_exists("/usr/local/ispconfig/server/conf-custom/goaccess_index.php.master")) {
222+
$app->system->copy("/usr/local/ispconfig/server/conf-custom/goaccess_index.php.master", $rec['document_root']."/".$web_folder."/stats/index.php");
223+
} else {
224+
$app->system->copy("/usr/local/ispconfig/server/conf/goaccess_index.php.master", $rec['document_root']."/".$web_folder."/stats/index.php");
225+
}
226+
}
227+
228+
$app->log('Created GoAccess statistics for ' . $domain, LOGLEVEL_DEBUG);
229+
if(is_file($rec['document_root']."/".$web_folder."/stats/index.php")) {
230+
chown($rec['document_root']."/".$web_folder."/stats/index.php", $rec['system_user']);
231+
chgrp($rec['document_root']."/".$web_folder."/stats/index.php", $rec['system_group']);
232+
}
212233

213-
unset($output);
234+
$app->system->exec_safe('chown -R ?:? ?', $username, $groupname, $statsdir);
235+
}
214236

215-
}
216237
} else {
217238
$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);
218239
}

server/plugins-available/apache2_plugin.inc.php

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,7 +1868,6 @@ function update($event_name, $data) {
18681868
$this->goaccess_update($data, $web_config);
18691869
}
18701870

1871-
18721871
//* Remove Stats-Folder when Statistics set to none
18731872
if($data['new']['stats_type'] == '' && ($data['new']['type'] == 'vhost' || $data['new']['type'] == 'vhostsubdomain' || $data['new']['type'] == 'vhostalias')) {
18741873
$app->file->removeDirectory($data['new']['document_root'].'/web/stats');
@@ -2282,6 +2281,11 @@ function delete($event_name, $data) {
22822281
$this->awstats_delete($data, $web_config);
22832282
}
22842283

2284+
//* Remove the GoAccess configuration file
2285+
if($data['old']['stats_type'] == 'goaccess') {
2286+
$this->goaccess_delete($data, $web_config);
2287+
}
2288+
22852289
if($data['old']['type'] == 'vhostsubdomain' || $data['old']['type'] == 'vhostalias') {
22862290
$app->system->web_folder_protection($parent_web_document_root, true);
22872291
}
@@ -2979,6 +2983,18 @@ private function awstats_update ($data, $web_config) {
29792983
}
29802984
}
29812985

2986+
//* Delete the awstats configuration file
2987+
private function awstats_delete ($data, $web_config) {
2988+
global $app;
2989+
2990+
$awstats_conf_dir = $web_config['awstats_conf_dir'];
2991+
2992+
if ( @is_file($awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf') ) {
2993+
$app->system->unlink($awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf');
2994+
$app->log('Removed AWStats config file: '.$awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf', LOGLEVEL_DEBUG);
2995+
}
2996+
}
2997+
29822998
//* Update the GoAccess configuration file
29832999
private function goaccess_update ($data, $web_config) {
29843000
global $app;
@@ -2996,34 +3012,44 @@ private function goaccess_update ($data, $web_config) {
29963012
} else {
29973013
$count++;
29983014
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);
3015+
$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_WARN);
30003016
}
30013017
}
30023018
}
30033019

3004-
3005-
if(!is_dir($data['new']['document_root']."/" . $web_folder . "/stats/")) mkdir($data['new']['document_root']."/" . $web_folder . "/stats/.db");
3006-
$goaccess_conf = escapeshellcmd($data['new']['document_root'].'/log/goaccess.conf');
3007-
3020+
if(!is_dir($data['new']['document_root']."/" . $web_folder . "/stats/")) $app->system->mkdirpath($data['new']['document_root']."/" . $web_folder . "/stats/.db");
3021+
$goaccess_conf = $data['new']['document_root'].'/log/goaccess.conf';
30083022

30093023
/*
30103024
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/.
30113025
By default the originaly with GoAccess shipped goaccess.conf from /etc/ will be used along with the log-format value COMBINED.
3012-
*/
3013-
if(file_exists("/usr/local/ispconfig/server/conf-custom/goaccess.conf.master") && (!file_exists($goaccess_conf))) {
3014-
copy("/usr/local/ispconfig/server/conf-custom/goaccess.conf.master", $goaccess_conf);
3026+
*/
3027+
3028+
if(file_exists("/usr/local/ispconfig/server/conf-custom/goaccess.conf.master")) {
3029+
$app->system->copy("/usr/local/ispconfig/server/conf-custom/goaccess_index.php.master", $goaccess_conf);
3030+
30153031
} elseif(!file_exists($goaccess_conf)) {
3016-
/*
3032+
3033+
/*
30173034
By default the goaccess.conf should get copied by the webserver plugin but in case it wasn't, or it got deleted by accident we gonna copy it again to the destination dir.
30183035
Also there was no /usr/local/ispconfig/server/conf-custom/goaccess.conf.master, so we gonna use /etc/goaccess.conf as the base conf.
3019-
*/
3020-
copy($goaccess_conf_main, $goaccess_conf);
3021-
file_put_contents($goaccess_conf, preg_replace('/^(#)?log-format COMBINED/m', "log-format COMBINED", file_get_contents($goaccess_conf)));
3036+
*/
3037+
3038+
$app->system->copy($goaccess_conf_main, $goaccess_conf);
3039+
$content = $app->system->file_get_contents($goaccess_conf, true);
3040+
$content = preg_replace('/^(#)?log-format COMBINED/m', "log-format COMBINED", $content);
3041+
$app->system->file_put_contents($goaccess_conf, $content, true);
3042+
unset($content);
3043+
30223044
}
30233045

30243046
if(file_exists($goaccess_conf)) {
3025-
$domain = escapeshellcmd($data['new']['domain']);
3026-
file_put_contents($goaccess_conf, preg_replace('/^(#)?html-report-title(.*)/m', "html-report-title $domain", file_get_contents($goaccess_conf)));
3047+
$domain = $data['new']['domain'];
3048+
$content = $app->system->file_get_contents($goaccess_conf, true);
3049+
$content = preg_replace('/^(#)?html-report-title(.*)/m', "html-report-title $domain", $content);
3050+
$app->system->file_put_contents($goaccess_conf, $content, true);
3051+
unset($content);
3052+
30273053
}
30283054

30293055
if(is_file($goaccess_conf) && (filesize($goaccess_conf) > 0)) {
@@ -3040,28 +3066,15 @@ private function goaccess_update ($data, $web_config) {
30403066
}
30413067
}
30423068

3043-
//* Delete the GoAccess configuration file
3044-
private function goaccess_delete ($data, $web_config) {
3045-
global $app;
3046-
3047-
$goaccess_conf = escapeshellcmd($data['new']['document_root'].'/log/goaccess.conf');
3048-
3049-
if ( @is_file($goaccess_conf) ) {
3050-
$app->system->unlink($goaccess_conf);
3051-
$app->log('Removed GoAccess config file: '.$goaccess_conf, LOGLEVEL_DEBUG);
3052-
}
3053-
}
3054-
3055-
3056-
//* Delete the awstats configuration file
3057-
private function awstats_delete ($data, $web_config) {
3069+
//* Delete the GoAccess configuration file
3070+
private function goaccess_delete ($data, $web_config) {
30583071
global $app;
30593072

3060-
$awstats_conf_dir = $web_config['awstats_conf_dir'];
3073+
$goaccess_conf = $data['old']['document_root'] . "/log/goaccess.conf";
30613074

3062-
if ( @is_file($awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf') ) {
3063-
$app->system->unlink($awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf');
3064-
$app->log('Removed AWStats config file: '.$awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf', LOGLEVEL_DEBUG);
3075+
if ( @is_file($goaccess_conf) ) {
3076+
$app->system->unlink($goaccess_conf);
3077+
$app->log('Removed GoAccess config file: '.$goaccess_conf, LOGLEVEL_DEBUG);
30653078
}
30663079
}
30673080

0 commit comments

Comments
 (0)