mirror of
https://github.com/librespeed/speedtest.git
synced 2026-08-04 06:39:45 +00:00
repair own url detection, switched to js
This commit is contained in:
parent
13eb4494df
commit
af9cbc0dd9
1 changed files with 13 additions and 29 deletions
|
|
@ -13,38 +13,22 @@ function I(i){return document.getElementById(i);}
|
|||
$mode=getenv("MODE");
|
||||
if($mode=="standalone" || $mode=="backend"){ ?>
|
||||
var SPEEDTEST_SERVERS=[];
|
||||
<?php } elseif ($mode=="dual") {
|
||||
$jsonContent = @file_get_contents('/servers.json');
|
||||
if ($jsonContent === false) {
|
||||
$servers = [];
|
||||
} else {
|
||||
$servers = json_decode($jsonContent, true) ?: [];
|
||||
}
|
||||
|
||||
// find out my own URL
|
||||
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
|
||||
|
||||
// Retrieve the host (e.g., www.example.com)
|
||||
$host = filter_var($_SERVER['HTTP_HOST'], FILTER_SANITIZE_STRING);
|
||||
$uri = filter_var($_SERVER['REQUEST_URI'], FILTER_SANITIZE_URL);
|
||||
$url = $protocol . htmlspecialchars($host) . htmlspecialchars($uri);
|
||||
array_unshift($servers,
|
||||
[
|
||||
"name"=> "This Server",
|
||||
"server"=> $url."backend/",
|
||||
"id"=> 1,
|
||||
"dlURL"=> "garbage.php",
|
||||
"ulURL"=> "empty.php",
|
||||
"pingURL"=> "empty.php",
|
||||
"getIpURL"=> "getIP.php"
|
||||
]
|
||||
);
|
||||
?>
|
||||
var SPEEDTEST_SERVERS= <?= json_encode($servers, JSON_PRETTY_PRINT) ?: '[]' ?>;
|
||||
<?php } else { ?>
|
||||
var SPEEDTEST_SERVERS= <?= file_get_contents('/servers.json') ?: '[]' ?>;
|
||||
<?php }
|
||||
if ($mode=="dual"){ ?>
|
||||
// add own server in dual mode
|
||||
SPEEDTEST_SERVERS.unshift({
|
||||
"name":"This Server",
|
||||
"server":document.location.href+"backend/",
|
||||
"id":1,
|
||||
"dlURL":"garbage.php",
|
||||
"ulURL":"empty.php",
|
||||
"pingURL":"empty.php",
|
||||
"getIpURL":"getIP.php",
|
||||
"pingT":-1
|
||||
})
|
||||
<?php } ?>
|
||||
|
||||
//INITIALIZE SPEED TEST
|
||||
var s=new Speedtest(); //create speed test object
|
||||
<?php if(getenv("TELEMETRY")=="true"){ ?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue