From f3457d52407aeea05a02fd8e12b14d89b669eb80 Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Fri, 18 Oct 2024 15:41:15 +0300 Subject: [PATCH] Adds a Jilo Server check and notice. --- app/classes/server.php | 34 ++++++++++++++++++++++++++++++++++ public_html/index.php | 9 +++++++++ 2 files changed, 43 insertions(+) create mode 100644 app/classes/server.php diff --git a/app/classes/server.php b/app/classes/server.php new file mode 100644 index 0000000..0127ced --- /dev/null +++ b/app/classes/server.php @@ -0,0 +1,34 @@ +db = $database->getConnection(); + } + + // get Jilo Server status + public function getServerStatus($host = '127.0.0.1', $port = 8080, $endpoint = '/health') { + $url = "http://$host:$port$endpoint"; + $options = [ + 'http' => [ + 'method' => 'GET', + 'timeout' => 3, + ], + ]; + $context = stream_context_create($options); + $response = @file_get_contents($url, false, $context); + + // We check the response if it's 200 OK + if ($response !== false && isset($http_response_header) && strpos($http_response_header[0], '200 OK') !== false) { + return true; + } + + // If it's not 200 OK + return false; + } + + +} + +?> diff --git a/public_html/index.php b/public_html/index.php index e255e95..4c15cf8 100644 --- a/public_html/index.php +++ b/public_html/index.php @@ -147,6 +147,15 @@ if ($page == 'logout') { $userTimezone = isset($userDetails[0]['timezone']) ? $userDetails[0]['timezone'] : 'UTC'; // Default to UTC if no timezone is set } + // check if the Jilo Server is running + require '../app/classes/server.php'; + $serverObject = new Server($dbWeb); + + $server_status = $serverObject->getServerStatus(); + if (!$server_status) { + $error = 'The Jilo Server is not running. Some data may be old and incorrect.'; + } + // page building include '../app/templates/page-header.php'; include '../app/templates/page-menu.php';