From 717c8258f3cfccc7496a685291653c74ea912950 Mon Sep 17 00:00:00 2001 From: Alex Phillips Date: Thu, 3 Feb 2022 09:12:39 -0500 Subject: [PATCH 1/5] make access.log file configurable via ENV variable --- root/dashboard/goaccess.conf | 2 +- root/dashboard/www/index.php | 1 + root/etc/cont-init.d/98-dashboard-config | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/root/dashboard/goaccess.conf b/root/dashboard/goaccess.conf index 268a554..5861081 100644 --- a/root/dashboard/goaccess.conf +++ b/root/dashboard/goaccess.conf @@ -332,7 +332,7 @@ with-mouse false # Specify the path to the input log file. If set, it will take # priority over -f from the command line. # -log-file /config/log/nginx/access.log +#log-file /config/log/nginx/access.log # Send all debug messages to the specified file. # diff --git a/root/dashboard/www/index.php b/root/dashboard/www/index.php index 4be246f..7a5ff22 100644 --- a/root/dashboard/www/index.php +++ b/root/dashboard/www/index.php @@ -252,6 +252,7 @@ $geodb = ''; endif; + $access_log = getenv("GOACCESS_LOG_FILE") ?: "/config/log/nginx/access.log"; $goaccess = shell_exec("/usr/local/bin/goaccess -a -o html --config-file=/dashboard/goaccess.conf ".$geodb); $goaccess = str_replace("Server Statistics", "<title>SWAG Dashboard", $goaccess); $goaccess = str_replace("<h1 class='h-dashboard'>", "<h1>", $goaccess); diff --git a/root/etc/cont-init.d/98-dashboard-config b/root/etc/cont-init.d/98-dashboard-config index ac11c0e..d238501 100644 --- a/root/etc/cont-init.d/98-dashboard-config +++ b/root/etc/cont-init.d/98-dashboard-config @@ -22,6 +22,10 @@ if [ "$(sed -nE 's|## Version ([0-9]{4}\/[0-9]{2}\/[0-9]{2}).*|\1|p' /dashboard/ echo "**** Compare the changes using the sample file: /config/nginx/proxy-confs/dashboard.subdomain.conf.sample" fi +# preserve environment variables in PHP +sed -E -i 's/^clear_env =.*$/clear_env = no/g' /config/php/www2.conf +grep -qxF 'clear_env = no' /config/php/www2.conf || echo 'clear_env = no' >> /config/php/www2.conf + # permissions chown -R abc:abc \ /dashboard \ From 52aaaa7741715df1fc245e01b79295c51ec37d82 Mon Sep 17 00:00:00 2001 From: Alex Phillips <ahp118@gmail.com> Date: Thu, 3 Feb 2022 09:17:39 -0500 Subject: [PATCH 2/5] pass in log file to php exec --- root/dashboard/www/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/root/dashboard/www/index.php b/root/dashboard/www/index.php index 7a5ff22..e46debb 100644 --- a/root/dashboard/www/index.php +++ b/root/dashboard/www/index.php @@ -253,7 +253,7 @@ endif; $access_log = getenv("GOACCESS_LOG_FILE") ?: "/config/log/nginx/access.log"; - $goaccess = shell_exec("/usr/local/bin/goaccess -a -o html --config-file=/dashboard/goaccess.conf ".$geodb); + $goaccess = shell_exec("/usr/local/bin/goaccess -a -o html -f $access_log --config-file=/dashboard/goaccess.conf ".$geodb); $goaccess = str_replace("<title>Server Statistics", "<title>SWAG Dashboard", $goaccess); $goaccess = str_replace("<h1 class='h-dashboard'>", "<h1>", $goaccess); $goaccess = str_replace("<i class='fa fa-tachometer'></i>", "<img src='/icon.svg' width='32' height='32'> SWAG ", $goaccess); From 52b59d4dcef538d31a8697883e4580f0f023c73d Mon Sep 17 00:00:00 2001 From: Alex Phillips <ahp118@gmail.com> Date: Thu, 3 Feb 2022 09:38:52 -0500 Subject: [PATCH 3/5] use optional volume mount instead of env --- root/dashboard/www/index.php | 4 ++-- root/etc/cont-init.d/98-dashboard-config | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/root/dashboard/www/index.php b/root/dashboard/www/index.php index e46debb..397719f 100644 --- a/root/dashboard/www/index.php +++ b/root/dashboard/www/index.php @@ -252,8 +252,8 @@ $geodb = ''; endif; - $access_log = getenv("GOACCESS_LOG_FILE") ?: "/config/log/nginx/access.log"; - $goaccess = shell_exec("/usr/local/bin/goaccess -a -o html -f $access_log --config-file=/dashboard/goaccess.conf ".$geodb); + $access_log = file_exists("/dashboard/logs") ? "/dashboard/logs/*" : "/config/log/nginx/access.log"; + $goaccess = shell_exec("cat $access_log" | /usr/local/bin/goaccess -a -o html --config-file=/dashboard/goaccess.conf $geodb -"); $goaccess = str_replace("<title>Server Statistics", "<title>SWAG Dashboard", $goaccess); $goaccess = str_replace("<h1 class='h-dashboard'>", "<h1>", $goaccess); $goaccess = str_replace("<i class='fa fa-tachometer'></i>", "<img src='/icon.svg' width='32' height='32'> SWAG ", $goaccess); diff --git a/root/etc/cont-init.d/98-dashboard-config b/root/etc/cont-init.d/98-dashboard-config index d238501..ac11c0e 100644 --- a/root/etc/cont-init.d/98-dashboard-config +++ b/root/etc/cont-init.d/98-dashboard-config @@ -22,10 +22,6 @@ if [ "$(sed -nE 's|## Version ([0-9]{4}\/[0-9]{2}\/[0-9]{2}).*|\1|p' /dashboard/ echo "**** Compare the changes using the sample file: /config/nginx/proxy-confs/dashboard.subdomain.conf.sample" fi -# preserve environment variables in PHP -sed -E -i 's/^clear_env =.*$/clear_env = no/g' /config/php/www2.conf -grep -qxF 'clear_env = no' /config/php/www2.conf || echo 'clear_env = no' >> /config/php/www2.conf - # permissions chown -R abc:abc \ /dashboard \ From b0840e2820cece188f070d2e4ec7b7e81c2c0f1c Mon Sep 17 00:00:00 2001 From: Alex Phillips <ahp118@gmail.com> Date: Thu, 3 Feb 2022 09:39:48 -0500 Subject: [PATCH 4/5] fixed syntax error --- root/dashboard/www/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/root/dashboard/www/index.php b/root/dashboard/www/index.php index 397719f..c3b4b40 100644 --- a/root/dashboard/www/index.php +++ b/root/dashboard/www/index.php @@ -253,7 +253,7 @@ endif; $access_log = file_exists("/dashboard/logs") ? "/dashboard/logs/*" : "/config/log/nginx/access.log"; - $goaccess = shell_exec("cat $access_log" | /usr/local/bin/goaccess -a -o html --config-file=/dashboard/goaccess.conf $geodb -"); + $goaccess = shell_exec("cat $access_log | /usr/local/bin/goaccess -a -o html --config-file=/dashboard/goaccess.conf $geodb -"); $goaccess = str_replace("<title>Server Statistics", "<title>SWAG Dashboard", $goaccess); $goaccess = str_replace("<h1 class='h-dashboard'>", "<h1>", $goaccess); $goaccess = str_replace("<i class='fa fa-tachometer'></i>", "<img src='/icon.svg' width='32' height='32'> SWAG ", $goaccess); From 51b52dd36999266ce131cb4934eae55a904534ec Mon Sep 17 00:00:00 2001 From: Alex Phillips <ahp118@gmail.com> Date: Thu, 3 Feb 2022 09:41:47 -0500 Subject: [PATCH 5/5] only pass logs in case of compressed logs or logrotate running --- root/dashboard/www/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/root/dashboard/www/index.php b/root/dashboard/www/index.php index c3b4b40..d596cb4 100644 --- a/root/dashboard/www/index.php +++ b/root/dashboard/www/index.php @@ -252,7 +252,7 @@ $geodb = ''; endif; - $access_log = file_exists("/dashboard/logs") ? "/dashboard/logs/*" : "/config/log/nginx/access.log"; + $access_log = file_exists("/dashboard/logs") ? "/dashboard/logs/*.log" : "/config/log/nginx/access.log"; $goaccess = shell_exec("cat $access_log | /usr/local/bin/goaccess -a -o html --config-file=/dashboard/goaccess.conf $geodb -"); $goaccess = str_replace("<title>Server Statistics", "<title>SWAG Dashboard", $goaccess); $goaccess = str_replace("<h1 class='h-dashboard'>", "<h1>", $goaccess);