Merge pull request #521 from henrywhitaker3/alpha

Bunch of updates
This commit is contained in:
Henry Whitaker
2021-04-10 13:56:47 +01:00
committed by GitHub
50 changed files with 27466 additions and 1100 deletions

View File

@@ -56,4 +56,4 @@ jobs:
env:
DB_CONNECTION: sqlite
DB_DATABASE: database/database.sqlite
run: vendor/bin/phpunit
run: php artisan test --parallel

View File

@@ -1,6 +1,6 @@
# Speedtest Tracker
[![Docker pulls](https://img.shields.io/docker/pulls/henrywhitaker3/speedtest-tracker?style=flat-square)](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/henrywhitaker3/Speedtest-Tracker/Stable?label=master&logo=github&style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/henrywhitaker3/Speedtest-Tracker/Dev?label=dev&logo=github&style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [![last_commit](https://img.shields.io/github/last-commit/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [![issues](https://img.shields.io/github/issues/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) [![commit_freq](https://img.shields.io/github/commit-activity/m/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) ![version](https://img.shields.io/badge/version-v1.10.4-success?style=flat-square) [![license](https://img.shields.io/github/license/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/blob/master/LICENSE)
[![Docker pulls](https://img.shields.io/docker/pulls/henrywhitaker3/speedtest-tracker?style=flat-square)](https://hub.docker.com/r/henrywhitaker3/speedtest-tracker) [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/henrywhitaker3/Speedtest-Tracker/Stable?label=master&logo=github&style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/henrywhitaker3/Speedtest-Tracker/Dev?label=dev&logo=github&style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/actions) [![last_commit](https://img.shields.io/github/last-commit/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) [![issues](https://img.shields.io/github/issues/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/issues) [![commit_freq](https://img.shields.io/github/commit-activity/m/henrywhitaker3/Speedtest-Tracker?style=flat-square)](https://github.com/henrywhitaker3/Speedtest-Tracker/commits) ![version](https://img.shields.io/badge/version-v1.11.1-success?style=flat-square) [![license](https://img.shields.io/github/license/henrywhitaker3/Speedtest-Tracker?style=flat-square)](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.

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Actions;
use App\Speedtest;
use Cache;
use Carbon\Carbon;
use DB;
use Henrywhitaker3\LaravelActions\Interfaces\ActionInterface;
class GetFailedSpeedtestData implements ActionInterface
{
/**
* Run the action.
*
* @return mixed
*/
public function run($days = 7)
{
$ttl = Carbon::now()->addDays(1);
return Cache::remember('failure-rate-' . $days, $ttl, function () use ($days) {
$range = [
Carbon::today()
];
for ($i = 0; $i < ($days - 1); $i++) {
$prev = end($range);
$new = $prev->copy()->subDays(1);
array_push($range, $new);
}
$rate = [];
foreach ($range as $day) {
$success = Speedtest::select(DB::raw('COUNT(id) as rate'))->whereDate('created_at', $day)->where('failed', false)->get()[0]['rate'];
$fail = Speedtest::select(DB::raw('COUNT(id) as rate'))->whereDate('created_at', $day)->where('failed', true)->get()[0]['rate'];
array_push($rate, [
'date' => $day->toDateString(),
'success' => $success,
'failure' => $fail,
]);
}
return array_reverse($rate);
});
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace App\Actions;
use App\Helpers\SettingsHelper;
use App\Helpers\SpeedtestHelper;
use App\Speedtest;
use DB;
use Henrywhitaker3\LaravelActions\Interfaces\ActionInterface;
class GetLatestSpeedtestData implements ActionInterface
{
/**
* Run the action.
*
* @return mixed
*/
public function run()
{
$data = SpeedtestHelper::latest();
$response = [
'data' => $data,
];
if (SettingsHelper::get('show_average')) {
$avg = Speedtest::select(DB::raw('AVG(ping) as ping, AVG(download) as download, AVG(upload) as upload'))
->where('failed', false)
->first()
->toArray();
$response['average'] = $avg;
}
if (SettingsHelper::get('show_max')) {
$max = Speedtest::select(DB::raw('MAX(ping) as ping, MAX(download) as download, MAX(upload) as upload'))
->where('failed', false)
->first()
->toArray();
$response['maximum'] = $max;
}
if (SettingsHelper::get('show_min')) {
$min = Speedtest::select(DB::raw('MIN(ping) as ping, MIN(download) as download, MIN(upload) as upload'))
->where('failed', false)
->first()
->toArray();
$response['minimum'] = $min;
}
return $response;
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Actions;
use App\Helpers\SettingsHelper;
use App\Speedtest;
use Cache;
use Carbon\Carbon;
use Henrywhitaker3\LaravelActions\Interfaces\ActionInterface;
class GetSpeedtestTimeData implements ActionInterface
{
/**
* Run the action.
*
* @return mixed
*/
public function run($days = 7)
{
$ttl = Carbon::now()->addDays(1);
return Cache::remember('speedtest-days-' . $days, $ttl, function () use ($days) {
$showFailed = (bool)SettingsHelper::get('show_failed_tests_on_graph')->value;
if ($showFailed === true) {
return Speedtest::where('created_at', '>=', Carbon::now()->subDays($days))
->orderBy('created_at', 'asc')
->get();
}
return Speedtest::where('created_at', '>=', Carbon::now()->subDays($days))
->where('failed', false)
->orderBy('created_at', 'asc')
->get();
});
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace App\Actions;
use App\Helpers\SettingsHelper;
use App\Interfaces\SpeedtestProvider;
use App\Jobs\SpeedtestJob;
use Henrywhitaker3\LaravelActions\Interfaces\ActionInterface;
class QueueSpeedtest implements ActionInterface
{
private SpeedtestProvider $speedtestProvider;
/**
* Create a new action instance.
*
* @return void
*/
public function __construct(SpeedtestProvider $speedtestProvider)
{
$this->speedtestProvider = $speedtestProvider;
}
/**
* Run the action.
*
* @return mixed
*/
public function run()
{
SettingsHelper::loadIntegrationConfig();
SpeedtestJob::dispatch(false, config('integrations'), $this->speedtestProvider);
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace App\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
class CommaSeparatedArrayCast implements CastsAttributes
{
/**
* Array of settings that should be cast
*/
private array $shouldCast = [
'visible_columns',
'hidden_columns',
];
/**
* Cast the given value.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $key
* @param mixed $value
* @param array $attributes
* @return mixed
*/
public function get($model, $key, $value, $attributes)
{
if (!in_array($model->name, $this->shouldCast)) {
return $value;
}
return explode(',', $value);
}
/**
* Prepare the given value for storage.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $key
* @param mixed $value
* @param array $attributes
* @return mixed
*/
public function set($model, $key, $value, $attributes)
{
if (!in_array($model->name, $this->shouldCast)) {
return $value;
}
return implode(',', $value);
}
}

View File

@@ -38,6 +38,7 @@ class AcceptEULACommand extends Command
*/
public function handle()
{
shell_exec(config('speedtest.home') . ' && ' . app_path() . '/Bin/speedtest --accept-license --accept-gdpr');
$this->info('Acceping EULA');
shell_exec(config('speedtest.home') . ' && timeout 3s ' . app_path() . '/Bin/speedtest --accept-license --accept-gdpr');
}
}

View File

@@ -3,6 +3,7 @@
namespace App\Console\Commands;
use App\Helpers\SpeedtestHelper;
use App\Interfaces\SpeedtestProvider;
use Illuminate\Console\Command;
class SpeedtestCommand extends Command
@@ -21,13 +22,17 @@ class SpeedtestCommand extends Command
*/
protected $description = 'Performs a new speedtest';
private SpeedtestProvider $speedtestProvider;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
public function __construct(SpeedtestProvider $speedtestProvider)
{
$this->speedtestProvider = $speedtestProvider;
parent::__construct();
}
@@ -40,14 +45,14 @@ class SpeedtestCommand extends Command
{
$this->info('Running speedtest, this might take a while...');
$results = SpeedtestHelper::runSpeedtest(false, false);
$results = $this->speedtestProvider->run(false, false);
if(!is_object($results)) {
if (!is_object($results)) {
$this->error('Something went wrong running the speedtest.');
exit();
}
if(property_exists($results, 'ping') && property_exists($results, 'download') && property_exists($results, 'upload')) {
if (property_exists($results, 'ping') && property_exists($results, 'download') && property_exists($results, 'upload')) {
$this->error('Something went wrong running the speedtest.');
exit();
}

View File

@@ -3,6 +3,7 @@
namespace App\Console\Commands;
use App\Helpers\SpeedtestHelper;
use App\Interfaces\SpeedtestProvider;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
@@ -22,13 +23,17 @@ class SpeedtestLatestCommand extends Command
*/
protected $description = 'Returns the latest speedtest result';
private SpeedtestProvider $speedtestProvider;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
public function __construct(SpeedtestProvider $speedtestProvider)
{
$this->speedtestProvider = $speedtestProvider;
parent::__construct();
}
@@ -41,8 +46,8 @@ class SpeedtestLatestCommand extends Command
{
$latest = SpeedtestHelper::latest();
if($latest) {
if($latest->scheduled) {
if ($latest) {
if ($latest->scheduled) {
$extra = '(scheduled)';
} else {
$extra = '(manual)';
@@ -50,7 +55,7 @@ class SpeedtestLatestCommand extends Command
$this->info('Last speedtest run at: ' . $latest->created_at . ' ' . $extra);
if($latest->failed) {
if ($latest->failed) {
$this->error('Speedtest failed');
} else {
$this->info('Ping: ' . $latest->ping . ' ms');
@@ -62,7 +67,7 @@ class SpeedtestLatestCommand extends Command
$this->info('Running speedtest, this might take a while...');
$results = SpeedtestHelper::runSpeedtest();
$results = $this->speedtestProvider->run();
$this->info('Ping: ' . $results->ping . ' ms');
$this->info('Download: ' . $results->download . ' Mbit/s');

View File

@@ -5,6 +5,7 @@ namespace App\Console;
use App\Events\SpeedtestOverviewEvent;
use App\Helpers\SettingsHelper;
use App\Helpers\SpeedtestHelper;
use App\Interfaces\SpeedtestProvider;
use App\Jobs\SpeedtestJob;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
@@ -29,9 +30,17 @@ class Kernel extends ConsoleKernel
protected function schedule(Schedule $schedule)
{
if ((bool)SettingsHelper::get('schedule_enabled')->value) {
$schedule->job(new SpeedtestJob(true, config('integrations')))->cron(SettingsHelper::get('schedule')['value']);
$schedule->job(
new SpeedtestJob(
true,
config('integrations'),
app()->make(SpeedtestProvider::class)
)
)
->cron(SettingsHelper::get('schedule')['value'])
->timezone(env('TZ', 'UTC'));
}
$schedule->command('speedtest:overview')->cron('0 ' . SettingsHelper::get('speedtest_overview_time')->value . ' * * *');
$schedule->command('speedtest:overview')->cron('0 ' . SettingsHelper::get('speedtest_overview_time')->value . ' * * *')->timezone(env('TZ', 'UTC'));
$schedule->command('speedtest:clear-sessions')->everyMinute();
}

View File

@@ -0,0 +1,10 @@
<?php
namespace App\Exceptions;
use Exception;
class SpeedtestFailureException extends Exception
{
//
}

View File

@@ -9,6 +9,7 @@ use Carbon\Carbon;
class SettingsHelper
{
private static $settings = null;
/**
* Get a Setting object by name
@@ -23,7 +24,7 @@ class SettingsHelper
if (sizeof($name) == 0) {
return false;
} else if (sizeof($name) == 1) {
return $name[0];
return $name->first();
} else {
$name = $name->keyBy('name');
return $name->all();
@@ -163,6 +164,10 @@ class SettingsHelper
'telegram_bot_token' => SettingsHelper::settingIsEditable('telegram_bot_token'),
'telegram_chat_id' => SettingsHelper::settingIsEditable('telegram_chat_id'),
],
'tables' => [
'visible_columns' => SettingsHelper::get('visible_columns')->value,
'hidden_columns' => SettingsHelper::get('hidden_columns')->value,
],
'auth' => (bool)SettingsHelper::get('auth')->value
];
}

View File

@@ -3,6 +3,7 @@
namespace App\Helpers;
use App\Speedtest;
use App\Utils\OoklaTester;
use Carbon\Carbon;
use Exception;
use Henrywhitaker3\Healthchecks\Healthchecks;
@@ -13,7 +14,8 @@ use Illuminate\Support\Facades\Log;
use InvalidArgumentException;
use JsonException;
class SpeedtestHelper {
class SpeedtestHelper
{
/**
* Runs/processes speedtest output to created a Speedtest object
@@ -21,79 +23,10 @@ class SpeedtestHelper {
* @param boolean|string $output If false, new speedtest runs. If anything else, will try to parse as JSON for speedtest results.
* @return \App\Speedtest|bool
*/
public static function runSpeedtest($output = false, $scheduled = true)
public static function runSpeedtest()
{
if($output === false) {
$output = SpeedtestHelper::output();
}
try {
$output = json_decode($output, true, 512, JSON_THROW_ON_ERROR);
if(!SpeedtestHelper::checkOutputIsComplete($output)) {
$test = false;
}
$test = Speedtest::create([
'ping' => $output['ping']['latency'],
'download' => SpeedtestHelper::convert($output['download']['bandwidth']),
'upload' => SpeedtestHelper::convert($output['upload']['bandwidth']),
'server_id' => $output['server']['id'],
'server_name' => $output['server']['name'],
'server_host' => $output['server']['host'] . ':' . $output['server']['port'],
'url' => $output['result']['url'],
'scheduled' => $scheduled
]);
} catch(JsonException $e) {
Log::error('Failed to parse speedtest JSON');
Log::error($output);
$test = false;
} catch(Exception $e) {
Log::error($e->getMessage());
$test = false;
}
if($test == false) {
Speedtest::create([
'ping' => 0,
'upload' => 0,
'download' => 0,
'failed' => true,
'scheduled' => $scheduled,
]);
return false;
}
Cache::flush();
return $test;
}
/**
* Gets the output of executing speedtest binary.
*
* @return boolean|string
*/
public static function output()
{
$server = SettingsHelper::get('server')['value'];
$binPath = app_path() . DIRECTORY_SEPARATOR . 'Bin' . DIRECTORY_SEPARATOR . 'speedtest';
$homePrefix = config('speedtest.home') . ' && ';
if($server != '' && $server != false) {
$server = explode(',', $server);
$server = $server[array_rand($server)];
if($server == false) {
Log::error('Speedtest server undefined');
return false;
}
return shell_exec($homePrefix . $binPath . ' -f json -s ' . $server);
}
return shell_exec($homePrefix . $binPath . ' -f json');
$tester = new OoklaTester();
return $tester->run();
}
/**
@@ -119,8 +52,9 @@ class SpeedtestHelper {
* @param int|float $bytes
* @return int|float
*/
public static function convert($bytes) {
return ( $bytes * 8 ) / 1000000;
public static function convert($bytes)
{
return ($bytes * 8) / 1000000;
}
/**
@@ -132,7 +66,7 @@ class SpeedtestHelper {
{
$data = Speedtest::latest()->get();
if($data->isEmpty()) {
if ($data->isEmpty()) {
return false;
}
@@ -152,7 +86,7 @@ class SpeedtestHelper {
$val = (float)$input[0];
$unit = explode('/', $input[1])[0];
switch($unit) {
switch ($unit) {
case 'Mbyte':
$val = $val * 8;
break;
@@ -173,86 +107,6 @@ class SpeedtestHelper {
];
}
/**
* Checks that the speedtest JSON output is complete/valid
*
* @param array $output
* @return boolean
*/
public static function checkOutputIsComplete($output)
{
/**
* Array of indexes that must exist in $output
*/
$checks = [
'type' => 'result',
'download' => [ 'bandwidth' => '*' ],
'upload' => [ 'bandwidth' => '*' ],
'ping' => [ 'latency' => '*' ],
'server' => [
'id' => '*',
'name' => '*',
'host' => '*',
'port' => '*'
],
'result' => [
'url' => '*'
],
];
/**
* Array of indexes that must not exist
*/
$checkMissing = [
'type' => 'error'
];
foreach($checks as $key => $value) {
if(!isset($output[$key])) {
return false;
}
}
return true;
}
/**
* Get a percentage rate of failure by days
*
* @param integer $days number of days to get rate for
* @return integer percentage fail rate
*/
public static function failureRate(int $days)
{
$ttl = Carbon::now()->addDays(1);
$rate = Cache::remember('failure-rate-' . $days, $ttl, function () use ($days) {
$range = [
Carbon::today()
];
for($i = 0; $i < ($days - 1); $i++) {
$prev = end($range);
$new = $prev->copy()->subDays(1);
array_push($range, $new);
}
$rate = [];
foreach($range as $day) {
$success = Speedtest::select(DB::raw('COUNT(id) as rate'))->whereDate('created_at', $day)->where('failed', false)->get()[0]['rate'];
$fail = Speedtest::select(DB::raw('COUNT(id) as rate'))->whereDate('created_at', $day)->where('failed', true)->get()[0]['rate'];
array_push($rate, [
'date' => $day->toDateString(),
'success' => $success,
'failure' => $fail,
]);
}
return array_reverse($rate);
});
return $rate;
}
/**
* Create a backup of the SQLite database
*
@@ -260,14 +114,14 @@ class SpeedtestHelper {
*/
public static function dbBackup()
{
if(env('DB_CONNECTION') === 'sqlite') {
if(env('DB_DATABASE') !== null) {
if (env('DB_CONNECTION') === 'sqlite') {
if (env('DB_DATABASE') !== null) {
$current = env('DB_DATABASE');
try {
if(File::copy($current, $current . '.bak')) {
if (File::copy($current, $current . '.bak')) {
return true;
}
}catch(Exception $e) {
} catch (Exception $e) {
return false;
}
}
@@ -289,8 +143,8 @@ class SpeedtestHelper {
SpeedtestHelper::dbBackup();
if(sizeof(Speedtest::whereNotNull('id')->get()) > 0) {
if(Speedtest::whereNotNull('id')->delete()) {
if (sizeof(Speedtest::whereNotNull('id')->get()) > 0) {
if (Speedtest::whereNotNull('id')->delete()) {
return [
'success' => true,
];
@@ -311,7 +165,7 @@ class SpeedtestHelper {
*/
public static function testIsLowerThanThreshold(String $type, Speedtest $test)
{
if($type == 'percentage') {
if ($type == 'percentage') {
$avg = Speedtest::select(DB::raw('AVG(ping) as ping, AVG(download) as download, AVG(upload) as upload'))
->where('failed', false)
->get()
@@ -319,23 +173,23 @@ class SpeedtestHelper {
$threshold = SettingsHelper::get('threshold_alert_percentage')->value;
if($threshold == '') {
if ($threshold == '') {
return [];
}
$errors = [];
foreach($avg as $key => $value) {
if($key == 'ping') {
$threshold = (float)$value * (1 + ( $threshold / 100 ));
foreach ($avg as $key => $value) {
if ($key == 'ping') {
$threshold = (float)$value * (1 + ($threshold / 100));
if($test->$key > $threshold) {
if ($test->$key > $threshold) {
array_push($errors, $key);
}
} else {
$threshold = (float)$value * (1 - ( $threshold / 100 ));
$threshold = (float)$value * (1 - ($threshold / 100));
if($test->$key < $threshold) {
if ($test->$key < $threshold) {
array_push($errors, $key);
}
}
@@ -344,7 +198,7 @@ class SpeedtestHelper {
return $errors;
}
if($type == 'absolute') {
if ($type == 'absolute') {
$thresholds = [
'download' => SettingsHelper::get('threshold_alert_absolute_download')->value,
'upload' => SettingsHelper::get('threshold_alert_absolute_upload')->value,
@@ -353,17 +207,17 @@ class SpeedtestHelper {
$errors = [];
foreach($thresholds as $key => $value) {
if($value == '') {
foreach ($thresholds as $key => $value) {
if ($value == '') {
continue;
}
if($key == 'ping') {
if($test->$key > $value) {
if ($key == 'ping') {
if ($test->$key > $value) {
array_push($errors, $key);
}
} else {
if($test->$key < $value) {
if ($test->$key < $value) {
array_push($errors, $key);
}
}
@@ -374,4 +228,42 @@ class SpeedtestHelper {
throw new InvalidArgumentException();
}
/**
* Get a percentage rate of failure by days
*
* @param integer $days number of days to get rate for
* @return integer percentage fail rate
*/
public static function failureRate(int $days)
{
$ttl = Carbon::now()->addDays(1);
$rate = Cache::remember('failure-rate-' . $days, $ttl, function () use ($days) {
$range = [
Carbon::today()
];
for ($i = 0; $i < ($days - 1); $i++) {
$prev = end($range);
$new = $prev->copy()->subDays(1);
array_push($range, $new);
}
$rate = [];
foreach ($range as $day) {
$success = Speedtest::select(DB::raw('COUNT(id) as rate'))->whereDate('created_at', $day)->where('failed', false)->get()[0]['rate'];
$fail = Speedtest::select(DB::raw('COUNT(id) as rate'))->whereDate('created_at', $day)->where('failed', true)->get()[0]['rate'];
array_push($rate, [
'date' => $day->toDateString(),
'success' => $success,
'failure' => $fail,
]);
}
return array_reverse($rate);
});
return $rate;
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace App\Http\Controllers;
use App\Actions\GetFailedSpeedtestData;
use App\Actions\GetLatestSpeedtestData;
use App\Actions\GetSpeedtestTimeData;
use App\Helpers\SettingsHelper;
use Illuminate\Http\Request;
use Validator;
class HomepageDataController extends Controller
{
public function __invoke($days)
{
$validator = Validator::make(
['days' => $days],
['days' => ['required', 'numeric']],
);
if ($validator->fails()) {
return response()->json([
'method' => 'get speedtests in last x days',
'error' => $validator->errors(),
], 422);
}
return [
'latest' => run(GetLatestSpeedtestData::class),
'time' => run(GetSpeedtestTimeData::class),
'fail' => run(GetFailedSpeedtestData::class),
'config' => SettingsHelper::getConfig(),
];
}
}

View File

@@ -2,6 +2,10 @@
namespace App\Http\Controllers;
use App\Actions\GetFailedSpeedtestData;
use App\Actions\GetLatestSpeedtestData;
use App\Actions\GetSpeedtestTimeData;
use App\Actions\QueueSpeedtest;
use App\Helpers\SettingsHelper;
use App\Helpers\SpeedtestHelper;
use App\Jobs\SpeedtestJob;
@@ -61,21 +65,7 @@ class SpeedtestController extends Controller
], 422);
}
$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();
});
$data = run(GetSpeedtestTimeData::class, $days);
return response()->json([
'method' => 'get speedtests in last x days',
@@ -105,7 +95,7 @@ class SpeedtestController extends Controller
], 422);
}
$data = SpeedtestHelper::failureRate($days);
$data = run(GetFailedSpeedtestData::class, $days);
return response()->json([
'method' => 'get speedtests in last x days',
@@ -121,39 +111,10 @@ class SpeedtestController extends Controller
*/
public function latest()
{
$data = SpeedtestHelper::latest();
$data = run(GetLatestSpeedtestData::class);
$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);
if ($data['data']) {
return response()->json($data, 200);
} else {
return response()->json([
'method' => 'get latest speedtest',
@@ -170,8 +131,8 @@ class SpeedtestController extends Controller
public function run()
{
try {
SettingsHelper::loadIntegrationConfig();
$data = SpeedtestJob::dispatch(false, config('integrations'));
run(QueueSpeedtest::class);
return response()->json([
'method' => 'run speedtest',
'data' => 'a new speedtest has been added to the queue'

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Interfaces;
use App\Speedtest;
interface SpeedtestProvider
{
public function run(): Speedtest;
public function output();
}

View File

@@ -6,6 +6,8 @@ use App\Events\SpeedtestCompleteEvent;
use App\Events\SpeedtestFailedEvent;
use App\Helpers\SettingsHelper;
use App\Helpers\SpeedtestHelper;
use App\Interfaces\SpeedtestProvider;
use App\Utils\OoklaTester;
use Exception;
use Healthcheck;
use Henrywhitaker3\Healthchecks\Healthchecks;
@@ -34,15 +36,18 @@ class SpeedtestJob implements ShouldQueue
*/
private $config;
private SpeedtestProvider $speedtestProvider;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($scheduled = true, $config = [])
public function __construct($scheduled = true, $config = [], SpeedtestProvider $speedtestProvider)
{
$this->scheduled = $scheduled;
$this->config = $config;
$this->speedtestProvider = $speedtestProvider;
}
/**
@@ -55,8 +60,8 @@ class SpeedtestJob implements ShouldQueue
if ($this->config['healthchecks_enabled'] === true) {
$this->healthcheck('start');
}
$output = SpeedtestHelper::output();
$speedtest = SpeedtestHelper::runSpeedtest($output, $this->scheduled);
$output = $this->speedtestProvider->output();
$speedtest = $this->speedtestProvider->run($output, $this->scheduled);
if ($speedtest == false) {
if ($this->config['healthchecks_enabled'] === true) {
$this->healthcheck('fail');

View File

@@ -15,7 +15,7 @@ class RouteServiceProvider extends ServiceProvider
*
* @var string
*/
protected $namespace = 'App\Http\Controllers';
protected $namespace = null;
/**
* The path to the "home" route for your application.

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Providers;
use App\Helpers\SettingsHelper;
use App\Interfaces\SpeedtestProvider;
use App\Utils\OoklaTester;
use File;
use Illuminate\Support\ServiceProvider;
use Schema;
class SpeedtestServiceProvider extends ServiceProvider
{
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
$this->app->singleton(
SpeedtestProvider::class,
function () {
return new OoklaTester();
}
);
}
}

View File

@@ -2,6 +2,7 @@
namespace App;
use App\Casts\CommaSeparatedArrayCast;
use App\Helpers\SettingsHelper;
use Illuminate\Database\Eloquent\Model;
@@ -17,4 +18,8 @@ class Setting extends Model
];
protected $table = 'settings';
protected $casts = [
'value' => CommaSeparatedArrayCast::class,
];
}

128
app/Utils/OoklaTester.php Normal file
View File

@@ -0,0 +1,128 @@
<?php
namespace App\Utils;
use App\Exceptions\SpeedtestFailureException;
use App\Helpers\SettingsHelper;
use App\Helpers\SpeedtestHelper;
use App\Interfaces\SpeedtestProvider;
use App\Speedtest;
use Cache;
use Exception;
use JsonException;
use Log;
class OoklaTester implements SpeedtestProvider
{
public function run($output = false, $scheduled = true): Speedtest
{
if ($output === false) {
$output = $this->output();
}
try {
$output = json_decode($output, true, 512, JSON_THROW_ON_ERROR);
if (!$this->isOutputComplete($output)) {
$test = false;
}
$test = Speedtest::create([
'ping' => $output['ping']['latency'],
'download' => SpeedtestHelper::convert($output['download']['bandwidth']),
'upload' => SpeedtestHelper::convert($output['upload']['bandwidth']),
'server_id' => $output['server']['id'],
'server_name' => $output['server']['name'],
'server_host' => $output['server']['host'] . ':' . $output['server']['port'],
'url' => $output['result']['url'],
'scheduled' => $scheduled
]);
} catch (JsonException $e) {
Log::error('Failed to parse speedtest JSON');
Log::error($output);
$test = false;
} catch (Exception $e) {
Log::error($e->getMessage());
$test = false;
}
if ($test == false) {
Speedtest::create([
'ping' => 0,
'upload' => 0,
'download' => 0,
'failed' => true,
'scheduled' => $scheduled,
]);
throw new SpeedtestFailureException(json_encode($output));
}
Cache::flush();
return $test;
}
public function output()
{
$server = SettingsHelper::get('server')['value'];
$binPath = app_path() . DIRECTORY_SEPARATOR . 'Bin' . DIRECTORY_SEPARATOR . 'speedtest';
$homePrefix = config('speedtest.home') . ' && ';
if ($server != '' && $server != false) {
$server = explode(',', $server);
$server = $server[array_rand($server)];
if ($server == false) {
Log::error('Speedtest server undefined');
return false;
}
return shell_exec($homePrefix . $binPath . ' -f json -s ' . $server);
}
return shell_exec($homePrefix . $binPath . ' -f json');
}
/**
* Checks that the speedtest JSON output is complete/valid
*
* @param array $output
* @return boolean
*/
public static function isOutputComplete($output)
{
/**
* Array of indexes that must exist in $output
*/
$checks = [
'type' => 'result',
'download' => ['bandwidth' => '*'],
'upload' => ['bandwidth' => '*'],
'ping' => ['latency' => '*'],
'server' => [
'id' => '*',
'name' => '*',
'host' => '*',
'port' => '*'
],
'result' => [
'url' => '*'
],
];
/**
* Array of indexes that must not exist
*/
$checkMissing = [
'type' => 'error'
];
foreach ($checks as $key => $value) {
if (!isset($output[$key])) {
return false;
}
}
return true;
}
}

View File

@@ -1,4 +1,28 @@
{
"1.11.1": [
{
"description": "Add option to show/hide columns in the all tests table.",
"link": ""
},
{
"description": "Add option to delete failed tests.",
"link": ""
}
],
"1.11.0": [
{
"description": "Upgrade to Laravel 8.",
"link": ""
},
{
"description": "Refactor loads of back-end stuff.",
"link": ""
},
{
"description": "Refactor front-end stuff.",
"link": ""
}
],
"1.10.4": [
{
"description": "Updated dependencies.",

View File

@@ -10,26 +10,29 @@
"require": {
"php": "^7.2.5",
"doctrine/dbal": "^2.10",
"dragonmantank/cron-expression": "^2",
"dragonmantank/cron-expression": "^3",
"fideloper/proxy": "^4.2",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0",
"guzzlehttp/guzzle": "^7.0.1",
"henrywhitaker3/healthchecks-io": "^1.0",
"henrywhitaker3/laravel-actions": "^1.0",
"laravel-notification-channels/telegram": "^0.5.0",
"laravel/framework": "^7.0",
"laravel/framework": "^8.0",
"laravel/slack-notification-channel": "^2.0",
"laravel/tinker": "^2.0",
"laravel/ui": "^2.0",
"laravel/ui": "^3.0",
"tymon/jwt-auth": "^1.0"
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^2.8",
"facade/ignition": "^2.0",
"brianium/paratest": "^6.2",
"facade/ignition": "^2.3.6",
"fzaninotto/faker": "^1.9.1",
"itsgoingd/clockwork": "^5.0",
"mockery/mockery": "^1.3.1",
"phpunit/phpunit": "^9.5",
"nunomaduro/collision": "^5.3",
"nunomaduro/larastan": "^0.7.0",
"nunomaduro/collision": "^5.3"
"phpunit/phpunit": "^9.5"
},
"config": {
"optimize-autoloader": true,

590
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "19bd0375e29ab5c67bacc1ea15b2e4e8",
"content-hash": "102adc5121f97ad3ad15009f410fb8fa",
"packages": [
{
"name": "asm89/stack-cors",
@@ -637,30 +637,32 @@
},
{
"name": "dragonmantank/cron-expression",
"version": "v2.3.1",
"version": "v3.1.0",
"source": {
"type": "git",
"url": "https://github.com/dragonmantank/cron-expression.git",
"reference": "65b2d8ee1f10915efb3b55597da3404f096acba2"
"reference": "7a8c6e56ab3ffcc538d05e8155bb42269abf1a0c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/dragonmantank/cron-expression/zipball/65b2d8ee1f10915efb3b55597da3404f096acba2",
"reference": "65b2d8ee1f10915efb3b55597da3404f096acba2",
"url": "https://api.github.com/repos/dragonmantank/cron-expression/zipball/7a8c6e56ab3ffcc538d05e8155bb42269abf1a0c",
"reference": "7a8c6e56ab3ffcc538d05e8155bb42269abf1a0c",
"shasum": ""
},
"require": {
"php": "^7.0|^8.0"
"php": "^7.2|^8.0",
"webmozart/assert": "^1.7.0"
},
"replace": {
"mtdowling/cron-expression": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^6.4|^7.0|^8.0|^9.0"
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-webmozart-assert": "^0.12.7",
"phpunit/phpunit": "^7.0|^8.0|^9.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.3-dev"
}
},
"autoload": {
"psr-4": {
"Cron\\": "src/Cron/"
@@ -671,11 +673,6 @@
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Chris Tankersley",
"email": "chris@ctankersley.com",
@@ -689,7 +686,7 @@
],
"support": {
"issues": "https://github.com/dragonmantank/cron-expression/issues",
"source": "https://github.com/dragonmantank/cron-expression/tree/v2.3.1"
"source": "https://github.com/dragonmantank/cron-expression/tree/v3.1.0"
},
"funding": [
{
@@ -697,7 +694,7 @@
"type": "github"
}
],
"time": "2020-10-13T00:52:37+00:00"
"time": "2020-11-24T19:55:57+00:00"
},
{
"name": "egulias/email-validator",
@@ -902,6 +899,72 @@
],
"time": "2020-10-22T13:57:20+00:00"
},
{
"name": "graham-campbell/result-type",
"version": "v1.0.1",
"source": {
"type": "git",
"url": "https://github.com/GrahamCampbell/Result-Type.git",
"reference": "7e279d2cd5d7fbb156ce46daada972355cea27bb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/GrahamCampbell/Result-Type/zipball/7e279d2cd5d7fbb156ce46daada972355cea27bb",
"reference": "7e279d2cd5d7fbb156ce46daada972355cea27bb",
"shasum": ""
},
"require": {
"php": "^7.0|^8.0",
"phpoption/phpoption": "^1.7.3"
},
"require-dev": {
"phpunit/phpunit": "^6.5|^7.5|^8.5|^9.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"GrahamCampbell\\ResultType\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Graham Campbell",
"email": "graham@alt-three.com"
}
],
"description": "An Implementation Of The Result Type",
"keywords": [
"Graham Campbell",
"GrahamCampbell",
"Result Type",
"Result-Type",
"result"
],
"support": {
"issues": "https://github.com/GrahamCampbell/Result-Type/issues",
"source": "https://github.com/GrahamCampbell/Result-Type/tree/v1.0.1"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/graham-campbell/result-type",
"type": "tidelift"
}
],
"time": "2020-04-13T13:17:36+00:00"
},
{
"name": "guzzlehttp/guzzle",
"version": "7.2.0",
@@ -1006,16 +1069,16 @@
},
{
"name": "guzzlehttp/promises",
"version": "1.4.0",
"version": "1.4.1",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
"reference": "60d379c243457e073cff02bc323a2a86cb355631"
"reference": "8e7d04f1f6450fef59366c399cfad4b9383aa30d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/60d379c243457e073cff02bc323a2a86cb355631",
"reference": "60d379c243457e073cff02bc323a2a86cb355631",
"url": "https://api.github.com/repos/guzzle/promises/zipball/8e7d04f1f6450fef59366c399cfad4b9383aa30d",
"reference": "8e7d04f1f6450fef59366c399cfad4b9383aa30d",
"shasum": ""
},
"require": {
@@ -1055,9 +1118,9 @@
],
"support": {
"issues": "https://github.com/guzzle/promises/issues",
"source": "https://github.com/guzzle/promises/tree/1.4.0"
"source": "https://github.com/guzzle/promises/tree/1.4.1"
},
"time": "2020-09-30T07:37:28+00:00"
"time": "2021-03-07T09:25:29+00:00"
},
{
"name": "guzzlehttp/psr7",
@@ -1189,6 +1252,63 @@
},
"time": "2020-08-21T23:17:42+00:00"
},
{
"name": "henrywhitaker3/laravel-actions",
"version": "v1.0.5",
"source": {
"type": "git",
"url": "https://github.com/henrywhitaker3/laravel-actions.git",
"reference": "2a8a7c0a0be7083c0c1fcbea0ba6a57220a17939"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/henrywhitaker3/laravel-actions/zipball/2a8a7c0a0be7083c0c1fcbea0ba6a57220a17939",
"reference": "2a8a7c0a0be7083c0c1fcbea0ba6a57220a17939",
"shasum": ""
},
"require": {
"illuminate/support": "~7|~8"
},
"require-dev": {
"orchestra/testbench": "~5|~6",
"phpunit/phpunit": "~9.0"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Henrywhitaker3\\LaravelActions\\LaravelActionsServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Henrywhitaker3\\LaravelActions\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Henry Whitaker",
"email": "henrywhitaker3@outlook.com",
"homepage": "https://github.com/henrywhitaker3"
}
],
"description": "Simple actions package for Laravel",
"homepage": "https://github.com/henrywhitaker3/laravel-actions",
"keywords": [
"LaravelActions",
"laravel"
],
"support": {
"issues": "https://github.com/henrywhitaker3/laravel-actions/issues",
"source": "https://github.com/henrywhitaker3/laravel-actions/tree/v1.0.5"
},
"time": "2021-02-06T09:50:49+00:00"
},
{
"name": "laravel-notification-channels/telegram",
"version": "0.5.1",
@@ -1256,21 +1376,21 @@
},
{
"name": "laravel/framework",
"version": "v7.30.4",
"version": "v8.31.0",
"source": {
"type": "git",
"url": "https://github.com/laravel/framework.git",
"reference": "9dd38140dc2924daa1a020a3d7a45f9ceff03df3"
"reference": "2aa5c2488d25178ebc097052c7897a0e463ddc35"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/framework/zipball/9dd38140dc2924daa1a020a3d7a45f9ceff03df3",
"reference": "9dd38140dc2924daa1a020a3d7a45f9ceff03df3",
"url": "https://api.github.com/repos/laravel/framework/zipball/2aa5c2488d25178ebc097052c7897a0e463ddc35",
"reference": "2aa5c2488d25178ebc097052c7897a0e463ddc35",
"shasum": ""
},
"require": {
"doctrine/inflector": "^1.4|^2.0",
"dragonmantank/cron-expression": "^2.3.1",
"dragonmantank/cron-expression": "^3.0.2",
"egulias/email-validator": "^2.1.10",
"ext-json": "*",
"ext-mbstring": "*",
@@ -1280,23 +1400,22 @@
"monolog/monolog": "^2.0",
"nesbot/carbon": "^2.31",
"opis/closure": "^3.6",
"php": "^7.2.5|^8.0",
"php": "^7.3|^8.0",
"psr/container": "^1.0",
"psr/simple-cache": "^1.0",
"ramsey/uuid": "^3.7|^4.0",
"ramsey/uuid": "^4.0",
"swiftmailer/swiftmailer": "^6.0",
"symfony/console": "^5.0",
"symfony/error-handler": "^5.0",
"symfony/finder": "^5.0",
"symfony/http-foundation": "^5.0",
"symfony/http-kernel": "^5.0",
"symfony/mime": "^5.0",
"symfony/polyfill-php73": "^1.17",
"symfony/process": "^5.0",
"symfony/routing": "^5.0",
"symfony/var-dumper": "^5.0",
"symfony/console": "^5.1.4",
"symfony/error-handler": "^5.1.4",
"symfony/finder": "^5.1.4",
"symfony/http-foundation": "^5.1.4",
"symfony/http-kernel": "^5.1.4",
"symfony/mime": "^5.1.4",
"symfony/process": "^5.1.4",
"symfony/routing": "^5.1.4",
"symfony/var-dumper": "^5.1.4",
"tijsverkoyen/css-to-inline-styles": "^2.2.2",
"vlucas/phpdotenv": "^4.0",
"vlucas/phpdotenv": "^5.2",
"voku/portable-ascii": "^1.4.8"
},
"conflict": {
@@ -1310,6 +1429,7 @@
"illuminate/broadcasting": "self.version",
"illuminate/bus": "self.version",
"illuminate/cache": "self.version",
"illuminate/collections": "self.version",
"illuminate/config": "self.version",
"illuminate/console": "self.version",
"illuminate/container": "self.version",
@@ -1322,6 +1442,7 @@
"illuminate/hashing": "self.version",
"illuminate/http": "self.version",
"illuminate/log": "self.version",
"illuminate/macroable": "self.version",
"illuminate/mail": "self.version",
"illuminate/notifications": "self.version",
"illuminate/pagination": "self.version",
@@ -1338,21 +1459,21 @@
},
"require-dev": {
"aws/aws-sdk-php": "^3.155",
"doctrine/dbal": "^2.6",
"doctrine/dbal": "^2.6|^3.0",
"filp/whoops": "^2.8",
"guzzlehttp/guzzle": "^6.3.1|^7.0.1",
"guzzlehttp/guzzle": "^6.5.5|^7.0.1",
"league/flysystem-cached-adapter": "^1.0",
"mockery/mockery": "~1.3.3|^1.4.2",
"moontoast/math": "^1.1",
"orchestra/testbench-core": "^5.8",
"mockery/mockery": "^1.4.2",
"orchestra/testbench-core": "^6.8",
"pda/pheanstalk": "^4.0",
"phpunit/phpunit": "^8.4|^9.3.3",
"phpunit/phpunit": "^8.5.8|^9.3.3",
"predis/predis": "^1.1.1",
"symfony/cache": "^5.0"
"symfony/cache": "^5.1.4"
},
"suggest": {
"aws/aws-sdk-php": "Required to use the SQS queue driver, DynamoDb failed job storage and SES mail driver (^3.155).",
"doctrine/dbal": "Required to rename columns and drop SQLite columns (^2.6).",
"brianium/paratest": "Required to run tests in parallel (^6.0).",
"doctrine/dbal": "Required to rename columns and drop SQLite columns (^2.6|^3.0).",
"ext-ftp": "Required to use the Flysystem FTP driver.",
"ext-gd": "Required to use Illuminate\\Http\\Testing\\FileFactory::image().",
"ext-memcached": "Required to use the memcache cache driver.",
@@ -1361,37 +1482,42 @@
"ext-redis": "Required to use the Redis cache and queue drivers (^4.0|^5.0).",
"fakerphp/faker": "Required to use the eloquent factory builder (^1.9.1).",
"filp/whoops": "Required for friendly error pages in development (^2.8).",
"guzzlehttp/guzzle": "Required to use the HTTP Client, Mailgun mail driver and the ping methods on schedules (^6.3.1|^7.0.1).",
"guzzlehttp/guzzle": "Required to use the HTTP Client, Mailgun mail driver and the ping methods on schedules (^6.5.5|^7.0.1).",
"laravel/tinker": "Required to use the tinker console command (^2.0).",
"league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (^1.0).",
"league/flysystem-cached-adapter": "Required to use the Flysystem cache (^1.0).",
"league/flysystem-sftp": "Required to use the Flysystem SFTP driver (^1.0).",
"mockery/mockery": "Required to use mocking (~1.3.3|^1.4.2).",
"moontoast/math": "Required to use ordered UUIDs (^1.1).",
"mockery/mockery": "Required to use mocking (^1.4.2).",
"nyholm/psr7": "Required to use PSR-7 bridging features (^1.2).",
"pda/pheanstalk": "Required to use the beanstalk queue driver (^4.0).",
"phpunit/phpunit": "Required to use assertions and run tests (^8.4|^9.3.3).",
"phpunit/phpunit": "Required to use assertions and run tests (^8.5.8|^9.3.3).",
"predis/predis": "Required to use the predis connector (^1.1.2).",
"psr/http-message": "Required to allow Storage::put to accept a StreamInterface (^1.0).",
"pusher/pusher-php-server": "Required to use the Pusher broadcast driver (^4.0).",
"symfony/cache": "Required to PSR-6 cache bridge (^5.0).",
"symfony/filesystem": "Required to create relative storage directory symbolic links (^5.0).",
"pusher/pusher-php-server": "Required to use the Pusher broadcast driver (^4.0|^5.0).",
"symfony/cache": "Required to PSR-6 cache bridge (^5.1.4).",
"symfony/filesystem": "Required to enable support for relative symbolic links (^5.1.4).",
"symfony/psr-http-message-bridge": "Required to use PSR-7 bridging features (^2.0).",
"wildbit/swiftmailer-postmark": "Required to use Postmark mail driver (^3.0)."
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "7.x-dev"
"dev-master": "8.x-dev"
}
},
"autoload": {
"files": [
"src/Illuminate/Collections/helpers.php",
"src/Illuminate/Events/functions.php",
"src/Illuminate/Foundation/helpers.php",
"src/Illuminate/Support/helpers.php"
],
"psr-4": {
"Illuminate\\": "src/Illuminate/"
"Illuminate\\": "src/Illuminate/",
"Illuminate\\Support\\": [
"src/Illuminate/Macroable/",
"src/Illuminate/Collections/"
]
}
},
"notification-url": "https://packagist.org/downloads/",
@@ -1414,7 +1540,7 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
"time": "2021-01-21T14:10:48+00:00"
"time": "2021-03-04T15:22:36+00:00"
},
{
"name": "laravel/slack-notification-channel",
@@ -1547,26 +1673,29 @@
},
{
"name": "laravel/ui",
"version": "v2.5.0",
"version": "v3.2.0",
"source": {
"type": "git",
"url": "https://github.com/laravel/ui.git",
"reference": "d01a705763c243b07be795e9d1bb47f89260f73d"
"reference": "a1f82c6283c8373ea1958b8a27c3d5c98cade351"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/ui/zipball/d01a705763c243b07be795e9d1bb47f89260f73d",
"reference": "d01a705763c243b07be795e9d1bb47f89260f73d",
"url": "https://api.github.com/repos/laravel/ui/zipball/a1f82c6283c8373ea1958b8a27c3d5c98cade351",
"reference": "a1f82c6283c8373ea1958b8a27c3d5c98cade351",
"shasum": ""
},
"require": {
"illuminate/console": "^7.0",
"illuminate/filesystem": "^7.0",
"illuminate/support": "^7.0",
"php": "^7.2.5|^8.0"
"illuminate/console": "^8.0",
"illuminate/filesystem": "^8.0",
"illuminate/support": "^8.0",
"php": "^7.3|^8.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.x-dev"
},
"laravel": {
"providers": [
"Laravel\\Ui\\UiServiceProvider"
@@ -1596,9 +1725,9 @@
],
"support": {
"issues": "https://github.com/laravel/ui/issues",
"source": "https://github.com/laravel/ui/tree/v2.5.0"
"source": "https://github.com/laravel/ui/tree/v3.2.0"
},
"time": "2020-11-03T19:45:19+00:00"
"time": "2021-01-06T19:20:22+00:00"
},
{
"name": "lcobucci/jwt",
@@ -5459,37 +5588,39 @@
},
{
"name": "vlucas/phpdotenv",
"version": "v4.2.0",
"version": "v5.3.0",
"source": {
"type": "git",
"url": "https://github.com/vlucas/phpdotenv.git",
"reference": "da64796370fc4eb03cc277088f6fede9fde88482"
"reference": "b3eac5c7ac896e52deab4a99068e3f4ab12d9e56"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/da64796370fc4eb03cc277088f6fede9fde88482",
"reference": "da64796370fc4eb03cc277088f6fede9fde88482",
"url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/b3eac5c7ac896e52deab4a99068e3f4ab12d9e56",
"reference": "b3eac5c7ac896e52deab4a99068e3f4ab12d9e56",
"shasum": ""
},
"require": {
"php": "^5.5.9 || ^7.0 || ^8.0",
"phpoption/phpoption": "^1.7.3",
"symfony/polyfill-ctype": "^1.17"
"ext-pcre": "*",
"graham-campbell/result-type": "^1.0.1",
"php": "^7.1.3 || ^8.0",
"phpoption/phpoption": "^1.7.4",
"symfony/polyfill-ctype": "^1.17",
"symfony/polyfill-mbstring": "^1.17",
"symfony/polyfill-php80": "^1.17"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.4.1",
"ext-filter": "*",
"ext-pcre": "*",
"phpunit/phpunit": "^4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20"
"phpunit/phpunit": "^7.5.20 || ^8.5.14 || ^9.5.1"
},
"suggest": {
"ext-filter": "Required to use the boolean validator.",
"ext-pcre": "Required to use most of the library."
"ext-filter": "Required to use the boolean validator."
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.1-dev"
"dev-master": "5.3-dev"
}
},
"autoload": {
@@ -5521,7 +5652,7 @@
],
"support": {
"issues": "https://github.com/vlucas/phpdotenv/issues",
"source": "https://github.com/vlucas/phpdotenv/tree/v4.2.0"
"source": "https://github.com/vlucas/phpdotenv/tree/v5.3.0"
},
"funding": [
{
@@ -5533,7 +5664,7 @@
"type": "tidelift"
}
],
"time": "2021-01-20T15:11:48+00:00"
"time": "2021-01-20T15:23:13+00:00"
},
{
"name": "voku/portable-ascii",
@@ -5608,49 +5739,102 @@
}
],
"time": "2020-11-12T00:07:28+00:00"
},
{
"name": "webmozart/assert",
"version": "1.9.1",
"source": {
"type": "git",
"url": "https://github.com/webmozarts/assert.git",
"reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/webmozarts/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389",
"reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389",
"shasum": ""
},
"require": {
"php": "^5.3.3 || ^7.0 || ^8.0",
"symfony/polyfill-ctype": "^1.8"
},
"conflict": {
"phpstan/phpstan": "<0.12.20",
"vimeo/psalm": "<3.9.1"
},
"require-dev": {
"phpunit/phpunit": "^4.8.36 || ^7.5.13"
},
"type": "library",
"autoload": {
"psr-4": {
"Webmozart\\Assert\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Bernhard Schussek",
"email": "bschussek@gmail.com"
}
],
"description": "Assertions to validate method input/output with nice error messages.",
"keywords": [
"assert",
"check",
"validate"
],
"support": {
"issues": "https://github.com/webmozarts/assert/issues",
"source": "https://github.com/webmozarts/assert/tree/1.9.1"
},
"time": "2020-07-08T17:02:28+00:00"
}
],
"packages-dev": [
{
"name": "barryvdh/laravel-ide-helper",
"version": "v2.8.2",
"version": "v2.9.0",
"source": {
"type": "git",
"url": "https://github.com/barryvdh/laravel-ide-helper.git",
"reference": "5515cabea39b9cf55f98980d0f269dc9d85cfcca"
"reference": "64a6b902583802c162cdccf7e76dc8619368bf1a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/barryvdh/laravel-ide-helper/zipball/5515cabea39b9cf55f98980d0f269dc9d85cfcca",
"reference": "5515cabea39b9cf55f98980d0f269dc9d85cfcca",
"url": "https://api.github.com/repos/barryvdh/laravel-ide-helper/zipball/64a6b902583802c162cdccf7e76dc8619368bf1a",
"reference": "64a6b902583802c162cdccf7e76dc8619368bf1a",
"shasum": ""
},
"require": {
"barryvdh/reflection-docblock": "^2.0.6",
"composer/composer": "^1.6 || ^2",
"doctrine/dbal": "~2.3",
"doctrine/dbal": "^2.6 || ^3",
"ext-json": "*",
"illuminate/console": "^6 || ^7 || ^8",
"illuminate/filesystem": "^6 || ^7 || ^8",
"illuminate/support": "^6 || ^7 || ^8",
"php": ">=7.2",
"illuminate/console": "^8",
"illuminate/filesystem": "^8",
"illuminate/support": "^8",
"php": "^7.3 || ^8.0",
"phpdocumentor/type-resolver": "^1.1.0"
},
"require-dev": {
"ext-pdo_sqlite": "*",
"friendsofphp/php-cs-fixer": "^2",
"illuminate/config": "^6 || ^7 || ^8",
"illuminate/view": "^6 || ^7 || ^8",
"mockery/mockery": "^1.3.3",
"orchestra/testbench": "^4 || ^5 || ^6",
"illuminate/config": "^8",
"illuminate/view": "^8",
"mockery/mockery": "^1.4",
"orchestra/testbench": "^6",
"phpunit/phpunit": "^8.5 || ^9",
"spatie/phpunit-snapshot-assertions": "^1.4 || ^2.2 || ^3 || ^4",
"spatie/phpunit-snapshot-assertions": "^3 || ^4",
"vimeo/psalm": "^3.12"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.8-dev"
"dev-master": "2.9-dev"
},
"laravel": {
"providers": [
@@ -5687,7 +5871,7 @@
],
"support": {
"issues": "https://github.com/barryvdh/laravel-ide-helper/issues",
"source": "https://github.com/barryvdh/laravel-ide-helper/tree/v2.8.2"
"source": "https://github.com/barryvdh/laravel-ide-helper/tree/v2.9.0"
},
"funding": [
{
@@ -5695,7 +5879,7 @@
"type": "github"
}
],
"time": "2020-12-06T08:55:05+00:00"
"time": "2020-12-29T10:11:05+00:00"
},
{
"name": "barryvdh/reflection-docblock",
@@ -5749,6 +5933,86 @@
},
"time": "2018-12-13T10:34:14+00:00"
},
{
"name": "brianium/paratest",
"version": "v6.2.0",
"source": {
"type": "git",
"url": "https://github.com/paratestphp/paratest.git",
"reference": "9a94366983ce32c7724fc92e3b544327d4adb9be"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/paratestphp/paratest/zipball/9a94366983ce32c7724fc92e3b544327d4adb9be",
"reference": "9a94366983ce32c7724fc92e3b544327d4adb9be",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-pcre": "*",
"ext-reflection": "*",
"ext-simplexml": "*",
"php": "^7.3 || ^8.0",
"phpunit/php-code-coverage": "^9.2.5",
"phpunit/php-file-iterator": "^3.0.5",
"phpunit/php-timer": "^5.0.3",
"phpunit/phpunit": "^9.5.1",
"sebastian/environment": "^5.1.3",
"symfony/console": "^4.4 || ^5.2",
"symfony/process": "^4.4 || ^5.2"
},
"require-dev": {
"doctrine/coding-standard": "^8.2.0",
"ekino/phpstan-banned-code": "^0.3.1",
"ergebnis/phpstan-rules": "^0.15.3",
"ext-posix": "*",
"infection/infection": "^0.20.2",
"phpstan/phpstan": "^0.12.70",
"phpstan/phpstan-deprecation-rules": "^0.12.6",
"phpstan/phpstan-phpunit": "^0.12.17",
"phpstan/phpstan-strict-rules": "^0.12.9",
"squizlabs/php_codesniffer": "^3.5.8",
"symfony/filesystem": "^5.2.2",
"thecodingmachine/phpstan-strict-rules": "^0.12.1",
"vimeo/psalm": "^4.4.1"
},
"bin": [
"bin/paratest"
],
"type": "library",
"autoload": {
"psr-4": {
"ParaTest\\": [
"src/"
]
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Brian Scaturro",
"email": "scaturrob@gmail.com",
"homepage": "http://brianscaturro.com",
"role": "Lead"
}
],
"description": "Parallel testing for PHP",
"homepage": "https://github.com/paratestphp/paratest",
"keywords": [
"concurrent",
"parallel",
"phpunit",
"testing"
],
"support": {
"issues": "https://github.com/paratestphp/paratest/issues",
"source": "https://github.com/paratestphp/paratest/tree/v6.2.0"
},
"time": "2021-01-29T15:25:31+00:00"
},
{
"name": "composer/ca-bundle",
"version": "1.2.9",
@@ -6586,6 +6850,75 @@
},
"time": "2020-07-09T08:09:16+00:00"
},
{
"name": "itsgoingd/clockwork",
"version": "v5.0.6",
"source": {
"type": "git",
"url": "https://github.com/itsgoingd/clockwork.git",
"reference": "1de3f9f9fc22217aa024f79ecbdf0fde418fc0a1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/itsgoingd/clockwork/zipball/1de3f9f9fc22217aa024f79ecbdf0fde418fc0a1",
"reference": "1de3f9f9fc22217aa024f79ecbdf0fde418fc0a1",
"shasum": ""
},
"require": {
"ext-json": "*",
"php": ">=5.6",
"psr/log": "1.*"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Clockwork\\Support\\Laravel\\ClockworkServiceProvider"
],
"aliases": {
"Clockwork": "Clockwork\\Support\\Laravel\\Facade"
}
}
},
"autoload": {
"psr-4": {
"Clockwork\\": "Clockwork/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "itsgoingd",
"email": "itsgoingd@luzer.sk",
"homepage": "https://twitter.com/itsgoingd"
}
],
"description": "php dev tools in your browser",
"homepage": "https://underground.works/clockwork",
"keywords": [
"Devtools",
"debugging",
"laravel",
"logging",
"lumen",
"profiling",
"slim"
],
"support": {
"issues": "https://github.com/itsgoingd/clockwork/issues",
"source": "https://github.com/itsgoingd/clockwork/tree/v5.0.6"
},
"funding": [
{
"url": "https://github.com/itsgoingd",
"type": "github"
}
],
"time": "2020-12-27T00:18:25+00:00"
},
{
"name": "justinrainbow/json-schema",
"version": "5.2.10",
@@ -9024,59 +9357,6 @@
}
],
"time": "2020-07-12T23:59:07+00:00"
},
{
"name": "webmozart/assert",
"version": "1.9.1",
"source": {
"type": "git",
"url": "https://github.com/webmozarts/assert.git",
"reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/webmozarts/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389",
"reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389",
"shasum": ""
},
"require": {
"php": "^5.3.3 || ^7.0 || ^8.0",
"symfony/polyfill-ctype": "^1.8"
},
"conflict": {
"phpstan/phpstan": "<0.12.20",
"vimeo/psalm": "<3.9.1"
},
"require-dev": {
"phpunit/phpunit": "^4.8.36 || ^7.5.13"
},
"type": "library",
"autoload": {
"psr-4": {
"Webmozart\\Assert\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Bernhard Schussek",
"email": "bschussek@gmail.com"
}
],
"description": "Assertions to validate method input/output with nice error messages.",
"keywords": [
"assert",
"check",
"validate"
],
"support": {
"issues": "https://github.com/webmozarts/assert/issues",
"source": "https://github.com/webmozarts/assert/tree/1.9.1"
},
"time": "2020-07-08T17:02:28+00:00"
}
],
"aliases": [],

View File

@@ -182,6 +182,7 @@ return [
* Custom providers...
*/
App\Providers\IntegrationsServiceProvider::class,
App\Providers\SpeedtestServiceProvider::class,
],

409
config/clockwork.php Normal file
View File

@@ -0,0 +1,409 @@
<?php
return [
/*
|------------------------------------------------------------------------------------------------------------------
| Enable Clockwork
|------------------------------------------------------------------------------------------------------------------
|
| Clockwork is enabled by default only when your application is in debug mode. Here you can explicitly enable or
| disable Clockwork. When disabled, no data is collected and the api and web ui are inactive.
|
*/
'enable' => env('CLOCKWORK_ENABLE', null),
/*
|------------------------------------------------------------------------------------------------------------------
| Features
|------------------------------------------------------------------------------------------------------------------
|
| You can enable or disable various Clockwork features here. Some features have additional settings (eg. slow query
| threshold for database queries).
|
*/
'features' => [
// Cache usage stats and cache queries including results
'cache' => [
'enabled' => env('CLOCKWORK_CACHE_ENABLED', true),
// Collect cache queries including results (high performance impact with a high number of queries)
'collect_queries' => env('CLOCKWORK_CACHE_QUERIES', false)
],
// Database usage stats and queries
'database' => [
'enabled' => env('CLOCKWORK_DATABASE_ENABLED', true),
// Collect database queries (high performance impact with a very high number of queries)
'collect_queries' => env('CLOCKWORK_DATABASE_COLLECT_QUERIES', true),
// Collect details of models updates (high performance impact with a lot of model updates)
'collect_models_actions' => env('CLOCKWORK_DATABASE_COLLECT_MODELS_ACTIONS', true),
// Collect details of retrieved models (very high performance impact with a lot of models retrieved)
'collect_models_retrieved' => env('CLOCKWORK_DATABASE_COLLECT_MODELS_RETRIEVED', false),
// Query execution time threshold in miliseconds after which the query will be marked as slow
'slow_threshold' => env('CLOCKWORK_DATABASE_SLOW_THRESHOLD'),
// Collect only slow database queries
'slow_only' => env('CLOCKWORK_DATABASE_SLOW_ONLY', false),
// Detect and report duplicate (N+1) queries
'detect_duplicate_queries' => env('CLOCKWORK_DATABASE_DETECT_DUPLICATE_QUERIES', false)
],
// Dispatched events
'events' => [
'enabled' => env('CLOCKWORK_EVENTS_ENABLED', true),
// Ignored events (framework events are ignored by default)
'ignored_events' => [
// App\Events\UserRegistered::class,
// 'user.registered'
],
],
// Laravel log (you can still log directly to Clockwork with laravel log disabled)
'log' => [
'enabled' => env('CLOCKWORK_LOG_ENABLED', true)
],
// Sent notifications
'notifications' => [
'enabled' => env('CLOCKWORK_NOTIFICATIONS_ENABLED', true),
],
// Performance metrics
'performance' => [
// Allow collecting of client metrics. Requires separate clockwork-browser npm package.
'client_metrics' => env('CLOCKWORK_PERFORMANCE_CLIENT_METRICS', true)
],
// Dispatched queue jobs
'queue' => [
'enabled' => env('CLOCKWORK_QUEUE_ENABLED', true)
],
// Redis commands
'redis' => [
'enabled' => env('CLOCKWORK_REDIS_ENABLED', true)
],
// Routes list
'routes' => [
'enabled' => env('CLOCKWORK_ROUTES_ENABLED', false)
],
// Rendered views
'views' => [
'enabled' => env('CLOCKWORK_VIEWS_ENABLED', true),
// Collect views including view data (high performance impact with a high number of views)
'collect_data' => env('CLOCKWORK_VIEWS_COLLECT_DATA', false),
// Use Twig profiler instead of Laravel events for apps using laravel-twigbridge (more precise, but does
// not support collecting view data)
'use_twig_profiler' => env('CLOCKWORK_VIEWS_USE_TWIG_PROFILER', false)
]
],
/*
|------------------------------------------------------------------------------------------------------------------
| Enable web UI
|------------------------------------------------------------------------------------------------------------------
|
| Clockwork comes with a web UI accessibla via http://your.app/clockwork. Here you can enable or disable this
| feature. You can also set a custom path for the web UI.
|
*/
'web' => env('CLOCKWORK_WEB', true),
/*
|------------------------------------------------------------------------------------------------------------------
| Enable toolbar
|------------------------------------------------------------------------------------------------------------------
|
| Clockwork can show a toolbar with basic metrics on all responses. Here you can enable or disable this feature.
| Requires a separate clockwork-browser npm library.
|
*/
'toolbar' => env('CLOCKWORK_TOOLBAR', false),
/*
|------------------------------------------------------------------------------------------------------------------
| HTTP requests collection
|------------------------------------------------------------------------------------------------------------------
|
| Clockwork collects data about HTTP requests to your app. Here you can choose which requests should be collected.
|
*/
'requests' => [
// With on-demand mode enabled, Clockwork will only profile requests when the browser extension is open or you
// manually pass a "clockwork-profile" cookie or get/post data key.
// Optionally you can specify a "secret" that has to be passed as the value to enable profiling.
'on_demand' => env('CLOCKWORK_REQUESTS_ON_DEMAND', false),
// Collect only errors (requests with HTTP 4xx and 5xx responses)
'errors_only' => env('CLOCKWORK_REQUESTS_ERRORS_ONLY', false),
// Response time threshold in miliseconds after which the request will be marked as slow
'slow_threshold' => env('CLOCKWORK_REQUESTS_SLOW_THRESHOLD'),
// Collect only slow requests
'slow_only' => env('CLOCKWORK_REQUESTS_SLOW_ONLY', false),
// Sample the collected requests (eg. set to 100 to collect only 1 in 100 requests)
'sample' => env('CLOCKWORK_REQUESTS_SAMPLE', false),
// List of URIs that should not be collected
'except' => [
'/horizon/.*', // Laravel Horizon requests
'/telescope/.*', // Laravel Telescope requests
'/files/*'
],
// List of URIs that should be collected, any other URI will not be collected if not empty
'only' => [
// '/api/.*'
],
// Don't collect OPTIONS requests, mostly used in the CSRF pre-flight requests and are rarely of interest
'except_preflight' => env('CLOCKWORK_REQUESTS_EXCEPT_PREFLIGHT', true)
],
/*
|------------------------------------------------------------------------------------------------------------------
| Artisan commands collection
|------------------------------------------------------------------------------------------------------------------
|
| Clockwork can collect data about executed artisan commands. Here you can enable and configure which commands
| should be collected.
|
*/
'artisan' => [
// Enable or disable collection of executed Artisan commands
'collect' => env('CLOCKWORK_ARTISAN_COLLECT', false),
// List of commands that should not be collected (built-in commands are not collected by default)
'except' => [
// 'inspire'
],
// List of commands that should be collected, any other command will not be collected if not empty
'only' => [
// 'inspire'
],
// Enable or disable collection of command output
'collect_output' => env('CLOCKWORK_ARTISAN_COLLECT_OUTPUT', false),
// Enable or disable collection of built-in Laravel commands
'except_laravel_commands' => env('CLOCKWORK_ARTISAN_EXCEPT_LARAVEL_COMMANDS', true)
],
/*
|------------------------------------------------------------------------------------------------------------------
| Queue jobs collection
|------------------------------------------------------------------------------------------------------------------
|
| Clockwork can collect data about executed queue jobs. Here you can enable and configure which queue jobs should
| be collected.
|
*/
'queue' => [
// Enable or disable collection of executed queue jobs
'collect' => env('CLOCKWORK_QUEUE_COLLECT', false),
// List of queue jobs that should not be collected
'except' => [
// App\Jobs\ExpensiveJob::class
],
// List of queue jobs that should be collected, any other queue job will not be collected if not empty
'only' => [
// App\Jobs\BuggyJob::class
]
],
/*
|------------------------------------------------------------------------------------------------------------------
| Tests collection
|------------------------------------------------------------------------------------------------------------------
|
| Clockwork can collect data about executed tests. Here you can enable and configure which tests should be
| collected.
|
*/
'tests' => [
// Enable or disable collection of ran tests
'collect' => env('CLOCKWORK_TESTS_COLLECT', false),
// List of tests that should not be collected
'except' => [
// Tests\Unit\ExampleTest::class
]
],
/*
|------------------------------------------------------------------------------------------------------------------
| Enable data collection when Clockwork is disabled
|------------------------------------------------------------------------------------------------------------------
|
| You can enable this setting to collect data even when Clockwork is disabled. Eg. for future analysis.
|
*/
'collect_data_always' => env('CLOCKWORK_COLLECT_DATA_ALWAYS', false),
/*
|------------------------------------------------------------------------------------------------------------------
| Metadata storage
|------------------------------------------------------------------------------------------------------------------
|
| Configure how is the metadata collected by Clockwork stored. Two options are available:
| - files - A simple fast storage implementation storing data in one-per-request files.
| - sql - Stores requests in a sql database. Supports MySQL, Postgresql, Sqlite and requires PDO.
|
*/
'storage' => env('CLOCKWORK_STORAGE', 'files'),
// Path where the Clockwork metadata is stored
'storage_files_path' => env('CLOCKWORK_STORAGE_FILES_PATH', storage_path('clockwork')),
// Compress the metadata files using gzip, trading a little bit of performance for lower disk usage
'storage_files_compress' => env('CLOCKWORK_STORAGE_FILES_COMPRESS', false),
// SQL database to use, can be a name of database configured in database.php or a path to a sqlite file
'storage_sql_database' => env('CLOCKWORK_STORAGE_SQL_DATABASE', storage_path('clockwork.sqlite')),
// SQL table name to use, the table is automatically created and udpated when needed
'storage_sql_table' => env('CLOCKWORK_STORAGE_SQL_TABLE', 'clockwork'),
// Maximum lifetime of collected metadata in minutes, older requests will automatically be deleted, false to disable
'storage_expiration' => env('CLOCKWORK_STORAGE_EXPIRATION', 60 * 24 * 7),
/*
|------------------------------------------------------------------------------------------------------------------
| Authentication
|------------------------------------------------------------------------------------------------------------------
|
| Clockwork can be configured to require authentication before allowing access to the collected data. This might be
| useful when the application is publicly accessible. Setting to true will enable a simple authentication with a
| pre-configured password. You can also pass a class name of a custom implementation.
|
*/
'authentication' => env('CLOCKWORK_AUTHENTICATION', false),
// Password for the simple authentication
'authentication_password' => env('CLOCKWORK_AUTHENTICATION_PASSWORD', 'VerySecretPassword'),
/*
|------------------------------------------------------------------------------------------------------------------
| Stack traces collection
|------------------------------------------------------------------------------------------------------------------
|
| Clockwork can collect stack traces for log messages and certain data like database queries. Here you can set
| whether to collect stack traces, limit the number of collected frames and set further configuration. Collecting
| long stack traces considerably increases metadata size.
|
*/
'stack_traces' => [
// Enable or disable collecting of stack traces
'enabled' => env('CLOCKWORK_STACK_TRACES_ENABLED', true),
// Limit the number of frames to be collected
'limit' => env('CLOCKWORK_STACK_TRACES_LIMIT', 10),
// List of vendor names to skip when determining caller, common vendors are automatically added
'skip_vendors' => [
// 'phpunit'
],
// List of namespaces to skip when determining caller
'skip_namespaces' => [
// 'Laravel'
],
// List of class names to skip when determining caller
'skip_classes' => [
// App\CustomLog::class
]
],
/*
|------------------------------------------------------------------------------------------------------------------
| Serialization
|------------------------------------------------------------------------------------------------------------------
|
| Clockwork serializes the collected data to json for storage and transfer. Here you can configure certain aspects
| of serialization. Serialization has a large effect on the cpu time and memory usage.
|
*/
// Maximum depth of serialized multi-level arrays and objects
'serialization_depth' => env('CLOCKWORK_SERIALIZATION_DEPTH', 10),
// A list of classes that will never be serialized (eg. a common service container class)
'serialization_blackbox' => [
\Illuminate\Container\Container::class,
\Illuminate\Foundation\Application::class,
\Laravel\Lumen\Application::class
],
/*
|------------------------------------------------------------------------------------------------------------------
| Register helpers
|------------------------------------------------------------------------------------------------------------------
|
| Clockwork comes with a "clock" global helper function. You can use this helper to quickly log something and to
| access the Clockwork instance.
|
*/
'register_helpers' => env('CLOCKWORK_REGISTER_HELPERS', true),
/*
|------------------------------------------------------------------------------------------------------------------
| Send Headers for AJAX request
|------------------------------------------------------------------------------------------------------------------
|
| When trying to collect data the AJAX method can sometimes fail if it is missing required headers. For example, an
| API might require a version number using Accept headers to route the HTTP request to the correct codebase.
|
*/
'headers' => [
// 'Accept' => 'application/vnd.com.whatever.v1+json',
],
/*
|------------------------------------------------------------------------------------------------------------------
| Server-Timing
|------------------------------------------------------------------------------------------------------------------
|
| Clockwork supports the W3C Server Timing specification, which allows for collecting a simple performance metrics
| in a cross-browser way. Eg. in Chrome, your app, database and timeline event timings will be shown in the Dev
| Tools network tab. This setting specifies the max number of timeline events that will be sent. Setting to false
| will disable the feature.
|
*/
'server_timing' => env('CLOCKWORK_SERVER_TIMING', 10)
];

View File

@@ -7,7 +7,7 @@ return [
|--------------------------------------------------------------------------
*/
'version' => '1.10.4',
'version' => '1.11.1',
/*
|--------------------------------------------------------------------------

1
database/.gitignore vendored
View File

@@ -1,3 +1,4 @@
*.sqlite
*.sqlite-journal
*.bak
*.db_test*

View File

@@ -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 AddSpeedtestProviderSetting extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (!SettingsHelper::get('healthchecks_server_url')) {
Setting::create([
'name' => 'speedtest_provider',
'value' => 'ookla',
'description' => 'The provider/package used to run speedtests.'
]);
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Setting::whereIn('name', [
'speedtest_provider',
])->delete();
}
}

View File

@@ -0,0 +1,37 @@
<?php
use App\Setting;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class UpdateSpeedtestServerSettingsText extends Migration
{
private Setting $setting;
public function __construct()
{
$this->setting = Setting::where('name', 'server')->first();
}
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$this->setting->description = '<p class="d-inline">Comma-separated list of speedtest.net server IDs picked randomly. Leave blank to use default settings.</p>;';
$this->setting->save();
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
$this->setting->description = '<p class="d-inline">Comma-separated list of speedtest.net servers picked randomly. Leave blank to use default settings.</p>';
$this->setting->save();
}
}

View File

@@ -0,0 +1,40 @@
<?php
use App\Helpers\SettingsHelper;
use App\Setting;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddVisibleColumnsSetting extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (!SettingsHelper::get('visible_columns')) {
Setting::create([
'name' => 'visible_columns',
'value' => [
'id', 'created_at', 'download', 'upload', 'ping'
],
'description' => 'Choose and order the columns shown in the "All Tests" table.'
]);
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Setting::whereIn('name', [
'visible_columns',
])->delete();
}
}

View File

@@ -0,0 +1,40 @@
<?php
use App\Helpers\SettingsHelper;
use App\Setting;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddHiddenColumnsSetting extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (!SettingsHelper::get('hidden_columns')) {
Setting::create([
'name' => 'hidden_columns',
'value' => [
'server_id', 'server_name', 'server_host', 'url', 'scheduled',
],
'description' => 'Columns hidden from the "All Tests" table.'
]);
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Setting::whereIn('name', [
'hidden_columns',
])->delete();
}
}

13287
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -10,8 +10,8 @@
"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": {
"axios": "^0.21",
"@babel/preset-react": "^7.12.13",
"axios": "^0.21",
"bootstrap": "^4.6.0",
"cross-env": "^7.0",
"jquery": "^3.5",
@@ -29,6 +29,7 @@
"chart.js": "^2.9.4",
"csv-file-validator": "^1.10.1",
"js-cookie": "^2.2.1",
"react-beautiful-dnd": "^13.1.0",
"react-bootstrap": "^1.5.1",
"react-chartjs-2": "^2.11.1",
"react-router": "^5.2.0",

12058
public/js/app.js vendored

File diff suppressed because it is too large Load Diff

View File

@@ -11,7 +11,10 @@ export default class HistoryGraph extends Component {
super(props)
this.state = {
days: 7,
days: props.days,
time: props.dlUl,
fail: props.fail,
config: props.config,
duData: {},
duOptions: {},
pingData: {},
@@ -26,26 +29,63 @@ export default class HistoryGraph extends Component {
graph_failure_width: 6,
graph_ping_enabled: true,
graph_ping_width: 6,
firstUpdate: false,
}
}
componentDidMount = () => {
this.getData();
var int = setInterval(this.getData, 10000);
}
componentDidUpdate() {
if(
this.state.time != this.props.dlUl ||
this.state.fail != this.props.fail ||
this.state.config != this.props.config ||
this.state.days != this.props.days
) {
this.setState({
interval: int,
time: this.props.dlUl,
fail: this.props.fail,
config: this.props.config,
days: this.props.days
});
if(this.state.config !== null) {
this.processData();
}
}
if(
!this.state.firstUpdate &&
this.state.config !== null
) {
this.processData();
this.setState({
firstUpdate: true,
});
}
}
processData() {
this.processConfig();
this.processDlUlPing();
this.processFailure();
}
processConfig() {
this.setState({
graph_ul_dl_enabled: Boolean(Number(this.state.config.graphs.download_upload_graph_enabled.value)),
graph_ul_dl_width: this.state.config.graphs.download_upload_graph_width.value,
graph_ping_enabled: Boolean(Number(this.state.config.graphs.ping_graph_enabled.value)),
graph_ping_width: this.state.config.graphs.ping_graph_width.value,
graph_failure_enabled: Boolean(Number(this.state.config.graphs.failure_graph_enabled.value)),
graph_failure_width: this.state.config.graphs.failure_graph_width.value,
});
}
componentWillUnmount() {
clearInterval(this.state.interval);
}
processDlUlPing() {
let days = this.state.days;
getDLULPing = (days) => {
var url = 'api/speedtest/time/' + days;
Axios.get(url)
.then((resp) => {
var duData = {
labels: [],
datasets:[
@@ -132,7 +172,7 @@ export default class HistoryGraph extends Component {
}
}
resp.data.data.forEach(e => {
this.state.time.forEach(e => {
var download = {
t: new Date(e.created_at),
y: e.download,
@@ -159,16 +199,11 @@ export default class HistoryGraph extends Component {
pingOptions: pingOptions,
loading: false,
});
})
.catch((err) => {
console.log(err);
})
}
getFailure = (days) => {
var url = 'api/speedtest/fail/' + days;
Axios.get(url)
.then((resp) => {
processFailure() {
let days = this.state.days;
var failData = {
labels: [],
datasets: [
@@ -202,7 +237,7 @@ export default class HistoryGraph extends Component {
}
};
resp.data.data.forEach(e => {
this.state.fail.forEach(e => {
var success = {x: e.date, y: e.success};
var fail = {x: e.date, y: e.failure};
failData.datasets[0].data.push(success);
@@ -214,45 +249,13 @@ export default class HistoryGraph extends Component {
failData: failData,
failOptions: failOptions
});
})
.catch((err) => {
console.log(err);
})
}
getData = (days = this.state.days) => {
Axios.get('api/settings/config')
.then((resp) => {
var data = resp.data.graphs;
this.setState({
graph_ul_dl_enabled: Boolean(Number(data.download_upload_graph_enabled.value)),
graph_ul_dl_width: data.download_upload_graph_width.value,
graph_ping_enabled: Boolean(Number(data.ping_graph_enabled.value)),
graph_ping_width: data.ping_graph_width.value,
graph_failure_enabled: Boolean(Number(data.failure_graph_enabled.value)),
graph_failure_width: data.failure_graph_width.value,
});
this.getDLULPing(days);
this.getFailure(days);
})
.catch((err) => {
console.log('Couldn\'t get the site config');
console.log(err);
})
}
updateDays = (e) => {
var days = e.target.value;
if(days) {
this.getData(days);
clearInterval(this.state.int);
var int = setInterval(this.getData, 10000);
toast.info('Showing results for the last ' + days + ' days');
this.setState({
days: days,
interval: int
});
this.props.updateDays(days);
}
}

View File

@@ -12,42 +12,25 @@ export default class LatestResults extends Component {
super(props)
this.state = {
data: {},
data: props.data,
interval: null,
loading: true,
}
}
componentDidMount = () => {
this.getData();
var int = setInterval(this.getData, 10000);
componentDidUpdate() {
if(this.state.data !== this.props.data) {
this.setState({
interval: int,
data: this.props.data,
loading: false,
});
}
}
componentWillUnmount() {
clearInterval(this.state.interval);
}
getData = () => {
var url = 'api/speedtest/latest';
Axios.get(url)
.then((resp) => {
this.setState({
data: resp.data,
loading: false
});
})
.catch((err) => {
this.setState({
data: false
});
console.log(err);
})
}
newScan = () => {
var url = 'api/speedtest/run?token=' + window.token;

View File

@@ -43,21 +43,66 @@ export default class TableRow extends Component {
}
})
this.props.refresh();
this.toggleShow();
}
getDataFields = () => {
let allFields = this.props.allFields;
let data = this.state.data;
let processedFields = [];
for(var key in allFields) {
let field = allFields[key];
let value = data[key];
if(field.type === 'date') {
value = new Date(value).toLocaleString();
} else if(field.type === 'bool') {
value = Boolean(value) ? field.if_true : field.if_false
}
let final = {
name: key,
key: field.alias,
value: value,
type: field.type
};
processedFields.push(final);
}
let visible = [];
let inModal = [];
window.config.tables.visible_columns.forEach(column => {
visible.push(processedFields.find(x => x.name == column));
});
inModal = processedFields.filter(el => {
return !visible.includes(el);
});
return {
visible: visible,
modal: inModal
};
}
render() {
var e = this.state.data;
var show = this.state.show;
var fields = this.getDataFields();
if(e.failed != true) {
return (
<tr>
<td>{e.id}</td>
<td>{new Date(e.created_at).toLocaleString()}</td>
<td>{e.download}</td>
<td>{e.upload}</td>
<td>{e.ping}</td>
{fields.visible.map((e, i) => {
return (
<td key={i}>{e.value}</td>
);
})}
{e.server_host != null ?
<td>
<span onClick={this.toggleShow} className="ti-arrow-top-right mouse"></span>
@@ -66,13 +111,17 @@ export default class TableRow extends Component {
<Modal.Title>More info</Modal.Title>
</Modal.Header>
<Modal.Body className="text-center">
<p>Server ID: {e.server_id}</p>
<p>Name: {e.server_name}</p>
<p>Host: {e.server_host}</p>
<p>URL: <a href={e.url} target="_blank" rel="noopener noreferer">Speedtest.net</a></p>
{e.scheduled != undefined &&
<p>Type: {e.scheduled == true ? 'scheduled' : 'manual'}</p>
{fields.modal.map((e, i) => {
if(e.type === 'url') {
return (
<p key={i}>{e.key}: <a href={e.value} target="_blank" rel="noopener noreferer">Speedtest.net</a></p>
);
} else {
return (
<p key={i}>{e.key}: {e.value}</p>
);
}
})}
<Button variant="danger" onClick={() => { this.delete(e.id) }}>Delete</Button>
</Modal.Body>
</Modal>
@@ -90,7 +139,7 @@ export default class TableRow extends Component {
<td><span className="ti-close text-danger"></span></td>
<td><span className="ti-close text-danger"></span></td>
<td><span className="ti-close text-danger"></span></td>
<td></td>
<td><Button variant="danger" onClick={() => { this.delete(e.id) }}>Delete</Button></td>
</tr>
);
}

View File

@@ -14,7 +14,51 @@ export default class TestsTable extends Component {
data: [],
showTable: false,
refresh: true,
interval: null
interval: null,
allFields: {
id: {
type: 'int',
alias: 'ID'
},
created_at: {
type: 'date',
alias: 'Time'
},
download: {
type: 'float',
alias: 'Download (Mbit/s)'
},
upload: {
type: 'float',
alias: 'Upload (Mbit/s)'
},
ping: {
type: 'float',
alias: 'Ping (ms)'
},
server_id: {
type: 'int',
alias: 'Server ID'
},
server_name: {
type: 'string',
alias: 'Name'
},
server_host: {
type: 'string',
alias: 'Host'
},
url: {
type: 'url',
alias: 'URL'
},
scheduled: {
type: 'bool',
alias: 'Type',
if_true: 'scheduled',
if_false: 'manual'
}
}
}
}
@@ -84,6 +128,7 @@ export default class TestsTable extends Component {
var data = this.state.data;
var show = this.state.showTable;
var refresh = this.state.refresh;
let allFields = this.state.allFields;
if(data.length > 0) {
return (
@@ -102,18 +147,18 @@ export default class TestsTable extends Component {
<Table responsive>
<thead>
<tr>
<th>ID</th>
<th>Time</th>
<th>Download (Mbit/s)</th>
<th>Upload (Mbit/s)</th>
<th>Ping (ms)</th>
{window.config.tables.visible_columns.map((e, i) => {
return (
<th key={i}>{allFields[e].alias}</th>
);
})}
<th>More</th>
</tr>
</thead>
<tbody>
{data.map((e,i) => {
return (
<TableRow key={e.id} data={e} />
<TableRow key={e.id} data={e} allFields={allFields} refresh={this.getData} />
);
})}
</tbody>

View File

@@ -8,10 +8,62 @@ import TestsTable from '../Graphics/TestsTable';
import Login from '../Login';
import Authentication from '../Authentication/Authentication';
import Navbar from '../Navbar';
import axios from 'axios';
export default class HomePage extends Component {
constructor(props) {
super(props)
this.state = {
latest: null,
time: null,
fail: null,
config: null,
days: 7,
interval: null,
}
}
componentDidMount = () => {
this.getData();
var interval = setInterval(this.getData, 10000);
this.setState({
interval: interval,
});
}
componentWillUnmount() {
clearInterval(this.state.interval);
}
updateDays = (days) => {
this.setState({ days: days });
this.getData();
}
getData = () => {
axios.get('api/speedtest/home/' + this.state.days)
.then((resp) => {
this.setState({
latest: resp.data.latest,
time: resp.data.time,
fail: resp.data.fail,
config: resp.data.config
});
})
.catch((err) => {
console.log(err);
})
}
render() {
let latest = this.state.latest;
let time = this.state.time;
let fail = this.state.fail;
let config = this.state.config;
let days = this.state.days;
return (
<div>
<Navbar />
@@ -19,8 +71,8 @@ export default class HomePage extends Component {
{(window.config.auth == true && window.authenticated == false) &&
<Login />
}
<LatestResults />
<HistoryGraph />
<LatestResults data={latest} />
<HistoryGraph updateDays={this.updateDays} dlUl={time} fail={fail} config={config} days={days} />
</div>
<Footer />
</div>

View File

@@ -63,6 +63,16 @@ export default class SettingsIndex extends Component {
type: 'checkbox',
}
],
Tables: [
{
obj: data.visible_columns,
type: 'list'
},
{
obj: data.hidden_columns,
type: 'list'
}
],
Graphs: [
{
obj: data.download_upload_graph_enabled,
@@ -268,7 +278,7 @@ export default class SettingsIndex extends Component {
{loading ?
<Loader />
:
<SettingsTabs data={data} />
<SettingsTabs data={data} refreshConfig={this.props.refreshConfig} />
}
</div>
<Footer />

View File

@@ -11,6 +11,7 @@ import GraphsSettings from './tabs/GraphsSettings';
import HealthchecksSettings from './tabs/HealthchecksSettings';
import NotificationsSettings from './tabs/NotificationsSettings';
import Authentication from '../Authentication/Authentication';
import TableSettings from './tabs/TableSettings';
export default class SettingsTabs extends Component {
constructor(props) {
@@ -26,6 +27,7 @@ export default class SettingsTabs extends Component {
var tabs = [
'General',
'Graphs',
'Tables',
'Notifications',
'healthchecks.io',
'Reset',
@@ -121,6 +123,11 @@ export default class SettingsTabs extends Component {
data={data.Graphs}
generateInputs={this.generateInputs}
save={this.save} />
case 'Tables':
return <TableSettings
data={data.Tables}
refreshConfig={this.props.refreshConfig}
save={this.save} />
case 'Notifications':
return <NotificationsSettings
data={data.Notifications}

View File

@@ -0,0 +1,123 @@
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { Modal, Button, Tab } from 'react-bootstrap';
import Axios from 'axios';
import { toast } from 'react-toastify';
import { DragDropContext, Draggable, Droppable } from 'react-beautiful-dnd';
export default class TableSettings extends Component {
constructor(props) {
super(props)
this.state = {
visible: this.props.data[0],
hidden: this.props.data[1],
}
}
handleOnDragEnd = (result) => {
if (!result.destination) return;
let visible = this.state.visible;
let hidden = this.state.hidden;
let from = result.source.droppableId == 'visibleColumns' ? visible.obj.value : hidden.obj.value;
let to = result.destination.droppableId == 'visibleColumns' ? visible.obj.value : hidden.obj.value;
let [reorderedItem] = from.splice(result.source.index, 1);
to.splice(result.destination.index, 0, reorderedItem);
this.setState({
visible: visible,
hidden: hidden
});
}
save = () => {
var url = 'api/settings/bulk?token=' + window.token;
Axios.post(url, {
data: [
{
name: 'visible_columns',
value: this.state.visible.obj.value
},
{
name: 'hidden_columns',
value: this.state.hidden.obj.value
}
],
})
.then((resp) => {
toast.success('Table settings updated');
this.props.refreshConfig();
})
.catch((err) => {
toast.error('Something went wrong');
console.log(err);
})
}
render() {
let visible = this.state.visible;
let hidden = this.state.hidden;
return (
<Tab.Content>
<div>
<p>{visible.obj.description}</p>
<DragDropContext onDragEnd={this.handleOnDragEnd}>
<div className="card pt-4 pb-2 px-4 mb-4">
<h4>Visible Columns</h4>
<Droppable droppableId="visibleColumns">
{(provided) => (
<ul className="visibleColumns pl-0" {...provided.droppableProps} ref={provided.innerRef}>
{visible.obj.value.map((e, i) => {
return (
<Draggable draggableId={e} index={i} key={e}>
{(provided) => (
<li className="card bg-secondary py-2 px-3 my-2" key={e} ref={provided.innerRef} {...provided.draggableProps} {...provided.dragHandleProps}>{e}</li>
)}
</Draggable>
);
})}
{provided.placeholder}
</ul>
)}
</Droppable>
</div>
<div className="card pt-4 pb-2 px-4">
<h4>Hidden Columns</h4>
<Droppable droppableId="hiddenColumns pl-0">
{(provided) => (
<ul className="hiddenColumns pl-0" {...provided.droppableProps} ref={provided.innerRef}>
{hidden.obj.value.map((e, i) => {
return (
<Draggable draggableId={e} index={i} key={e}>
{(provided) => (
<li className="card bg-secondary py-2 px-3 my-2" key={e} ref={provided.innerRef} {...provided.draggableProps} {...provided.dragHandleProps}>{e}</li>
)}
</Draggable>
);
})}
{provided.placeholder}
</ul>
)}
</Droppable>
</div>
</DragDropContext>
<div className="mt-3">
<button className="btn btn-primary" onClick={() => { this.save() }}>Save</button>
</div>
</div>
</Tab.Content>
);
}
}
if (document.getElementById('TableSettings')) {
ReactDOM.render(<TableSettings />, document.getElementById('TableSettings'));
}

View File

@@ -94,7 +94,7 @@ export default class Index extends Component {
)} />
<Route exact path={window.config.base + 'settings'} render={(props) => (
<div>
<SettingsIndex />
<SettingsIndex refreshConfig={this.getConfig} />
</div>
)} />

View File

@@ -1,7 +1,12 @@
<?php
use App\Helpers\SpeedtestHelper;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\BackupController;
use App\Http\Controllers\HomepageDataController;
use App\Http\Controllers\SettingsController;
use App\Http\Controllers\SpeedtestController;
use App\Http\Controllers\UpdateController;
use App\Speedtest;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
@@ -18,34 +23,36 @@ use Illuminate\Support\Facades\Route;
*/
Route::group([
'middleware' => [ 'api' ],
'middleware' => ['api'],
'prefix' => 'speedtest'
], function($router) {
Route::get('/', 'SpeedtestController@index')
], function ($router) {
Route::get('/', [SpeedtestController::class, 'index'])
->name('speedtest.index');
Route::get('latest', 'SpeedtestController@latest')
Route::get('latest', [SpeedtestController::class, 'latest'])
->name('speedtest.latest');
Route::get('time/{time}', 'SpeedtestController@time')
Route::get('time/{time}', [SpeedtestController::class, 'time'])
->name('speedtest.time');
Route::get('fail/{time}', 'SpeedtestController@fail')
Route::get('fail/{time}', [SpeedtestController::class, 'fail'])
->name('speedtest.fail');
Route::get('run', 'SpeedtestController@run')
Route::get('run', [SpeedtestController::class, 'run'])
->name('speedtest.run');
Route::get('home/{time}', HomepageDataController::class)
->name('speedtest.home');
Route::group([
'prefix' => 'delete'
], function () {
Route::delete('all', 'SpeedtestController@deleteAll');
Route::delete('{speedtest}', 'SpeedtestController@delete');
Route::delete('all', [SpeedtestController::class, 'deleteAll']);
Route::delete('{speedtest}', [SpeedtestController::class, 'delete']);
});
});
Route::group([
'middleware' => 'api'
], function () {
Route::get('backup', 'BackupController@backup')
Route::get('backup', [BackupController::class, 'backup'])
->name('data.backup');
Route::post('restore', 'BackupController@restore')
Route::post('restore', [BackupController::class, 'restore'])
->name('data.restore');
});
@@ -53,15 +60,15 @@ Route::group([
'middleware' => 'api',
'prefix' => 'update',
], function () {
Route::get('changelog', 'UpdateController@changelog')
Route::get('changelog', [UpdateController::class, 'changelog'])
->name('update.changelog');
Route::get('check', 'UpdateController@checkForUpdate')
Route::get('check', [UpdateController::class, 'checkForUpdate'])
->name('update.check');
Route::get('download', 'UpdateController@downloadUpdate')
Route::get('download', [UpdateController::class, 'downloadUpdate'])
->name('update.download');
Route::get('extract', 'UpdateController@extractUpdate')
Route::get('extract', [UpdateController::class, 'extractUpdate'])
->name('update.extract');
Route::get('move', 'UpdateController@moveUpdate')
Route::get('move', [UpdateController::class, 'moveUpdate'])
->name('update.move');
});
@@ -69,19 +76,19 @@ Route::group([
'middleware' => 'api',
'prefix' => 'settings'
], function () {
Route::get('/config', 'SettingsController@config')
Route::get('/config', [SettingsController::class, 'config'])
->name('settings.config');
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')
Route::get('/', [SettingsController::class, 'index'])
->name('settings.index');
Route::put('/', 'SettingsController@store')
Route::put('/', [SettingsController::class, 'store'])
->name('settings.store');
Route::post('/', 'SettingsController@store')
Route::post('/', [SettingsController::class, 'store'])
->name('settings.update');
Route::post('/bulk', 'SettingsController@bulkStore')
Route::post('/bulk', [SettingsController::class, 'bulkStore'])
->name('settings.bulk.update');
});
@@ -91,21 +98,21 @@ Route::group(
'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::post('register', [AuthController::class, 'register'])->name('auth.register');
Route::post('login', [AuthController::class, 'login'])->middleware('throttle:60,1')->name('auth.login');
Route::get('logout', [AuthController::class, 'logout'])->name('auth.logout');
Route::get('refresh', [AuthController::class, 'refresh'])->middleware('throttle:60,1')->name('auth.refresh');
Route::get('me', [AuthController::class, 'me'])->middleware('session_active')->name('auth.me');
Route::post('change-password', [AuthController::class, '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');
function ($router) {
Route::get('/', [AuthController::class, 'getSessions'])->name('auth.sessions.all');
Route::delete('/{id}', [AuthController::class, 'deleteSession'])->name('auth.sessions.delete');
}
);
}

3
storage/clockwork/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
*.json
*.json.gz
index

View File

@@ -56,7 +56,6 @@ class APISpeedtestTest extends TestCase
$response->assertStatus(200);
$response->assertJsonStructure([
'method',
'data' => [
'id',
'ping',

View File

@@ -2,11 +2,18 @@
namespace Tests\Unit\Helpers\SpeedtestHelper;
use App\Helpers\SpeedtestHelper;
use App\Utils\OoklaTester;
use PHPUnit\Framework\TestCase;
class CheckOutputTest extends TestCase
{
private OoklaTester $speedtestProvider;
public function setUp(): void
{
$this->speedtestProvider = new OoklaTester();
}
/**
* A basic unit test example.
*
@@ -16,9 +23,9 @@ class CheckOutputTest extends TestCase
{
$expected = [
'type' => 'result',
'download' => [ 'bandwidth' => '*' ],
'upload' => [ 'bandwidth' => '*' ],
'ping' => [ 'latency' => '*' ],
'download' => ['bandwidth' => '*'],
'upload' => ['bandwidth' => '*'],
'ping' => ['latency' => '*'],
'server' => [
'id' => '*',
'name' => '*',
@@ -30,7 +37,7 @@ class CheckOutputTest extends TestCase
]
];
$this->assertTrue(SpeedtestHelper::checkOutputIsComplete($expected));
$this->assertTrue($this->speedtestProvider->isOutputComplete($expected));
}
/**
@@ -42,7 +49,7 @@ class CheckOutputTest extends TestCase
{
$expected = [
'type' => 'result',
'download' => [ 'bandwidth' => '*' ],
'download' => ['bandwidth' => '*'],
'server' => [
'id' => '*',
'name' => '*',
@@ -54,6 +61,6 @@ class CheckOutputTest extends TestCase
]
];
$this->assertFalse(SpeedtestHelper::checkOutputIsComplete($expected));
$this->assertFalse($this->speedtestProvider->isOutputComplete($expected));
}
}

View File

@@ -2,9 +2,10 @@
namespace Tests\Unit\Helpers\SpeedtestHelper;
use App\Exceptions\SpeedtestFailureException;
use App\Helpers\SpeedtestHelper;
use App\Utils\OoklaTester;
use Illuminate\Foundation\Testing\RefreshDatabase;
use JsonException;
use Tests\TestCase;
class SpeedtestTest extends TestCase
@@ -13,11 +14,15 @@ class SpeedtestTest extends TestCase
private $output;
public function setUp() : void
private OoklaTester $speedtestProvider;
public function setUp(): void
{
parent::setUp();
$this->output = SpeedtestHelper::output();
$this->speedtestProvider = new OoklaTester();
$this->output = $this->speedtestProvider->output();
}
/**
@@ -39,7 +44,7 @@ class SpeedtestTest extends TestCase
{
$output = json_decode($this->output, true);
$test = SpeedtestHelper::runSpeedtest($this->output);
$test = $this->speedtestProvider->run($this->output);
$this->assertEquals($output['ping']['latency'], $test->ping);
$this->assertEquals(SpeedtestHelper::convert($output['download']['bandwidth']), $test->download);
@@ -53,11 +58,11 @@ class SpeedtestTest extends TestCase
*/
public function testInvaidJson()
{
$this->expectException(SpeedtestFailureException::class);
$json = '{hi: hi}';
$o = SpeedtestHelper::runSpeedtest($json);
$this->assertFalse($o);
$o = $this->speedtestProvider->run($json);
}
/**
@@ -67,10 +72,10 @@ class SpeedtestTest extends TestCase
*/
public function testIncompleteJson()
{
$this->expectException(SpeedtestFailureException::class);
$json = '{"hi": "hi"}';
$o = SpeedtestHelper::runSpeedtest($json);
$this->assertFalse($o);
$o = $this->speedtestProvider->run($json);
}
}