diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d60cd3d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,44 @@ +FROM php:7.4-apache + +# Install extensions +RUN apt-get update && apt-get install -y \ + libfreetype6-dev \ + libjpeg62-turbo-dev \ + libpng-dev \ + && docker-php-ext-install -j$(nproc) iconv \ + && docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \ + && docker-php-ext-install -j$(nproc) gd + +# Prepare files and folders + +RUN mkdir -p /speedtest/ + +# Copy sources + +COPY backend/ /speedtest/backend + +COPY results/*.php /speedtest/results/ +COPY results/*.ttf /speedtest/results/ + +COPY *.js /speedtest/ +COPY favicon.ico /speedtest/ + +COPY docker/servers.json /servers.json + +COPY docker/*.php /speedtest/ +COPY docker/entrypoint.sh / + +# Prepare environment variabiles defaults + +ENV TITLE=LibreSpeed +ENV MODE=standalone +ENV PASSWORD=password +ENV TELEMETRY=false +ENV ENABLE_ID_OBFUSCATION=false +ENV REDACT_IP_ADDRESSES=false +ENV WEBPORT=80 + +# Final touches + +EXPOSE 80 +CMD ["bash", "/entrypoint.sh"] diff --git a/README.md b/README.md index 7d0a72d..76dabf2 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Works with mobile versions too. A template to build an Android client for your LibreSpeed installation is available [here](https://github.com/librespeed/speedtest-android). ## Docker -Please see the `docker` branch +A docker image is available on the [Docker Hub](https://registry.hub.docker.com/r/adolfintel/speedtest), see `doc_docker.md` for more info about it ## Go backend A Go implementation is available in the [`speedtest-go`](https://github.com/librespeed/speedtest-go) repo, maintained by [Maddie Zhan](https://github.com/maddie). diff --git a/doc.md b/doc.md index c51d402..620b30e 100644 --- a/doc.md +++ b/doc.md @@ -1,7 +1,7 @@ # LibreSpeed > by Federico Dossena -> Version 5.2.3 +> Version 5.2.4 > [https://github.com/librespeed/speedtest/](https://github.com/librespeed/speedtest/) ## Introduction diff --git a/doc_docker.md b/doc_docker.md new file mode 100644 index 0000000..753fe02 --- /dev/null +++ b/doc_docker.md @@ -0,0 +1,106 @@ +A docker version of LibreSpeed is available on docker hub: [https://hub.docker.com/r/adolfintel/speedtest/](https://hub.docker.com/r/adolfintel/speedtest/) + +## Downloading from Docker hub +To download LibreSpeed from the docker hub, use this command: + +``` +docker pull adolfintel/speedtest +``` + +You will now have a new docker image called `adolfintel/speedtest`. + +## Standalone mode +If you want to install LibreSpeed on a single server, you need to configure it in standalone mode. To do this, set the `MODE` environment variable to `standalone`. + +The test can be accessed on port 80. + +Here's a list of additional environment variables available in this mode: +* __`TITLE`__: Title of your speedtest. Default value: `LibreSpeed` +* __`TELEMETRY`__: Whether to enable telemetry or not. Default value: `false` +* __`ENABLE_ID_OBFUSCATION`__: When set to true with telemetry enabled, test IDs are obfuscated, to avoid exposing the database internal sequential IDs. Default value: `false` +* __`REDACT_IP_ADDRESSES`__: When set to true with telemetry enabled, IP addresses and hostnames are redacted from the collected telemetry, for better privacy. Default value: `false` +* __`PASSWORD`__: Password to access the stats page. If not set, stats page will not allow accesses. +* __`EMAIL`__: Email address for GDPR requests. Must be specified when telemetry is enabled. +* __`IPINFO_APIKEY`__: API key for ipinfo.io. Optional, but required if you expect to serve a large number of tests +* __`DISABLE_IPINFO`__: If set to true, ISP info and distance will not be fetched from ipinfo.io. Default: value: `false` +* __`DISTANCE`__: When `DISABLE_IPINFO` is set to false, this specifies how the distance from the server is measured. Can be either `km` for kilometers, `mi` for miles, or an empty string to disable distance measurement. Default value: `km` +* __`WEBPORT`__: Allows choosing a custom port for the included web server. Default value: `80`. Note that you will have to expose it through docker with the -p argument + +If telemetry is enabled, a stats page will be available at `http://your.server/results/stats.php`, but a password must be specified. + +###### Example +This command starts LibreSpeed in standalone mode, with the default settings, on port 80: + +``` +docker run -e MODE=standalone -p 80:80 -it adolfintel/speedtest +``` + +This command starts LibreSpeed in standalone mode, with telemetry, ID obfuscation and a stats password, on port 86: + +``` +docker run -e MODE=standalone -e TELEMETRY=true -e ENABLE_ID_OBFUSCATION=true -e PASSWORD="yourPasswordHere" -e WEBPORT=86 -p 86:86 -it adolfintel/speedtest +``` + +## Multiple Points of Test +For multiple servers, you need to set up 1+ LibreSpeed backends, and 1 LibreSpeed frontend. + +### Backend mode +In backend mode, LibreSpeed provides only a test point with no UI. To do this, set the `MODE` environment variable to `backend`. + +The following backend files can be accessed on port 80: `garbage.php`, `empty.php`, `getIP.php` + +Here's a list of additional environment variables available in this mode: +* __`IPINFO_APIKEY`__: API key for ipinfo.io. Optional, but required if you expect to serve a large number of tests + +###### Example: +This command starts LibreSpeed in backend mode, with the default settings, on port 80: +``` +docker run -e MODE=backend -p 80:80 -it adolfintel/speedtest +``` + +### Frontend mode +In frontend mode, LibreSpeed serves clients the Web UI and a list of servers. To do this: +* Set the `MODE` environment variable to `frontend` +* Create a servers.json file with your test points. The syntax is the following: + ``` + [ + { + "name": "Friendly name for Server 1", + "server" :"//server1.mydomain.com/", + "dlURL" :"garbage.php", + "ulURL" :"empty.php", + "pingURL" :"empty.php", + "getIpURL" :"getIP.php" + }, + { + "name": "Friendly name for Server 2", + "server" :"https://server2.mydomain.com/", + "dlURL" :"garbage.php", + "ulURL" :"empty.php", + "pingURL" :"empty.php", + "getIpURL" :"getIP.php" + }, + ...more servers... + ] + ``` + Note: if a server only supports HTTP or HTTPS, specify the protocol in the server field. If it supports both, just use `//`. +* Mount this file to `/servers.json` in the container (example at the end of this file) + +The test can be accessed on port 80. + +Here's a list of additional environment variables available in this mode: +* __`TITLE`__: Title of your speedtest. Default value: `LibreSpeed` +* __`TELEMETRY`__: Whether to enable telemetry or not. Default value: `false` +* __`ENABLE_ID_OBFUSCATION`__: When set to true with telemetry enabled, test IDs are obfuscated, to avoid exposing the database internal sequential IDs. Default value: `false` +* __`REDACT_IP_ADDRESSES`__: When set to true with telemetry enabled, IP addresses and hostnames are redacted from the collected telemetry, for better privacy. Default value: `false` +* __`PASSWORD`__: Password to access the stats page. If not set, stats page will not allow accesses. +* __`EMAIL`__: Email address for GDPR requests. Must be specified when telemetry is enabled. +* __`DISABLE_IPINFO`__: If set to true, ISP info and distance will not be fetched from ipinfo.io. Default: value: `false` +* __`DISTANCE`__: When `DISABLE_IPINFO` is set to false, this specifies how the distance from the server is measured. Can be either `km` for kilometers, `mi` for miles, or an empty string to disable distance measurement. Default value: `km` +* __`WEBPORT`__: Allows choosing a custom port for the included web server. Default value: `80` + +###### Example +This command starts LibreSpeed in frontend mode, with a given `servers.json` file, and with telemetry, ID obfuscation, and a stats password: +``` +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 adolfintel/speedtest +``` diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100644 index 0000000..3a5af55 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +set -e +set -x + +# Cleanup +rm -rf /var/www/html/* + +# Copy frontend files +cp /speedtest/*.js /var/www/html/ + +# Copy favicon +cp /speedtest/favicon.ico /var/www/html/ + +# Set up backend side for standlone modes +if [ "$MODE" == "standalone" ]; 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 + fi +fi + +if [ "$MODE" == "backend" ]; then + cp -r /speedtest/backend/* /var/www/html + if [ ! -z "$IPINFO_APIKEY" ]; then + sed -i s/\$IPINFO_APIKEY\ =\ \'\'/\$IPINFO_APIKEY\ =\ \'$IPINFO_APIKEY\'/g /var/www/html/getIP_ipInfo_apikey.php + fi +fi + +# Set up index.php for frontend-only or standalone modes +if [ "$MODE" == "frontend" ]; 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 + cp -r /speedtest/results /var/www/html/results + + sed -i s/\$db_type\ =\ \'.*\'/\$db_type\ =\ \'sqlite\'\/g /var/www/html/results/telemetry_settings.php + sed -i s/\$Sqlite_db_file\ =\ \'.*\'/\$Sqlite_db_file=\'\\\/database\\\/db.sql\'/g /var/www/html/results/telemetry_settings.php + sed -i s/\$stats_password\ =\ \'.*\'/\$stats_password\ =\ \'$PASSWORD\'/g /var/www/html/results/telemetry_settings.php + + if [ "$ENABLE_ID_OBFUSCATION" == "true" ]; then + sed -i s/\$enable_id_obfuscation\ =\ .*\;/\$enable_id_obfuscation\ =\ true\;/g /var/www/html/results/telemetry_settings.php + fi + + if [ "$REDACT_IP_ADDRESSES" == "true" ]; then + sed -i s/\$redact_ip_addresses\ =\ .*\;/\$redact_ip_addresses\ =\ true\;/g /var/www/html/results/telemetry_settings.php + fi + + mkdir -p /database/ + chown www-data /database/ +fi + +chown -R www-data /var/www/html/* + +# Allow selection of Apache port for network_mode: host +if [ "$WEBPORT" != "80" ]; then + sed -i "s/^Listen 80\$/Listen $WEBPORT/g" /etc/apache2/ports.conf + sed -i "s/*:80>/*:$WEBPORT>/g" /etc/apache2/sites-available/000-default.conf +fi + +echo "Done, Starting APACHE" + +# This runs apache +apache2-foreground diff --git a/docker/frontend.php b/docker/frontend.php new file mode 100644 index 0000000..366cdad --- /dev/null +++ b/docker/frontend.php @@ -0,0 +1,472 @@ + + + + + + + + + +<?= getenv('TITLE') ?: 'LibreSpeed Example' ?> + + +

+
+

Selecting a server...

+
+ + + + diff --git a/docker/servers.json b/docker/servers.json new file mode 100644 index 0000000..bd2c04e --- /dev/null +++ b/docker/servers.json @@ -0,0 +1,19 @@ + +[ + { + "name": "Example server 1 (HTTP and HTTPS)", + "server" :"//example1.mydomain.com/", + "dlURL" :"garbage.php", + "ulURL" :"empty.php", + "pingURL" :"empty.php", + "getIpURL" :"getIP.php" + }, + { + "name": "Example server 2 (HTTPS only)", + "server" :"https://example2.mydomain.com/", + "dlURL" :"garbage.php", + "ulURL" :"empty.php", + "pingURL" :"empty.php", + "getIpURL" :"getIP.php" + } +] diff --git a/docker/standalone.php b/docker/standalone.php new file mode 100644 index 0000000..bf28693 --- /dev/null +++ b/docker/standalone.php @@ -0,0 +1,365 @@ + + + + + + + + + +<?= getenv('TITLE') ?: 'LibreSpeed Example' ?> + + +

+
+

+ + Privacy + +
+
+
+
Ping
+
+
ms
+
+
+
Jitter
+
+
ms
+
+
+
+
+
Download
+ +
+
Mbps
+
+
+
Upload
+ +
+
Mbps
+
+
+
+ +
+ +
+ Source code +
+ + + + diff --git a/speedtest.js b/speedtest.js index 7d42a1c..61d0e77 100644 --- a/speedtest.js +++ b/speedtest.js @@ -49,7 +49,7 @@ function Speedtest() { this._settings = {}; //settings for the speedtest 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.3 - https://github.com/librespeed/speedtest" + "LibreSpeed by Federico Dossena v5.2.4 - https://github.com/librespeed/speedtest" ); }