Skip to content

Commit fa064a7

Browse files
committed
missed nginx_plugin code in previous commit
1 parent d3c8533 commit fa064a7

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

server/plugins-available/nginx_plugin.inc.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2532,6 +2532,71 @@ function _create_web_folder_auth_configuration($website){
25322532
//$app->services->restartServiceDelayed('httpd','reload');
25332533
}
25342534

2535+
2536+
2537+
//* Update the GoAccess configuration file
2538+
private function goaccess_update ($data, $web_config) {
2539+
global $app;
2540+
2541+
$web_folder = $data['new']['web_folder'];
2542+
if($data['new']['type'] == 'vhost') $web_folder = 'web';
2543+
2544+
$goaccess_conf_dir = '/etc/';
2545+
$goaccess_conf_main = $goaccess_conf_dir.'goaccess.conf';
2546+
2547+
if(!is_dir($data['new']['document_root']."/" . $web_folder . "/stats/")) mkdir($data['new']['document_root']."/" . $web_folder . "/stats/.db");
2548+
$goaccess_conf = escapeshellcmd($data['new']['document_root'].'/log/goaccess.conf');
2549+
2550+
2551+
/*
2552+
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/.
2553+
By default the originaly with GoAccess shipped goaccess.conf from /etc/ will be used along with the log-format value COMBINED.
2554+
*/
2555+
if(file_exists("/usr/local/ispconfig/server/conf-custom/goaccess.conf.master") && (!file_exists($goaccess_conf))) {
2556+
copy("/usr/local/ispconfig/server/conf-custom/goaccess.conf.master", $goaccess_conf);
2557+
} elseif(!file_exists($goaccess_conf)) {
2558+
/*
2559+
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.
2560+
Also there was no /usr/local/ispconfig/server/conf-custom/goaccess.conf.master, so we gonna use /etc/goaccess.conf as the base conf.
2561+
*/
2562+
copy($goaccess_conf_main, $goaccess_conf);
2563+
file_put_contents($goaccess_conf, preg_replace('/^(#)?log-format COMBINED/m', "log-format COMBINED", file_get_contents($goaccess_conf)));
2564+
}
2565+
2566+
if(file_exists($goaccess_conf)) {
2567+
$domain = escapeshellcmd($data['new']['domain']);
2568+
file_put_contents($goaccess_conf, preg_replace('/^(#)?html-report-title(.*)/m', "html-report-title $domain", file_get_contents($goaccess_conf)));
2569+
}
2570+
2571+
if(is_file($goaccess_conf) && (filesize($goaccess_conf) > 0)) {
2572+
$app->log('Created GoAccess config file: '.$goaccess_conf, LOGLEVEL_DEBUG);
2573+
} else {
2574+
$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);
2575+
}
2576+
2577+
if(is_file($data['new']['document_root']."/" . $web_folder . "/stats/index.html")) $app->system->unlink($data['new']['document_root']."/" . $web_folder . "/stats/index.html");
2578+
if(file_exists("/usr/local/ispconfig/server/conf-custom/goaccess_index.php.master")) {
2579+
$app->system->copy("/usr/local/ispconfig/server/conf-custom/goaccess_index.php.master", $data['new']['document_root']."/" . $web_folder . "/stats/index.php");
2580+
} else {
2581+
$app->system->copy("/usr/local/ispconfig/server/conf/goaccess_index.php.master", $data['new']['document_root']."/" . $web_folder . "/stats/index.php");
2582+
}
2583+
}
2584+
2585+
//* Delete the GoAccess configuration file
2586+
private function goaccess_delete ($data, $web_config) {
2587+
global $app;
2588+
2589+
$goaccess_conf = escapeshellcmd($data['new']['document_root'].'/log/goaccess.conf');
2590+
2591+
if ( @is_file($goaccess_conf) ) {
2592+
$app->system->unlink($goaccess_conf);
2593+
$app->log('Removed GoAccess config file: '.$goaccess_conf, LOGLEVEL_DEBUG);
2594+
}
2595+
}
2596+
2597+
2598+
2599+
25352600
//* Update the awstats configuration file
25362601
private function awstats_update ($data, $web_config) {
25372602
global $app;

0 commit comments

Comments
 (0)