From d4de074161bf73b0cbc6284b1bd63af3174c38cf Mon Sep 17 00:00:00 2001 From: idevakk <219866223+idevakk@users.noreply.github.com> Date: Fri, 28 Nov 2025 05:59:25 -0800 Subject: [PATCH] fix: add fallback value for setting variables --- app/Livewire/Frontend/Action.php | 41 ++++++++++-------- dropmail.php | 10 ++--- dropmailP.php | 10 ++--- .../views/components/layouts/app.blade.php | 42 +++++++++++++------ .../components/layouts/dashboard.blade.php | 24 +++++++---- resources/views/livewire/blog.blade.php | 5 ++- .../views/livewire/frontend/mailbox.blade.php | 6 ++- 7 files changed, 88 insertions(+), 50 deletions(-) diff --git a/app/Livewire/Frontend/Action.php b/app/Livewire/Frontend/Action.php index a74e854..c397033 100644 --- a/app/Livewire/Frontend/Action.php +++ b/app/Livewire/Frontend/Action.php @@ -2,13 +2,13 @@ namespace App\Livewire\Frontend; -use Illuminate\Routing\Redirector; -use Illuminate\Http\RedirectResponse; -use Illuminate\Support\Facades\Date; -use Illuminate\Contracts\View\Factory; -use Illuminate\Contracts\View\View; use App\Models\Log; use App\Models\ZEmail; +use Illuminate\Contracts\View\Factory; +use Illuminate\Contracts\View\View; +use Illuminate\Http\RedirectResponse; +use Illuminate\Routing\Redirector; +use Illuminate\Support\Facades\Date; use Livewire\Component; class Action extends Component @@ -27,9 +27,12 @@ class Action extends Component public $initial; + private $configSettings; + public function mount(): void { - $this->domains = json_decode((string) config('app.settings.configuration_settings'))->domains ?? []; + $this->configSettings = json_decode(config('app.settings.configuration_settings') ?: '{}'); + $this->domains = $this->configSettings->domains ?? []; $this->email = ZEmail::getEmail(); $this->emails = ZEmail::getEmails(); $this->validateDomainInEmail(); @@ -41,17 +44,17 @@ class Action extends Component return $this->showAlert('error', __('Please enter Username')); } $this->checkDomainInUsername(); - if (strlen((string) $this->username) < json_decode((string) config('app.settings.configuration_settings'))->custom_username_length_min || strlen((string) $this->username) > json_decode((string) config('app.settings.configuration_settings'))->custom_username_length_max) { - return $this->showAlert('error', __('Username length cannot be less than').' '.json_decode((string) config('app.settings.configuration_settings'))->custom_username_length_min.' '.__('and greater than').' '.json_decode((string) config('app.settings.configuration_settings'))->custom_username_length_max); + if (strlen((string) $this->username) < ($this->configSettings->custom_username_length_min ?? 3) || strlen((string) $this->username) > ($this->configSettings->custom_username_length_max ?? 30)) { + return $this->showAlert('error', __('Username length cannot be less than').' '.($this->configSettings->custom_username_length_min ?? 3).' '.__('and greater than').' '.($this->configSettings->custom_username_length_max ?? 30)); } if (! $this->domain) { return $this->showAlert('error', __('Please Select a Domain')); } - if (in_array($this->username, json_decode((string) config('app.settings.configuration_settings'))->forbidden_ids)) { + if (in_array($this->username, $this->configSettings->forbidden_ids ?? [])) { return $this->showAlert('error', __('Username not allowed')); } if (! $this->checkEmailLimit()) { - return $this->showAlert('error', __('You have reached daily limit of MAX ').json_decode((string) config('app.settings.configuration_settings'))->email_limit.__(' temp mail')); + return $this->showAlert('error', __('You have reached daily limit of MAX ').($this->configSettings->email_limit ?? 10).__(' temp mail')); } if (! $this->checkUsedEmail()) { return $this->showAlert('error', __('Sorry! That email is already been used by someone else. Please try a different email address.')); @@ -66,7 +69,7 @@ class Action extends Component public function random() { if (! $this->checkEmailLimit()) { - return $this->showAlert('error', __('You have reached daily limit of maximum ').json_decode((string) config('app.settings.configuration_settings'))->email_limit.__(' temp mail addresses.')); + return $this->showAlert('error', __('You have reached daily limit of maximum ').($this->configSettings->email_limit ?? 10).__(' temp mail addresses.')); } $this->email = ZEmail::generateRandomEmail(); @@ -76,7 +79,7 @@ class Action extends Component public function gmail() { if (! $this->checkEmailLimit()) { - return $this->showAlert('error', __('You have reached daily limit of maximum ').json_decode((string) config('app.settings.configuration_settings'))->email_limit.__(' temp mail addresses.')); + return $this->showAlert('error', __('You have reached daily limit of maximum ').($this->configSettings->email_limit ?? 10).__(' temp mail addresses.')); } $this->email = ZEmail::generateRandomGmail(); @@ -86,7 +89,7 @@ class Action extends Component public function outlook() { if (! $this->checkEmailLimit()) { - return $this->showAlert('error', __('You have reached daily limit of maximum ').json_decode((string) config('app.settings.configuration_settings'))->email_limit.__(' temp mail addresses.')); + return $this->showAlert('error', __('You have reached daily limit of maximum ').($this->configSettings->email_limit ?? 10).__(' temp mail addresses.')); } $this->email = ZEmail::generateRandomOutlook(); @@ -100,7 +103,7 @@ class Action extends Component private function showAlert(string $type, $message): void { - $check = json_decode((string) config('app.settings.configuration_settings'))->email_limit; + $check = $this->configSettings->email_limit ?? 10; if (str_contains((string) $message, (string) $check)) { $this->dispatch('promotePremium'); } @@ -110,13 +113,15 @@ class Action extends Component private function checkEmailLimit(): bool { $logs = Log::query()->select('ip', 'email')->where('ip', request()->ip())->where('created_at', '>', Date::now()->subDay())->groupBy('email')->groupBy('ip')->get(); - return count($logs) < json_decode((string) config('app.settings.configuration_settings'))->email_limit; + + return count($logs) < ($this->configSettings->email_limit ?? 10); } private function checkUsedEmail(): bool { - if (json_decode((string) config('app.settings.configuration_settings'))->disable_used_email) { + if ($this->configSettings->disable_used_email ?? false) { $check = Log::query()->where('email', $this->user.'@'.$this->domain)->where('ip', '<>', request()->ip())->count(); + return $check <= 0; } @@ -139,11 +144,11 @@ class Action extends Component $data = explode('@', (string) $this->email); if (isset($data[1])) { $domain = $data[1]; - $domains = json_decode((string) config('app.settings.configuration_settings'))->domains ?? []; + $domains = $this->configSettings->domains ?? []; if (! in_array($domain, $domains)) { $key = array_search($this->email, $this->emails); ZEmail::removeEmail($this->email); - if ($key == 0 && count($this->emails) === 1 && json_decode((string) config('app.settings.configuration_settings'))->after_last_email_delete == 'redirect_to_homepage') { + if ($key == 0 && count($this->emails) === 1 && ($this->configSettings->after_last_email_delete ?? '') == 'redirect_to_homepage') { to_route('home'); } else { to_route('mailbox'); diff --git a/dropmail.php b/dropmail.php index 5debbca..883b6b5 100644 --- a/dropmail.php +++ b/dropmail.php @@ -3,7 +3,7 @@ // 1. Bootstrap Laravel require __DIR__.'/vendor/autoload.php'; -$app = require_once __DIR__.'/bootstrap/app.php'; +$app = require __DIR__.'/bootstrap/app.php'; // 2. Start Laravel container $kernel = $app->make(Illuminate\Contracts\Console\Kernel::class); @@ -14,12 +14,12 @@ set_time_limit(0); $newTimezone = 'Europe/London'; date_default_timezone_set($newTimezone); -$imapDB = json_decode(config('app.settings.imap_settings'), true); +$imapDB = json_decode(config('app.settings.imap_settings') ?: '{}', true); // Mailbox credentials -$hostname = '{'.$imapDB['host'].':'.$imapDB['port'].'/ssl}INBOX'; -$username = $imapDB['username']; -$password = $imapDB['password']; +$hostname = '{'.($imapDB['host'] ?? 'localhost').':'.($imapDB['port'] ?? '993').'/ssl}INBOX'; +$username = $imapDB['username'] ?? ''; +$password = $imapDB['password'] ?? ''; // Connect to mailbox $inbox = imap_open($hostname, $username, $password); diff --git a/dropmailP.php b/dropmailP.php index 29eaf3b..08ad1e9 100644 --- a/dropmailP.php +++ b/dropmailP.php @@ -3,7 +3,7 @@ // 1. Bootstrap Laravel require __DIR__.'/vendor/autoload.php'; -$app = require_once __DIR__.'/bootstrap/app.php'; +$app = require __DIR__.'/bootstrap/app.php'; // 2. Start Laravel container $kernel = $app->make(Illuminate\Contracts\Console\Kernel::class); @@ -14,12 +14,12 @@ set_time_limit(0); $newTimezone = 'Europe/London'; date_default_timezone_set($newTimezone); -$imapDB = json_decode(config('app.settings.imap_settings'), true); +$imapDB = json_decode(config('app.settings.imap_settings') ?: '{}', true); // Mailbox credentials -$hostname = '{'.$imapDB['premium_host'].':'.$imapDB['premium_port'].'/ssl}INBOX'; -$username = $imapDB['premium_username']; -$password = $imapDB['premium_password']; +$hostname = '{'.($imapDB['premium_host'] ?? 'localhost').':'.($imapDB['premium_port'] ?? '993').'/ssl}INBOX'; +$username = $imapDB['premium_username'] ?? ''; +$password = $imapDB['premium_password'] ?? ''; // Connect to mailbox $inbox = imap_open($hostname, $username, $password); diff --git a/resources/views/components/layouts/app.blade.php b/resources/views/components/layouts/app.blade.php index 57d1b57..c1efd80 100644 --- a/resources/views/components/layouts/app.blade.php +++ b/resources/views/components/layouts/app.blade.php @@ -8,12 +8,16 @@
Support us by disabling ad blockеrs on our site 🙏