bug fixes #23

Closed
realtkco wants to merge 4 commits from main into main
2 changed files with 10 additions and 5 deletions

View File

@ -428,7 +428,11 @@ class LookingGlass
*/
private static function getLatencyFromSs(string $ip): array
{
$lines = shell_exec('/usr/sbin/ss -Hti state established');
if (file_exists('/usr/sbin/ss')) {
$lines = shell_exec('/usr/sbin/ss -Hti state established'); // RHEL Directory for ss
} elseif (file_exists('/usr/bin/ss')) {
$lines = shell_exec('/usr/bin/ss -Hti state established'); // Debian Directory for ss
}
$ss = [];
MarcHagen commented 2023-08-09 22:28:38 +08:00 (Migrated from github.com)
Review

This change makes it working for magnitude of OSs (including alpine)

Also adding n option to remove the parsed ports in the output.

        $ssPath = exec('which ss 2>/dev/null');
        if (empty($ssPath)) {
            // RHEL based systems
            $ssPath = '/usr/sbin/ss';
        }

        $lines = shell_exec("$ssPath -Hnti state established");

This change makes it working for magnitude of OSs (including alpine) Also adding `n` option to remove the parsed ports in the output. ```suggestion $ssPath = exec('which ss 2>/dev/null'); if (empty($ssPath)) { // RHEL based systems $ssPath = '/usr/sbin/ss'; } $lines = shell_exec("$ssPath -Hnti state established"); ```
$i = 0;
$j = 0;
@ -446,12 +450,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];

View File

@ -77,7 +77,7 @@ if (LG_BLOCK_CUSTOM) {
$templateData['custom_html'] = ob_get_clean();
}
if (LG_CHECK_LATENCY && filter_var(LookingGlass::detectIpAddress(), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
if (LG_CHECK_LATENCY) {
tomhatzer commented 2023-07-09 22:35:43 +08:00 (Migrated from github.com)
Review

You can keep the filter_var() and just add the FILTER_FLAG_IPV6 to it.

if (LG_CHECK_LATENCY && filter_var(LookingGlass::detectIpAddress(), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6)) {
You can keep the `filter_var()` and just add the `FILTER_FLAG_IPV6` to it. ```suggestion if (LG_CHECK_LATENCY && filter_var(LookingGlass::detectIpAddress(), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6)) { ```
dqos commented 2023-07-09 22:42:18 +08:00 (Migrated from github.com)
Review

The filter_var can be removed, validation is done in detectIpAddress(). We added the filter to make sure it only works on v4 back then.

The filter_var can be removed, validation is done in `detectIpAddress()`. We added the filter to make sure it only works on v4 back then.
$templateData['latency'] = LookingGlass::getLatency();
}
@ -167,7 +167,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>