Skip to content

Commit

Permalink
Merge pull request #520 from henrywhitaker3/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
henrywhitaker3 authored Mar 7, 2021
2 parents 17b72b9 + 99d80ed commit 2ed811e
Show file tree
Hide file tree
Showing 46 changed files with 152,263 additions and 1,835 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/laravel-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: shivammathur/setup-php@b7d1d9c9a92d8d8463ce36d7f60da34d461724f8
with:
php-version: '7.4'
- uses: actions/checkout@v2
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/laravel-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: shivammathur/setup-php@b7d1d9c9a92d8d8463ce36d7f60da34d461724f8
with:
php-version: '7.4'
- uses: actions/checkout@v2
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/laravel-stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: shivammathur/setup-php@b7d1d9c9a92d8d8463ce36d7f60da34d461724f8
with:
php-version: '7.4'
- uses: actions/checkout@v2
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.0-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.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)

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.

Expand Down Expand Up @@ -100,4 +100,4 @@ After enabling, you should change the password through the web UI.

### Manual Install

For manual installtions, please follow the instrucitons [here](https://github.com/henrywhitaker3/Speedtest-Tracker/wiki/Manual-Installation).
For manual installations, please follow the instructions [here](https://github.com/henrywhitaker3/Speedtest-Tracker/wiki/Manual-Installation).
6 changes: 4 additions & 2 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
$schedule->job(new SpeedtestJob(true, config('integrations')))->cron(SettingsHelper::get('schedule')['value']);
if ((bool)SettingsHelper::get('schedule_enabled')->value) {
$schedule->job(new SpeedtestJob(true, config('integrations')))->cron(SettingsHelper::get('schedule')['value']);
}
$schedule->command('speedtest:overview')->cron('0 ' . SettingsHelper::get('speedtest_overview_time')->value . ' * * *');
$schedule->command('speedtest:clear-sessions')->everyMinute();
}
Expand All @@ -40,7 +42,7 @@ protected function schedule(Schedule $schedule)
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
$this->load(__DIR__ . '/Commands');

require base_path('routes/console.php');
}
Expand Down
6 changes: 6 additions & 0 deletions app/Helpers/SettingsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public static function getBase()
*/
public static function settingIsEditable(string $key)
{
// Manual override for app_name
if ($key === 'app_name') {
return true;
}

$results = [];

// Try exact key
Expand Down Expand Up @@ -139,6 +144,7 @@ public static function getConfig()
{
return [
'base' => SettingsHelper::getBase(),
'name' => SettingsHelper::get('app_name')->value,
'widgets' => [
'show_average' => (bool)SettingsHelper::get('show_average')->value,
'show_max' => (bool)SettingsHelper::get('show_max')->value,
Expand Down
36 changes: 18 additions & 18 deletions app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class SettingsController extends Controller
{
public function __construct()
{
if((bool)SettingsHelper::get('auth')->value === true) {
if ((bool)SettingsHelper::get('auth')->value === true) {
$this->middleware('auth:api')
->except([ 'config' ]);
->except(['config']);
}
}

Expand Down Expand Up @@ -51,21 +51,21 @@ public function get(Setting $setting)
public function store(Request $request)
{
$rule = [
'name' => [ 'required', 'string', 'min:1' ],
'name' => ['required', 'string', 'min:1'],
];
if($request->name == 'schedule') {
$rule['value'] = [ 'required', new Cron ];
if ($request->name == 'schedule') {
$rule['value'] = ['required', new Cron];
}

$validator = Validator::make($request->all(), $rule);
if($validator->fails()) {
if ($validator->fails()) {
return response()->json([
'method' => 'Store a setting',
'error' => $validator->errors()
], 422);
}

if(!isset($request->value)) {
if (!isset($request->value)) {
$request->value = '';
}

Expand All @@ -86,27 +86,27 @@ public function store(Request $request)
public function bulkStore(Request $request)
{
$rule = [
'data' => [ 'array', 'required' ],
'data.*.name' => [ 'string', 'required' ],
'data' => ['array', 'required'],
'data.*.name' => ['string', 'required'],
];

$validator = Validator::make($request->all(), $rule);
if($validator->fails()) {
if ($validator->fails()) {
return response()->json([
'method' => 'Bulk store a setting',
'error' => $validator->errors()
], 422);
}

$settings = [];
foreach($request->data as $d) {
if(!isset($d['value']) || $d['value'] == null) {
$d['value'] = '';
foreach ($request->data as $d) {
if (!isset($d['value']) || $d['value'] == null) {
$d['value'] = '';
}

if($d['name'] == 'speedtest_overview_time') {
$ok = [ '00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23' ];
if(!in_array($d['value'], $ok)) {
if ($d['name'] == 'speedtest_overview_time') {
$ok = ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23'];
if (!in_array($d['value'], $ok)) {
return response()->json([
'method' => 'Bulk store a setting',
'error' => 'Invalid speedtest_overview_time value'
Expand All @@ -116,9 +116,9 @@ public function bulkStore(Request $request)

$setting = SettingsHelper::get($d['name']);

if($setting == false) {
if ($setting == false) {
$setting = SettingsHelper::set($d['name'], $d['value']);
} else if(SettingsHelper::settingIsEditable($setting->name)) {
} else if (SettingsHelper::settingIsEditable($setting->name)) {
$setting = SettingsHelper::set($d['name'], $d['value']);
} else {
continue;
Expand Down
18 changes: 9 additions & 9 deletions app/Jobs/SpeedtestJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ public function __construct($scheduled = true, $config = [])
*/
public function handle()
{
if($this->config['healthchecks_enabled'] === true) {
if ($this->config['healthchecks_enabled'] === true) {
$this->healthcheck('start');
}
$output = SpeedtestHelper::output();
$speedtest = SpeedtestHelper::runSpeedtest($output, $this->scheduled);
if($speedtest == false) {
if($this->config['healthchecks_enabled'] === true) {
if ($speedtest == false) {
if ($this->config['healthchecks_enabled'] === true) {
$this->healthcheck('fail');
}

event(new SpeedtestFailedEvent());
} else {
if($this->config['healthchecks_enabled'] === true) {
if ($this->config['healthchecks_enabled'] === true) {
$this->healthcheck('success');
}

Expand All @@ -82,19 +82,19 @@ public function handle()
private function healthcheck(String $method)
{
try {
$hc = new Healthchecks(SettingsHelper::get('healthchecks_uuid')->value);
if($method === 'start') {
$hc = new Healthchecks(SettingsHelper::get('healthchecks_uuid')->value, SettingsHelper::get('healthchecks_server_url')->value);
if ($method === 'start') {
$hc->start();
}

if($method === 'success') {
if ($method === 'success') {
$hc->success();
}

if($method === 'fail') {
if ($method === 'fail') {
$hc->fail();
}
} catch(Exception $e) {
} catch (Exception $e) {
Log::error($e->getMessage());
}
}
Expand Down
16 changes: 9 additions & 7 deletions app/Providers/IntegrationsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,20 @@ public function register()
*/
public function boot()
{
if(File::exists(env('DB_DATABASE'))) {
if(Schema::hasTable('settings')) {
if (File::exists(env('DB_DATABASE'))) {
if (Schema::hasTable('settings')) {
$setting = SettingsHelper::get('healthchecks_uuid');

if($setting !== false) {
if ($setting !== false) {
try {
App::bind('healthcheck', function() use ($setting) {
return new Healthchecks($setting->value);
SettingsHelper::loadIntegrationConfig();

App::bind('healthcheck', function () use ($setting) {
return new Healthchecks($setting->value, SettingsHelper::get('healthchecks_server_url')->value);
});
} catch(InvalidUuidStringException $e) {
} catch (InvalidUuidStringException $e) {
Log::error('Invalid healthchecks UUID');
} catch(Exception $e) {
} catch (Exception $e) {
Log::error($e->getMessage());
}
}
Expand Down
24 changes: 24 additions & 0 deletions changelog.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,28 @@
{
"1.10.4": [
{
"description": "Updated dependencies.",
"link": ""
}
],
"1.10.3": [
{
"description": "Moved stuff into pages.",
"link": ""
}
],
"1.10.2": [
{
"description": "Added option to disable scheduled tests.",
"link": ""
}
],
"1.10.1": [
{
"description": "Fixed integrations config being empty causing healthchecks to not run on scheduled tests.",
"link": ""
}
],
"1.10.0": [
{
"description": "Added automated build for ARM.",
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
"facade/ignition": "^2.0",
"fzaninotto/faker": "^1.9.1",
"mockery/mockery": "^1.3.1",
"nunomaduro/collision": "^4.1",
"nunomaduro/larastan": "^0.6.2",
"phpunit/phpunit": "^8.5"
"phpunit/phpunit": "^9.5",
"nunomaduro/larastan": "^0.7.0",
"nunomaduro/collision": "^5.3"
},
"config": {
"optimize-autoloader": true,
Expand Down
Loading

0 comments on commit 2ed811e

Please sign in to comment.