From 308c84f423964880d9a97f3250b16286205d8a45 Mon Sep 17 00:00:00 2001
From: evanebb <78433178+evanebb@users.noreply.github.com>
Date: Sat, 2 Dec 2023 21:24:14 +0100
Subject: [PATCH 1/3] Fix typo
---
LookingGlass.php | 4 ++--
bootstrap.php | 2 +-
config.dist.php | 2 +-
docker/php-fpm/src/config.php | 1 +
index.php | 2 +-
5 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/LookingGlass.php b/LookingGlass.php
index dc71779..2dc5580 100644
--- a/LookingGlass.php
+++ b/LookingGlass.php
@@ -62,8 +62,8 @@ class LookingGlass
if (!defined('LG_BLOCK_NETWORK')) {
die('LG_BLOCK_NETWORK not found in config.php');
}
- if (!defined('LG_BLOCK_LOOKINGGLAS')) {
- die('LG_BLOCK_LOOKINGGLAS not found in config.php');
+ if (!defined('LG_BLOCK_LOOKINGGLASS')) {
+ die('LG_BLOCK_LOOKINGGLASS not found in config.php');
}
if (!defined('LG_BLOCK_SPEEDTEST')) {
die('LG_BLOCK_SPEEDTEST not found in config.php');
diff --git a/bootstrap.php b/bootstrap.php
index 56b4c55..a84de33 100644
--- a/bootstrap.php
+++ b/bootstrap.php
@@ -44,7 +44,7 @@ $templateData = [
'logo_data_dark' => LG_LOGO_DARK,
//
'block_network' => LG_BLOCK_NETWORK,
- 'block_lookingglas' => LG_BLOCK_LOOKINGGLAS,
+ 'block_lookingglass' => LG_BLOCK_LOOKINGGLASS,
'block_speedtest' => LG_BLOCK_SPEEDTEST,
'block_custom' => LG_BLOCK_CUSTOM,
'custom_html' => '',
diff --git a/config.dist.php b/config.dist.php
index 9e2034a..5b7e2ec 100644
--- a/config.dist.php
+++ b/config.dist.php
@@ -24,7 +24,7 @@ const LG_CUSTOM_HEAD = false;
// Enable or disable blocks/parts of the LG, set false to hide a part;
const LG_BLOCK_NETWORK = true;
-const LG_BLOCK_LOOKINGGLAS = true;
+const LG_BLOCK_LOOKINGGLASS = true;
const LG_BLOCK_SPEEDTEST = true;
// This enables the custom block, which you can use to add something custom to the LG;
const LG_BLOCK_CUSTOM = false;
diff --git a/docker/php-fpm/src/config.php b/docker/php-fpm/src/config.php
index 62e8ab1..684c03c 100644
--- a/docker/php-fpm/src/config.php
+++ b/docker/php-fpm/src/config.php
@@ -26,6 +26,7 @@ const LG_CUSTOM_HEAD = false;
const LG_BLOCK_NETWORK = true;
const LG_BLOCK_LOOKINGGLAS = true;
const LG_BLOCK_SPEEDTEST = true;
+const LG_BLOCK_LOOKINGGLASS = true;
// This enables the custom block, which you can use to add something custom to the LG;
define('LG_BLOCK_CUSTOM', getenv('ENABLE_CUSTOM_BLOCK') !== false);
diff --git a/index.php b/index.php
index 90d49de..274d07a 100644
--- a/index.php
+++ b/index.php
@@ -194,7 +194,7 @@ $templateData['csrfToken'] = $_SESSION[LookingGlass::SESSION_CSRF] = bin2hex(ran
-
+
From 2de4d97a2d78196451ce293112435a471e5237e2 Mon Sep 17 00:00:00 2001
From: evanebb <78433178+evanebb@users.noreply.github.com>
Date: Sat, 2 Dec 2023 21:34:43 +0100
Subject: [PATCH 2/3] Make different blocks toggleable in Docker container
through env variables
---
docker-compose.yml | 4 ++++
docker/php-fpm/src/config.php | 11 +++++------
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/docker-compose.yml b/docker-compose.yml
index 6a92465..cb5da1a 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -25,6 +25,10 @@ services:
IPV4_ADDRESS: 127.0.0.1
IPV6_ADDRESS: ::1
MAPS_QUERY: Amsterdam
+ # Pass these variables with any arbitrary value to disable the respective block.
+ # DISABLE_BLOCK_NETWORK: 'true'
+ # DISABLE_BLOCK_LOOKINGGLASS: 'true'
+ # DISABLE_BLOCK_SPEEDTEST: 'true'
# Uncomment to enable the custom block, which you can use to add something custom to the LG.
# ENABLE_CUSTOM_BLOCK: 'true'
# Uncomment if you require visitors to accept the Terms of Use; the value should be a link to the terms.
diff --git a/docker/php-fpm/src/config.php b/docker/php-fpm/src/config.php
index 684c03c..1cab635 100644
--- a/docker/php-fpm/src/config.php
+++ b/docker/php-fpm/src/config.php
@@ -22,13 +22,12 @@ const LG_CSS_OVERRIDES = false;
// Define content, this could be JS, CSS or meta tags;
const LG_CUSTOM_HEAD = false;
-// Enable or disable blocks/parts of the LG, set false to hide a part;
-const LG_BLOCK_NETWORK = true;
-const LG_BLOCK_LOOKINGGLAS = true;
-const LG_BLOCK_SPEEDTEST = true;
-const LG_BLOCK_LOOKINGGLASS = true;
+// Enable or disable blocks/parts of the LG, pass these environment variables with any value to disable them;
+define('LG_BLOCK_NETWORK', !isset($_ENV['DISABLE_BLOCK_NETWORK']));
+define('LG_BLOCK_LOOKINGGLASS', !isset($_ENV['DISABLE_BLOCK_LOOKINGGLASS']));
+define('LG_BLOCK_SPEEDTEST', !isset($_ENV['DISABLE_BLOCK_SPEEDTEST']));
// This enables the custom block, which you can use to add something custom to the LG;
-define('LG_BLOCK_CUSTOM', getenv('ENABLE_CUSTOM_BLOCK') !== false);
+define('LG_BLOCK_CUSTOM', isset($_ENV['ENABLE_CUSTOM_BLOCK']));
// Define a file here which will be used to display the custom block, can be PHP too which outputs HTML;
const LG_CUSTOM_HTML = __DIR__.'/custom.html.php';
From 614bcdd887c5fc80a8b5a12c82d7291d31560b4a Mon Sep 17 00:00:00 2001
From: evanebb <78433178+evanebb@users.noreply.github.com>
Date: Sat, 2 Dec 2023 22:00:43 +0100
Subject: [PATCH 3/3] Custom block: check if constants are defined and if files
actually exist
---
index.php | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/index.php b/index.php
index 274d07a..db75619 100644
--- a/index.php
+++ b/index.php
@@ -70,19 +70,23 @@ if (isset($_SESSION[LookingGlass::SESSION_ERROR_MESSAGE])) {
}
if (LG_BLOCK_CUSTOM) {
- include LG_CUSTOM_PHP;
+ if (defined('LG_CUSTOM_PHP') && file_exists(LG_CUSTOM_PHP)) {
+ include LG_CUSTOM_PHP;
+ }
- ob_start();
- include LG_CUSTOM_HTML;
- $templateData['custom_html'] = ob_get_clean();
+ if (defined('LG_CUSTOM_HTML') && file_exists(LG_CUSTOM_HTML)) {
+ ob_start();
+ include LG_CUSTOM_HTML;
+ $templateData['custom_html'] = ob_get_clean();
+ }
- if (defined('LG_CUSTOM_HEADER_PHP')) {
+ if (defined('LG_CUSTOM_HEADER_PHP') && file_exists(LG_CUSTOM_HEADER_PHP)) {
ob_start();
include LG_CUSTOM_HEADER_PHP;
$templateData['custom_header'] = ob_get_clean();
}
- if (defined('LG_CUSTOM_FOOTER_PHP')) {
+ if (defined('LG_CUSTOM_FOOTER_PHP') && file_exists(LG_CUSTOM_FOOTER_PHP)) {
ob_start();
include LG_CUSTOM_FOOTER_PHP;
$templateData['custom_footer'] = ob_get_clean();