Fix latency feature

This commit is contained in:
dqos 2023-11-01 19:14:38 +01:00
parent 540bef3e12
commit 9346288160
No known key found for this signature in database
3 changed files with 19 additions and 14 deletions

View File

@ -430,11 +430,10 @@ class LookingGlass
{
$ssPath = exec('which ss 2>/dev/null');
if (empty($ssPath)) {
// RHEL based systems
// RHEL based systems;
$ssPath = '/usr/sbin/ss';
}
$lines = shell_exec("$ssPath -Hnti state established");
$ss = [];
$i = 0;
$j = 0;
@ -451,22 +450,27 @@ class LookingGlass
$output = [];
foreach ($ss as $socket) {
$socket = preg_replace('!\s+!', ' ', $socket);
preg_match('/^\d+\s+\d+\s+(?:\[::ffff:)?(?<localIp>[a-f0-9.:]+)]?:(?<localPort>\d+)\s+(?:\[::ffff:)?(?<remoteIp>[a-f0-9.:]+)]?:(?<remotePort>\d+)/', $line, $matches);
if ($matches['remoteIp'] !== $ip) {
$explodedsocket = explode(' ', $socket);
preg_match('/\d+\.\d+\.\d+\.\d+|\[[:a-fA-F0-9]+\]/', $explodedsocket[2], $temp);
if (!isset($temp[0])) {
continue;
}
$sock['local'] = $matches['localIp'];
$sock['remote'] = $matches['remoteIp'];
$sock['local'] = $temp[0];
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];
preg_match('/segs_in:(\d+)/', $socket, $temp);
$sock['segs_in'] = $temp[1];
preg_match('/rtt:(\d+\.\d+)\/(\d+\.\d+)/', $socket, $temp);
$sock['latency'] = $temp[1];
$sock['jitter'] = $temp[2];
preg_match('/retrans:\d+\/(\d+)/', $socket, $temp);
$sock['retransmissions'] = ($temp[1] ?? 0);
$output[] = $sock;
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;
}

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

View File

@ -89,7 +89,7 @@ if (LG_BLOCK_CUSTOM) {
}
}
if (LG_CHECK_LATENCY && filter_var(LookingGlass::detectIpAddress(), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
if (LG_CHECK_LATENCY) {
$templateData['latency'] = LookingGlass::getLatency();
}
@ -181,7 +181,7 @@ $templateData['csrfToken'] = $_SESSION[LookingGlass::SESSION_CSRF] = bin2hex(ran
<label class="mb-2 text-muted">Your IP</label>
<div class="input-group">
<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>