mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2025-12-21 21:33:08 +01:00
Compare commits
228 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
858dcc1f7b | ||
|
|
283de67e17 | ||
|
|
d92dd33b84 | ||
|
|
0c8e074a86 | ||
|
|
0384f61f15 | ||
|
|
98e037bf97 | ||
|
|
0b1645cda0 | ||
|
|
9fb573e785 | ||
|
|
219c5d6b7a | ||
|
|
ce549b5b7a | ||
|
|
a962865867 | ||
|
|
48fbbc3713 | ||
|
|
f809f816c1 | ||
|
|
91b7ec7fab | ||
|
|
5dbc6b900a | ||
|
|
4dc3e5b09c | ||
|
|
7cf8dfc0b2 | ||
|
|
99c64af482 | ||
|
|
0b8ccfd8d3 | ||
|
|
7b16f1ab09 | ||
|
|
845359726d | ||
|
|
4e6049b7ec | ||
|
|
5db1106c37 | ||
|
|
cb5abcfa98 | ||
|
|
76e21bfe9d | ||
|
|
dd871606a4 | ||
|
|
492b5df6ae | ||
|
|
f92c040f63 | ||
|
|
b82b7c6307 | ||
|
|
20b3cb98b6 | ||
|
|
bed7e841c2 | ||
|
|
1d9fba6421 | ||
|
|
78fcf49688 | ||
|
|
b0659fd0d3 | ||
|
|
5e2cc96830 | ||
|
|
39b3637b44 | ||
|
|
9870aeb9ba | ||
|
|
fe871a7d58 | ||
|
|
c9e86ac5aa | ||
|
|
b232c21ae1 | ||
|
|
305e4bb17f | ||
|
|
0b593e60b4 | ||
|
|
d91a5ef0a4 | ||
|
|
a71356f197 | ||
|
|
ac4fd6cb20 | ||
|
|
2861196cff | ||
|
|
85d2d87e53 | ||
|
|
a45f52f7b3 | ||
|
|
2d60f1c81d | ||
|
|
ce4913afa6 | ||
|
|
75c5a49398 | ||
|
|
a2d8886bae | ||
|
|
ba8f82aa98 | ||
|
|
1fd033b3c1 | ||
|
|
a170a96ced | ||
|
|
99d80ed235 | ||
|
|
9541117125 | ||
|
|
db7e307b20 | ||
|
|
e90619b536 | ||
|
|
fa58ab0168 | ||
|
|
c98ddc74c1 | ||
|
|
2d6e00f51b | ||
|
|
744f045ccf | ||
|
|
56e3b15e75 | ||
|
|
8468ffc022 | ||
|
|
7fece6fd89 | ||
|
|
c5c3a54809 | ||
|
|
2837f9f031 | ||
|
|
d1efe9a166 | ||
|
|
be2c70605e | ||
|
|
e21ce23bbe | ||
|
|
6b7bbf089f | ||
|
|
cee8a887ef | ||
|
|
dcd3381259 | ||
|
|
dab973dbf8 | ||
|
|
0c23b16164 | ||
|
|
02f76ca617 | ||
|
|
11fb44b789 | ||
|
|
715dac7828 | ||
|
|
9b4a0afda0 | ||
|
|
da8e7f409c | ||
|
|
676df45ae9 | ||
|
|
2f8d12dba1 | ||
|
|
4929d0efac | ||
|
|
bee655dd8f | ||
|
|
32bcde92bb | ||
|
|
f412dc70e6 | ||
|
|
681fc8fbed | ||
|
|
a81adebe62 | ||
|
|
1ae66474f3 | ||
|
|
dd158c7c83 | ||
|
|
fd70dc6cb8 | ||
|
|
77576f6537 | ||
|
|
f41039ce78 | ||
|
|
2ada8a22a9 | ||
|
|
52a91af086 | ||
|
|
af66d17ba4 | ||
|
|
dd27802e0f | ||
|
|
3444b8be18 | ||
|
|
043fd42b9a | ||
|
|
eeec6ae26c | ||
|
|
05d276fca0 | ||
|
|
f5f378e8c3 | ||
|
|
2f8137db0e | ||
|
|
95dbbc96b6 | ||
|
|
3d44da1f87 | ||
|
|
4e8b46f786 | ||
|
|
f110704a7a | ||
|
|
73517f92f7 | ||
|
|
ea9e5c1a52 | ||
|
|
ad36edc749 | ||
|
|
1467bee847 | ||
|
|
67eec58d74 | ||
|
|
752ef06626 | ||
|
|
feffc0023f | ||
|
|
f918288728 | ||
|
|
b74e69314a | ||
|
|
44c6c256c0 | ||
|
|
fde30602b0 | ||
|
|
a7652af2ba | ||
|
|
95325db128 | ||
|
|
46d13fd08a | ||
|
|
1637e66bef | ||
|
|
71e132e513 | ||
|
|
21ed016d25 | ||
|
|
8bc6975b69 | ||
|
|
5a0f5a2b3c | ||
|
|
17b72b91d0 | ||
|
|
0910bbb757 | ||
|
|
e9de226c7a | ||
|
|
10137a602a | ||
|
|
342e87b08d | ||
|
|
100cc1d768 | ||
|
|
2d1af61fb1 | ||
|
|
41a3bb3b5b | ||
|
|
365acda11c | ||
|
|
2df827b722 | ||
|
|
48839a0aa3 | ||
|
|
05e856799a | ||
|
|
2a243d251c | ||
|
|
73999eba53 | ||
|
|
24a2c0e7df | ||
|
|
c18b334128 | ||
|
|
e479e828bb | ||
|
|
f9b6f99a05 | ||
|
|
d577954660 | ||
|
|
cf5bafe586 | ||
|
|
7eb668a892 | ||
|
|
bc28094e67 | ||
|
|
326b0edbac | ||
|
|
eb1ec516b9 | ||
|
|
33c61071d4 | ||
|
|
6306824351 | ||
|
|
47cbce56a9 | ||
|
|
f8387e4f4b | ||
|
|
353b381f25 | ||
|
|
065bc45d11 | ||
|
|
4d78eff393 | ||
|
|
14ba9e092f | ||
|
|
628b0fdbea | ||
|
|
2cb31d52a7 | ||
|
|
8b8c3ae801 | ||
|
|
846942929e | ||
|
|
8e151c9ce5 | ||
|
|
a568d83dbc | ||
|
|
dcf94b6a4b | ||
|
|
47ecb7d58c | ||
|
|
4e61e0fccb | ||
|
|
59a4a25bed | ||
|
|
0e60bf195f | ||
|
|
2b57d6c244 | ||
|
|
8f846bd4fe | ||
|
|
081eac4f1e | ||
|
|
7071d0ac4c | ||
|
|
87aba591c0 | ||
|
|
5e5e9d8992 | ||
|
|
d16889f406 | ||
|
|
5d0020a707 | ||
|
|
e9d8f4754b | ||
|
|
18439da15a | ||
|
|
2919c9fb9b | ||
|
|
3097c244de | ||
|
|
6c64613628 | ||
|
|
2e39a238e7 | ||
|
|
8e003017bd | ||
|
|
9190385f93 | ||
|
|
226e2c42a7 | ||
|
|
c55baae478 | ||
|
|
7654da9559 | ||
|
|
7922955217 | ||
|
|
c90b40a96f | ||
|
|
72ff3317fa | ||
|
|
b00db26910 | ||
|
|
b31252a7b3 | ||
|
|
a836967445 | ||
|
|
ced5a2e7a4 | ||
|
|
270abea478 | ||
|
|
efc9b29360 | ||
|
|
b9d289c9d2 | ||
|
|
1562e13e19 | ||
|
|
0b00ba2304 | ||
|
|
5f5b731fbe | ||
|
|
dd7df0df81 | ||
|
|
0e454f8143 | ||
|
|
f61be56f2e | ||
|
|
f33af5fc41 | ||
|
|
861d354d15 | ||
|
|
07b419801c | ||
|
|
be2be4583c | ||
|
|
b05168ac6f | ||
|
|
c70e7a26c4 | ||
|
|
daf9975853 | ||
|
|
7a03c64ceb | ||
|
|
29a0b3d0a1 | ||
|
|
1c09d39b1e | ||
|
|
439c6322f2 | ||
|
|
d093a89829 | ||
|
|
6ffd59485a | ||
|
|
7dd7cdda8c | ||
|
|
15e4537ea6 | ||
|
|
4403cf161c | ||
|
|
7a950b838a | ||
|
|
21d3aea934 | ||
|
|
342d3fabf4 | ||
|
|
0b8c633a75 | ||
|
|
212c7a99bf | ||
|
|
3dc494b02e | ||
|
|
478c209bb2 |
19
.dockerignore
Normal file
19
.dockerignore
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
/node_modules
|
||||||
|
/public/hot
|
||||||
|
/public/storage
|
||||||
|
/storage/*.key
|
||||||
|
/vendor
|
||||||
|
.env
|
||||||
|
.env.backup
|
||||||
|
.phpunit.result.cache
|
||||||
|
Homestead.json
|
||||||
|
Homestead.yaml
|
||||||
|
npm-debug.log
|
||||||
|
yarn-error.log
|
||||||
|
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
_ide_helper.php
|
||||||
|
.idea
|
||||||
|
.config
|
||||||
|
reports/
|
||||||
16
.github/workflows/docker-image-pr.yml
vendored
Normal file
16
.github/workflows/docker-image-pr.yml
vendored
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
name: DockerPR
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches: [ docker, dev-docker, alpha-docker ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Build the Docker image
|
||||||
|
run: docker build . --file Dockerfile --tag my-image-name:$(date +%s)
|
||||||
5
.github/workflows/laravel-dev.yml
vendored
5
.github/workflows/laravel-dev.yml
vendored
@@ -10,6 +10,9 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
- uses: shivammathur/setup-php@b7d1d9c9a92d8d8463ce36d7f60da34d461724f8
|
||||||
|
with:
|
||||||
|
php-version: '7.4'
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Copy .env
|
- name: Copy .env
|
||||||
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
|
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
|
||||||
@@ -43,7 +46,7 @@ jobs:
|
|||||||
- name: Directory Permissions
|
- name: Directory Permissions
|
||||||
run: chmod -R 777 storage bootstrap/cache
|
run: chmod -R 777 storage bootstrap/cache
|
||||||
- name: Download Speedtest binary
|
- name: Download Speedtest binary
|
||||||
run: wget https://bintray.com/ookla/download/download_file?file_path=ookla-speedtest-1.0.0-x86_64-linux.tgz -O speedtest.tgz && tar zxvf speedtest.tgz && mv speedtest app/Bin/
|
run: wget https://install.speedtest.net/app/cli/ookla-speedtest-1.0.0-x86_64-linux.tgz -O speedtest.tgz && tar zxvf speedtest.tgz && mv speedtest app/Bin/
|
||||||
- name: Accept EULA
|
- name: Accept EULA
|
||||||
env:
|
env:
|
||||||
DB_CONNECTION: sqlite
|
DB_CONNECTION: sqlite
|
||||||
|
|||||||
7
.github/workflows/laravel-pr.yml
vendored
7
.github/workflows/laravel-pr.yml
vendored
@@ -10,6 +10,9 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
- uses: shivammathur/setup-php@b7d1d9c9a92d8d8463ce36d7f60da34d461724f8
|
||||||
|
with:
|
||||||
|
php-version: '7.4'
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Copy .env
|
- name: Copy .env
|
||||||
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
|
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
|
||||||
@@ -43,7 +46,7 @@ jobs:
|
|||||||
- name: Directory Permissions
|
- name: Directory Permissions
|
||||||
run: chmod -R 777 storage bootstrap/cache
|
run: chmod -R 777 storage bootstrap/cache
|
||||||
- name: Download Speedtest binary
|
- name: Download Speedtest binary
|
||||||
run: wget https://bintray.com/ookla/download/download_file?file_path=ookla-speedtest-1.0.0-x86_64-linux.tgz -O speedtest.tgz && tar zxvf speedtest.tgz && mv speedtest app/Bin/
|
run: wget https://install.speedtest.net/app/cli/ookla-speedtest-1.0.0-x86_64-linux.tgz -O speedtest.tgz && tar zxvf speedtest.tgz && mv speedtest app/Bin/
|
||||||
- name: Accept EULA
|
- name: Accept EULA
|
||||||
env:
|
env:
|
||||||
DB_CONNECTION: sqlite
|
DB_CONNECTION: sqlite
|
||||||
@@ -53,4 +56,4 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
DB_CONNECTION: sqlite
|
DB_CONNECTION: sqlite
|
||||||
DB_DATABASE: database/database.sqlite
|
DB_DATABASE: database/database.sqlite
|
||||||
run: vendor/bin/phpunit
|
run: php artisan test --parallel
|
||||||
|
|||||||
5
.github/workflows/laravel-stable.yml
vendored
5
.github/workflows/laravel-stable.yml
vendored
@@ -10,6 +10,9 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
- uses: shivammathur/setup-php@b7d1d9c9a92d8d8463ce36d7f60da34d461724f8
|
||||||
|
with:
|
||||||
|
php-version: '7.4'
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Copy .env
|
- name: Copy .env
|
||||||
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
|
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
|
||||||
@@ -43,7 +46,7 @@ jobs:
|
|||||||
- name: Directory Permissions
|
- name: Directory Permissions
|
||||||
run: chmod -R 777 storage bootstrap/cache
|
run: chmod -R 777 storage bootstrap/cache
|
||||||
- name: Download Speedtest binary
|
- name: Download Speedtest binary
|
||||||
run: wget https://bintray.com/ookla/download/download_file?file_path=ookla-speedtest-1.0.0-x86_64-linux.tgz -O speedtest.tgz && tar zxvf speedtest.tgz && mv speedtest app/Bin/
|
run: wget https://install.speedtest.net/app/cli/ookla-speedtest-1.0.0-x86_64-linux.tgz -O speedtest.tgz && tar zxvf speedtest.tgz && mv speedtest app/Bin/
|
||||||
- name: Accept EULA
|
- name: Accept EULA
|
||||||
env:
|
env:
|
||||||
DB_CONNECTION: sqlite
|
DB_CONNECTION: sqlite
|
||||||
|
|||||||
11
README.md
11
README.md
@@ -1,6 +1,6 @@
|
|||||||
# Speedtest Tracker
|
# Speedtest Tracker
|
||||||
|
|
||||||
[](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits)  [](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE)
|
[](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) [](https://github.com/henrywhitaker3/Speedtest-Tracker/commits)  [](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE)
|
||||||
|
|
||||||
This program runs a speedtest check every hour and graphs the results. The back-end is written in [Laravel](https://laravel.com/) and the front-end uses [React](https://reactjs.org/). It uses the [Ookla's speedtest cli](https://www.speedtest.net/apps/cli) package to get the data and uses [Chart.js](https://www.chartjs.org/) to plot the results.
|
This program runs a speedtest check every hour and graphs the results. The back-end is written in [Laravel](https://laravel.com/) and the front-end uses [React](https://reactjs.org/). It uses the [Ookla's speedtest cli](https://www.speedtest.net/apps/cli) package to get the data and uses [Chart.js](https://www.chartjs.org/) to plot the results.
|
||||||
|
|
||||||
@@ -18,6 +18,7 @@ Disclaimer: You will need to accept Ookla's EULA and privacy agreements in order
|
|||||||
- Slack/Discord/Telegram notifications
|
- Slack/Discord/Telegram notifications
|
||||||
- [healthchecks.io](https://healthchecks.io) integration
|
- [healthchecks.io](https://healthchecks.io) integration
|
||||||
- Organizr integration
|
- Organizr integration
|
||||||
|
- InfluxDB integration (currently v1 only, v2 is a WIP)
|
||||||
|
|
||||||
## Installation & Setup
|
## Installation & Setup
|
||||||
|
|
||||||
@@ -84,6 +85,8 @@ Container images are configured using parameters passed at runtime (such as thos
|
|||||||
| `-e PUID` | Optional. Supply a local user ID for volume permissions |
|
| `-e PUID` | Optional. Supply a local user ID for volume permissions |
|
||||||
| `-e PGID` | Optional. Supply a local group ID for volume permissions |
|
| `-e PGID` | Optional. Supply a local group ID for volume permissions |
|
||||||
| `-e AUTH` | Optional. Set to 'true' to enable authentication for the app |
|
| `-e AUTH` | Optional. Set to 'true' to enable authentication for the app |
|
||||||
|
| `-e INFLUXDB_RETENTION`| Optional. Sets the InfluxDB retention period, defaults to `30d` |
|
||||||
|
| `-e INFLUXDB_HOST_TAG | Optional. Sets the InfluxDB host tag value, defaults to `speedtest` |
|
||||||
|
|
||||||
### Authentication
|
### Authentication
|
||||||
|
|
||||||
@@ -100,4 +103,8 @@ After enabling, you should change the password through the web UI.
|
|||||||
|
|
||||||
### Manual Install
|
### Manual Install
|
||||||
|
|
||||||
For manual installtions, please follow the instrucitons [here](https://github.com/henrywhitaker3/Speedtest-Tracker/wiki/Manual-Installation).
|
For manual installations, please follow the instructions [here](https://github.com/henrywhitaker3/Speedtest-Tracker/wiki/Manual-Installation).
|
||||||
|
|
||||||
|
### Kubernetes
|
||||||
|
|
||||||
|
There is a 3rd party helm chart available [here](https://github.com/sOblivionsCall/charts).
|
||||||
|
|||||||
48
app/Actions/GetFailedSpeedtestData.php
Normal file
48
app/Actions/GetFailedSpeedtestData.php
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions;
|
||||||
|
|
||||||
|
use App\Models\Speedtest;
|
||||||
|
use Cache;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use DB;
|
||||||
|
use Henrywhitaker3\LaravelActions\Interfaces\ActionInterface;
|
||||||
|
|
||||||
|
class GetFailedSpeedtestData implements ActionInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the action.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function run($days = 7)
|
||||||
|
{
|
||||||
|
$ttl = Carbon::now()->addDays(1);
|
||||||
|
|
||||||
|
return Cache::remember('failure-rate-' . $days, $ttl, function () use ($days) {
|
||||||
|
$range = [
|
||||||
|
Carbon::today()
|
||||||
|
];
|
||||||
|
for ($i = 0; $i < ($days - 1); $i++) {
|
||||||
|
$prev = end($range);
|
||||||
|
$new = $prev->copy()->subDays(1);
|
||||||
|
array_push($range, $new);
|
||||||
|
}
|
||||||
|
|
||||||
|
$rate = [];
|
||||||
|
|
||||||
|
foreach ($range as $day) {
|
||||||
|
$success = Speedtest::select(DB::raw('COUNT(id) as rate'))->whereDate('created_at', $day)->where('failed', false)->get()[0]['rate'];
|
||||||
|
$fail = Speedtest::select(DB::raw('COUNT(id) as rate'))->whereDate('created_at', $day)->where('failed', true)->get()[0]['rate'];
|
||||||
|
|
||||||
|
array_push($rate, [
|
||||||
|
'date' => $day->toDateString(),
|
||||||
|
'success' => $success,
|
||||||
|
'failure' => $fail,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_reverse($rate);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
52
app/Actions/GetLatestSpeedtestData.php
Normal file
52
app/Actions/GetLatestSpeedtestData.php
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions;
|
||||||
|
|
||||||
|
use App\Helpers\SettingsHelper;
|
||||||
|
use App\Helpers\SpeedtestHelper;
|
||||||
|
use App\Models\Speedtest;
|
||||||
|
use DB;
|
||||||
|
use Henrywhitaker3\LaravelActions\Interfaces\ActionInterface;
|
||||||
|
|
||||||
|
class GetLatestSpeedtestData implements ActionInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the action.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
$data = SpeedtestHelper::latest();
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'data' => $data,
|
||||||
|
];
|
||||||
|
|
||||||
|
if (SettingsHelper::get('show_average')) {
|
||||||
|
$avg = Speedtest::select(DB::raw('AVG(ping) as ping, AVG(download) as download, AVG(upload) as upload'))
|
||||||
|
->where('failed', false)
|
||||||
|
->first()
|
||||||
|
->toArray();
|
||||||
|
$response['average'] = $avg;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SettingsHelper::get('show_max')) {
|
||||||
|
$max = Speedtest::select(DB::raw('MAX(ping) as ping, MAX(download) as download, MAX(upload) as upload'))
|
||||||
|
->where('failed', false)
|
||||||
|
->first()
|
||||||
|
->toArray();
|
||||||
|
$response['maximum'] = $max;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SettingsHelper::get('show_min')) {
|
||||||
|
$min = Speedtest::select(DB::raw('MIN(ping) as ping, MIN(download) as download, MIN(upload) as upload'))
|
||||||
|
->where('failed', false)
|
||||||
|
->first()
|
||||||
|
->toArray();
|
||||||
|
$response['minimum'] = $min;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
}
|
||||||
37
app/Actions/GetSpeedtestTimeData.php
Normal file
37
app/Actions/GetSpeedtestTimeData.php
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions;
|
||||||
|
|
||||||
|
use App\Helpers\SettingsHelper;
|
||||||
|
use App\Models\Speedtest;
|
||||||
|
use Cache;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Henrywhitaker3\LaravelActions\Interfaces\ActionInterface;
|
||||||
|
|
||||||
|
class GetSpeedtestTimeData implements ActionInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the action.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function run($days = 7)
|
||||||
|
{
|
||||||
|
$ttl = Carbon::now()->addDays(1);
|
||||||
|
|
||||||
|
return Cache::remember('speedtest-days-' . $days, $ttl, function () use ($days) {
|
||||||
|
$showFailed = (bool)SettingsHelper::get('show_failed_tests_on_graph')->value;
|
||||||
|
|
||||||
|
if ($showFailed === true) {
|
||||||
|
return Speedtest::where('created_at', '>=', Carbon::now()->subDays($days))
|
||||||
|
->orderBy('created_at', 'asc')
|
||||||
|
->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Speedtest::where('created_at', '>=', Carbon::now()->subDays($days))
|
||||||
|
->where('failed', false)
|
||||||
|
->orderBy('created_at', 'asc')
|
||||||
|
->get();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
35
app/Actions/QueueSpeedtest.php
Normal file
35
app/Actions/QueueSpeedtest.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions;
|
||||||
|
|
||||||
|
use App\Helpers\SettingsHelper;
|
||||||
|
use App\Interfaces\SpeedtestProvider;
|
||||||
|
use App\Jobs\SpeedtestJob;
|
||||||
|
use Henrywhitaker3\LaravelActions\Interfaces\ActionInterface;
|
||||||
|
|
||||||
|
class QueueSpeedtest implements ActionInterface
|
||||||
|
{
|
||||||
|
private SpeedtestProvider $speedtestProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new action instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(SpeedtestProvider $speedtestProvider)
|
||||||
|
{
|
||||||
|
$this->speedtestProvider = $speedtestProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the action.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
SettingsHelper::loadIntegrationConfig();
|
||||||
|
|
||||||
|
SpeedtestJob::dispatch(false, config('integrations'), $this->speedtestProvider);
|
||||||
|
}
|
||||||
|
}
|
||||||
52
app/Casts/CommaSeparatedArrayCast.php
Normal file
52
app/Casts/CommaSeparatedArrayCast.php
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Casts;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||||
|
|
||||||
|
class CommaSeparatedArrayCast implements CastsAttributes
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Array of settings that should be cast
|
||||||
|
*/
|
||||||
|
private array $shouldCast = [
|
||||||
|
'visible_columns',
|
||||||
|
'hidden_columns',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cast the given value.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Database\Eloquent\Model $model
|
||||||
|
* @param string $key
|
||||||
|
* @param mixed $value
|
||||||
|
* @param array $attributes
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function get($model, $key, $value, $attributes)
|
||||||
|
{
|
||||||
|
if (!in_array($model->name, $this->shouldCast)) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return explode(',', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare the given value for storage.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Database\Eloquent\Model $model
|
||||||
|
* @param string $key
|
||||||
|
* @param mixed $value
|
||||||
|
* @param array $attributes
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function set($model, $key, $value, $attributes)
|
||||||
|
{
|
||||||
|
if (!in_array($model->name, $this->shouldCast)) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode(',', $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -38,6 +38,7 @@ class AcceptEULACommand extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
shell_exec(config('speedtest.home') . ' && ' . app_path() . '/Bin/speedtest --accept-license --accept-gdpr');
|
$this->info('Acceping EULA');
|
||||||
|
shell_exec(config('speedtest.home') . ' && timeout 10s ' . app_path() . '/Bin/speedtest --accept-license --accept-gdpr');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use App\Auth\LoginSession;
|
use App\Models\Auth\LoginSession;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Log;
|
use Log;
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Exceptions\SpeedtestFailureException;
|
||||||
use App\Helpers\SpeedtestHelper;
|
use App\Helpers\SpeedtestHelper;
|
||||||
|
use App\Interfaces\SpeedtestProvider;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
class SpeedtestCommand extends Command
|
class SpeedtestCommand extends Command
|
||||||
@@ -21,13 +23,17 @@ class SpeedtestCommand extends Command
|
|||||||
*/
|
*/
|
||||||
protected $description = 'Performs a new speedtest';
|
protected $description = 'Performs a new speedtest';
|
||||||
|
|
||||||
|
private SpeedtestProvider $speedtestProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new command instance.
|
* Create a new command instance.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct(SpeedtestProvider $speedtestProvider)
|
||||||
{
|
{
|
||||||
|
$this->speedtestProvider = $speedtestProvider;
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,14 +46,14 @@ class SpeedtestCommand extends Command
|
|||||||
{
|
{
|
||||||
$this->info('Running speedtest, this might take a while...');
|
$this->info('Running speedtest, this might take a while...');
|
||||||
|
|
||||||
$results = SpeedtestHelper::runSpeedtest(false, false);
|
try {
|
||||||
|
$results = $this->speedtestProvider->run(false, false);
|
||||||
if(!is_object($results)) {
|
} catch (SpeedtestFailureException $e) {
|
||||||
$this->error('Something went wrong running the speedtest.');
|
$this->error('Something went wrong running the speedtest.');
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(property_exists($results, 'ping') && property_exists($results, 'download') && property_exists($results, 'upload')) {
|
if (property_exists($results, 'ping') && property_exists($results, 'download') && property_exists($results, 'upload')) {
|
||||||
$this->error('Something went wrong running the speedtest.');
|
$this->error('Something went wrong running the speedtest.');
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use App\Helpers\SpeedtestHelper;
|
use App\Helpers\SpeedtestHelper;
|
||||||
|
use App\Interfaces\SpeedtestProvider;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\Artisan;
|
use Illuminate\Support\Facades\Artisan;
|
||||||
|
|
||||||
@@ -22,13 +23,17 @@ class SpeedtestLatestCommand extends Command
|
|||||||
*/
|
*/
|
||||||
protected $description = 'Returns the latest speedtest result';
|
protected $description = 'Returns the latest speedtest result';
|
||||||
|
|
||||||
|
private SpeedtestProvider $speedtestProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new command instance.
|
* Create a new command instance.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct(SpeedtestProvider $speedtestProvider)
|
||||||
{
|
{
|
||||||
|
$this->speedtestProvider = $speedtestProvider;
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,8 +46,8 @@ class SpeedtestLatestCommand extends Command
|
|||||||
{
|
{
|
||||||
$latest = SpeedtestHelper::latest();
|
$latest = SpeedtestHelper::latest();
|
||||||
|
|
||||||
if($latest) {
|
if ($latest) {
|
||||||
if($latest->scheduled) {
|
if ($latest->scheduled) {
|
||||||
$extra = '(scheduled)';
|
$extra = '(scheduled)';
|
||||||
} else {
|
} else {
|
||||||
$extra = '(manual)';
|
$extra = '(manual)';
|
||||||
@@ -50,7 +55,7 @@ class SpeedtestLatestCommand extends Command
|
|||||||
|
|
||||||
$this->info('Last speedtest run at: ' . $latest->created_at . ' ' . $extra);
|
$this->info('Last speedtest run at: ' . $latest->created_at . ' ' . $extra);
|
||||||
|
|
||||||
if($latest->failed) {
|
if ($latest->failed) {
|
||||||
$this->error('Speedtest failed');
|
$this->error('Speedtest failed');
|
||||||
} else {
|
} else {
|
||||||
$this->info('Ping: ' . $latest->ping . ' ms');
|
$this->info('Ping: ' . $latest->ping . ' ms');
|
||||||
@@ -62,7 +67,7 @@ class SpeedtestLatestCommand extends Command
|
|||||||
|
|
||||||
$this->info('Running speedtest, this might take a while...');
|
$this->info('Running speedtest, this might take a while...');
|
||||||
|
|
||||||
$results = SpeedtestHelper::runSpeedtest();
|
$results = $this->speedtestProvider->run();
|
||||||
|
|
||||||
$this->info('Ping: ' . $results->ping . ' ms');
|
$this->info('Ping: ' . $results->ping . ' ms');
|
||||||
$this->info('Download: ' . $results->download . ' Mbit/s');
|
$this->info('Download: ' . $results->download . ' Mbit/s');
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace App\Console;
|
|||||||
use App\Events\SpeedtestOverviewEvent;
|
use App\Events\SpeedtestOverviewEvent;
|
||||||
use App\Helpers\SettingsHelper;
|
use App\Helpers\SettingsHelper;
|
||||||
use App\Helpers\SpeedtestHelper;
|
use App\Helpers\SpeedtestHelper;
|
||||||
|
use App\Interfaces\SpeedtestProvider;
|
||||||
use App\Jobs\SpeedtestJob;
|
use App\Jobs\SpeedtestJob;
|
||||||
use Illuminate\Console\Scheduling\Schedule;
|
use Illuminate\Console\Scheduling\Schedule;
|
||||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||||
@@ -28,8 +29,18 @@ class Kernel extends ConsoleKernel
|
|||||||
*/
|
*/
|
||||||
protected function schedule(Schedule $schedule)
|
protected function schedule(Schedule $schedule)
|
||||||
{
|
{
|
||||||
$schedule->job(new SpeedtestJob(true, config('integrations')))->cron(SettingsHelper::get('schedule')['value']);
|
if ((bool)SettingsHelper::get('schedule_enabled')->value) {
|
||||||
$schedule->command('speedtest:overview')->cron('0 ' . SettingsHelper::get('speedtest_overview_time')->value . ' * * *');
|
$schedule->job(
|
||||||
|
new SpeedtestJob(
|
||||||
|
true,
|
||||||
|
config('integrations'),
|
||||||
|
app()->make(SpeedtestProvider::class)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
->cron(SettingsHelper::get('schedule')['value'])
|
||||||
|
->timezone(env('TZ', 'UTC'));
|
||||||
|
}
|
||||||
|
$schedule->command('speedtest:overview')->cron('0 ' . SettingsHelper::get('speedtest_overview_time')->value . ' * * *')->timezone(env('TZ', 'UTC'));
|
||||||
$schedule->command('speedtest:clear-sessions')->everyMinute();
|
$schedule->command('speedtest:clear-sessions')->everyMinute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +51,7 @@ class Kernel extends ConsoleKernel
|
|||||||
*/
|
*/
|
||||||
protected function commands()
|
protected function commands()
|
||||||
{
|
{
|
||||||
$this->load(__DIR__.'/Commands');
|
$this->load(__DIR__ . '/Commands');
|
||||||
|
|
||||||
require base_path('routes/console.php');
|
require base_path('routes/console.php');
|
||||||
}
|
}
|
||||||
|
|||||||
10
app/Exceptions/InfluxDBConnectionErrorException.php
Normal file
10
app/Exceptions/InfluxDBConnectionErrorException.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class InfluxDBConnectionErrorException extends Exception
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
10
app/Exceptions/InfluxDBNotEnabledException.php
Normal file
10
app/Exceptions/InfluxDBNotEnabledException.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class InfluxDBNotEnabledException extends Exception
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
10
app/Exceptions/SpeedtestFailureException.php
Normal file
10
app/Exceptions/SpeedtestFailureException.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class SpeedtestFailureException extends Exception
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Helpers;
|
namespace App\Helpers;
|
||||||
|
|
||||||
use App\Speedtest;
|
use App\Models\Speedtest;
|
||||||
use Cache;
|
use Cache;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Helpers;
|
namespace App\Helpers;
|
||||||
|
|
||||||
use App\Auth\EmailVerification;
|
use App\Models\Auth\EmailVerification;
|
||||||
use App\User;
|
use App\Models\User;
|
||||||
|
|
||||||
class EmailVerificationHelper {
|
class EmailVerificationHelper {
|
||||||
public static function checkVerificationAttempt($userID, $token)
|
public static function checkVerificationAttempt($userID, $token)
|
||||||
|
|||||||
@@ -3,12 +3,13 @@
|
|||||||
namespace App\Helpers;
|
namespace App\Helpers;
|
||||||
|
|
||||||
use App\Events\TestNotificationEvent;
|
use App\Events\TestNotificationEvent;
|
||||||
use App\Setting;
|
use App\Models\Setting;
|
||||||
use Cache;
|
use Cache;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
|
||||||
class SettingsHelper
|
class SettingsHelper
|
||||||
{
|
{
|
||||||
|
private static $settings = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a Setting object by name
|
* Get a Setting object by name
|
||||||
@@ -23,7 +24,7 @@ class SettingsHelper
|
|||||||
if (sizeof($name) == 0) {
|
if (sizeof($name) == 0) {
|
||||||
return false;
|
return false;
|
||||||
} else if (sizeof($name) == 1) {
|
} else if (sizeof($name) == 1) {
|
||||||
return $name[0];
|
return $name->first();
|
||||||
} else {
|
} else {
|
||||||
$name = $name->keyBy('name');
|
$name = $name->keyBy('name');
|
||||||
return $name->all();
|
return $name->all();
|
||||||
@@ -91,6 +92,11 @@ class SettingsHelper
|
|||||||
*/
|
*/
|
||||||
public static function settingIsEditable(string $key)
|
public static function settingIsEditable(string $key)
|
||||||
{
|
{
|
||||||
|
// Manual override for app_name
|
||||||
|
if ($key === 'app_name') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
$results = [];
|
$results = [];
|
||||||
|
|
||||||
// Try exact key
|
// Try exact key
|
||||||
@@ -139,6 +145,7 @@ class SettingsHelper
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'base' => SettingsHelper::getBase(),
|
'base' => SettingsHelper::getBase(),
|
||||||
|
'name' => SettingsHelper::get('app_name')->value,
|
||||||
'widgets' => [
|
'widgets' => [
|
||||||
'show_average' => (bool)SettingsHelper::get('show_average')->value,
|
'show_average' => (bool)SettingsHelper::get('show_average')->value,
|
||||||
'show_max' => (bool)SettingsHelper::get('show_max')->value,
|
'show_max' => (bool)SettingsHelper::get('show_max')->value,
|
||||||
@@ -157,6 +164,10 @@ class SettingsHelper
|
|||||||
'telegram_bot_token' => SettingsHelper::settingIsEditable('telegram_bot_token'),
|
'telegram_bot_token' => SettingsHelper::settingIsEditable('telegram_bot_token'),
|
||||||
'telegram_chat_id' => SettingsHelper::settingIsEditable('telegram_chat_id'),
|
'telegram_chat_id' => SettingsHelper::settingIsEditable('telegram_chat_id'),
|
||||||
],
|
],
|
||||||
|
'tables' => [
|
||||||
|
'visible_columns' => SettingsHelper::get('visible_columns')->value,
|
||||||
|
'hidden_columns' => SettingsHelper::get('hidden_columns')->value,
|
||||||
|
],
|
||||||
'auth' => (bool)SettingsHelper::get('auth')->value
|
'auth' => (bool)SettingsHelper::get('auth')->value
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Helpers;
|
namespace App\Helpers;
|
||||||
|
|
||||||
use App\Speedtest;
|
use App\Interfaces\SpeedtestProvider;
|
||||||
|
use App\Models\Speedtest;
|
||||||
|
use App\Utils\OoklaTester;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Henrywhitaker3\Healthchecks\Healthchecks;
|
use Henrywhitaker3\Healthchecks\Healthchecks;
|
||||||
@@ -13,7 +15,8 @@ use Illuminate\Support\Facades\Log;
|
|||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use JsonException;
|
use JsonException;
|
||||||
|
|
||||||
class SpeedtestHelper {
|
class SpeedtestHelper
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs/processes speedtest output to created a Speedtest object
|
* Runs/processes speedtest output to created a Speedtest object
|
||||||
@@ -21,79 +24,10 @@ class SpeedtestHelper {
|
|||||||
* @param boolean|string $output If false, new speedtest runs. If anything else, will try to parse as JSON for speedtest results.
|
* @param boolean|string $output If false, new speedtest runs. If anything else, will try to parse as JSON for speedtest results.
|
||||||
* @return \App\Speedtest|bool
|
* @return \App\Speedtest|bool
|
||||||
*/
|
*/
|
||||||
public static function runSpeedtest($output = false, $scheduled = true)
|
public static function runSpeedtest()
|
||||||
{
|
{
|
||||||
if($output === false) {
|
$tester = app()->make(SpeedtestProvider::class);
|
||||||
$output = SpeedtestHelper::output();
|
return $tester->run();
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$output = json_decode($output, true, 512, JSON_THROW_ON_ERROR);
|
|
||||||
|
|
||||||
if(!SpeedtestHelper::checkOutputIsComplete($output)) {
|
|
||||||
$test = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$test = Speedtest::create([
|
|
||||||
'ping' => $output['ping']['latency'],
|
|
||||||
'download' => SpeedtestHelper::convert($output['download']['bandwidth']),
|
|
||||||
'upload' => SpeedtestHelper::convert($output['upload']['bandwidth']),
|
|
||||||
'server_id' => $output['server']['id'],
|
|
||||||
'server_name' => $output['server']['name'],
|
|
||||||
'server_host' => $output['server']['host'] . ':' . $output['server']['port'],
|
|
||||||
'url' => $output['result']['url'],
|
|
||||||
'scheduled' => $scheduled
|
|
||||||
]);
|
|
||||||
} catch(JsonException $e) {
|
|
||||||
Log::error('Failed to parse speedtest JSON');
|
|
||||||
Log::error($output);
|
|
||||||
$test = false;
|
|
||||||
} catch(Exception $e) {
|
|
||||||
Log::error($e->getMessage());
|
|
||||||
$test = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($test == false) {
|
|
||||||
Speedtest::create([
|
|
||||||
'ping' => 0,
|
|
||||||
'upload' => 0,
|
|
||||||
'download' => 0,
|
|
||||||
'failed' => true,
|
|
||||||
'scheduled' => $scheduled,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Cache::flush();
|
|
||||||
|
|
||||||
return $test;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the output of executing speedtest binary.
|
|
||||||
*
|
|
||||||
* @return boolean|string
|
|
||||||
*/
|
|
||||||
public static function output()
|
|
||||||
{
|
|
||||||
$server = SettingsHelper::get('server')['value'];
|
|
||||||
|
|
||||||
$binPath = app_path() . DIRECTORY_SEPARATOR . 'Bin' . DIRECTORY_SEPARATOR . 'speedtest';
|
|
||||||
$homePrefix = config('speedtest.home') . ' && ';
|
|
||||||
|
|
||||||
if($server != '' && $server != false) {
|
|
||||||
$server = explode(',', $server);
|
|
||||||
$server = $server[array_rand($server)];
|
|
||||||
if($server == false) {
|
|
||||||
Log::error('Speedtest server undefined');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return shell_exec($homePrefix . $binPath . ' -f json -s ' . $server);
|
|
||||||
}
|
|
||||||
|
|
||||||
return shell_exec($homePrefix . $binPath . ' -f json');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,10 +39,10 @@ class SpeedtestHelper {
|
|||||||
{
|
{
|
||||||
$t = Carbon::now()->subDay();
|
$t = Carbon::now()->subDay();
|
||||||
$s = Speedtest::select(DB::raw('AVG(ping) as ping, AVG(download) as download, AVG(upload) as upload'))
|
$s = Speedtest::select(DB::raw('AVG(ping) as ping, AVG(download) as download, AVG(upload) as upload'))
|
||||||
->where('created_at', '>=', $t)
|
->where('created_at', '>=', $t)
|
||||||
->where('failed', false)
|
->where('failed', false)
|
||||||
->first()
|
->first()
|
||||||
->toArray();
|
->toArray();
|
||||||
|
|
||||||
return $s;
|
return $s;
|
||||||
}
|
}
|
||||||
@@ -119,8 +53,9 @@ class SpeedtestHelper {
|
|||||||
* @param int|float $bytes
|
* @param int|float $bytes
|
||||||
* @return int|float
|
* @return int|float
|
||||||
*/
|
*/
|
||||||
public static function convert($bytes) {
|
public static function convert($bytes)
|
||||||
return ( $bytes * 8 ) / 1000000;
|
{
|
||||||
|
return ($bytes * 8) / 1000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -132,7 +67,7 @@ class SpeedtestHelper {
|
|||||||
{
|
{
|
||||||
$data = Speedtest::latest()->get();
|
$data = Speedtest::latest()->get();
|
||||||
|
|
||||||
if($data->isEmpty()) {
|
if ($data->isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +87,7 @@ class SpeedtestHelper {
|
|||||||
$val = (float)$input[0];
|
$val = (float)$input[0];
|
||||||
$unit = explode('/', $input[1])[0];
|
$unit = explode('/', $input[1])[0];
|
||||||
|
|
||||||
switch($unit) {
|
switch ($unit) {
|
||||||
case 'Mbyte':
|
case 'Mbyte':
|
||||||
$val = $val * 8;
|
$val = $val * 8;
|
||||||
break;
|
break;
|
||||||
@@ -173,86 +108,6 @@ class SpeedtestHelper {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks that the speedtest JSON output is complete/valid
|
|
||||||
*
|
|
||||||
* @param array $output
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public static function checkOutputIsComplete($output)
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Array of indexes that must exist in $output
|
|
||||||
*/
|
|
||||||
$checks = [
|
|
||||||
'type' => 'result',
|
|
||||||
'download' => [ 'bandwidth' => '*' ],
|
|
||||||
'upload' => [ 'bandwidth' => '*' ],
|
|
||||||
'ping' => [ 'latency' => '*' ],
|
|
||||||
'server' => [
|
|
||||||
'id' => '*',
|
|
||||||
'name' => '*',
|
|
||||||
'host' => '*',
|
|
||||||
'port' => '*'
|
|
||||||
],
|
|
||||||
'result' => [
|
|
||||||
'url' => '*'
|
|
||||||
],
|
|
||||||
];
|
|
||||||
/**
|
|
||||||
* Array of indexes that must not exist
|
|
||||||
*/
|
|
||||||
$checkMissing = [
|
|
||||||
'type' => 'error'
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach($checks as $key => $value) {
|
|
||||||
if(!isset($output[$key])) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a percentage rate of failure by days
|
|
||||||
*
|
|
||||||
* @param integer $days number of days to get rate for
|
|
||||||
* @return integer percentage fail rate
|
|
||||||
*/
|
|
||||||
public static function failureRate(int $days)
|
|
||||||
{
|
|
||||||
$ttl = Carbon::now()->addDays(1);
|
|
||||||
$rate = Cache::remember('failure-rate-' . $days, $ttl, function () use ($days) {
|
|
||||||
$range = [
|
|
||||||
Carbon::today()
|
|
||||||
];
|
|
||||||
for($i = 0; $i < ($days - 1); $i++) {
|
|
||||||
$prev = end($range);
|
|
||||||
$new = $prev->copy()->subDays(1);
|
|
||||||
array_push($range, $new);
|
|
||||||
}
|
|
||||||
|
|
||||||
$rate = [];
|
|
||||||
|
|
||||||
foreach($range as $day) {
|
|
||||||
$success = Speedtest::select(DB::raw('COUNT(id) as rate'))->whereDate('created_at', $day)->where('failed', false)->get()[0]['rate'];
|
|
||||||
$fail = Speedtest::select(DB::raw('COUNT(id) as rate'))->whereDate('created_at', $day)->where('failed', true)->get()[0]['rate'];
|
|
||||||
|
|
||||||
array_push($rate, [
|
|
||||||
'date' => $day->toDateString(),
|
|
||||||
'success' => $success,
|
|
||||||
'failure' => $fail,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return array_reverse($rate);
|
|
||||||
});
|
|
||||||
|
|
||||||
return $rate;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a backup of the SQLite database
|
* Create a backup of the SQLite database
|
||||||
*
|
*
|
||||||
@@ -260,14 +115,14 @@ class SpeedtestHelper {
|
|||||||
*/
|
*/
|
||||||
public static function dbBackup()
|
public static function dbBackup()
|
||||||
{
|
{
|
||||||
if(env('DB_CONNECTION') === 'sqlite') {
|
if (env('DB_CONNECTION') === 'sqlite') {
|
||||||
if(env('DB_DATABASE') !== null) {
|
if (env('DB_DATABASE') !== null) {
|
||||||
$current = env('DB_DATABASE');
|
$current = env('DB_DATABASE');
|
||||||
try {
|
try {
|
||||||
if(File::copy($current, $current . '.bak')) {
|
if (File::copy($current, $current . '.bak')) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}catch(Exception $e) {
|
} catch (Exception $e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -289,8 +144,8 @@ class SpeedtestHelper {
|
|||||||
|
|
||||||
SpeedtestHelper::dbBackup();
|
SpeedtestHelper::dbBackup();
|
||||||
|
|
||||||
if(sizeof(Speedtest::whereNotNull('id')->get()) > 0) {
|
if (sizeof(Speedtest::whereNotNull('id')->get()) > 0) {
|
||||||
if(Speedtest::whereNotNull('id')->delete()) {
|
if (Speedtest::whereNotNull('id')->delete()) {
|
||||||
return [
|
return [
|
||||||
'success' => true,
|
'success' => true,
|
||||||
];
|
];
|
||||||
@@ -311,31 +166,31 @@ class SpeedtestHelper {
|
|||||||
*/
|
*/
|
||||||
public static function testIsLowerThanThreshold(String $type, Speedtest $test)
|
public static function testIsLowerThanThreshold(String $type, Speedtest $test)
|
||||||
{
|
{
|
||||||
if($type == 'percentage') {
|
if ($type == 'percentage') {
|
||||||
$avg = Speedtest::select(DB::raw('AVG(ping) as ping, AVG(download) as download, AVG(upload) as upload'))
|
$avg = Speedtest::select(DB::raw('AVG(ping) as ping, AVG(download) as download, AVG(upload) as upload'))
|
||||||
->where('failed', false)
|
->where('failed', false)
|
||||||
->get()
|
->get()
|
||||||
->toArray()[0];
|
->toArray()[0];
|
||||||
|
|
||||||
$threshold = SettingsHelper::get('threshold_alert_percentage')->value;
|
$threshold = SettingsHelper::get('threshold_alert_percentage')->value;
|
||||||
|
|
||||||
if($threshold == '') {
|
if ($threshold == '') {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$errors = [];
|
$errors = [];
|
||||||
|
|
||||||
foreach($avg as $key => $value) {
|
foreach ($avg as $key => $value) {
|
||||||
if($key == 'ping') {
|
if ($key == 'ping') {
|
||||||
$threshold = (float)$value * (1 + ( $threshold / 100 ));
|
$threshold = (float)$value * (1 + ($threshold / 100));
|
||||||
|
|
||||||
if($test->$key > $threshold) {
|
if ($test->$key > $threshold) {
|
||||||
array_push($errors, $key);
|
array_push($errors, $key);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$threshold = (float)$value * (1 - ( $threshold / 100 ));
|
$threshold = (float)$value * (1 - ($threshold / 100));
|
||||||
|
|
||||||
if($test->$key < $threshold) {
|
if ($test->$key < $threshold) {
|
||||||
array_push($errors, $key);
|
array_push($errors, $key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -344,7 +199,7 @@ class SpeedtestHelper {
|
|||||||
return $errors;
|
return $errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($type == 'absolute') {
|
if ($type == 'absolute') {
|
||||||
$thresholds = [
|
$thresholds = [
|
||||||
'download' => SettingsHelper::get('threshold_alert_absolute_download')->value,
|
'download' => SettingsHelper::get('threshold_alert_absolute_download')->value,
|
||||||
'upload' => SettingsHelper::get('threshold_alert_absolute_upload')->value,
|
'upload' => SettingsHelper::get('threshold_alert_absolute_upload')->value,
|
||||||
@@ -353,17 +208,17 @@ class SpeedtestHelper {
|
|||||||
|
|
||||||
$errors = [];
|
$errors = [];
|
||||||
|
|
||||||
foreach($thresholds as $key => $value) {
|
foreach ($thresholds as $key => $value) {
|
||||||
if($value == '') {
|
if ($value == '') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($key == 'ping') {
|
if ($key == 'ping') {
|
||||||
if($test->$key > $value) {
|
if ($test->$key > $value) {
|
||||||
array_push($errors, $key);
|
array_push($errors, $key);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if($test->$key < $value) {
|
if ($test->$key < $value) {
|
||||||
array_push($errors, $key);
|
array_push($errors, $key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -374,4 +229,42 @@ class SpeedtestHelper {
|
|||||||
|
|
||||||
throw new InvalidArgumentException();
|
throw new InvalidArgumentException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a percentage rate of failure by days
|
||||||
|
*
|
||||||
|
* @param integer $days number of days to get rate for
|
||||||
|
* @return integer percentage fail rate
|
||||||
|
*/
|
||||||
|
public static function failureRate(int $days)
|
||||||
|
{
|
||||||
|
$ttl = Carbon::now()->addDays(1);
|
||||||
|
$rate = Cache::remember('failure-rate-' . $days, $ttl, function () use ($days) {
|
||||||
|
$range = [
|
||||||
|
Carbon::today()
|
||||||
|
];
|
||||||
|
for ($i = 0; $i < ($days - 1); $i++) {
|
||||||
|
$prev = end($range);
|
||||||
|
$new = $prev->copy()->subDays(1);
|
||||||
|
array_push($range, $new);
|
||||||
|
}
|
||||||
|
|
||||||
|
$rate = [];
|
||||||
|
|
||||||
|
foreach ($range as $day) {
|
||||||
|
$success = Speedtest::select(DB::raw('COUNT(id) as rate'))->whereDate('created_at', $day)->where('failed', false)->get()[0]['rate'];
|
||||||
|
$fail = Speedtest::select(DB::raw('COUNT(id) as rate'))->whereDate('created_at', $day)->where('failed', true)->get()[0]['rate'];
|
||||||
|
|
||||||
|
array_push($rate, [
|
||||||
|
'date' => $day->toDateString(),
|
||||||
|
'success' => $success,
|
||||||
|
'failure' => $fail,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_reverse($rate);
|
||||||
|
});
|
||||||
|
|
||||||
|
return $rate;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,14 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Auth\EmailVerification;
|
use App\Models\Auth\EmailVerification;
|
||||||
use App\Auth\LoginSession as AuthLoginSession;
|
use App\Models\Auth\LoginSession as AuthLoginSession;
|
||||||
use App\Helpers\EmailVerificationHelper;
|
use App\Helpers\EmailVerificationHelper;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\LoginSession;
|
use App\LoginSession;
|
||||||
use App\Rules\CurrentPasswordMatches;
|
use App\Rules\CurrentPasswordMatches;
|
||||||
use App\User;
|
use App\Models\User;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Hash;
|
use Hash;
|
||||||
use Illuminate\Support\Facades\Request as RequestFacade;
|
use Illuminate\Support\Facades\Request as RequestFacade;
|
||||||
|
|||||||
35
app/Http/Controllers/HomepageDataController.php
Normal file
35
app/Http/Controllers/HomepageDataController.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Actions\GetFailedSpeedtestData;
|
||||||
|
use App\Actions\GetLatestSpeedtestData;
|
||||||
|
use App\Actions\GetSpeedtestTimeData;
|
||||||
|
use App\Helpers\SettingsHelper;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Validator;
|
||||||
|
|
||||||
|
class HomepageDataController extends Controller
|
||||||
|
{
|
||||||
|
public function __invoke($days)
|
||||||
|
{
|
||||||
|
$validator = Validator::make(
|
||||||
|
['days' => $days],
|
||||||
|
['days' => ['required', 'numeric']],
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($validator->fails()) {
|
||||||
|
return response()->json([
|
||||||
|
'method' => 'get speedtests in last x days',
|
||||||
|
'error' => $validator->errors(),
|
||||||
|
], 422);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'latest' => run(GetLatestSpeedtestData::class),
|
||||||
|
'time' => run(GetSpeedtestTimeData::class),
|
||||||
|
'fail' => run(GetFailedSpeedtestData::class),
|
||||||
|
'config' => SettingsHelper::getConfig(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ namespace App\Http\Controllers;
|
|||||||
|
|
||||||
use App\Helpers\SettingsHelper;
|
use App\Helpers\SettingsHelper;
|
||||||
use App\Rules\Cron;
|
use App\Rules\Cron;
|
||||||
use App\Setting;
|
use App\Models\Setting;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
@@ -15,9 +15,9 @@ class SettingsController extends Controller
|
|||||||
{
|
{
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
if((bool)SettingsHelper::get('auth')->value === true) {
|
if ((bool)SettingsHelper::get('auth')->value === true) {
|
||||||
$this->middleware('auth:api')
|
$this->middleware('auth:api')
|
||||||
->except([ 'config' ]);
|
->except(['config']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,21 +51,21 @@ class SettingsController extends Controller
|
|||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$rule = [
|
$rule = [
|
||||||
'name' => [ 'required', 'string', 'min:1' ],
|
'name' => ['required', 'string', 'min:1'],
|
||||||
];
|
];
|
||||||
if($request->name == 'schedule') {
|
if ($request->name == 'schedule') {
|
||||||
$rule['value'] = [ 'required', new Cron ];
|
$rule['value'] = ['required', new Cron];
|
||||||
}
|
}
|
||||||
|
|
||||||
$validator = Validator::make($request->all(), $rule);
|
$validator = Validator::make($request->all(), $rule);
|
||||||
if($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'method' => 'Store a setting',
|
'method' => 'Store a setting',
|
||||||
'error' => $validator->errors()
|
'error' => $validator->errors()
|
||||||
], 422);
|
], 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isset($request->value)) {
|
if (!isset($request->value)) {
|
||||||
$request->value = '';
|
$request->value = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,12 +86,12 @@ class SettingsController extends Controller
|
|||||||
public function bulkStore(Request $request)
|
public function bulkStore(Request $request)
|
||||||
{
|
{
|
||||||
$rule = [
|
$rule = [
|
||||||
'data' => [ 'array', 'required' ],
|
'data' => ['array', 'required'],
|
||||||
'data.*.name' => [ 'string', 'required' ],
|
'data.*.name' => ['string', 'required'],
|
||||||
];
|
];
|
||||||
|
|
||||||
$validator = Validator::make($request->all(), $rule);
|
$validator = Validator::make($request->all(), $rule);
|
||||||
if($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'method' => 'Bulk store a setting',
|
'method' => 'Bulk store a setting',
|
||||||
'error' => $validator->errors()
|
'error' => $validator->errors()
|
||||||
@@ -99,14 +99,14 @@ class SettingsController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$settings = [];
|
$settings = [];
|
||||||
foreach($request->data as $d) {
|
foreach ($request->data as $d) {
|
||||||
if(!isset($d['value']) || $d['value'] == null) {
|
if (!isset($d['value']) || $d['value'] == null) {
|
||||||
$d['value'] = '';
|
$d['value'] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if($d['name'] == 'speedtest_overview_time') {
|
if ($d['name'] == 'speedtest_overview_time') {
|
||||||
$ok = [ '00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23' ];
|
$ok = ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23'];
|
||||||
if(!in_array($d['value'], $ok)) {
|
if (!in_array($d['value'], $ok)) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'method' => 'Bulk store a setting',
|
'method' => 'Bulk store a setting',
|
||||||
'error' => 'Invalid speedtest_overview_time value'
|
'error' => 'Invalid speedtest_overview_time value'
|
||||||
@@ -116,9 +116,9 @@ class SettingsController extends Controller
|
|||||||
|
|
||||||
$setting = SettingsHelper::get($d['name']);
|
$setting = SettingsHelper::get($d['name']);
|
||||||
|
|
||||||
if($setting == false) {
|
if ($setting == false) {
|
||||||
$setting = SettingsHelper::set($d['name'], $d['value']);
|
$setting = SettingsHelper::set($d['name'], $d['value']);
|
||||||
} else if(SettingsHelper::settingIsEditable($setting->name)) {
|
} else if (SettingsHelper::settingIsEditable($setting->name)) {
|
||||||
$setting = SettingsHelper::set($d['name'], $d['value']);
|
$setting = SettingsHelper::set($d['name'], $d['value']);
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -2,10 +2,14 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Actions\GetFailedSpeedtestData;
|
||||||
|
use App\Actions\GetLatestSpeedtestData;
|
||||||
|
use App\Actions\GetSpeedtestTimeData;
|
||||||
|
use App\Actions\QueueSpeedtest;
|
||||||
use App\Helpers\SettingsHelper;
|
use App\Helpers\SettingsHelper;
|
||||||
use App\Helpers\SpeedtestHelper;
|
use App\Helpers\SpeedtestHelper;
|
||||||
use App\Jobs\SpeedtestJob;
|
use App\Jobs\SpeedtestJob;
|
||||||
use App\Speedtest;
|
use App\Models\Speedtest;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@@ -61,21 +65,7 @@ class SpeedtestController extends Controller
|
|||||||
], 422);
|
], 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
$ttl = Carbon::now()->addDays(1);
|
$data = run(GetSpeedtestTimeData::class, $days);
|
||||||
$data = Cache::remember('speedtest-days-' . $days, $ttl, function () use ($days) {
|
|
||||||
$showFailed = (bool)SettingsHelper::get('show_failed_tests_on_graph')->value;
|
|
||||||
|
|
||||||
if ($showFailed === true) {
|
|
||||||
return Speedtest::where('created_at', '>=', Carbon::now()->subDays($days))
|
|
||||||
->orderBy('created_at', 'asc')
|
|
||||||
->get();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Speedtest::where('created_at', '>=', Carbon::now()->subDays($days))
|
|
||||||
->where('failed', false)
|
|
||||||
->orderBy('created_at', 'asc')
|
|
||||||
->get();
|
|
||||||
});
|
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'method' => 'get speedtests in last x days',
|
'method' => 'get speedtests in last x days',
|
||||||
@@ -105,7 +95,7 @@ class SpeedtestController extends Controller
|
|||||||
], 422);
|
], 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = SpeedtestHelper::failureRate($days);
|
$data = run(GetFailedSpeedtestData::class, $days);
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'method' => 'get speedtests in last x days',
|
'method' => 'get speedtests in last x days',
|
||||||
@@ -121,39 +111,10 @@ class SpeedtestController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function latest()
|
public function latest()
|
||||||
{
|
{
|
||||||
$data = SpeedtestHelper::latest();
|
$data = run(GetLatestSpeedtestData::class);
|
||||||
|
|
||||||
$response = [
|
if ($data['data']) {
|
||||||
'method' => 'get latest speedtest',
|
return response()->json($data, 200);
|
||||||
'data' => $data,
|
|
||||||
];
|
|
||||||
|
|
||||||
if (SettingsHelper::get('show_average')) {
|
|
||||||
$avg = Speedtest::select(DB::raw('AVG(ping) as ping, AVG(download) as download, AVG(upload) as upload'))
|
|
||||||
->where('failed', false)
|
|
||||||
->first()
|
|
||||||
->toArray();
|
|
||||||
$response['average'] = $avg;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SettingsHelper::get('show_max')) {
|
|
||||||
$max = Speedtest::select(DB::raw('MAX(ping) as ping, MAX(download) as download, MAX(upload) as upload'))
|
|
||||||
->where('failed', false)
|
|
||||||
->first()
|
|
||||||
->toArray();
|
|
||||||
$response['maximum'] = $max;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SettingsHelper::get('show_average')) {
|
|
||||||
$min = Speedtest::select(DB::raw('MIN(ping) as ping, MIN(download) as download, MIN(upload) as upload'))
|
|
||||||
->where('failed', false)
|
|
||||||
->first()
|
|
||||||
->toArray();
|
|
||||||
$response['minimum'] = $min;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($data) {
|
|
||||||
return response()->json($response, 200);
|
|
||||||
} else {
|
} else {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'method' => 'get latest speedtest',
|
'method' => 'get latest speedtest',
|
||||||
@@ -170,8 +131,8 @@ class SpeedtestController extends Controller
|
|||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
SettingsHelper::loadIntegrationConfig();
|
run(QueueSpeedtest::class);
|
||||||
$data = SpeedtestJob::dispatch(false, config('integrations'));
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'method' => 'run speedtest',
|
'method' => 'run speedtest',
|
||||||
'data' => 'a new speedtest has been added to the queue'
|
'data' => 'a new speedtest has been added to the queue'
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
use App\Auth\LoginSession;
|
use App\Models\Auth\LoginSession;
|
||||||
use Closure;
|
use Closure;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
|
|||||||
13
app/Interfaces/InfluxDBWrapperInterface.php
Normal file
13
app/Interfaces/InfluxDBWrapperInterface.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Interfaces;
|
||||||
|
|
||||||
|
use App\Models\Speedtest;
|
||||||
|
|
||||||
|
interface InfluxDBWrapperInterface
|
||||||
|
{
|
||||||
|
public function testConnection(): bool;
|
||||||
|
public function doesDatabaseExist(string $database): bool;
|
||||||
|
public function createDatabase(string $database): bool;
|
||||||
|
public function store(Speedtest $speedtest): bool;
|
||||||
|
}
|
||||||
11
app/Interfaces/SpeedtestProvider.php
Normal file
11
app/Interfaces/SpeedtestProvider.php
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Interfaces;
|
||||||
|
|
||||||
|
use App\Models\Speedtest;
|
||||||
|
|
||||||
|
interface SpeedtestProvider
|
||||||
|
{
|
||||||
|
public function run(): Speedtest;
|
||||||
|
public function output();
|
||||||
|
}
|
||||||
@@ -6,6 +6,8 @@ use App\Events\SpeedtestCompleteEvent;
|
|||||||
use App\Events\SpeedtestFailedEvent;
|
use App\Events\SpeedtestFailedEvent;
|
||||||
use App\Helpers\SettingsHelper;
|
use App\Helpers\SettingsHelper;
|
||||||
use App\Helpers\SpeedtestHelper;
|
use App\Helpers\SpeedtestHelper;
|
||||||
|
use App\Interfaces\SpeedtestProvider;
|
||||||
|
use App\Utils\OoklaTester;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Healthcheck;
|
use Healthcheck;
|
||||||
use Henrywhitaker3\Healthchecks\Healthchecks;
|
use Henrywhitaker3\Healthchecks\Healthchecks;
|
||||||
@@ -34,15 +36,18 @@ class SpeedtestJob implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
private $config;
|
private $config;
|
||||||
|
|
||||||
|
private SpeedtestProvider $speedtestProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct($scheduled = true, $config = [])
|
public function __construct($scheduled = true, $config = [], SpeedtestProvider $speedtestProvider)
|
||||||
{
|
{
|
||||||
$this->scheduled = $scheduled;
|
$this->scheduled = $scheduled;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
|
$this->speedtestProvider = $speedtestProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,19 +57,19 @@ class SpeedtestJob implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
if($this->config['healthchecks_enabled'] === true) {
|
if ($this->config['healthchecks_enabled'] === true) {
|
||||||
$this->healthcheck('start');
|
$this->healthcheck('start');
|
||||||
}
|
}
|
||||||
$output = SpeedtestHelper::output();
|
$output = $this->speedtestProvider->output();
|
||||||
$speedtest = SpeedtestHelper::runSpeedtest($output, $this->scheduled);
|
$speedtest = $this->speedtestProvider->run($output, $this->scheduled);
|
||||||
if($speedtest == false) {
|
if ($speedtest == false) {
|
||||||
if($this->config['healthchecks_enabled'] === true) {
|
if ($this->config['healthchecks_enabled'] === true) {
|
||||||
$this->healthcheck('fail');
|
$this->healthcheck('fail');
|
||||||
}
|
}
|
||||||
|
|
||||||
event(new SpeedtestFailedEvent());
|
event(new SpeedtestFailedEvent());
|
||||||
} else {
|
} else {
|
||||||
if($this->config['healthchecks_enabled'] === true) {
|
if ($this->config['healthchecks_enabled'] === true) {
|
||||||
$this->healthcheck('success');
|
$this->healthcheck('success');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,19 +87,19 @@ class SpeedtestJob implements ShouldQueue
|
|||||||
private function healthcheck(String $method)
|
private function healthcheck(String $method)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$hc = new Healthchecks(SettingsHelper::get('healthchecks_uuid')->value);
|
$hc = new Healthchecks(SettingsHelper::get('healthchecks_uuid')->value, SettingsHelper::get('healthchecks_server_url')->value);
|
||||||
if($method === 'start') {
|
if ($method === 'start') {
|
||||||
$hc->start();
|
$hc->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
if($method === 'success') {
|
if ($method === 'success') {
|
||||||
$hc->success();
|
$hc->success();
|
||||||
}
|
}
|
||||||
|
|
||||||
if($method === 'fail') {
|
if ($method === 'fail') {
|
||||||
$hc->fail();
|
$hc->fail();
|
||||||
}
|
}
|
||||||
} catch(Exception $e) {
|
} catch (Exception $e) {
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Auth;
|
namespace App\Models\Auth;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Auth;
|
namespace App\Models\Auth;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Casts\CommaSeparatedArrayCast;
|
||||||
use App\Helpers\SettingsHelper;
|
use App\Helpers\SettingsHelper;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
@@ -17,4 +18,8 @@ class Setting extends Model
|
|||||||
];
|
];
|
||||||
|
|
||||||
protected $table = 'settings';
|
protected $table = 'settings';
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'value' => CommaSeparatedArrayCast::class,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
45
app/Models/Speedtest.php
Normal file
45
app/Models/Speedtest.php
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Speedtest extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The attributes that are mass assignable.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $fillable = [
|
||||||
|
'ping',
|
||||||
|
'download',
|
||||||
|
'upload',
|
||||||
|
'created_at',
|
||||||
|
'server_id',
|
||||||
|
'server_name',
|
||||||
|
'server_host',
|
||||||
|
'url',
|
||||||
|
'scheduled',
|
||||||
|
'failed',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $table = 'speedtests';
|
||||||
|
|
||||||
|
public function formatForInfluxDB()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => (int) $this->id,
|
||||||
|
'download' => (float) $this->download,
|
||||||
|
'upload' => (float) $this->upload,
|
||||||
|
'ping' => (float) $this->ping,
|
||||||
|
'server_id' => (int) $this->server_id,
|
||||||
|
'server_host' => $this->server_host,
|
||||||
|
'server_name' => $this->server_name,
|
||||||
|
'scheduled' => (bool) $this->scheduled,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App;
|
namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
@@ -107,7 +107,7 @@ class User extends Authenticatable implements JWTSubject
|
|||||||
|
|
||||||
public function setPasswordAttribute($password)
|
public function setPasswordAttribute($password)
|
||||||
{
|
{
|
||||||
if ( !empty($password) ) {
|
if (!empty($password)) {
|
||||||
$this->attributes['password'] = Hash::make($password);
|
$this->attributes['password'] = Hash::make($password);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
30
app/Observers/SpeedtestObserver.php
Normal file
30
app/Observers/SpeedtestObserver.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Observers;
|
||||||
|
|
||||||
|
use App\Exceptions\InfluxDBNotEnabledException;
|
||||||
|
use App\Models\Speedtest;
|
||||||
|
use App\Utils\InfluxDB\InfluxDB;
|
||||||
|
use Exception;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
class SpeedtestObserver
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle the Speedtest "created" event.
|
||||||
|
*
|
||||||
|
* @param \App\Speedtest $speedtest
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function created(Speedtest $speedtest)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
InfluxDB::connect()
|
||||||
|
->store($speedtest);
|
||||||
|
} catch (InfluxDBNotEnabledException $e) {
|
||||||
|
// /
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Log::error($e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,8 @@ use App\Listeners\SpeedtestCompleteListener;
|
|||||||
use App\Listeners\SpeedtestFailedListener;
|
use App\Listeners\SpeedtestFailedListener;
|
||||||
use App\Listeners\SpeedtestOverviewListener;
|
use App\Listeners\SpeedtestOverviewListener;
|
||||||
use App\Listeners\TestNotificationListener;
|
use App\Listeners\TestNotificationListener;
|
||||||
|
use App\Observers\SpeedtestObserver;
|
||||||
|
use App\Models\Speedtest;
|
||||||
use Illuminate\Auth\Events\Registered;
|
use Illuminate\Auth\Events\Registered;
|
||||||
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
|
||||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||||
@@ -49,6 +51,6 @@ class EventServiceProvider extends ServiceProvider
|
|||||||
{
|
{
|
||||||
parent::boot();
|
parent::boot();
|
||||||
|
|
||||||
//
|
Speedtest::observe(SpeedtestObserver::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,18 +35,20 @@ class IntegrationsServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
if(File::exists(env('DB_DATABASE'))) {
|
if (File::exists(env('DB_DATABASE'))) {
|
||||||
if(Schema::hasTable('settings')) {
|
if (Schema::hasTable('settings')) {
|
||||||
$setting = SettingsHelper::get('healthchecks_uuid');
|
$setting = SettingsHelper::get('healthchecks_uuid');
|
||||||
|
|
||||||
if($setting !== false) {
|
if ($setting !== false) {
|
||||||
try {
|
try {
|
||||||
App::bind('healthcheck', function() use ($setting) {
|
SettingsHelper::loadIntegrationConfig();
|
||||||
return new Healthchecks($setting->value);
|
|
||||||
|
App::bind('healthcheck', function () use ($setting) {
|
||||||
|
return new Healthchecks($setting->value, SettingsHelper::get('healthchecks_server_url')->value);
|
||||||
});
|
});
|
||||||
} catch(InvalidUuidStringException $e) {
|
} catch (InvalidUuidStringException $e) {
|
||||||
Log::error('Invalid healthchecks UUID');
|
Log::error('Invalid healthchecks UUID');
|
||||||
} catch(Exception $e) {
|
} catch (Exception $e) {
|
||||||
Log::error($e->getMessage());
|
Log::error($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class RouteServiceProvider extends ServiceProvider
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $namespace = 'App\Http\Controllers';
|
protected $namespace = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The path to the "home" route for your application.
|
* The path to the "home" route for your application.
|
||||||
|
|||||||
28
app/Providers/SpeedtestServiceProvider.php
Normal file
28
app/Providers/SpeedtestServiceProvider.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Helpers\SettingsHelper;
|
||||||
|
use App\Interfaces\SpeedtestProvider;
|
||||||
|
use App\Utils\OoklaTester;
|
||||||
|
use File;
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
use Schema;
|
||||||
|
|
||||||
|
class SpeedtestServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Bootstrap services.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function boot()
|
||||||
|
{
|
||||||
|
$this->app->singleton(
|
||||||
|
SpeedtestProvider::class,
|
||||||
|
function () {
|
||||||
|
return new OoklaTester();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class Speedtest extends Model
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The attributes that are mass assignable.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $fillable = [
|
|
||||||
'ping',
|
|
||||||
'download',
|
|
||||||
'upload',
|
|
||||||
'created_at',
|
|
||||||
'server_id',
|
|
||||||
'server_name',
|
|
||||||
'server_host',
|
|
||||||
'url',
|
|
||||||
'scheduled',
|
|
||||||
'failed',
|
|
||||||
];
|
|
||||||
|
|
||||||
protected $table = 'speedtests';
|
|
||||||
}
|
|
||||||
113
app/Utils/InfluxDB/InfluxDB.php
Normal file
113
app/Utils/InfluxDB/InfluxDB.php
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Utils\InfluxDB;
|
||||||
|
|
||||||
|
use App\Exceptions\InfluxDBConnectionErrorException;
|
||||||
|
use App\Exceptions\InfluxDBNotEnabledException;
|
||||||
|
use App\Helpers\SettingsHelper;
|
||||||
|
use App\Models\Speedtest;
|
||||||
|
use InfluxDB\Client as Version1;
|
||||||
|
use InfluxDB2\Client as Version2;
|
||||||
|
use App\Interfaces\InfluxDBWrapperInterface as Client;
|
||||||
|
|
||||||
|
class InfluxDB
|
||||||
|
{
|
||||||
|
private Client $client;
|
||||||
|
|
||||||
|
private string $database;
|
||||||
|
|
||||||
|
public function __construct(Client $client)
|
||||||
|
{
|
||||||
|
$this->client = $client;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connect to influx db
|
||||||
|
*
|
||||||
|
* @param string $host
|
||||||
|
* @param integer $port
|
||||||
|
* @param string $database
|
||||||
|
* @return InfluxDB
|
||||||
|
*/
|
||||||
|
public static function connect()
|
||||||
|
{
|
||||||
|
if (!(bool) SettingsHelper::get('influx_db_enabled')->value) {
|
||||||
|
throw new InfluxDBNotEnabledException();
|
||||||
|
}
|
||||||
|
|
||||||
|
$host = SettingsHelper::get('influx_db_host')->value;
|
||||||
|
$port = SettingsHelper::get('influx_db_port')->value;
|
||||||
|
$username = SettingsHelper::get('influx_db_username')->value;
|
||||||
|
$password = SettingsHelper::get('influx_db_password')->value;
|
||||||
|
$database = SettingsHelper::get('influx_db_database')->value;
|
||||||
|
$version = (int) SettingsHelper::get('influx_db_version')->value;
|
||||||
|
|
||||||
|
$wrapper = $version === 1
|
||||||
|
? new InfluxDBVersion1Wrapper(
|
||||||
|
new Version1(
|
||||||
|
str_replace(['http://', 'https://'], '', $host),
|
||||||
|
$port,
|
||||||
|
$username,
|
||||||
|
$password
|
||||||
|
)
|
||||||
|
)
|
||||||
|
: new InfluxDBVersion2Wrapper(
|
||||||
|
new Version2([
|
||||||
|
'url' => $host . ':' . $port,
|
||||||
|
'token' => '',
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
return (new self($wrapper))->setDatabase($database)
|
||||||
|
->testConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the database field
|
||||||
|
*
|
||||||
|
* @param string $database
|
||||||
|
* @return InfluxDB
|
||||||
|
*/
|
||||||
|
public function setDatabase(string $database): InfluxDB
|
||||||
|
{
|
||||||
|
$this->database = $database;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the connection
|
||||||
|
*
|
||||||
|
* @throws InfluxDBConnectionErrorException
|
||||||
|
* @return InfluxDB
|
||||||
|
*/
|
||||||
|
public function testConnection(): InfluxDB
|
||||||
|
{
|
||||||
|
if (!$this->client->testConnection()) {
|
||||||
|
throw new InfluxDBConnectionErrorException();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->doesDatabaseExist()) {
|
||||||
|
$this->createDatabase();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function doesDatabaseExist(): bool
|
||||||
|
{
|
||||||
|
return $this->client->doesDatabaseExist($this->database);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createDatabase(): bool
|
||||||
|
{
|
||||||
|
return $this->client->createDatabase($this->database);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(Speedtest $speedtest): InfluxDB
|
||||||
|
{
|
||||||
|
$this->client->store($speedtest);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
74
app/Utils/InfluxDB/InfluxDBVersion1Wrapper.php
Normal file
74
app/Utils/InfluxDB/InfluxDBVersion1Wrapper.php
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Utils\InfluxDB;
|
||||||
|
|
||||||
|
use App\Interfaces\InfluxDBWrapperInterface;
|
||||||
|
use App\Models\Speedtest;
|
||||||
|
use Exception;
|
||||||
|
use InfluxDB\Client;
|
||||||
|
use InfluxDB\Database;
|
||||||
|
use InfluxDB\Database\RetentionPolicy;
|
||||||
|
use InfluxDB\Point;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
class InfluxDBVersion1Wrapper implements InfluxDBWrapperInterface
|
||||||
|
{
|
||||||
|
private Client $client;
|
||||||
|
private Database $database;
|
||||||
|
|
||||||
|
public function __construct(Client $client)
|
||||||
|
{
|
||||||
|
$this->client = $client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConnection(): bool
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$this->client->listDatabases();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Log::error($e);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function doesDatabaseExist(string $database): bool
|
||||||
|
{
|
||||||
|
$this->database = $this->client->selectDB($database);
|
||||||
|
|
||||||
|
return (bool) $this->database->exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createDatabase(string $database): bool
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$this->database->create(
|
||||||
|
new RetentionPolicy(
|
||||||
|
'speedtest_retention_policy',
|
||||||
|
config('services.influxdb.retention'),
|
||||||
|
1,
|
||||||
|
true
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Log::error($e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(Speedtest $speedtest): bool
|
||||||
|
{
|
||||||
|
return $this->database->writePoints([
|
||||||
|
new Point(
|
||||||
|
'speedtest',
|
||||||
|
null,
|
||||||
|
['host' => config('services.influxdb.host')],
|
||||||
|
$speedtest->formatForInfluxDB(),
|
||||||
|
)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
37
app/Utils/InfluxDB/InfluxDBVersion2Wrapper.php
Normal file
37
app/Utils/InfluxDB/InfluxDBVersion2Wrapper.php
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Utils\InfluxDB;
|
||||||
|
|
||||||
|
use App\Interfaces\InfluxDBWrapperInterface;
|
||||||
|
use App\Models\Speedtest;
|
||||||
|
use InfluxDB2\Client;
|
||||||
|
|
||||||
|
class InfluxDBVersion2Wrapper implements InfluxDBWrapperInterface
|
||||||
|
{
|
||||||
|
private Client $client;
|
||||||
|
|
||||||
|
public function __construct(Client $client)
|
||||||
|
{
|
||||||
|
$this->client = $client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConnection(): bool
|
||||||
|
{
|
||||||
|
return $this->client->health()->getStatus() !== 'pass';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function doesDatabaseExist(string $database): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function createDatabase(string $database): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(Speedtest $speedtest): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
128
app/Utils/OoklaTester.php
Normal file
128
app/Utils/OoklaTester.php
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Utils;
|
||||||
|
|
||||||
|
use App\Exceptions\SpeedtestFailureException;
|
||||||
|
use App\Helpers\SettingsHelper;
|
||||||
|
use App\Helpers\SpeedtestHelper;
|
||||||
|
use App\Interfaces\SpeedtestProvider;
|
||||||
|
use App\Models\Speedtest;
|
||||||
|
use Cache;
|
||||||
|
use Exception;
|
||||||
|
use JsonException;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
class OoklaTester implements SpeedtestProvider
|
||||||
|
{
|
||||||
|
public function run($output = false, $scheduled = true): Speedtest
|
||||||
|
{
|
||||||
|
if ($output === false) {
|
||||||
|
$output = $this->output();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$output = json_decode($output, true, 512, JSON_THROW_ON_ERROR);
|
||||||
|
|
||||||
|
if (!$this->isOutputComplete($output)) {
|
||||||
|
$test = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$test = Speedtest::create([
|
||||||
|
'ping' => $output['ping']['latency'],
|
||||||
|
'download' => SpeedtestHelper::convert($output['download']['bandwidth']),
|
||||||
|
'upload' => SpeedtestHelper::convert($output['upload']['bandwidth']),
|
||||||
|
'server_id' => $output['server']['id'],
|
||||||
|
'server_name' => $output['server']['name'],
|
||||||
|
'server_host' => $output['server']['host'] . ':' . $output['server']['port'],
|
||||||
|
'url' => $output['result']['url'],
|
||||||
|
'scheduled' => $scheduled
|
||||||
|
]);
|
||||||
|
} catch (JsonException $e) {
|
||||||
|
Log::error('Failed to parse speedtest JSON');
|
||||||
|
Log::error($output);
|
||||||
|
$test = false;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Log::error($e->getMessage());
|
||||||
|
$test = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($test == false) {
|
||||||
|
Speedtest::create([
|
||||||
|
'ping' => 0,
|
||||||
|
'upload' => 0,
|
||||||
|
'download' => 0,
|
||||||
|
'failed' => true,
|
||||||
|
'scheduled' => $scheduled,
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw new SpeedtestFailureException(json_encode($output));
|
||||||
|
}
|
||||||
|
|
||||||
|
Cache::flush();
|
||||||
|
|
||||||
|
return $test;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function output()
|
||||||
|
{
|
||||||
|
$server = SettingsHelper::get('server')['value'];
|
||||||
|
|
||||||
|
$binPath = app_path() . DIRECTORY_SEPARATOR . 'Bin' . DIRECTORY_SEPARATOR . 'speedtest';
|
||||||
|
$homePrefix = config('speedtest.home') . ' && ';
|
||||||
|
|
||||||
|
if ($server != '' && $server != false) {
|
||||||
|
$server = explode(',', $server);
|
||||||
|
$server = $server[array_rand($server)];
|
||||||
|
if ($server == false) {
|
||||||
|
Log::error('Speedtest server undefined');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return shell_exec($homePrefix . $binPath . ' -f json -s ' . $server);
|
||||||
|
}
|
||||||
|
|
||||||
|
return shell_exec($homePrefix . $binPath . ' -f json');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks that the speedtest JSON output is complete/valid
|
||||||
|
*
|
||||||
|
* @param array $output
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public static function isOutputComplete($output)
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Array of indexes that must exist in $output
|
||||||
|
*/
|
||||||
|
$checks = [
|
||||||
|
'type' => 'result',
|
||||||
|
'download' => ['bandwidth' => '*'],
|
||||||
|
'upload' => ['bandwidth' => '*'],
|
||||||
|
'ping' => ['latency' => '*'],
|
||||||
|
'server' => [
|
||||||
|
'id' => '*',
|
||||||
|
'name' => '*',
|
||||||
|
'host' => '*',
|
||||||
|
'port' => '*'
|
||||||
|
],
|
||||||
|
'result' => [
|
||||||
|
'url' => '*'
|
||||||
|
],
|
||||||
|
];
|
||||||
|
/**
|
||||||
|
* Array of indexes that must not exist
|
||||||
|
*/
|
||||||
|
$checkMissing = [
|
||||||
|
'type' => 'error'
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($checks as $key => $value) {
|
||||||
|
if (!isset($output[$key])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,92 @@
|
|||||||
{
|
{
|
||||||
|
"1.12.1": [
|
||||||
|
{
|
||||||
|
"description": "Fixed a bug where the latest X days widget would not update (#680)",
|
||||||
|
"link": "https://github.com/henrywhitaker3/Speedtest-Tracker/pull/680"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"1.12.0": [
|
||||||
|
{
|
||||||
|
"description": "Added InfluxDB intergation.",
|
||||||
|
"link": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"1.11.1": [
|
||||||
|
{
|
||||||
|
"description": "Add option to show/hide columns in the all tests table.",
|
||||||
|
"link": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Add option to delete failed tests.",
|
||||||
|
"link": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"1.11.0": [
|
||||||
|
{
|
||||||
|
"description": "Upgrade to Laravel 8.",
|
||||||
|
"link": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Refactor loads of back-end stuff.",
|
||||||
|
"link": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Refactor front-end stuff.",
|
||||||
|
"link": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"1.10.4": [
|
||||||
|
{
|
||||||
|
"description": "Updated dependencies.",
|
||||||
|
"link": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"1.10.3": [
|
||||||
|
{
|
||||||
|
"description": "Moved stuff into pages.",
|
||||||
|
"link": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"1.10.2": [
|
||||||
|
{
|
||||||
|
"description": "Added option to disable scheduled tests.",
|
||||||
|
"link": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"1.10.1": [
|
||||||
|
{
|
||||||
|
"description": "Fixed integrations config being empty causing healthchecks to not run on scheduled tests.",
|
||||||
|
"link": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"1.10.0": [
|
||||||
|
{
|
||||||
|
"description": "Added automated build for ARM.",
|
||||||
|
"link": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Updated dependencies.",
|
||||||
|
"link": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"1.9.10": [
|
||||||
|
{
|
||||||
|
"description": "Laravel will now log into daily files and logs will only be kept for 7 days.",
|
||||||
|
"link": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"1.9.9": [
|
||||||
|
{
|
||||||
|
"description": "Updated dependencies.",
|
||||||
|
"link": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"1.9.8": [
|
||||||
|
{
|
||||||
|
"description": "Fixed bug with minimum display setting.",
|
||||||
|
"link": ""
|
||||||
|
}
|
||||||
|
],
|
||||||
"1.9.7": [
|
"1.9.7": [
|
||||||
{
|
{
|
||||||
"description": "Added option to display minimum values on the top widgets.",
|
"description": "Added option to display minimum values on the top widgets.",
|
||||||
|
|||||||
@@ -10,26 +10,30 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": "^7.2.5",
|
"php": "^7.2.5",
|
||||||
"doctrine/dbal": "^2.10",
|
"doctrine/dbal": "^2.10",
|
||||||
"dragonmantank/cron-expression": "^2",
|
"dragonmantank/cron-expression": "^3",
|
||||||
"fideloper/proxy": "^4.2",
|
"fideloper/proxy": "^4.2",
|
||||||
"fruitcake/laravel-cors": "^2.0",
|
"fruitcake/laravel-cors": "^2.0",
|
||||||
"guzzlehttp/guzzle": "^7.0",
|
"guzzlehttp/guzzle": "^7.0.1",
|
||||||
"henrywhitaker3/healthchecks-io": "^1.0",
|
"henrywhitaker3/healthchecks-io": "^1.0",
|
||||||
|
"henrywhitaker3/laravel-actions": "^1.0",
|
||||||
|
"influxdata/influxdb-client-php": "^1.12",
|
||||||
|
"influxdb/influxdb-php": "^1.15",
|
||||||
"laravel-notification-channels/telegram": "^0.5.0",
|
"laravel-notification-channels/telegram": "^0.5.0",
|
||||||
"laravel/framework": "^7.0",
|
"laravel/framework": "^8.0",
|
||||||
"laravel/slack-notification-channel": "^2.0",
|
"laravel/slack-notification-channel": "^2.0",
|
||||||
"laravel/tinker": "^2.0",
|
"laravel/tinker": "^2.0",
|
||||||
"laravel/ui": "^2.0",
|
"laravel/ui": "^3.0",
|
||||||
"tymon/jwt-auth": "^1.0"
|
"tymon/jwt-auth": "^1.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"barryvdh/laravel-ide-helper": "^2.8",
|
"barryvdh/laravel-ide-helper": "^2.8",
|
||||||
"facade/ignition": "^2.0",
|
"brianium/paratest": "^6.2",
|
||||||
|
"facade/ignition": "^2.3.6",
|
||||||
"fzaninotto/faker": "^1.9.1",
|
"fzaninotto/faker": "^1.9.1",
|
||||||
"mockery/mockery": "^1.3.1",
|
"mockery/mockery": "^1.3.1",
|
||||||
"nunomaduro/collision": "^4.1",
|
"nunomaduro/collision": "^5.3",
|
||||||
"nunomaduro/larastan": "^0.6.2",
|
"nunomaduro/larastan": "^0.7.0",
|
||||||
"phpunit/phpunit": "^8.5"
|
"phpunit/phpunit": "^9.5"
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"optimize-autoloader": true,
|
"optimize-autoloader": true,
|
||||||
@@ -43,12 +47,10 @@
|
|||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"App\\": "app/"
|
"App\\": "app/",
|
||||||
},
|
"Database\\Factories\\": "database/factories/",
|
||||||
"classmap": [
|
"Database\\Seeders\\": "database/seeders/"
|
||||||
"database/seeds",
|
}
|
||||||
"database/factories"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|||||||
3715
composer.lock
generated
3715
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -182,6 +182,7 @@ return [
|
|||||||
* Custom providers...
|
* Custom providers...
|
||||||
*/
|
*/
|
||||||
App\Providers\IntegrationsServiceProvider::class,
|
App\Providers\IntegrationsServiceProvider::class,
|
||||||
|
App\Providers\SpeedtestServiceProvider::class,
|
||||||
|
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|||||||
409
config/clockwork.php
Normal file
409
config/clockwork.php
Normal file
@@ -0,0 +1,409 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
/*
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
| Enable Clockwork
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Clockwork is enabled by default only when your application is in debug mode. Here you can explicitly enable or
|
||||||
|
| disable Clockwork. When disabled, no data is collected and the api and web ui are inactive.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'enable' => env('CLOCKWORK_ENABLE', null),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
| Features
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| You can enable or disable various Clockwork features here. Some features have additional settings (eg. slow query
|
||||||
|
| threshold for database queries).
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'features' => [
|
||||||
|
|
||||||
|
// Cache usage stats and cache queries including results
|
||||||
|
'cache' => [
|
||||||
|
'enabled' => env('CLOCKWORK_CACHE_ENABLED', true),
|
||||||
|
|
||||||
|
// Collect cache queries including results (high performance impact with a high number of queries)
|
||||||
|
'collect_queries' => env('CLOCKWORK_CACHE_QUERIES', false)
|
||||||
|
],
|
||||||
|
|
||||||
|
// Database usage stats and queries
|
||||||
|
'database' => [
|
||||||
|
'enabled' => env('CLOCKWORK_DATABASE_ENABLED', true),
|
||||||
|
|
||||||
|
// Collect database queries (high performance impact with a very high number of queries)
|
||||||
|
'collect_queries' => env('CLOCKWORK_DATABASE_COLLECT_QUERIES', true),
|
||||||
|
|
||||||
|
// Collect details of models updates (high performance impact with a lot of model updates)
|
||||||
|
'collect_models_actions' => env('CLOCKWORK_DATABASE_COLLECT_MODELS_ACTIONS', true),
|
||||||
|
|
||||||
|
// Collect details of retrieved models (very high performance impact with a lot of models retrieved)
|
||||||
|
'collect_models_retrieved' => env('CLOCKWORK_DATABASE_COLLECT_MODELS_RETRIEVED', false),
|
||||||
|
|
||||||
|
// Query execution time threshold in miliseconds after which the query will be marked as slow
|
||||||
|
'slow_threshold' => env('CLOCKWORK_DATABASE_SLOW_THRESHOLD'),
|
||||||
|
|
||||||
|
// Collect only slow database queries
|
||||||
|
'slow_only' => env('CLOCKWORK_DATABASE_SLOW_ONLY', false),
|
||||||
|
|
||||||
|
// Detect and report duplicate (N+1) queries
|
||||||
|
'detect_duplicate_queries' => env('CLOCKWORK_DATABASE_DETECT_DUPLICATE_QUERIES', false)
|
||||||
|
],
|
||||||
|
|
||||||
|
// Dispatched events
|
||||||
|
'events' => [
|
||||||
|
'enabled' => env('CLOCKWORK_EVENTS_ENABLED', true),
|
||||||
|
|
||||||
|
// Ignored events (framework events are ignored by default)
|
||||||
|
'ignored_events' => [
|
||||||
|
// App\Events\UserRegistered::class,
|
||||||
|
// 'user.registered'
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
// Laravel log (you can still log directly to Clockwork with laravel log disabled)
|
||||||
|
'log' => [
|
||||||
|
'enabled' => env('CLOCKWORK_LOG_ENABLED', true)
|
||||||
|
],
|
||||||
|
|
||||||
|
// Sent notifications
|
||||||
|
'notifications' => [
|
||||||
|
'enabled' => env('CLOCKWORK_NOTIFICATIONS_ENABLED', true),
|
||||||
|
],
|
||||||
|
|
||||||
|
// Performance metrics
|
||||||
|
'performance' => [
|
||||||
|
// Allow collecting of client metrics. Requires separate clockwork-browser npm package.
|
||||||
|
'client_metrics' => env('CLOCKWORK_PERFORMANCE_CLIENT_METRICS', true)
|
||||||
|
],
|
||||||
|
|
||||||
|
// Dispatched queue jobs
|
||||||
|
'queue' => [
|
||||||
|
'enabled' => env('CLOCKWORK_QUEUE_ENABLED', true)
|
||||||
|
],
|
||||||
|
|
||||||
|
// Redis commands
|
||||||
|
'redis' => [
|
||||||
|
'enabled' => env('CLOCKWORK_REDIS_ENABLED', true)
|
||||||
|
],
|
||||||
|
|
||||||
|
// Routes list
|
||||||
|
'routes' => [
|
||||||
|
'enabled' => env('CLOCKWORK_ROUTES_ENABLED', false)
|
||||||
|
],
|
||||||
|
|
||||||
|
// Rendered views
|
||||||
|
'views' => [
|
||||||
|
'enabled' => env('CLOCKWORK_VIEWS_ENABLED', true),
|
||||||
|
|
||||||
|
// Collect views including view data (high performance impact with a high number of views)
|
||||||
|
'collect_data' => env('CLOCKWORK_VIEWS_COLLECT_DATA', false),
|
||||||
|
|
||||||
|
// Use Twig profiler instead of Laravel events for apps using laravel-twigbridge (more precise, but does
|
||||||
|
// not support collecting view data)
|
||||||
|
'use_twig_profiler' => env('CLOCKWORK_VIEWS_USE_TWIG_PROFILER', false)
|
||||||
|
]
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
| Enable web UI
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Clockwork comes with a web UI accessibla via http://your.app/clockwork. Here you can enable or disable this
|
||||||
|
| feature. You can also set a custom path for the web UI.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'web' => env('CLOCKWORK_WEB', true),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
| Enable toolbar
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Clockwork can show a toolbar with basic metrics on all responses. Here you can enable or disable this feature.
|
||||||
|
| Requires a separate clockwork-browser npm library.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'toolbar' => env('CLOCKWORK_TOOLBAR', false),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
| HTTP requests collection
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Clockwork collects data about HTTP requests to your app. Here you can choose which requests should be collected.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'requests' => [
|
||||||
|
// With on-demand mode enabled, Clockwork will only profile requests when the browser extension is open or you
|
||||||
|
// manually pass a "clockwork-profile" cookie or get/post data key.
|
||||||
|
// Optionally you can specify a "secret" that has to be passed as the value to enable profiling.
|
||||||
|
'on_demand' => env('CLOCKWORK_REQUESTS_ON_DEMAND', false),
|
||||||
|
|
||||||
|
// Collect only errors (requests with HTTP 4xx and 5xx responses)
|
||||||
|
'errors_only' => env('CLOCKWORK_REQUESTS_ERRORS_ONLY', false),
|
||||||
|
|
||||||
|
// Response time threshold in miliseconds after which the request will be marked as slow
|
||||||
|
'slow_threshold' => env('CLOCKWORK_REQUESTS_SLOW_THRESHOLD'),
|
||||||
|
|
||||||
|
// Collect only slow requests
|
||||||
|
'slow_only' => env('CLOCKWORK_REQUESTS_SLOW_ONLY', false),
|
||||||
|
|
||||||
|
// Sample the collected requests (eg. set to 100 to collect only 1 in 100 requests)
|
||||||
|
'sample' => env('CLOCKWORK_REQUESTS_SAMPLE', false),
|
||||||
|
|
||||||
|
// List of URIs that should not be collected
|
||||||
|
'except' => [
|
||||||
|
'/horizon/.*', // Laravel Horizon requests
|
||||||
|
'/telescope/.*', // Laravel Telescope requests
|
||||||
|
'/files/*'
|
||||||
|
],
|
||||||
|
|
||||||
|
// List of URIs that should be collected, any other URI will not be collected if not empty
|
||||||
|
'only' => [
|
||||||
|
// '/api/.*'
|
||||||
|
],
|
||||||
|
|
||||||
|
// Don't collect OPTIONS requests, mostly used in the CSRF pre-flight requests and are rarely of interest
|
||||||
|
'except_preflight' => env('CLOCKWORK_REQUESTS_EXCEPT_PREFLIGHT', true)
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
| Artisan commands collection
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Clockwork can collect data about executed artisan commands. Here you can enable and configure which commands
|
||||||
|
| should be collected.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'artisan' => [
|
||||||
|
// Enable or disable collection of executed Artisan commands
|
||||||
|
'collect' => env('CLOCKWORK_ARTISAN_COLLECT', false),
|
||||||
|
|
||||||
|
// List of commands that should not be collected (built-in commands are not collected by default)
|
||||||
|
'except' => [
|
||||||
|
// 'inspire'
|
||||||
|
],
|
||||||
|
|
||||||
|
// List of commands that should be collected, any other command will not be collected if not empty
|
||||||
|
'only' => [
|
||||||
|
// 'inspire'
|
||||||
|
],
|
||||||
|
|
||||||
|
// Enable or disable collection of command output
|
||||||
|
'collect_output' => env('CLOCKWORK_ARTISAN_COLLECT_OUTPUT', false),
|
||||||
|
|
||||||
|
// Enable or disable collection of built-in Laravel commands
|
||||||
|
'except_laravel_commands' => env('CLOCKWORK_ARTISAN_EXCEPT_LARAVEL_COMMANDS', true)
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
| Queue jobs collection
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Clockwork can collect data about executed queue jobs. Here you can enable and configure which queue jobs should
|
||||||
|
| be collected.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'queue' => [
|
||||||
|
// Enable or disable collection of executed queue jobs
|
||||||
|
'collect' => env('CLOCKWORK_QUEUE_COLLECT', false),
|
||||||
|
|
||||||
|
// List of queue jobs that should not be collected
|
||||||
|
'except' => [
|
||||||
|
// App\Jobs\ExpensiveJob::class
|
||||||
|
],
|
||||||
|
|
||||||
|
// List of queue jobs that should be collected, any other queue job will not be collected if not empty
|
||||||
|
'only' => [
|
||||||
|
// App\Jobs\BuggyJob::class
|
||||||
|
]
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
| Tests collection
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Clockwork can collect data about executed tests. Here you can enable and configure which tests should be
|
||||||
|
| collected.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'tests' => [
|
||||||
|
// Enable or disable collection of ran tests
|
||||||
|
'collect' => env('CLOCKWORK_TESTS_COLLECT', false),
|
||||||
|
|
||||||
|
// List of tests that should not be collected
|
||||||
|
'except' => [
|
||||||
|
// Tests\Unit\ExampleTest::class
|
||||||
|
]
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
| Enable data collection when Clockwork is disabled
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| You can enable this setting to collect data even when Clockwork is disabled. Eg. for future analysis.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'collect_data_always' => env('CLOCKWORK_COLLECT_DATA_ALWAYS', false),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
| Metadata storage
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Configure how is the metadata collected by Clockwork stored. Two options are available:
|
||||||
|
| - files - A simple fast storage implementation storing data in one-per-request files.
|
||||||
|
| - sql - Stores requests in a sql database. Supports MySQL, Postgresql, Sqlite and requires PDO.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'storage' => env('CLOCKWORK_STORAGE', 'files'),
|
||||||
|
|
||||||
|
// Path where the Clockwork metadata is stored
|
||||||
|
'storage_files_path' => env('CLOCKWORK_STORAGE_FILES_PATH', storage_path('clockwork')),
|
||||||
|
|
||||||
|
// Compress the metadata files using gzip, trading a little bit of performance for lower disk usage
|
||||||
|
'storage_files_compress' => env('CLOCKWORK_STORAGE_FILES_COMPRESS', false),
|
||||||
|
|
||||||
|
// SQL database to use, can be a name of database configured in database.php or a path to a sqlite file
|
||||||
|
'storage_sql_database' => env('CLOCKWORK_STORAGE_SQL_DATABASE', storage_path('clockwork.sqlite')),
|
||||||
|
|
||||||
|
// SQL table name to use, the table is automatically created and udpated when needed
|
||||||
|
'storage_sql_table' => env('CLOCKWORK_STORAGE_SQL_TABLE', 'clockwork'),
|
||||||
|
|
||||||
|
// Maximum lifetime of collected metadata in minutes, older requests will automatically be deleted, false to disable
|
||||||
|
'storage_expiration' => env('CLOCKWORK_STORAGE_EXPIRATION', 60 * 24 * 7),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
| Authentication
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Clockwork can be configured to require authentication before allowing access to the collected data. This might be
|
||||||
|
| useful when the application is publicly accessible. Setting to true will enable a simple authentication with a
|
||||||
|
| pre-configured password. You can also pass a class name of a custom implementation.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'authentication' => env('CLOCKWORK_AUTHENTICATION', false),
|
||||||
|
|
||||||
|
// Password for the simple authentication
|
||||||
|
'authentication_password' => env('CLOCKWORK_AUTHENTICATION_PASSWORD', 'VerySecretPassword'),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
| Stack traces collection
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Clockwork can collect stack traces for log messages and certain data like database queries. Here you can set
|
||||||
|
| whether to collect stack traces, limit the number of collected frames and set further configuration. Collecting
|
||||||
|
| long stack traces considerably increases metadata size.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'stack_traces' => [
|
||||||
|
// Enable or disable collecting of stack traces
|
||||||
|
'enabled' => env('CLOCKWORK_STACK_TRACES_ENABLED', true),
|
||||||
|
|
||||||
|
// Limit the number of frames to be collected
|
||||||
|
'limit' => env('CLOCKWORK_STACK_TRACES_LIMIT', 10),
|
||||||
|
|
||||||
|
// List of vendor names to skip when determining caller, common vendors are automatically added
|
||||||
|
'skip_vendors' => [
|
||||||
|
// 'phpunit'
|
||||||
|
],
|
||||||
|
|
||||||
|
// List of namespaces to skip when determining caller
|
||||||
|
'skip_namespaces' => [
|
||||||
|
// 'Laravel'
|
||||||
|
],
|
||||||
|
|
||||||
|
// List of class names to skip when determining caller
|
||||||
|
'skip_classes' => [
|
||||||
|
// App\CustomLog::class
|
||||||
|
]
|
||||||
|
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
| Serialization
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Clockwork serializes the collected data to json for storage and transfer. Here you can configure certain aspects
|
||||||
|
| of serialization. Serialization has a large effect on the cpu time and memory usage.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Maximum depth of serialized multi-level arrays and objects
|
||||||
|
'serialization_depth' => env('CLOCKWORK_SERIALIZATION_DEPTH', 10),
|
||||||
|
|
||||||
|
// A list of classes that will never be serialized (eg. a common service container class)
|
||||||
|
'serialization_blackbox' => [
|
||||||
|
\Illuminate\Container\Container::class,
|
||||||
|
\Illuminate\Foundation\Application::class,
|
||||||
|
\Laravel\Lumen\Application::class
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
| Register helpers
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Clockwork comes with a "clock" global helper function. You can use this helper to quickly log something and to
|
||||||
|
| access the Clockwork instance.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'register_helpers' => env('CLOCKWORK_REGISTER_HELPERS', true),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
| Send Headers for AJAX request
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| When trying to collect data the AJAX method can sometimes fail if it is missing required headers. For example, an
|
||||||
|
| API might require a version number using Accept headers to route the HTTP request to the correct codebase.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'headers' => [
|
||||||
|
// 'Accept' => 'application/vnd.com.whatever.v1+json',
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
| Server-Timing
|
||||||
|
|------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Clockwork supports the W3C Server Timing specification, which allows for collecting a simple performance metrics
|
||||||
|
| in a cross-browser way. Eg. in Chrome, your app, database and timeline event timings will be shown in the Dev
|
||||||
|
| Tools network tab. This setting specifies the max number of timeline events that will be sent. Setting to false
|
||||||
|
| will disable the feature.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'server_timing' => env('CLOCKWORK_SERVER_TIMING', 10)
|
||||||
|
|
||||||
|
];
|
||||||
@@ -37,7 +37,7 @@ return [
|
|||||||
'channels' => [
|
'channels' => [
|
||||||
'stack' => [
|
'stack' => [
|
||||||
'driver' => 'stack',
|
'driver' => 'stack',
|
||||||
'channels' => ['single'],
|
'channels' => ['daily'],
|
||||||
'ignore_exceptions' => false,
|
'ignore_exceptions' => false,
|
||||||
],
|
],
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ return [
|
|||||||
'driver' => 'daily',
|
'driver' => 'daily',
|
||||||
'path' => storage_path('logs/laravel.log'),
|
'path' => storage_path('logs/laravel.log'),
|
||||||
'level' => 'debug',
|
'level' => 'debug',
|
||||||
'days' => 14,
|
'days' => 7,
|
||||||
],
|
],
|
||||||
|
|
||||||
'slack' => [
|
'slack' => [
|
||||||
|
|||||||
@@ -34,4 +34,9 @@ return [
|
|||||||
'token' => env('TELEGRAM_BOT_TOKEN', 'YOUR BOT TOKEN HERE')
|
'token' => env('TELEGRAM_BOT_TOKEN', 'YOUR BOT TOKEN HERE')
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'influxdb' => [
|
||||||
|
'retention' => env('INFLUXDB_RETENTION', '30d'),
|
||||||
|
'host' => env('INFLUXDB_HOST_TAG', 'speedtest'),
|
||||||
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ return [
|
|||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'version' => '1.9.7',
|
'version' => '1.12.1',
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
@@ -15,7 +15,7 @@ return [
|
|||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'install' => 'manual',
|
'install' => 'docker',
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
@@ -23,7 +23,7 @@ return [
|
|||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'home' => 'HOME=' . base_path() . DIRECTORY_SEPARATOR,
|
'home' => 'HOME=/config',
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|||||||
1
database/.gitignore
vendored
1
database/.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
*.sqlite
|
*.sqlite
|
||||||
*.sqlite-journal
|
*.sqlite-journal
|
||||||
*.bak
|
*.bak
|
||||||
|
*.db_test*
|
||||||
|
|||||||
32
database/factories/SpeedtestFactory.php
Normal file
32
database/factories/SpeedtestFactory.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\Speedtest;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
class SpeedtestFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name of the factory's corresponding model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $model = Speedtest::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function definition()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'download' => rand(15, 900),
|
||||||
|
'upload' => rand(15, 900),
|
||||||
|
'ping' => rand(1, 25),
|
||||||
|
'scheduled' => (bool) rand(0, 1),
|
||||||
|
'failed' => false,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
/** @var \Illuminate\Database\Eloquent\Factory $factory */
|
/** @var \Illuminate\Database\Eloquent\Factory $factory */
|
||||||
|
|
||||||
use App\User;
|
use App\Models\User;
|
||||||
use Faker\Generator as Faker;
|
use Faker\Generator as Faker;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\User;
|
use App\Models\User;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Helpers\SettingsHelper;
|
use App\Helpers\SettingsHelper;
|
||||||
use App\Setting;
|
use App\Models\Setting;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Setting;
|
use App\Models\Setting;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Setting;
|
use App\Models\Setting;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Helpers\SettingsHelper;
|
use App\Helpers\SettingsHelper;
|
||||||
use App\Setting;
|
use App\Models\Setting;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Helpers\SettingsHelper;
|
use App\Helpers\SettingsHelper;
|
||||||
use App\Setting;
|
use App\Models\Setting;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Helpers\SettingsHelper;
|
use App\Helpers\SettingsHelper;
|
||||||
use App\Setting;
|
use App\Models\Setting;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Helpers\SettingsHelper;
|
use App\Helpers\SettingsHelper;
|
||||||
use App\Setting;
|
use App\Models\Setting;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Helpers\SettingsHelper;
|
use App\Helpers\SettingsHelper;
|
||||||
use App\Setting;
|
use App\Models\Setting;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Helpers\SettingsHelper;
|
use App\Helpers\SettingsHelper;
|
||||||
use App\Setting;
|
use App\Models\Setting;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Helpers\SettingsHelper;
|
||||||
|
use App\Models\Setting;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddScheduleEnabledSetting extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
if (!SettingsHelper::get('schedule_enabled')) {
|
||||||
|
Setting::create([
|
||||||
|
'name' => 'schedule_enabled',
|
||||||
|
'value' => true,
|
||||||
|
'description' => 'Enable/disable the schedule worker'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Setting::whereIn('name', [
|
||||||
|
'schedule_enabled',
|
||||||
|
])->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Helpers\SettingsHelper;
|
||||||
|
use App\Models\Setting;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddAppNameSetting extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
if (!SettingsHelper::get('app_name')) {
|
||||||
|
Setting::create([
|
||||||
|
'name' => 'app_name',
|
||||||
|
'value' => 'Speedtest Tracker',
|
||||||
|
'description' => 'Set a custom app name'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Setting::whereIn('name', [
|
||||||
|
'app_name',
|
||||||
|
])->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Helpers\SettingsHelper;
|
||||||
|
use App\Models\Setting;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddCustomHealthchecksSetting extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
if (!SettingsHelper::get('healthchecks_server_url')) {
|
||||||
|
Setting::create([
|
||||||
|
'name' => 'healthchecks_server_url',
|
||||||
|
'value' => 'https://hc-ping.com/',
|
||||||
|
'description' => 'The URL of the healthchecks.io server. Change this to use a self-hosted server.'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Setting::whereIn('name', [
|
||||||
|
'healthchecks_server_url',
|
||||||
|
])->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Helpers\SettingsHelper;
|
||||||
|
use App\Models\Setting;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddSpeedtestProviderSetting extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
if (!SettingsHelper::get('healthchecks_server_url')) {
|
||||||
|
Setting::create([
|
||||||
|
'name' => 'speedtest_provider',
|
||||||
|
'value' => 'ookla',
|
||||||
|
'description' => 'The provider/package used to run speedtests.'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Setting::whereIn('name', [
|
||||||
|
'speedtest_provider',
|
||||||
|
])->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Setting;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class UpdateSpeedtestServerSettingsText extends Migration
|
||||||
|
{
|
||||||
|
private Setting $setting;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->setting = Setting::where('name', 'server')->first();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
$this->setting->description = '<p class="d-inline">Comma-separated list of speedtest.net server IDs picked randomly. Leave blank to use default settings.</p>;';
|
||||||
|
$this->setting->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
$this->setting->description = '<p class="d-inline">Comma-separated list of speedtest.net servers picked randomly. Leave blank to use default settings.</p>';
|
||||||
|
$this->setting->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Helpers\SettingsHelper;
|
||||||
|
use App\Models\Setting;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddVisibleColumnsSetting extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
if (!SettingsHelper::get('visible_columns')) {
|
||||||
|
Setting::create([
|
||||||
|
'name' => 'visible_columns',
|
||||||
|
'value' => [
|
||||||
|
'id', 'created_at', 'download', 'upload', 'ping'
|
||||||
|
],
|
||||||
|
'description' => 'Choose and order the columns shown in the "All Tests" table.'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Setting::whereIn('name', [
|
||||||
|
'visible_columns',
|
||||||
|
])->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Helpers\SettingsHelper;
|
||||||
|
use App\Models\Setting;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddHiddenColumnsSetting extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
if (!SettingsHelper::get('hidden_columns')) {
|
||||||
|
Setting::create([
|
||||||
|
'name' => 'hidden_columns',
|
||||||
|
'value' => [
|
||||||
|
'server_id', 'server_name', 'server_host', 'url', 'scheduled',
|
||||||
|
],
|
||||||
|
'description' => 'Columns hidden from the "All Tests" table.'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Setting::whereIn('name', [
|
||||||
|
'hidden_columns',
|
||||||
|
])->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Helpers\SettingsHelper;
|
||||||
|
use App\Models\Setting;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddInfluxDbSettings extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
if (!SettingsHelper::get('influx_db_enabled')) {
|
||||||
|
Setting::create([
|
||||||
|
'name' => 'influx_db_enabled',
|
||||||
|
'value' => false,
|
||||||
|
'description' => 'Enable the InfluxDB integration for speedtests.'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!SettingsHelper::get('influx_db_host')) {
|
||||||
|
Setting::create([
|
||||||
|
'name' => 'influx_db_host',
|
||||||
|
'value' => '',
|
||||||
|
'description' => 'InfluxDB hostname, include the protocol (http:// or https://).'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!SettingsHelper::get('influx_db_port')) {
|
||||||
|
Setting::create([
|
||||||
|
'name' => 'influx_db_port',
|
||||||
|
'value' => '',
|
||||||
|
'description' => 'InfluxDB port'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!SettingsHelper::get('influx_db_database')) {
|
||||||
|
Setting::create([
|
||||||
|
'name' => 'influx_db_database',
|
||||||
|
'value' => '',
|
||||||
|
'description' => 'InfluxDB database'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!SettingsHelper::get('influx_db_username')) {
|
||||||
|
Setting::create([
|
||||||
|
'name' => 'influx_db_username',
|
||||||
|
'value' => '',
|
||||||
|
'description' => 'InfluxDB username'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!SettingsHelper::get('influx_db_password')) {
|
||||||
|
Setting::create([
|
||||||
|
'name' => 'influx_db_password',
|
||||||
|
'value' => '',
|
||||||
|
'description' => 'InfluxDB password'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!SettingsHelper::get('influx_db_version')) {
|
||||||
|
Setting::create([
|
||||||
|
'name' => 'influx_db_version',
|
||||||
|
'value' => 1,
|
||||||
|
'description' => 'InfluxDB version'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Setting::whereIn('name', [
|
||||||
|
'influx_db_enabled',
|
||||||
|
'influx_db_host',
|
||||||
|
'influx_db_port',
|
||||||
|
'influx_db_database',
|
||||||
|
'influx_db_username',
|
||||||
|
'influx_db_password',
|
||||||
|
'influx_db_version',
|
||||||
|
])->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use Database\Seeders\SpeedtestSeeder;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
class DatabaseSeeder extends Seeder
|
class DatabaseSeeder extends Seeder
|
||||||
@@ -11,6 +14,6 @@ class DatabaseSeeder extends Seeder
|
|||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
// $this->call(UserSeeder::class);
|
$this->call(SpeedtestSeeder::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
21
database/seeders/SpeedtestSeeder.php
Normal file
21
database/seeders/SpeedtestSeeder.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use App\Models\Speedtest;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
|
class SpeedtestSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
Speedtest::factory()
|
||||||
|
->count(250)
|
||||||
|
->create();
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
11
docker/Dockerfile
Normal file
11
docker/Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
FROM linuxserver/nginx
|
||||||
|
LABEL maintainer=henrywhitaker3@outlook.com
|
||||||
|
|
||||||
|
ENV arch='x86_64'
|
||||||
|
|
||||||
|
COPY docker/conf/ /
|
||||||
|
COPY . /site
|
||||||
|
|
||||||
|
EXPOSE 80 443
|
||||||
|
|
||||||
|
VOLUME ["/config"]
|
||||||
10
docker/arm.Dockerfile
Normal file
10
docker/arm.Dockerfile
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
FROM linuxserver/nginx:arm32v7-latest
|
||||||
|
LABEL maintainer=henrywhitaker3@outlook.com
|
||||||
|
|
||||||
|
ENV arch='arm'
|
||||||
|
|
||||||
|
COPY conf/ /
|
||||||
|
|
||||||
|
EXPOSE 80 443
|
||||||
|
|
||||||
|
VOLUME ["/config"]
|
||||||
10
docker/conf/defaults/crontab
Normal file
10
docker/conf/defaults/crontab
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# do daily/weekly/monthly maintenance
|
||||||
|
# min hour day month weekday command
|
||||||
|
*/15 * * * * run-parts /etc/periodic/15min
|
||||||
|
0 * * * * run-parts /etc/periodic/hourly
|
||||||
|
0 2 * * * run-parts /etc/periodic/daily
|
||||||
|
0 3 * * 6 run-parts /etc/periodic/weekly
|
||||||
|
0 5 1 * * run-parts /etc/periodic/monthly
|
||||||
|
# speedtest cron
|
||||||
|
* * * * * php /config/www/artisan schedule:run >> /config/log/speedtest/cron.log
|
||||||
|
# */5 * * * * php /config/www/artisan queue:retry all >> /config/log/speedtest.cron.log
|
||||||
30
docker/conf/defaults/default
Normal file
30
docker/conf/defaults/default
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
server {
|
||||||
|
listen 80 default_server;
|
||||||
|
|
||||||
|
listen 443 ssl;
|
||||||
|
|
||||||
|
root /config/www/public;
|
||||||
|
index index.html index.htm index.php;
|
||||||
|
|
||||||
|
server_name _;
|
||||||
|
|
||||||
|
ssl_certificate /config/keys/cert.crt;
|
||||||
|
ssl_certificate_key /config/keys/cert.key;
|
||||||
|
|
||||||
|
client_max_body_size 0;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ /index.php?$args;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~ \.php$ {
|
||||||
|
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||||
|
# With php5-cgi alone:
|
||||||
|
fastcgi_pass 127.0.0.1:9000;
|
||||||
|
# With php5-fpm:
|
||||||
|
#fastcgi_pass unix:/var/run/php5-fpm.sock;
|
||||||
|
fastcgi_index index.php;
|
||||||
|
include /etc/nginx/fastcgi_params;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
138
docker/conf/etc/cont-init.d/50-speedtest
Normal file
138
docker/conf/etc/cont-init.d/50-speedtest
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
#!/usr/bin/with-contenv bash
|
||||||
|
# # This script sets up the speedtest app
|
||||||
|
|
||||||
|
function eulaError()
|
||||||
|
{
|
||||||
|
echo "##################################################################################################################################"
|
||||||
|
echo "##################################################################################################################################"
|
||||||
|
echo "You haven't accepted the Ookla EULA. Please re-create the container with the environment variable 'OOKLA_EULA_GDPR' set to 'true'."
|
||||||
|
echo "##################################################################################################################################"
|
||||||
|
echo "##################################################################################################################################"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Do Ookla stuff
|
||||||
|
if [ -z ${OOKLA_EULA_GDPR+x} ]; then
|
||||||
|
eulaError
|
||||||
|
else
|
||||||
|
if [ $OOKLA_EULA_GDPR != "true" ]; then
|
||||||
|
eulaError
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f /config/www/app/Bin/speedtest ]; then
|
||||||
|
echo "Ookla GDPR and EULA accepted. Downloading Speedtest CLI."
|
||||||
|
cd /tmp
|
||||||
|
wget https://install.speedtest.net/app/cli/ookla-speedtest-1.0.0-$arch-linux.tgz -O speedtest.tgz > /dev/null
|
||||||
|
tar zxvf speedtest.tgz > /dev/null
|
||||||
|
cp speedtest /site/app/Bin/
|
||||||
|
|
||||||
|
HOME=/config && s6-setuidgid abc /site/artisan speedtest:eula > /dev/null
|
||||||
|
HOME=/root
|
||||||
|
else
|
||||||
|
HOME=/config && s6-setuidgid abc /config/www/artisan speedtest:eula > /dev/null
|
||||||
|
HOME=/root
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Copy site files to /config
|
||||||
|
echo "Copying latest site files to config"
|
||||||
|
cp -rfT /site/ /config/www/
|
||||||
|
|
||||||
|
# Check for DB
|
||||||
|
if [ ! -f /config/speed.db ]; then
|
||||||
|
echo "Database file not found! Creating empty database"
|
||||||
|
touch /config/speed.db
|
||||||
|
else
|
||||||
|
echo "Database file exists"
|
||||||
|
chown abc:abc /config/speed.db
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check for .env
|
||||||
|
if [ ! -f /config/www/.env ]; then
|
||||||
|
echo "Env file not found! Creating .env file"
|
||||||
|
cp /site/.env.example /config/www/.env
|
||||||
|
else
|
||||||
|
echo "Env file exists"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f /config/www/.composer-time ]; then
|
||||||
|
echo 'Removing old packages'
|
||||||
|
rm -rf /config/www/vendor/
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo 'Updating packages'
|
||||||
|
apk add composer
|
||||||
|
cd /config/www && composer install && echo date > /config/www/.composer-time
|
||||||
|
|
||||||
|
sed "s,DB_DATABASE=.*,DB_DATABASE=/config/speed.db," -i.bak /config/www/.env
|
||||||
|
|
||||||
|
echo "Running database migrations"
|
||||||
|
php /config/www/artisan migrate
|
||||||
|
|
||||||
|
# Check app key exists
|
||||||
|
if grep -E "APP_KEY=[0-9A-Za-z:+\/=]{1,}" /config/www/.env > /dev/null; then
|
||||||
|
echo "App key exists"
|
||||||
|
else
|
||||||
|
echo "Generating app key"
|
||||||
|
php /config/www/artisan key:generate
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check JWT secret exists
|
||||||
|
if grep -E "JWT_SECRET=[0-9A-Za-z:+\/=]{1,}" /config/www/.env > /dev/null ; then
|
||||||
|
echo "JWT secret exists"
|
||||||
|
else
|
||||||
|
echo "Generating JWT secret"
|
||||||
|
php /config/www/artisan jwt:secret
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z ${SLACK_WEBHOOK+x} ]; then
|
||||||
|
echo "Slack webhook is unset"
|
||||||
|
sed "s,SLACK_WEBHOOK=.*,SLACK_WEBHOOK=," -i.bak /config/www/.env
|
||||||
|
else
|
||||||
|
echo "Slack webhook set, updating db"
|
||||||
|
sed "s,SLACK_WEBHOOK=.*,SLACK_WEBHOOK=$SLACK_WEBHOOK," -i.bak /config/www/.env
|
||||||
|
php /config/www/artisan speedtest:slack $SLACK_WEBHOOK
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z ${TELEGRAM_BOT_TOKEN+x} ] && [ -z ${TELEGRAM_CHAT_ID+x} ]; then
|
||||||
|
echo "Telegram chat id and bot token unset"
|
||||||
|
sed "s,TELEGRAM_BOT_TOKEN=.*,TELEGRAM_BOT_TOKEN=," -i.bak /config/www/.env
|
||||||
|
sed "s,TELEGRAM_CHAT_ID=.*,TELEGRAM_CHAT_ID=," -i.bak /config/www/.env
|
||||||
|
else
|
||||||
|
echo "Telegram chat id and bot token set, updating .env"
|
||||||
|
sed "s,TELEGRAM_BOT_TOKEN=.*,TELEGRAM_BOT_TOKEN=$TELEGRAM_BOT_TOKEN," -i.bak /config/www/.env
|
||||||
|
sed "s,TELEGRAM_CHAT_ID=.*,TELEGRAM_CHAT_ID=$TELEGRAM_CHAT_ID," -i.bak /config/www/.env
|
||||||
|
php /config/www/artisan speedtest:telegram --chat=$TELEGRAM_CHAT_ID --bot=$TELEGRAM_BOT_TOKEN
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z ${BASE_PATH+x} ]; then
|
||||||
|
echo "Base path is unset"
|
||||||
|
sed "s,BASE_PATH=.*,BASE_PATH=," -i.bak /config/www/.env
|
||||||
|
else
|
||||||
|
echo "Base path set, updating .env"
|
||||||
|
sed "s,BASE_PATH=.*,BASE_PATH=$BASE_PATH," -i.bak /config/www/.env
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z ${AUTH+x} ]; then
|
||||||
|
echo "AUTH variable not set. Disabling authentication"
|
||||||
|
php /config/www/artisan speedtest:auth --disable
|
||||||
|
else
|
||||||
|
if [ $AUTH == 'true' ]; then
|
||||||
|
echo "AUTH variable set. Enabling authentication"
|
||||||
|
php /config/www/artisan speedtest:auth --enable
|
||||||
|
else
|
||||||
|
echo "AUTH variable set, but not to 'true'. Disabling authentication"
|
||||||
|
php /config/www/artisan speedtest:auth --disable
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Clearing old jobs from queue"
|
||||||
|
php /config/www/artisan queue:clear
|
||||||
|
|
||||||
|
mkdir -p /config/log/speedtest
|
||||||
|
|
||||||
|
cp /defaults/crontab /etc/crontabs/root
|
||||||
|
|
||||||
|
chown -R abc:abc /config
|
||||||
|
chmod +x /config/www/app/Bin/speedtest
|
||||||
|
chmod -R 777 /config/www/storage/clockwork
|
||||||
439
docker/conf/etc/php7/php-fpm.d/www.conf
Normal file
439
docker/conf/etc/php7/php-fpm.d/www.conf
Normal file
@@ -0,0 +1,439 @@
|
|||||||
|
; Start a new pool named 'www'.
|
||||||
|
; the variable $pool can be used in any directive and will be replaced by the
|
||||||
|
; pool name ('www' here)
|
||||||
|
[www]
|
||||||
|
|
||||||
|
; Per pool prefix
|
||||||
|
; It only applies on the following directives:
|
||||||
|
; - 'access.log'
|
||||||
|
; - 'slowlog'
|
||||||
|
; - 'listen' (unixsocket)
|
||||||
|
; - 'chroot'
|
||||||
|
; - 'chdir'
|
||||||
|
; - 'php_values'
|
||||||
|
; - 'php_admin_values'
|
||||||
|
; When not set, the global prefix (or /usr) applies instead.
|
||||||
|
; Note: This directive can also be relative to the global prefix.
|
||||||
|
; Default Value: none
|
||||||
|
;prefix = /path/to/pools/$pool
|
||||||
|
|
||||||
|
; Unix user/group of processes
|
||||||
|
; Note: The user is mandatory. If the group is not set, the default user's group
|
||||||
|
; will be used.
|
||||||
|
user = abc
|
||||||
|
group = abc
|
||||||
|
|
||||||
|
; The address on which to accept FastCGI requests.
|
||||||
|
; Valid syntaxes are:
|
||||||
|
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on
|
||||||
|
; a specific port;
|
||||||
|
; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
|
||||||
|
; a specific port;
|
||||||
|
; 'port' - to listen on a TCP socket to all addresses
|
||||||
|
; (IPv6 and IPv4-mapped) on a specific port;
|
||||||
|
; '/path/to/unix/socket' - to listen on a unix socket.
|
||||||
|
; Note: This value is mandatory.
|
||||||
|
listen = 127.0.0.1:9000
|
||||||
|
|
||||||
|
; Set listen(2) backlog.
|
||||||
|
; Default Value: 511 (-1 on FreeBSD and OpenBSD)
|
||||||
|
;listen.backlog = 511
|
||||||
|
|
||||||
|
; Set permissions for unix socket, if one is used. In Linux, read/write
|
||||||
|
; permissions must be set in order to allow connections from a web server. Many
|
||||||
|
; BSD-derived systems allow connections regardless of permissions. The owner
|
||||||
|
; and group can be specified either by name or by their numeric IDs.
|
||||||
|
; Default Values: user and group are set as the running user
|
||||||
|
; mode is set to 0660
|
||||||
|
;listen.owner = nobody
|
||||||
|
;listen.group = abc
|
||||||
|
;listen.mode = 0660
|
||||||
|
; When POSIX Access Control Lists are supported you can set them using
|
||||||
|
; these options, value is a comma separated list of user/group names.
|
||||||
|
; When set, listen.owner and listen.group are ignored
|
||||||
|
;listen.acl_users =
|
||||||
|
;listen.acl_groups =
|
||||||
|
|
||||||
|
; List of addresses (IPv4/IPv6) of FastCGI clients which are allowed to connect.
|
||||||
|
; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
|
||||||
|
; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
|
||||||
|
; must be separated by a comma. If this value is left blank, connections will be
|
||||||
|
; accepted from any ip address.
|
||||||
|
; Default Value: any
|
||||||
|
;listen.allowed_clients = 127.0.0.1
|
||||||
|
|
||||||
|
; Specify the nice(2) priority to apply to the pool processes (only if set)
|
||||||
|
; The value can vary from -19 (highest priority) to 20 (lower priority)
|
||||||
|
; Note: - It will only work if the FPM master process is launched as root
|
||||||
|
; - The pool processes will inherit the master process priority
|
||||||
|
; unless it specified otherwise
|
||||||
|
; Default Value: no set
|
||||||
|
; process.priority = -19
|
||||||
|
|
||||||
|
; Set the process dumpable flag (PR_SET_DUMPABLE prctl) even if the process user
|
||||||
|
; or group is differrent than the master process user. It allows to create process
|
||||||
|
; core dump and ptrace the process for the pool user.
|
||||||
|
; Default Value: no
|
||||||
|
; process.dumpable = yes
|
||||||
|
|
||||||
|
; Choose how the process manager will control the number of child processes.
|
||||||
|
; Possible Values:
|
||||||
|
; static - a fixed number (pm.max_children) of child processes;
|
||||||
|
; dynamic - the number of child processes are set dynamically based on the
|
||||||
|
; following directives. With this process management, there will be
|
||||||
|
; always at least 1 children.
|
||||||
|
; pm.max_children - the maximum number of children that can
|
||||||
|
; be alive at the same time.
|
||||||
|
; pm.start_servers - the number of children created on startup.
|
||||||
|
; pm.min_spare_servers - the minimum number of children in 'idle'
|
||||||
|
; state (waiting to process). If the number
|
||||||
|
; of 'idle' processes is less than this
|
||||||
|
; number then some children will be created.
|
||||||
|
; pm.max_spare_servers - the maximum number of children in 'idle'
|
||||||
|
; state (waiting to process). If the number
|
||||||
|
; of 'idle' processes is greater than this
|
||||||
|
; number then some children will be killed.
|
||||||
|
; ondemand - no children are created at startup. Children will be forked when
|
||||||
|
; new requests will connect. The following parameter are used:
|
||||||
|
; pm.max_children - the maximum number of children that
|
||||||
|
; can be alive at the same time.
|
||||||
|
; pm.process_idle_timeout - The number of seconds after which
|
||||||
|
; an idle process will be killed.
|
||||||
|
; Note: This value is mandatory.
|
||||||
|
pm = dynamic
|
||||||
|
|
||||||
|
; The number of child processes to be created when pm is set to 'static' and the
|
||||||
|
; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
|
||||||
|
; This value sets the limit on the number of simultaneous requests that will be
|
||||||
|
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
|
||||||
|
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
|
||||||
|
; CGI. The below defaults are based on a server without much resources. Don't
|
||||||
|
; forget to tweak pm.* to fit your needs.
|
||||||
|
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
|
||||||
|
; Note: This value is mandatory.
|
||||||
|
pm.max_children = 5
|
||||||
|
|
||||||
|
; The number of child processes created on startup.
|
||||||
|
; Note: Used only when pm is set to 'dynamic'
|
||||||
|
; Default Value: (min_spare_servers + max_spare_servers) / 2
|
||||||
|
pm.start_servers = 2
|
||||||
|
|
||||||
|
; The desired minimum number of idle server processes.
|
||||||
|
; Note: Used only when pm is set to 'dynamic'
|
||||||
|
; Note: Mandatory when pm is set to 'dynamic'
|
||||||
|
pm.min_spare_servers = 1
|
||||||
|
|
||||||
|
; The desired maximum number of idle server processes.
|
||||||
|
; Note: Used only when pm is set to 'dynamic'
|
||||||
|
; Note: Mandatory when pm is set to 'dynamic'
|
||||||
|
pm.max_spare_servers = 3
|
||||||
|
|
||||||
|
; The number of seconds after which an idle process will be killed.
|
||||||
|
; Note: Used only when pm is set to 'ondemand'
|
||||||
|
; Default Value: 10s
|
||||||
|
;pm.process_idle_timeout = 10s;
|
||||||
|
|
||||||
|
; The number of requests each child process should execute before respawning.
|
||||||
|
; This can be useful to work around memory leaks in 3rd party libraries. For
|
||||||
|
; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
|
||||||
|
; Default Value: 0
|
||||||
|
;pm.max_requests = 500
|
||||||
|
|
||||||
|
; The URI to view the FPM status page. If this value is not set, no URI will be
|
||||||
|
; recognized as a status page. It shows the following informations:
|
||||||
|
; pool - the name of the pool;
|
||||||
|
; process manager - static, dynamic or ondemand;
|
||||||
|
; start time - the date and time FPM has started;
|
||||||
|
; start since - number of seconds since FPM has started;
|
||||||
|
; accepted conn - the number of request accepted by the pool;
|
||||||
|
; listen queue - the number of request in the queue of pending
|
||||||
|
; connections (see backlog in listen(2));
|
||||||
|
; max listen queue - the maximum number of requests in the queue
|
||||||
|
; of pending connections since FPM has started;
|
||||||
|
; listen queue len - the size of the socket queue of pending connections;
|
||||||
|
; idle processes - the number of idle processes;
|
||||||
|
; active processes - the number of active processes;
|
||||||
|
; total processes - the number of idle + active processes;
|
||||||
|
; max active processes - the maximum number of active processes since FPM
|
||||||
|
; has started;
|
||||||
|
; max children reached - number of times, the process limit has been reached,
|
||||||
|
; when pm tries to start more children (works only for
|
||||||
|
; pm 'dynamic' and 'ondemand');
|
||||||
|
; Value are updated in real time.
|
||||||
|
; Example output:
|
||||||
|
; pool: www
|
||||||
|
; process manager: static
|
||||||
|
; start time: 01/Jul/2011:17:53:49 +0200
|
||||||
|
; start since: 62636
|
||||||
|
; accepted conn: 190460
|
||||||
|
; listen queue: 0
|
||||||
|
; max listen queue: 1
|
||||||
|
; listen queue len: 42
|
||||||
|
; idle processes: 4
|
||||||
|
; active processes: 11
|
||||||
|
; total processes: 15
|
||||||
|
; max active processes: 12
|
||||||
|
; max children reached: 0
|
||||||
|
;
|
||||||
|
; By default the status page output is formatted as text/plain. Passing either
|
||||||
|
; 'html', 'xml' or 'json' in the query string will return the corresponding
|
||||||
|
; output syntax. Example:
|
||||||
|
; http://www.foo.bar/status
|
||||||
|
; http://www.foo.bar/status?json
|
||||||
|
; http://www.foo.bar/status?html
|
||||||
|
; http://www.foo.bar/status?xml
|
||||||
|
;
|
||||||
|
; By default the status page only outputs short status. Passing 'full' in the
|
||||||
|
; query string will also return status for each pool process.
|
||||||
|
; Example:
|
||||||
|
; http://www.foo.bar/status?full
|
||||||
|
; http://www.foo.bar/status?json&full
|
||||||
|
; http://www.foo.bar/status?html&full
|
||||||
|
; http://www.foo.bar/status?xml&full
|
||||||
|
; The Full status returns for each process:
|
||||||
|
; pid - the PID of the process;
|
||||||
|
; state - the state of the process (Idle, Running, ...);
|
||||||
|
; start time - the date and time the process has started;
|
||||||
|
; start since - the number of seconds since the process has started;
|
||||||
|
; requests - the number of requests the process has served;
|
||||||
|
; request duration - the duration in µs of the requests;
|
||||||
|
; request method - the request method (GET, POST, ...);
|
||||||
|
; request URI - the request URI with the query string;
|
||||||
|
; content length - the content length of the request (only with POST);
|
||||||
|
; user - the user (PHP_AUTH_USER) (or '-' if not set);
|
||||||
|
; script - the main script called (or '-' if not set);
|
||||||
|
; last request cpu - the %cpu the last request consumed
|
||||||
|
; it's always 0 if the process is not in Idle state
|
||||||
|
; because CPU calculation is done when the request
|
||||||
|
; processing has terminated;
|
||||||
|
; last request memory - the max amount of memory the last request consumed
|
||||||
|
; it's always 0 if the process is not in Idle state
|
||||||
|
; because memory calculation is done when the request
|
||||||
|
; processing has terminated;
|
||||||
|
; If the process is in Idle state, then informations are related to the
|
||||||
|
; last request the process has served. Otherwise informations are related to
|
||||||
|
; the current request being served.
|
||||||
|
; Example output:
|
||||||
|
; ************************
|
||||||
|
; pid: 31330
|
||||||
|
; state: Running
|
||||||
|
; start time: 01/Jul/2011:17:53:49 +0200
|
||||||
|
; start since: 63087
|
||||||
|
; requests: 12808
|
||||||
|
; request duration: 1250261
|
||||||
|
; request method: GET
|
||||||
|
; request URI: /test_mem.php?N=10000
|
||||||
|
; content length: 0
|
||||||
|
; user: -
|
||||||
|
; script: /home/fat/web/docs/php/test_mem.php
|
||||||
|
; last request cpu: 0.00
|
||||||
|
; last request memory: 0
|
||||||
|
;
|
||||||
|
; Note: There is a real-time FPM status monitoring sample web page available
|
||||||
|
; It's available in: /usr/share/php7/fpm/status.html
|
||||||
|
;
|
||||||
|
; Note: The value must start with a leading slash (/). The value can be
|
||||||
|
; anything, but it may not be a good idea to use the .php extension or it
|
||||||
|
; may conflict with a real PHP file.
|
||||||
|
; Default Value: not set
|
||||||
|
;pm.status_path = /status
|
||||||
|
|
||||||
|
; The ping URI to call the monitoring page of FPM. If this value is not set, no
|
||||||
|
; URI will be recognized as a ping page. This could be used to test from outside
|
||||||
|
; that FPM is alive and responding, or to
|
||||||
|
; - create a graph of FPM availability (rrd or such);
|
||||||
|
; - remove a server from a group if it is not responding (load balancing);
|
||||||
|
; - trigger alerts for the operating team (24/7).
|
||||||
|
; Note: The value must start with a leading slash (/). The value can be
|
||||||
|
; anything, but it may not be a good idea to use the .php extension or it
|
||||||
|
; may conflict with a real PHP file.
|
||||||
|
; Default Value: not set
|
||||||
|
;ping.path = /ping
|
||||||
|
|
||||||
|
; This directive may be used to customize the response of a ping request. The
|
||||||
|
; response is formatted as text/plain with a 200 response code.
|
||||||
|
; Default Value: pong
|
||||||
|
;ping.response = pong
|
||||||
|
|
||||||
|
; The access log file
|
||||||
|
; Default: not set
|
||||||
|
;access.log = log/php7/$pool.access.log
|
||||||
|
|
||||||
|
; The access log format.
|
||||||
|
; The following syntax is allowed
|
||||||
|
; %%: the '%' character
|
||||||
|
; %C: %CPU used by the request
|
||||||
|
; it can accept the following format:
|
||||||
|
; - %{user}C for user CPU only
|
||||||
|
; - %{system}C for system CPU only
|
||||||
|
; - %{total}C for user + system CPU (default)
|
||||||
|
; %d: time taken to serve the request
|
||||||
|
; it can accept the following format:
|
||||||
|
; - %{seconds}d (default)
|
||||||
|
; - %{miliseconds}d
|
||||||
|
; - %{mili}d
|
||||||
|
; - %{microseconds}d
|
||||||
|
; - %{micro}d
|
||||||
|
; %e: an environment variable (same as $_ENV or $_SERVER)
|
||||||
|
; it must be associated with embraces to specify the name of the env
|
||||||
|
; variable. Some exemples:
|
||||||
|
; - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e
|
||||||
|
; - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e
|
||||||
|
; %f: script filename
|
||||||
|
; %l: content-length of the request (for POST request only)
|
||||||
|
; %m: request method
|
||||||
|
; %M: peak of memory allocated by PHP
|
||||||
|
; it can accept the following format:
|
||||||
|
; - %{bytes}M (default)
|
||||||
|
; - %{kilobytes}M
|
||||||
|
; - %{kilo}M
|
||||||
|
; - %{megabytes}M
|
||||||
|
; - %{mega}M
|
||||||
|
; %n: pool name
|
||||||
|
; %o: output header
|
||||||
|
; it must be associated with embraces to specify the name of the header:
|
||||||
|
; - %{Content-Type}o
|
||||||
|
; - %{X-Powered-By}o
|
||||||
|
; - %{Transfert-Encoding}o
|
||||||
|
; - ....
|
||||||
|
; %p: PID of the child that serviced the request
|
||||||
|
; %P: PID of the parent of the child that serviced the request
|
||||||
|
; %q: the query string
|
||||||
|
; %Q: the '?' character if query string exists
|
||||||
|
; %r: the request URI (without the query string, see %q and %Q)
|
||||||
|
; %R: remote IP address
|
||||||
|
; %s: status (response code)
|
||||||
|
; %t: server time the request was received
|
||||||
|
; it can accept a strftime(3) format:
|
||||||
|
; %d/%b/%Y:%H:%M:%S %z (default)
|
||||||
|
; The strftime(3) format must be encapsuled in a %{<strftime_format>}t tag
|
||||||
|
; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t
|
||||||
|
; %T: time the log has been written (the request has finished)
|
||||||
|
; it can accept a strftime(3) format:
|
||||||
|
; %d/%b/%Y:%H:%M:%S %z (default)
|
||||||
|
; The strftime(3) format must be encapsuled in a %{<strftime_format>}t tag
|
||||||
|
; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t
|
||||||
|
; %u: remote user
|
||||||
|
;
|
||||||
|
; Default: "%R - %u %t \"%m %r\" %s"
|
||||||
|
;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"
|
||||||
|
|
||||||
|
; The log file for slow requests
|
||||||
|
; Default Value: not set
|
||||||
|
; Note: slowlog is mandatory if request_slowlog_timeout is set
|
||||||
|
;slowlog = log/php7/$pool.slow.log
|
||||||
|
|
||||||
|
; The timeout for serving a single request after which a PHP backtrace will be
|
||||||
|
; dumped to the 'slowlog' file. A value of '0s' means 'off'.
|
||||||
|
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
|
||||||
|
; Default Value: 0
|
||||||
|
;request_slowlog_timeout = 0
|
||||||
|
|
||||||
|
; Depth of slow log stack trace.
|
||||||
|
; Default Value: 20
|
||||||
|
;request_slowlog_trace_depth = 20
|
||||||
|
|
||||||
|
; The timeout for serving a single request after which the worker process will
|
||||||
|
; be killed. This option should be used when the 'max_execution_time' ini option
|
||||||
|
; does not stop script execution for some reason. A value of '0' means 'off'.
|
||||||
|
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
|
||||||
|
; Default Value: 0
|
||||||
|
;request_terminate_timeout = 0
|
||||||
|
|
||||||
|
; The timeout set by 'request_terminate_timeout' ini option is not engaged after
|
||||||
|
; application calls 'fastcgi_finish_request' or when application has finished and
|
||||||
|
; shutdown functions are being called (registered via register_shutdown_function).
|
||||||
|
; This option will enable timeout limit to be applied unconditionally
|
||||||
|
; even in such cases.
|
||||||
|
; Default Value: no
|
||||||
|
;request_terminate_timeout_track_finished = no
|
||||||
|
|
||||||
|
; Set open file descriptor rlimit.
|
||||||
|
; Default Value: system defined value
|
||||||
|
;rlimit_files = 1024
|
||||||
|
|
||||||
|
; Set max core size rlimit.
|
||||||
|
; Possible Values: 'unlimited' or an integer greater or equal to 0
|
||||||
|
; Default Value: system defined value
|
||||||
|
;rlimit_core = 0
|
||||||
|
|
||||||
|
; Chroot to this directory at the start. This value must be defined as an
|
||||||
|
; absolute path. When this value is not set, chroot is not used.
|
||||||
|
; Note: you can prefix with '$prefix' to chroot to the pool prefix or one
|
||||||
|
; of its subdirectories. If the pool prefix is not set, the global prefix
|
||||||
|
; will be used instead.
|
||||||
|
; Note: chrooting is a great security feature and should be used whenever
|
||||||
|
; possible. However, all PHP paths will be relative to the chroot
|
||||||
|
; (error_log, sessions.save_path, ...).
|
||||||
|
; Default Value: not set
|
||||||
|
;chroot =
|
||||||
|
|
||||||
|
; Chdir to this directory at the start.
|
||||||
|
; Note: relative path can be used.
|
||||||
|
; Default Value: current directory or / when chroot
|
||||||
|
;chdir = /var/www
|
||||||
|
|
||||||
|
; Redirect worker stdout and stderr into main error log. If not set, stdout and
|
||||||
|
; stderr will be redirected to /dev/null according to FastCGI specs.
|
||||||
|
; Note: on highloaded environement, this can cause some delay in the page
|
||||||
|
; process time (several ms).
|
||||||
|
; Default Value: no
|
||||||
|
;catch_workers_output = yes
|
||||||
|
|
||||||
|
; Decorate worker output with prefix and suffix containing information about
|
||||||
|
; the child that writes to the log and if stdout or stderr is used as well as
|
||||||
|
; log level and time. This options is used only if catch_workers_output is yes.
|
||||||
|
; Settings to "no" will output data as written to the stdout or stderr.
|
||||||
|
; Default value: yes
|
||||||
|
;decorate_workers_output = no
|
||||||
|
|
||||||
|
; Clear environment in FPM workers
|
||||||
|
; Prevents arbitrary environment variables from reaching FPM worker processes
|
||||||
|
; by clearing the environment in workers before env vars specified in this
|
||||||
|
; pool configuration are added.
|
||||||
|
; Setting to "no" will make all environment variables available to PHP code
|
||||||
|
; via getenv(), $_ENV and $_SERVER.
|
||||||
|
; Default Value: yes
|
||||||
|
clear_env = no
|
||||||
|
|
||||||
|
; Limits the extensions of the main script FPM will allow to parse. This can
|
||||||
|
; prevent configuration mistakes on the web server side. You should only limit
|
||||||
|
; FPM to .php extensions to prevent malicious users to use other extensions to
|
||||||
|
; execute php code.
|
||||||
|
; Note: set an empty value to allow all extensions.
|
||||||
|
; Default Value: .php
|
||||||
|
;security.limit_extensions = .php .php3 .php4 .php5 .php7
|
||||||
|
|
||||||
|
; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from
|
||||||
|
; the current environment.
|
||||||
|
; Default Value: clean env
|
||||||
|
;env[HOSTNAME] = $HOSTNAME
|
||||||
|
;env[PATH] = /usr/local/bin:/usr/bin:/bin
|
||||||
|
;env[TMP] = /tmp
|
||||||
|
;env[TMPDIR] = /tmp
|
||||||
|
;env[TEMP] = /tmp
|
||||||
|
|
||||||
|
; Additional php.ini defines, specific to this pool of workers. These settings
|
||||||
|
; overwrite the values previously defined in the php.ini. The directives are the
|
||||||
|
; same as the PHP SAPI:
|
||||||
|
; php_value/php_flag - you can set classic ini defines which can
|
||||||
|
; be overwritten from PHP call 'ini_set'.
|
||||||
|
; php_admin_value/php_admin_flag - these directives won't be overwritten by
|
||||||
|
; PHP call 'ini_set'
|
||||||
|
; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no.
|
||||||
|
|
||||||
|
; Defining 'extension' will load the corresponding shared extension from
|
||||||
|
; extension_dir. Defining 'disable_functions' or 'disable_classes' will not
|
||||||
|
; overwrite previously defined php.ini values, but will append the new value
|
||||||
|
; instead.
|
||||||
|
|
||||||
|
; Note: path INI options can be relative and will be expanded with the prefix
|
||||||
|
; (pool, global or /usr)
|
||||||
|
|
||||||
|
; Default Value: nothing is defined by default except the values in php.ini and
|
||||||
|
; specified at startup with the -d argument
|
||||||
|
;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com
|
||||||
|
;php_flag[display_errors] = off
|
||||||
|
;php_admin_value[error_log] = /var/log/php7/$pool.error.log
|
||||||
|
;php_admin_flag[log_errors] = on
|
||||||
|
;php_admin_value[memory_limit] = 32M
|
||||||
3
docker/conf/etc/services.d/speedtest/run
Normal file
3
docker/conf/etc/services.d/speedtest/run
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/with-contenv bash
|
||||||
|
|
||||||
|
exec s6-setuidgid abc php /config/www/artisan queue:work --timeout=120 >> /config/log/speedtest/queue.log
|
||||||
15432
package-lock.json
generated
15432
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
33
package.json
33
package.json
@@ -10,29 +10,30 @@
|
|||||||
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
|
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/preset-react": "^7.10.4",
|
"@babel/preset-react": "^7.12.13",
|
||||||
"axios": "^0.20",
|
"axios": "^0.21",
|
||||||
"bootstrap": "^4.5.2",
|
"bootstrap": "^4.6.0",
|
||||||
"cross-env": "^7.0",
|
"cross-env": "^7.0",
|
||||||
"jquery": "^3.5",
|
"jquery": "^3.5",
|
||||||
"laravel-mix": "^5.0.5",
|
"laravel-mix": "^5.0.9",
|
||||||
"lodash": "^4.17.20",
|
"lodash": "^4.17.21",
|
||||||
"popper.js": "^1.12",
|
"popper.js": "^1.12",
|
||||||
"react": "^16.2.0",
|
"react": "^17.0.1",
|
||||||
"react-dom": "^16.2.0",
|
"react-dom": "^17.0.1",
|
||||||
"resolve-url-loader": "^3.1.0",
|
"resolve-url-loader": "^3.1.2",
|
||||||
"sass": "^1.26.10",
|
"sass": "^1.32.8",
|
||||||
"sass-loader": "^10.0.2"
|
"sass-loader": "^10.1.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/plugin-proposal-class-properties": "^7.10.4",
|
"@babel/plugin-proposal-class-properties": "^7.13.0",
|
||||||
"chart.js": "^2.9.3",
|
"chart.js": "^2.9.4",
|
||||||
"csv-file-validator": "^1.8.0",
|
"csv-file-validator": "^1.10.1",
|
||||||
"js-cookie": "^2.2.1",
|
"js-cookie": "^2.2.1",
|
||||||
"react-bootstrap": "^1.3.0",
|
"react-beautiful-dnd": "^13.1.0",
|
||||||
"react-chartjs-2": "^2.10.0",
|
"react-bootstrap": "^1.5.1",
|
||||||
|
"react-chartjs-2": "^2.11.1",
|
||||||
"react-router": "^5.2.0",
|
"react-router": "^5.2.0",
|
||||||
"react-router-dom": "^5.2.0",
|
"react-router-dom": "^5.2.0",
|
||||||
"react-toastify": "^6.0.8"
|
"react-toastify": "^7.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
51
phpunit.xml
51
phpunit.xml
@@ -1,29 +1,26 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true">
|
||||||
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
|
<coverage processUncoveredFiles="true">
|
||||||
bootstrap="vendor/autoload.php"
|
<include>
|
||||||
colors="true">
|
<directory suffix=".php">./app</directory>
|
||||||
<testsuites>
|
</include>
|
||||||
<testsuite name="Unit">
|
</coverage>
|
||||||
<directory suffix="Test.php">./tests/Unit</directory>
|
<testsuites>
|
||||||
</testsuite>
|
<testsuite name="Unit">
|
||||||
<testsuite name="Feature">
|
<directory suffix="Test.php">./tests/Unit</directory>
|
||||||
<directory suffix="Test.php">./tests/Feature</directory>
|
</testsuite>
|
||||||
</testsuite>
|
<testsuite name="Feature">
|
||||||
</testsuites>
|
<directory suffix="Test.php">./tests/Feature</directory>
|
||||||
<filter>
|
</testsuite>
|
||||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
</testsuites>
|
||||||
<directory suffix=".php">./app</directory>
|
<php>
|
||||||
</whitelist>
|
<server name="APP_ENV" value="testing"/>
|
||||||
</filter>
|
<server name="BCRYPT_ROUNDS" value="4"/>
|
||||||
<php>
|
<server name="CACHE_DRIVER" value="array"/>
|
||||||
<server name="APP_ENV" value="testing"/>
|
<server name="DB_CONNECTION" value="sqlite"/>
|
||||||
<server name="BCRYPT_ROUNDS" value="4"/>
|
<server name="DB_DATABASE" value=":memory:"/>
|
||||||
<server name="CACHE_DRIVER" value="array"/>
|
<server name="MAIL_MAILER" value="array"/>
|
||||||
<server name="DB_CONNECTION" value="sqlite"/>
|
<server name="QUEUE_CONNECTION" value="sync"/>
|
||||||
<server name="DB_DATABASE" value=":memory:"/>
|
<server name="SESSION_DRIVER" value="array"/>
|
||||||
<server name="MAIL_MAILER" value="array"/>
|
</php>
|
||||||
<server name="QUEUE_CONNECTION" value="sync"/>
|
|
||||||
<server name="SESSION_DRIVER" value="array"/>
|
|
||||||
</php>
|
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|||||||
8
public/css/app.css
vendored
8
public/css/app.css
vendored
File diff suppressed because one or more lines are too long
2
public/js/app.js
vendored
2
public/js/app.js
vendored
File diff suppressed because one or more lines are too long
@@ -6,14 +6,14 @@ object-assign
|
|||||||
|
|
||||||
/* @license
|
/* @license
|
||||||
Papa Parse
|
Papa Parse
|
||||||
v5.2.0
|
v5.3.0
|
||||||
https://github.com/mholt/PapaParse
|
https://github.com/mholt/PapaParse
|
||||||
License: MIT
|
License: MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Bootstrap v4.5.2 (https://getbootstrap.com/)
|
* Bootstrap v4.6.0 (https://getbootstrap.com/)
|
||||||
* Copyright 2011-2020 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
|
* Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
|
||||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -24,9 +24,9 @@ License: MIT
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Chart.js v2.9.3
|
* Chart.js v2.9.4
|
||||||
* https://www.chartjs.org
|
* https://www.chartjs.org
|
||||||
* (c) 2019 Chart.js Contributors
|
* (c) 2020 Chart.js Contributors
|
||||||
* Released under the MIT License
|
* Released under the MIT License
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ License: MIT
|
|||||||
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** @license React v0.19.1
|
/** @license React v0.20.1
|
||||||
* scheduler.production.min.js
|
* scheduler.production.min.js
|
||||||
*
|
*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
@@ -81,15 +81,6 @@ License: MIT
|
|||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** @license React v16.13.1
|
|
||||||
* react-dom.production.min.js
|
|
||||||
*
|
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @license React v16.13.1
|
/** @license React v16.13.1
|
||||||
* react-is.production.min.js
|
* react-is.production.min.js
|
||||||
*
|
*
|
||||||
@@ -99,7 +90,16 @@ License: MIT
|
|||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** @license React v16.13.1
|
/** @license React v17.0.1
|
||||||
|
* react-dom.production.min.js
|
||||||
|
*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @license React v17.0.1
|
||||||
* react.production.min.js
|
* react.production.min.js
|
||||||
*
|
*
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
@@ -132,3 +132,7 @@ License: MIT
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//! moment.js
|
||||||
|
|
||||||
|
//! moment.js locale configuration
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import { Container, Row, Col, Collapse, Button, Modal } from 'react-bootstrap';
|
import { Row, Col} from 'react-bootstrap';
|
||||||
import SessionsTable from './SessionsTable';
|
import SessionsTable from './SessionsTable';
|
||||||
import ResetPassword from './ResetPassword';
|
import ResetPassword from './ResetPassword';
|
||||||
|
|
||||||
@@ -44,34 +44,18 @@ export default class Authentication extends Component {
|
|||||||
|
|
||||||
if( (window.config.auth == true && window.authenticated == true)) {
|
if( (window.config.auth == true && window.authenticated == true)) {
|
||||||
return (
|
return (
|
||||||
<Container className="mb-4">
|
<div>
|
||||||
<Row>
|
<Row>
|
||||||
<Col sm={{ span: 12 }} className="mb-3 text-center">
|
<Col sm={{ span: 12 }} className="text-center">
|
||||||
<div className="mouse" aria-controls="testsTable" onClick={this.toggleCollapse} aria-expanded={showCollapse}>
|
<ResetPassword />
|
||||||
<h4 className="d-inline mr-2">Authentication</h4>
|
|
||||||
{(showCollapse) ?
|
|
||||||
<span className="ti-angle-up"></span>
|
|
||||||
:
|
|
||||||
<span className="ti-angle-down"></span>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
<Collapse in={showCollapse}>
|
<Row>
|
||||||
<div>
|
<Col sm={{ span: 12 }} className="text-center">
|
||||||
<Row>
|
<SessionsTable />
|
||||||
<Col sm={{ span: 12 }} className="text-center">
|
</Col>
|
||||||
<ResetPassword />
|
</Row>
|
||||||
</Col>
|
</div>
|
||||||
</Row>
|
|
||||||
<Row>
|
|
||||||
<Col sm={{ span: 12 }} className="text-center">
|
|
||||||
<SessionsTable />
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
</div>
|
|
||||||
</Collapse>
|
|
||||||
</Container>
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
|
|||||||
393
resources/js/components/Graphics/HistoryGraph.js
vendored
393
resources/js/components/Graphics/HistoryGraph.js
vendored
@@ -11,7 +11,10 @@ export default class HistoryGraph extends Component {
|
|||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
days: 7,
|
days: props.days,
|
||||||
|
time: props.dlUl,
|
||||||
|
fail: props.fail,
|
||||||
|
config: props.config,
|
||||||
duData: {},
|
duData: {},
|
||||||
duOptions: {},
|
duOptions: {},
|
||||||
pingData: {},
|
pingData: {},
|
||||||
@@ -26,229 +29,233 @@ export default class HistoryGraph extends Component {
|
|||||||
graph_failure_width: 6,
|
graph_failure_width: 6,
|
||||||
graph_ping_enabled: true,
|
graph_ping_enabled: true,
|
||||||
graph_ping_width: 6,
|
graph_ping_width: 6,
|
||||||
|
firstUpdate: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount = () => {
|
componentDidMount = () => {
|
||||||
this.getData();
|
}
|
||||||
var int = setInterval(this.getData, 10000);
|
|
||||||
|
componentDidUpdate() {
|
||||||
|
if(
|
||||||
|
this.state.time != this.props.dlUl ||
|
||||||
|
this.state.fail != this.props.fail ||
|
||||||
|
this.state.config != this.props.config ||
|
||||||
|
this.state.days != this.props.days
|
||||||
|
) {
|
||||||
|
this.setState({
|
||||||
|
time: this.props.dlUl,
|
||||||
|
fail: this.props.fail,
|
||||||
|
config: this.props.config,
|
||||||
|
days: this.props.days
|
||||||
|
});
|
||||||
|
|
||||||
|
if(this.state.config !== null) {
|
||||||
|
this.processData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(
|
||||||
|
!this.state.firstUpdate &&
|
||||||
|
this.state.config !== null
|
||||||
|
) {
|
||||||
|
this.processData();
|
||||||
|
this.setState({
|
||||||
|
firstUpdate: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
processData() {
|
||||||
|
this.processConfig();
|
||||||
|
this.processDlUlPing();
|
||||||
|
this.processFailure();
|
||||||
|
}
|
||||||
|
|
||||||
|
processConfig() {
|
||||||
this.setState({
|
this.setState({
|
||||||
interval: int,
|
graph_ul_dl_enabled: Boolean(Number(this.state.config.graphs.download_upload_graph_enabled.value)),
|
||||||
|
graph_ul_dl_width: this.state.config.graphs.download_upload_graph_width.value,
|
||||||
|
graph_ping_enabled: Boolean(Number(this.state.config.graphs.ping_graph_enabled.value)),
|
||||||
|
graph_ping_width: this.state.config.graphs.ping_graph_width.value,
|
||||||
|
graph_failure_enabled: Boolean(Number(this.state.config.graphs.failure_graph_enabled.value)),
|
||||||
|
graph_failure_width: this.state.config.graphs.failure_graph_width.value,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getDLULPing = (days) => {
|
processDlUlPing() {
|
||||||
var url = 'api/speedtest/time/' + days;
|
let days = this.state.days;
|
||||||
|
|
||||||
Axios.get(url)
|
var duData = {
|
||||||
.then((resp) => {
|
labels: [],
|
||||||
var duData = {
|
datasets:[
|
||||||
labels: [],
|
{
|
||||||
datasets:[
|
data: [],
|
||||||
{
|
label: 'Download',
|
||||||
data: [],
|
borderColor: "#fca503",
|
||||||
label: 'Download',
|
fill: false,
|
||||||
borderColor: "#fca503",
|
|
||||||
fill: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: [],
|
|
||||||
label: 'Upload',
|
|
||||||
borderColor: "#3e95cd",
|
|
||||||
fill: false,
|
|
||||||
}
|
|
||||||
],
|
|
||||||
};
|
|
||||||
var duOptions = {
|
|
||||||
maintainAspectRatio: false,
|
|
||||||
responsive: true,
|
|
||||||
tooltips: {
|
|
||||||
callbacks: {
|
|
||||||
label: (item) => `${item.yLabel} Mbit/s`,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
title: {
|
{
|
||||||
display: false,
|
data: [],
|
||||||
text: 'Speedtests results for the last ' + days + ' days',
|
label: 'Upload',
|
||||||
},
|
borderColor: "#3e95cd",
|
||||||
scales: {
|
fill: false,
|
||||||
xAxes: [{
|
|
||||||
display: false,
|
|
||||||
scaleLabel: {
|
|
||||||
display: true,
|
|
||||||
labelString: 'DateTime'
|
|
||||||
}
|
|
||||||
}],
|
|
||||||
},
|
|
||||||
elements: {
|
|
||||||
point:{
|
|
||||||
radius: 0,
|
|
||||||
hitRadius: 8
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
],
|
||||||
|
};
|
||||||
var pingData = {
|
var duOptions = {
|
||||||
labels: [],
|
maintainAspectRatio: false,
|
||||||
datasets:[
|
responsive: true,
|
||||||
{
|
tooltips: {
|
||||||
data: [],
|
callbacks: {
|
||||||
label: 'Ping',
|
label: (item) => `${item.yLabel} Mbit/s`,
|
||||||
borderColor: "#07db71",
|
|
||||||
fill: false,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
var pingOptions = {
|
|
||||||
maintainAspectRatio: false,
|
|
||||||
responsive: true,
|
|
||||||
tooltips: {
|
|
||||||
callbacks: {
|
|
||||||
label: (item) => `${item.yLabel} ms`,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
title: {
|
},
|
||||||
|
title: {
|
||||||
|
display: false,
|
||||||
|
text: 'Speedtests results for the last ' + days + ' days',
|
||||||
|
},
|
||||||
|
scales: {
|
||||||
|
xAxes: [{
|
||||||
display: false,
|
display: false,
|
||||||
text: 'Ping results for the last ' + days + ' days',
|
scaleLabel: {
|
||||||
},
|
display: true,
|
||||||
scales: {
|
labelString: 'DateTime'
|
||||||
xAxes: [{
|
|
||||||
display: false,
|
|
||||||
scaleLabel: {
|
|
||||||
display: true,
|
|
||||||
labelString: 'DateTime'
|
|
||||||
}
|
|
||||||
}],
|
|
||||||
},
|
|
||||||
elements: {
|
|
||||||
point:{
|
|
||||||
radius: 0,
|
|
||||||
hitRadius: 8
|
|
||||||
}
|
}
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
elements: {
|
||||||
|
point:{
|
||||||
|
radius: 0,
|
||||||
|
hitRadius: 8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
resp.data.data.forEach(e => {
|
var pingData = {
|
||||||
var download = {
|
labels: [],
|
||||||
t: new Date(e.created_at),
|
datasets:[
|
||||||
y: e.download,
|
{
|
||||||
};
|
data: [],
|
||||||
var upload = {
|
label: 'Ping',
|
||||||
t: new Date(e.created_at),
|
borderColor: "#07db71",
|
||||||
y: e.upload,
|
fill: false,
|
||||||
};
|
|
||||||
var ping = {
|
|
||||||
t: new Date(e.created_at),
|
|
||||||
y: parseFloat(e.ping)
|
|
||||||
}
|
|
||||||
duData.datasets[0].data.push(download);
|
|
||||||
duData.datasets[1].data.push(upload);
|
|
||||||
pingData.datasets[0].data.push(ping);
|
|
||||||
duData.labels.push(new Date(e.created_at).toLocaleString());
|
|
||||||
pingData.labels.push(new Date(e.created_at).toLocaleString());
|
|
||||||
});
|
|
||||||
|
|
||||||
this.setState({
|
|
||||||
duData: duData,
|
|
||||||
duOptions: duOptions,
|
|
||||||
pingData: pingData,
|
|
||||||
pingOptions: pingOptions,
|
|
||||||
loading: false,
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
getFailure = (days) => {
|
|
||||||
var url = 'api/speedtest/fail/' + days;
|
|
||||||
Axios.get(url)
|
|
||||||
.then((resp) => {
|
|
||||||
var failData = {
|
|
||||||
labels: [],
|
|
||||||
datasets: [
|
|
||||||
{
|
|
||||||
data: [],
|
|
||||||
label: 'Successful',
|
|
||||||
backgroundColor: '#07db71'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
data: [],
|
|
||||||
label: 'Failed',
|
|
||||||
backgroundColor: '#E74C3C'
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
var failOptions = {
|
|
||||||
maintainAspectRatio: false,
|
|
||||||
responsive: true,
|
|
||||||
tooltips: {
|
|
||||||
callbacks: {
|
|
||||||
label: (item) => `${item.yLabel} speedtests`,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
scales: {
|
],
|
||||||
xAxes: [{
|
};
|
||||||
stacked: true
|
var pingOptions = {
|
||||||
}],
|
maintainAspectRatio: false,
|
||||||
yAxes: [{
|
responsive: true,
|
||||||
stacked: true
|
tooltips: {
|
||||||
}]
|
callbacks: {
|
||||||
|
label: (item) => `${item.yLabel} ms`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
display: false,
|
||||||
|
text: 'Ping results for the last ' + days + ' days',
|
||||||
|
},
|
||||||
|
scales: {
|
||||||
|
xAxes: [{
|
||||||
|
display: false,
|
||||||
|
scaleLabel: {
|
||||||
|
display: true,
|
||||||
|
labelString: 'DateTime'
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
elements: {
|
||||||
|
point:{
|
||||||
|
radius: 0,
|
||||||
|
hitRadius: 8
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.state.time.forEach(e => {
|
||||||
|
var download = {
|
||||||
|
t: new Date(e.created_at),
|
||||||
|
y: e.download,
|
||||||
};
|
};
|
||||||
|
var upload = {
|
||||||
|
t: new Date(e.created_at),
|
||||||
|
y: e.upload,
|
||||||
|
};
|
||||||
|
var ping = {
|
||||||
|
t: new Date(e.created_at),
|
||||||
|
y: parseFloat(e.ping)
|
||||||
|
}
|
||||||
|
duData.datasets[0].data.push(download);
|
||||||
|
duData.datasets[1].data.push(upload);
|
||||||
|
pingData.datasets[0].data.push(ping);
|
||||||
|
duData.labels.push(new Date(e.created_at).toLocaleString());
|
||||||
|
pingData.labels.push(new Date(e.created_at).toLocaleString());
|
||||||
|
});
|
||||||
|
|
||||||
resp.data.data.forEach(e => {
|
this.setState({
|
||||||
var success = {x: e.date, y: e.success};
|
duData: duData,
|
||||||
var fail = {x: e.date, y: e.failure};
|
duOptions: duOptions,
|
||||||
failData.datasets[0].data.push(success);
|
pingData: pingData,
|
||||||
failData.datasets[1].data.push(fail);
|
pingOptions: pingOptions,
|
||||||
failData.labels.push(new Date(e.date).toLocaleString([], {year: '2-digit', month:'2-digit', day:'2-digit'}));
|
loading: false,
|
||||||
})
|
});
|
||||||
|
|
||||||
this.setState({
|
|
||||||
failData: failData,
|
|
||||||
failOptions: failOptions
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err);
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getData = (days = this.state.days) => {
|
processFailure() {
|
||||||
Axios.get('api/settings/config')
|
let days = this.state.days;
|
||||||
.then((resp) => {
|
|
||||||
var data = resp.data.graphs;
|
|
||||||
this.setState({
|
|
||||||
graph_ul_dl_enabled: Boolean(Number(data.download_upload_graph_enabled.value)),
|
|
||||||
graph_ul_dl_width: data.download_upload_graph_width.value,
|
|
||||||
graph_ping_enabled: Boolean(Number(data.ping_graph_enabled.value)),
|
|
||||||
graph_ping_width: data.ping_graph_width.value,
|
|
||||||
graph_failure_enabled: Boolean(Number(data.failure_graph_enabled.value)),
|
|
||||||
graph_failure_width: data.failure_graph_width.value,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.getDLULPing(days);
|
var failData = {
|
||||||
this.getFailure(days);
|
labels: [],
|
||||||
})
|
datasets: [
|
||||||
.catch((err) => {
|
{
|
||||||
console.log('Couldn\'t get the site config');
|
data: [],
|
||||||
console.log(err);
|
label: 'Successful',
|
||||||
|
backgroundColor: '#07db71'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: [],
|
||||||
|
label: 'Failed',
|
||||||
|
backgroundColor: '#E74C3C'
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
var failOptions = {
|
||||||
|
maintainAspectRatio: false,
|
||||||
|
responsive: true,
|
||||||
|
tooltips: {
|
||||||
|
callbacks: {
|
||||||
|
label: (item) => `${item.yLabel} speedtests`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
scales: {
|
||||||
|
xAxes: [{
|
||||||
|
stacked: true
|
||||||
|
}],
|
||||||
|
yAxes: [{
|
||||||
|
stacked: true
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.state.fail.forEach(e => {
|
||||||
|
var success = {x: e.date, y: e.success};
|
||||||
|
var fail = {x: e.date, y: e.failure};
|
||||||
|
failData.datasets[0].data.push(success);
|
||||||
|
failData.datasets[1].data.push(fail);
|
||||||
|
failData.labels.push(new Date(e.date).toLocaleString([], {year: '2-digit', month:'2-digit', day:'2-digit'}));
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
failData: failData,
|
||||||
|
failOptions: failOptions
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
updateDays = (e) => {
|
updateDays = (e) => {
|
||||||
var days = e.target.value;
|
var days = e.target.value;
|
||||||
if(days) {
|
if(days) {
|
||||||
this.getData(days);
|
|
||||||
clearInterval(this.state.int);
|
|
||||||
var int = setInterval(this.getData, 10000);
|
|
||||||
toast.info('Showing results for the last ' + days + ' days');
|
toast.info('Showing results for the last ' + days + ' days');
|
||||||
this.setState({
|
this.props.updateDays(days);
|
||||||
days: days,
|
|
||||||
interval: int
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,36 +12,23 @@ export default class LatestResults extends Component {
|
|||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
data: {},
|
data: props.data,
|
||||||
interval: null,
|
interval: null,
|
||||||
loading: true,
|
loading: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount = () => {
|
componentDidUpdate() {
|
||||||
this.getData();
|
if(this.state.data !== this.props.data) {
|
||||||
var int = setInterval(this.getData, 10000);
|
this.setState({
|
||||||
this.setState({
|
data: this.props.data,
|
||||||
interval: int,
|
loading: false,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getData = () => {
|
componentWillUnmount() {
|
||||||
var url = 'api/speedtest/latest';
|
clearInterval(this.state.interval);
|
||||||
|
|
||||||
Axios.get(url)
|
|
||||||
.then((resp) => {
|
|
||||||
this.setState({
|
|
||||||
data: resp.data,
|
|
||||||
loading: false
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
this.setState({
|
|
||||||
data: false
|
|
||||||
});
|
|
||||||
console.log(err);
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
newScan = () => {
|
newScan = () => {
|
||||||
|
|||||||
98
resources/js/components/Graphics/TableRow.js
vendored
98
resources/js/components/Graphics/TableRow.js
vendored
@@ -28,7 +28,7 @@ export default class TableRow extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
delete = (id) => {
|
delete = (id) => {
|
||||||
var url = 'api/speedtest/delete/' + id;
|
var url = 'api/speedtest/delete/' + id + '?token=' + window.token;
|
||||||
|
|
||||||
Axios.delete(url)
|
Axios.delete(url)
|
||||||
.then((resp) => {
|
.then((resp) => {
|
||||||
@@ -43,21 +43,66 @@ export default class TableRow extends Component {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.props.refresh();
|
||||||
this.toggleShow();
|
this.toggleShow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getDataFields = () => {
|
||||||
|
let allFields = this.props.allFields;
|
||||||
|
let data = this.state.data;
|
||||||
|
let processedFields = [];
|
||||||
|
|
||||||
|
for(var key in allFields) {
|
||||||
|
let field = allFields[key];
|
||||||
|
|
||||||
|
let value = data[key];
|
||||||
|
|
||||||
|
if(field.type === 'date') {
|
||||||
|
value = new Date(value).toLocaleString();
|
||||||
|
} else if(field.type === 'bool') {
|
||||||
|
value = Boolean(value) ? field.if_true : field.if_false
|
||||||
|
}
|
||||||
|
|
||||||
|
let final = {
|
||||||
|
name: key,
|
||||||
|
key: field.alias,
|
||||||
|
value: value,
|
||||||
|
type: field.type
|
||||||
|
};
|
||||||
|
|
||||||
|
processedFields.push(final);
|
||||||
|
}
|
||||||
|
|
||||||
|
let visible = [];
|
||||||
|
let inModal = [];
|
||||||
|
|
||||||
|
window.config.tables.visible_columns.forEach(column => {
|
||||||
|
visible.push(processedFields.find(x => x.name == column));
|
||||||
|
});
|
||||||
|
|
||||||
|
inModal = processedFields.filter(el => {
|
||||||
|
return !visible.includes(el);
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
visible: visible,
|
||||||
|
modal: inModal
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
var e = this.state.data;
|
var e = this.state.data;
|
||||||
var show = this.state.show;
|
var show = this.state.show;
|
||||||
|
var fields = this.getDataFields();
|
||||||
|
|
||||||
if(e.failed != true) {
|
if(e.failed != true) {
|
||||||
return (
|
return (
|
||||||
<tr>
|
<tr>
|
||||||
<td>{e.id}</td>
|
{fields.visible.map((e, i) => {
|
||||||
<td>{new Date(e.created_at).toLocaleString()}</td>
|
return (
|
||||||
<td>{e.download}</td>
|
<td key={i}>{e.value}</td>
|
||||||
<td>{e.upload}</td>
|
);
|
||||||
<td>{e.ping}</td>
|
})}
|
||||||
{e.server_host != null ?
|
{e.server_host != null ?
|
||||||
<td>
|
<td>
|
||||||
<span onClick={this.toggleShow} className="ti-arrow-top-right mouse"></span>
|
<span onClick={this.toggleShow} className="ti-arrow-top-right mouse"></span>
|
||||||
@@ -66,13 +111,17 @@ export default class TableRow extends Component {
|
|||||||
<Modal.Title>More info</Modal.Title>
|
<Modal.Title>More info</Modal.Title>
|
||||||
</Modal.Header>
|
</Modal.Header>
|
||||||
<Modal.Body className="text-center">
|
<Modal.Body className="text-center">
|
||||||
<p>Server ID: {e.server_id}</p>
|
{fields.modal.map((e, i) => {
|
||||||
<p>Name: {e.server_name}</p>
|
if(e.type === 'url') {
|
||||||
<p>Host: {e.server_host}</p>
|
return (
|
||||||
<p>URL: <a href={e.url} target="_blank" rel="noopener noreferer">Speedtest.net</a></p>
|
<p key={i}>{e.key}: <a href={e.value} target="_blank" rel="noopener noreferer">Speedtest.net</a></p>
|
||||||
{e.scheduled != undefined &&
|
);
|
||||||
<p>Type: {e.scheduled == true ? 'scheduled' : 'manual'}</p>
|
} else {
|
||||||
}
|
return (
|
||||||
|
<p key={i}>{e.key}: {e.value}</p>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})}
|
||||||
<Button variant="danger" onClick={() => { this.delete(e.id) }}>Delete</Button>
|
<Button variant="danger" onClick={() => { this.delete(e.id) }}>Delete</Button>
|
||||||
</Modal.Body>
|
</Modal.Body>
|
||||||
</Modal>
|
</Modal>
|
||||||
@@ -85,12 +134,23 @@ export default class TableRow extends Component {
|
|||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<tr>
|
<tr>
|
||||||
<td>{e.id}</td>
|
{fields.visible.map((e, i) => {
|
||||||
<td>{new Date(e.created_at).toLocaleString()}</td>
|
console.log(e);
|
||||||
<td><span className="ti-close text-danger"></span></td>
|
if(e.name === 'created_at') {
|
||||||
<td><span className="ti-close text-danger"></span></td>
|
return <td key={i}>{new Date(e.value).toLocaleString()}</td>
|
||||||
<td><span className="ti-close text-danger"></span></td>
|
} else if (e.name === 'id') {
|
||||||
<td></td>
|
return <td key={i}>{e.value}</td>
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<td key={i}><span className="ti-close text-danger"></span></td>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
{(window.config.auth && window.authenticated) || !window.config.auth ?
|
||||||
|
<td><Button variant="danger" onClick={() => { this.delete(e.id) }}>Delete</Button></td>
|
||||||
|
:
|
||||||
|
<td></td>
|
||||||
|
}
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
132
resources/js/components/Graphics/TestsTable.js
vendored
132
resources/js/components/Graphics/TestsTable.js
vendored
@@ -14,7 +14,51 @@ export default class TestsTable extends Component {
|
|||||||
data: [],
|
data: [],
|
||||||
showTable: false,
|
showTable: false,
|
||||||
refresh: true,
|
refresh: true,
|
||||||
interval: null
|
interval: null,
|
||||||
|
allFields: {
|
||||||
|
id: {
|
||||||
|
type: 'int',
|
||||||
|
alias: 'ID'
|
||||||
|
},
|
||||||
|
created_at: {
|
||||||
|
type: 'date',
|
||||||
|
alias: 'Time'
|
||||||
|
},
|
||||||
|
download: {
|
||||||
|
type: 'float',
|
||||||
|
alias: 'Download (Mbit/s)'
|
||||||
|
},
|
||||||
|
upload: {
|
||||||
|
type: 'float',
|
||||||
|
alias: 'Upload (Mbit/s)'
|
||||||
|
},
|
||||||
|
ping: {
|
||||||
|
type: 'float',
|
||||||
|
alias: 'Ping (ms)'
|
||||||
|
},
|
||||||
|
server_id: {
|
||||||
|
type: 'int',
|
||||||
|
alias: 'Server ID'
|
||||||
|
},
|
||||||
|
server_name: {
|
||||||
|
type: 'string',
|
||||||
|
alias: 'Name'
|
||||||
|
},
|
||||||
|
server_host: {
|
||||||
|
type: 'string',
|
||||||
|
alias: 'Host'
|
||||||
|
},
|
||||||
|
url: {
|
||||||
|
type: 'url',
|
||||||
|
alias: 'URL'
|
||||||
|
},
|
||||||
|
scheduled: {
|
||||||
|
type: 'bool',
|
||||||
|
alias: 'Type',
|
||||||
|
if_true: 'scheduled',
|
||||||
|
if_false: 'manual'
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,6 +70,10 @@ export default class TestsTable extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
clearInterval(this.state.interval);
|
||||||
|
}
|
||||||
|
|
||||||
getData = (page = this.state.page, refresh = true) => {
|
getData = (page = this.state.page, refresh = true) => {
|
||||||
var url = 'api/speedtest/?page=' + page;
|
var url = 'api/speedtest/?page=' + page;
|
||||||
|
|
||||||
@@ -80,62 +128,52 @@ export default class TestsTable extends Component {
|
|||||||
var data = this.state.data;
|
var data = this.state.data;
|
||||||
var show = this.state.showTable;
|
var show = this.state.showTable;
|
||||||
var refresh = this.state.refresh;
|
var refresh = this.state.refresh;
|
||||||
|
let allFields = this.state.allFields;
|
||||||
|
|
||||||
if(data.length > 0) {
|
if(data.length > 0) {
|
||||||
return (
|
return (
|
||||||
<Container className="mb-4 mt-4" fluid>
|
<div>
|
||||||
<Row>
|
<Container className="mb-4 mt-4 px-5">
|
||||||
<Col sm={{ span: 12 }} className="mb-3 text-center">
|
<Row>
|
||||||
<div className="mouse" aria-controls="testsTable" onClick={this.toggleCollapse} aria-expanded={show}>
|
<Col sm={{ span: 12 }} className="mb-3 text-center">
|
||||||
<h4 className="d-inline mr-2">All tests</h4>
|
<div>
|
||||||
{(show) ?
|
<h4 className="d-inline mr-2">All tests</h4>
|
||||||
<span className="ti-angle-up"></span>
|
|
||||||
:
|
|
||||||
<span className="ti-angle-down"></span>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
{(show) &&
|
|
||||||
<div className="my-1">
|
|
||||||
<span className="text-muted">Auto refresh: {(refresh) ? 'On' : 'Off'}</span>
|
<span className="text-muted">Auto refresh: {(refresh) ? 'On' : 'Off'}</span>
|
||||||
</div>
|
</div>
|
||||||
}
|
</Col>
|
||||||
</Col>
|
</Row>
|
||||||
</Row>
|
<Row>
|
||||||
<Collapse in={show}>
|
<Col sm={{ span: 12 }} id="testsTable">
|
||||||
<div>
|
<Table responsive>
|
||||||
<Row>
|
<thead>
|
||||||
<Col sm={{ span: 12 }} id="testsTable">
|
<tr>
|
||||||
<Table responsive>
|
{window.config.tables.visible_columns.map((e, i) => {
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>ID</th>
|
|
||||||
<th>Time</th>
|
|
||||||
<th>Download (Mbit/s)</th>
|
|
||||||
<th>Upload (Mbit/s)</th>
|
|
||||||
<th>Ping (ms)</th>
|
|
||||||
<th>More</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{data.map((e,i) => {
|
|
||||||
return (
|
return (
|
||||||
<TableRow key={e.id} data={e} />
|
<th key={i}>{allFields[e].alias}</th>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</tbody>
|
<th>More</th>
|
||||||
</Table>
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{data.map((e,i) => {
|
||||||
|
return (
|
||||||
|
<TableRow key={e.id} data={e} allFields={allFields} refresh={this.getData} />
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</tbody>
|
||||||
|
</Table>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
{page < lastPage &&
|
||||||
|
<Row>
|
||||||
|
<Col sm={{ span: 12 }} className="text-center">
|
||||||
|
<Button variant="primary" onClick={this.getMoreData}>Show more</Button>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
{page < lastPage &&
|
}
|
||||||
<Row>
|
</Container>
|
||||||
<Col sm={{ span: 12 }} className="text-center">
|
</div>
|
||||||
<Button variant="primary" onClick={this.getMoreData}>Show more</Button>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</Collapse>
|
|
||||||
</Container>
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
|
|||||||
6
resources/js/components/Graphics/Widget.js
vendored
6
resources/js/components/Graphics/Widget.js
vendored
@@ -30,7 +30,7 @@ export default class Widget extends Component {
|
|||||||
returnData.max = parseFloat(data.maximum.ping).toFixed(1);
|
returnData.max = parseFloat(data.maximum.ping).toFixed(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(window.config.widgets.show_max) {
|
if(window.config.widgets.show_min) {
|
||||||
returnData.min = parseFloat(data.minimum.ping).toFixed(1);
|
returnData.min = parseFloat(data.minimum.ping).toFixed(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,7 +46,7 @@ export default class Widget extends Component {
|
|||||||
returnData.max = parseFloat(data.maximum.upload).toFixed(1);
|
returnData.max = parseFloat(data.maximum.upload).toFixed(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(window.config.widgets.show_max) {
|
if(window.config.widgets.show_min) {
|
||||||
returnData.min = parseFloat(data.minimum.upload).toFixed(1);
|
returnData.min = parseFloat(data.minimum.upload).toFixed(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,7 @@ export default class Widget extends Component {
|
|||||||
returnData.max = parseFloat(data.maximum.download).toFixed(1);
|
returnData.max = parseFloat(data.maximum.download).toFixed(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(window.config.widgets.show_max) {
|
if(window.config.widgets.show_min) {
|
||||||
returnData.min = parseFloat(data.minimum.download).toFixed(1);
|
returnData.min = parseFloat(data.minimum.download).toFixed(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
62
resources/js/components/Home/HomePage.js
vendored
62
resources/js/components/Home/HomePage.js
vendored
@@ -5,25 +5,73 @@ import LatestResults from '../Graphics/LatestResults';
|
|||||||
import Footer from './Footer';
|
import Footer from './Footer';
|
||||||
import DataRow from '../Data/DataRow';
|
import DataRow from '../Data/DataRow';
|
||||||
import TestsTable from '../Graphics/TestsTable';
|
import TestsTable from '../Graphics/TestsTable';
|
||||||
import Settings from '../Settings/Settings';
|
|
||||||
import Login from '../Login';
|
import Login from '../Login';
|
||||||
import Authentication from '../Authentication/Authentication';
|
import Authentication from '../Authentication/Authentication';
|
||||||
|
import Navbar from '../Navbar';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
export default class HomePage extends Component {
|
export default class HomePage extends Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props)
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
latest: null,
|
||||||
|
time: null,
|
||||||
|
fail: null,
|
||||||
|
config: null,
|
||||||
|
days: 7,
|
||||||
|
interval: null,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount = () => {
|
||||||
|
this.getData();
|
||||||
|
var interval = setInterval(this.getData, 10000);
|
||||||
|
this.setState({
|
||||||
|
interval: interval,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
clearInterval(this.state.interval);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateDays = (days) => {
|
||||||
|
this.setState({ days: days });
|
||||||
|
this.setState({ days: days }, () => { this.getData() });
|
||||||
|
}
|
||||||
|
|
||||||
|
getData = () => {
|
||||||
|
axios.get('api/speedtest/home/' + this.state.days)
|
||||||
|
.then((resp) => {
|
||||||
|
this.setState({
|
||||||
|
latest: resp.data.latest,
|
||||||
|
time: resp.data.time,
|
||||||
|
fail: resp.data.fail,
|
||||||
|
config: resp.data.config
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
let latest = this.state.latest;
|
||||||
|
let time = this.state.time;
|
||||||
|
let fail = this.state.fail;
|
||||||
|
let config = this.state.config;
|
||||||
|
let days = this.state.days;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
<Navbar />
|
||||||
<div className="my-4">
|
<div className="my-4">
|
||||||
{(window.config.auth == true && window.authenticated == false) &&
|
{(window.config.auth == true && window.authenticated == false) &&
|
||||||
<Login />
|
<Login />
|
||||||
}
|
}
|
||||||
<LatestResults />
|
<LatestResults data={latest} />
|
||||||
<HistoryGraph />
|
<HistoryGraph updateDays={this.updateDays} dlUl={time} fail={fail} config={config} days={days} />
|
||||||
<TestsTable />
|
|
||||||
<Settings />
|
|
||||||
<Authentication />
|
|
||||||
<DataRow />
|
|
||||||
</div>
|
</div>
|
||||||
<Footer />
|
<Footer />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
3
resources/js/components/Login.js
vendored
3
resources/js/components/Login.js
vendored
@@ -39,6 +39,9 @@ export default class Login extends Component {
|
|||||||
Cookies.set('auth', token, { expires: expires })
|
Cookies.set('auth', token, { expires: expires })
|
||||||
window.location.reload(true);
|
window.location.reload(true);
|
||||||
})
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
toast.error('Something went wrong logging in.');
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleShow = () => {
|
toggleShow = () => {
|
||||||
|
|||||||
64
resources/js/components/Navbar.js
vendored
64
resources/js/components/Navbar.js
vendored
@@ -1,19 +1,77 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
|
import {Nav, Navbar as BootstrapNavbar, NavLink as BootstrapNavLink} from 'react-bootstrap';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
|
import { Link, NavLink } from 'react-router-dom';
|
||||||
|
|
||||||
export default class Navbar extends Component {
|
export default class Navbar extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
|
brand: {
|
||||||
|
name: window.config.name,
|
||||||
|
url: window.config.base
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
generatePagesArray() {
|
||||||
|
var pages = [
|
||||||
|
{
|
||||||
|
name: 'Home',
|
||||||
|
url: window.config.base,
|
||||||
|
authRequired: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'All Tests',
|
||||||
|
url: window.config.base + 'speedtests',
|
||||||
|
authRequired: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Settings',
|
||||||
|
url: window.config.base + 'settings',
|
||||||
|
authRequired: true
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
return pages;
|
||||||
|
}
|
||||||
|
|
||||||
|
generateLinks = () => {
|
||||||
|
var pages = this.generatePagesArray();
|
||||||
|
|
||||||
|
return pages.map(page => {
|
||||||
|
if(
|
||||||
|
page.authRequired === false ||
|
||||||
|
(
|
||||||
|
page.authRequired === true &&
|
||||||
|
window.config.auth &&
|
||||||
|
window.authenticated
|
||||||
|
) ||
|
||||||
|
(
|
||||||
|
page.authRequired === true &&
|
||||||
|
window.config.auth === false
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return <BootstrapNavLink key={page.url} as={NavLink} to={page.url}>{page.name}</BootstrapNavLink>;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
var brand = this.state.brand;
|
||||||
|
var pages = this.generateLinks();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<BootstrapNavbar variant="dark" bg="dark" expand="sm">
|
||||||
</div>
|
<BootstrapNavbar.Brand as={Link} to={brand.url}><img style={{width: '15%'}} src={window.config.base + 'files/icons/fav/android-icon-192x192.png'} /> {brand.name}</BootstrapNavbar.Brand>
|
||||||
|
<BootstrapNavbar.Toggle aria-controls="basic-navbar-nav" />
|
||||||
|
<BootstrapNavbar.Collapse id="basic-navbar-nav">
|
||||||
|
<Nav className="ml-auto">
|
||||||
|
{pages}
|
||||||
|
</Nav>
|
||||||
|
</BootstrapNavbar.Collapse>
|
||||||
|
</BootstrapNavbar>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user