mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2025-12-25 06:49:15 +01:00
Compare commits
304 Commits
v1.7.15
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f6bb77ce71 | ||
|
|
2ed811e949 | ||
|
|
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 | ||
|
|
4b95cb12ef | ||
|
|
8ff87c2e7a | ||
|
|
149c69ce64 | ||
|
|
933291c5fc | ||
|
|
29c36d88e2 | ||
|
|
4b167af50e | ||
|
|
7d0ea79798 | ||
|
|
375eab288d | ||
|
|
8e2ddd974a | ||
|
|
d78c3e2669 | ||
|
|
a83d4e363b | ||
|
|
334623454d | ||
|
|
a7aa3e7885 | ||
|
|
2e1022c116 | ||
|
|
355d38acb7 | ||
|
|
1e9887ac46 | ||
|
|
8538dd231f | ||
|
|
5793140e89 | ||
|
|
56ecff1a09 | ||
|
|
eff8f92016 | ||
|
|
0b8c633a75 | ||
|
|
8ae4bc602c | ||
|
|
9028ffb7cd | ||
|
|
62fde8fb2a | ||
|
|
601d46915c | ||
|
|
751acff32c | ||
|
|
4e133e97c7 | ||
|
|
61a85ced34 | ||
|
|
aa37a50f57 | ||
|
|
99ac0b008c | ||
|
|
b4147ce57a | ||
|
|
80b80811aa | ||
|
|
2d8bc7d71f | ||
|
|
a036ed7c8f | ||
|
|
01b097b4d3 | ||
|
|
a6326f6d98 | ||
|
|
ef34238043 | ||
|
|
212c7a99bf | ||
|
|
8e556250aa | ||
|
|
87fc35c1c5 | ||
|
|
b6fca4e1a7 | ||
|
|
ae40f503e2 | ||
|
|
61da652b82 | ||
|
|
ec56337b99 | ||
|
|
0ed4674c3f | ||
|
|
dd56a667cd | ||
|
|
3dc494b02e | ||
|
|
35a1de7333 | ||
|
|
f6de728265 | ||
|
|
d6da8962eb | ||
|
|
db12f8cfee | ||
|
|
9b8c764b0d | ||
|
|
7999867f50 | ||
|
|
1fcdd5bb1d | ||
|
|
900ecb2218 | ||
|
|
7da1d3d760 | ||
|
|
0eff685277 | ||
|
|
94e4919b44 | ||
|
|
1e4604d975 | ||
|
|
b30ec477f4 | ||
|
|
13a00d43bf | ||
|
|
2d779e50b0 | ||
|
|
322ef98608 | ||
|
|
cc2e4ae91d | ||
|
|
7ab788e61d | ||
|
|
da34c723a3 | ||
|
|
e7c3dcd369 | ||
|
|
0d80c198af | ||
|
|
41f4e9667f | ||
|
|
f93c801f27 | ||
|
|
30657a07e8 | ||
|
|
6e712cbbdc | ||
|
|
375ecf650c | ||
|
|
a15d633322 | ||
|
|
ef485b2909 | ||
|
|
79a85fdba9 | ||
|
|
a49979daae | ||
|
|
053138093c | ||
|
|
e10b4dccde | ||
|
|
2fbfe6f48e | ||
|
|
f3043baa5a | ||
|
|
c1f44fe733 | ||
|
|
cd87a902a7 | ||
|
|
71101f71eb | ||
|
|
5a56b80322 | ||
|
|
4173321ce5 | ||
|
|
de8884b550 | ||
|
|
4bc002ef6c | ||
|
|
ed50a05415 | ||
|
|
603c306107 | ||
|
|
49a0f9087e | ||
|
|
640a62eed7 | ||
|
|
dc2ee05344 | ||
|
|
30ead5e82a | ||
|
|
532837621f | ||
|
|
ad60f19a53 | ||
|
|
92544142a9 | ||
|
|
08926d19ab | ||
|
|
2a9f9e7c55 | ||
|
|
a73e058ab1 | ||
|
|
1a8f4d3139 | ||
|
|
f32fcf8256 | ||
|
|
6ab2ae9e53 | ||
|
|
33169be746 | ||
|
|
7dccdb3c1f | ||
|
|
f0cd810f43 | ||
|
|
5aee6dae70 | ||
|
|
c4a26624e6 | ||
|
|
372086bc8e | ||
|
|
b8a3a0e72e | ||
|
|
1a688ebe69 | ||
|
|
3102e9e7ab | ||
|
|
97bf5bc4af | ||
|
|
2a4f70c70e | ||
|
|
2d805e3936 | ||
|
|
6cccefa21f | ||
|
|
f0e2d28d8b | ||
|
|
8a8c608bd0 | ||
|
|
c8fdb13f45 | ||
|
|
0e1b69f96f | ||
|
|
f5b14cdf99 | ||
|
|
05bed7b831 | ||
|
|
2526f9596b | ||
|
|
e2967ac1dd | ||
|
|
7a62b113bf | ||
|
|
4b8b4ccfa3 | ||
|
|
9f6fcb7439 | ||
|
|
33bbe14100 | ||
|
|
2541a371fb | ||
|
|
f38e60346a | ||
|
|
f8c46dc047 | ||
|
|
7e3bc8724f | ||
|
|
4617213073 |
79
.github/dependabot.yml
vendored
Normal file
79
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: composer
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: daily
|
||||
open-pull-requests-limit: 10
|
||||
target-branch: dev
|
||||
ignore:
|
||||
- dependency-name: laravel/framework
|
||||
versions:
|
||||
- 7.30.3
|
||||
- 8.36.2
|
||||
- 8.37.0
|
||||
- 8.38.0
|
||||
- dependency-name: doctrine/dbal
|
||||
versions:
|
||||
- 2.13.0
|
||||
- 3.0.0
|
||||
- dependency-name: phpunit/phpunit
|
||||
versions:
|
||||
- 9.5.1
|
||||
- 9.5.3
|
||||
- dependency-name: facade/ignition
|
||||
versions:
|
||||
- 2.5.10
|
||||
- 2.5.11
|
||||
- 2.5.12
|
||||
- 2.5.13
|
||||
- 2.5.9
|
||||
- dependency-name: laravel/tinker
|
||||
versions:
|
||||
- 2.6.0
|
||||
- dependency-name: nunomaduro/collision
|
||||
versions:
|
||||
- 5.3.0
|
||||
- dependency-name: nunomaduro/larastan
|
||||
versions:
|
||||
- 0.6.13
|
||||
- package-ecosystem: npm
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: daily
|
||||
open-pull-requests-limit: 10
|
||||
target-branch: dev
|
||||
ignore:
|
||||
- dependency-name: chart.js
|
||||
versions:
|
||||
- 3.1.0
|
||||
- 3.1.1
|
||||
- dependency-name: laravel-mix
|
||||
versions:
|
||||
- 6.0.16
|
||||
- dependency-name: y18n
|
||||
versions:
|
||||
- 4.0.1
|
||||
- 4.0.2
|
||||
- dependency-name: react-dom
|
||||
versions:
|
||||
- 17.0.2
|
||||
- dependency-name: react
|
||||
versions:
|
||||
- 17.0.2
|
||||
- dependency-name: react-bootstrap
|
||||
versions:
|
||||
- 1.4.3
|
||||
- 1.5.0
|
||||
- dependency-name: sass
|
||||
versions:
|
||||
- 1.32.5
|
||||
- 1.32.6
|
||||
- 1.32.7
|
||||
- dependency-name: "@babel/plugin-proposal-class-properties"
|
||||
versions:
|
||||
- 7.12.13
|
||||
- dependency-name: react-toastify
|
||||
versions:
|
||||
- 7.0.1
|
||||
- 7.0.2
|
||||
14
.github/workflows/laravel-dev.yml
vendored
14
.github/workflows/laravel-dev.yml
vendored
@@ -10,9 +10,23 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: shivammathur/setup-php@b7d1d9c9a92d8d8463ce36d7f60da34d461724f8
|
||||
with:
|
||||
php-version: '7.4'
|
||||
- uses: actions/checkout@v2
|
||||
- name: Copy .env
|
||||
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
|
||||
- name: Update .env with secrets
|
||||
env:
|
||||
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
|
||||
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
|
||||
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
|
||||
HEALTHCHECKS_UUID: ${{ secrets.HEALTHCHECKS_UUID }}
|
||||
run: |
|
||||
echo SLACK_WEBHOOK=$SLACK_WEBHOOK >> .env
|
||||
echo TELEGRAM_BOT_TOKEN=$TELEGRAM_BOT_TOKEN >> .env
|
||||
echo TELEGRAM_CHAT_ID=$TELEGRAM_CHAT_ID >> .env
|
||||
echo HEALTHCHECKS_UUID=$HEALTHCHECKS_UUID >> .env
|
||||
- name: Install Dependencies
|
||||
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
|
||||
- name: Create Database
|
||||
|
||||
14
.github/workflows/laravel-pr.yml
vendored
14
.github/workflows/laravel-pr.yml
vendored
@@ -10,9 +10,23 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: shivammathur/setup-php@b7d1d9c9a92d8d8463ce36d7f60da34d461724f8
|
||||
with:
|
||||
php-version: '7.4'
|
||||
- uses: actions/checkout@v2
|
||||
- name: Copy .env
|
||||
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
|
||||
- name: Update .env with secrets
|
||||
env:
|
||||
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
|
||||
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
|
||||
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
|
||||
HEALTHCHECKS_UUID: ${{ secrets.HEALTHCHECKS_UUID }}
|
||||
run: |
|
||||
echo SLACK_WEBHOOK=$SLACK_WEBHOOK >> .env
|
||||
echo TELEGRAM_BOT_TOKEN=$TELEGRAM_BOT_TOKEN >> .env
|
||||
echo TELEGRAM_CHAT_ID=$TELEGRAM_CHAT_ID >> .env
|
||||
echo HEALTHCHECKS_UUID=$HEALTHCHECKS_UUID >> .env
|
||||
- name: Install Dependencies
|
||||
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
|
||||
- name: Create Database
|
||||
|
||||
14
.github/workflows/laravel-stable.yml
vendored
14
.github/workflows/laravel-stable.yml
vendored
@@ -10,9 +10,23 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: shivammathur/setup-php@b7d1d9c9a92d8d8463ce36d7f60da34d461724f8
|
||||
with:
|
||||
php-version: '7.4'
|
||||
- uses: actions/checkout@v2
|
||||
- name: Copy .env
|
||||
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
|
||||
- name: Update .env with secrets
|
||||
env:
|
||||
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
|
||||
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
|
||||
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
|
||||
HEALTHCHECKS_UUID: ${{ secrets.HEALTHCHECKS_UUID }}
|
||||
run: |
|
||||
echo SLACK_WEBHOOK=$SLACK_WEBHOOK >> .env
|
||||
echo TELEGRAM_BOT_TOKEN=$TELEGRAM_BOT_TOKEN >> .env
|
||||
echo TELEGRAM_CHAT_ID=$TELEGRAM_CHAT_ID >> .env
|
||||
echo HEALTHCHECKS_UUID=$HEALTHCHECKS_UUID >> .env
|
||||
- name: Install Dependencies
|
||||
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
|
||||
- name: Create Database
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -16,3 +16,4 @@ yarn-error.log
|
||||
_ide_helper.php
|
||||
.idea
|
||||
.config
|
||||
reports/
|
||||
|
||||
21
README.md
21
README.md
@@ -1,9 +1,11 @@
|
||||
# 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.
|
||||
|
||||
A demo can be found [here](https://speedtest.henrywhitaker.com)
|
||||
|
||||
Disclaimer: You will need to accept Ookla's EULA and privacy agreements in order to use this container.
|
||||
|
||||

|
||||
@@ -14,6 +16,7 @@ Disclaimer: You will need to accept Ookla's EULA and privacy agreements in order
|
||||
- Graph of previous speedtests going back x days
|
||||
- Backup/restore data in JSON/CSV format
|
||||
- Slack/Discord/Telegram notifications
|
||||
- [healthchecks.io](https://healthchecks.io) integration
|
||||
- Organizr integration
|
||||
|
||||
## Installation & Setup
|
||||
@@ -80,7 +83,21 @@ Container images are configured using parameters passed at runtime (such as thos
|
||||
| `-e TELEGRAM_CHAT_ID` | Optional. Telegram chat ID. |
|
||||
| `-e PUID` | Optional. Supply a local user 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 |
|
||||
|
||||
### Authentication
|
||||
|
||||
Authentication is optional. When enabled, unauthenticated users will only be able to see the graphs and tests table. To be able to queue a new speedtest, backup/restore data and update instance settings you will need to log in. To enable authentication, pass the `AUTH=true` environment variable in docker or run `php artisan speedtest:auth --enable` for manual installs (same command with `--disable` to turn it off).
|
||||
|
||||
The default credentials are:
|
||||
|
||||
| Field | Function |
|
||||
| --- | --- |
|
||||
| username | admin@admin.com |
|
||||
| password | password |
|
||||
|
||||
After enabling, you should change the password through the web UI.
|
||||
|
||||
### 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).
|
||||
|
||||
@@ -34,7 +34,7 @@ class AcceptEULACommand extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
59
app/Console/Commands/AuthenticationCommand.php
Normal file
59
app/Console/Commands/AuthenticationCommand.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class AuthenticationCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'speedtest:auth {--enable} {--disable}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Toggle authentication for the app';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$opts = $this->options();
|
||||
|
||||
if($opts['enable'] === true && $opts['disable'] === true) {
|
||||
$this->warn('Please specify only ONE of --enable and --disable');
|
||||
} else if($opts['enable'] === false && $opts['disable'] === false) {
|
||||
$this->warn('You need to specify either --enable OR --disable');
|
||||
} else {
|
||||
if($opts['enable'] === true) {
|
||||
$this->info('Enabling authentication');
|
||||
SettingsHelper::set('auth', true);
|
||||
}
|
||||
|
||||
if($opts['disable'] === true) {
|
||||
$this->info('Disabling authentication');
|
||||
SettingsHelper::set('auth', false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
48
app/Console/Commands/ClearOldSessionsCommand.php
Normal file
48
app/Console/Commands/ClearOldSessionsCommand.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Auth\LoginSession;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use Log;
|
||||
|
||||
class ClearOldSessionsCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'speedtest:clear-sessions';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Clear expired sessions from database';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$now = Carbon::now()->timestamp;
|
||||
$sessions = LoginSession::where('expires', '<=', $now)
|
||||
->delete();
|
||||
$this->info('Invalidated expired sessions');
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ class ClearQueueCommand extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
@@ -34,7 +34,7 @@ class GetConfig extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
@@ -34,7 +34,7 @@ class SetSlackWebhook extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
@@ -36,7 +36,7 @@ class SetTelegramOptions extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
@@ -34,7 +34,7 @@ class SpeedtestCommand extends Command
|
||||
/**
|
||||
* Runs a speedtest synchroonously and displays the results..
|
||||
*
|
||||
* @return null
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
@@ -35,7 +35,7 @@ class SpeedtestLatestCommand extends Command
|
||||
/**
|
||||
* Prints the latest speedtest values.
|
||||
*
|
||||
* @return null
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
@@ -33,7 +33,7 @@ class SpeedtestVersionCommand extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
@@ -34,7 +34,7 @@ class TestNotification extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
@@ -28,8 +28,11 @@ class Kernel extends ConsoleKernel
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
$schedule->job(new SpeedtestJob)->cron(SettingsHelper::get('schedule')['value']);
|
||||
if ((bool)SettingsHelper::get('schedule_enabled')->value) {
|
||||
$schedule->job(new SpeedtestJob(true, config('integrations')))->cron(SettingsHelper::get('schedule')['value']);
|
||||
}
|
||||
$schedule->command('speedtest:overview')->cron('0 ' . SettingsHelper::get('speedtest_overview_time')->value . ' * * *');
|
||||
$schedule->command('speedtest:clear-sessions')->everyMinute();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,7 +42,7 @@ class Kernel extends ConsoleKernel
|
||||
*/
|
||||
protected function commands()
|
||||
{
|
||||
$this->load(__DIR__.'/Commands');
|
||||
$this->load(__DIR__ . '/Commands');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ class SpeedtestCompleteEvent
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $speedtest;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
|
||||
13
app/Facades/HealthchecksFacade.php
Normal file
13
app/Facades/HealthchecksFacade.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
class HealthchecksFacade extends Facade
|
||||
{
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return 'healthcheck';
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Helpers;
|
||||
|
||||
use App\Speedtest;
|
||||
use Cache;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -26,13 +27,13 @@ class BackupHelper {
|
||||
case 'csv':
|
||||
$data = Speedtest::get();
|
||||
|
||||
$csv = Storage::disk('local')->getDriver()->getAdapter()->getPathPrefix() . $name . '.csv';
|
||||
$csv = storage_path() . '/app/' . $name . '.csv';
|
||||
$name = $name . '.csv';
|
||||
$handle = fopen($csv, 'w+');
|
||||
fputcsv($handle, array('id', 'ping', 'download', 'upload', 'created_at', 'updated_at'));
|
||||
fputcsv($handle, array('id', 'ping', 'download', 'upload', 'server_id', 'server_name', 'server_host', 'url', 'scheduled', 'failed', 'created_at', 'updated_at'));
|
||||
|
||||
foreach($data as $d) {
|
||||
fputcsv($handle, array($d->id, $d->ping, $d->download, $d->upload, $d->created_at, $d->updated_at));
|
||||
fputcsv($handle, BackupHelper::createCSVBackupArray($d));
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
@@ -55,29 +56,32 @@ class BackupHelper {
|
||||
*
|
||||
* @param array|string $array Backup data
|
||||
* @param string $format json|csv
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public static function restore($array, $format)
|
||||
{
|
||||
Cache::flush();
|
||||
if($format == 'json') {
|
||||
foreach($array as $test) {
|
||||
try {
|
||||
$st = Speedtest::create([
|
||||
'ping' => $test['ping'],
|
||||
'download' => $test['download'],
|
||||
'upload' => $test['upload'],
|
||||
'created_at' => $test['created_at'],
|
||||
]);
|
||||
$data = BackupHelper::backupJSONToArray($test);
|
||||
|
||||
if($data === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Speedtest::create($data);
|
||||
} catch(Exception $e) {
|
||||
Log::error($e);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else if($format == 'csv') {
|
||||
$csv = explode(PHP_EOL, $array);
|
||||
$headers = 'id,ping,download,upload,created_at,updated_at';
|
||||
if($csv[0] != $headers) {
|
||||
Log::error('Incorrect CSV format');
|
||||
|
||||
$headers = BackupHelper::validateCSV($csv[0]);
|
||||
if($headers === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -85,14 +89,14 @@ class BackupHelper {
|
||||
$csv = array_values($csv);
|
||||
|
||||
for($i = 0; $i < sizeof($csv); $i++) {
|
||||
$e = explode(',', $csv[$i]);
|
||||
$data = BackupHelper::backupCSVToArray($csv[$i]);
|
||||
|
||||
if($data === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$st = Speedtest::create([
|
||||
'ping' => $e[1],
|
||||
'download' => $e[2],
|
||||
'upload' => $e[3],
|
||||
'created_at' => substr($e[4], 1, -1),
|
||||
]);
|
||||
Speedtest::create($data);
|
||||
} catch(Exception $e) {
|
||||
Log::error($e);
|
||||
continue;
|
||||
@@ -101,5 +105,182 @@ class BackupHelper {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a CSV file passed for restore
|
||||
*
|
||||
* @param String $csv The line containing the CSV headers
|
||||
* @return bool|string
|
||||
*/
|
||||
public static function validateCSV(String $csv)
|
||||
{
|
||||
$headers = [
|
||||
'old' => 'id,ping,download,upload,created_at,updated_at',
|
||||
'new' => 'id,ping,download,upload,server_id,server_name,server_host,url,scheduled,failed,created_at,updated_at',
|
||||
];
|
||||
$backupHeaders = null;
|
||||
|
||||
foreach($headers as $key => $h) {
|
||||
if($csv == $h) {
|
||||
$backupHeaders = $key;
|
||||
}
|
||||
}
|
||||
|
||||
if($backupHeaders === null) {
|
||||
Log::info('Incorrect CSV format');
|
||||
return false;
|
||||
}
|
||||
|
||||
return $backupHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array from the raw CSV data
|
||||
*
|
||||
* @param String $line The line of CSV data
|
||||
* @param String $header The type of backup header
|
||||
* @return array|bool
|
||||
*/
|
||||
public static function backupCSVToArray(String $line, String $header = 'new')
|
||||
{
|
||||
$basic = explode(',', $line);
|
||||
|
||||
if($header == 'old') {
|
||||
$array = [
|
||||
'ping' => $basic[1],
|
||||
'download' => $basic[2],
|
||||
'upload' => $basic[3],
|
||||
'created_at' => substr($basic[4], 1, -1),
|
||||
];
|
||||
}
|
||||
|
||||
if($header == 'new') {
|
||||
$array = [
|
||||
'ping' => $basic[1],
|
||||
'download' => $basic[2],
|
||||
'upload' => $basic[3],
|
||||
'server_id' => $basic[4],
|
||||
'server_name' => $basic[5],
|
||||
'server_host' => $basic[6],
|
||||
'url' => $basic[7],
|
||||
'scheduled' => $basic[8],
|
||||
'failed' => $basic[9],
|
||||
'created_at' => substr($basic[10], 1, -1),
|
||||
];
|
||||
}
|
||||
|
||||
if(!isset($array)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return BackupHelper::cleanRestoreDataArray($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean an array, setting values with '' to null
|
||||
*
|
||||
* @param array $array
|
||||
* @return array
|
||||
*/
|
||||
public static function cleanRestoreDataArray(array $array)
|
||||
{
|
||||
foreach($array as $key => $val) {
|
||||
if($val === '') {
|
||||
$array[$key] = null;
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array from the JSON data
|
||||
*
|
||||
* @param array $json json_decoded data
|
||||
* @return array|bool
|
||||
*/
|
||||
public static function backupJSONToArray($json)
|
||||
{
|
||||
$required = [
|
||||
'ping',
|
||||
'upload',
|
||||
'download',
|
||||
'created_at',
|
||||
];
|
||||
|
||||
$extras = [
|
||||
'server_id',
|
||||
'server_name',
|
||||
'server_host',
|
||||
'url',
|
||||
'failed',
|
||||
'scheduled'
|
||||
];
|
||||
|
||||
$array = [];
|
||||
|
||||
foreach($required as $req) {
|
||||
if(!array_key_exists($req, $json)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$val = $json[$req];
|
||||
|
||||
if($val === '') {
|
||||
$val = null;
|
||||
}
|
||||
|
||||
$array[$req] = $val;
|
||||
}
|
||||
|
||||
foreach($extras as $extra) {
|
||||
if(array_key_exists($extra, $json)) {
|
||||
$val = $json[$extra];
|
||||
|
||||
if($val === '') {
|
||||
$val = null;
|
||||
}
|
||||
$array[$extra] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array to store in CSV
|
||||
*
|
||||
* @param Speedtest $test
|
||||
* @return array
|
||||
*/
|
||||
public static function createCSVBackupArray(Speedtest $test)
|
||||
{
|
||||
$data = [
|
||||
$test->id,
|
||||
$test->ping,
|
||||
$test->download,
|
||||
$test->upload,
|
||||
$test->server_id,
|
||||
$test->server_name,
|
||||
$test->server_host,
|
||||
$test->url,
|
||||
$test->scheduled,
|
||||
$test->failed,
|
||||
$test->created_at,
|
||||
$test->updated_at
|
||||
];
|
||||
|
||||
foreach($data as $key => $val) {
|
||||
if(strpos($val, ',') !== false) {
|
||||
$val = str_replace(',', ' -', $val);
|
||||
}
|
||||
|
||||
$data[$key] = $val;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
67
app/Helpers/NotificationsHelper.php
Normal file
67
app/Helpers/NotificationsHelper.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
class NotificationsHelper {
|
||||
|
||||
/**
|
||||
* Parse $errors and format message
|
||||
*
|
||||
* @param array $errors
|
||||
* @return String
|
||||
*/
|
||||
public static function formatPercentageThresholdMessage(array $errors)
|
||||
{
|
||||
$msg = NotificationsHelper::thresholdMessageStart($errors);
|
||||
|
||||
$msg = $msg . 'exceeded the percentage threshold';
|
||||
|
||||
return $msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse $errors and format message
|
||||
*
|
||||
* @param array $errors
|
||||
* @return String
|
||||
*/
|
||||
public static function formatAbsoluteThresholdMessage(array $errors)
|
||||
{
|
||||
$msg = NotificationsHelper::thresholdMessageStart($errors);
|
||||
|
||||
$msg = $msg . 'exceeded the absolute threshold';
|
||||
|
||||
return $msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate through errors to format message
|
||||
*
|
||||
* @param array $errors
|
||||
* @return String
|
||||
*/
|
||||
public static function thresholdMessageStart(array $errors)
|
||||
{
|
||||
$msg = 'For the latest speedtest, the ';
|
||||
|
||||
for($i = 0; $i < sizeof($errors); $i++) {
|
||||
$key = $errors[$i];
|
||||
$msg = $msg . $key;
|
||||
if(sizeof($errors) > 1 && $i < (sizeof($errors) - 1)) {
|
||||
$msg = $msg . ', ';
|
||||
}
|
||||
}
|
||||
|
||||
if($msg[-1] != '') {
|
||||
$msg = $msg . ' ';
|
||||
}
|
||||
|
||||
if(sizeof($errors) > 1) {
|
||||
$msg = $msg . 'values ';
|
||||
} else {
|
||||
$msg = $msg . 'value ';
|
||||
}
|
||||
|
||||
return $msg;
|
||||
}
|
||||
}
|
||||
@@ -4,23 +4,25 @@ namespace App\Helpers;
|
||||
|
||||
use App\Events\TestNotificationEvent;
|
||||
use App\Setting;
|
||||
use Cache;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class SettingsHelper {
|
||||
class SettingsHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* Get a Setting object by name
|
||||
*
|
||||
* @param String $name The name field in the setting table
|
||||
* @return \App\Setting|boolean $name The Setting object. Returns false if no mathcing obj.
|
||||
* @return \App\Setting|bool|array $name The Setting object. Returns false if no mathcing obj.
|
||||
*/
|
||||
public static function get(String $name)
|
||||
{
|
||||
$name = Setting::where('name', $name)->get();
|
||||
|
||||
if(sizeof($name) == 0) {
|
||||
if (sizeof($name) == 0) {
|
||||
return false;
|
||||
} else if(sizeof($name) == 1) {
|
||||
} else if (sizeof($name) == 1) {
|
||||
return $name[0];
|
||||
} else {
|
||||
$name = $name->keyBy('name');
|
||||
@@ -32,18 +34,18 @@ class SettingsHelper {
|
||||
* Create / update value for Setting object.
|
||||
*
|
||||
* @param String $name Name of setting
|
||||
* @param String $value Value of setting
|
||||
* @param String|bool $value Value of setting
|
||||
* @return \App\Setting
|
||||
*/
|
||||
public static function set(String $name, $value)
|
||||
{
|
||||
$setting = SettingsHelper::get($name);
|
||||
|
||||
if($value === false) {
|
||||
if ($value === false) {
|
||||
$value = "0";
|
||||
}
|
||||
|
||||
if($setting !== false) {
|
||||
if ($setting !== false) {
|
||||
$setting->value = $value;
|
||||
$setting->save();
|
||||
} else {
|
||||
@@ -53,6 +55,10 @@ class SettingsHelper {
|
||||
]);
|
||||
}
|
||||
|
||||
if ($name == 'show_failed_tests_on_graph') {
|
||||
Cache::flush();
|
||||
}
|
||||
|
||||
return $setting;
|
||||
}
|
||||
|
||||
@@ -64,13 +70,13 @@ class SettingsHelper {
|
||||
public static function getBase()
|
||||
{
|
||||
$base = env('BASE_PATH', '/');
|
||||
if($base == '') {
|
||||
if ($base == '') {
|
||||
$base = '/';
|
||||
} else {
|
||||
if($base[0] != '/') {
|
||||
if ($base[0] != '/') {
|
||||
$base = '/' . $base;
|
||||
}
|
||||
if($base[-1] != '/') {
|
||||
if ($base[-1] != '/') {
|
||||
$base = $base . '/';
|
||||
}
|
||||
}
|
||||
@@ -85,12 +91,17 @@ class SettingsHelper {
|
||||
*/
|
||||
public static function settingIsEditable(string $key)
|
||||
{
|
||||
// Manual override for app_name
|
||||
if ($key === 'app_name') {
|
||||
return true;
|
||||
}
|
||||
|
||||
$results = [];
|
||||
|
||||
// Try exact key
|
||||
$val = exec('echo $' . $key);
|
||||
|
||||
if($val == "") {
|
||||
if ($val == "") {
|
||||
array_push($results, true);
|
||||
} else {
|
||||
array_push($results, false);
|
||||
@@ -99,25 +110,25 @@ class SettingsHelper {
|
||||
// Try key all caps
|
||||
$val = exec('echo $' . strtoupper($key));
|
||||
|
||||
if($val == "") {
|
||||
if ($val == "") {
|
||||
array_push($results, true);
|
||||
} else {
|
||||
array_push($results, false);
|
||||
}
|
||||
|
||||
if(env($key, false) == false) {
|
||||
if (env($key, false) == false) {
|
||||
array_push($results, true);
|
||||
} else {
|
||||
array_push($results, false);
|
||||
}
|
||||
|
||||
if(env(strtoupper($key), false) == false) {
|
||||
if (env(strtoupper($key), false) == false) {
|
||||
array_push($results, true);
|
||||
} else {
|
||||
array_push($results, false);
|
||||
}
|
||||
|
||||
if(in_array(false, $results)) {
|
||||
if (in_array(false, $results)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -133,6 +144,12 @@ class SettingsHelper {
|
||||
{
|
||||
return [
|
||||
'base' => SettingsHelper::getBase(),
|
||||
'name' => SettingsHelper::get('app_name')->value,
|
||||
'widgets' => [
|
||||
'show_average' => (bool)SettingsHelper::get('show_average')->value,
|
||||
'show_max' => (bool)SettingsHelper::get('show_max')->value,
|
||||
'show_min' => (bool)SettingsHelper::get('show_min')->value,
|
||||
],
|
||||
'graphs' => [
|
||||
'download_upload_graph_enabled' => SettingsHelper::get('download_upload_graph_enabled'),
|
||||
'download_upload_graph_width' => SettingsHelper::get('download_upload_graph_width'),
|
||||
@@ -145,7 +162,8 @@ class SettingsHelper {
|
||||
'slack_webhook' => SettingsHelper::settingIsEditable('slack_webhook'),
|
||||
'telegram_bot_token' => SettingsHelper::settingIsEditable('telegram_bot_token'),
|
||||
'telegram_chat_id' => SettingsHelper::settingIsEditable('telegram_chat_id'),
|
||||
]
|
||||
],
|
||||
'auth' => (bool)SettingsHelper::get('auth')->value
|
||||
];
|
||||
}
|
||||
|
||||
@@ -153,20 +171,43 @@ class SettingsHelper {
|
||||
* Send test notification to agents
|
||||
*
|
||||
* @param boolean|string $agent
|
||||
* @return void
|
||||
* @return bool
|
||||
*/
|
||||
public static function testNotification($agent = true)
|
||||
{
|
||||
$agents = [ 'slack', 'telegram' ];
|
||||
$agents = ['slack', 'telegram'];
|
||||
|
||||
if($agent === true) {
|
||||
if ($agent === true) {
|
||||
event(new TestNotificationEvent($agents));
|
||||
return true;
|
||||
}
|
||||
|
||||
if(in_array($agent, $agents)) {
|
||||
event(new TestNotificationEvent([ $agent ]));
|
||||
if (in_array($agent, $agents)) {
|
||||
event(new TestNotificationEvent([$agent]));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function loadIntegrationConfig()
|
||||
{
|
||||
$settings = [
|
||||
'healthchecks_enabled' => (bool)SettingsHelper::get('healthchecks_enabled')->value,
|
||||
'healthchecks_uuid' => SettingsHelper::get('healthchecks_uuid')->value,
|
||||
'slack_webhook' => SettingsHelper::get('slack_webhook')->value,
|
||||
'telegram_bot_token' => SettingsHelper::get('telegram_bot_token')->value,
|
||||
'telegram_chat_id' => SettingsHelper::get('telegram_chat_id')->value,
|
||||
];
|
||||
|
||||
foreach ($settings as $key => $value) {
|
||||
$key = 'integrations.' . $key;
|
||||
|
||||
if ($value === "") {
|
||||
$value = null;
|
||||
}
|
||||
|
||||
config()->set([$key => $value]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,12 @@ namespace App\Helpers;
|
||||
use App\Speedtest;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Henrywhitaker3\Healthchecks\Healthchecks;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use InvalidArgumentException;
|
||||
use JsonException;
|
||||
|
||||
class SpeedtestHelper {
|
||||
@@ -17,7 +19,7 @@ class SpeedtestHelper {
|
||||
* Runs/processes speedtest output to created a Speedtest object
|
||||
*
|
||||
* @param boolean|string $output If false, new speedtest runs. If anything else, will try to parse as JSON for speedtest results.
|
||||
* @return \App\Speedtest|boolean
|
||||
* @return \App\Speedtest|bool
|
||||
*/
|
||||
public static function runSpeedtest($output = false, $scheduled = true)
|
||||
{
|
||||
@@ -51,7 +53,7 @@ class SpeedtestHelper {
|
||||
$test = false;
|
||||
}
|
||||
|
||||
if(!$test) {
|
||||
if($test == false) {
|
||||
Speedtest::create([
|
||||
'ping' => 0,
|
||||
'upload' => 0,
|
||||
@@ -59,9 +61,7 @@ class SpeedtestHelper {
|
||||
'failed' => true,
|
||||
'scheduled' => $scheduled,
|
||||
]);
|
||||
}
|
||||
|
||||
if(!isset($test) || $test == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -142,14 +142,14 @@ class SpeedtestHelper {
|
||||
/**
|
||||
* Parses network speeds and return converted to Mbps
|
||||
*
|
||||
* @param array $input
|
||||
* @param string $input
|
||||
* @return array
|
||||
*/
|
||||
public static function parseUnits($input)
|
||||
{
|
||||
$input = explode(' ', $input);
|
||||
|
||||
$val = $input[0];
|
||||
$val = (float)$input[0];
|
||||
$unit = explode('/', $input[1])[0];
|
||||
|
||||
switch($unit) {
|
||||
@@ -228,7 +228,7 @@ class SpeedtestHelper {
|
||||
$range = [
|
||||
Carbon::today()
|
||||
];
|
||||
for($i = 0; $i < $days; $i++) {
|
||||
for($i = 0; $i < ($days - 1); $i++) {
|
||||
$prev = end($range);
|
||||
$new = $prev->copy()->subDays(1);
|
||||
array_push($range, $new);
|
||||
@@ -256,15 +256,19 @@ class SpeedtestHelper {
|
||||
/**
|
||||
* Create a backup of the SQLite database
|
||||
*
|
||||
* @return boolean
|
||||
* @return null|boolean
|
||||
*/
|
||||
public static function dbBackup()
|
||||
{
|
||||
if(env('DB_CONNECTION') === 'sqlite') {
|
||||
if(env('DB_DATABASE') !== null) {
|
||||
$current = env('DB_DATABASE');
|
||||
if(File::copy($current, $current . '.bak')) {
|
||||
return true;
|
||||
try {
|
||||
if(File::copy($current, $current . '.bak')) {
|
||||
return true;
|
||||
}
|
||||
}catch(Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,30 +281,97 @@ class SpeedtestHelper {
|
||||
/**
|
||||
* Delete all speedtests from the database
|
||||
*
|
||||
* @return boolean|string
|
||||
* @return array
|
||||
*/
|
||||
public static function deleteAll()
|
||||
{
|
||||
Cache::flush();
|
||||
|
||||
if(SpeedtestHelper::dbBackup() !== false) {
|
||||
if(sizeof(Speedtest::whereNotNull('id')->get()) > 0) {
|
||||
if(Speedtest::whereNotNull('id')->delete()) {
|
||||
return [
|
||||
'success' => true,
|
||||
];
|
||||
}
|
||||
SpeedtestHelper::dbBackup();
|
||||
|
||||
if(sizeof(Speedtest::whereNotNull('id')->get()) > 0) {
|
||||
if(Speedtest::whereNotNull('id')->delete()) {
|
||||
return [
|
||||
'success' => true,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => false,
|
||||
'msg' => 'There was an error backing up the database. No speedtests have been deleted.'
|
||||
'success' => true,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Work out if a test is lower than the threshold for historic tests
|
||||
*
|
||||
* @param String $type
|
||||
* @param Speedtest $test
|
||||
* @return array
|
||||
*/
|
||||
public static function testIsLowerThanThreshold(String $type, Speedtest $test)
|
||||
{
|
||||
if($type == 'percentage') {
|
||||
$avg = Speedtest::select(DB::raw('AVG(ping) as ping, AVG(download) as download, AVG(upload) as upload'))
|
||||
->where('failed', false)
|
||||
->get()
|
||||
->toArray()[0];
|
||||
|
||||
$threshold = SettingsHelper::get('threshold_alert_percentage')->value;
|
||||
|
||||
if($threshold == '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
$errors = [];
|
||||
|
||||
foreach($avg as $key => $value) {
|
||||
if($key == 'ping') {
|
||||
$threshold = (float)$value * (1 + ( $threshold / 100 ));
|
||||
|
||||
if($test->$key > $threshold) {
|
||||
array_push($errors, $key);
|
||||
}
|
||||
} else {
|
||||
$threshold = (float)$value * (1 - ( $threshold / 100 ));
|
||||
|
||||
if($test->$key < $threshold) {
|
||||
array_push($errors, $key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
if($type == 'absolute') {
|
||||
$thresholds = [
|
||||
'download' => SettingsHelper::get('threshold_alert_absolute_download')->value,
|
||||
'upload' => SettingsHelper::get('threshold_alert_absolute_upload')->value,
|
||||
'ping' => SettingsHelper::get('threshold_alert_absolute_ping')->value,
|
||||
];
|
||||
|
||||
$errors = [];
|
||||
|
||||
foreach($thresholds as $key => $value) {
|
||||
if($value == '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if($key == 'ping') {
|
||||
if($test->$key > $value) {
|
||||
array_push($errors, $key);
|
||||
}
|
||||
} else {
|
||||
if($test->$key < $value) {
|
||||
array_push($errors, $key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,38 +13,52 @@ class UpdateHelper {
|
||||
/**
|
||||
* URL of updates
|
||||
*
|
||||
* @var string
|
||||
* @var string|bool
|
||||
*/
|
||||
public $url;
|
||||
|
||||
/**
|
||||
* Current app version number
|
||||
*
|
||||
* @var string
|
||||
* @var string|bool
|
||||
*/
|
||||
public $currentVersion;
|
||||
|
||||
/**
|
||||
* Latest app version number
|
||||
*
|
||||
* @var string|bool
|
||||
*/
|
||||
public $latestVersion;
|
||||
|
||||
/**
|
||||
* Username of GitHub repo
|
||||
*
|
||||
* @var string
|
||||
* @var string|bool
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Name of GitHub repo
|
||||
*
|
||||
* @var string
|
||||
* @var string|bool
|
||||
*/
|
||||
public $repo;
|
||||
|
||||
/**
|
||||
* Branch of GitHub repo
|
||||
*
|
||||
* @var string
|
||||
* @var string|bool
|
||||
*/
|
||||
public $branch;
|
||||
|
||||
/**
|
||||
* Store download
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $download;
|
||||
|
||||
function __construct() {
|
||||
$this->currentVersion = config('speedtest.version');
|
||||
$this->user = config('speedtest.user');
|
||||
@@ -87,7 +101,7 @@ class UpdateHelper {
|
||||
/**
|
||||
* Gets the latest version number from GitHub
|
||||
*
|
||||
* @return array [ repo, branch, version ]
|
||||
* @return array|bool [ repo, branch, version ]
|
||||
*/
|
||||
public function checkLatestVersion()
|
||||
{
|
||||
@@ -256,7 +270,6 @@ class UpdateHelper {
|
||||
$zip->open($backupZip, ZipArchive::CREATE | ZipArchive::OVERWRITE);
|
||||
|
||||
// Create recursive directory iterator
|
||||
/** @var SplFileInfo[] $files */
|
||||
$files = new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($rootPath),
|
||||
RecursiveIteratorIterator::LEAVES_ONLY
|
||||
|
||||
@@ -8,11 +8,14 @@ use App\Helpers\EmailVerificationHelper;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\LoginSession;
|
||||
use App\Rules\CurrentPasswordMatches;
|
||||
use App\User;
|
||||
use DateTime;
|
||||
use Hash;
|
||||
use Illuminate\Support\Facades\Request as RequestFacade;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Log;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
class AuthController extends Controller
|
||||
@@ -164,6 +167,10 @@ class AuthController extends Controller
|
||||
[ 'expires', '>', time() ]
|
||||
])->get();
|
||||
|
||||
$sessions = $sessions->map(function ($item) {
|
||||
return collect($item)->forget(['token']);
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'method' => 'get auth sessions',
|
||||
'response' => $sessions
|
||||
@@ -211,4 +218,36 @@ class AuthController extends Controller
|
||||
'success' => true,
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function changePassword(Request $request)
|
||||
{
|
||||
$rules = [
|
||||
'currentPassword' => [ 'string', 'required', new CurrentPasswordMatches() ],
|
||||
'newPassword' => [ 'required', 'string', 'confirmed', 'min:8' ],
|
||||
'logoutDevices' => [ 'required', 'bool' ]
|
||||
];
|
||||
|
||||
$validator = Validator::make($request->all(), $rules);
|
||||
if($validator->fails()) {
|
||||
return response()->json([
|
||||
'method' => 'reset password',
|
||||
'success' => false,
|
||||
'error' => $validator->errors()
|
||||
], 403);
|
||||
}
|
||||
|
||||
$user = Auth::user();
|
||||
|
||||
$user->password = $request->newPassword;
|
||||
$user->save();
|
||||
|
||||
if($request->logoutDevices == true) {
|
||||
AuthLoginSession::where('user_id', $user->id)->update([ 'active' => false ]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'method' => 'reset password',
|
||||
'success' => true
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,19 +3,28 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Helpers\BackupHelper;
|
||||
use App\Helpers\SettingsHelper;
|
||||
use DateTime;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class BackupController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if((bool)SettingsHelper::get('auth')->value === true) {
|
||||
$this->middleware('auth:api');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get backup of speedtests
|
||||
*
|
||||
* @param Request $request
|
||||
* @return file
|
||||
* @return mixed|JsonResponse
|
||||
*/
|
||||
public function backup(Request $request)
|
||||
{
|
||||
@@ -36,7 +45,7 @@ class BackupController extends Controller
|
||||
* Retore from a backup
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function restore(Request $request)
|
||||
{
|
||||
|
||||
84
app/Http/Controllers/IntegrationsController.php
Normal file
84
app/Http/Controllers/IntegrationsController.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use Exception;
|
||||
use Healthcheck;
|
||||
use Henrywhitaker3\Healthchecks\Exceptions\HealthchecksUuidNotFoundException;
|
||||
use Henrywhitaker3\Healthchecks\Healthchecks;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Ramsey\Uuid\Exception\InvalidUuidStringException;
|
||||
|
||||
class IntegrationsController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
if((bool)SettingsHelper::get('auth')->value === true) {
|
||||
$this->middleware('auth:api');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the healthchecks config
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function testHealthchecks(String $method)
|
||||
{
|
||||
$methodResp = 'test healthchecks \'' . $method . '\' endpoint';
|
||||
|
||||
try {
|
||||
// SettingsHelper::loadIntegrationConfig();
|
||||
if($method == 'success') {
|
||||
Healthcheck::success();
|
||||
}
|
||||
|
||||
if($method == 'fail') {
|
||||
Healthcheck::fail();
|
||||
}
|
||||
|
||||
if($method == 'start') {
|
||||
Healthcheck::start();
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'method' => $methodResp,
|
||||
'success' => true
|
||||
], 200);
|
||||
} catch(InvalidUuidStringException $e) {
|
||||
return response()->json([
|
||||
'method' => $methodResp,
|
||||
'success' => false,
|
||||
'error' => 'Invalid UUID'
|
||||
], 422);
|
||||
} catch(HealthchecksUuidNotFoundException $e) {
|
||||
return response()->json([
|
||||
'method' => $methodResp,
|
||||
'success' => false,
|
||||
'error' => 'UUID not found'
|
||||
], 404);
|
||||
} catch(Exception $e) {
|
||||
return response()->json([
|
||||
'method' => $methodResp,
|
||||
'success' => false,
|
||||
'error' => $e->getMessage()
|
||||
], 422);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger a test of all notification agents
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function testNotification()
|
||||
{
|
||||
SettingsHelper::testNotification();
|
||||
|
||||
return response()->json([
|
||||
'method' => 'test notification agents'
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
@@ -8,14 +8,23 @@ use App\Setting;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class SettingsController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
if ((bool)SettingsHelper::get('auth')->value === true) {
|
||||
$this->middleware('auth:api')
|
||||
->except(['config']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all settings
|
||||
*
|
||||
* @return array
|
||||
* @return Collection
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
@@ -37,26 +46,26 @@ class SettingsController extends Controller
|
||||
* Store/update a setting
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$rule = [
|
||||
'name' => [ 'required', 'string', 'min:1' ],
|
||||
'name' => ['required', 'string', 'min:1'],
|
||||
];
|
||||
if($request->name == 'schedule') {
|
||||
$rule['value'] = [ 'required', new Cron ];
|
||||
if ($request->name == 'schedule') {
|
||||
$rule['value'] = ['required', new Cron];
|
||||
}
|
||||
|
||||
$validator = Validator::make($request->all(), $rule);
|
||||
if($validator->fails()) {
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'method' => 'Store a setting',
|
||||
'error' => $validator->errors()
|
||||
], 422);
|
||||
}
|
||||
|
||||
if(!isset($request->value)) {
|
||||
if (!isset($request->value)) {
|
||||
$request->value = '';
|
||||
}
|
||||
|
||||
@@ -72,17 +81,17 @@ class SettingsController extends Controller
|
||||
* Bulk store/update a setting
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function bulkStore(Request $request)
|
||||
{
|
||||
$rule = [
|
||||
'data' => [ 'array', 'required' ],
|
||||
'data.*.name' => [ 'string', 'required' ],
|
||||
'data' => ['array', 'required'],
|
||||
'data.*.name' => ['string', 'required'],
|
||||
];
|
||||
|
||||
$validator = Validator::make($request->all(), $rule);
|
||||
if($validator->fails()) {
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'method' => 'Bulk store a setting',
|
||||
'error' => $validator->errors()
|
||||
@@ -90,14 +99,14 @@ class SettingsController extends Controller
|
||||
}
|
||||
|
||||
$settings = [];
|
||||
foreach($request->data as $d) {
|
||||
if(!isset($d['value']) || $d['value'] == null) {
|
||||
$d['value'] = '';
|
||||
foreach ($request->data as $d) {
|
||||
if (!isset($d['value']) || $d['value'] == null) {
|
||||
$d['value'] = '';
|
||||
}
|
||||
|
||||
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' ];
|
||||
if(!in_array($d['value'], $ok)) {
|
||||
|
||||
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'];
|
||||
if (!in_array($d['value'], $ok)) {
|
||||
return response()->json([
|
||||
'method' => 'Bulk store a setting',
|
||||
'error' => 'Invalid speedtest_overview_time value'
|
||||
@@ -107,9 +116,9 @@ class SettingsController extends Controller
|
||||
|
||||
$setting = SettingsHelper::get($d['name']);
|
||||
|
||||
if($setting == false) {
|
||||
if ($setting == false) {
|
||||
$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']);
|
||||
} else {
|
||||
continue;
|
||||
@@ -133,13 +142,4 @@ class SettingsController extends Controller
|
||||
{
|
||||
return SettingsHelper::getConfig();
|
||||
}
|
||||
|
||||
public function testNotification()
|
||||
{
|
||||
SettingsHelper::testNotification();
|
||||
|
||||
return response()->json([
|
||||
'method' => 'test notificaiton agents'
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Helpers\SpeedtestHelper;
|
||||
use App\Jobs\SpeedtestJob;
|
||||
use App\Speedtest;
|
||||
@@ -11,19 +12,27 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class SpeedtestController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
if ((bool)SettingsHelper::get('auth')->value === true) {
|
||||
$this->middleware('auth:api')
|
||||
->only(['run', 'delete', 'deleteAll']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns paginated list of speedtests
|
||||
*
|
||||
* @return Response
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$data = Speedtest::orderBy('created_at', 'desc')
|
||||
->paginate();
|
||||
->paginate();
|
||||
|
||||
return response()->json([
|
||||
'method' => 'index of speedtests',
|
||||
@@ -35,17 +44,17 @@ class SpeedtestController extends Controller
|
||||
* Returns speedtest going back 'x' days
|
||||
*
|
||||
* @param int $days
|
||||
* @return void
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function time($days)
|
||||
{
|
||||
$rule = [
|
||||
'days' => [ 'required', 'integer' ],
|
||||
'days' => ['required', 'integer'],
|
||||
];
|
||||
|
||||
$validator = Validator::make([ 'days' => $days ], $rule);
|
||||
$validator = Validator::make(['days' => $days], $rule);
|
||||
|
||||
if($validator->fails()) {
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'method' => 'get speedtests in last x days',
|
||||
'error' => $validator->errors(),
|
||||
@@ -54,10 +63,18 @@ class SpeedtestController extends Controller
|
||||
|
||||
$ttl = Carbon::now()->addDays(1);
|
||||
$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();
|
||||
->where('failed', false)
|
||||
->orderBy('created_at', 'asc')
|
||||
->get();
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
@@ -71,17 +88,17 @@ class SpeedtestController extends Controller
|
||||
* Returns speedtest failure rate going back 'x' days
|
||||
*
|
||||
* @param int $days
|
||||
* @return void
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function fail($days)
|
||||
{
|
||||
$rule = [
|
||||
'days' => [ 'required', 'integer' ],
|
||||
'days' => ['required', 'integer'],
|
||||
];
|
||||
|
||||
$validator = Validator::make([ 'days' => $days ], $rule);
|
||||
$validator = Validator::make(['days' => $days], $rule);
|
||||
|
||||
if($validator->fails()) {
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'method' => 'get speedtests in last x days',
|
||||
'error' => $validator->errors(),
|
||||
@@ -100,25 +117,43 @@ class SpeedtestController extends Controller
|
||||
/**
|
||||
* Return latest speedtest
|
||||
*
|
||||
* @return Response
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function latest()
|
||||
{
|
||||
$data = SpeedtestHelper::latest();
|
||||
$avg = Speedtest::select(DB::raw('AVG(ping) as ping, AVG(download) as download, AVG(upload) as upload'))
|
||||
->where('failed', false)
|
||||
->get();
|
||||
$max = Speedtest::select(DB::raw('MAX(ping) as ping, MAX(download) as download, MAX(upload) as upload'))
|
||||
->where('failed', false)
|
||||
->get();
|
||||
|
||||
if($data) {
|
||||
return response()->json([
|
||||
'method' => 'get latest speedtest',
|
||||
'data' => $data,
|
||||
'average' => $avg[0],
|
||||
'max' => $max[0],
|
||||
], 200);
|
||||
$response = [
|
||||
'method' => 'get latest speedtest',
|
||||
'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;
|
||||
}
|
||||
|
||||
if ($data) {
|
||||
return response()->json($response, 200);
|
||||
} else {
|
||||
return response()->json([
|
||||
'method' => 'get latest speedtest',
|
||||
@@ -130,17 +165,18 @@ class SpeedtestController extends Controller
|
||||
/**
|
||||
* Queue a new speedtest
|
||||
*
|
||||
* @return Response
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
try {
|
||||
$data = SpeedtestJob::dispatch(false);
|
||||
SettingsHelper::loadIntegrationConfig();
|
||||
$data = SpeedtestJob::dispatch(false, config('integrations'));
|
||||
return response()->json([
|
||||
'method' => 'run speedtest',
|
||||
'data' => 'a new speedtest has been added to the queue'
|
||||
], 200);
|
||||
} catch(Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
return response()->json([
|
||||
'method' => 'run speedtest',
|
||||
'error' => $e
|
||||
@@ -151,13 +187,13 @@ class SpeedtestController extends Controller
|
||||
/**
|
||||
* Delete all speedtests from db
|
||||
*
|
||||
* @return Response
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function deleteAll()
|
||||
{
|
||||
$ret = SpeedtestHelper::deleteAll();
|
||||
|
||||
if($ret['success']) {
|
||||
if ($ret['success']) {
|
||||
return response()->json([
|
||||
'method' => 'delete all speedtests from the database',
|
||||
'success' => true
|
||||
@@ -175,7 +211,7 @@ class SpeedtestController extends Controller
|
||||
* Delete a specific speedtest from the database
|
||||
*
|
||||
* @param Speedtest $speedtest
|
||||
* @return boolean
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function delete(Speedtest $speedtest)
|
||||
{
|
||||
|
||||
@@ -2,17 +2,25 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use Exception;
|
||||
use Updater;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class UpdateController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
if((bool)SettingsHelper::get('auth')->value === true) {
|
||||
$this->middleware('auth:api');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for new update
|
||||
*
|
||||
* @return Response
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function checkForUpdate()
|
||||
{
|
||||
@@ -25,7 +33,7 @@ class UpdateController extends Controller
|
||||
/**
|
||||
* Download new update
|
||||
*
|
||||
* @return Response
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function downloadUpdate()
|
||||
{
|
||||
@@ -47,7 +55,7 @@ class UpdateController extends Controller
|
||||
/**
|
||||
* Trigger update extraction
|
||||
*
|
||||
* @return Response
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function extractUpdate()
|
||||
{
|
||||
@@ -69,22 +77,22 @@ class UpdateController extends Controller
|
||||
/**
|
||||
* Trigger update file move
|
||||
*
|
||||
* @return Response
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function moveUpdate()
|
||||
{
|
||||
$cp = Updater::updateFiles();
|
||||
Updater::updateFiles();
|
||||
|
||||
return response()->json([
|
||||
'method' => 'copy latest version',
|
||||
'success' => $cp,
|
||||
'success' => null,
|
||||
], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get local changelog
|
||||
*
|
||||
* @return Response
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function changelog()
|
||||
{
|
||||
|
||||
@@ -17,5 +17,7 @@ class Authenticate extends Middleware
|
||||
if (! $request->expectsJson()) {
|
||||
return route('auth.login');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,11 @@ namespace App\Jobs;
|
||||
|
||||
use App\Events\SpeedtestCompleteEvent;
|
||||
use App\Events\SpeedtestFailedEvent;
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Helpers\SpeedtestHelper;
|
||||
use Exception;
|
||||
use Healthcheck;
|
||||
use Henrywhitaker3\Healthchecks\Healthchecks;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
@@ -16,16 +20,29 @@ class SpeedtestJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Scheduled bool
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $scheduled;
|
||||
|
||||
/**
|
||||
* Integrations config array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($scheduled = true)
|
||||
public function __construct($scheduled = true, $config = [])
|
||||
{
|
||||
$this->scheduled = $scheduled;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,13 +52,50 @@ class SpeedtestJob implements ShouldQueue
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if ($this->config['healthchecks_enabled'] === true) {
|
||||
$this->healthcheck('start');
|
||||
}
|
||||
$output = SpeedtestHelper::output();
|
||||
$speedtest = SpeedtestHelper::runSpeedtest($output, $this->scheduled);
|
||||
if($speedtest == false) {
|
||||
if ($speedtest == false) {
|
||||
if ($this->config['healthchecks_enabled'] === true) {
|
||||
$this->healthcheck('fail');
|
||||
}
|
||||
|
||||
event(new SpeedtestFailedEvent());
|
||||
} else {
|
||||
if ($this->config['healthchecks_enabled'] === true) {
|
||||
$this->healthcheck('success');
|
||||
}
|
||||
|
||||
event(new SpeedtestCompleteEvent($speedtest));
|
||||
}
|
||||
return $speedtest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper to reduce duplication of try/catch for hc
|
||||
*
|
||||
* @param String $method
|
||||
* @return void
|
||||
*/
|
||||
private function healthcheck(String $method)
|
||||
{
|
||||
try {
|
||||
$hc = new Healthchecks(SettingsHelper::get('healthchecks_uuid')->value, SettingsHelper::get('healthchecks_server_url')->value);
|
||||
if ($method === 'start') {
|
||||
$hc->start();
|
||||
}
|
||||
|
||||
if ($method === 'success') {
|
||||
$hc->success();
|
||||
}
|
||||
|
||||
if ($method === 'fail') {
|
||||
$hc->fail();
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,13 @@
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Helpers\SpeedtestHelper;
|
||||
use App\Notifications\SpeedtestAbsoluteThresholdNotificationSlack;
|
||||
use App\Notifications\SpeedtestAbsoluteThresholdTelegram;
|
||||
use App\Notifications\SpeedtestCompleteSlack;
|
||||
use App\Notifications\SpeedtestCompleteTelegram;
|
||||
use App\Notifications\SpeedtestPercentageThresholdNotificationSlack;
|
||||
use App\Notifications\SpeedtestPercentageThresholdTelegram;
|
||||
use Exception;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
@@ -32,9 +37,63 @@ class SpeedtestCompleteListener
|
||||
*/
|
||||
public function handle($event)
|
||||
{
|
||||
if((bool)SettingsHelper::get('threshold_alert_percentage_notifications')->value == true) {
|
||||
$data = $event->speedtest;
|
||||
$errors = SpeedtestHelper::testIsLowerThanThreshold('percentage', $data);
|
||||
if(sizeof($errors) > 0) {
|
||||
if(SettingsHelper::get('slack_webhook')->value) {
|
||||
try {
|
||||
Notification::route('slack', SettingsHelper::get('slack_webhook')->value)
|
||||
->notify(new SpeedtestPercentageThresholdNotificationSlack($errors));
|
||||
} catch(Exception $e) {
|
||||
Log::notice('Your sleck webhook is invalid');
|
||||
Log::notice($e);
|
||||
}
|
||||
}
|
||||
|
||||
if(SettingsHelper::get('telegram_bot_token')->value == true && SettingsHelper::get('telegram_chat_id')->value == true) {
|
||||
try {
|
||||
config([ 'services.telegram-bot-api' => [ 'token' => SettingsHelper::get('telegram_bot_token')->value ] ]);
|
||||
Notification::route(TelegramChannel::class, SettingsHelper::get('telegram_chat_id')->value)
|
||||
->notify(new SpeedtestPercentageThresholdTelegram($errors));
|
||||
} catch(Exception $e) {
|
||||
Log::notice('Your telegram settings are invalid');
|
||||
Log::notice($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if((bool)SettingsHelper::get('threshold_alert_absolute_notifications')->value == true) {
|
||||
$data = $event->speedtest;
|
||||
$errors = SpeedtestHelper::testIsLowerThanThreshold('absolute', $data);
|
||||
if(sizeof($errors) > 0) {
|
||||
if(SettingsHelper::get('slack_webhook')->value) {
|
||||
try {
|
||||
Notification::route('slack', SettingsHelper::get('slack_webhook')->value)
|
||||
->notify(new SpeedtestAbsoluteThresholdNotificationSlack($errors));
|
||||
} catch(Exception $e) {
|
||||
Log::notice('Your sleck webhook is invalid');
|
||||
Log::notice($e);
|
||||
}
|
||||
}
|
||||
|
||||
if(SettingsHelper::get('telegram_bot_token')->value == true && SettingsHelper::get('telegram_chat_id')->value == true) {
|
||||
try {
|
||||
config([ 'services.telegram-bot-api' => [ 'token' => SettingsHelper::get('telegram_bot_token')->value ] ]);
|
||||
Notification::route(TelegramChannel::class, SettingsHelper::get('telegram_chat_id')->value)
|
||||
->notify(new SpeedtestAbsoluteThresholdTelegram($errors));
|
||||
} catch(Exception $e) {
|
||||
Log::notice('Your telegram settings are invalid');
|
||||
Log::notice($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(SettingsHelper::get('speedtest_notifications')->value == true) {
|
||||
$data = $event->speedtest;
|
||||
if(SettingsHelper::get('slack_webhook')) {
|
||||
if(SettingsHelper::get('slack_webhook')->value) {
|
||||
try {
|
||||
Notification::route('slack', SettingsHelper::get('slack_webhook')->value)
|
||||
->notify(new SpeedtestCompleteSlack($data));
|
||||
|
||||
@@ -10,6 +10,7 @@ use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use NotificationChannels\Telegram\TelegramChannel;
|
||||
|
||||
class SpeedtestFailedListener
|
||||
{
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Helpers\NotificationsHelper;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class SpeedtestAbsoluteThresholdNotificationSlack extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
protected $errors;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @param array $errors
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $errors)
|
||||
{
|
||||
$this->errors = $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return ['slack'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Format slack notification
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return SlackMessage
|
||||
*/
|
||||
public function toSlack($notifiable)
|
||||
{
|
||||
$msg = NotificationsHelper::formatAbsoluteThresholdMessage($this->errors);
|
||||
|
||||
return (new SlackMessage)
|
||||
->warning()
|
||||
->attachment(function ($attachment) use ($msg) {
|
||||
$attachment->title('Speedtest absolute threshold error')
|
||||
->content($msg);
|
||||
});
|
||||
}
|
||||
}
|
||||
58
app/Notifications/SpeedtestAbsoluteThresholdTelegram.php
Normal file
58
app/Notifications/SpeedtestAbsoluteThresholdTelegram.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Helpers\NotificationsHelper;
|
||||
use App\Helpers\SettingsHelper;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use NotificationChannels\Telegram\TelegramChannel;
|
||||
use NotificationChannels\Telegram\TelegramMessage;
|
||||
|
||||
class SpeedtestAbsoluteThresholdTelegram extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
private $errors;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($errors)
|
||||
{
|
||||
$this->errors = $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return [
|
||||
TelegramChannel::class
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Format telegram notification
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return TelegramMessage
|
||||
*/
|
||||
public function toTelegram($notifiable)
|
||||
{
|
||||
$msg = NotificationsHelper::formatAbsoluteThresholdMessage($this->errors);
|
||||
|
||||
return TelegramMessage::create()
|
||||
->to(SettingsHelper::get('telegram_chat_id')->value)
|
||||
->content($msg)
|
||||
->options(['parse_mode' => 'Markdown']);
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,8 @@ class SpeedtestCompleteTelegram extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public $speedtest;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
|
||||
@@ -12,6 +12,8 @@ class SpeedtestOverviewSlack extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public $data;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
|
||||
@@ -14,6 +14,8 @@ class SpeedtestOverviewTelegram extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public $data;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Helpers\NotificationsHelper;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class SpeedtestPercentageThresholdNotificationSlack extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
protected $errors;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @param array $errors
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $errors)
|
||||
{
|
||||
$this->errors = $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return ['slack'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Format slack notification
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return SlackMessage
|
||||
*/
|
||||
public function toSlack($notifiable)
|
||||
{
|
||||
$msg = NotificationsHelper::formatPercentageThresholdMessage($this->errors);
|
||||
|
||||
return (new SlackMessage)
|
||||
->warning()
|
||||
->attachment(function ($attachment) use ($msg) {
|
||||
$attachment->title('Speedtest percentage threshold error')
|
||||
->content($msg);
|
||||
});
|
||||
}
|
||||
}
|
||||
58
app/Notifications/SpeedtestPercentageThresholdTelegram.php
Normal file
58
app/Notifications/SpeedtestPercentageThresholdTelegram.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Helpers\NotificationsHelper;
|
||||
use App\Helpers\SettingsHelper;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use NotificationChannels\Telegram\TelegramChannel;
|
||||
use NotificationChannels\Telegram\TelegramMessage;
|
||||
|
||||
class SpeedtestPercentageThresholdTelegram extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
private $errors;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($errors)
|
||||
{
|
||||
$this->errors = $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return [
|
||||
TelegramChannel::class
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Format telegram notification
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return TelegramMessage
|
||||
*/
|
||||
public function toTelegram($notifiable)
|
||||
{
|
||||
$msg = NotificationsHelper::formatAbsoluteThresholdMessage($this->errors);
|
||||
|
||||
return TelegramMessage::create()
|
||||
->to(SettingsHelper::get('telegram_chat_id')->value)
|
||||
->content($msg)
|
||||
->options(['parse_mode' => 'Markdown']);
|
||||
}
|
||||
}
|
||||
58
app/Providers/IntegrationsServiceProvider.php
Normal file
58
app/Providers/IntegrationsServiceProvider.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use Exception;
|
||||
use File;
|
||||
use Henrywhitaker3\Healthchecks\Healthchecks;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Ramsey\Uuid\Exception\InvalidUuidStringException;
|
||||
use Schema;
|
||||
|
||||
/**
|
||||
* This class updates the integrations.php config with the relevant values
|
||||
* from the databse.
|
||||
*/
|
||||
class IntegrationsServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
if (File::exists(env('DB_DATABASE'))) {
|
||||
if (Schema::hasTable('settings')) {
|
||||
$setting = SettingsHelper::get('healthchecks_uuid');
|
||||
|
||||
if ($setting !== false) {
|
||||
try {
|
||||
SettingsHelper::loadIntegrationConfig();
|
||||
|
||||
App::bind('healthcheck', function () use ($setting) {
|
||||
return new Healthchecks($setting->value, SettingsHelper::get('healthchecks_server_url')->value);
|
||||
});
|
||||
} catch (InvalidUuidStringException $e) {
|
||||
Log::error('Invalid healthchecks UUID');
|
||||
} catch (Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
41
app/Rules/CurrentPasswordMatches.php
Normal file
41
app/Rules/CurrentPasswordMatches.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use Hash;
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class CurrentPasswordMatches implements Rule
|
||||
{
|
||||
/**
|
||||
* Create a new rule instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
return Hash::check($value, auth()->user()->password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return 'The current password doesn\'t match.';
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,7 @@ class User extends Authenticatable implements JWTSubject
|
||||
/**
|
||||
* Returns a user's login sessions
|
||||
*
|
||||
* @return array
|
||||
* @return mixed
|
||||
*/
|
||||
public function sessions()
|
||||
{
|
||||
|
||||
168
changelog.json
168
changelog.json
@@ -1,4 +1,172 @@
|
||||
{
|
||||
"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": [
|
||||
{
|
||||
"description": "Added option to display minimum values on the top widgets.",
|
||||
"link": ""
|
||||
},
|
||||
{
|
||||
"description": "New general settings section.",
|
||||
"link": ""
|
||||
},
|
||||
{
|
||||
"description": "Updated dependencies.",
|
||||
"link": ""
|
||||
}
|
||||
],
|
||||
"1.9.6": [
|
||||
{
|
||||
"description": "Clear the cache on restore.",
|
||||
"link": ""
|
||||
},
|
||||
{
|
||||
"description": "Updated dependencies.",
|
||||
"link": ""
|
||||
}
|
||||
],
|
||||
"1.9.5": [
|
||||
{
|
||||
"description": "Added toggle to show failed tests on graphs.",
|
||||
"link": ""
|
||||
},
|
||||
{
|
||||
"description": "Updated dependencies.",
|
||||
"link": ""
|
||||
}
|
||||
],
|
||||
"1.9.4": [
|
||||
{
|
||||
"description": "Changed integration config loading.",
|
||||
"link": ""
|
||||
},
|
||||
{
|
||||
"description": "Added more tests.",
|
||||
"link": ""
|
||||
}
|
||||
],
|
||||
"1.9.3": [
|
||||
{
|
||||
"description": "Updated dependencies.",
|
||||
"link": ""
|
||||
}
|
||||
],
|
||||
"1.9.2": [
|
||||
{
|
||||
"description": "Authentication bugfixes.",
|
||||
"link": ""
|
||||
}
|
||||
],
|
||||
"1.9.1": [
|
||||
{
|
||||
"description": "Added conditional notifications.",
|
||||
"link": ""
|
||||
}
|
||||
],
|
||||
"1.9.0": [
|
||||
{
|
||||
"description": "Added optional authentication.",
|
||||
"link": ""
|
||||
}
|
||||
],
|
||||
"1.8.1": [
|
||||
{
|
||||
"description": "Added healthchecks.io test buttons.",
|
||||
"link": ""
|
||||
},
|
||||
{
|
||||
"description": "Added close buttons to modals.",
|
||||
"link": ""
|
||||
},
|
||||
{
|
||||
"description": "Back-end config handling changes.",
|
||||
"link": ""
|
||||
}
|
||||
],
|
||||
"1.8.0": [
|
||||
{
|
||||
"description": "Added healthchecks.io integration.",
|
||||
"link": ""
|
||||
}
|
||||
],
|
||||
"1.7.19": [
|
||||
{
|
||||
"description": "Updated dependencies.",
|
||||
"link": ""
|
||||
}
|
||||
],
|
||||
"1.7.18": [
|
||||
{
|
||||
"description": "Fixed issue with widgets not updating when switching between failed/successful tests.",
|
||||
"link": ""
|
||||
},
|
||||
{
|
||||
"description": "Updated backup/restore functions to reflect new DB fields.",
|
||||
"link": ""
|
||||
}
|
||||
],
|
||||
"1.7.17": [
|
||||
{
|
||||
"description": "Updated dependencies.",
|
||||
"link": ""
|
||||
}
|
||||
],
|
||||
"1.7.16": [
|
||||
{
|
||||
"description": "Updated dependencies.",
|
||||
"link": ""
|
||||
}
|
||||
],
|
||||
"1.7.15": [
|
||||
{
|
||||
"description": "Updates for manual installs.",
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
"fideloper/proxy": "^4.2",
|
||||
"fruitcake/laravel-cors": "^2.0",
|
||||
"guzzlehttp/guzzle": "^7.0",
|
||||
"laravel-notification-channels/telegram": "^0.4.0",
|
||||
"henrywhitaker3/healthchecks-io": "^1.0",
|
||||
"laravel-notification-channels/telegram": "^0.5.0",
|
||||
"laravel/framework": "^7.0",
|
||||
"laravel/slack-notification-channel": "^2.0",
|
||||
"laravel/tinker": "^2.0",
|
||||
@@ -22,11 +23,13 @@
|
||||
"tymon/jwt-auth": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"barryvdh/laravel-ide-helper": "^2.8",
|
||||
"facade/ignition": "^2.0",
|
||||
"fzaninotto/faker": "^1.9.1",
|
||||
"mockery/mockery": "^1.3.1",
|
||||
"nunomaduro/collision": "^4.1",
|
||||
"phpunit/phpunit": "^8.5"
|
||||
"phpunit/phpunit": "^9.5",
|
||||
"nunomaduro/larastan": "^0.7.0",
|
||||
"nunomaduro/collision": "^5.3"
|
||||
},
|
||||
"config": {
|
||||
"optimize-autoloader": true,
|
||||
|
||||
4261
composer.lock
generated
4261
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -178,6 +178,11 @@ return [
|
||||
App\Providers\RouteServiceProvider::class,
|
||||
App\Providers\UpdaterServiceProvider::class,
|
||||
|
||||
/*
|
||||
* Custom providers...
|
||||
*/
|
||||
App\Providers\IntegrationsServiceProvider::class,
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
@@ -230,6 +235,7 @@ return [
|
||||
'Validator' => Illuminate\Support\Facades\Validator::class,
|
||||
'View' => Illuminate\Support\Facades\View::class,
|
||||
'Updater' => App\Facades\UpdaterFacade::class,
|
||||
'Healthcheck' => App\Facades\HealthchecksFacade::class,
|
||||
],
|
||||
|
||||
];
|
||||
|
||||
59
config/integrations.php
Normal file
59
config/integrations.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Healthchecks enabled
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option defines whether healthchecks integrations are enabled
|
||||
|
|
||||
*/
|
||||
|
||||
'healthchecks_enabled' => false,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Healthchecks UUID
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option defines the UUID for healthchecks
|
||||
|
|
||||
*/
|
||||
|
||||
'healthchecks_uuid' => null,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Slack webhook
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option defines the slack webhook url
|
||||
|
|
||||
*/
|
||||
|
||||
'slack_webhook' => null,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Telegram bot token
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option defines the telegram bot token
|
||||
|
|
||||
*/
|
||||
|
||||
'telegram_bot_token' => null,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Telegram chat id
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option defines the telegram chat id
|
||||
|
|
||||
*/
|
||||
|
||||
'telegram_chat_id' => null,
|
||||
];
|
||||
@@ -37,7 +37,7 @@ return [
|
||||
'channels' => [
|
||||
'stack' => [
|
||||
'driver' => 'stack',
|
||||
'channels' => ['single'],
|
||||
'channels' => ['daily'],
|
||||
'ignore_exceptions' => false,
|
||||
],
|
||||
|
||||
@@ -51,7 +51,7 @@ return [
|
||||
'driver' => 'daily',
|
||||
'path' => storage_path('logs/laravel.log'),
|
||||
'level' => 'debug',
|
||||
'days' => 14,
|
||||
'days' => 7,
|
||||
],
|
||||
|
||||
'slack' => [
|
||||
|
||||
@@ -7,7 +7,7 @@ return [
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
'version' => '1.7.15',
|
||||
'version' => '1.10.4',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Setting;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddHealthchecksSettings extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if(!SettingsHelper::get('healthchecks_enabled')) {
|
||||
Setting::create([
|
||||
'name' => 'healthchecks_enabled',
|
||||
'value' => false,
|
||||
'description' => 'Enable the healthchecks.io integration for speedtests.'
|
||||
]);
|
||||
}
|
||||
|
||||
if(!SettingsHelper::get('healthchecks_uuid')) {
|
||||
Setting::create([
|
||||
'name' => 'healthchecks_uuid',
|
||||
'value' => '',
|
||||
'description' => ''
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Setting::whereIn('name', [
|
||||
'healthchecks_enabled',
|
||||
'healthchecks_uuid',
|
||||
])->delete();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Setting;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddAuthenticationSettings extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if(!SettingsHelper::get('auth')) {
|
||||
Setting::create([
|
||||
'name' => 'auth',
|
||||
'value' => false,
|
||||
'description' => 'Enable authentication.'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Setting::whereIn('name', [
|
||||
'auth',
|
||||
])->delete();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Setting;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddConditionalNotificationsSettings extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if(!SettingsHelper::get('threshold_alert_percentage_notifications')) {
|
||||
Setting::create([
|
||||
'name' => 'threshold_alert_percentage_notifications',
|
||||
'value' => false,
|
||||
'description' => 'Enable/disable theshold percentage notifications'
|
||||
]);
|
||||
}
|
||||
|
||||
if(!SettingsHelper::get('threshold_alert_percentage')) {
|
||||
Setting::create([
|
||||
'name' => 'threshold_alert_percentage',
|
||||
'value' => 15,
|
||||
'description' => 'When any value of a speedtest is x percent lower than the average, a notification will be sent.'
|
||||
]);
|
||||
}
|
||||
|
||||
if(!SettingsHelper::get('threshold_alert_absolute_notifications')) {
|
||||
Setting::create([
|
||||
'name' => 'threshold_alert_absolute_notifications',
|
||||
'value' => false,
|
||||
'description' => 'Enable/disable absolute theshold notifications'
|
||||
]);
|
||||
}
|
||||
|
||||
if(!SettingsHelper::get('threshold_alert_absolute_download')) {
|
||||
Setting::create([
|
||||
'name' => 'threshold_alert_absolute_download',
|
||||
'value' => '',
|
||||
'description' => 'When the download is lower than this value, a notification will be sent. Leave blank to disable'
|
||||
]);
|
||||
}
|
||||
|
||||
if(!SettingsHelper::get('threshold_alert_absolute_upload')) {
|
||||
Setting::create([
|
||||
'name' => 'threshold_alert_absolute_upload',
|
||||
'value' => '',
|
||||
'description' => 'When the upload is lower than this value, a notification will be sent. Leave blank to disable'
|
||||
]);
|
||||
}
|
||||
|
||||
if(!SettingsHelper::get('threshold_alert_absolute_ping')) {
|
||||
Setting::create([
|
||||
'name' => 'threshold_alert_absolute_ping',
|
||||
'value' => '',
|
||||
'description' => 'When the ping is higher than this value, a notification will be sent. Leave blank to disable'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Setting::whereIn('name', [
|
||||
'threshold_alert_percentage',
|
||||
'threshold_alert_absolute_download',
|
||||
'threshold_alert_absolute_upload',
|
||||
'threshold_alert_absolute_ping',
|
||||
'threshold_alert_percentage_notifications',
|
||||
'threshold_alert_absolute_notifications'
|
||||
])->delete();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Setting;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddShowFailedTestsSetting extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if(!SettingsHelper::get('show_failed_tests_on_graph')) {
|
||||
Setting::create([
|
||||
'name' => 'show_failed_tests_on_graph',
|
||||
'value' => true,
|
||||
'description' => 'If enabled, failed tests will appear on the graphs as 0.'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Setting::whereIn('name', [
|
||||
'show_failed_tests_on_graph',
|
||||
])->delete();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Setting;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddWidgetCardSettings extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if (!SettingsHelper::get('show_average')) {
|
||||
Setting::create([
|
||||
'name' => 'show_average',
|
||||
'value' => true,
|
||||
'description' => 'If enabled, the average value for speedtests will be shown in the widgets.'
|
||||
]);
|
||||
}
|
||||
|
||||
if (!SettingsHelper::get('show_max')) {
|
||||
Setting::create([
|
||||
'name' => 'show_max',
|
||||
'value' => true,
|
||||
'description' => 'If enabled, the maximum value for speedtests will be shown in the widgets.'
|
||||
]);
|
||||
}
|
||||
|
||||
if (!SettingsHelper::get('show_min')) {
|
||||
Setting::create([
|
||||
'name' => 'show_min',
|
||||
'value' => true,
|
||||
'description' => 'If enabled, the minimum value for speedtests will be shown in the widgets.'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Setting::whereIn('name', [
|
||||
'show_average',
|
||||
'show_max',
|
||||
'show_min',
|
||||
])->delete();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\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\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\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();
|
||||
}
|
||||
}
|
||||
3938
package-lock.json
generated
3938
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
33
package.json
33
package.json
@@ -10,28 +10,29 @@
|
||||
"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": {
|
||||
"@babel/preset-react": "^7.10.4",
|
||||
"axios": "^0.19",
|
||||
"bootstrap": "^4.5.0",
|
||||
"axios": "^0.21",
|
||||
"@babel/preset-react": "^7.12.13",
|
||||
"bootstrap": "^4.6.0",
|
||||
"cross-env": "^7.0",
|
||||
"jquery": "^3.5",
|
||||
"laravel-mix": "^5.0.1",
|
||||
"lodash": "^4.17.19",
|
||||
"laravel-mix": "^5.0.9",
|
||||
"lodash": "^4.17.21",
|
||||
"popper.js": "^1.12",
|
||||
"react": "^16.2.0",
|
||||
"react-dom": "^16.2.0",
|
||||
"resolve-url-loader": "^3.1.0",
|
||||
"sass": "^1.26.10",
|
||||
"sass-loader": "^9.0.2"
|
||||
"react": "^17.0.1",
|
||||
"react-dom": "^17.0.1",
|
||||
"resolve-url-loader": "^3.1.2",
|
||||
"sass": "^1.32.8",
|
||||
"sass-loader": "^10.1.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/plugin-proposal-class-properties": "^7.10.4",
|
||||
"chart.js": "^2.9.3",
|
||||
"csv-file-validator": "^1.8.0",
|
||||
"react-bootstrap": "^1.3.0",
|
||||
"react-chartjs-2": "^2.9.0",
|
||||
"@babel/plugin-proposal-class-properties": "^7.13.0",
|
||||
"chart.js": "^2.9.4",
|
||||
"csv-file-validator": "^1.10.1",
|
||||
"js-cookie": "^2.2.1",
|
||||
"react-bootstrap": "^1.5.1",
|
||||
"react-chartjs-2": "^2.11.1",
|
||||
"react-router": "^5.2.0",
|
||||
"react-router-dom": "^5.2.0",
|
||||
"react-toastify": "^6.0.8"
|
||||
"react-toastify": "^7.0.3"
|
||||
}
|
||||
}
|
||||
|
||||
17
phpstan.neon
Normal file
17
phpstan.neon
Normal file
@@ -0,0 +1,17 @@
|
||||
includes:
|
||||
- ./vendor/nunomaduro/larastan/extension.neon
|
||||
|
||||
parameters:
|
||||
|
||||
paths:
|
||||
- app
|
||||
|
||||
# The level 8 is the highest level
|
||||
level: 5
|
||||
|
||||
ignoreErrors:
|
||||
|
||||
excludes_analyse:
|
||||
- ./*/*/FileToBeExcluded.php
|
||||
|
||||
checkMissingIterableValueType: false
|
||||
51
phpunit.xml
51
phpunit.xml
@@ -1,29 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
|
||||
bootstrap="vendor/autoload.php"
|
||||
colors="true">
|
||||
<testsuites>
|
||||
<testsuite name="Unit">
|
||||
<directory suffix="Test.php">./tests/Unit</directory>
|
||||
</testsuite>
|
||||
<testsuite name="Feature">
|
||||
<directory suffix="Test.php">./tests/Feature</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">./app</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
<php>
|
||||
<server name="APP_ENV" value="testing"/>
|
||||
<server name="BCRYPT_ROUNDS" value="4"/>
|
||||
<server name="CACHE_DRIVER" value="array"/>
|
||||
<server name="DB_CONNECTION" value="sqlite"/>
|
||||
<server name="DB_DATABASE" value=":memory:"/>
|
||||
<server name="MAIL_MAILER" value="array"/>
|
||||
<server name="QUEUE_CONNECTION" value="sync"/>
|
||||
<server name="SESSION_DRIVER" value="array"/>
|
||||
</php>
|
||||
<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">
|
||||
<coverage processUncoveredFiles="true">
|
||||
<include>
|
||||
<directory suffix=".php">./app</directory>
|
||||
</include>
|
||||
</coverage>
|
||||
<testsuites>
|
||||
<testsuite name="Unit">
|
||||
<directory suffix="Test.php">./tests/Unit</directory>
|
||||
</testsuite>
|
||||
<testsuite name="Feature">
|
||||
<directory suffix="Test.php">./tests/Feature</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<php>
|
||||
<server name="APP_ENV" value="testing"/>
|
||||
<server name="BCRYPT_ROUNDS" value="4"/>
|
||||
<server name="CACHE_DRIVER" value="array"/>
|
||||
<server name="DB_CONNECTION" value="sqlite"/>
|
||||
<server name="DB_DATABASE" value=":memory:"/>
|
||||
<server name="MAIL_MAILER" value="array"/>
|
||||
<server name="QUEUE_CONNECTION" value="sync"/>
|
||||
<server name="SESSION_DRIVER" value="array"/>
|
||||
</php>
|
||||
</phpunit>
|
||||
|
||||
10950
public/css/app.css
vendored
10950
public/css/app.css
vendored
File diff suppressed because one or more lines are too long
138415
public/js/app.js
vendored
138415
public/js/app.js
vendored
File diff suppressed because one or more lines are too long
@@ -12,9 +12,9 @@ License: MIT
|
||||
*/
|
||||
|
||||
/*!
|
||||
* Bootstrap v4.5.0 (https://getbootstrap.com/)
|
||||
* Bootstrap v4.5.3 (https://getbootstrap.com/)
|
||||
* Copyright 2011-2020 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
|
||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||
*/
|
||||
|
||||
/*!
|
||||
@@ -24,12 +24,20 @@ License: MIT
|
||||
*/
|
||||
|
||||
/*!
|
||||
* Chart.js v2.9.3
|
||||
* Chart.js v2.9.4
|
||||
* https://www.chartjs.org
|
||||
* (c) 2019 Chart.js Contributors
|
||||
* (c) 2020 Chart.js Contributors
|
||||
* Released under the MIT License
|
||||
*/
|
||||
|
||||
/*!
|
||||
* JavaScript Cookie v2.2.1
|
||||
* https://github.com/js-cookie/js-cookie
|
||||
*
|
||||
* Copyright 2006, 2015 Klaus Hartl & Fagner Brack
|
||||
* Released under the MIT license
|
||||
*/
|
||||
|
||||
/*!
|
||||
* Sizzle CSS Selector Engine v2.3.5
|
||||
* https://sizzlejs.com/
|
||||
@@ -73,15 +81,6 @@ License: MIT
|
||||
* 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
|
||||
* react-is.production.min.js
|
||||
*
|
||||
@@ -91,7 +90,16 @@ License: MIT
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/** @license React v16.13.1
|
||||
/** @license React v16.14.0
|
||||
* 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.14.0
|
||||
* react.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
@@ -124,3 +132,7 @@ License: MIT
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
//! moment.js
|
||||
|
||||
//! moment.js locale configuration
|
||||
|
||||
70
resources/js/components/Authentication/Authentication.js
vendored
Normal file
70
resources/js/components/Authentication/Authentication.js
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Row, Col} from 'react-bootstrap';
|
||||
import SessionsTable from './SessionsTable';
|
||||
import ResetPassword from './ResetPassword';
|
||||
|
||||
export default class Authentication extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
showCollapse: false,
|
||||
showModal: false
|
||||
}
|
||||
}
|
||||
|
||||
toggleCollapse = () => {
|
||||
if(this.state.showCollapse) {
|
||||
this.setState({
|
||||
showCollapse: false
|
||||
});
|
||||
} else {
|
||||
this.setState({
|
||||
showCollapse: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
toggleModal = () => {
|
||||
if(this.state.showModal) {
|
||||
this.setState({
|
||||
showModal: false
|
||||
});
|
||||
} else {
|
||||
this.setState({
|
||||
showModal: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
var showCollapse = this.state.showCollapse;
|
||||
var showModal = this.state.showModal;
|
||||
|
||||
if( (window.config.auth == true && window.authenticated == true)) {
|
||||
return (
|
||||
<div>
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="text-center">
|
||||
<ResetPassword />
|
||||
</Col>
|
||||
</Row>
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="text-center">
|
||||
<SessionsTable />
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<></>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('Authentication')) {
|
||||
ReactDOM.render(<Authentication />, document.getElementById('Authentication'));
|
||||
}
|
||||
111
resources/js/components/Authentication/ResetPassword.js
vendored
Normal file
111
resources/js/components/Authentication/ResetPassword.js
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Container, Row, Col, Collapse, Button, Modal, Form } from 'react-bootstrap';
|
||||
import SessionsTable from './SessionsTable';
|
||||
import Axios from 'axios';
|
||||
import { toast } from 'react-toastify';
|
||||
|
||||
export default class ResetPassword extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
showModal: false,
|
||||
currentPassword: '',
|
||||
newPassword: '',
|
||||
newPasswordConfirmation: '',
|
||||
logoutDevices: false
|
||||
}
|
||||
}
|
||||
|
||||
toggleModal = () => {
|
||||
if(this.state.showModal) {
|
||||
this.setState({
|
||||
showModal: false
|
||||
});
|
||||
} else {
|
||||
this.setState({
|
||||
showModal: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
updateTextField = (e) => {
|
||||
this.setState({
|
||||
[e.target.id]: e.target.value
|
||||
})
|
||||
}
|
||||
|
||||
updateCheckbox = (e) => {
|
||||
this.setState({
|
||||
[e.target.id]: e.target.checked
|
||||
});
|
||||
}
|
||||
|
||||
changePassword = (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
var data = {
|
||||
currentPassword: this.state.currentPassword,
|
||||
newPassword: this.state.newPassword,
|
||||
newPassword_confirmation: this.state.newPasswordConfirmation,
|
||||
logoutDevices: this.state.logoutDevices
|
||||
}
|
||||
|
||||
var url = 'api/auth/change-password?token=' + window.token;
|
||||
Axios.post(url, data)
|
||||
.then((resp) => {
|
||||
toast.success('Password updated');
|
||||
this.toggleModal();
|
||||
if(this.state.logoutDevices == true) {
|
||||
location.reload(true);
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
if(err.response) {
|
||||
for(var key in err.response.data.error) {
|
||||
toast.error(err.response.data.error[key][0]);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
var showModal = this.state.showModal;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Button variant="primary" onClick={this.toggleModal} className="mb-3">Change password</Button>
|
||||
<Modal show={showModal} onHide={this.toggleModal}>
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title>Change password</Modal.Title>
|
||||
</Modal.Header>
|
||||
<Modal.Body>
|
||||
<Form onSubmit={this.changePassword}>
|
||||
<Form.Group controlId="currentPassword">
|
||||
<Form.Label>Current password</Form.Label>
|
||||
<Form.Control type="password" onInput={this.updateTextField} required />
|
||||
</Form.Group>
|
||||
<Form.Group controlId="newPassword">
|
||||
<Form.Label>New Password</Form.Label>
|
||||
<Form.Control type="password" onInput={this.updateTextField} required />
|
||||
</Form.Group>
|
||||
<Form.Group controlId="newPasswordConfirmation">
|
||||
<Form.Label>Confirm New Password</Form.Label>
|
||||
<Form.Control type="password" onInput={this.updateTextField} required />
|
||||
</Form.Group>
|
||||
<Button variant="primary" type="submit" className="d-inline-block">Change password</Button>
|
||||
<Form.Group controlId="logoutDevices" className="d-inline-block ml-2">
|
||||
<Form.Check type="checkbox" label="Log everywhere out" onInput={this.updateCheckbox} />
|
||||
</Form.Group>
|
||||
</Form>
|
||||
</Modal.Body>
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('ResetPassword')) {
|
||||
ReactDOM.render(<ResetPassword />, document.getElementById('ResetPassword'));
|
||||
}
|
||||
67
resources/js/components/Authentication/SessionsTable.js
vendored
Normal file
67
resources/js/components/Authentication/SessionsTable.js
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Container, Row, Col, Table } from 'react-bootstrap';
|
||||
import Axios from 'axios';
|
||||
|
||||
export default class SessionsTable extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
sessions: []
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.getSessions();
|
||||
}
|
||||
|
||||
getSessions = () => {
|
||||
var url = 'api/auth/sessions?token=' + window.token;
|
||||
|
||||
Axios.get(url)
|
||||
.then((resp) => {
|
||||
this.setState({
|
||||
sessions: resp.data.response
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
var sessions = this.state.sessions;
|
||||
|
||||
return (
|
||||
<Container className="mb-4">
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="mb-3 text-center">
|
||||
<h5>Login Sessions</h5>
|
||||
<Table responsive>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>IP</th>
|
||||
<th>Expires</th>
|
||||
<th>Created at</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{sessions.map((e,i) => {
|
||||
return(
|
||||
<tr key={i}>
|
||||
<td>{e.ip}</td>
|
||||
<td>{new Date(e.expires * 1000).toLocaleDateString() + ' ' + new Date(e.expires * 1000).toLocaleTimeString()}</td>
|
||||
<td>{e.created_at}</td>
|
||||
</tr>
|
||||
)
|
||||
})}
|
||||
</tbody>
|
||||
</Table>
|
||||
</Col>
|
||||
</Row>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('SessionsTable')) {
|
||||
ReactDOM.render(<SessionsTable />, document.getElementById('SessionsTable'));
|
||||
}
|
||||
2
resources/js/components/Data/Backup.js
vendored
2
resources/js/components/Data/Backup.js
vendored
@@ -6,7 +6,7 @@ import Axios from 'axios';
|
||||
|
||||
export default class Backup extends Component {
|
||||
backup = (format) => {
|
||||
var url = 'api/backup?format=' + format;
|
||||
var url = 'api/backup?format=' + format + '&token=' + window.token;
|
||||
|
||||
toast.info('Your backup has started downloading...');
|
||||
|
||||
|
||||
6
resources/js/components/Data/Changelog.js
vendored
6
resources/js/components/Data/Changelog.js
vendored
@@ -16,11 +16,13 @@ export default class Changelog extends Component {
|
||||
}
|
||||
|
||||
componentDidMount = () => {
|
||||
this.getChangelog();
|
||||
if( (window.config.auth == true && window.authenticated == true) || window.config.auth == false) {
|
||||
this.getChangelog();
|
||||
}
|
||||
}
|
||||
|
||||
getChangelog = () => {
|
||||
Axios.get('api/update/changelog')
|
||||
Axios.get('api/update/changelog?token=' + window.token)
|
||||
.then((resp) => {
|
||||
this.setState({
|
||||
changelog: resp.data.data,
|
||||
|
||||
36
resources/js/components/Data/DataRow.js
vendored
36
resources/js/components/Data/DataRow.js
vendored
@@ -8,21 +8,27 @@ import Restore from './Restore';
|
||||
|
||||
export default class DataRow extends Component {
|
||||
render() {
|
||||
return (
|
||||
<Container className="mb-4">
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="text-center">
|
||||
<p>Use these buttons to backup/restore your data</p>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="text-center">
|
||||
<Backup />
|
||||
<Restore />
|
||||
</Col>
|
||||
</Row>
|
||||
</Container>
|
||||
);
|
||||
if( (window.config.auth == true && window.authenticated == true) || window.config.auth == false) {
|
||||
return (
|
||||
<Container className="mb-4">
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="text-center">
|
||||
<p>Use these buttons to backup/restore your data</p>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="text-center">
|
||||
<Backup />
|
||||
<Restore />
|
||||
</Col>
|
||||
</Row>
|
||||
</Container>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<></>
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
32
resources/js/components/Data/Restore.js
vendored
32
resources/js/components/Data/Restore.js
vendored
@@ -75,6 +75,36 @@ export default class Restore extends Component {
|
||||
inputName: 'created_at',
|
||||
required: false,
|
||||
},
|
||||
{
|
||||
name: "server_id",
|
||||
inputName: 'server_id',
|
||||
required: false,
|
||||
},
|
||||
{
|
||||
name: "server_name",
|
||||
inputName: 'server_name',
|
||||
required: false,
|
||||
},
|
||||
{
|
||||
name: "server_host",
|
||||
inputName: 'server_host',
|
||||
required: false,
|
||||
},
|
||||
{
|
||||
name: "url",
|
||||
inputName: 'url',
|
||||
required: false,
|
||||
},
|
||||
{
|
||||
name: "scheduled",
|
||||
inputName: 'scheduled',
|
||||
required: false,
|
||||
},
|
||||
{
|
||||
name: "failed",
|
||||
inputName: 'failed',
|
||||
required: false,
|
||||
},
|
||||
{
|
||||
name: "updated_at",
|
||||
inputName: 'updated_at',
|
||||
@@ -118,7 +148,7 @@ export default class Restore extends Component {
|
||||
|
||||
uploadFile = () => {
|
||||
var data = { data: this.state.data, format: this.state.format };
|
||||
var url = 'api/restore';
|
||||
var url = 'api/restore?token=' + window.token;
|
||||
|
||||
Axios.post(url, data)
|
||||
.then((resp) => {
|
||||
|
||||
@@ -37,6 +37,10 @@ export default class HistoryGraph extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
clearInterval(this.state.interval);
|
||||
}
|
||||
|
||||
getDLULPing = (days) => {
|
||||
var url = 'api/speedtest/time/' + days;
|
||||
|
||||
@@ -205,7 +209,6 @@ export default class HistoryGraph extends Component {
|
||||
failData.datasets[1].data.push(fail);
|
||||
failData.labels.push(new Date(e.date).toLocaleString([], {year: '2-digit', month:'2-digit', day:'2-digit'}));
|
||||
})
|
||||
console.log(failData);
|
||||
|
||||
this.setState({
|
||||
failData: failData,
|
||||
|
||||
@@ -26,6 +26,10 @@ export default class LatestResults extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
clearInterval(this.state.interval);
|
||||
}
|
||||
|
||||
getData = () => {
|
||||
var url = 'api/speedtest/latest';
|
||||
|
||||
@@ -45,7 +49,7 @@ export default class LatestResults extends Component {
|
||||
}
|
||||
|
||||
newScan = () => {
|
||||
var url = 'api/speedtest/run';
|
||||
var url = 'api/speedtest/run?token=' + window.token;
|
||||
|
||||
Axios.get(url)
|
||||
.then((resp) => {
|
||||
@@ -78,25 +82,47 @@ export default class LatestResults extends Component {
|
||||
</Container>
|
||||
);
|
||||
} else if(data === false) {
|
||||
return (
|
||||
<Container fluid>
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="text-center">
|
||||
<div>
|
||||
<Button variant="primary" onClick={this.newScan}>Start your first test!</Button>
|
||||
</div>
|
||||
</Col>
|
||||
</Row>
|
||||
</Container>
|
||||
);
|
||||
if( (window.config.auth == true && window.authenticated == true) || window.config.auth == false) {
|
||||
return (
|
||||
<Container fluid>
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="text-center">
|
||||
<div>
|
||||
<Button variant="primary" onClick={this.newScan}>Start your first test!</Button>
|
||||
</div>
|
||||
</Col>
|
||||
</Row>
|
||||
</Container>
|
||||
);
|
||||
} else if(window.config.auth == true && window.authenticated == false) {
|
||||
return (
|
||||
<Container fluid>
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="text-center">
|
||||
<div>
|
||||
<p>Please login to run the first test</p>
|
||||
</div>
|
||||
</Col>
|
||||
</Row>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return (
|
||||
<Container fluid>
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="text-center mb-2">
|
||||
<div>
|
||||
<Button className="d-inline-block mx-3 mb-2" variant="primary" onClick={this.newScan}>Test again</Button>
|
||||
<p className="text-muted mb-0 d-inline-block">Last test performed at: {new Date(data.data.created_at).toLocaleString()}</p>
|
||||
{(window.config.auth == true && window.authenticated == true) || window.config.auth == false ?
|
||||
<div>
|
||||
<Button className="d-inline-block mx-3 mb-2" variant="primary" onClick={this.newScan}>Test again</Button>
|
||||
<p className="text-muted mb-0 d-inline-block">Last test performed at: {new Date(data.data.created_at).toLocaleString()}</p>
|
||||
</div>
|
||||
:
|
||||
<div>
|
||||
<p className="text-muted mb-0 d-inline-block">Last test performed at: {new Date(data.data.created_at).toLocaleString()}</p>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</Col>
|
||||
</Row>
|
||||
@@ -109,9 +135,7 @@ export default class LatestResults extends Component {
|
||||
>
|
||||
<Widget
|
||||
title="Ping"
|
||||
value={parseFloat(data.data.ping).toFixed(1)}
|
||||
avg={parseFloat(data.average.ping).toFixed(1)}
|
||||
max={parseFloat(data.max.ping).toFixed(1)}
|
||||
data={data}
|
||||
failed={data.data.failed}
|
||||
unit="ms"
|
||||
icon="ping"
|
||||
@@ -125,9 +149,7 @@ export default class LatestResults extends Component {
|
||||
>
|
||||
<Widget
|
||||
title="Download"
|
||||
value={parseFloat(data.data.download).toFixed(1)}
|
||||
avg={parseFloat(data.average.download).toFixed(1)}
|
||||
max={parseFloat(data.max.download).toFixed(1)}
|
||||
data={data}
|
||||
failed={data.data.failed}
|
||||
unit="Mbit/s"
|
||||
icon="dl"
|
||||
@@ -141,9 +163,7 @@ export default class LatestResults extends Component {
|
||||
>
|
||||
<Widget
|
||||
title="Upload"
|
||||
value={parseFloat(data.data.upload).toFixed(1)}
|
||||
avg={parseFloat(data.average.upload).toFixed(1)}
|
||||
max={parseFloat(data.max.upload).toFixed(1)}
|
||||
data={data}
|
||||
failed={data.data.failed}
|
||||
unit="Mbit/s"
|
||||
icon="ul"
|
||||
|
||||
2
resources/js/components/Graphics/TableRow.js
vendored
2
resources/js/components/Graphics/TableRow.js
vendored
@@ -62,7 +62,7 @@ export default class TableRow extends Component {
|
||||
<td>
|
||||
<span onClick={this.toggleShow} className="ti-arrow-top-right mouse"></span>
|
||||
<Modal show={show} onHide={this.toggleShow}>
|
||||
<Modal.Header>
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title>More info</Modal.Title>
|
||||
</Modal.Header>
|
||||
<Modal.Body className="text-center">
|
||||
|
||||
89
resources/js/components/Graphics/TestsTable.js
vendored
89
resources/js/components/Graphics/TestsTable.js
vendored
@@ -26,6 +26,10 @@ export default class TestsTable extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
clearInterval(this.state.interval);
|
||||
}
|
||||
|
||||
getData = (page = this.state.page, refresh = true) => {
|
||||
var url = 'api/speedtest/?page=' + page;
|
||||
|
||||
@@ -83,59 +87,48 @@ export default class TestsTable extends Component {
|
||||
|
||||
if(data.length > 0) {
|
||||
return (
|
||||
<Container className="mb-4 mt-4" fluid>
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="mb-3 text-center">
|
||||
<div className="mouse" aria-controls="testsTable" onClick={this.toggleCollapse} aria-expanded={show}>
|
||||
<h4 className="d-inline mr-2">All tests</h4>
|
||||
{(show) ?
|
||||
<span className="ti-angle-up"></span>
|
||||
:
|
||||
<span className="ti-angle-down"></span>
|
||||
}
|
||||
</div>
|
||||
{(show) &&
|
||||
<div className="my-1">
|
||||
<div>
|
||||
<Container className="mb-4 mt-4 px-5">
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="mb-3 text-center">
|
||||
<div>
|
||||
<h4 className="d-inline mr-2">All tests</h4>
|
||||
<span className="text-muted">Auto refresh: {(refresh) ? 'On' : 'Off'}</span>
|
||||
</div>
|
||||
}
|
||||
</Col>
|
||||
</Row>
|
||||
<Collapse in={show}>
|
||||
<div>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} id="testsTable">
|
||||
<Table responsive>
|
||||
<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 (
|
||||
<TableRow key={e.id} data={e} />
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</Table>
|
||||
</Col>
|
||||
</Row>
|
||||
{page < lastPage &&
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} id="testsTable">
|
||||
<Table responsive>
|
||||
<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 (
|
||||
<TableRow key={e.id} data={e} />
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</Table>
|
||||
<Col sm={{ span: 12 }} className="text-center">
|
||||
<Button variant="primary" onClick={this.getMoreData}>Show more</Button>
|
||||
</Col>
|
||||
</Row>
|
||||
{page < lastPage &&
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="text-center">
|
||||
<Button variant="primary" onClick={this.getMoreData}>Show more</Button>
|
||||
</Col>
|
||||
</Row>
|
||||
}
|
||||
</div>
|
||||
</Collapse>
|
||||
</Container>
|
||||
}
|
||||
</Container>
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
|
||||
102
resources/js/components/Graphics/Widget.js
vendored
102
resources/js/components/Graphics/Widget.js
vendored
@@ -8,37 +8,88 @@ export default class Widget extends Component {
|
||||
|
||||
this.state = {
|
||||
title: this.props.title,
|
||||
value: this.props.value,
|
||||
unit: this.props.unit,
|
||||
icon: this.props.icon,
|
||||
avg: this.props.avg,
|
||||
max: this.props.max,
|
||||
failed: this.props.failed,
|
||||
data: this.props.data
|
||||
}
|
||||
}
|
||||
|
||||
parseData(title, data) {
|
||||
var returnData = {};
|
||||
|
||||
|
||||
if(title == 'Ping') {
|
||||
returnData.value = parseFloat(data.data.ping).toFixed(1);
|
||||
|
||||
if(window.config.widgets.show_average) {
|
||||
returnData.avg = parseFloat(data.average.ping).toFixed(1);
|
||||
}
|
||||
|
||||
if(window.config.widgets.show_max) {
|
||||
returnData.max = parseFloat(data.maximum.ping).toFixed(1);
|
||||
}
|
||||
|
||||
if(window.config.widgets.show_min) {
|
||||
returnData.min = parseFloat(data.minimum.ping).toFixed(1);
|
||||
}
|
||||
}
|
||||
|
||||
if(title == 'Upload') {
|
||||
returnData.value = parseFloat(data.data.upload).toFixed(1);
|
||||
|
||||
if(window.config.widgets.show_average) {
|
||||
returnData.avg = parseFloat(data.average.upload).toFixed(1);
|
||||
}
|
||||
|
||||
if(window.config.widgets.show_max) {
|
||||
returnData.max = parseFloat(data.maximum.upload).toFixed(1);
|
||||
}
|
||||
|
||||
if(window.config.widgets.show_min) {
|
||||
returnData.min = parseFloat(data.minimum.upload).toFixed(1);
|
||||
}
|
||||
}
|
||||
|
||||
if(title == 'Download') {
|
||||
returnData.value = parseFloat(data.data.download).toFixed(1);
|
||||
|
||||
if(window.config.widgets.show_average) {
|
||||
returnData.avg = parseFloat(data.average.download).toFixed(1);
|
||||
}
|
||||
|
||||
if(window.config.widgets.show_max) {
|
||||
returnData.max = parseFloat(data.maximum.download).toFixed(1);
|
||||
}
|
||||
|
||||
if(window.config.widgets.show_min) {
|
||||
returnData.min = parseFloat(data.minimum.download).toFixed(1);
|
||||
}
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
componentDidUpdate = () => {
|
||||
if(this.props.title != this.state.title || this.props.value != this.state.value || this.props.unit != this.state.unit || this.props.icon != this.state.icon || this.props.avg != this.state.avg || this.props.max != this.state.max) {
|
||||
if(this.props.title != this.state.title || this.props.data != this.state.data || this.props.unit != this.state.unit || this.props.icon != this.state.icon || this.props.failed != this.state.failed) {
|
||||
this.setState({
|
||||
title: this.props.title,
|
||||
value: this.props.value,
|
||||
unit: this.props.unit,
|
||||
icon: this.props.icon,
|
||||
avg: this.props.avg,
|
||||
max: this.props.max
|
||||
failed: this.props.failed,
|
||||
data: this.props.data
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
var title = this.state.title;
|
||||
var value = this.state.value;
|
||||
var unit = this.state.unit;
|
||||
var icon = this.state.icon;
|
||||
var max = this.state.max;
|
||||
var avg = this.state.avg;
|
||||
var failed = Boolean(Number(this.state.failed));
|
||||
|
||||
var data = this.parseData(title, this.state.data);
|
||||
|
||||
switch(icon) {
|
||||
case 'ping':
|
||||
icon = <span className="ti-pulse icon text-success"></span>;
|
||||
@@ -62,17 +113,30 @@ export default class Widget extends Component {
|
||||
</div>
|
||||
|
||||
<div className="text-truncate">
|
||||
<h3 className="d-inline">{(!failed) ? value : <span className="ti-close text-danger"></span> }</h3>
|
||||
<h3 className="d-inline">{(!failed) ? data.value : <span className="ti-close text-danger"></span> }</h3>
|
||||
<p className="d-inline ml-2">{unit} (current)</p>
|
||||
</div>
|
||||
<div className="text-muted text-truncate">
|
||||
<h5 className="d-inline">{avg}</h5>
|
||||
<p className="d-inline ml-2">{unit} (average)</p>
|
||||
</div>
|
||||
<div className="text-muted text-truncate">
|
||||
<h5 className="d-inline">{max}</h5>
|
||||
<p className="d-inline ml-2">{unit} (maximum)</p>
|
||||
</div>
|
||||
|
||||
{window.config.widgets.show_average &&
|
||||
<div className="text-muted text-truncate">
|
||||
<h5 className="d-inline">{data.avg}</h5>
|
||||
<p className="d-inline ml-2">{unit} (average)</p>
|
||||
</div>
|
||||
}
|
||||
|
||||
{window.config.widgets.show_max &&
|
||||
<div className="text-muted text-truncate">
|
||||
<h5 className="d-inline">{data.max}</h5>
|
||||
<p className="d-inline ml-2">{unit} (maximum)</p>
|
||||
</div>
|
||||
}
|
||||
|
||||
{window.config.widgets.show_min &&
|
||||
<div className="text-muted text-truncate">
|
||||
<h5 className="d-inline">{data.min}</h5>
|
||||
<p className="d-inline ml-2">{unit} (minimum)</p>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</Card.Body>
|
||||
|
||||
11
resources/js/components/Home/HomePage.js
vendored
11
resources/js/components/Home/HomePage.js
vendored
@@ -5,19 +5,22 @@ import LatestResults from '../Graphics/LatestResults';
|
||||
import Footer from './Footer';
|
||||
import DataRow from '../Data/DataRow';
|
||||
import TestsTable from '../Graphics/TestsTable';
|
||||
import Settings from '../Settings/Settings';
|
||||
import Login from '../Login';
|
||||
import Authentication from '../Authentication/Authentication';
|
||||
import Navbar from '../Navbar';
|
||||
|
||||
export default class HomePage extends Component {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<Navbar />
|
||||
<div className="my-4">
|
||||
{(window.config.auth == true && window.authenticated == false) &&
|
||||
<Login />
|
||||
}
|
||||
<LatestResults />
|
||||
<HistoryGraph />
|
||||
<TestsTable />
|
||||
<Settings />
|
||||
<DataRow />
|
||||
</div>
|
||||
<Footer />
|
||||
</div>
|
||||
|
||||
78
resources/js/components/Login.js
vendored
78
resources/js/components/Login.js
vendored
@@ -1,10 +1,11 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Container, Row, Form, Toast } from 'react-bootstrap';
|
||||
import { Container, Row, Form, Toast, Modal } from 'react-bootstrap';
|
||||
import { Col } from 'react-bootstrap';
|
||||
import { Button } from 'react-bootstrap';
|
||||
import Axios from 'axios';
|
||||
import { toast } from 'react-toastify';
|
||||
import Cookies from 'js-cookie';
|
||||
|
||||
export default class Login extends Component {
|
||||
constructor(props) {
|
||||
@@ -12,59 +13,78 @@ export default class Login extends Component {
|
||||
|
||||
this.state = {
|
||||
loginEmailInput: '',
|
||||
loginPasswordInput: '',
|
||||
toast: null,
|
||||
loginPasswordInput: ''
|
||||
}
|
||||
}
|
||||
|
||||
updateTextField = (e) => {
|
||||
this.setState({
|
||||
[e.target.id]: e.target.value
|
||||
})
|
||||
}
|
||||
|
||||
login = (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
var data = {
|
||||
email: this.state.loginEmailInput,
|
||||
password: this.state.loginPasswordInput
|
||||
};
|
||||
var url = 'api/auth/login';
|
||||
}
|
||||
|
||||
var url = 'api/auth/login';
|
||||
Axios.post(url, data)
|
||||
.then((resp) => {
|
||||
var token = resp.data;
|
||||
this.props.setToken(token);
|
||||
var token = resp.data.access_token;
|
||||
var expires = (resp.data.expires_in / 60) / 24;
|
||||
Cookies.set('auth', token, { expires: expires })
|
||||
window.location.reload(true);
|
||||
})
|
||||
.catch((err) => {
|
||||
toast.error('Something went wrong. Please try again.')
|
||||
});
|
||||
toast.error('Something went wrong logging in.');
|
||||
})
|
||||
}
|
||||
|
||||
updateTextField = (e) => {
|
||||
this.setState({
|
||||
[e.target.id]: e.target.value
|
||||
});
|
||||
toggleShow = () => {
|
||||
if(this.state.show) {
|
||||
this.setState({
|
||||
show: false
|
||||
})
|
||||
} else {
|
||||
this.setState({
|
||||
show: true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
var error = this.state.error;
|
||||
var show = this.state.show;
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<Row className="fullscreen align-items-center">
|
||||
<Row>
|
||||
<Col
|
||||
lg={{ span: 4, offset: 4 }}
|
||||
md={{ span: 6, offset: 3 }}
|
||||
sm={{ span: 10, offset: 1 }}
|
||||
xs={{ span: 12 }}
|
||||
className="pb-2 text-center"
|
||||
>
|
||||
<Form onSubmit={this.login}>
|
||||
<Form.Group controlId="loginEmailInput">
|
||||
<Form.Label>Email address</Form.Label>
|
||||
<Form.Control type="email" placeholder="admin@admin.com" onInput={this.updateTextField} required />
|
||||
</Form.Group>
|
||||
<Form.Group controlId="loginPasswordInput">
|
||||
<Form.Label>Password</Form.Label>
|
||||
<Form.Control type="password" onInput={this.updateTextField} required />
|
||||
</Form.Group>
|
||||
<Button variant="primary" type="submit">Login</Button>
|
||||
</Form>
|
||||
<Button variant="primary" onClick={this.toggleShow}>Login</Button>
|
||||
<Modal show={show} onHide={this.toggleShow}>
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title>Login</Modal.Title>
|
||||
</Modal.Header>
|
||||
<Modal.Body>
|
||||
<Form onSubmit={this.login}>
|
||||
<Form.Group controlId="loginEmailInput">
|
||||
<Form.Label>Email address</Form.Label>
|
||||
<Form.Control type="email" placeholder="admin@admin.com" onInput={this.updateTextField} required />
|
||||
</Form.Group>
|
||||
<Form.Group controlId="loginPasswordInput">
|
||||
<Form.Label>Password</Form.Label>
|
||||
<Form.Control type="password" onInput={this.updateTextField} required />
|
||||
</Form.Group>
|
||||
<Button variant="primary" type="submit">Login</Button>
|
||||
</Form>
|
||||
</Modal.Body>
|
||||
</Modal>
|
||||
</Col>
|
||||
</Row>
|
||||
</Container>
|
||||
|
||||
64
resources/js/components/Navbar.js
vendored
64
resources/js/components/Navbar.js
vendored
@@ -1,19 +1,77 @@
|
||||
import React, { Component } from 'react';
|
||||
import {Nav, Navbar as BootstrapNavbar, NavLink as BootstrapNavLink} from 'react-bootstrap';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Link, NavLink } from 'react-router-dom';
|
||||
|
||||
export default class Navbar extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
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() {
|
||||
var brand = this.state.brand;
|
||||
var pages = this.generateLinks();
|
||||
|
||||
return (
|
||||
<div>
|
||||
</div>
|
||||
<BootstrapNavbar variant="dark" bg="dark" expand="sm">
|
||||
<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>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
77
resources/js/components/Settings/Setting.js
vendored
77
resources/js/components/Settings/Setting.js
vendored
@@ -1,77 +0,0 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Card, Form, Button } from 'react-bootstrap';
|
||||
import Axios from 'axios';
|
||||
import { toast } from 'react-toastify';
|
||||
|
||||
export default class Setting extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
name: this.props.name,
|
||||
value: this.props.value,
|
||||
description: this.props.description,
|
||||
}
|
||||
}
|
||||
|
||||
ucfirst(string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
}
|
||||
|
||||
update = () => {
|
||||
var url = 'api/settings';
|
||||
var data = {
|
||||
name: this.state.name,
|
||||
value: this.state.value
|
||||
};
|
||||
|
||||
Axios.post(url, data)
|
||||
.then((resp) => {
|
||||
toast.success(this.ucfirst(this.state.name) + ' updated');
|
||||
})
|
||||
.catch((err) => {
|
||||
if(err.response.status == 422) {
|
||||
var errors = err.response.data.error;
|
||||
for(var key in errors) {
|
||||
var error = errors[key];
|
||||
toast.error(error[0])
|
||||
}
|
||||
} else {
|
||||
toast.error('Something went wrong')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
updateValue = (e) => {
|
||||
this.setState({
|
||||
value: e.target.value
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
var name = this.state.name;
|
||||
var value = this.state.value;
|
||||
var description = this.state.description;
|
||||
|
||||
return (
|
||||
<Card className="m-2 setting-card">
|
||||
<Card.Body className="d-flex align-items-center">
|
||||
<div>
|
||||
<h4>{this.ucfirst(name)}</h4>
|
||||
<div dangerouslySetInnerHTML={{ __html: description}} />
|
||||
<Form.Group controlId={name}>
|
||||
<Form.Label>{this.ucfirst(name)}</Form.Label>
|
||||
<Form.Control type="text" label={name} defaultValue={value} onInput={this.updateValue} />
|
||||
</Form.Group>
|
||||
<Button variant="primary" onClick={this.update}>Save</Button>
|
||||
</div>
|
||||
</Card.Body>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('Setting')) {
|
||||
ReactDOM.render(<Setting />, document.getElementById('Setting'));
|
||||
}
|
||||
263
resources/js/components/Settings/SettingWithModal.js
vendored
263
resources/js/components/Settings/SettingWithModal.js
vendored
@@ -1,263 +0,0 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Card, Form, Button, Modal, Row, Col } from 'react-bootstrap';
|
||||
import Axios from 'axios';
|
||||
import { toast } from 'react-toastify';
|
||||
import SettingsModalCard from '../Settings/SettingsModalCard';
|
||||
|
||||
export default class SettingWithModal extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
title: this.props.title,
|
||||
description: this.props.description,
|
||||
settings: this.props.settings,
|
||||
show: false,
|
||||
autoClose: this.props.autoClose
|
||||
}
|
||||
}
|
||||
|
||||
ucfirst(string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
}
|
||||
|
||||
update = () => {
|
||||
var url = 'api/settings/bulk';
|
||||
var data = [];
|
||||
var settings = this.state.settings;
|
||||
|
||||
settings.forEach(e => {
|
||||
if(e.type !== 'button-get') {
|
||||
var res = {
|
||||
name: e.obj.name,
|
||||
value: e.obj.value
|
||||
};
|
||||
data.push(res);
|
||||
}
|
||||
});
|
||||
|
||||
data = {
|
||||
data: data
|
||||
};
|
||||
|
||||
Axios.post(url, data)
|
||||
.then((resp) => {
|
||||
toast.success(this.state.title + ' updated');
|
||||
if(this.state.autoClose) {
|
||||
this.toggleShow();
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
if(err.response.status == 422) {
|
||||
toast.error('Your input was invalid');
|
||||
} else {
|
||||
toast.error('Something went wrong')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
updateValue = (e) => {
|
||||
var name = e.target.id;
|
||||
if(e.target.type == 'checkbox') {
|
||||
var val = e.target.checked;
|
||||
} else {
|
||||
var val = e.target.value;
|
||||
}
|
||||
var settings = this.state.settings;
|
||||
var i = 0;
|
||||
settings.forEach(ele => {
|
||||
if(ele.obj.name == name) {
|
||||
ele.obj.value = val;
|
||||
}
|
||||
settings[i] = ele;
|
||||
i++;
|
||||
});
|
||||
this.setState({
|
||||
settings: settings
|
||||
});
|
||||
}
|
||||
|
||||
toggleShow = () => {
|
||||
var show = this.state.show;
|
||||
if(show) {
|
||||
this.setState({
|
||||
show: false
|
||||
});
|
||||
} else {
|
||||
this.setState({
|
||||
show: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
var title = this.state.title;
|
||||
var description = this.state.description;
|
||||
var show = this.state.show;
|
||||
var settings = this.state.settings;
|
||||
|
||||
return (
|
||||
<>
|
||||
<SettingsModalCard title={title} description={description} toggleShow={this.toggleShow} />
|
||||
<Modal show={show} onHide={this.toggleShow}>
|
||||
<Modal.Header>
|
||||
<Modal.Title>{title}</Modal.Title>
|
||||
</Modal.Header>
|
||||
<Modal.Body>
|
||||
{settings.map((e,i) => {
|
||||
var name = e.obj.name.split('_');
|
||||
name[0] = this.ucfirst(name[0]);
|
||||
name = name.join(' ');
|
||||
|
||||
if(e.obj.description == null || e.obj.description == '') {
|
||||
var sm = { span: 12 };
|
||||
var md = { span: 12 };
|
||||
} else {
|
||||
var sm = { span: 12 };
|
||||
var md = { span: 6 };
|
||||
}
|
||||
|
||||
var readonly = false;
|
||||
if(window.config.editable[e.obj.name] == false) {
|
||||
readonly = true;
|
||||
}
|
||||
|
||||
if(e.type == 'info') {
|
||||
return (
|
||||
<Row key={e.obj.id} className="d-flex align-items-center">
|
||||
<Col md={md} sm={sm}>
|
||||
<p>{e.obj.content}</p>
|
||||
</Col>
|
||||
</Row>
|
||||
)
|
||||
} else if(e.type == 'checkbox') {
|
||||
return (
|
||||
<Row key={e.obj.id} className="d-flex align-items-center">
|
||||
<Col md={md} sm={sm}>
|
||||
<Form.Group controlId={e.obj.name}>
|
||||
{readonly ?
|
||||
<>
|
||||
<Form.Check type="checkbox" disabled label={name} defaultChecked={Boolean(Number(e.obj.value))} onInput={this.updateValue} />
|
||||
<Form.Text className="text-muted">This setting is defined as an env variable and is not editable.</Form.Text>
|
||||
</>
|
||||
:
|
||||
<Form.Check type="checkbox" label={name} defaultChecked={Boolean(Number(e.obj.value))} onInput={this.updateValue} />
|
||||
}
|
||||
</Form.Group>
|
||||
</Col>
|
||||
{e.description == null &&
|
||||
<Col md={md} sm={sm}>
|
||||
<p>{e.obj.description}</p>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
);
|
||||
} else if(e.type == 'number') {
|
||||
return (
|
||||
<Row key={e.obj.id}>
|
||||
<Col md={md} sm={sm}>
|
||||
<Form.Group controlId={e.obj.name}>
|
||||
<Form.Label>{name}</Form.Label>
|
||||
{readonly ?
|
||||
<>
|
||||
<Form.Control type="number" disabled min={e.min} max={e.max} defaultValue={e.obj.value} onInput={this.updateValue} />
|
||||
<Form.Text className="text-muted">This setting is defined as an env variable and is not editable.</Form.Text>
|
||||
</>
|
||||
:
|
||||
<Form.Control type="number" min={e.min} max={e.max} defaultValue={e.obj.value} onInput={this.updateValue} />
|
||||
}
|
||||
</Form.Group>
|
||||
</Col>
|
||||
{e.description == null &&
|
||||
<Col md={md} sm={sm}>
|
||||
<p>{e.obj.description}</p>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
);
|
||||
} else if(e.type == 'text') {
|
||||
return (
|
||||
<Row key={e.obj.id}>
|
||||
<Col md={md} sm={sm}>
|
||||
<Form.Group controlId={e.obj.name}>
|
||||
<Form.Label>{name}</Form.Label>
|
||||
{readonly ?
|
||||
<>
|
||||
<Form.Control type="text" disabled defaultValue={e.obj.value} onInput={this.updateValue} />
|
||||
<Form.Text className="text-muted">This setting is defined as an env variable and is not editable.</Form.Text>
|
||||
</>
|
||||
:
|
||||
<Form.Control type="text" defaultValue={e.obj.value} onInput={this.updateValue} />
|
||||
}
|
||||
</Form.Group>
|
||||
</Col>
|
||||
{e.description == null &&
|
||||
<Col md={md} sm={sm}>
|
||||
<p>{e.obj.description}</p>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
);
|
||||
} else if(e.type == 'select') {
|
||||
return (
|
||||
<Row key={e.obj.id}>
|
||||
<Col md={md} sm={sm}>
|
||||
<Form.Group controlId={e.obj.name}>
|
||||
<Form.Label>{name}</Form.Label>
|
||||
{readonly ?
|
||||
<>
|
||||
<Form.Control as="select" disabled defaultValue={e.obj.value} onInput={this.updateValue}>
|
||||
{e.options.map((e,i) => {
|
||||
return (
|
||||
<option key={i} value={e.value}>{e.name}</option>
|
||||
)
|
||||
})}
|
||||
</Form.Control>
|
||||
<Form.Text className="text-muted">This setting is defined as an env variable and is not editable.</Form.Text>
|
||||
</>
|
||||
:
|
||||
<Form.Control as="select" defaultValue={e.obj.value} onInput={this.updateValue}>
|
||||
{e.options.map((e,i) => {
|
||||
return (
|
||||
<option key={i} value={e.value}>{e.name}</option>
|
||||
)
|
||||
})}
|
||||
</Form.Control>
|
||||
}
|
||||
</Form.Group>
|
||||
</Col>
|
||||
{e.description == null &&
|
||||
<Col md={md} sm={sm}>
|
||||
<p>{e.obj.description}</p>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
)
|
||||
} else if(e.type == 'button-get') {
|
||||
return (
|
||||
<Row key={e.obj.id}>
|
||||
<Col md={md} sm={sm}>
|
||||
<p>{name}</p>
|
||||
<Button onClick={() => { Axios.get(e.url) }} >{name}</Button>
|
||||
</Col>
|
||||
{e.description == null &&
|
||||
<Col md={md} sm={sm}>
|
||||
<p>{e.obj.description}</p>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
)
|
||||
}
|
||||
})}
|
||||
<Button variant="primary" type="submit" onClick={this.update} >Save</Button>
|
||||
</Modal.Body>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('Setting')) {
|
||||
ReactDOM.render(<Setting />, document.getElementById('Setting'));
|
||||
}
|
||||
213
resources/js/components/Settings/Settings.js
vendored
213
resources/js/components/Settings/Settings.js
vendored
@@ -1,213 +0,0 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Modal, Container, Row, Col, Collapse } from 'react-bootstrap';
|
||||
import Loader from '../Loader';
|
||||
import Axios from 'axios';
|
||||
import Setting from './Setting';
|
||||
import SettingWithModal from './SettingWithModal';
|
||||
import ResetSettings from './ResetSettings';
|
||||
|
||||
export default class Settings extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
show: false,
|
||||
loading: true,
|
||||
data: [],
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount = () => {
|
||||
this.getData();
|
||||
}
|
||||
|
||||
toggleShow = () => {
|
||||
if(this.state.show) {
|
||||
var show = false;
|
||||
} else {
|
||||
var show = true;
|
||||
}
|
||||
|
||||
this.setState({
|
||||
show: show
|
||||
});
|
||||
}
|
||||
|
||||
getData = () => {
|
||||
var url = 'api/settings/';
|
||||
|
||||
Axios.get(url)
|
||||
.then((resp) => {
|
||||
this.setState({
|
||||
loading: false,
|
||||
data: resp.data
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
if(err.response) {
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
buildSettingsCards = () => {
|
||||
var e = this.state.data;
|
||||
return (
|
||||
<Row>
|
||||
<Col lg={{ span: 4 }} md={{ span: 6 }} sm={{ span: 12 }}>
|
||||
<Setting name={e.schedule.name} value={e.schedule.value} description={e.schedule.description} />
|
||||
</Col>
|
||||
<Col lg={{ span: 4 }} md={{ span: 6 }} sm={{ span: 12 }}>
|
||||
<Setting name={e.server.name} value={e.server.value} description={e.server.description} />
|
||||
</Col>
|
||||
<Col lg={{ span: 4 }} md={{ span: 6 }} sm={{ span: 12 }}>
|
||||
<SettingWithModal title="Graph settings" description="Control settings for the graphs." autoClose={true} settings={[
|
||||
{
|
||||
obj: e.download_upload_graph_enabled,
|
||||
type: 'checkbox'
|
||||
},
|
||||
{
|
||||
obj: e.download_upload_graph_width,
|
||||
type: 'select',
|
||||
options: [
|
||||
{
|
||||
name: 'Full-width',
|
||||
'value': 12
|
||||
},
|
||||
{
|
||||
name: 'Half-width',
|
||||
'value': 6
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
obj: e.ping_graph_enabled,
|
||||
type: 'checkbox'
|
||||
},
|
||||
{
|
||||
obj: e.ping_graph_width,
|
||||
type: 'select',
|
||||
options: [
|
||||
{
|
||||
name: 'Full-width',
|
||||
'value': 12
|
||||
},
|
||||
{
|
||||
name: 'Half-width',
|
||||
'value': 6
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
obj: e.failure_graph_enabled,
|
||||
type: 'checkbox'
|
||||
},
|
||||
{
|
||||
obj: e.failure_graph_width,
|
||||
type: 'select',
|
||||
options: [
|
||||
{
|
||||
name: 'Full-width',
|
||||
'value': 12
|
||||
},
|
||||
{
|
||||
name: 'Half-width',
|
||||
'value': 6
|
||||
}
|
||||
],
|
||||
}
|
||||
]} />
|
||||
</Col>
|
||||
<Col lg={{ span: 4 }} md={{ span: 6 }} sm={{ span: 12 }}>
|
||||
<SettingWithModal title="Notification settings" description="Control which types of notifications the server sends." autoClose={false} settings={[
|
||||
{
|
||||
obj: e.slack_webhook,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
obj: e.telegram_bot_token,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
obj: e.telegram_chat_id,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
obj: {
|
||||
id: (Math.floor(Math.random() * 10000) + 1),
|
||||
name: "Test notifications",
|
||||
description: "After saving your updated notification settings, use this to check your settings are correct."
|
||||
},
|
||||
type: 'button-get',
|
||||
url: 'api/settings/test-notification'
|
||||
},
|
||||
{
|
||||
obj: e.speedtest_notifications,
|
||||
type: 'checkbox'
|
||||
},
|
||||
{
|
||||
obj: e.speedtest_overview_notification,
|
||||
type: 'checkbox'
|
||||
},
|
||||
{
|
||||
obj: e.speedtest_overview_time,
|
||||
type: 'number',
|
||||
min: 0,
|
||||
max: 23
|
||||
}
|
||||
]} />
|
||||
</Col>
|
||||
<Col lg={{ span: 4 }} md={{ span: 6 }} sm={{ span: 12 }}>
|
||||
<ResetSettings />
|
||||
</Col>
|
||||
</Row>
|
||||
)
|
||||
}
|
||||
|
||||
render() {
|
||||
var show = this.state.show;
|
||||
var loading = this.state.loading;
|
||||
var data = this.state.data;
|
||||
if(!loading) {
|
||||
var cards = this.buildSettingsCards();
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Container className="my-4">
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="mb-3 text-center">
|
||||
<div className="mouse" onClick={this.toggleShow}>
|
||||
<h4 className="mb-0 mr-2 d-inline">Settings</h4>
|
||||
{(show) ?
|
||||
<span className="ti-angle-up"></span>
|
||||
:
|
||||
<span className="ti-angle-down"></span>
|
||||
}
|
||||
</div>
|
||||
</Col>
|
||||
</Row>
|
||||
<Collapse in={show}>
|
||||
<div>
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }}>
|
||||
{loading ?
|
||||
<Loader small />
|
||||
:
|
||||
cards
|
||||
}
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
</Collapse>
|
||||
</Container>
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('Settings')) {
|
||||
ReactDOM.render(<Settings />, document.getElementById('Settings'));
|
||||
}
|
||||
282
resources/js/components/Settings/SettingsIndex.js
vendored
Normal file
282
resources/js/components/Settings/SettingsIndex.js
vendored
Normal file
@@ -0,0 +1,282 @@
|
||||
import Axios from 'axios';
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import Footer from '../Home/Footer';
|
||||
import Loader from '../Loader';
|
||||
import Navbar from '../Navbar';
|
||||
import SettingsTabs from './SettingsTabs';
|
||||
|
||||
export default class SettingsIndex extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
data: null,
|
||||
loading: true,
|
||||
}
|
||||
}
|
||||
|
||||
getData = () => {
|
||||
var url = 'api/settings/?token=' + window.token;
|
||||
|
||||
Axios.get(url)
|
||||
.then((resp) => {
|
||||
this.setState({
|
||||
data: this.sortSettings(resp.data),
|
||||
loading: false,
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
//
|
||||
})
|
||||
}
|
||||
|
||||
sortSettings = (data) => {
|
||||
return {
|
||||
General: [
|
||||
{
|
||||
obj: data.app_name,
|
||||
type: 'text',
|
||||
},
|
||||
{
|
||||
obj: data.schedule_enabled,
|
||||
type: 'checkbox',
|
||||
},
|
||||
{
|
||||
obj: data.schedule,
|
||||
type: 'text',
|
||||
},
|
||||
{
|
||||
obj: data.server,
|
||||
type: 'text',
|
||||
},
|
||||
{
|
||||
obj: data.show_average,
|
||||
type: 'checkbox',
|
||||
},
|
||||
{
|
||||
obj: data.show_max,
|
||||
type: 'checkbox',
|
||||
},
|
||||
{
|
||||
obj: data.show_min,
|
||||
type: 'checkbox',
|
||||
}
|
||||
],
|
||||
Graphs: [
|
||||
{
|
||||
obj: data.download_upload_graph_enabled,
|
||||
type: 'checkbox',
|
||||
hideDescription: true
|
||||
},
|
||||
{
|
||||
obj: data.download_upload_graph_width,
|
||||
type: 'select',
|
||||
options: [
|
||||
{
|
||||
name: 'Full-width',
|
||||
'value': 12
|
||||
},
|
||||
{
|
||||
name: 'Half-width',
|
||||
'value': 6
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
obj: data.ping_graph_enabled,
|
||||
type: 'checkbox',
|
||||
hideDescription: true
|
||||
},
|
||||
{
|
||||
obj: data.ping_graph_width,
|
||||
type: 'select',
|
||||
options: [
|
||||
{
|
||||
name: 'Full-width',
|
||||
'value': 12
|
||||
},
|
||||
{
|
||||
name: 'Half-width',
|
||||
'value': 6
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
obj: data.failure_graph_enabled,
|
||||
type: 'checkbox',
|
||||
hideDescription: true
|
||||
},
|
||||
{
|
||||
obj: data.failure_graph_width,
|
||||
type: 'select',
|
||||
options: [
|
||||
{
|
||||
name: 'Full-width',
|
||||
'value': 12
|
||||
},
|
||||
{
|
||||
name: 'Half-width',
|
||||
'value': 6
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
obj: data.show_failed_tests_on_graph,
|
||||
type: 'checkbox',
|
||||
},
|
||||
],
|
||||
Notifications: [
|
||||
{
|
||||
obj: data.slack_webhook,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
obj: data.telegram_bot_token,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
obj: data.telegram_chat_id,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
type: 'btn-get',
|
||||
url: 'api/settings/test-notification?token=' + window.token,
|
||||
btnType: 'primary',
|
||||
obj: {
|
||||
id: (Math.floor(Math.random() * 10000) + 1),
|
||||
name: 'Test notifications',
|
||||
description: 'After saving your updated notification settings, use this to check your settings are correct.'
|
||||
}
|
||||
},
|
||||
{
|
||||
obj: data.speedtest_notifications,
|
||||
type: 'checkbox'
|
||||
},
|
||||
{
|
||||
obj: data.speedtest_overview_notification,
|
||||
type: 'checkbox'
|
||||
},
|
||||
{
|
||||
obj: data.speedtest_overview_time,
|
||||
type: 'number',
|
||||
min: 0,
|
||||
max: 23,
|
||||
},
|
||||
// Add handling for title stuff
|
||||
{
|
||||
obj: data.threshold_alert_percentage,
|
||||
type: 'number',
|
||||
min: 0,
|
||||
max: 100
|
||||
},
|
||||
{
|
||||
obj: data.threshold_alert_absolute_notifications,
|
||||
type: 'checkbox'
|
||||
},
|
||||
{
|
||||
obj: data.threshold_alert_absolute_download,
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
obj: data.threshold_alert_absolute_upload,
|
||||
type: 'number'
|
||||
},
|
||||
{
|
||||
obj: data.threshold_alert_absolute_ping,
|
||||
type: 'number'
|
||||
},
|
||||
],
|
||||
healthchecks: [
|
||||
{
|
||||
obj: data.healthchecks_enabled,
|
||||
type: 'checkbox'
|
||||
},
|
||||
{
|
||||
obj: data.healthchecks_server_url,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
obj: data.healthchecks_uuid,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
obj: {
|
||||
id: (Math.floor(Math.random() * 10000) + 1),
|
||||
name: "Test healthchecks.io integration",
|
||||
description: ""
|
||||
},
|
||||
},
|
||||
{
|
||||
obj: {
|
||||
id: (Math.floor(Math.random() * 10000) + 1),
|
||||
name: "Start",
|
||||
description: ""
|
||||
},
|
||||
type: 'btn-get',
|
||||
url: 'api/settings/test-healthchecks/start?token=' + window.token,
|
||||
btnType: 'outline-success',
|
||||
inline: true,
|
||||
earlyReturn: true,
|
||||
classes: 'mr-2'
|
||||
},
|
||||
{
|
||||
obj: {
|
||||
id: (Math.floor(Math.random() * 10000) + 1),
|
||||
name: "Success",
|
||||
description: ""
|
||||
},
|
||||
type: 'btn-get',
|
||||
url: 'api/settings/test-healthchecks/success?token=' + window.token,
|
||||
btnType: 'success',
|
||||
text: 'Success',
|
||||
inline: true,
|
||||
earlyReturn: true,
|
||||
classes: 'mr-2'
|
||||
},
|
||||
{
|
||||
obj: {
|
||||
id: (Math.floor(Math.random() * 10000) + 1),
|
||||
name: "Fail",
|
||||
description: ""
|
||||
},
|
||||
type: 'btn-get',
|
||||
url: 'api/settings/test-healthchecks/fail?token=' + window.token,
|
||||
btnType: 'danger',
|
||||
text: 'Fail',
|
||||
inline: true,
|
||||
earlyReturn: true,
|
||||
classes: 'mr-2'
|
||||
},
|
||||
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.getData();
|
||||
}
|
||||
|
||||
render() {
|
||||
var data = this.state.data;
|
||||
var loading = this.state.loading;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Navbar />
|
||||
<div className="container my-5">
|
||||
{loading ?
|
||||
<Loader />
|
||||
:
|
||||
<SettingsTabs data={data} />
|
||||
}
|
||||
</div>
|
||||
<Footer />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('settingsIndex')) {
|
||||
ReactDOM.render(<SettingsIndex />, document.getElementById('settingsIndex'));
|
||||
}
|
||||
185
resources/js/components/Settings/SettingsInput.js
vendored
Normal file
185
resources/js/components/Settings/SettingsInput.js
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
import React, { Component } from 'react';
|
||||
import { Form } from 'react-bootstrap';
|
||||
import ReactDOM from 'react-dom';
|
||||
|
||||
export default class SettingsInput extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
type: this.props.type,
|
||||
name: this.props.name,
|
||||
displayName: (this.props.name) ? this.formatName(this.props.name) : '',
|
||||
value: (this.props.value) ? this.props.value : '',
|
||||
classes: this.props.classes,
|
||||
id: this.props.id,
|
||||
label: (this.props.label) ? this.props.label : false,
|
||||
readonly: true,
|
||||
description: (this.props.description) ? this.props.description : false,
|
||||
options: this.props.options ? this.props.options : [],
|
||||
hideDescription: this.props.hideDescription ? true : false,
|
||||
min: this.props.min ? this.props.min : null,
|
||||
max: this.props.max ? this.props.max : null,
|
||||
url: this.props.url,
|
||||
inline: this.props.inline ? 'd-inline-block' : 'd-block',
|
||||
btnType: this.props.btnType,
|
||||
earlyReturn: this.props.earlyReturn ? true : false,
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.setState({
|
||||
readonly: this.isReadOnly()
|
||||
});
|
||||
}
|
||||
|
||||
formatName(name) {
|
||||
name = name.split('_').join(' ');
|
||||
|
||||
return name.charAt(0).toUpperCase() + name.slice(1);
|
||||
}
|
||||
|
||||
handleInput = (evt) => {
|
||||
var val = evt.target.value;
|
||||
|
||||
if(this.state.type === 'checkbox') {
|
||||
val = evt.target.checked;
|
||||
}
|
||||
|
||||
this.props.handler(
|
||||
this.state.name,
|
||||
val
|
||||
);
|
||||
|
||||
this.setState({
|
||||
value: val
|
||||
});
|
||||
}
|
||||
|
||||
isReadOnly = () => {
|
||||
if(window.config.editable[this.state.name] == false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
generateNumberInput(disabled) {
|
||||
return <Form.Control
|
||||
name={this.state.name}
|
||||
type={this.state.type}
|
||||
defaultValue={this.state.value}
|
||||
disabled={disabled}
|
||||
min={this.state.min}
|
||||
max={this.state.max}
|
||||
onInput={this.handleInput} />
|
||||
}
|
||||
|
||||
generateSelectInput(disabled) {
|
||||
return (
|
||||
<Form.Control
|
||||
as="select"
|
||||
name={this.state.name}
|
||||
type={this.state.type}
|
||||
defaultValue={this.state.value}
|
||||
disabled={disabled}
|
||||
onInput={this.handleInput}
|
||||
>
|
||||
{this.state.options.map((option,i) => {
|
||||
return <option key={i} value={option.value}>{option.name}</option>
|
||||
})}
|
||||
</Form.Control>
|
||||
);
|
||||
}
|
||||
|
||||
generateCheckboxInput(disabled) {
|
||||
return <Form.Control
|
||||
custom
|
||||
className="ml-2"
|
||||
name={this.state.name}
|
||||
type={this.state.type}
|
||||
defaultChecked={this.state.value}
|
||||
disabled={disabled}
|
||||
onInput={this.handleInput} />
|
||||
}
|
||||
|
||||
generateTextInput(disabled) {
|
||||
return <Form.Control
|
||||
name={this.state.name}
|
||||
type={this.state.type}
|
||||
defaultValue={this.state.value}
|
||||
disabled={disabled}
|
||||
onInput={this.handleInput} />
|
||||
}
|
||||
|
||||
generateButtonGetInput() {
|
||||
var url = this.state.url;
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className={"btn btn-" + this.state.btnType + ' ' + this.state.inline + ' ' + this.state.classes}
|
||||
onClick={() => {
|
||||
window.axios.get(url)
|
||||
}}
|
||||
>{this.state.displayName}</button>
|
||||
);
|
||||
}
|
||||
|
||||
generateInput = () => {
|
||||
var disabled = (this.state.readonly) ? true : false;
|
||||
var input = null;
|
||||
|
||||
if(this.state.type === 'number') {
|
||||
input = this.generateNumberInput(disabled);
|
||||
}
|
||||
|
||||
if(this.state.type === 'select') {
|
||||
input = this.generateSelectInput(disabled);
|
||||
}
|
||||
|
||||
if(this.state.type === 'checkbox') {
|
||||
input = this.generateCheckboxInput(disabled);
|
||||
}
|
||||
|
||||
if(this.state.type === 'text') {
|
||||
input = this.generateTextInput(disabled);
|
||||
}
|
||||
|
||||
if(this.state.type === 'btn-get') {
|
||||
input = this.generateButtonGetInput();
|
||||
}
|
||||
|
||||
if(this.state.earlyReturn) {
|
||||
return input;
|
||||
}
|
||||
|
||||
return (
|
||||
<Form.Group controlId={this.state.id}>
|
||||
{this.state.label &&
|
||||
<Form.Label style={{fontSize: '1.25rem'}}>{this.formatName(this.state.name)}</Form.Label>
|
||||
}
|
||||
|
||||
{input}
|
||||
|
||||
{this.state.description && !this.state.hideDescription &&
|
||||
<p className="mt-1 text-muted" dangerouslySetInnerHTML={{ __html: this.state.description }}></p>
|
||||
}
|
||||
|
||||
{this.state.readonly &&
|
||||
<Form.Text className="text-muted">This setting is defined as an env variable and is not editable.</Form.Text>
|
||||
}
|
||||
</Form.Group>
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
var input = this.generateInput();
|
||||
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('SettingsInput')) {
|
||||
ReactDOM.render(<SettingsInput />, document.getElementById('SettingsInput'));
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Card, Button } from 'react-bootstrap';
|
||||
|
||||
export default class SettingsModalCard extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
title: this.props.title,
|
||||
description: this.props.description,
|
||||
toggleShow: this.props.toggleShow,
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
var title = this.state.title;
|
||||
var description = this.state.description;
|
||||
var toggleShow = this.state.toggleShow;
|
||||
|
||||
return (
|
||||
<Card className="m-2 setting-card">
|
||||
<Card.Body className="d-flex align-items-center">
|
||||
<div>
|
||||
<h4>{title}</h4>
|
||||
<p>{description}</p>
|
||||
<Button variant="primary" onClick={toggleShow}>Edit</Button>
|
||||
</div>
|
||||
</Card.Body>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('SettingModalCard')) {
|
||||
ReactDOM.render(<SettingsModalCard />, document.getElementById('SettingModalCard'));
|
||||
}
|
||||
177
resources/js/components/Settings/SettingsTabs.js
vendored
Normal file
177
resources/js/components/Settings/SettingsTabs.js
vendored
Normal file
@@ -0,0 +1,177 @@
|
||||
import Axios from 'axios';
|
||||
import React, { Component } from 'react';
|
||||
import { Nav, Tab, Tabs } from 'react-bootstrap';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { toast } from 'react-toastify';
|
||||
import SettingsInput from './SettingsInput';
|
||||
import ResetSettings from './tabs/ResetSettings';
|
||||
import BackupSettings from './tabs/BackupSettings';
|
||||
import GeneralSettings from './tabs/GeneralSettings';
|
||||
import GraphsSettings from './tabs/GraphsSettings';
|
||||
import HealthchecksSettings from './tabs/HealthchecksSettings';
|
||||
import NotificationsSettings from './tabs/NotificationsSettings';
|
||||
import Authentication from '../Authentication/Authentication';
|
||||
|
||||
export default class SettingsTabs extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
tab: "General",
|
||||
data: this.props.data
|
||||
}
|
||||
}
|
||||
|
||||
generateTabs = () => {
|
||||
var tabs = [
|
||||
'General',
|
||||
'Graphs',
|
||||
'Notifications',
|
||||
'healthchecks.io',
|
||||
'Reset',
|
||||
'Backup/Restore',
|
||||
];
|
||||
|
||||
if(window.config.auth) {
|
||||
tabs.push('Authentication');
|
||||
}
|
||||
|
||||
return tabs.map((tab) => {
|
||||
return <Tab key={tab} eventKey={tab} title={tab} />
|
||||
});
|
||||
}
|
||||
|
||||
switchTab = (tab) => {
|
||||
this.setState({
|
||||
tab: tab
|
||||
});
|
||||
}
|
||||
|
||||
save = (settings, name) => {
|
||||
var url = 'api/settings/bulk?token=' + window.token;
|
||||
var data = [];
|
||||
|
||||
settings.forEach(e => {
|
||||
if(e.type !== 'btn-get') {
|
||||
var res = {
|
||||
name: e.obj.name,
|
||||
value: e.obj.value
|
||||
};
|
||||
data.push(res);
|
||||
}
|
||||
});
|
||||
|
||||
data = {
|
||||
data: data
|
||||
};
|
||||
|
||||
Axios.post(url, data)
|
||||
.then((resp) => {
|
||||
toast.success(name + ' settings updated');
|
||||
Axios.get('api/settings/config')
|
||||
.then((resp) => {
|
||||
window.config = resp.data;
|
||||
})
|
||||
})
|
||||
.catch((err) => {
|
||||
if(err.response.status == 422) {
|
||||
toast.error('Your input was invalid');
|
||||
} else {
|
||||
toast.error('Something went wrong')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
generateInputs = (settings, handler) => {
|
||||
return settings.map((setting) => {
|
||||
return <SettingsInput
|
||||
key={setting.obj.id}
|
||||
name={setting.obj.name}
|
||||
id={setting.obj.id}
|
||||
type={setting.type}
|
||||
value={setting.obj.value}
|
||||
description={setting.obj.description}
|
||||
handler={handler}
|
||||
label={setting.obj.name}
|
||||
description={setting.obj.description}
|
||||
options={setting.type == 'select' ? setting.options : []}
|
||||
hideDescription={setting.hideDescription ? setting.hideDescription : false}
|
||||
min={setting.min ? setting.min : false}
|
||||
max={setting.max ? setting.max : false}
|
||||
btnType={setting.btnType}
|
||||
inline={setting.inline}
|
||||
url={setting.url}
|
||||
earlyReturn={setting.earlyReturn ? true : false}
|
||||
classes={setting.classes ? setting.classes : ''}
|
||||
/>
|
||||
})
|
||||
}
|
||||
|
||||
getTabContent = () => {
|
||||
var data = this.state.data;
|
||||
|
||||
switch(this.state.tab) {
|
||||
case 'General':
|
||||
return <GeneralSettings
|
||||
data={data.General}
|
||||
generateInputs={this.generateInputs}
|
||||
save={this.save} />
|
||||
case 'Graphs':
|
||||
return <GraphsSettings
|
||||
data={data.Graphs}
|
||||
generateInputs={this.generateInputs}
|
||||
save={this.save} />
|
||||
case 'Notifications':
|
||||
return <NotificationsSettings
|
||||
data={data.Notifications}
|
||||
generateInputs={this.generateInputs}
|
||||
save={this.save} />
|
||||
case 'healthchecks.io':
|
||||
return <HealthchecksSettings
|
||||
data={data.healthchecks}
|
||||
generateInputs={this.generateInputs}
|
||||
save={this.save} />
|
||||
case 'Reset':
|
||||
return <ResetSettings
|
||||
data={data.healthchecks}
|
||||
generateInputs={this.generateInputs}
|
||||
save={this.save} />
|
||||
case 'Backup/Restore':
|
||||
return <BackupSettings
|
||||
data={data.healthchecks}
|
||||
generateInputs={this.generateInputs}
|
||||
save={this.save} />
|
||||
case 'Authentication':
|
||||
return <Authentication
|
||||
data={data.healthchecks}
|
||||
generateInputs={this.generateInputs}
|
||||
save={this.save} />
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
var tabs = this.generateTabs();
|
||||
var activeTab = this.state.tab;
|
||||
var tabContent = this.getTabContent();
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Tabs
|
||||
variant="tabs"
|
||||
onSelect={(tab) => { this.switchTab(tab) }}
|
||||
activeKey={activeTab}
|
||||
>
|
||||
{tabs}
|
||||
</Tabs>
|
||||
|
||||
<div className="mt-3">
|
||||
{tabContent}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('settingsTabs')) {
|
||||
ReactDOM.render(<SettingsTabs />, document.getElementById('settingsTabs'));
|
||||
}
|
||||
26
resources/js/components/Settings/tabs/BackupSettings.js
vendored
Normal file
26
resources/js/components/Settings/tabs/BackupSettings.js
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Modal, Button, Tab } from 'react-bootstrap';
|
||||
import Axios from 'axios';
|
||||
import DataRow from '../../Data/DataRow';
|
||||
|
||||
export default class BackupSettings extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Tab.Content>
|
||||
<DataRow />
|
||||
</Tab.Content>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('BackupSettings')) {
|
||||
ReactDOM.render(<BackupSettings />, document.getElementById('BackupSettings'));
|
||||
}
|
||||
46
resources/js/components/Settings/tabs/GeneralSettings.js
vendored
Normal file
46
resources/js/components/Settings/tabs/GeneralSettings.js
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Modal, Button, Tab } from 'react-bootstrap';
|
||||
import Axios from 'axios';
|
||||
|
||||
export default class GeneralSettings extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
data: this.props.data
|
||||
}
|
||||
}
|
||||
|
||||
inputHandler = (name, val) => {
|
||||
var settings = this.state.data;
|
||||
var i = 0;
|
||||
settings.forEach(ele => {
|
||||
if(ele.obj.name == name) {
|
||||
ele.obj.value = val;
|
||||
}
|
||||
settings[i] = ele;
|
||||
i++;
|
||||
});
|
||||
this.setState({
|
||||
data: settings
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
var settings = this.props.generateInputs(this.state.data, this.inputHandler);
|
||||
|
||||
return (
|
||||
<Tab.Content>
|
||||
{settings}
|
||||
<div className="mt-3">
|
||||
<button className="btn btn-primary" onClick={() => { this.props.save(this.state.data, 'General') }}>Save</button>
|
||||
</div>
|
||||
</Tab.Content>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('GeneralSettings')) {
|
||||
ReactDOM.render(<GeneralSettings />, document.getElementById('GeneralSettings'));
|
||||
}
|
||||
48
resources/js/components/Settings/tabs/GraphsSettings.js
vendored
Normal file
48
resources/js/components/Settings/tabs/GraphsSettings.js
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Modal, Button, Tab } from 'react-bootstrap';
|
||||
import Axios from 'axios';
|
||||
import { toast } from 'react-toastify';
|
||||
import SettingsInput from '../SettingsInput';
|
||||
|
||||
export default class GraphsSettings extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
data: this.props.data
|
||||
}
|
||||
}
|
||||
|
||||
inputHandler = (name, val) => {
|
||||
var settings = this.state.data;
|
||||
var i = 0;
|
||||
settings.forEach(ele => {
|
||||
if(ele.obj.name == name) {
|
||||
ele.obj.value = val;
|
||||
}
|
||||
settings[i] = ele;
|
||||
i++;
|
||||
});
|
||||
this.setState({
|
||||
data: settings
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
var settings = this.props.generateInputs(this.state.data, this.inputHandler);
|
||||
|
||||
return (
|
||||
<Tab.Content>
|
||||
{settings}
|
||||
<div className="mt-3">
|
||||
<button className="btn btn-primary" onClick={() => { this.props.save(this.state.data, 'General') }}>Save</button>
|
||||
</div>
|
||||
</Tab.Content>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('GraphsSettings')) {
|
||||
ReactDOM.render(<GraphsSettings />, document.getElementById('GraphsSettings'));
|
||||
}
|
||||
48
resources/js/components/Settings/tabs/HealthchecksSettings.js
vendored
Normal file
48
resources/js/components/Settings/tabs/HealthchecksSettings.js
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Modal, Button, Tab } from 'react-bootstrap';
|
||||
import Axios from 'axios';
|
||||
import { toast } from 'react-toastify';
|
||||
import SettingsInput from '../SettingsInput';
|
||||
|
||||
export default class HealthchecksSettings extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
data: this.props.data
|
||||
}
|
||||
}
|
||||
|
||||
inputHandler = (name, val) => {
|
||||
var settings = this.state.data;
|
||||
var i = 0;
|
||||
settings.forEach(ele => {
|
||||
if(ele.obj.name == name) {
|
||||
ele.obj.value = val;
|
||||
}
|
||||
settings[i] = ele;
|
||||
i++;
|
||||
});
|
||||
this.setState({
|
||||
data: settings
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
var settings = this.props.generateInputs(this.state.data, this.inputHandler);
|
||||
|
||||
return (
|
||||
<Tab.Content>
|
||||
{settings}
|
||||
<div className="mt-3">
|
||||
<button className="btn btn-primary" onClick={() => { this.props.save(this.state.data, 'healthchecks.io') }}>Save</button>
|
||||
</div>
|
||||
</Tab.Content>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('HealthchecksSettings')) {
|
||||
ReactDOM.render(<HealthchecksSettings />, document.getElementById('HealthchecksSettings'));
|
||||
}
|
||||
46
resources/js/components/Settings/tabs/NotificationsSettings.js
vendored
Normal file
46
resources/js/components/Settings/tabs/NotificationsSettings.js
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Modal, Button, Tab } from 'react-bootstrap';
|
||||
import Axios from 'axios';
|
||||
|
||||
export default class NotificationsSettings extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
data: this.props.data
|
||||
}
|
||||
}
|
||||
|
||||
inputHandler = (name, val) => {
|
||||
var settings = this.state.data;
|
||||
var i = 0;
|
||||
settings.forEach(ele => {
|
||||
if(ele.obj.name == name) {
|
||||
ele.obj.value = val;
|
||||
}
|
||||
settings[i] = ele;
|
||||
i++;
|
||||
});
|
||||
this.setState({
|
||||
data: settings
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
var settings = this.props.generateInputs(this.state.data, this.inputHandler);
|
||||
|
||||
return (
|
||||
<Tab.Content>
|
||||
{settings}
|
||||
<div className="mt-3">
|
||||
<button className="btn btn-primary" onClick={() => { this.props.save(this.state.data, 'Notifications') }}>Save</button>
|
||||
</div>
|
||||
</Tab.Content>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('NotificationsSettings')) {
|
||||
ReactDOM.render(<NotificationsSettings />, document.getElementById('NotificationsSettings'));
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Modal, Button } from 'react-bootstrap';
|
||||
import SettingsModalCard from './SettingsModalCard';
|
||||
import { Button } from 'react-bootstrap';
|
||||
import Axios from 'axios';
|
||||
import { toast } from 'react-toastify';
|
||||
|
||||
@@ -10,15 +9,6 @@ export default class ResetSettings extends Component {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
show: false,
|
||||
}
|
||||
}
|
||||
|
||||
toggleShow = () => {
|
||||
if(this.state.show) {
|
||||
this.setState({ show: false });
|
||||
} else {
|
||||
this.setState({ show:true });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,17 +35,9 @@ export default class ResetSettings extends Component {
|
||||
|
||||
return (
|
||||
<>
|
||||
<SettingsModalCard title={title} description="Bulk delete speedtests from the database." toggleShow={this.toggleShow} />
|
||||
<Modal show={show} onHide={this.toggleShow}>
|
||||
<Modal.Header>
|
||||
<Modal.Title>{title}</Modal.Title>
|
||||
</Modal.Header>
|
||||
<Modal.Body>
|
||||
<h4>Clear all speedtests</h4>
|
||||
<p className="text-muted">If using SQLite, a backup of the database will be stored in the location of the current database.</p>
|
||||
<Button onClick={this.deleteAll} variant="danger">Delete all</Button>
|
||||
</Modal.Body>
|
||||
</Modal>
|
||||
<h4>Clear all speedtests</h4>
|
||||
<p className="text-muted">If using SQLite, a backup of the database will be stored in the location of the current database.</p>
|
||||
<Button onClick={this.deleteAll} variant="danger">Delete all</Button>
|
||||
</>
|
||||
);
|
||||
}
|
||||
29
resources/js/components/SpeedtestsPage.js
vendored
Normal file
29
resources/js/components/SpeedtestsPage.js
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import TestsTable from './Graphics/TestsTable';
|
||||
import Footer from './Home/Footer';
|
||||
import Navbar from './Navbar';
|
||||
|
||||
export default class SpeedtestsPage extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<Navbar />
|
||||
<TestsTable />
|
||||
<Footer />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.getElementById('SpeedtestsPage')) {
|
||||
ReactDOM.render(<SpeedtestsPage />, document.getElementById('SpeedtestsPage'));
|
||||
}
|
||||
54
resources/js/index.js
vendored
54
resources/js/index.js
vendored
@@ -4,10 +4,12 @@ import { BrowserRouter, Switch, Route, Redirect, useHistory } from 'react-router
|
||||
import Axios from 'axios';
|
||||
import ErrorPage from './components/ErrorPage';
|
||||
import Loader from './components/Loader';
|
||||
import Login from './components/Login';
|
||||
import { ToastContainer } from 'react-toastify';
|
||||
import 'react-toastify/dist/ReactToastify.css';
|
||||
import HomePage from './components/Home/HomePage';
|
||||
import Cookies from 'js-cookie';
|
||||
import SettingsIndex from './components/Settings/SettingsIndex';
|
||||
import SpeedtestsPage from './components/SpeedtestsPage';
|
||||
|
||||
export default class Index extends Component {
|
||||
constructor(props) {
|
||||
@@ -15,7 +17,7 @@ export default class Index extends Component {
|
||||
|
||||
this.state = {
|
||||
loading: true,
|
||||
redirect: false
|
||||
redirect: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,10 +31,38 @@ export default class Index extends Component {
|
||||
Axios.get(url)
|
||||
.then((resp) => {
|
||||
window.config = resp.data;
|
||||
this.setState({
|
||||
loading: false,
|
||||
redirect: true,
|
||||
});
|
||||
if(window.config.auth === true) {
|
||||
var authCookie = Cookies.get('auth');
|
||||
if(authCookie == undefined) {
|
||||
window.authenticated = false;
|
||||
this.setState({
|
||||
loading: false,
|
||||
redirect: true,
|
||||
});
|
||||
} else {
|
||||
var url = 'api/auth/me?token=' + authCookie;
|
||||
Axios.get(url)
|
||||
.then((resp) => {
|
||||
window.authenticated = true;
|
||||
window.token = authCookie;
|
||||
})
|
||||
.catch((err) => {
|
||||
Cookies.remove('auth');
|
||||
window.authenticated = false;
|
||||
})
|
||||
.finally(() => {
|
||||
this.setState({
|
||||
loading: false,
|
||||
redirect: true,
|
||||
});
|
||||
})
|
||||
}
|
||||
} else {
|
||||
this.setState({
|
||||
loading: false,
|
||||
redirect: true,
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -56,6 +86,18 @@ export default class Index extends Component {
|
||||
<HomePage />
|
||||
</div>
|
||||
)} />
|
||||
<Route exact path={window.config.base + 'speedtests'} render={(props) => (
|
||||
<div>
|
||||
<SpeedtestsPage />
|
||||
|
||||
</div>
|
||||
)} />
|
||||
<Route exact path={window.config.base + 'settings'} render={(props) => (
|
||||
<div>
|
||||
<SettingsIndex />
|
||||
|
||||
</div>
|
||||
)} />
|
||||
<Route exact path={window.config.base + "error/:code"} render={(props) => ( <ErrorPage code={props.match.params.code} /> )} />
|
||||
<Route render={(props) => (<ErrorPage code="404" />)} />
|
||||
</Switch>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
use App\Helpers\SpeedtestHelper;
|
||||
use App\Http\Controllers\SpeedtestController;
|
||||
use App\Speedtest;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
@@ -70,7 +71,9 @@ Route::group([
|
||||
], function () {
|
||||
Route::get('/config', 'SettingsController@config')
|
||||
->name('settings.config');
|
||||
Route::get('/test-notification', 'SettingsController@testNotification')
|
||||
Route::get('/test-notification', 'IntegrationsController@testNotification')
|
||||
->name('settings.test_notification');
|
||||
Route::get('/test-healthchecks/{method}', 'IntegrationsController@testHealthchecks')
|
||||
->name('settings.test_notification');
|
||||
Route::get('/', 'SettingsController@index')
|
||||
->name('settings.index');
|
||||
@@ -81,3 +84,29 @@ Route::group([
|
||||
Route::post('/bulk', 'SettingsController@bulkStore')
|
||||
->name('settings.bulk.update');
|
||||
});
|
||||
|
||||
Route::group(
|
||||
[
|
||||
'middleware' => 'api',
|
||||
'prefix' => 'auth'
|
||||
],
|
||||
function ($router) {
|
||||
Route::post('register', 'AuthController@register')->name('auth.register');
|
||||
Route::post('login', 'AuthController@login')->middleware('throttle:60,1')->name('auth.login');
|
||||
Route::get('logout', 'AuthController@logout')->name('auth.logout');
|
||||
Route::get('refresh', 'AuthController@refresh')->middleware('throttle:60,1')->name('auth.refresh');
|
||||
Route::get('me', 'AuthController@me')->middleware('session_active')->name('auth.me');
|
||||
Route::post('change-password', 'AuthController@changePassword')->middleware('session_active')->name('auth.change_password');
|
||||
|
||||
Route::group(
|
||||
[
|
||||
'middleware' => ['api', 'session_active'],
|
||||
'prefix' => 'sessions'
|
||||
],
|
||||
function($router) {
|
||||
Route::get('/', 'AuthController@getSessions')->name('auth.sessions.all');
|
||||
Route::delete('/{id}', 'AuthController@deleteSession')->name('auth.sessions.delete');
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -16,20 +16,20 @@ use Illuminate\Support\Facades\Route;
|
||||
|
|
||||
*/
|
||||
|
||||
Route::get(SettingsHelper::getBase() . 'files/{path?}', function($file) {
|
||||
Route::get(SettingsHelper::getBase() . 'files/{path?}', function ($file) {
|
||||
$fileP = explode('?', $file)[0];
|
||||
$fileP = public_path() . '/' . $fileP;
|
||||
if(file_exists($fileP)) {
|
||||
if (file_exists($fileP)) {
|
||||
$contents = File::get($fileP);
|
||||
$mime = \GuzzleHttp\Psr7\mimetype_from_filename($fileP);
|
||||
return Response::make(File::get($fileP), 200, [ 'Content-type' => $mime ]);
|
||||
return Response::make(File::get($fileP), 200, ['Content-type' => $mime]);
|
||||
} else {
|
||||
abort(404);
|
||||
}
|
||||
})->where('path', '.*')
|
||||
->name('files');
|
||||
->name('files');
|
||||
|
||||
Route::get('/{path?}', function() {
|
||||
return view('app', [ 'title' => 'Speedtest Tracker' ]);
|
||||
Route::get('/{path?}', function () {
|
||||
return view('app', ['title' => SettingsHelper::get('app_name')->value]);
|
||||
})->where('path', '^((?!\/api\/).)*$')
|
||||
->name('react');
|
||||
->name('react');
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user