Compare commits

..

No commits in common. "fb506fa84681707c95cf560ee6205eec973d8cdf" and "25f36eaf54ce074746e925650a845b3096b16ffa" have entirely different histories.

15 changed files with 130 additions and 151 deletions

View file

@ -1,5 +1,5 @@
# From official php image.
FROM php:8.4-cli-alpine
FROM php:8.3-cli-alpine
# Create a user group and account under id 1000.
RUN addgroup -g 1000 -S user && adduser -u 1000 -D user -G user
# Install quality-of-life packages.
@ -16,14 +16,14 @@ ENV PUPPETEER_DOCKER=1
RUN mkdir -p /usr/src/php/ext/imagick
RUN chmod 777 /usr/src/php/ext/imagick
RUN curl -fsSL https://github.com/Imagick/imagick/archive/refs/tags/3.8.0.tar.gz | tar xvz -C "/usr/src/php/ext/imagick" --strip 1
RUN curl -fsSL https://github.com/Imagick/imagick/archive/refs/tags/3.7.0.tar.gz | tar xvz -C "/usr/src/php/ext/imagick" --strip 1
# Install PHP extensions
RUN docker-php-ext-install imagick
# Composer uses its php binary, but we want it to use the container's one
RUN rm -f /usr/bin/php84
RUN ln -s /usr/local/bin/php /usr/bin/php84
RUN rm -f /usr/bin/php83
RUN ln -s /usr/local/bin/php /usr/bin/php83
# Install postgres pdo driver.
# RUN apk add --no-cache postgresql-dev && docker-php-ext-install pdo_pgsql
# Install redis driver.

View file

@ -1,5 +1,5 @@
# From official php image.
FROM php:8.4-fpm-alpine
FROM php:8.3-fpm-alpine
RUN addgroup -g 1000 -S user && adduser -u 1000 -D user -G user
# Install postgres pdo driver.
# RUN apk add --no-cache postgresql-dev && docker-php-ext-install pdo_pgsql
@ -21,10 +21,10 @@ ENV PUPPETEER_DOCKER=1
RUN mkdir -p /usr/src/php/ext/imagick
RUN chmod 777 /usr/src/php/ext/imagick
RUN curl -fsSL https://github.com/Imagick/imagick/archive/refs/tags/3.8.0.tar.gz | tar xvz -C "/usr/src/php/ext/imagick" --strip 1
RUN curl -fsSL https://github.com/Imagick/imagick/archive/refs/tags/3.7.0.tar.gz | tar xvz -C "/usr/src/php/ext/imagick" --strip 1
# Install PHP extensions
RUN docker-php-ext-install imagick
RUN rm -f /usr/bin/php84
RUN ln -s /usr/local/bin/php /usr/bin/php84
RUN rm -f /usr/bin/php83
RUN ln -s /usr/local/bin/php /usr/bin/php83

View file

@ -1,7 +1,7 @@
########################
# Base Image
########################
FROM bnussbau/serversideup-php:8.4-fpm-nginx-alpine-imagick-chromium AS base
FROM bnussbau/serversideup-php:8.3-fpm-nginx-alpine-imagick-chromium AS base
LABEL org.opencontainers.image.source=https://github.com/usetrmnl/byos_laravel
LABEL org.opencontainers.image.description="TRMNL BYOS Laravel"

View file

@ -2,9 +2,7 @@
namespace App\Console\Commands;
use Exception;
use Illuminate\Console\Command;
use InvalidArgumentException;
use Laravel\Socialite\Facades\Socialite;
class OidcTestCommand extends Command
@ -33,7 +31,7 @@ class OidcTestCommand extends Command
// Check if OIDC is enabled
$enabled = config('services.oidc.enabled');
$this->line('OIDC Enabled: '.($enabled ? '✅ Yes' : '❌ No'));
$this->line("OIDC Enabled: " . ($enabled ? '✅ Yes' : '❌ No'));
// Check configuration values
$endpoint = config('services.oidc.endpoint');
@ -42,11 +40,11 @@ class OidcTestCommand extends Command
$redirect = config('services.oidc.redirect');
$scopes = config('services.oidc.scopes', []);
$this->line('OIDC Endpoint: '.($endpoint ? "{$endpoint}" : '❌ Not set'));
$this->line('Client ID: '.($clientId ? "{$clientId}" : '❌ Not set'));
$this->line('Client Secret: '.($clientSecret ? '✅ Set' : '❌ Not set'));
$this->line('Redirect URL: '.($redirect ? "{$redirect}" : '❌ Not set'));
$this->line('Scopes: '.(empty($scopes) ? '❌ Not set' : '✅ '.implode(', ', $scopes)));
$this->line("OIDC Endpoint: " . ($endpoint ? "{$endpoint}" : '❌ Not set'));
$this->line("Client ID: " . ($clientId ? "{$clientId}" : '❌ Not set'));
$this->line("Client Secret: " . ($clientSecret ? '✅ Set' : '❌ Not set'));
$this->line("Redirect URL: " . ($redirect ? "{$redirect}" : '❌ Not set'));
$this->line("Scopes: " . (empty($scopes) ? '❌ Not set' : '✅ ' . implode(', ', $scopes)));
$this->newLine();
@ -55,45 +53,38 @@ class OidcTestCommand extends Command
// Only test driver if we have basic configuration
if ($endpoint && $clientId && $clientSecret) {
$driver = Socialite::driver('oidc');
$this->line('OIDC Driver: ✅ Successfully registered and accessible');
$this->line("OIDC Driver: ✅ Successfully registered and accessible");
if ($enabled) {
$this->info('✅ OIDC is fully configured and ready to use!');
$this->line('You can test the login flow at: /auth/oidc/redirect');
$this->info("✅ OIDC is fully configured and ready to use!");
$this->line("You can test the login flow at: /auth/oidc/redirect");
} else {
$this->warn('⚠️ OIDC driver is working but OIDC_ENABLED is false.');
$this->warn("⚠️ OIDC driver is working but OIDC_ENABLED is false.");
}
} else {
$this->line('OIDC Driver: ✅ Registered (configuration test skipped due to missing values)');
$this->warn('⚠️ OIDC driver is registered but missing required configuration.');
$this->line('Please set the following environment variables:');
if (! $enabled) {
$this->line(' - OIDC_ENABLED=true');
}
$this->line("OIDC Driver: ✅ Registered (configuration test skipped due to missing values)");
$this->warn("⚠️ OIDC driver is registered but missing required configuration.");
$this->line("Please set the following environment variables:");
if (!$enabled) $this->line(" - OIDC_ENABLED=true");
if (!$endpoint) {
$this->line(' - OIDC_ENDPOINT=https://your-oidc-provider.com (base URL)');
$this->line(' OR');
$this->line(' - OIDC_ENDPOINT=https://your-oidc-provider.com/.well-known/openid-configuration (full URL)');
$this->line(" - OIDC_ENDPOINT=https://your-oidc-provider.com (base URL)");
$this->line(" OR");
$this->line(" - OIDC_ENDPOINT=https://your-oidc-provider.com/.well-known/openid-configuration (full URL)");
}
if (! $clientId) {
$this->line(' - OIDC_CLIENT_ID=your-client-id');
if (!$clientId) $this->line(" - OIDC_CLIENT_ID=your-client-id");
if (!$clientSecret) $this->line(" - OIDC_CLIENT_SECRET=your-client-secret");
}
if (! $clientSecret) {
$this->line(' - OIDC_CLIENT_SECRET=your-client-secret');
}
}
} catch (InvalidArgumentException $e) {
} catch (\InvalidArgumentException $e) {
if (str_contains($e->getMessage(), 'Driver [oidc] not supported')) {
$this->error('❌ OIDC Driver registration failed: Driver not supported');
$this->error("❌ OIDC Driver registration failed: Driver not supported");
} else {
$this->error('❌ OIDC Driver error: '.$e->getMessage());
$this->error("❌ OIDC Driver error: " . $e->getMessage());
}
} catch (Exception $e) {
$this->warn('⚠️ OIDC Driver registered but configuration error: '.$e->getMessage());
} catch (\Exception $e) {
$this->warn("⚠️ OIDC Driver registered but configuration error: " . $e->getMessage());
}
$this->newLine();
return Command::SUCCESS;
}
}

View file

@ -4,7 +4,6 @@ namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\User;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
@ -27,16 +26,14 @@ class OidcController extends Controller
foreach ($requiredConfig as $key) {
if (!config("services.oidc.{$key}")) {
Log::error("OIDC configuration missing: {$key}");
return redirect()->route('login')->withErrors(['oidc' => 'OIDC is not properly configured.']);
}
}
try {
return Socialite::driver('oidc')->redirect();
} catch (Exception $e) {
} catch (\Exception $e) {
Log::error('OIDC redirect error: ' . $e->getMessage());
return redirect()->route('login')->withErrors(['oidc' => 'Failed to initiate OIDC authentication.']);
}
}
@ -55,7 +52,6 @@ class OidcController extends Controller
foreach ($requiredConfig as $key) {
if (!config("services.oidc.{$key}")) {
Log::error("OIDC configuration missing: {$key}");
return redirect()->route('login')->withErrors(['oidc' => 'OIDC is not properly configured.']);
}
}
@ -71,9 +67,8 @@ class OidcController extends Controller
return redirect()->intended(route('dashboard', absolute: false));
} catch (Exception $e) {
} catch (\Exception $e) {
Log::error('OIDC callback error: ' . $e->getMessage());
return redirect()->route('login')->withErrors(['oidc' => 'Failed to authenticate with OIDC provider.']);
}
}
@ -92,7 +87,6 @@ class OidcController extends Controller
'name' => $oidcUser->getName() ?: $user->name,
'email' => $oidcUser->getEmail() ?: $user->email,
]);
return $user;
}
@ -106,7 +100,6 @@ class OidcController extends Controller
'oidc_sub' => $oidcUser->getId(),
'name' => $oidcUser->getName() ?: $user->name,
]);
return $user;
}
}

View file

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace App\Liquid\FileSystems;
use InvalidArgumentException;
use Keepsuit\Liquid\Contracts\LiquidFileSystem;
/**
@ -54,7 +53,7 @@ class InlineTemplatesFileSystem implements LiquidFileSystem
public function readTemplateFile(string $templateName): string
{
if (!isset($this->templates[$templateName])) {
throw new InvalidArgumentException("Template '{$templateName}' not found in inline templates");
throw new \InvalidArgumentException("Template '{$templateName}' not found in inline templates");
}
return $this->templates[$templateName];

View file

@ -20,7 +20,6 @@ use Keepsuit\Liquid\TagBlock;
class TemplateTag extends TagBlock
{
protected string $templateName;
protected Raw $body;
public static function tagName(): string
@ -42,7 +41,7 @@ class TemplateTag extends TagBlock
is_string($templateNameExpression) => trim($templateNameExpression),
is_numeric($templateNameExpression) => (string) $templateNameExpression,
$templateNameExpression instanceof VariableLookup => (string) $templateNameExpression,
default => throw new SyntaxException('Template name must be a string, number, or variable'),
default => throw new SyntaxException("Template name must be a string, number, or variable"),
};
// Validate template name (letters, numbers, underscores, and slashes only)

View file

@ -182,12 +182,10 @@ class Device extends Model
{
return $this->belongsTo(Firmware::class, 'update_firmware_id');
}
public function deviceModel(): BelongsTo
{
return $this->belongsTo(DeviceModel::class);
}
public function logs(): HasMany
{
return $this->hasMany(DeviceLog::class);
@ -226,20 +224,19 @@ class Device extends Model
if ($from < $to) {
// Normal range, same day
return $now->between($from, $to) ? (int) $now->diffInSeconds($to, false) : null;
}
} else {
// Overnight range
if ($now->gte($from)) {
// After 'from', before midnight
return (int) $now->diffInSeconds($to->copy()->addDay(), false);
}
if ($now->lt($to)) {
} elseif ($now->lt($to)) {
// After midnight, before 'to'
return (int) $now->diffInSeconds($to, false);
}
} else {
// Not in sleep window
return null;
}
}
}
public function isPauseActive(): bool

View file

@ -41,7 +41,6 @@ class AppServiceProvider extends ServiceProvider
// Register OIDC provider with Socialite
Socialite::extend('oidc', function ($app) {
$config = $app['config']['services.oidc'] ?? [];
return new OidcProvider(
$app['request'],
$config['client_id'] ?? null,

View file

@ -51,7 +51,7 @@ class ImageGenerationService
if (config('app.puppeteer_wait_for_network_idle')) {
$browsershot->waitUntilNetworkIdle();
}
if (config('app.puppeteer_window_size_strategy') === 'v2') {
if (config('app.puppeteer_window_size_strategy') == 'v2') {
$browsershot->windowSize($imageSettings['width'], $imageSettings['height']);
} else {
$browsershot->windowSize(800, 480);

View file

@ -2,11 +2,11 @@
namespace App\Services;
use Exception;
use GuzzleHttp\Client;
use Laravel\Socialite\Two\AbstractProvider;
use Laravel\Socialite\Two\ProviderInterface;
use Laravel\Socialite\Two\User;
use GuzzleHttp\Client;
use Illuminate\Support\Arr;
class OidcProvider extends AbstractProvider implements ProviderInterface
{
@ -39,7 +39,7 @@ class OidcProvider extends AbstractProvider implements ProviderInterface
$endpoint = config('services.oidc.endpoint');
if (!$endpoint) {
throw new Exception('OIDC endpoint is not configured. Please set OIDC_ENDPOINT environment variable.');
throw new \Exception('OIDC endpoint is not configured. Please set OIDC_ENDPOINT environment variable.');
}
// Handle both full well-known URL and base URL
@ -65,15 +65,15 @@ class OidcProvider extends AbstractProvider implements ProviderInterface
$this->oidcConfig = json_decode($response->getBody()->getContents(), true);
if (!$this->oidcConfig) {
throw new Exception('OIDC configuration is empty or invalid JSON');
throw new \Exception('OIDC configuration is empty or invalid JSON');
}
if (!isset($this->oidcConfig['authorization_endpoint'])) {
throw new Exception('authorization_endpoint not found in OIDC configuration');
throw new \Exception('authorization_endpoint not found in OIDC configuration');
}
} catch (Exception $e) {
throw new Exception('Failed to load OIDC configuration: '.$e->getMessage());
} catch (\Exception $e) {
throw new \Exception('Failed to load OIDC configuration: ' . $e->getMessage());
}
}
@ -83,9 +83,8 @@ class OidcProvider extends AbstractProvider implements ProviderInterface
protected function getAuthUrl($state)
{
if (!$this->oidcConfig || !isset($this->oidcConfig['authorization_endpoint'])) {
throw new Exception('OIDC configuration not loaded or authorization_endpoint not found.');
throw new \Exception('OIDC configuration not loaded or authorization_endpoint not found.');
}
return $this->buildAuthUrlFromBase($this->oidcConfig['authorization_endpoint'], $state);
}
@ -95,9 +94,8 @@ class OidcProvider extends AbstractProvider implements ProviderInterface
protected function getTokenUrl()
{
if (!$this->oidcConfig || !isset($this->oidcConfig['token_endpoint'])) {
throw new Exception('OIDC configuration not loaded or token_endpoint not found.');
throw new \Exception('OIDC configuration not loaded or token_endpoint not found.');
}
return $this->oidcConfig['token_endpoint'];
}
@ -107,7 +105,7 @@ class OidcProvider extends AbstractProvider implements ProviderInterface
protected function getUserByToken($token)
{
if (!$this->oidcConfig || !isset($this->oidcConfig['userinfo_endpoint'])) {
throw new Exception('OIDC configuration not loaded or userinfo_endpoint not found.');
throw new \Exception('OIDC configuration not loaded or userinfo_endpoint not found.');
}
$response = $this->getHttpClient()->get($this->oidcConfig['userinfo_endpoint'], [

View file

@ -2,8 +2,7 @@
declare(strict_types=1);
use App\Models\Device;
use App\Models\User;
use App\Models\{Device, User};
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
@ -17,8 +16,8 @@ test('dashboard shows device image with correct rotation', function () {
]);
// Mock the file existence check
Illuminate\Support\Facades\Storage::fake('public');
Illuminate\Support\Facades\Storage::disk('public')->put('images/generated/test-image-uuid.png', 'fake-image-content');
\Illuminate\Support\Facades\Storage::fake('public');
\Illuminate\Support\Facades\Storage::disk('public')->put('images/generated/test-image-uuid.png', 'fake-image-content');
$response = $this->actingAs($user)
->get(route('dashboard'));
@ -37,8 +36,8 @@ test('device configure page shows device image with correct rotation', function
]);
// Mock the file existence check
Illuminate\Support\Facades\Storage::fake('public');
Illuminate\Support\Facades\Storage::disk('public')->put('images/generated/test-image-uuid.png', 'fake-image-content');
\Illuminate\Support\Facades\Storage::fake('public');
\Illuminate\Support\Facades\Storage::disk('public')->put('images/generated/test-image-uuid.png', 'fake-image-content');
$response = $this->actingAs($user)
->get(route('devices.configure', $device));
@ -57,8 +56,8 @@ test('device with no rotation shows no transform style', function () {
]);
// Mock the file existence check
Illuminate\Support\Facades\Storage::fake('public');
Illuminate\Support\Facades\Storage::disk('public')->put('images/generated/test-image-uuid.png', 'fake-image-content');
\Illuminate\Support\Facades\Storage::fake('public');
\Illuminate\Support\Facades\Storage::disk('public')->put('images/generated/test-image-uuid.png', 'fake-image-content');
$response = $this->actingAs($user)
->get(route('dashboard'));
@ -76,8 +75,8 @@ test('device with null rotation defaults to 0', function () {
]);
// Mock the file existence check
Illuminate\Support\Facades\Storage::fake('public');
Illuminate\Support\Facades\Storage::disk('public')->put('images/generated/test-image-uuid.png', 'fake-image-content');
\Illuminate\Support\Facades\Storage::fake('public');
\Illuminate\Support\Facades\Storage::disk('public')->put('images/generated/test-image-uuid.png', 'fake-image-content');
$response = $this->actingAs($user)
->get(route('dashboard'));

View file

@ -3,6 +3,10 @@
use App\Models\Plugin;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Livewire\Volt\Volt;
use Symfony\Component\Yaml\Yaml;
uses(RefreshDatabase::class);
@ -18,23 +22,23 @@ test('plugin import extracts default values from custom_fields and stores in con
'field_type' => 'string',
'name' => 'Reading Days',
'description' => 'Select days of the week to read',
'default' => 'Monday,Friday,Saturday,Sunday',
'default' => 'Monday,Friday,Saturday,Sunday'
],
[
'keyname' => 'refresh_interval',
'field_type' => 'number',
'name' => 'Refresh Interval',
'description' => 'How often to refresh data',
'default' => 15,
'default' => 15
],
[
'keyname' => 'timezone',
'field_type' => 'time_zone',
'name' => 'Timezone',
'description' => 'Select your timezone',
'description' => 'Select your timezone'
// No default value
],
],
]
]
];
// Extract default values from custom_fields and populate configuration
@ -49,7 +53,7 @@ test('plugin import extracts default values from custom_fields and stores in con
// Create the plugin directly
$plugin = Plugin::create([
'uuid' => Illuminate\Support\Str::uuid(),
'uuid' => \Illuminate\Support\Str::uuid(),
'user_id' => $user->id,
'name' => 'Test Plugin with Defaults',
'data_stale_minutes' => 30,
@ -85,9 +89,9 @@ test('plugin import handles custom_fields without default values', function () {
'keyname' => 'timezone',
'field_type' => 'time_zone',
'name' => 'Timezone',
'description' => 'Select your timezone',
],
],
'description' => 'Select your timezone'
]
]
];
// Extract default values from custom_fields and populate configuration
@ -102,7 +106,7 @@ test('plugin import handles custom_fields without default values', function () {
// Create the plugin directly
$plugin = Plugin::create([
'uuid' => Illuminate\Support\Str::uuid(),
'uuid' => \Illuminate\Support\Str::uuid(),
'user_id' => $user->id,
'name' => 'Test Plugin No Defaults',
'data_stale_minutes' => 30,