Skip to content

Commit

Permalink
Merge pull request #31 from hybula/main
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
dqos authored Nov 1, 2023
2 parents d613015 + b9f8cc2 commit 1fb9da0
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 67 deletions.
58 changes: 0 additions & 58 deletions CHANGELOG.md

This file was deleted.

12 changes: 9 additions & 3 deletions LookingGlass.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,12 @@ public static function getLatency(): float
*/
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 = [];
$i = 0;
$j = 0;
Expand All @@ -446,12 +451,13 @@ private static function getLatencyFromSs(string $ip): array
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];
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function exitErrorMessage(string $message): void

function exitNormal(): void
{
header('Location: /');
header("Refresh: 0");
exit;
}

Expand Down
5 changes: 5 additions & 0 deletions config.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
// 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';

// 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;
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)
Expand Down
26 changes: 21 additions & 5 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,21 @@
ob_start();
include LG_CUSTOM_HTML;
$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 (defined('LG_CUSTOM_FOOTER_PHP')) {
ob_start();
include LG_CUSTOM_FOOTER_PHP;
$templateData['custom_footer'] = ob_get_clean();
}
}

if (LG_CHECK_LATENCY && filter_var(LookingGlass::detectIpAddress(), FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
if (LG_CHECK_LATENCY) {
$templateData['latency'] = LookingGlass::getLatency();
}

Expand All @@ -97,7 +109,9 @@
</head>
<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">
<div class="col-8">
Expand Down Expand Up @@ -167,7 +181,7 @@
<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>
Expand All @@ -182,7 +196,7 @@
<div class="card shadow-lg">
<div class="card-body p-3">
<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'] ?>">

<div class="row">
Expand Down Expand Up @@ -274,6 +288,8 @@
</footer>
</div>

<?php echo isset($templateData['custom_footer']) ? $templateData['custom_footer'] : '' ?>

<?php if ($templateData['session_call_backend']): ?>
<script type="text/javascript">
(function () {
Expand All @@ -286,7 +302,7 @@

outputCard.style.display = 'inherit'

fetch('/backend.php')
fetch('backend.php')
.then(async (response) => {
// response.body is a ReadableStream
const reader = response.body.getReader()
Expand Down

0 comments on commit 1fb9da0

Please sign in to comment.