Skip to content

Commit

Permalink
Merge branch 'librespeed:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
cremesk committed May 20, 2024
2 parents 2e5cb6b + 3034bf2 commit ad040a8
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 22 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ name: Docker
# documentation.

on:
# schedule:
# - cron: '30 20 * * *'
schedule:
- cron: '30 20 * * Sun'
push:
branches: ["*"]
# Publish semver tags as releases.
Expand Down Expand Up @@ -73,6 +73,7 @@ jobs:
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ ENV ENABLE_ID_OBFUSCATION=false
ENV REDACT_IP_ADDRESSES=false
ENV WEBPORT=80

# https://httpd.apache.org/docs/2.4/stopping.html#gracefulstop
STOPSIGNAL SIGWINCH

# Final touches
EXPOSE 80
CMD ["bash", "/entrypoint.sh"]
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Works with mobile versions too.

## Server requirements
* A reasonably fast web server with Apache 2 (nginx, IIS also supported)
* PHP 5.4 (other backends also available)
* PHP 5.4 or newer (other backends also available)
* MySQL database to store test results (optional, Microsoft SQL Server, PostgreSQL and SQLite also supported)
* A fast! internet connection

Expand All @@ -37,7 +37,7 @@ Assuming you have PHP installed, the installation steps are quite simple.
I set this up on a QNAP.
For this example, I am using a folder called **speedtest** in my web share area.

1. Choose one of the example-xxx.html files as your new index.html in your speedtest folder. I used: example-singleServer-full.html
1. Choose one of the example-xxx.html files in `examples` folder as your index.html if the default index.html does not fit.
2. Add: speedtest.js, speedtest_worker.js, and favicon.ico to your speedtest folder.
3. Download all of the backend folder into speedtest/backend.
4. Download all of the results folder into speedtest/results.
Expand All @@ -51,6 +51,9 @@ There is a more in-depth installation video here:
## Android app
A template to build an Android client for your LibreSpeed installation is available [here](https://github.com/librespeed/speedtest-android).

## CLI client
A command line client is available [here](https://github.com/librespeed/speedtest-cli).

## Docker
A docker image is available on [GitHub](https://github.com/librespeed/speedtest/pkgs/container/speedtest), check our [docker documentation](doc_docker.md) for more info about it.

Expand Down
6 changes: 1 addition & 5 deletions backend/garbage.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ function sendHeaders()
$chunks = getChunkCount();

// Generate data
if (function_exists('random_bytes')) {
$data = random_bytes(1048576);
} else {
$data = openssl_random_pseudo_bytes(1048576);
}
$data = openssl_random_pseudo_bytes(1048576);

// Deliver chunks of 1048576 bytes
sendHeaders();
Expand Down
5 changes: 5 additions & 0 deletions backend/getIP.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ function getLocalOrPrivateIpInfo($ip)
return 'link-local IPv6 access';
}

// fc00::/7 Unique Local IPv6 Unicast Addresses
if (preg_match('/^(fc|fd)([0-9a-f]{0,4}:){1,7}[0-9a-f]{1,4}$/i', $ip) === 1) {
return 'ULA IPv6 access';
}

// anything within the 127/8 range is localhost ipv4, the ip must start with 127.0
if (strpos($ip, '127.') === 0) {
return 'localhost IPv4 access';
Expand Down
9 changes: 4 additions & 5 deletions doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ A basic front-end for visualizing and searching tests by ID is available in `res
A login is required to access the interface. __Important__: change the default password in `results/telemetry_settings.php`.

#### The end
Now that the test is installed, rename one of the examples to `index.html` and delete the other examples.
The best starting point for most people is `example-singleServer-gauges.html`. If you want to use telemetry and results sharing, use `example-singleServer-full.html` instead.
Now that the test is installed, the default page uses telemetry and results sharing. If you want another index page, rename one of the examples to `index.html` and delete the other examples. The best starting point for most people is `example-singleServer-gauges.html`.

If you're not using telemetry and results sharing, you can delete the `results` folder too.

Expand All @@ -119,7 +118,7 @@ Details about the examples and how to make custom UIs will be discussed later. I
#### Privacy
Telemetry contains personal information (according to GDPR definition), therefore it is important to treat this data respectfully of national and international laws, especially if you plan to offer the service in the European Union.

`example-singleServer-full.html` and `example-multipleServers-full.html` both contain a privacy policy for the service: you MUST read it, change it if necessary, and add your email address for data deletion requests. __Failure to comply with GDPR regulations can get you in serious trouble.__
Default `index.html` and `example-multipleServers-full.html` both contain a privacy policy for the service: you MUST read it, change it if necessary, and add your email address for data deletion requests. __Failure to comply with GDPR regulations can get you in serious trouble.__

### Multiple servers, PHP
The speed test can automatically choose between multiple test points and use the one with the lowest ping in a list.
Expand Down Expand Up @@ -240,11 +239,11 @@ __Single server:__
* `example-singleServer-customSettings.html`: Same as `example-singleServer-pretty.html` but configures the test so that it only performs download and upload tests, and with a fixed length instead of automatic
* `example-singleServer-gauges.html`: The most sophisticated example, with the same functionality as `example-singleServer-pretty.html` but adds gauges. This is also a good starting point, but the gauges may slow down underpowered devices
* `example-singleServer-chart.html`: Shows how to use the test with the Chart.js library
* `example-singleServer-full.html`: The most complete example. Based on `example-singleServer-gauges.html`, also enables telemetry and results sharing
* default `index.html`: The most complete example. Based on `example-singleServer-gauges.html`, also enables telemetry and results sharing

__Multiple servers:__
* `example-multipleServers-pretty.html`: Same as `example-singleServer-pretty.html` but with multiple test points. Server selection is fully automatic
* `example-multipleServers-full.html`: Same as `example-singleServer-full.html` but with multiple test points. Server selection is automatic but the server can be changed afterwards by the user
* `example-multipleServers-full.html`: Same as default `index.html` but with multiple test points. Server selection is automatic but the server can be changed afterwards by the user

### Initialization
To use the speed test in your page, first you need to load it:
Expand Down
7 changes: 7 additions & 0 deletions doc_docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,10 @@ This command starts LibreSpeed in frontend mode, with a given `servers.json` fil
```
docker run -e MODE=frontend -e TELEMETRY=true -e ENABLE_ID_OBFUSCATION=true -e PASSWORD="yourPasswordHere" -v $(pwd)/servers.json:/servers.json -p 80:80 -it ghcr.io/librespeed/speedtest
```

### Dual mode
In dual mode, LibreSpeed operates as a standalone server that can also connect to other test points.
To do this:
* Set the `MODE` environment variable to `dual`
* Follow the `servers.json` instructions for the frontend mode
* The first server entry should be the local server, using the server endpoint address that a client can access.
8 changes: 4 additions & 4 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cp /speedtest/*.js /var/www/html/
cp /speedtest/favicon.ico /var/www/html/

# Set up backend side for standlone modes
if [ "$MODE" == "standalone" ]; then
if [[ "$MODE" == "standalone" || "$MODE" == "dual" ]]; then
cp -r /speedtest/backend/ /var/www/html/backend
if [ ! -z "$IPINFO_APIKEY" ]; then
sed -i s/\$IPINFO_APIKEY\ =\ \'\'/\$IPINFO_APIKEY\ =\ \'$IPINFO_APIKEY\'/g /var/www/html/backend/getIP_ipInfo_apikey.php
Expand All @@ -28,14 +28,14 @@ if [ "$MODE" == "backend" ]; then
fi

# Set up index.php for frontend-only or standalone modes
if [ "$MODE" == "frontend" ]; then
if [[ "$MODE" == "frontend" || "$MODE" == "dual" ]]; then
cp /speedtest/frontend.php /var/www/html/index.php
elif [ "$MODE" == "standalone" ]; then
cp /speedtest/standalone.php /var/www/html/index.php
fi

# Apply Telemetry settings when running in standalone or frontend mode and telemetry is enabled
if [[ "$TELEMETRY" == "true" && ( "$MODE" == "frontend" || "$MODE" == "standalone" ) ]]; then
if [[ "$TELEMETRY" == "true" && ( "$MODE" == "frontend" || "$MODE" == "standalone" || "$MODE" == "dual" ) ]]; then
cp -r /speedtest/results /var/www/html/results

if [ "$MODE" == "frontend" ]; then
Expand Down Expand Up @@ -88,4 +88,4 @@ fi
echo "Done, Starting APACHE"

# This runs apache
apache2-foreground
exec apache2-foreground
9 changes: 6 additions & 3 deletions results/json.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

error_reporting(0);
header('Content-Type: application/json; charset=utf-8');

require_once 'telemetry_db.php';

/**
Expand Down Expand Up @@ -53,7 +56,7 @@ function formatSpeedtestData($speedtest)
$speedtest = getSpeedtestUserById($_GET['id']);
if (!is_array($speedtest)) {
echo '{}';
} else {
$speedtest = formatSpeedtestData($speedtest);
echo json_encode(array('timestamp'=>$speedtest['timestamp'],'download'=>$speedtest['dl'],'upload'=>$speedtest['ul'],'ping'=>$speedtest['ping'],'jitter'=>$speedtest['jitter'],'ispinfo'=>$speedtest['ispinfo']));
}
$speedtest = formatSpeedtestData($speedtest);

echo json_encode(array('timestamp'=>$speedtest['timestamp'],'download'=>$speedtest['dl'],'upload'=>$speedtest['ul'],'ping'=>$speedtest['ping'],'jitter'=>$speedtest['jitter'],'ispinfo'=>$speedtest['ispinfo']));
2 changes: 1 addition & 1 deletion speedtest.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function Speedtest() {
this._settings = {}; //settings for the speed test worker
this._state = 0; //0=adding settings, 1=adding servers, 2=server selection done, 3=test running, 4=done
console.log(
"LibreSpeed by Federico Dossena v5.2.5 - https://github.com/librespeed/speedtest"
"LibreSpeed by Federico Dossena v5.3.1 - https://github.com/librespeed/speedtest"
);
}

Expand Down

0 comments on commit ad040a8

Please sign in to comment.