Add all files
This commit is contained in:
163
app/Providers/AppServiceProvider.php
Normal file
163
app/Providers/AppServiceProvider.php
Normal file
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Classes\Synths\PriceSynth;
|
||||
use App\Helpers\ExtensionHelper;
|
||||
use App\Models\EmailLog;
|
||||
use App\Models\Extension;
|
||||
use App\Models\OauthClient;
|
||||
use App\Models\User;
|
||||
use App\Support\Passport\ScopeRegistry;
|
||||
use Closure;
|
||||
use Dedoc\Scramble\Scramble;
|
||||
use Dedoc\Scramble\Support\Generator\OpenApi;
|
||||
use Dedoc\Scramble\Support\Generator\SecurityScheme;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Queue\Events\JobFailed;
|
||||
use Illuminate\Queue\Events\JobProcessed;
|
||||
use Illuminate\Routing\UrlGenerator;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Passport\Passport;
|
||||
use League\CommonMark\Extension\Table\TableExtension;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
// Service provider for settings
|
||||
$this->app->register(SettingsProvider::class);
|
||||
|
||||
UrlGenerator::macro('alternateHasCorrectSignature', function (Request $request, $absolute = true, Closure|array $ignoreQuery = []) {
|
||||
// ensure the base path is applied to absolute url
|
||||
$absoluteUrl = url($request->path()); // forceRootUrl and forceScheme will apply
|
||||
$url = $absolute ? $absoluteUrl : '/' . $request->path();
|
||||
|
||||
$queryString = collect(explode('&', (string) $request->server->get('QUERY_STRING')))
|
||||
->reject(function ($parameter) use ($ignoreQuery) {
|
||||
$parameter = Str::before($parameter, '=');
|
||||
|
||||
if ($parameter === 'signature') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($ignoreQuery instanceof Closure) {
|
||||
return $ignoreQuery($parameter);
|
||||
}
|
||||
|
||||
return in_array($parameter, $ignoreQuery);
|
||||
})
|
||||
->join('&');
|
||||
|
||||
$original = rtrim($url . '?' . $queryString, '?');
|
||||
|
||||
$keys = call_user_func($this->keyResolver);
|
||||
|
||||
$keys = is_array($keys) ? $keys : [$keys];
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (
|
||||
hash_equals(
|
||||
hash_hmac('sha256', $original, $key),
|
||||
(string) $request->query('signature', '')
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
UrlGenerator::macro('alternateHasValidSignature', function (Request $request, $absolute = true, array $ignoreQuery = []) {
|
||||
return \URL::alternateHasCorrectSignature($request, $absolute, $ignoreQuery)
|
||||
&& \URL::signatureHasNotExpired($request);
|
||||
});
|
||||
|
||||
Request::macro('hasValidSignature', function ($absolute = true, array $ignoreQuery = []) {
|
||||
return \URL::alternateHasValidSignature($this, $absolute, $ignoreQuery);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
// Change livewire url
|
||||
\Livewire\Livewire::setUpdateRoute(function ($handle) {
|
||||
return \Illuminate\Support\Facades\Route::post('/paymenter/update', $handle)->middleware('web')->name('paymenter.');
|
||||
});
|
||||
\Livewire\Livewire::propertySynthesizer(PriceSynth::class);
|
||||
|
||||
Gate::define('has-permission', function (User $user, string $ability) {
|
||||
return $user->hasPermission($ability);
|
||||
});
|
||||
|
||||
Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
|
||||
$event->extendSocialite('discord', \SocialiteProviders\Discord\Provider::class);
|
||||
});
|
||||
|
||||
try {
|
||||
foreach (
|
||||
collect(Extension::where(function ($query) {
|
||||
$query->where('enabled', true)->orWhere('type', 'server')->orWhere('type', 'gateway');
|
||||
})->get())->unique('extension') as $extension
|
||||
) {
|
||||
ExtensionHelper::call($extension, 'boot', mayFail: true);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Fail silently
|
||||
}
|
||||
|
||||
Queue::after(function (JobProcessed $event) {
|
||||
if ($event->job->resolveName() === 'App\Mail\Mail') {
|
||||
$payload = json_decode($event->job->getRawBody());
|
||||
$data = unserialize($payload->data->command);
|
||||
EmailLog::where('id', $data->mailable->email_log_id)->update([
|
||||
'sent_at' => now(),
|
||||
'status' => 'sent',
|
||||
]);
|
||||
}
|
||||
});
|
||||
Queue::failing(function (JobFailed $event) {
|
||||
if ($event->job->resolveName() === 'App\Mail\Mail') {
|
||||
$payload = json_decode($event->job->getRawBody());
|
||||
$data = unserialize($payload->data->command);
|
||||
EmailLog::where('id', $data->mailable->email_log_id)->update([
|
||||
'status' => 'failed',
|
||||
'error' => $event->exception->getMessage(),
|
||||
'job_uuid' => $event->job->uuid(),
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
Str::macro('markdown', function ($markdown) {
|
||||
return Str::markdown($markdown, extensions: [
|
||||
new TableExtension,
|
||||
]);
|
||||
});
|
||||
Passport::clientModel(OauthClient::class);
|
||||
Passport::ignoreRoutes();
|
||||
Passport::tokensCan(ScopeRegistry::getAll());
|
||||
|
||||
if (class_exists(Scramble::class)) {
|
||||
Scramble::configure()
|
||||
->routes(function (\Illuminate\Routing\Route $route) {
|
||||
return Str::startsWith($route->uri, 'api/v1/admin');
|
||||
})
|
||||
->withDocumentTransformers(function (OpenApi $openApi) {
|
||||
$openApi->secure(
|
||||
SecurityScheme::http('bearer')
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
100
app/Providers/Filament/AdminPanelProvider.php
Normal file
100
app/Providers/Filament/AdminPanelProvider.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers\Filament;
|
||||
|
||||
use App\Http\Middleware\ImpersonateMiddleware;
|
||||
use App\Models\Extension;
|
||||
use App\Providers\SettingsProvider;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Http\Middleware\Authenticate;
|
||||
use Filament\Http\Middleware\DisableBladeIconComponents;
|
||||
use Filament\Http\Middleware\DispatchServingFilamentEvent;
|
||||
use Filament\Navigation\MenuItem;
|
||||
use Filament\Notifications\Livewire\Notifications;
|
||||
use Filament\Panel;
|
||||
use Filament\PanelProvider;
|
||||
use Filament\Support\Colors\Color;
|
||||
use Filament\Support\Enums\Alignment;
|
||||
use Filament\View\PanelsRenderHook;
|
||||
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies;
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
|
||||
use Illuminate\Routing\Middleware\SubstituteBindings;
|
||||
use Illuminate\Session\Middleware\AuthenticateSession;
|
||||
use Illuminate\Session\Middleware\StartSession;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\View\Middleware\ShareErrorsFromSession;
|
||||
|
||||
class AdminPanelProvider extends PanelProvider
|
||||
{
|
||||
public function panel(Panel $panel): Panel
|
||||
{
|
||||
// Filament loads before the settings provider, so we need to load the settings here
|
||||
SettingsProvider::getSettings();
|
||||
|
||||
Notifications::alignment(Alignment::Center);
|
||||
|
||||
$panel
|
||||
->default()
|
||||
->id('admin')
|
||||
->path('admin')
|
||||
->spa()
|
||||
->colors([
|
||||
'primary' => Color::Blue,
|
||||
])
|
||||
->globalSearchKeyBindings(['command+k', 'ctrl+k'])
|
||||
->favicon(config('settings.logo') ? Storage::url(config('settings.logo')) : null)
|
||||
->discoverResources(in: app_path('Admin/Resources'), for: 'App\\Admin\\Resources')
|
||||
->discoverPages(in: app_path('Admin/Pages'), for: 'App\\Admin\\Pages')
|
||||
->discoverClusters(in: app_path('Admin/Clusters'), for: 'App\\Admin\\Clusters')
|
||||
->userMenuItems([
|
||||
MenuItem::make()
|
||||
->label('Exit Admin')
|
||||
->url('/')
|
||||
->icon('heroicon-s-arrow-uturn-left')
|
||||
->sort(24),
|
||||
])
|
||||
->discoverWidgets(in: app_path('Admin/Widgets'), for: 'App\\Admin\\Widgets')
|
||||
->renderHook(
|
||||
PanelsRenderHook::SIDEBAR_NAV_END,
|
||||
fn (): string => Blade::render('<x-admin-footer />'),
|
||||
)
|
||||
->navigationGroups([
|
||||
'Administration',
|
||||
'Configuration',
|
||||
'Extensions',
|
||||
'System',
|
||||
])
|
||||
->middleware([
|
||||
EncryptCookies::class,
|
||||
AddQueuedCookiesToResponse::class,
|
||||
StartSession::class,
|
||||
ImpersonateMiddleware::class,
|
||||
AuthenticateSession::class,
|
||||
ShareErrorsFromSession::class,
|
||||
VerifyCsrfToken::class,
|
||||
SubstituteBindings::class,
|
||||
DisableBladeIconComponents::class,
|
||||
DispatchServingFilamentEvent::class,
|
||||
])
|
||||
->theme(asset('css/filament/admin/theme.css'))
|
||||
->authMiddleware([
|
||||
Authenticate::class,
|
||||
]);
|
||||
|
||||
try {
|
||||
foreach (collect(Extension::where(function ($query) {
|
||||
$query->where('enabled', true)->orWhere('type', 'server')->orWhere('type', 'gateway');
|
||||
})->get())->unique('extension') as $extension) {
|
||||
$panel->discoverResources(in: base_path('extensions' . '/' . $extension->path . '/Admin/Resources'), for: $extension->namespace . '\\Admin\\Resources');
|
||||
$panel->discoverPages(in: base_path('extensions' . '/' . $extension->path . '/Admin/Pages'), for: $extension->namespace . '\\Admin\\Pages');
|
||||
$panel->discoverClusters(in: base_path('extensions' . '/' . $extension->path . '/Admin/Clusters'), for: $extension->namespace . '\\Admin\\Clusters');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
return $panel;
|
||||
}
|
||||
}
|
||||
78
app/Providers/SettingsProvider.php
Normal file
78
app/Providers/SettingsProvider.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Str;
|
||||
use Qirolab\Theme\Theme;
|
||||
|
||||
class SettingsProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register services.
|
||||
*/
|
||||
public function register(): void {}
|
||||
|
||||
/**
|
||||
* Bootstrap services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
$this->getSettings();
|
||||
}
|
||||
|
||||
public static function getSettings($force = false): void
|
||||
{
|
||||
if (config('settings') && !empty(config('settings')) && !$force) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// Load settings from cache
|
||||
$settings = Cache::get('settings', []);
|
||||
if (empty($settings)) {
|
||||
$settings = Setting::where('settingable_type', null)->get()->pluck('value', 'key');
|
||||
Cache::put('settings', $settings);
|
||||
}
|
||||
// Is the current command a config:cache command?
|
||||
if (isset($_SERVER['argv']) && (in_array('config:cache', $_SERVER['argv']) || in_array('optimize', $_SERVER['argv']) || in_array('app:optimize', $_SERVER['argv']))) {
|
||||
return;
|
||||
}
|
||||
config(['settings' => $settings]);
|
||||
foreach (\App\Classes\Settings::settings() as $settings) {
|
||||
foreach ($settings as $setting) {
|
||||
if (isset($setting['override']) && config("settings.$setting[name]") !== null) {
|
||||
config([$setting['override'] => config("settings.$setting[name]")]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
include_once app_path('Classes/helpers.php');
|
||||
|
||||
date_default_timezone_set(config('settings.timezone', 'UTC'));
|
||||
|
||||
Theme::set(config('settings.theme', 'default'), 'default');
|
||||
|
||||
if (Str::startsWith(config('app.url') ?? '', 'https://')) {
|
||||
URL::forceScheme('https');
|
||||
}
|
||||
URL::forceRootUrl(config('app.url'));
|
||||
|
||||
Config::set('filesystems.disks.public.url', config('app.url') . '/storage');
|
||||
} catch (\Exception $e) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
public static function flushCache()
|
||||
{
|
||||
Cache::forget('settings');
|
||||
// Restart queue worker
|
||||
Artisan::call('queue:restart');
|
||||
self::getSettings(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user