diff --git a/Dockerfile b/Dockerfile index dd261fd43..0d3483753 100755 --- a/Dockerfile +++ b/Dockerfile @@ -9,14 +9,13 @@ RUN apt-get update && apt-get install -y \ && docker-php-ext-install -j$(nproc) iconv \ && docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \ && docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \ - && docker-php-ext-install -j$(nproc) gd pdo pdo_mysql pdo_pgsql pgsql + && docker-php-ext-install -j$(nproc) gd pdo pdo_mysql pdo_pgsql pgsql \ + && rm -rf /var/lib/apt/lists/* # Prepare files and folders - RUN mkdir -p /speedtest/ # Copy sources - COPY backend/ /speedtest/backend COPY results/*.php /speedtest/results/ @@ -30,8 +29,7 @@ COPY docker/servers.json /servers.json COPY docker/*.php /speedtest/ COPY docker/entrypoint.sh / -# Prepare environment variabiles defaults - +# Prepare default environment variables ENV TITLE=LibreSpeed ENV MODE=standalone ENV PASSWORD=password @@ -41,6 +39,5 @@ 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 8df437196..81d692cb3 100755 --- a/README.md +++ b/README.md @@ -4,10 +4,10 @@ No Flash, No Java, No Websocket, No Bullshit. -This is a very lightweight Speedtest implemented in Javascript, using XMLHttpRequest and Web Workers. +This is a very lightweight speed test implemented in Javascript, using XMLHttpRequest and Web Workers. ## Try it -[Take a Speedtest](https://librespeed.org) +[Take a speed test](https://librespeed.org) ## Compatibility All modern browsers are supported: IE11, latest Edge, latest Chrome, latest Firefox, latest Safari. @@ -29,17 +29,30 @@ 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) -* MySQL database to store test results (optional, PostgreSQL and SQLite also supported) +* MySQL database to store test results (optional, Microsoft SQL Server, PostgreSQL and SQLite also supported) * A fast! internet connection -## Installation videos +## Installation +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 +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. +5. Be sure your permissions allow execute (755). +6. Visit YOURSITE/speedtest/index.html and voila! + +### Installation Video +There is a more in-depth installation video here: * [Quick start installation guide for Ubuntu Server 19.04](https://fdossena.com/?p=speedtest/quickstart_v5_ubuntu.frag) ## Android app A template to build an Android client for your LibreSpeed installation is available [here](https://github.com/librespeed/speedtest-android). ## Docker -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 +A docker image is available on the [Docker Hub](https://registry.hub.docker.com/r/adolfintel/speedtest), check our [docker documentation](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 620b30e82..51b5db9a6 100755 --- a/doc.md +++ b/doc.md @@ -5,7 +5,7 @@ > [https://github.com/librespeed/speedtest/](https://github.com/librespeed/speedtest/) ## Introduction -LibreSpeed is a Free and Open Source speedtest that you can host on your server(s), and users can run in their browser. +LibreSpeed is a Free and Open Source speed test that you can host on your server(s), and users can run in their browser. __Features:__ * Download test @@ -30,7 +30,7 @@ The following browsers are officially supported: Client side, the test can use up to 500MB of RAM on very fast connections. ## Quick start guides -These guides cover a simple single server installation of the Speedtest. +These guides cover a simple single server installation of the speed test. * [Quick start installation guide for Ubuntu Server 19.04](https://fdossena.com/?p=speedtest/quickstart_v5_ubuntu.frag) @@ -50,14 +50,14 @@ Server side, you'll need: * If you want to enable results sharing: - FreeType 2 and its PHP module (this is usually installed automatically by most distros) -Let's install the speedtest. +Let's install the speed test. Put all files on your web server via FTP or by copying them directly. You can install it in the root, or in a subdirectory. -__Important:__ The speedtest needs write permissions in the installation folder! +__Important:__ The speed test needs write permissions in the installation folder! #### ipinfo.io -The speedtest uses [ipinfo.io](https://ipinfo.io) to detect ISP and distance from server. This is completely optional and can be disabled if you want (see Speedtest settings), but it is enabled by default, and if you expect more than ~500 tests per day, you will need to sign up to [ipinfo.io](https://ipinfo.io) and edit `backend/getIP_ipInfo_apikey.php` to set your access token. +The speed test uses [ipinfo.io](https://ipinfo.io) to detect ISP and distance from server. This is completely optional and can be disabled if you want (see speed test settings), but it is enabled by default, and if you expect more than ~500 tests per day, you will need to sign up to [ipinfo.io](https://ipinfo.io) and edit `backend/getIP_ipInfo_apikey.php` to set your access token. IpInfo.io has kindly offered free access to their APIs for users of this project; if you're interested, contact me at [info@fdossena.com](mailto:info@fdossena.com) and provide a description of what you intend to do with the project, and you'll get the API key. @@ -117,14 +117,14 @@ If you're not using telemetry and results sharing, you can delete the `results` Details about the examples and how to make custom UIs will be discussed later. If you don't want to make a custom UI, feel free to modify the example and replace "LibreSpeed Example" with the name of your test. #### Privacy -Telemetry contains personal information (according to GDPR defintion), 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. +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.__ ### Multiple servers, PHP -The speedtest can automatically choose between multiple test points and use the one with the lowest ping in a list. +The speed test can automatically choose between multiple test points and use the one with the lowest ping in a list. -Note that this is an advanced use case and it is recommended that you already know how to use the speedtest with a single server. +Note that this is an advanced use case and it is recommended that you already know how to use the speed test with a single server. We must distinguish 2 types of servers: * __Frontend server__: hosts the UI, the JS files, and optionally telemetry and results sharing stuff. You only need 1 of these, and this is the server that your clients will first connect to. @@ -143,20 +143,20 @@ Requirements: * If you want to enable results sharing: - FreeType 2 and its PHP module (this is usually installed automatically by most distros) -To install the speedtest frontend, copy the following files to your web server: +To install the speed test frontend, copy the following files to your web server: * `speedtest.js` * `speedtest_worker.js` * Optionally, the `results` folder * One of the `multipleServers` examples (the best starting points are `example-multipleServers-pretty.html` if you don't want to use telemetry and results sharing, `example-multipleServers-full.html` if you want to use them). Rename the example you choose to `index.html` -__Important:__ The speedtest needs write permissions in the installation folder! +__Important:__ The speed test needs write permissions in the installation folder! ##### Server list Edit `index.html`, you will see a list of servers: ```js var SPEEDTEST_SERVERS=[ { - "name":"Speedtest Demo Server 1", //user friendly name for the server + "name":"Speed test Demo Server 1", //user friendly name for the server "server":"//mpotdemo.fdossena.com/", //URL to the server. // at the beginning will be replaced with http:// or https:// automatically "dlURL":"garbage.php", //path to download test on this server (garbage.php or replacement) "ulURL":"empty.php", //path to upload test on this server (empty.php or replacement) @@ -164,7 +164,7 @@ var SPEEDTEST_SERVERS=[ "getIpURL":"getIP.php" //path to getIP on this server (getIP.php or replacement) }, { - "name":"Speedtest Demo Server 2", + "name":"Speed test Demo Server 2", "server":"//mpotdemo2.fdossena.com/", "dlURL":"garbage.php", "ulURL":"empty.php", @@ -221,10 +221,10 @@ Requirements: To install a backend, simply copy all the files in the `backend` folder to your backend server. -__Important:__ The speedtest needs write permissions in the installation folder! +__Important:__ The speed test needs write permissions in the installation folder! #### ipinfo.io -The speedtest uses [ipinfo.io](https://ipinfo.io) to detect ISP and distance from server. This is completely optional and can be disabled if you want (see Speedtest settings), but it is enabled by default, and if you expect more than ~500 tests per day, you will need to sign up to [ipinfo.io](https://ipinfo.io) and edit `getIP_ipInfo_apikey.php` to set your access token. +The speed test uses [ipinfo.io](https://ipinfo.io) to detect ISP and distance from server. This is completely optional and can be disabled if you want (see speed test settings), but it is enabled by default, and if you expect more than ~500 tests per day, you will need to sign up to [ipinfo.io](https://ipinfo.io) and edit `getIP_ipInfo_apikey.php` to set your access token. IpInfo.io has kindly offered free access to their APIs for users of this project; if you're interested, contact me at [info@fdossena.com](mailto:info@fdossena.com) and provide a description of what you intend to do with the project, and you'll get the API key. @@ -247,7 +247,7 @@ __Multiple servers:__ * `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 ### Initialization -To use the speedtest in your page, first you need to load it: +To use the speed test in your page, first you need to load it: ```xml ``` @@ -271,7 +271,7 @@ s.onend=function(aborted){ } ``` -The `onupdate` event handler will be called periodically by the test with data coming from the speedtest worker thread. The `data` argument is an object containing the following: +The `onupdate` event handler will be called periodically by the test with data coming from the speed test worker thread. The `data` argument is an object containing the following: * __testState__: an integer between -1 and 5 * `-1` = Test not started yet * `0` = Test starting @@ -307,7 +307,7 @@ The `onupdate` event handler will be called periodically by the test with data c The `onend` event handler will be called at the end of the test (`onupdate` will be called first), with a boolean telling you if the test was aborted (either manually or because of an error) or if it ended normally. ### Test parameters -Before starting the test, you can change some of the settings from their default values. You might want to do this to better adapt the speedtest to a specific scenario, such as a satellite connection. To change a setting, use +Before starting the test, you can change some of the settings from their default values. You might want to do this to better adapt the speed test to a specific scenario, such as a satellite connection. To change a setting, use ```js s.setParameter("parameter_name",value); ``` @@ -362,7 +362,7 @@ __Main parameters:__ * __Important:__ On Firefox, it is better to run the upload test last * __getIp_ispInfo__: if true, the server will try to get ISP info and pass it along with the IP address. This will add `isp=true` to the request to `url_getIp`. getIP.php accomplishes this using ipinfo.io * Default: `true` -* __getIp_ispInfo_distance__: if true, the server will try to get an estimate of the distance from the client to the speedtest server. This will add a `distance` argument to the request to `url_getIp`. `__getIp_ispInfo__` must be enabled in order for this to work. getIP.php accomplishes this using ipinfo.io +* __getIp_ispInfo_distance__: if true, the server will try to get an estimate of the distance from the client to the speed test server. This will add a `distance` argument to the request to `url_getIp`. `__getIp_ispInfo__` must be enabled in order for this to work. getIP.php accomplishes this using ipinfo.io * `km`: estimate distance in kilometers * `mi`: estimate distance in miles * not set: do not measure distance @@ -421,7 +421,7 @@ __Advanced parameters:__ (Seriously, don't change these unless you know what you ### Multiple Points of Test If you want to use more than one test server, this is the time to add all your test points and select the best one. Skip this part if you don't want to use this feature. -The best way to do this is to declare an array with all your servers, and give it to the speedtest: +The best way to do this is to declare an array with all your servers, and give it to the speed test: ```js var SPEEDTEST_SERVERS=[ server1, @@ -483,15 +483,15 @@ s.abort(); When the test is finished, you can run it again if you want, or you can just destroy `s`. ## Implementation details -The purpose of this section is to help developers who want to make changes to the inner workings of the speedtest. +The purpose of this section is to help developers who want to make changes to the inner workings of the speed test. It will be divided into 4 sections: `speedtest.js`, `speedtest_worker.js`, the `backend` files and the `results` files. ### `speedtest.js` -This is the main interface between your webpage and the speedtest. -It hides the speedtest web worker to the page, and provides many convenient functions to control the test. +This is the main interface between your webpage and the speed test. +It hides the speed test web worker to the page, and provides many convenient functions to control the test. You can think of this as a finite state machine. These are the states (use getState() to see them): -* __0__: here you can change the speedtest settings (such as test duration) with the `setParameter("parameter",value)` function. From here you can either start the test using `start()` (goes to state 3) or you can add multiple test points using `addTestPoint(server)` or `addTestPoints(serverList)` (goes to state 1). Additionally, this is the perfect moment to set up callbacks for the `onupdate(data)` and `onend(aborted)` events. +* __0__: here you can change the speed test settings (such as test duration) with the `setParameter("parameter",value)` function. From here you can either start the test using `start()` (goes to state 3) or you can add multiple test points using `addTestPoint(server)` or `addTestPoints(serverList)` (goes to state 1). Additionally, this is the perfect moment to set up callbacks for the `onupdate(data)` and `onend(aborted)` events. * __1__: here you can add test points. You only need to do this if you want to use multiple test points. A server is defined as an object like this: ``` @@ -506,7 +506,7 @@ You can think of this as a finite state machine. These are the states (use getSt ``` While in state 1, you can only add test points, you cannot change the test settings. When you're done, use selectServer(callback) to select the test point with the lowest ping. This is asynchronous, when it's done, it will call your callback function and move to state 2. Calling setSelectedServer(server) will manually select a server and move to state 2. * __2__: test point selected, ready to start the test. Use `start()` to begin, this will move to state 3 -* __3__: test running. Here, your `onupdate` event calback will be called periodically, with data coming from the worker about speed and progress. A data object will be passed to your `onupdate` function, with the following items: +* __3__: test running. Here, your `onupdate` event callback will be called periodically, with data coming from the worker about speed and progress. A data object will be passed to your `onupdate` function, with the following items: - `dlStatus`: download speed in mbps - `ulStatus`: upload speed in mbps - `pingStatus`: ping in ms @@ -531,7 +531,7 @@ Change one of the test settings from their defaults. - parameter: string with the name of the parameter that you want to set - value: new value for the parameter -Invalid values or nonexistant parameters will be ignored by the speedtest worker. +Invalid values or nonexistant parameters will be ignored by the speed test worker. ##### addTestPoint(server) Add a test point (multiple points of test) @@ -547,7 +547,7 @@ Add a test point (multiple points of test) } ``` -Note that this will add `mpot`:`true` to the parameters sent to the speedtest worker. +Note that this will add `mpot`:`true` to the parameters sent to the speed test worker. ##### addTestPoints(list) Same as addTestPoint, but you can pass an array of servers @@ -582,7 +582,7 @@ At the end of the test, the `onend(aborted)` function will be called with a bool Aborts the test while it's running. ### `speedtest_worker.js` -This is where the actual speedtest code is. It receives the settings from the main thread, runs the test, and reports back the results. +This is where the actual speed test code is. It receives the settings from the main thread, runs the test, and reports back the results. The worker accepts 3 commands: * `start`: starts the test. Optionally, test settings can be passed as a JSON string after the word start and a space @@ -664,7 +664,7 @@ Access-Control-Allow-Headers: Content-Encoding, Content-Type This file stores telemetry information into the database. Data is passed as POST parameters: -* `ispinfo`: ISP info (if enabled, empty strng otherwise) +* `ispinfo`: ISP info (if enabled, empty string otherwise) * `extra`: the `telemetry_extra` string passed to the worker (if set, empty string otherwise) * `dl`: download speed * `ul`: upload speed @@ -689,11 +689,11 @@ See the code for the implementation details, it's basically a bunch of bitwise o Simple UI to display and search test results. Not required to run the test. ## Alternative backends -If for some reason you can't or don't want to use PHP, the speedtest can run with other backends, or even no backend (with limited functionality). +If for some reason you can't or don't want to use PHP, the speed test can run with other backends, or even no backend (with limited functionality). You will need replacements for `backend/garbage.php` and `backend/empty.php` and optionally `backend/getIP.php`, and the test needs to know where to find them: ```js -//Speedtest initialization +//Speed test initialization var s=new Speedtest(); ... //Custom backend @@ -725,7 +725,7 @@ Your replacement can simply respond with the client's IP as plaintext or do some If you want to make your own backend, see the section on the implementation details of `getIP.php`. ### No backend -The speedtest can run, albeit with limited functionality, using only a web server as backend, with no PHP or other server-side scripting. +The speed test can run, albeit with limited functionality, using only a web server as backend, with no PHP or other server-side scripting. You will be able to run the download and upload test, but no IP, ISP and distance detection, no telemetry and results sharing, and only a single point of test. @@ -741,7 +741,7 @@ s.setParameter("url_ping","backend/empty.dat"); s.setParameter("test_order","P_D_U"); ``` -This will point to our static files and set the test to only do ping/jitter, download and uplod tests. +This will point to our static files and set the test to only do ping/jitter, download and upload tests. ## Troubleshooting These are the most common issues reported by users, and how to fix them. If you still need help, contact me at [info@fdossena.com](mailto:info@fdossena.com). @@ -772,7 +772,7 @@ If the image doesn't display and the browser displays a broken image icon, FreeT If the image is blank, this usually happens because PHP can't find the font files inside the `results` folder. You can fix your PHP config or edit `results/index.php` and use absolute paths for the fonts. This is a [known issue with PHP](http://php.net/manual/en/function.imagefttext.php) and no real solution is known. #### My server is behind Cloudflare and I can't reach full speed on some of the tests -This is not a speedtest related issue, as it can be replicated in virtually any HTTP file upload/download. +This is not a speed test related issue, as it can be replicated in virtually any HTTP file upload/download. Go to your domain's DNS settings and change "DNS and HTTP proxy (CDN)" to "DNS only", and wait for the settings to be applied (can take a few minutes). #### On Windows Server, using IIS, the upload test doesn't work, CORS errors are visible in the console @@ -807,10 +807,10 @@ Also, make sure that the web server has write permission on the `results` folder ## Known bugs and limitations ### General -* The ping/jitter test is measured by seeing how long it takes for an empty XHR to complete. It is not an acutal ICMP ping. Different browsers may also show different results, especially on very fast connections on slow devices. +* The ping/jitter test is measured by seeing how long it takes for an empty XHR to complete. It is not an actual ICMP ping. Different browsers may also show different results, especially on very fast connections on slow devices. ### IE specific * The upload test is not precise on very fast connections with high latency (will probably be fixed by Edge 17) -* On IE11, a same origin policy error is erroneously triggered under unknown conditions. Seems to be related to running the test from unusual URLs like a top level domain (for instance http://abc/speedtest). These are bugs in IE11's implementation of the same origin policy, not in the speedtest itself. +* On IE11, a same origin policy error is erroneously triggered under unknown conditions. Seems to be related to running the test from unusual URLs like a top level domain (for instance http://abc/speedtest). These are bugs in IE11's implementation of the same origin policy, not in the speed test itself. * On IE11, under unknown circumstances, on some systems the test can only be run once, after which speedtest_worker.js will not be loaded by IE until the browser is restarted. This is a rare bug in IE11. ### Firefox specific * On some Linux systems with hardware acceleration turned off, the page rendering makes the browser lag, reducing the accuracy of the ping/jitter test, and potentially even the download and upload tests on very fast connections. diff --git a/doc_docker.md b/doc_docker.md index 753fe024c..6e377a2b2 100755 --- a/doc_docker.md +++ b/doc_docker.md @@ -9,14 +9,42 @@ docker pull adolfintel/speedtest You will now have a new docker image called `adolfintel/speedtest`. + +## Docker Compose +To start the container using [docker compose](https://docs.docker.com/compose/) the following configuration can be used: + +```yml +version: '3.7' +services: + speedtest: + container_name: speedtest + image: adolfintel/speedtest + restart: always + environment: + MODE: standalone + #TITLE: "LibreSpeed" + #TELEMETRY: "false" + #ENABLE_ID_OBFUSCATION: "false" + #REDACT_IP_ADDRESSES: "false" + #PASSWORD: + #EMAIL: + #DISABLE_IPINFO: "false" + #DISTANCE: "km" + #WEBPORT: 80 + ports: + - "80:80" # webport mapping (host:container) +``` + +Please adjust the environment variables according to the intended operating mode. + ## 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` +* __`TITLE`__: Title of your speed test. Default value: `LibreSpeed` +* __`TELEMETRY`__: Whether to enable telemetry or not. If enabled, you maybe want your data to be persisted. See below. 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. @@ -28,6 +56,13 @@ Here's a list of additional environment variables available in this mode: If telemetry is enabled, a stats page will be available at `http://your.server/results/stats.php`, but a password must be specified. +### Persist sqlite database + +Default DB driver is sqlite. The DB file is written to `/database/db.sql`. + +So if you want your data to be persisted over image updates, you have to mount a volume with `-v $PWD/db-dir:/database`. + + ###### Example This command starts LibreSpeed in standalone mode, with the default settings, on port 80: @@ -38,7 +73,7 @@ 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 +docker run -e MODE=standalone -e TELEMETRY=true -e ENABLE_ID_OBFUSCATION=true -e PASSWORD="yourPasswordHere" -e WEBPORT=86 -p 86:86 -v $PWD/db-dir/:/database -it adolfintel/speedtest ``` ## Multiple Points of Test diff --git a/docker/frontend.php b/docker/frontend.php index 366cdadce..8e801b632 100755 --- a/docker/frontend.php +++ b/docker/frontend.php @@ -11,8 +11,8 @@ function I(i){return document.getElementById(i);} //LIST OF TEST SERVERS. See documentation for details if needed var SPEEDTEST_SERVERS= ; -//INITIALIZE SPEEDTEST -var s=new Speedtest(); //create speedtest object +//INITIALIZE SPEED TEST +var s=new Speedtest(); //create speed test object s.setParameter("telemetry_level","basic"); @@ -112,7 +112,7 @@ function format(d){ var uiData=null; function startStop(){ if(s.getState()==3){ - //speedtest is running, abort + //speed test is running, abort s.abort(); data=null; I("startStopBtn").className=""; @@ -432,7 +432,7 @@ function initUI(){ - Run speedtest + Run speed test

Charts by Chart.js

Source code diff --git a/example-singleServer-full.html b/example-singleServer-full.html index 823ef9f29..d72aa6624 100755 --- a/example-singleServer-full.html +++ b/example-singleServer-full.html @@ -321,7 +321,7 @@

Share results