mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2025-12-21 21:33:08 +01:00
Compare commits
179 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
8ae4bc602c | ||
|
|
9028ffb7cd | ||
|
|
62fde8fb2a | ||
|
|
601d46915c | ||
|
|
751acff32c | ||
|
|
4e133e97c7 | ||
|
|
61a85ced34 | ||
|
|
aa37a50f57 | ||
|
|
99ac0b008c | ||
|
|
b4147ce57a | ||
|
|
80b80811aa | ||
|
|
2d8bc7d71f | ||
|
|
a036ed7c8f | ||
|
|
01b097b4d3 | ||
|
|
a6326f6d98 | ||
|
|
ef34238043 | ||
|
|
8e556250aa | ||
|
|
87fc35c1c5 | ||
|
|
b6fca4e1a7 | ||
|
|
ae40f503e2 | ||
|
|
61da652b82 | ||
|
|
ec56337b99 | ||
|
|
0ed4674c3f | ||
|
|
dd56a667cd | ||
|
|
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 |
11
.github/workflows/laravel-dev.yml
vendored
11
.github/workflows/laravel-dev.yml
vendored
@@ -13,6 +13,17 @@ jobs:
|
||||
- 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
|
||||
|
||||
11
.github/workflows/laravel-pr.yml
vendored
11
.github/workflows/laravel-pr.yml
vendored
@@ -13,6 +13,17 @@ jobs:
|
||||
- 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
|
||||
|
||||
11
.github/workflows/laravel-stable.yml
vendored
11
.github/workflows/laravel-stable.yml
vendored
@@ -13,6 +13,17 @@ jobs:
|
||||
- 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/
|
||||
|
||||
19
README.md
19
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).
|
||||
|
||||
@@ -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,9 @@ class Kernel extends ConsoleKernel
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
$schedule->job(new SpeedtestJob)->cron(SettingsHelper::get('schedule')['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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 . '/';
|
||||
}
|
||||
}
|
||||
@@ -90,7 +96,7 @@ class SettingsHelper {
|
||||
// Try exact key
|
||||
$val = exec('echo $' . $key);
|
||||
|
||||
if($val == "") {
|
||||
if ($val == "") {
|
||||
array_push($results, true);
|
||||
} else {
|
||||
array_push($results, false);
|
||||
@@ -99,25 +105,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 +139,11 @@ class SettingsHelper {
|
||||
{
|
||||
return [
|
||||
'base' => SettingsHelper::getBase(),
|
||||
'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 +156,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 +165,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,7 +46,7 @@ class SettingsController extends Controller
|
||||
* Store/update a setting
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
@@ -72,7 +81,7 @@ class SettingsController extends Controller
|
||||
* Bulk store/update a setting
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function bulkStore(Request $request)
|
||||
{
|
||||
@@ -94,7 +103,7 @@ class SettingsController extends Controller
|
||||
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)) {
|
||||
@@ -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($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);
|
||||
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']);
|
||||
}
|
||||
}
|
||||
56
app/Providers/IntegrationsServiceProvider.php
Normal file
56
app/Providers/IntegrationsServiceProvider.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?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 {
|
||||
App::bind('healthcheck', function() use ($setting) {
|
||||
return new Healthchecks($setting->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()
|
||||
{
|
||||
|
||||
128
changelog.json
128
changelog.json
@@ -1,4 +1,132 @@
|
||||
{
|
||||
"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,10 +23,12 @@
|
||||
"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",
|
||||
"nunomaduro/larastan": "^0.6.2",
|
||||
"phpunit/phpunit": "^8.5"
|
||||
},
|
||||
"config": {
|
||||
|
||||
2046
composer.lock
generated
2046
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,
|
||||
];
|
||||
@@ -7,7 +7,7 @@ return [
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
'version' => '1.7.15',
|
||||
'version' => '1.9.9',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
3882
package-lock.json
generated
3882
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
27
package.json
27
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",
|
||||
"@babel/preset-react": "^7.12.5",
|
||||
"axios": "^0.20",
|
||||
"bootstrap": "^4.5.3",
|
||||
"cross-env": "^7.0",
|
||||
"jquery": "^3.5",
|
||||
"laravel-mix": "^5.0.1",
|
||||
"lodash": "^4.17.19",
|
||||
"laravel-mix": "^5.0.9",
|
||||
"lodash": "^4.17.20",
|
||||
"popper.js": "^1.12",
|
||||
"react": "^16.2.0",
|
||||
"react": "^16.14.0",
|
||||
"react-dom": "^16.2.0",
|
||||
"resolve-url-loader": "^3.1.0",
|
||||
"sass": "^1.26.10",
|
||||
"sass-loader": "^9.0.2"
|
||||
"resolve-url-loader": "^3.1.2",
|
||||
"sass-loader": "^10.0.5",
|
||||
"sass": "^1.29.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/plugin-proposal-class-properties": "^7.10.4",
|
||||
"chart.js": "^2.9.3",
|
||||
"@babel/plugin-proposal-class-properties": "^7.12.1",
|
||||
"chart.js": "^2.9.4",
|
||||
"csv-file-validator": "^1.8.0",
|
||||
"js-cookie": "^2.2.1",
|
||||
"react-bootstrap": "^1.3.0",
|
||||
"react-chartjs-2": "^2.9.0",
|
||||
"react-chartjs-2": "^2.10.0",
|
||||
"react-router": "^5.2.0",
|
||||
"react-router-dom": "^5.2.0",
|
||||
"react-toastify": "^6.0.8"
|
||||
"react-toastify": "^6.0.9"
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
10905
public/css/app.css
vendored
10905
public/css/app.css
vendored
File diff suppressed because one or more lines are too long
141345
public/js/app.js
vendored
141345
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.2 (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)
|
||||
*/
|
||||
|
||||
/*!
|
||||
@@ -30,6 +30,14 @@ License: MIT
|
||||
* 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/
|
||||
|
||||
86
resources/js/components/Authentication/Authentication.js
vendored
Normal file
86
resources/js/components/Authentication/Authentication.js
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
import React, { Component } from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Container, Row, Col, Collapse, Button, Modal } 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 (
|
||||
<Container className="mb-4">
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="mb-3 text-center">
|
||||
<div className="mouse" aria-controls="testsTable" onClick={this.toggleCollapse} aria-expanded={showCollapse}>
|
||||
<h4 className="d-inline mr-2">Authentication</h4>
|
||||
{(showCollapse) ?
|
||||
<span className="ti-angle-up"></span>
|
||||
:
|
||||
<span className="ti-angle-down"></span>
|
||||
}
|
||||
</div>
|
||||
</Col>
|
||||
</Row>
|
||||
<Collapse in={showCollapse}>
|
||||
<div>
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="text-center">
|
||||
<ResetPassword />
|
||||
</Col>
|
||||
</Row>
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }} className="text-center">
|
||||
<SessionsTable />
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
</Collapse>
|
||||
</Container>
|
||||
);
|
||||
} 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) => {
|
||||
|
||||
@@ -205,7 +205,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,
|
||||
|
||||
@@ -45,7 +45,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 +78,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 +131,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 +145,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 +159,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">
|
||||
|
||||
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>
|
||||
|
||||
6
resources/js/components/Home/HomePage.js
vendored
6
resources/js/components/Home/HomePage.js
vendored
@@ -6,6 +6,8 @@ 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';
|
||||
|
||||
export default class HomePage extends Component {
|
||||
|
||||
@@ -13,10 +15,14 @@ export default class HomePage extends Component {
|
||||
return (
|
||||
<div>
|
||||
<div className="my-4">
|
||||
{(window.config.auth == true && window.authenticated == false) &&
|
||||
<Login />
|
||||
}
|
||||
<LatestResults />
|
||||
<HistoryGraph />
|
||||
<TestsTable />
|
||||
<Settings />
|
||||
<Authentication />
|
||||
<DataRow />
|
||||
</div>
|
||||
<Footer />
|
||||
|
||||
77
resources/js/components/Login.js
vendored
77
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,75 @@ 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.')
|
||||
});
|
||||
}
|
||||
|
||||
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>
|
||||
|
||||
2
resources/js/components/Settings/Setting.js
vendored
2
resources/js/components/Settings/Setting.js
vendored
@@ -20,7 +20,7 @@ export default class Setting extends Component {
|
||||
}
|
||||
|
||||
update = () => {
|
||||
var url = 'api/settings';
|
||||
var url = 'api/settings?token=' + window.token;
|
||||
var data = {
|
||||
name: this.state.name,
|
||||
value: this.state.value
|
||||
|
||||
@@ -23,7 +23,7 @@ export default class SettingWithModal extends Component {
|
||||
}
|
||||
|
||||
update = () => {
|
||||
var url = 'api/settings/bulk';
|
||||
var url = 'api/settings/bulk?token=' + window.token;
|
||||
var data = [];
|
||||
var settings = this.state.settings;
|
||||
|
||||
@@ -47,6 +47,10 @@ export default class SettingWithModal extends Component {
|
||||
if(this.state.autoClose) {
|
||||
this.toggleShow();
|
||||
}
|
||||
Axios.get('api/settings/config')
|
||||
.then((resp) => {
|
||||
window.config = resp.data;
|
||||
})
|
||||
})
|
||||
.catch((err) => {
|
||||
if(err.response.status == 422) {
|
||||
@@ -101,7 +105,7 @@ export default class SettingWithModal extends Component {
|
||||
<>
|
||||
<SettingsModalCard title={title} description={description} toggleShow={this.toggleShow} />
|
||||
<Modal show={show} onHide={this.toggleShow}>
|
||||
<Modal.Header>
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title>{title}</Modal.Title>
|
||||
</Modal.Header>
|
||||
<Modal.Body>
|
||||
@@ -194,7 +198,7 @@ export default class SettingWithModal extends Component {
|
||||
</Col>
|
||||
{e.description == null &&
|
||||
<Col md={md} sm={sm}>
|
||||
<p>{e.obj.description}</p>
|
||||
<p dangerouslySetInnerHTML={{ __html: e.obj.description}}></p>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
@@ -248,6 +252,35 @@ export default class SettingWithModal extends Component {
|
||||
}
|
||||
</Row>
|
||||
)
|
||||
} else if(e.type == 'group') {
|
||||
return (
|
||||
<div key={e.obj.id}>
|
||||
<Row>
|
||||
<Col md={md} sm={sm}>
|
||||
<p className="mb-0">{name}</p>
|
||||
</Col>
|
||||
{e.description == null &&
|
||||
<Col md={md} sm={sm}>
|
||||
<p>{e.obj.description}</p>
|
||||
</Col>
|
||||
}
|
||||
</Row>
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }}>
|
||||
{e.children.map((ee,ii) => {
|
||||
if(ee.type == 'button-get') {
|
||||
return (
|
||||
<Button key={ii} variant={ee.btnType} className={'mr-2 mb-3'} onClick={() => { Axios.get(ee.url)
|
||||
.then((resp) => { toast.success('Healthcheck sent') })
|
||||
.catch((resp) => { resp = resp.response; toast.error(resp.data.error) })
|
||||
}} >{ee.text}</Button>
|
||||
)
|
||||
}
|
||||
})}
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
})}
|
||||
<Button variant="primary" type="submit" onClick={this.update} >Save</Button>
|
||||
|
||||
184
resources/js/components/Settings/Settings.js
vendored
184
resources/js/components/Settings/Settings.js
vendored
@@ -19,7 +19,9 @@ export default class Settings extends Component {
|
||||
}
|
||||
|
||||
componentDidMount = () => {
|
||||
this.getData();
|
||||
if( (window.config.auth == true && window.authenticated == true) || window.config.auth == false) {
|
||||
this.getData();
|
||||
}
|
||||
}
|
||||
|
||||
toggleShow = () => {
|
||||
@@ -35,7 +37,7 @@ export default class Settings extends Component {
|
||||
}
|
||||
|
||||
getData = () => {
|
||||
var url = 'api/settings/';
|
||||
var url = 'api/settings/?token=' + window.token;
|
||||
|
||||
Axios.get(url)
|
||||
.then((resp) => {
|
||||
@@ -53,13 +55,32 @@ export default class Settings extends Component {
|
||||
|
||||
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} />
|
||||
<SettingWithModal title="General settings" description="Configure general settings for the app." autoClose={true} settings={[
|
||||
{
|
||||
obj: e.schedule,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
obj: e.server,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
obj: e.show_average,
|
||||
type: 'checkbox'
|
||||
},
|
||||
{
|
||||
obj: e.show_max,
|
||||
type: 'checkbox'
|
||||
},
|
||||
{
|
||||
obj: e.show_min,
|
||||
type: 'checkbox'
|
||||
},
|
||||
]} />
|
||||
</Col>
|
||||
<Col lg={{ span: 4 }} md={{ span: 6 }} sm={{ span: 12 }}>
|
||||
<SettingWithModal title="Graph settings" description="Control settings for the graphs." autoClose={true} settings={[
|
||||
@@ -116,6 +137,10 @@ export default class Settings extends Component {
|
||||
'value': 6
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
obj: e.show_failed_tests_on_graph,
|
||||
type: 'checkbox'
|
||||
}
|
||||
]} />
|
||||
</Col>
|
||||
@@ -140,7 +165,7 @@ export default class Settings extends Component {
|
||||
description: "After saving your updated notification settings, use this to check your settings are correct."
|
||||
},
|
||||
type: 'button-get',
|
||||
url: 'api/settings/test-notification'
|
||||
url: 'api/settings/test-notification?token=' + window.token
|
||||
},
|
||||
{
|
||||
obj: e.speedtest_notifications,
|
||||
@@ -155,9 +180,89 @@ export default class Settings extends Component {
|
||||
type: 'number',
|
||||
min: 0,
|
||||
max: 23
|
||||
},
|
||||
{
|
||||
obj: {
|
||||
id: (Math.floor(Math.random() * 10000) + 1),
|
||||
name: "Conditional Notifications",
|
||||
description: ""
|
||||
},
|
||||
type: 'group',
|
||||
children: [
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
obj: e.threshold_alert_percentage_notifications,
|
||||
type: 'checkbox',
|
||||
},
|
||||
{
|
||||
obj: e.threshold_alert_percentage,
|
||||
type: 'number',
|
||||
min: 0,
|
||||
max: 100
|
||||
},
|
||||
{
|
||||
obj: e.threshold_alert_absolute_notifications,
|
||||
type: 'checkbox',
|
||||
},
|
||||
{
|
||||
obj: e.threshold_alert_absolute_download,
|
||||
type: 'number',
|
||||
},
|
||||
{
|
||||
obj: e.threshold_alert_absolute_upload,
|
||||
type: 'number',
|
||||
},
|
||||
{
|
||||
obj: e.threshold_alert_absolute_ping,
|
||||
type: 'number',
|
||||
}
|
||||
]} />
|
||||
</Col>
|
||||
<Col lg={{ span: 4 }} md={{ span: 6 }} sm={{ span: 12 }}>
|
||||
<SettingWithModal title="healthchecks.io settings" description="Control settings for healthchecks.io" autoClose={false} settings={[
|
||||
{
|
||||
obj: e.healthchecks_uuid,
|
||||
type: 'text'
|
||||
},
|
||||
{
|
||||
obj: e.healthchecks_enabled,
|
||||
type: 'checkbox'
|
||||
},
|
||||
{
|
||||
obj: {
|
||||
id: (Math.floor(Math.random() * 10000) + 1),
|
||||
name: "Test healthchecks (after saving)",
|
||||
description: ""
|
||||
},
|
||||
type: 'group',
|
||||
children: [
|
||||
{
|
||||
type: 'button-get',
|
||||
url: 'api/settings/test-healthchecks/start?token=' + window.token,
|
||||
btnType: 'outline-success',
|
||||
text: 'Start',
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
type: 'button-get',
|
||||
url: 'api/settings/test-healthchecks/success?token=' + window.token,
|
||||
btnType: 'success',
|
||||
text: 'Success',
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
type: 'button-get',
|
||||
url: 'api/settings/test-healthchecks/fail?token=' + window.token,
|
||||
btnType: 'danger',
|
||||
text: 'Fail',
|
||||
inline: true,
|
||||
},
|
||||
]
|
||||
},
|
||||
]} />
|
||||
</Col>
|
||||
<Col lg={{ span: 4 }} md={{ span: 6 }} sm={{ span: 12 }}>
|
||||
<ResetSettings />
|
||||
</Col>
|
||||
@@ -172,39 +277,44 @@ export default class Settings extends Component {
|
||||
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 />
|
||||
if( (window.config.auth == true && window.authenticated == true) || window.config.auth == false) {
|
||||
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>
|
||||
:
|
||||
cards
|
||||
<span className="ti-angle-down"></span>
|
||||
}
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
</Collapse>
|
||||
</Container>
|
||||
</div>
|
||||
</Col>
|
||||
</Row>
|
||||
<Collapse in={show}>
|
||||
<div>
|
||||
<Row>
|
||||
<Col sm={{ span: 12 }}>
|
||||
{loading ?
|
||||
<Loader small />
|
||||
:
|
||||
cards
|
||||
}
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
</Collapse>
|
||||
</Container>
|
||||
|
||||
</div>
|
||||
);
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
return(
|
||||
<></>
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
40
resources/js/index.js
vendored
40
resources/js/index.js
vendored
@@ -4,10 +4,10 @@ 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';
|
||||
|
||||
export default class Index extends Component {
|
||||
constructor(props) {
|
||||
@@ -15,7 +15,7 @@ export default class Index extends Component {
|
||||
|
||||
this.state = {
|
||||
loading: true,
|
||||
redirect: false
|
||||
redirect: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,10 +29,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,
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -27,13 +27,13 @@ class APISpeedtestTest extends TestCase
|
||||
$dl = [];
|
||||
$ul = [];
|
||||
|
||||
for($i = 0; $i < 3; $i++) {
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$pingVal = $faker->randomFloat();
|
||||
array_push($ping,$pingVal);
|
||||
array_push($ping, $pingVal);
|
||||
$dlVal = $faker->randomFloat();
|
||||
array_push($dl,$dlVal);
|
||||
array_push($dl, $dlVal);
|
||||
$ulVal = $faker->randomFloat();
|
||||
array_push($ul,$ulVal);
|
||||
array_push($ul, $ulVal);
|
||||
|
||||
Speedtest::create([
|
||||
'ping' => $pingVal,
|
||||
@@ -70,7 +70,12 @@ class APISpeedtestTest extends TestCase
|
||||
'download',
|
||||
'upload',
|
||||
],
|
||||
'max' => [
|
||||
'maximum' => [
|
||||
'ping',
|
||||
'download',
|
||||
'upload',
|
||||
],
|
||||
'minimum' => [
|
||||
'ping',
|
||||
'download',
|
||||
'upload',
|
||||
|
||||
21
tests/Feature/Commands/AcceptEULACommandTest.php
Normal file
21
tests/Feature/Commands/AcceptEULACommandTest.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Commands;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AcceptEULACommandTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAcceptEULA()
|
||||
{
|
||||
$response = $this->artisan('speedtest:eula')
|
||||
->assertExitCode(0);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
namespace Tests\Feature\Commands;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
73
tests/Feature/Commands/AuthenticationCommandTest.php
Normal file
73
tests/Feature/Commands/AuthenticationCommandTest.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Commands;
|
||||
|
||||
use App\Console\Commands\AuthenticationCommand;
|
||||
use App\Helpers\SettingsHelper;
|
||||
use Artisan;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AuthenticationCommandTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* Enable app auth
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEnableAuth()
|
||||
{
|
||||
SettingsHelper::set('auth', false);
|
||||
|
||||
$this->assertEquals(Artisan::call('speedtest:auth', [ '--enable' => true ]), 0);
|
||||
|
||||
$this->assertTrue((bool)SettingsHelper::get('auth')->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable app auth
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDisableAuth()
|
||||
{
|
||||
SettingsHelper::set('auth', true);
|
||||
|
||||
$this->assertEquals(Artisan::call('speedtest:auth', [ '--disable' => true ]), 0);
|
||||
|
||||
$this->assertFalse((bool)SettingsHelper::get('auth')->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test invalid params for command
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
// public function testAuthBothOptions()
|
||||
// {
|
||||
// $command = new AuthenticationCommand();
|
||||
// $command->setLaravel($this->app);
|
||||
// $tester = new CommandTester($command);
|
||||
// $tester->setInputs([]);
|
||||
// $tester->execute([ '--enable' => true, '--disable' => true ]);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Test invalid params for command
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
// public function testAuthNoOptions()
|
||||
// {
|
||||
// $command = new AuthenticationCommand();
|
||||
// $command->setLaravel($this->app);
|
||||
// $tester = new CommandTester($command);
|
||||
// $tester->setInputs([]);
|
||||
// $tester->execute([]);
|
||||
// }
|
||||
}
|
||||
24
tests/Feature/Commands/ClearOldSessionCommandTest.php
Normal file
24
tests/Feature/Commands/ClearOldSessionCommandTest.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Commands;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ClearOldSessionCommandTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testClearSessionsCommand()
|
||||
{
|
||||
$this->artisan('speedtest:clear-sessions')
|
||||
->expectsOutput('Invalidated expired sessions')
|
||||
->assertExitCode(0);
|
||||
}
|
||||
}
|
||||
23
tests/Feature/Commands/ClearQueueCommandTest.php
Normal file
23
tests/Feature/Commands/ClearQueueCommandTest.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Commands;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ClearQueueCommandTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testClearQueue()
|
||||
{
|
||||
$this->artisan('queue:clear')
|
||||
->assertExitCode(0);
|
||||
}
|
||||
}
|
||||
27
tests/Feature/Commands/GetConfigCommandTest.php
Normal file
27
tests/Feature/Commands/GetConfigCommandTest.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Commands;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class GetConfigCommandTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetConfig()
|
||||
{
|
||||
$configJson = json_encode(SettingsHelper::getConfig(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
|
||||
$this->artisan('speedtest:config')
|
||||
->expectsOutput($configJson)
|
||||
->assertExitCode(0);
|
||||
}
|
||||
}
|
||||
29
tests/Feature/Commands/SetSlackWebhookCommandTest.php
Normal file
29
tests/Feature/Commands/SetSlackWebhookCommandTest.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Commands;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SetSlackWebhookCommandTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetSlackWebhook()
|
||||
{
|
||||
SettingsHelper::set('slack_webhook', 'pre-test');
|
||||
|
||||
$this->artisan('speedtest:slack', [ 'webhook' => 'test' ])
|
||||
->expectsOutput('Slack webhook updated')
|
||||
->assertExitCode(0);
|
||||
|
||||
$this->assertEquals(SettingsHelper::get('slack_webhook')->value, 'test');
|
||||
}
|
||||
}
|
||||
33
tests/Feature/Commands/SetTelegramOptionsCommandTest.php
Normal file
33
tests/Feature/Commands/SetTelegramOptionsCommandTest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Commands;
|
||||
|
||||
use App\Helpers\SettingsHelper;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SetTelegramOptionsCommandTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetTelegramOptions()
|
||||
{
|
||||
SettingsHelper::set('telegram_bot_token', 'pre-test-bot');
|
||||
SettingsHelper::set('telegram_chat_id', 'pre-test-bot');
|
||||
|
||||
$this->artisan('speedtest:telegram', [
|
||||
'--bot' => 'test-bot',
|
||||
'--chat' => 'test-chat'
|
||||
])->expectsOutput('Telegram options updated')
|
||||
->assertExitCode(0);
|
||||
|
||||
$this->assertEquals(SettingsHelper::get('telegram_bot_token')->value, 'test-bot');
|
||||
$this->assertEquals(SettingsHelper::get('telegram_chat_id')->value, 'test-chat');
|
||||
}
|
||||
}
|
||||
23
tests/Feature/Commands/SpeedtestOverviewCommandTest.php
Normal file
23
tests/Feature/Commands/SpeedtestOverviewCommandTest.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Commands;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SpeedtestOverviewCommandTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testOverviewCommand()
|
||||
{
|
||||
$this->artisan('speedtest:overview')
|
||||
->assertExitCode(0);
|
||||
}
|
||||
}
|
||||
23
tests/Feature/Commands/TestNotificationCommandTest.php
Normal file
23
tests/Feature/Commands/TestNotificationCommandTest.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Commands;
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TestNotificationCommandTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* A basic feature test example.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTestNotificationCommand()
|
||||
{
|
||||
$this->artisan('speedtest:notification')
|
||||
->assertExitCode(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Controllers\IntegrationsController;
|
||||
|
||||
use App;
|
||||
use App\Helpers\SettingsHelper;
|
||||
use App\Http\Controllers\IntegrationsController;
|
||||
use Henrywhitaker3\Healthchecks\Healthchecks;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class HealthcheckTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* Controller
|
||||
*
|
||||
* @var IntegrationsController
|
||||
*/
|
||||
private $controller;
|
||||
|
||||
private $uuid;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->controller = new IntegrationsController();
|
||||
|
||||
$this->uuid = env('HEALTHCHECKS_UUID');
|
||||
$this->bindFacade($this->uuid);
|
||||
}
|
||||
|
||||
public function testStartPing()
|
||||
{
|
||||
$resp = $this->controller->testHealthchecks('start')->original;
|
||||
|
||||
$this->assertEquals([
|
||||
'method' => 'test healthchecks \'start\' endpoint',
|
||||
'success' => true
|
||||
], $resp);
|
||||
}
|
||||
|
||||
public function testSuccessPing()
|
||||
{
|
||||
$resp = $this->controller->testHealthchecks('success')->original;
|
||||
|
||||
$this->assertEquals([
|
||||
'method' => 'test healthchecks \'success\' endpoint',
|
||||
'success' => true
|
||||
], $resp);
|
||||
}
|
||||
|
||||
public function testFailPing()
|
||||
{
|
||||
$resp = $this->controller->testHealthchecks('fail')->original;
|
||||
|
||||
$this->assertEquals([
|
||||
'method' => 'test healthchecks \'fail\' endpoint',
|
||||
'success' => true
|
||||
], $resp);
|
||||
}
|
||||
|
||||
public function testInvalidUUID()
|
||||
{
|
||||
$this->bindFacade('test');
|
||||
|
||||
$resp = $this->controller->testHealthchecks('start')->original;
|
||||
|
||||
$this->assertEquals([
|
||||
'method' => 'test healthchecks \'start\' endpoint',
|
||||
'success' => false,
|
||||
'error' => 'Invalid UUID'
|
||||
], $resp);
|
||||
|
||||
$this->bindFacade($this->uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* As clean install before setting up, there is no healthchecks
|
||||
* uuid in the db, so the facade doesn't get created during boot,
|
||||
* now just bind it in the container on test setup
|
||||
*
|
||||
* @param String $uuid
|
||||
* @return void
|
||||
*/
|
||||
private function bindFacade(String $uuid)
|
||||
{
|
||||
App::bind('healthcheck', function() use ($uuid) {
|
||||
return new Healthchecks($uuid);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Controllers\IntegrationsController;
|
||||
|
||||
use App\Http\Controllers\IntegrationsController;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class NotificationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* Controller
|
||||
*
|
||||
* @var IntegrationsController
|
||||
*/
|
||||
private $controller;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->controller = new IntegrationsController();
|
||||
}
|
||||
|
||||
public function testNotificationsTest()
|
||||
{
|
||||
$resp = $this->controller->testNotification()->original;
|
||||
|
||||
$this->assertEquals([
|
||||
'method' => 'test notification agents'
|
||||
], $resp);
|
||||
}
|
||||
}
|
||||
66
tests/Unit/Controllers/SpeedtestController/DeleteTest.php
Normal file
66
tests/Unit/Controllers/SpeedtestController/DeleteTest.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Controllers\SpeedtestController;
|
||||
|
||||
use App\Http\Controllers\SpeedtestController;
|
||||
use App\Speedtest;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DeleteTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* SpeedtestController
|
||||
*
|
||||
* @var SpeedtestController
|
||||
*/
|
||||
private $controller;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->controller = new SpeedtestController();
|
||||
}
|
||||
|
||||
public function testDeleteAll()
|
||||
{
|
||||
for($i = 0; $i < 5; $i++) {
|
||||
Speedtest::create([
|
||||
'download' => 5,
|
||||
'upload' => 5,
|
||||
'ping' => 5
|
||||
]);
|
||||
}
|
||||
|
||||
$this->assertEquals(5, Speedtest::count());
|
||||
|
||||
$resp = $this->controller->deleteAll()->original;
|
||||
|
||||
$this->assertArrayHasKey('method', $resp);
|
||||
$this->assertArrayHasKey('success', $resp);
|
||||
|
||||
$this->assertEquals(0, Speedtest::count());
|
||||
}
|
||||
|
||||
public function testDeleteSpecific()
|
||||
{
|
||||
$test = Speedtest::create([
|
||||
'download' => 5,
|
||||
'upload' => 5,
|
||||
'ping' => 5
|
||||
]);
|
||||
$id = $test->id;
|
||||
|
||||
$this->assertNotNull(Speedtest::find($id));
|
||||
|
||||
$resp = $this->controller->delete($test)->original;
|
||||
|
||||
$this->assertArrayHasKey('method', $resp);
|
||||
$this->assertArrayHasKey('success', $resp);
|
||||
|
||||
$this->assertNull(Speedtest::find($id));
|
||||
}
|
||||
}
|
||||
43
tests/Unit/Controllers/SpeedtestController/FailTest.php
Normal file
43
tests/Unit/Controllers/SpeedtestController/FailTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Controllers\SpeedtestController;
|
||||
|
||||
use App\Http\Controllers\SpeedtestController;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FailTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* SpeedtestController
|
||||
*
|
||||
* @var SpeedtestController
|
||||
*/
|
||||
private $controller;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->controller = new SpeedtestController();
|
||||
}
|
||||
|
||||
public function testFail()
|
||||
{
|
||||
$resp = $this->controller->fail(5)->original;
|
||||
|
||||
$this->assertArrayHasKey('method', $resp);
|
||||
$this->assertArrayHasKey('data', $resp);
|
||||
$this->assertArrayHasKey('days', $resp);
|
||||
}
|
||||
|
||||
public function testFailInvalidInput()
|
||||
{
|
||||
$resp = $this->controller->fail('test')->original;
|
||||
|
||||
$this->assertArrayHasKey('method', $resp);
|
||||
$this->assertArrayHasKey('error', $resp);
|
||||
}
|
||||
}
|
||||
34
tests/Unit/Controllers/SpeedtestController/IndexTest.php
Normal file
34
tests/Unit/Controllers/SpeedtestController/IndexTest.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Controllers\SpeedtestController;
|
||||
|
||||
use App\Http\Controllers\SpeedtestController;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class IndexTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* SpeedtestController
|
||||
*
|
||||
* @var SpeedtestController
|
||||
*/
|
||||
private $controller;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->controller = new SpeedtestController();
|
||||
}
|
||||
|
||||
public function testIndex()
|
||||
{
|
||||
$resp = $this->controller->index()->original;
|
||||
|
||||
$this->assertArrayHasKey('method', $resp);
|
||||
$this->assertArrayHasKey('data', $resp);
|
||||
}
|
||||
}
|
||||
59
tests/Unit/Controllers/SpeedtestController/LatestTest.php
Normal file
59
tests/Unit/Controllers/SpeedtestController/LatestTest.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Controllers\SpeedtestController;
|
||||
|
||||
use App\Http\Controllers\SpeedtestController;
|
||||
use App\Speedtest;
|
||||
use DB;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LatestTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* SpeedtestController
|
||||
*
|
||||
* @var SpeedtestController
|
||||
*/
|
||||
private $controller;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->controller = new SpeedtestController();
|
||||
}
|
||||
|
||||
public function testLatestNoEntries()
|
||||
{
|
||||
DB::table('speedtests')->delete();
|
||||
|
||||
$resp = $this->controller->latest();
|
||||
$resp = $resp->original;
|
||||
|
||||
$this->assertEquals([
|
||||
'method' => 'get latest speedtest',
|
||||
'error' => 'no speedtests have been run'
|
||||
], $resp);
|
||||
}
|
||||
|
||||
public function testLatest()
|
||||
{
|
||||
$test = Speedtest::create([
|
||||
'download' => 5,
|
||||
'upload' => 5,
|
||||
'ping' => 5
|
||||
]);
|
||||
$test = $test->attributesToArray();
|
||||
|
||||
$resp = $this->controller->latest();
|
||||
$resp = $resp->original;
|
||||
|
||||
$this->assertArrayHasKey('data', $resp);
|
||||
$this->assertArrayHasKey('average', $resp);
|
||||
$this->assertArrayHasKey('maximum', $resp);
|
||||
$this->assertArrayHasKey('minimum', $resp);
|
||||
}
|
||||
}
|
||||
42
tests/Unit/Controllers/SpeedtestController/RunTest.php
Normal file
42
tests/Unit/Controllers/SpeedtestController/RunTest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Controllers\SpeedtestController;
|
||||
|
||||
use App\Http\Controllers\SpeedtestController;
|
||||
use App\Jobs\SpeedtestJob;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Queue;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RunTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* SpeedtestController
|
||||
*
|
||||
* @var SpeedtestController
|
||||
*/
|
||||
private $controller;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->controller = new SpeedtestController();
|
||||
}
|
||||
|
||||
public function testRun()
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
$resp = $this->controller->run()->original;
|
||||
|
||||
$this->assertArrayHasKey('method', $resp);
|
||||
$this->assertArrayHasKey('data', $resp);
|
||||
|
||||
Queue::assertPushed(SpeedtestJob::class, function($job) {
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
43
tests/Unit/Controllers/SpeedtestController/TimeTest.php
Normal file
43
tests/Unit/Controllers/SpeedtestController/TimeTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Controllers\SpeedtestController;
|
||||
|
||||
use App\Http\Controllers\SpeedtestController;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TimeTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* SpeedtestController
|
||||
*
|
||||
* @var SpeedtestController
|
||||
*/
|
||||
private $controller;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->controller = new SpeedtestController();
|
||||
}
|
||||
|
||||
public function testTime()
|
||||
{
|
||||
$resp = $this->controller->time(5)->original;
|
||||
|
||||
$this->assertArrayHasKey('method', $resp);
|
||||
$this->assertArrayHasKey('data', $resp);
|
||||
$this->assertArrayHasKey('days', $resp);
|
||||
}
|
||||
|
||||
public function testTimeInvalidInput()
|
||||
{
|
||||
$resp = $this->controller->time('test')->original;
|
||||
|
||||
$this->assertArrayHasKey('method', $resp);
|
||||
$this->assertArrayHasKey('error', $resp);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Helpers\NotificationsHelper;
|
||||
|
||||
use App\Helpers\NotificationsHelper;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ThresholdMessageTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test absolute message
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAbsoluteMessageMultiField()
|
||||
{
|
||||
$msg = NotificationsHelper::formatAbsoluteThresholdMessage([ 'ping', 'upload' ]);
|
||||
|
||||
$this->assertEquals('For the latest speedtest, the ping, upload values exceeded the absolute threshold', $msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test absolute message
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAbsoluteMessageSingleField()
|
||||
{
|
||||
$msg = NotificationsHelper::formatAbsoluteThresholdMessage([ 'ping' ]);
|
||||
|
||||
$this->assertEquals('For the latest speedtest, the ping value exceeded the absolute threshold', $msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test absolute message
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPercentageMessageMultiField()
|
||||
{
|
||||
$msg = NotificationsHelper::formatPercentageThresholdMessage([ 'ping', 'upload' ]);
|
||||
|
||||
$this->assertEquals('For the latest speedtest, the ping, upload values exceeded the percentage threshold', $msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test absolute message
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPercentageMessageSingleField()
|
||||
{
|
||||
$msg = NotificationsHelper::formatPercentageThresholdMessage([ 'ping' ]);
|
||||
|
||||
$this->assertEquals('For the latest speedtest, the ping value exceeded the percentage threshold', $msg);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user