Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ _ide_helper.php
.env.backup
.phpstorm.meta.php
.phpunit.result.cache
config.yml
auth.json
docker-compose.yml
Homestead.json
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/public/storage
/storage/*.key
/vendor
config.yml

.env
.env.backup
.phpunit.result.cache
Expand Down
66 changes: 66 additions & 0 deletions .phpstorm.meta.php

Large diffs are not rendered by default.

23 changes: 9 additions & 14 deletions app/Console/Commands/TestInfluxDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
namespace App\Console\Commands;

use App\Models\Result;
use App\Settings\InfluxDbSettings;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Symfony\Component\Yaml\Yaml;

class TestInfluxDB extends Command
{
Expand All @@ -28,19 +27,15 @@ class TestInfluxDB extends Command
*
* @return int
*/
public function handle()
public function handle(InfluxDbSettings $settings)
{
if (File::exists(base_path().'/config.yml')) {
$config = Yaml::parseFile(
base_path().'/config.yml'
);
}

if (File::exists('/app/config.yml')) {
$config = Yaml::parseFile('/app/config.yml');
}

$influxdb = $config['influxdb'];
$influxdb = [
'enabled' => $settings->v2_enabled,
'url' => optional($settings)->v2_url,
'org' => optional($settings)->v2_org,
'bucket' => optional($settings)->v2_bucket,
'token' => optional($settings)->v2_token,
];

if ($influxdb['enabled'] == true) {
$result = Result::factory()->create();
Expand Down
11 changes: 9 additions & 2 deletions app/Filament/Pages/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Filament\Widgets\StatsOverview;
use App\Jobs\ExecSpeedtest;
use App\Settings\GeneralSettings;
use Filament\Notifications\Notification;
use Filament\Pages\Actions\Action;
use Filament\Pages\Dashboard as BasePage;
Expand All @@ -28,9 +29,15 @@ public function getHeaderWidgets(): array
];
}

public function queueSpeedtest()
public function queueSpeedtest(GeneralSettings $settings)
{
ExecSpeedtest::dispatch();
$speedtest = [
'enabled' => ! blank($settings->speedtest_schedule),
'schedule' => optional($settings)->speedtest_schedule,
'ookla_server_id' => optional($settings)->speedtest_server,
];

ExecSpeedtest::dispatch(speedtest: $speedtest, scheduled: false);

Notification::make()
->title('Speedtest added to the queue')
Expand Down
89 changes: 89 additions & 0 deletions app/Filament/Pages/Settings/General.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace App\Filament\Pages\Settings;

use App\Settings\GeneralSettings;
use Filament\Forms\Components\Card;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Pages\SettingsPage;
use Squire\Models\Timezone;

class General extends SettingsPage
{
protected static ?string $navigationIcon = 'heroicon-o-cog';

protected static ?string $navigationGroup = 'Settings';

protected static ?int $navigationSort = 1;

protected static string $settings = GeneralSettings::class;

protected function getFormSchema(): array
{
return [
Grid::make([
'default' => 1,
'md' => 3,
])
->schema([
Grid::make([
'default' => 1,
])
->schema([
Section::make('Site Settings')
->collapsible()
->schema([
TextInput::make('site_name')
->maxLength(50)
->required()
->columnSpan(['md' => 2]),
Select::make('timezone')
->options(Timezone::all()->pluck('code', 'code'))
->searchable()
->required()
->columnSpan(1),
])
->columns([
'default' => 1,
'md' => 2,
]),

Section::make('Speedtest Settings')
->collapsible()
->schema([
TextInput::make('speedtest_schedule')
->helperText('Leave empty to disable the schedule. You can also use the cron expression generator [HERE](https://crontab.cronhub.io/) to help you make schedules.')
->nullable()
->columnSpan(1),
TextInput::make('speedtest_server')
->helperText('Leave empty to let the system pick the best server.')
->nullable()
->columnSpan(1),
])
->columns([
'default' => 1,
'md' => 2,
]),
])
->columnSpan([
'md' => 2,
]),

Card::make()
->schema([
Toggle::make('auth_enabled')
->label('Authentication enabled')
->helperText("NOTE: Authentication is currently required. It's on the roadmap to be able to disabled it though.")
->disabled(),
])
->columnSpan([
'md' => 1,
]),
]),
];
}
}
82 changes: 82 additions & 0 deletions app/Filament/Pages/Settings/InfluxDb.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace App\Filament\Pages\Settings;

use App\Settings\InfluxDbSettings;
use Filament\Forms\Components\Card;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Pages\SettingsPage;

class InfluxDb extends SettingsPage
{
protected static ?string $navigationIcon = 'heroicon-o-database';

protected static ?string $navigationLabel = 'InfluxDB';

protected static ?string $navigationGroup = 'Settings';

protected static ?int $navigationSort = 2;

protected static string $settings = InfluxDbSettings::class;

protected function getFormSchema(): array
{
return [
Grid::make([
'default' => 1,
'md' => 3,
])
->schema([
Grid::make([
'default' => 1,
])
->schema([
Section::make('InfluxDB v2 Settings')
->collapsible()
->schema([
TextInput::make('v2_url')
->label('URL')
->placeholder('http://your-influxdb-instance')
->maxLength(255)
->columnSpan(['md' => 2]),
TextInput::make('v2_org')
->label('Org')
->maxLength(255)
->columnSpan(1),
TextInput::make('v2_bucket')
->placeholder('speedtest-tracker')
->label('Bucket')
->maxLength(255)
->columnSpan(1),
TextInput::make('v2_token')
->label('Token')
->maxLength(255)
->password()
->disableAutocomplete()
->columnSpan(['md' => 2]),
])
->columns([
'default' => 1,
'md' => 2,
]),
])
->columnSpan([
'md' => 2,
]),

Card::make()
->schema([
Toggle::make('v2_enabled')
->label('v2 enabled')
->helperText('NOTE: At this time only InfluxDB v2 is supported'),
])
->columnSpan([
'md' => 1,
]),
]),
];
}
}
43 changes: 14 additions & 29 deletions app/Jobs/SearchForSpeedtests.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,37 @@

namespace App\Jobs;

use App\Settings\GeneralSettings;
use Cron\CronExpression;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\File;
use Symfony\Component\Yaml\Yaml;

class SearchForSpeedtests implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Execute the job.
*
* @return void
*/
public function handle()
public function handle(GeneralSettings $settings)
{
if (File::exists(base_path().'/config.yml')) {
$config = Yaml::parseFile(
base_path().'/config.yml'
);
}

if (File::exists('/app/config.yml')) {
$config = Yaml::parseFile('/app/config.yml');
}

$speedtest = $config['speedtest'];

$cron = new CronExpression($speedtest['schedule']);

if ($cron->isDue() && $speedtest['enabled']) {
ExecSpeedtest::dispatch(speedtest: $speedtest, scheduled: true);
$speedtest = [
'enabled' => ! blank($settings->speedtest_schedule),
'schedule' => optional($settings)->speedtest_schedule,
'ookla_server_id' => optional($settings)->speedtest_server,
];

if ($speedtest['enabled']) {
$cron = new CronExpression($speedtest['schedule']);

if ($cron->isDue()) {
ExecSpeedtest::dispatch(speedtest: $speedtest, scheduled: true);
}
}
}
}
28 changes: 15 additions & 13 deletions app/Observers/ResultObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
namespace App\Observers;

use App\Models\Result;
use Illuminate\Support\Facades\File;
use App\Settings\InfluxDbSettings;
use Illuminate\Support\Facades\Log;
use InfluxDB2\Client;
use Symfony\Component\Yaml\Yaml;

class ResultObserver
{
Expand All @@ -17,6 +16,13 @@ class ResultObserver
*/
public $afterCommit = true;

public $settings;

public function __construct(InfluxDbSettings $settings)
{
$this->settings = $settings;
}

/**
* Handle the Result "created" event.
*
Expand All @@ -25,17 +31,13 @@ class ResultObserver
*/
public function created(Result $result)
{
if (File::exists(base_path().'/config.yml')) {
$config = Yaml::parseFile(
base_path().'/config.yml'
);
}

if (File::exists('/app/config.yml')) {
$config = Yaml::parseFile('/app/config.yml');
}

$influxdb = $config['influxdb'];
$influxdb = [
'enabled' => $this->settings->v2_enabled,
'url' => optional($this->settings)->v2_url,
'org' => optional($this->settings)->v2_org,
'bucket' => optional($this->settings)->v2_bucket,
'token' => optional($this->settings)->v2_token,
];

if ($influxdb['enabled'] == true) {
$client = new Client([
Expand Down
1 change: 1 addition & 0 deletions app/Providers/FilamentServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function boot()
{
Filament::serving(function () {
Filament::registerNavigationGroups([
'Settings',
'Links',
]);

Expand Down
Loading