Fix latency feature
This commit is contained in:
parent
540bef3e12
commit
9346288160
@ -430,11 +430,10 @@ class LookingGlass
|
|||||||
{
|
{
|
||||||
$ssPath = exec('which ss 2>/dev/null');
|
$ssPath = exec('which ss 2>/dev/null');
|
||||||
if (empty($ssPath)) {
|
if (empty($ssPath)) {
|
||||||
// RHEL based systems
|
// RHEL based systems;
|
||||||
$ssPath = '/usr/sbin/ss';
|
$ssPath = '/usr/sbin/ss';
|
||||||
}
|
}
|
||||||
$lines = shell_exec("$ssPath -Hnti state established");
|
$lines = shell_exec("$ssPath -Hnti state established");
|
||||||
|
|
||||||
$ss = [];
|
$ss = [];
|
||||||
$i = 0;
|
$i = 0;
|
||||||
$j = 0;
|
$j = 0;
|
||||||
@ -451,22 +450,27 @@ class LookingGlass
|
|||||||
$output = [];
|
$output = [];
|
||||||
foreach ($ss as $socket) {
|
foreach ($ss as $socket) {
|
||||||
$socket = preg_replace('!\s+!', ' ', $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);
|
$explodedsocket = explode(' ', $socket);
|
||||||
if ($matches['remoteIp'] !== $ip) {
|
preg_match('/\d+\.\d+\.\d+\.\d+|\[[:a-fA-F0-9]+\]/', $explodedsocket[2], $temp);
|
||||||
|
if (!isset($temp[0])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$sock['local'] = $matches['localIp'];
|
$sock['local'] = $temp[0];
|
||||||
$sock['remote'] = $matches['remoteIp'];
|
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);
|
preg_match('/segs_out:(\d+)/', $socket, $temp);
|
||||||
$sock['segs_out'] = $temp[1];
|
$sock['segs_out'] = $temp[1];
|
||||||
preg_match('/segs_in:(\d+)/', $socket, $temp);
|
preg_match('/segs_in:(\d+)/', $socket, $temp);
|
||||||
$sock['segs_in'] = $temp[1];
|
$sock['segs_in'] = $temp[1];
|
||||||
preg_match('/rtt:(\d+\.\d+)\/(\d+\.\d+)/', $socket, $temp);
|
preg_match_all('/rtt:(\d+\.\d+)\/(\d+\.\d+)/', $socket, $temp);
|
||||||
$sock['latency'] = $temp[1];
|
$sock['latency'] = $temp[1][0];
|
||||||
$sock['jitter'] = $temp[2];
|
$sock['jitter'] = $temp[2][0];
|
||||||
preg_match('/retrans:\d+\/(\d+)/', $socket, $temp);
|
preg_match_all('/retrans:\d+\/(\d+)/', $socket, $temp);
|
||||||
$sock['retransmissions'] = ($temp[1] ?? 0);
|
$sock['retransmissions'] = (isset($temp[1][0]) ? $temp[1][0] : 0);
|
||||||
$output[] = $sock;
|
if ($sock['remote'] == $ip) {
|
||||||
|
$output[] = $sock;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
@ -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.
|
||||||
|
@ -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();
|
$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>
|
<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>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user