From c15052fe84b092aabd08e65081560795dc628a8d Mon Sep 17 00:00:00 2001
From: Tamer <8611981+dqos@users.noreply.github.com>
Date: Wed, 1 Mar 2023 11:48:42 +0100
Subject: [PATCH 01/10] Update CHANGELOG.md
---
CHANGELOG.md | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ad1f8a1..290b44d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+## 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.
From ff2d46080ba781bfc1f6a60f627a1a383f106c3d Mon Sep 17 00:00:00 2001
From: Tamer <8611981+dqos@users.noreply.github.com>
Date: Fri, 3 Mar 2023 19:10:01 +0100
Subject: [PATCH 02/10] Update README.md
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 0ca27ea..fb97d75 100644
--- a/README.md
+++ b/README.md
@@ -2,10 +2,10 @@
Modern, simple and fresh looking glass based on Bootstrap 5 and PHP 8 (also compatible with 7). A looking glass is a network utility which is
made user-friendly for everyone to use. It allows you to execute network related commands within a remote network, usually that of an ISP.
-![](screenshot.png)
+[![](screenshot.png)](https://lg-nl-ams.hybula.net/)
### Demo
-[See it in action here!](https://lg-nl-oum.hybula.net/)
+[See it in action here!](https://lg-nl-ams.hybula.net/)
### Features
- Bootstrap 5 UI.
From 41adb719f827f98c63b5acca434688b67ebc3451 Mon Sep 17 00:00:00 2001
From: dqos <8611981+dqos@users.noreply.github.com>
Date: Sat, 25 Mar 2023 15:35:05 +0100
Subject: [PATCH 03/10] Some experimenting
---
LookingGlass.php | 273 +++++++++++++++++++++++++++++++++--------------
config.dist.php | 3 +
index.php | 5 +
3 files changed, 201 insertions(+), 80 deletions(-)
diff --git a/LookingGlass.php b/LookingGlass.php
index 1c0ae45..56bb319 100644
--- a/LookingGlass.php
+++ b/LookingGlass.php
@@ -1,4 +1,5 @@
-update($str);
- echo '---' . PHP_EOL . $parser->__toString() . PHP_EOL . str_pad('', 4096) . PHP_EOL;
+ echo '---'.PHP_EOL.$parser->__toString().PHP_EOL.str_pad('', 4096).PHP_EOL;
// flush output buffering
@ob_flush();
flush();
continue;
- }
- // correct output for traceroute
+ } // correct output for traceroute
elseif ($type === 'traceroute') {
if ($match < 10 && preg_match('/^[0-9] /', $str, $string)) {
- $str = preg_replace('/^[0-9] /', ' ' . $string[0], $str);
+ $str = preg_replace('/^[0-9] /', ' '.$string[0], $str);
$match++;
}
// check for consecutive failed hops
@@ -304,9 +358,9 @@ class LookingGlass
$fail++;
if ($lastFail !== 'start'
&& ($traceCount - 1) === $lastFail
- && $fail >= $failCount
+ && $fail >= $failCount
) {
- echo str_pad($str . ' -- Traceroute timed out -- ', 4096, ' ', STR_PAD_RIGHT);
+ echo str_pad($str.' -- Traceroute timed out -- ', 4096, ' ', STR_PAD_RIGHT);
break;
}
$lastFail = $traceCount;
@@ -315,7 +369,7 @@ class LookingGlass
}
// pad string for live output
- echo str_pad($str . ' ', 4096, ' ', STR_PAD_RIGHT);
+ echo str_pad($str.' ', 4096, ' ', STR_PAD_RIGHT);
// flush output buffering
@ob_flush();
@@ -345,7 +399,7 @@ class LookingGlass
// kill remaining processes
foreach ($pids as $pid) {
if (is_numeric($pid)) {
- posix_kill((int) $pid, 9);
+ posix_kill((int)$pid, 9);
}
}
}
@@ -353,6 +407,66 @@ class LookingGlass
}
return true;
}
+
+ public static function getLatency(): float
+ {
+ $getLatency = self::getLatencyFromSs(self::detectIpAddress());
+ if (isset($getLatency[0])) {
+ return (float)round($getLatency[0]['latency'], 2);
+ } else {
+ return 0.00;
+ }
+ }
+
+ /**
+ * This uses the command 'ss' in order to find out latency.
+ * A clever way coded by @ayyylias, so please keep credits and do not just steal.
+ *
+ * @param string $ip The command to execute.
+ * @return array Returns an array with results.
+ */
+ private static function getLatencyFromSs(string $ip): array
+ {
+ $lines = shell_exec('/usr/sbin/ss -Hti state established');
+ $ss = [];
+ $i = 0;
+ $j = 0;
+ foreach (explode(PHP_EOL, $lines) as $line) {
+ if ($i > 1) {
+ $i = 0;
+ $j++;
+ }
+ if ($line !== '') {
+ @$ss[$j] .= $line;
+ $i++;
+ }
+ }
+ $output = [];
+ foreach ($ss as $socket) {
+ $socket = preg_replace('!\s+!', ' ', $socket);
+ $explodedsocket = explode(' ', $socket);
+ preg_match('/\d+\.\d+\.\d+\.\d+/', $explodedsocket[2], $temp);
+ if (!isset($temp[0])) {
+ continue;
+ } // when thsi cantt be filled just continue
+ $sock['local'] = $temp[0];
+ preg_match('/\d+\.\d+\.\d+\.\d+/', $explodedsocket[3], $temp);
+ $sock['remote'] = $temp[0];
+ preg_match('/segs_out:(\d+)/', $socket, $temp);
+ $sock['segs_out'] = $temp[1];
+ preg_match('/segs_in:(\d+)/', $socket, $temp);
+ $sock['segs_in'] = $temp[1];
+ preg_match_all('/rtt:(\d+\.\d+)\/(\d+\.\d+)/', $socket, $temp);
+ $sock['latency'] = $temp[1][0];
+ $sock['jitter'] = $temp[2][0];
+ preg_match_all('/retrans:\d+\/(\d+)/', $socket, $temp);
+ $sock['retransmissions'] = (isset($temp[1][0]) ? $temp[1][0] : 0);
+ if ($sock['remote'] == $ip) {
+ $output[] = $sock;
+ }
+ }
+ return $output;
+ }
}
class Hop
@@ -423,10 +537,10 @@ class Parser
$hop->recieved = count($hop->timings);
if (count($hop->timings)) {
- $hop->last = $hop->timings[count($hop->timings) - 1];
- $hop->best = $hop->timings[0];
+ $hop->last = $hop->timings[count($hop->timings) - 1];
+ $hop->best = $hop->timings[0];
$hop->worst = $hop->timings[0];
- $hop->avg = array_sum($hop->timings) / count($hop->timings);
+ $hop->avg = array_sum($hop->timings) / count($hop->timings);
}
if (count($hop->timings) > 1) {
@@ -434,7 +548,6 @@ class Parser
}
foreach ($hop->timings as $time) {
-
if ($hop->best > $time) {
$hop->best = $time;
}
@@ -483,10 +596,10 @@ class Parser
return;
}
- $rawHop = new RawHop();
+ $rawHop = new RawHop();
$rawHop->dataType = $things[0];
- $rawHop->idx = (int)$things[1];
- $rawHop->value = $things[2];
+ $rawHop->idx = (int)$things[1];
+ $rawHop->value = $things[2];
if ($this->hopCount < $rawHop->idx + 1) {
$this->hopCount = $rawHop->idx + 1;
@@ -496,12 +609,12 @@ class Parser
$this->hopsCollection[$rawHop->idx] = new Hop();
}
- $hop = $this->hopsCollection[$rawHop->idx];
+ $hop = $this->hopsCollection[$rawHop->idx];
$hop->idx = $rawHop->idx;
switch ($rawHop->dataType) {
case 'h':
- $hop->ips[] = $rawHop->value;
- $hop->hosts[] = gethostbyaddr($rawHop->value) ? : null;
+ $hop->ips[] = $rawHop->value;
+ $hop->hosts[] = gethostbyaddr($rawHop->value) ?: null;
break;
case 'd':
//Not entirely sure if multiple IPs. Better use -n in mtr and resolve later in summarize.
@@ -523,13 +636,13 @@ class Parser
private function filterLastDupeHop()
{
// filter dupe last hop
- $finalIdx = 0;
+ $finalIdx = 0;
$previousIp = '';
foreach ($this->hopsCollection as $key => $hop) {
if (count($hop->ips) && $hop->ips[0] !== $previousIp) {
$previousIp = $hop->ips[0];
- $finalIdx = $key + 1;
+ $finalIdx = $key + 1;
}
}
diff --git a/config.dist.php b/config.dist.php
index aaa9fd6..0215e72 100644
--- a/config.dist.php
+++ b/config.dist.php
@@ -9,6 +9,9 @@ const LG_LOGO = '
Company Looking Glass
';
// Define the URL where the logo points to;
const LG_LOGO_URL = 'https://github.com/hybula/lookingglass/';
+// Enable the latency check feature;
+const LG_CHECK_LATENCY = false;
+
// Define a custom CSS file which can be used to style the LG, set false to disable, else point to the CSS file;
const LG_CSS_OVERRIDES = false;
// Define content, this could be JS, CSS or meta tags;
diff --git a/index.php b/index.php
index eec0265..16bfb4c 100644
--- a/index.php
+++ b/index.php
@@ -77,6 +77,10 @@ if (LG_BLOCK_CUSTOM) {
$templateData['custom_html'] = ob_get_clean();
}
+if (LG_CHECK_LATENCY) {
+ $templateData['latency'] = LookingGlass::getLatency();
+}
+
$templateData['csrfToken'] = $_SESSION[LookingGlass::SESSION_CSRF] = bin2hex(random_bytes(12));
?>
@@ -162,6 +166,7 @@ $templateData['csrfToken'] = $_SESSION[LookingGlass::SESSION_CSRF] = bin2hex(ran
';
// Define the URL where the logo points to;
const LG_LOGO_URL = 'https://github.com/hybula/lookingglass/';
-// Define content, this could be JS, CSS or meta tags;
-const LG_CUSTOM_HEAD = false;
+
+// Enable the latency check feature;
+const LG_CHECK_LATENCY = false;
// Define a custom CSS file which can be used to style the LG, set false to disable, else point to the CSS file;
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;
// 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);
+const LG_BLOCK_CUSTOM = false;
// 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';
@@ -27,17 +30,17 @@ const LG_CUSTOM_HTML = __DIR__.'/custom.html.php';
const LG_CUSTOM_PHP = __DIR__.'/custom.post.php';
// Define the location of this network, usually a city and a country;
-define('LG_LOCATION', getenv('LOCATION'));
+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)
-define('LG_MAPS_QUERY', getenv('MAPS_QUERY'));
+const LG_MAPS_QUERY = 'Amsterdam, Netherlands';
// Define the facility where the network is located, usually a data center;
-define('LG_FACILITY', getenv('FACILITY'));
+const LG_FACILITY = 'Nikhef';
// Define a direct link to more information about the facility, this should be a link to PeeringDB;
-define('LG_FACILITY_URL', getenv('FACILITY_URL'));
+const LG_FACILITY_URL = 'https://www.peeringdb.com/fac/18';
// Define an IPv4 for testing;
-define('LG_IPV4', getenv('IPV4_ADDRESS'));
+const LG_IPV4 = '127.0.0.1';
// Define an IPv6 for testing;
-define('LG_IPV6', getenv('IPV6_ADDRESS'));
+const LG_IPV6 = '::1';
// Define the methods that can be used by visitors to test it out;
const LG_METHODS = [
@@ -56,7 +59,7 @@ const LG_LOCATIONS = [
'Location C' => 'https://github.com/hybula/lookingglass/',
];
-// Enable the iPerf info inside the speedtest block, set too false to disable;
+// Enable the iPerf info inside the speedtest block, set to false to disable;
const LG_SPEEDTEST_IPERF = true;
// Define the label of an incoming iPerf test;
const LG_SPEEDTEST_LABEL_INCOMING = 'iPerf3 Incoming';
@@ -74,4 +77,4 @@ const LG_SPEEDTEST_FILES = [
];
// Define if you require visitors to agree with the Terms, set false to disable;
-define('LG_TERMS', getenv('LG_TERMS') ?: 'https://github.com/hybula/lookingglass/');
+const LG_TERMS = 'https://github.com/hybula/lookingglass/';
From 33c94a8cb7a0814d7d24c8f344de759b279350d5 Mon Sep 17 00:00:00 2001
From: Tamer <8611981+dqos@users.noreply.github.com>
Date: Mon, 8 May 2023 20:31:24 +0200
Subject: [PATCH 08/10] Update config.php
---
docker/php-fpm/src/config.php | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/docker/php-fpm/src/config.php b/docker/php-fpm/src/config.php
index 0215e72..69aa094 100644
--- a/docker/php-fpm/src/config.php
+++ b/docker/php-fpm/src/config.php
@@ -8,6 +8,8 @@ const LG_TITLE = 'Looking Glass';
const LG_LOGO = '
Company Looking Glass
';
// Define the URL where the logo points to;
const LG_LOGO_URL = 'https://github.com/hybula/lookingglass/';
+// Define content, this could be JS, CSS or meta tags;
+const LG_CUSTOM_HEAD = false;
// Enable the latency check feature;
const LG_CHECK_LATENCY = false;
@@ -22,7 +24,7 @@ const LG_BLOCK_NETWORK = true;
const LG_BLOCK_LOOKINGGLAS = 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;
+define('LG_BLOCK_CUSTOM', getenv('ENABLE_CUSTOM_BLOCK') !== false);
// 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';
@@ -30,17 +32,17 @@ const LG_CUSTOM_HTML = __DIR__.'/custom.html.php';
const LG_CUSTOM_PHP = __DIR__.'/custom.post.php';
// Define the location of this network, usually a city and a country;
-const LG_LOCATION = 'Amsterdam, Netherlands';
+define('LG_LOCATION', getenv('LOCATION'));
// Define a query location for the link to openstreetmap (eg: Amsterdam, Netherlands will be https://www.openstreetmap.org/search?query=Amsterdam, Netherlands)
-const LG_MAPS_QUERY = 'Amsterdam, Netherlands';
+define('LG_MAPS_QUERY', getenv('MAPS_QUERY'));
// Define the facility where the network is located, usually a data center;
-const LG_FACILITY = 'Nikhef';
+define('LG_FACILITY', getenv('FACILITY'));
// Define a direct link to more information about the facility, this should be a link to PeeringDB;
-const LG_FACILITY_URL = 'https://www.peeringdb.com/fac/18';
+define('LG_FACILITY_URL', getenv('FACILITY_URL'));
// Define an IPv4 for testing;
-const LG_IPV4 = '127.0.0.1';
+define('LG_IPV4', getenv('IPV4_ADDRESS'));
// Define an IPv6 for testing;
-const LG_IPV6 = '::1';
+define('LG_IPV6', getenv('IPV6_ADDRESS'));
// Define the methods that can be used by visitors to test it out;
const LG_METHODS = [
@@ -59,7 +61,7 @@ const LG_LOCATIONS = [
'Location C' => 'https://github.com/hybula/lookingglass/',
];
-// Enable the iPerf info inside the speedtest block, set to false to disable;
+// Enable the iPerf info inside the speedtest block, set too false to disable;
const LG_SPEEDTEST_IPERF = true;
// Define the label of an incoming iPerf test;
const LG_SPEEDTEST_LABEL_INCOMING = 'iPerf3 Incoming';
@@ -77,4 +79,4 @@ const LG_SPEEDTEST_FILES = [
];
// Define if you require visitors to agree with the Terms, set false to disable;
-const LG_TERMS = 'https://github.com/hybula/lookingglass/';
+define('LG_TERMS', getenv('LG_TERMS') ?: 'https://github.com/hybula/lookingglass/');
From fc7e072436e7db4806d24f49e12ef0af03de5165 Mon Sep 17 00:00:00 2001
From: Josh Jameson
Date: Thu, 1 Jun 2023 09:20:46 +0100
Subject: [PATCH 09/10] Disable NGINX gzip & buffering
---
backend.php | 2 ++
1 file changed, 2 insertions(+)
diff --git a/backend.php b/backend.php
index 58badd5..ce3fb4f 100644
--- a/backend.php
+++ b/backend.php
@@ -19,6 +19,8 @@ use Hybula\LookingGlass;
LookingGlass::validateConfig();
LookingGlass::startSession();
+header('X-Accel-Buffering: no');
+
if (isset($_SESSION[LookingGlass::SESSION_TARGET_HOST]) &&
isset($_SESSION[LookingGlass::SESSION_TARGET_METHOD]) &&
isset($_SESSION[LookingGlass::SESSION_CALL_BACKEND])
From bbd849bf2ae885339b6d46c55d552f9055975edd Mon Sep 17 00:00:00 2001
From: dqos <8611981+dqos@users.noreply.github.com>
Date: Mon, 26 Jun 2023 16:06:57 +0200
Subject: [PATCH 10/10] Update CHANGELOG.md
---
CHANGELOG.md | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 290b44d..d91c0dc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,10 +6,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [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
+- 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