diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index d91c0dc..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,58 +0,0 @@ -# Changelog -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [Unreleased] - -## 1.2.0 - 2023-06-26 -### Fixed -- PR https://github.com/hybula/lookingglass/pull/21 thanks to @JKJameson. -- Issue #20 thanks to @amirgilan for reporting. - -### Added -- Latency feature (by default disabled). - -## 1.1.3 - 2023-03-01 -### Fixed -- Issue #12 with https://github.com/hybula/lookingglass/pull/14 thanks to @MarcHagen. -- Issue #13 with https://github.com/hybula/lookingglass/pull/15 thanks to @MarcHagen. - -## 1.1.2 - 2023-01-05 -### Fixed -- Added contact in config.php for Docker thanks to @deliciousbob. - -## 1.1.1 - 2022-12-27 -### Fixed -- Fix IPv6 issues thanks to @kimma. - -## 1.1.0 - 2022-11-23 -### Fixed -- Changelog date format adjusted to ISO 8601. -- Improvements on MTR live output thanks to @MarcHagen. -- Minor improvements in backend thanks to @MarcHagen. -- Improved Docker support thanks to @MarcHagen. -- Updated README.md about POSIX installation. -- Updated Bootstrap to version 5.2.3 - -### Added -- A way to add custom content, in the future this will replace the custom CSS feature. -- Upgrade tips to README.md. - -## [1.0.1] - 2022-04-19 -### Fixed -- Ping6/Traceroute6/MTR6 validation when using hostnames (PR #2). - -## [1.0.0] - 2022-04-14 -### Fixed -- Undefined warning when refreshing a page after execution. -- Traceroute error when there is no PID found. - -### Added -- Added Docker support. -- This CHANGELOG.md to track changes. - -## [0.1.0] - 2022-01-17 -### Changed -- First release. diff --git a/LookingGlass.php b/LookingGlass.php index cf32239..a8911df 100644 --- a/LookingGlass.php +++ b/LookingGlass.php @@ -428,7 +428,12 @@ class LookingGlass */ private static function getLatencyFromSs(string $ip): array { - $lines = shell_exec('/usr/sbin/ss -Hti state established'); + $ssPath = exec('which ss 2>/dev/null'); + if (empty($ssPath)) { + // RHEL based systems; + $ssPath = '/usr/sbin/ss'; + } + $lines = shell_exec("$ssPath -Hnti state established"); $ss = []; $i = 0; $j = 0; @@ -446,12 +451,13 @@ class LookingGlass foreach ($ss as $socket) { $socket = preg_replace('!\s+!', ' ', $socket); $explodedsocket = explode(' ', $socket); - preg_match('/\d+\.\d+\.\d+\.\d+/', $explodedsocket[2], $temp); + preg_match('/\d+\.\d+\.\d+\.\d+|\[[:a-fA-F0-9]+\]/', $explodedsocket[2], $temp); if (!isset($temp[0])) { continue; } $sock['local'] = $temp[0]; - preg_match('/\d+\.\d+\.\d+\.\d+/', $explodedsocket[3], $temp); + preg_match('/\d+\.\d+\.\d+\.\d+|\[[:a-fA-F0-9]+\]/', $explodedsocket[3], $temp); + if (preg_match('/^\[(.*)\]$/', $temp[0], $matches)) { $temp[0] = $matches[1]; } $sock['remote'] = $temp[0]; preg_match('/segs_out:(\d+)/', $socket, $temp); $sock['segs_out'] = $temp[1]; diff --git a/README.md b/README.md index fb97d75..41c3d21 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ made user-friendly for everyone to use. It allows you to execute network related - Supports ping/ping6, traceroute/traceroute6 and mtr/mtr6. - Easy to customize and to configure. - DNS checking to prevent unnecessary executions. +- Latency feature from visitor to LG. ### Requirements - Any Linux distribution, this has been tested on RHEL 8 + 9. diff --git a/bootstrap.php b/bootstrap.php index fb0ce09..92a2191 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -31,7 +31,7 @@ function exitErrorMessage(string $message): void function exitNormal(): void { - header('Location: /'); + header("Refresh: 0"); exit; } diff --git a/config.dist.php b/config.dist.php index 0215e72..fe18c9f 100644 --- a/config.dist.php +++ b/config.dist.php @@ -29,6 +29,11 @@ const LG_CUSTOM_HTML = __DIR__.'/custom.html.php'; // Define a file here which will be loaded on top of the index file, this can be used to do some post logic; const LG_CUSTOM_PHP = __DIR__.'/custom.post.php'; +// Define a file here which will be used to display the custom header. Will be at the top of file; +const LG_CUSTOM_HEADER_PHP = __DIR__.'/custom.header.php'; +// Define a file here which will be used to display the custom footer. Will be at the bottom of file; +const LG_CUSTOM_FOOTER_PHP = __DIR__.'/custom.footer.php'; + // Define the location of this network, usually a city and a country; const LG_LOCATION = 'Amsterdam, Netherlands'; // Define a query location for the link to openstreetmap (eg: Amsterdam, Netherlands will be https://www.openstreetmap.org/search?query=Amsterdam, Netherlands) diff --git a/index.php b/index.php index e62956f..3cec0f3 100644 --- a/index.php +++ b/index.php @@ -75,9 +75,21 @@ if (LG_BLOCK_CUSTOM) { ob_start(); include LG_CUSTOM_HTML; $templateData['custom_html'] = ob_get_clean(); + + if (defined('LG_CUSTOM_HEADER_PHP')) { + ob_start(); + include LG_CUSTOM_HEADER_PHP; + $templateData['custom_header'] = ob_get_clean(); + } + + if (defined('LG_CUSTOM_FOOTER_PHP')) { + ob_start(); + include LG_CUSTOM_FOOTER_PHP; + $templateData['custom_footer'] = ob_get_clean(); + } } -if (LG_CHECK_LATENCY && filter_var(LookingGlass::detectIpAddress(), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { +if (LG_CHECK_LATENCY) { $templateData['latency'] = LookingGlass::getLatency(); } @@ -97,7 +109,9 @@ $templateData['csrfToken'] = $_SESSION[LookingGlass::SESSION_CSRF] = bin2hex(ran -
+ + +
@@ -167,7 +181,7 @@ $templateData['csrfToken'] = $_SESSION[LookingGlass::SESSION_CSRF] = bin2hex(ran
- +
@@ -182,7 +196,7 @@ $templateData['csrfToken'] = $_SESSION[LookingGlass::SESSION_CSRF] = bin2hex(ran

Looking Glass

-
+
@@ -274,6 +288,8 @@ $templateData['csrfToken'] = $_SESSION[LookingGlass::SESSION_CSRF] = bin2hex(ran
+ +