Merge pull request #31 from hybula/main

New release
This commit is contained in:
Tamer 2023-11-01 21:27:02 +01:00 committed by GitHub
commit 1fb9da0812
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 67 deletions

View file

@ -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 <head> 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.

View file

@ -428,7 +428,12 @@ class LookingGlass
*/ */
private static function getLatencyFromSs(string $ip): array 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 = []; $ss = [];
$i = 0; $i = 0;
$j = 0; $j = 0;
@ -446,12 +451,13 @@ class LookingGlass
foreach ($ss as $socket) { foreach ($ss as $socket) {
$socket = preg_replace('!\s+!', ' ', $socket); $socket = preg_replace('!\s+!', ' ', $socket);
$explodedsocket = explode(' ', $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])) { if (!isset($temp[0])) {
continue; continue;
} }
$sock['local'] = $temp[0]; $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]; $sock['remote'] = $temp[0];
preg_match('/segs_out:(\d+)/', $socket, $temp); preg_match('/segs_out:(\d+)/', $socket, $temp);
$sock['segs_out'] = $temp[1]; $sock['segs_out'] = $temp[1];

View file

@ -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. - Supports ping/ping6, traceroute/traceroute6 and mtr/mtr6.
- Easy to customize and to configure. - Easy to customize and to configure.
- DNS checking to prevent unnecessary executions. - DNS checking to prevent unnecessary executions.
- Latency feature from visitor to LG.
### Requirements ### Requirements
- Any Linux distribution, this has been tested on RHEL 8 + 9. - Any Linux distribution, this has been tested on RHEL 8 + 9.

View file

@ -31,7 +31,7 @@ function exitErrorMessage(string $message): void
function exitNormal(): void function exitNormal(): void
{ {
header('Location: /'); header("Refresh: 0");
exit; exit;
} }

View file

@ -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; // 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'; 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; // Define the location of this network, usually a city and a country;
const LG_LOCATION = 'Amsterdam, Netherlands'; 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 a query location for the link to openstreetmap (eg: Amsterdam, Netherlands will be https://www.openstreetmap.org/search?query=Amsterdam, Netherlands)

View file

@ -75,9 +75,21 @@ if (LG_BLOCK_CUSTOM) {
ob_start(); ob_start();
include LG_CUSTOM_HTML; include LG_CUSTOM_HTML;
$templateData['custom_html'] = ob_get_clean(); $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 (LG_CHECK_LATENCY && filter_var(LookingGlass::detectIpAddress(), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { if (defined('LG_CUSTOM_FOOTER_PHP')) {
ob_start();
include LG_CUSTOM_FOOTER_PHP;
$templateData['custom_footer'] = ob_get_clean();
}
}
if (LG_CHECK_LATENCY) {
$templateData['latency'] = LookingGlass::getLatency(); $templateData['latency'] = LookingGlass::getLatency();
} }
@ -97,7 +109,9 @@ $templateData['csrfToken'] = $_SESSION[LookingGlass::SESSION_CSRF] = bin2hex(ran
</head> </head>
<body> <body>
<div class="col-lg-6 mx-auto p-3 py-md-5"> <?php echo isset($templateData['custom_header']) ? $templateData['custom_header'] : '' ?>
<div class="col-lg-8 mx-auto p-3 py-md-5">
<header class="d-flex align-items-center pb-3 mb-5 border-bottom"> <header class="d-flex align-items-center pb-3 mb-5 border-bottom">
<div class="col-8"> <div class="col-8">
@ -167,7 +181,7 @@ $templateData['csrfToken'] = $_SESSION[LookingGlass::SESSION_CSRF] = bin2hex(ran
<label class="mb-2 text-muted">Your IP</label> <label class="mb-2 text-muted">Your IP</label>
<div class="input-group"> <div class="input-group">
<input type="text" class="form-control" value="<?php echo $templateData['user_ip'] ?>" onfocus="this.select()" readonly=""> <input type="text" class="form-control" value="<?php echo $templateData['user_ip'] ?>" onfocus="this.select()" readonly="">
<?php if (LG_CHECK_LATENCY && filter_var(LookingGlass::detectIpAddress(), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)): ?><label class="input-group-text" title="Latency between this looking glass and your connection." style="cursor: help;"><small><?php echo $templateData['latency'] ?> MS</small></label><?php endif ?> <?php if (LG_CHECK_LATENCY): ?><label class="input-group-text" title="Latency between this looking glass and your connection." style="cursor: help;"><small><?php echo $templateData['latency'] ?> MS</small></label><?php endif ?>
</div> </div>
</div> </div>
</div> </div>
@ -182,7 +196,7 @@ $templateData['csrfToken'] = $_SESSION[LookingGlass::SESSION_CSRF] = bin2hex(ran
<div class="card shadow-lg"> <div class="card shadow-lg">
<div class="card-body p-3"> <div class="card-body p-3">
<h1 class="fs-4 card-title mb-4">Looking Glass</h1> <h1 class="fs-4 card-title mb-4">Looking Glass</h1>
<form method="POST" action="/" autocomplete="off"> <form method="POST" autocomplete="off">
<input type="hidden" name="csrfToken" value="<?php echo $templateData['csrfToken'] ?>"> <input type="hidden" name="csrfToken" value="<?php echo $templateData['csrfToken'] ?>">
<div class="row"> <div class="row">
@ -274,6 +288,8 @@ $templateData['csrfToken'] = $_SESSION[LookingGlass::SESSION_CSRF] = bin2hex(ran
</footer> </footer>
</div> </div>
<?php echo isset($templateData['custom_footer']) ? $templateData['custom_footer'] : '' ?>
<?php if ($templateData['session_call_backend']): ?> <?php if ($templateData['session_call_backend']): ?>
<script type="text/javascript"> <script type="text/javascript">
(function () { (function () {
@ -286,7 +302,7 @@ $templateData['csrfToken'] = $_SESSION[LookingGlass::SESSION_CSRF] = bin2hex(ran
outputCard.style.display = 'inherit' outputCard.style.display = 'inherit'
fetch('/backend.php') fetch('backend.php')
.then(async (response) => { .then(async (response) => {
// response.body is a ReadableStream // response.body is a ReadableStream
const reader = response.body.getReader() const reader = response.body.getReader()