diff --git a/app/Filament/Resources/PlanResource.php b/app/Filament/Resources/PlanResource.php index 79fbab7..686309c 100644 --- a/app/Filament/Resources/PlanResource.php +++ b/app/Filament/Resources/PlanResource.php @@ -46,6 +46,7 @@ class PlanResource extends Resource TextInput::make('product_id')->required(), TextInput::make('pricing_id')->required(), TextInput::make('price')->numeric()->required(), + TextInput::make('mailbox_limit')->numeric()->required(), Select::make('monthly_billing')->options([ 1 => 'Monthly', 0 => 'Yearly', diff --git a/app/Http/Controllers/AppController.php b/app/Http/Controllers/AppController.php index d9330fd..94de456 100644 --- a/app/Http/Controllers/AppController.php +++ b/app/Http/Controllers/AppController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Models\Premium; use App\Models\ZEmail; use Illuminate\Http\Request; @@ -48,6 +49,16 @@ class AppController extends Controller } } + public function deleteP($email = null) { + if ($email) { + $emails = Premium::getEmails(); + Premium::removeEmail($email); + return redirect()->route('dashboard.premium'); + } else { + return redirect()->route('dashboard'); + } + } + public function locale($locale) { if (in_array($locale, config('app.locales'))) { session(['locale' => $locale]); diff --git a/app/Livewire/Dashboard/Mailbox/Inbox.php b/app/Livewire/Dashboard/Mailbox/Inbox.php new file mode 100644 index 0000000..1c9916b --- /dev/null +++ b/app/Livewire/Dashboard/Mailbox/Inbox.php @@ -0,0 +1,295 @@ + 'syncEmail', 'getEmail' => 'generateEmail', 'fetchMessages' => 'fetch', 'setMessageId' => 'setMessageId']; + + + public function mount(): void + { + $this->domains = json_decode(config('app.settings.configuration_settings'))->premium_domains ?? []; + $this->email = Premium::getEmail(); + $this->emails = Premium::getEmails(); + $this->initial = false; + $this->checkMultipleEmails(); + $this->validateDomainInEmail(); + + if(auth()->user()->subscribedToProduct(config('app.plans')[0]['product_id'])) { + try { + $result = auth()->user()->subscriptions()->where(['stripe_status' => 'active'])->orderByDesc('updated_at')->first(); + $userPriceID = $result['items'][0]['stripe_price']; + + $mailboxLimit = $this->email_limit; + foreach (config('app.plans') as $plan) { + if ($plan['pricing_id'] === $userPriceID) { + $mailboxLimit = $plan['mailbox_limit']; + break; + } + } + $this->email_limit = $mailboxLimit; + + } catch (\Exception $e) { + \Log::error($e->getMessage()); + } + } + } + + private function checkMultipleEmails(): void + { + if (count($this->emails) == 0) { + $this->emails = [$this->email]; + } + if (count($this->emails) > 1) { + $this->list = true; + } else { + $this->list = false; + } + } + + public function switchEmail($email) + { + return redirect()->route('switch', ['email' => $email]); + } + + public function syncEmail(): void + { + $this->email = Premium::getEmail(); + $this->emails = Premium::getEmails(); + if (count($this->emails) == 0) { + $this->dispatch('getEmail'); + } + $this->checkMultipleEmails(); + $this->dispatch('syncMailbox', $this->email); + $this->dispatch('fetchMessages'); + } + + public function generateEmail(): void + { + if ($this->email == null) { + Premium::generateRandomEmail(); + } + $this->checkMultipleEmails(); + $this->dispatch('updateEmail'); + } + + /* Actions */ + public function create() { + if (!$this->username) { + return $this->showAlert('error', __('Please enter Username')); + } + $this->checkDomainInUsername(); + if (strlen($this->username) < json_decode(config('app.settings.configuration_settings'))->custom_username_length_min || strlen($this->username) > json_decode(config('app.settings.configuration_settings'))->custom_username_length_max) { + return $this->showAlert('error', __('Username length cannot be less than') . ' ' . json_decode(config('app.settings.configuration_settings'))->custom_username_length_min . ' ' . __('and greater than') . ' ' . json_decode(config('app.settings.configuration_settings'))->custom_username_length_max); + } + if (!$this->domain) { + return $this->showAlert('error', __('Please Select a Domain')); + } + if (in_array($this->username, json_decode(config('app.settings.configuration_settings'))->forbidden_ids)) { + return $this->showAlert('error', __('Username not allowed')); + } + if (!$this->checkEmailLimit()) { + return $this->showAlert('error', __('You have reached daily limit of MAX ') . $this->email_limit . __(' 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.')); + } + + $this->email = Premium::createCustomEmail($this->username, $this->domain); + return redirect()->route('dashboard.premium'); + + } + public function random() { + + if (!$this->checkEmailLimit()) { + return $this->showAlert('error', __('You have reached daily limit of maximum ') . $this->email_limit . __(' temp mail addresses.')); + } + $this->email = Premium::generateRandomEmail(); + return redirect()->route('dashboard.premium'); + } + public function gmail() { + if (!$this->checkEmailLimit()) { + return $this->showAlert('error', __('You have reached daily limit of maximum ') . $this->email_limit . __(' temp mail addresses.')); + } + $this->email = Premium::generateRandomGmail(); + return redirect()->route('dashboard.premium'); + } + + public function deleteEmail() + { + return redirect()->route('deleteP', ['email' => $this->email]); + } + + private function showAlert($type, $message): void + { + $this->dispatch('showAlert', ['type' => $type, 'message' => $message]); + } + + private function checkEmailLimit(): bool + { + $logs = Log::select('ip', 'email')->where('user_id', auth()->user()->id)->where('created_at', '>', Carbon::now()->subDay())->groupBy('email')->groupBy('ip')->get(); + if (count($logs) >= $this->email_limit) { + return false; + } + return true; + } + + private function checkUsedEmail(): bool + { + if (json_decode(config('app.settings.configuration_settings'))->disable_used_email) { + $check = Log::where('email', $this->user . '@' . $this->domain)->where('ip', '<>', request()->ip())->count(); + if ($check > 0) { + return false; + } + return true; + } + return true; + } + + private function checkDomainInUsername(): void + { + $parts = explode('@', $this->username); + if (isset($parts[1])) { + if (in_array($parts[1], $this->domains)) { + $this->domain = $parts[1]; + } + $this->username = $parts[0]; + } + } + + private function validateDomainInEmail(): void + { + $data = explode('@', $this->email); + if (isset($data[1])) { + $domain = $data[1]; + $domains = json_decode(config('app.settings.configuration_settings'))->premium_domains ?? []; + if (!in_array($domain, $domains)) { + $key = array_search($this->email, $this->emails); + Premium::removeEmail($this->email); + if ($key == 0 && count($this->emails) == 1 && json_decode(config('app.settings.configuration_settings'))->after_last_email_delete == 'redirect_to_homepage') { + redirect()->route('dashboard.premium'); + } else { + redirect()->route('dashboard.premium'); + } + } + } + } + + /* Mailbox */ + + + public function fetch(): void + { + try { + $count = count($this->messages); + if ($count > 0) { + $this->messages = []; + } + $responses = []; + if (config('app.beta_feature') || !json_decode(config('app.settings.imap_settings'))->premium_cc_check) { + $responses = [ + 'to' => Premium::getMessages($this->email, 'to', $this->deleted), + 'cc' => [ + 'data' => [], + 'notifications' => [] + ] + ]; + } else { + $responses = [ + 'to' => Premium::getMessages($this->email, 'to', $this->deleted), + 'cc' => Premium::getMessages($this->email, 'cc', $this->deleted) + ]; + } + + $this->deleted = []; + $this->messages = array_merge($responses['to']['data'], $responses['cc']['data']); + $notifications = array_merge($responses['to']['notifications'], $responses['cc']['notifications']); + + if (count($notifications)) { + if (!$this->overflow && count($this->messages) == $count) { + $this->overflow = true; + } + } else { + $this->overflow = false; + } + + foreach ($notifications as $notification) { + $this->dispatch('showNewMailNotification', $notification); + } + Premium::incrementMessagesStats(count($notifications)); + } catch (\Exception $e) { + if (Auth::check() && Auth::user()->level == 9) { + $this->error = $e->getMessage(); + } else { + $this->error = 'Not able to connect to Mail Server'; + } + } + $this->dispatch('stopLoader'); + $this->initial = true; + } + + public function delete($messageId) { + + try { + $this->deleted[] = $messageId; + foreach ($this->messages as $key => $message) { + if ($message['id'] == $messageId) { + $directory = public_path('tmp/premium/attachments/') . $messageId; + $this->rrmdir($directory); + unset($this->messages[$key]); + } + } + + } catch ( + \Exception $exception + ) { + \Illuminate\Support\Facades\Log::error($exception->getMessage()); + } + + } + + public function render() + { + return view('livewire.dashboard.mailbox.inbox')->layout('components.layouts.dashboard'); + } + + private function rrmdir($dir): void + { + if (is_dir($dir)) { + $objects = scandir($dir); + foreach ($objects as $object) { + if ($object != "." && $object != "..") { + if (is_dir($dir . DIRECTORY_SEPARATOR . $object) && !is_link($dir . "/" . $object)) + $this->rrmdir($dir . DIRECTORY_SEPARATOR . $object); + else + unlink($dir . DIRECTORY_SEPARATOR . $object); + } + } + rmdir($dir); + } + } +} diff --git a/app/Livewire/Frontend/Action.php b/app/Livewire/Frontend/Action.php index 3c68e13..573d78a 100644 --- a/app/Livewire/Frontend/Action.php +++ b/app/Livewire/Frontend/Action.php @@ -10,8 +10,6 @@ use Livewire\Component; class Action extends Component { public $username, $email, $emails, $domain, $domains, $action, $initial; - - public function mount() { $this->domains = json_decode(config('app.settings.configuration_settings'))->domains ?? []; $this->email = ZEmail::getEmail(); diff --git a/app/Models/Log.php b/app/Models/Log.php index ce1ec70..52438f0 100644 --- a/app/Models/Log.php +++ b/app/Models/Log.php @@ -16,6 +16,7 @@ class Log extends Model * @var array */ protected $fillable = [ + 'user_id', 'ip', 'email', ]; diff --git a/app/Models/Plan.php b/app/Models/Plan.php index ea0ee84..d8af905 100644 --- a/app/Models/Plan.php +++ b/app/Models/Plan.php @@ -12,6 +12,7 @@ class Plan extends Model 'product_id', 'pricing_id', 'price', + 'mailbox_limit', 'monthly_billing', 'details' ]; diff --git a/app/Models/Premium.php b/app/Models/Premium.php new file mode 100644 index 0000000..68f45ba --- /dev/null +++ b/app/Models/Premium.php @@ -0,0 +1,482 @@ + $imapDB['premium_host'], + 'port' => $imapDB['premium_port'], + 'encryption' => $imapDB['premium_encryption'], + 'validate_cert' => $imapDB['premium_validate_cert'], + 'username' => $imapDB['premium_username'], + 'password' => $imapDB['premium_password'], + 'default_account' => $imapDB['premium_default_account'], + 'protocol' => $imapDB['premium_protocol'], + 'cc_check' => $imapDB['premium_cc_check'] + ]; + + return ZEmail::connectMailBox($imap); + } + + public static function fetchMessages($email, $type = 'to', $deleted = []): array + { + $allowed = explode(',', 'doc,docx,xls,xlsx,ppt,pptx,xps,pdf,dxf,ai,psd,eps,ps,svg,ttf,zip,rar,tar,gzip,mp3,mpeg,wav,ogg,jpeg,jpg,png,gif,bmp,tif,webm,mpeg4,3gpp,mov,avi,mpegs,wmv,flx,txt'); + $connection = self::connectMailBox(); + + $mailbox = $connection->getMailbox('INBOX'); + $search = new SearchExpression(); + if ($type == 'cc') { + $search->addCondition(new Cc($email)); + } else { + $search->addCondition(new To($email)); + } + $messages = $mailbox->getMessages($search, \SORTDATE, true); + $limit = json_decode(config('app.settings.configuration_settings'))->fetch_messages_limit ?? 15; + $count = 1; + $response = [ + 'data' => [], + 'notifications' => [] + ]; + foreach ($messages as $message) { + if (in_array($message->getNumber(), $deleted)) { + $message->delete(); + continue; + } + $blocked = false; + $sender = $message->getFrom(); + $date = $message->getDate(); + if (!$date) { + $date = new \DateTime(); + if ($message->getHeaders()->get('udate')) { + $date->setTimestamp($message->getHeaders()->get('udate')); + } + } + $datediff = new Carbon($date); + $content = ''; + $contentText = ''; + $html = $message->getBodyHtml(); + $text = $message->getBodyText(); + if ($text) { + $contentText = str_replace('', $text)); + } + if (json_decode(config('app.settings.configuration_settings'))->enable_masking_external_link) { + $content = str_replace('href="', 'href="http://href.li/?', $content); + } + + $obj = []; + $obj['subject'] = $message->getSubject(); + $obj['sender_name'] = $sender->getName(); + $obj['sender_email'] = $sender->getAddress(); + $obj['timestamp'] = $message->getDate(); + $obj['date'] = $date->format(json_decode(config('app.settings.configuration_settings'))->date_format ?? 'd M Y h:i A'); + $obj['datediff'] = $datediff->diffForHumans(); + $obj['id'] = $message->getNumber(); + $obj['content'] = $content; + $obj['contentText'] = $contentText; + $obj['attachments'] = []; + $obj['is_seen'] = true; + $obj['sender_photo'] = self::chooseColor(strtoupper(substr($sender->getName() ?: $sender->getAddress(), 0, 1) )); + + //Checking if Sender is Blocked + $domain = explode('@', $obj['sender_email'])[1]; + $blocked = in_array($domain, json_decode(config('app.settings.configuration_settings'))->blocked_domains); + if ($blocked) { + $obj['subject'] = __('Blocked'); + $obj['content'] = __('Emails from') . ' ' . $domain . ' ' . __('are blocked by Admin'); + $obj['contentText'] = __('Emails from') . ' ' . $domain . ' ' . __('are blocked by Admin'); + } + if ($message->hasAttachments() && !$blocked) { + $attachments = $message->getAttachments(); + $directory = './tmp/premium/attachments/' . $obj['id'] . '/'; + is_dir($directory) || mkdir($directory, 0777, true); + foreach ($attachments as $attachment) { + $filenameArray = explode('.', $attachment->getFilename()); + $extension = $filenameArray[count($filenameArray) - 1]; + if (in_array($extension, $allowed)) { + if (!file_exists($directory . $attachment->getFilename())) { + try { + file_put_contents( + $directory . $attachment->getFilename(), + $attachment->getDecodedContent() + ); + } catch (\Exception $e) { + \Illuminate\Support\Facades\Log::error($e->getMessage()); + } + } + if ($attachment->getFilename() !== 'undefined') { + $url = config('app.settings.app_base_url') . str_replace('./', '/', $directory . $attachment->getFilename()); + $structure = $attachment->getStructure(); + if (isset($structure->id) && str_contains($obj['content'], trim($structure->id, '<>'))) { + $obj['content'] = str_replace('cid:' . trim($structure->id, '<>'), $url, $obj['content']); + } + $obj['attachments'][] = [ + 'file' => $attachment->getFilename(), + 'url' => $url + ]; + } + } + } + } + $response['data'][] = $obj; + if (!$message->isSeen()) { + $response['notifications'][] = [ + 'subject' => $obj['subject'], + 'sender_name' => $obj['sender_name'], + 'sender_email' => $obj['sender_email'] + ]; + if (config('app.zemail_log')) { + file_put_contents(storage_path('logs/zemail.csv'), request()->ip() . "," . date("Y-m-d h:i:s a") . "," . $obj['sender_email'] . "," . $email . PHP_EOL, FILE_APPEND); + } + } + $message->markAsSeen(); + if (++$count > $limit) { + break; + } + } + + $response['data'] = array_reverse($response['data']); + $connection->expunge(); + return $response; + } + + public static function getMessages($email, $type = 'to', $deleted = []): array + { + return self::fetchMessages($email, $type, $deleted); + } + public static function deleteMessage($id): void + { + $connection = self::connectMailBox(); + $mailbox = $connection->getMailbox('INBOX'); + $mailbox->getMessage($id)->delete(); + $connection->expunge(); + } + public static function getEmail($generate = false) { + if (Cookie::has('email')) { + return Cookie::get('email'); + } else { + return $generate ? self::generateRandomEmail() : null; + } + } + public static function getEmails() { + if (Cookie::has('emails')) { + return unserialize(Cookie::get('emails')); + } else { + return []; + } + } + public static function setEmail($email): void + { + $emails = unserialize(Cookie::get('emails')); + if (is_array($emails) && in_array($email, $emails)) { + Cookie::queue('email', $email, 43800); + } + } + public static function removeEmail($email): void + { + $emails = self::getEmails(); + $key = array_search($email, $emails); + if ($key !== false) { + array_splice($emails, $key, 1); + } + if (count($emails) > 0) { + self::setEmail($emails[0]); + Cookie::queue('emails', serialize($emails), 43800); + } else { + Cookie::queue('email', '', -1); + Cookie::queue('emails', serialize([]), -1); + } + } + public static function createCustomEmailFull($email): string + { + $data = explode('@', $email); + $username = $data[0]; + if (strlen($username) < json_decode(config('app.settings.configuration_settings'))->custom_username_length_min || strlen($username) > json_decode(config('app.settings.configuration_settings'))->custom_username_length_max) { + $zemail = new Premium(); + $username = $zemail->generateRandomUsername(); + } + $domain = $data[1]; + return self::createCustomEmail($username, $domain); + } + public static function createCustomEmail($username, $domain): string + { + $username = preg_replace('/[^a-zA-Z0-9+.]/', '', strtolower($username)); + + $settings = json_decode(config('app.settings.configuration_settings'), true); + $forbidden_ids = $settings['forbidden_ids'] ?? []; + $gmail_usernames = $settings['premium_gmailUsernames'] ?? []; + $domains = $settings['premium_domains'] ?? []; + + if (in_array($username, $forbidden_ids)) { + return self::generateRandomEmail(true); + } + + if ($username === '' && in_array($domain, ['gmail.com', 'googlemail.com'])) { + return self::generateRandomGmail(true); + } + + $zemail = new Premium(); + + if ($username === '' && in_array($domain, $domains)) { + return $zemail->generateRandomUsername().'@'.$domain; + } + + + + if (in_array($domain, ['gmail.com', 'googlemail.com'])) { + if (str_contains($username, '+')) { + [$check_username, $post_username] = explode('+', $username, 2); + + if (in_array($check_username, $gmail_usernames)) { + $email = $username . '@' . $domain; + } else { + $email = $zemail->getRandomGmailUser() . '+' . $post_username . '@' . $domain; + } + + } elseif (str_contains($username, '.')) { + $check_username = str_replace('.', '', $username); + + if (in_array($check_username, $gmail_usernames)) { + $email = $username . '@' . $domain; + } else { + $email = $zemail->generateRandomGmail() . '@' . $domain; + } + + } else { + $email = $zemail->getRandomGmailUser() . '+' . $username . '@' . $domain; + } + + self::storeEmail($email); + return $email; + } + + // Handle other custom domains + if (!in_array($domain, $domains)) { + return self::generateRandomEmail(true); + } + + $finalDomain = in_array($domain, $domains) ? $domain : ($domains[0] ?? 'example.com'); + $email = $username . '@' . $finalDomain; + + self::storeEmail($email); + return $email; + } + public static function generateRandomEmail($store = true): string + { + $zemail = new Premium(); + $domain = $zemail->getRandomDomain(); + if ($domain == "gmail.com") { + $rd = mt_rand(0,1); + if ($rd == 0) { + $email = $zemail->generateRandomGmail(); + } else { + $email = $zemail->getRandomGmailUser().'+'.$zemail->generateRandomUsername().'@gmail.com'; + } + } elseif ($domain == "googlemail.com") { + $rd = mt_rand(0,1); + if ($rd == 0) { + $email = $zemail->generateRandomGmail(); + } else { + $email = $zemail->getRandomGmailUser().'+'.$zemail->generateRandomUsername().'@googlemail.com'; + } + } else { + $email = $zemail->generateRandomUsername() . '@' . $domain; + } + if ($store) { + self::storeEmail($email); + } + return $email; + } + public static function generateRandomGmail($store = true): string + { + $zemail = new Premium(); + $uname = $zemail->getRandomGmailUser(); + $uname_len = strlen($uname); + $len_power = $uname_len - 1; + $combination = pow(2,$len_power); + $rand_comb = mt_rand(1,$combination); + $formatted = implode(' ',str_split($uname)); + $uname_exp = explode(' ', $formatted); + + $bin = intval(""); + for($i=0; $i<$len_power; $i++) { + $bin .= mt_rand(0,1); + } + $bin = explode(' ', implode(' ',str_split(strval($bin)))); + + $email = ""; + for($i=0; $i<$len_power; $i++) { + $email .= $uname_exp[$i]; + if($bin[$i]) { + $email .= "."; + } + } + $email .= $uname_exp[$i]; + $gmail_rand = mt_rand(1,10); + if($gmail_rand > 5) { + $email .= "@gmail.com"; + } else { + $email .= "@googlemail.com"; + } + if ($store) { + self::storeEmail($email); + } + return $email; + } + private static function storeEmail($email): void + { + Log::create([ + 'user_id' => auth()->user()->id, + 'ip' => request()->ip(), + 'email' => $email + ]); + + self::storeUsageLog($email); + + Cookie::queue('email', $email, 43800); + $emails = Cookie::has('emails') ? unserialize(Cookie::get('emails')) : []; + if (!in_array($email, $emails)) { + self::incrementEmailStats(); + $emails[] = $email; + Cookie::queue('emails', serialize($emails), 43800); + } + } + public static function incrementEmailStats($count = 1): void + { + Meta::incrementEmailIdsCreated($count); + self::incrementEmailIdsCreated($count); + } + public static function incrementMessagesStats($count = 1): void + { + Meta::incrementMessagesReceived($count); + self::incrementMessagesReceived($count); + } + private function generateRandomUsername(): string + { + $start = json_decode(config('app.settings.configuration_settings'))->random_username_length_min ?? 0; + $end = json_decode(config('app.settings.configuration_settings'))->random_username_length_max ?? 0; + if ($start == 0 && $end == 0) { + return $this->generatePronounceableWord(); + } + return $this->generatedRandomBetweenLength($start, $end); + } + protected function generatedRandomBetweenLength($start, $end): string + { + $length = rand($start, $end); + return $this->generateRandomString($length); + } + private function getRandomDomain() { + $domains = json_decode(config('app.settings.configuration_settings'))->premium_domains ?? []; + $count = count($domains); + return $count > 0 ? $domains[rand(1, $count) - 1] : ''; + } + private function getRandomGmailUser() { + $gmailusername = json_decode(config('app.settings.configuration_settings'))->premium_gmailUsernames ?? []; + $count = count($gmailusername); + return $count > 0 ? $gmailusername[rand(1, $count) - 1] : ''; + } + private function generatePronounceableWord(): string + { + $c = 'bcdfghjklmnprstvwz'; //consonants except hard to speak ones + $v = 'aeiou'; //vowels + $a = $c . $v; //both + $random = ''; + for ($j = 0; $j < 2; $j++) { + $random .= $c[rand(0, strlen($c) - 1)]; + $random .= $v[rand(0, strlen($v) - 1)]; + $random .= $a[rand(0, strlen($a) - 1)]; + } + return $random; + } + private function generateRandomString($length = 10): string + { + $characters = '0123456789abcdefghijklmnopqrstuvwxyz'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + /** + * Stats Handling Functions + */ + + + public static function incrementEmailIdsCreated($count = 1): void + { + $user = Auth::user(); + if (!$user) { + return; + } + + $usageLog = UsageLog::firstOrCreate( + ['user_id' => $user->id], + ['ip_address' => request()->ip()] + ); + + $usageLog->increment('emails_created_count', $count); + } + + public static function incrementMessagesReceived($count = 1): void + { + $user = Auth::user(); + if (!$user) { + return; + } + + $usageLog = UsageLog::firstOrCreate( + ['user_id' => $user->id], + ['ip_address' => request()->ip()] + ); + + $usageLog->increment('emails_received_count', $count); + } + + public static function storeUsageLog($email): void + { + try { + $user = Auth::user(); + if (!$user) { + return; + } + + $ip = request()->ip(); + $usageLog = UsageLog::firstOrCreate( + ['user_id' => $user->id], + ['ip_address' => $ip] + ); + + $history = $usageLog->emails_created_history ?? []; + if (!in_array($email, $history)) { + $history[] = $email; + //$usageLog->emails_created_count += 1; + $usageLog->emails_created_history = $history; + $usageLog->save(); + } + } catch (\Exception $exception) { + \Log::error($exception->getMessage()); + } + + } +} diff --git a/app/Models/UsageLog.php b/app/Models/UsageLog.php new file mode 100644 index 0000000..5d8d9e6 --- /dev/null +++ b/app/Models/UsageLog.php @@ -0,0 +1,23 @@ + 'array', + 'emails_received_history' => 'array', + ]; + +} diff --git a/app/Models/ZEmail.php b/app/Models/ZEmail.php index 577c082..184ef5b 100644 --- a/app/Models/ZEmail.php +++ b/app/Models/ZEmail.php @@ -318,100 +318,3 @@ class ZEmail extends Model } } - - -// public static function createCustomEmail($username, $domain): string -// { -// $username = str_replace('[^a-zA-Z0-9]', '', strtolower($username)); -// $forbidden_ids = json_decode(config('app.settings.configuration_settings'))->forbidden_ids ?? []; -// $gmail_usernames = json_decode(config('app.settings.configuration_settings'))->gmailUsernames ?? []; -// if (in_array($username, $forbidden_ids)) { -// return ZEmail::generateRandomEmail(true); -// } -// $zemail = new ZEmail(); -// if($domain == "gmail.com") { -// -// if(str_contains($username, "+")){ -// $check_username = explode("+", $username)[0]; -// $post_username = explode("+", $username)[1]; -// if (in_array($check_username, $gmail_usernames)) { -// $email = $username . '@gmail.com'; -// ZEmail::storeEmail($email); -// return $email; -// } else { -// -// $email = $zemail->getRandomGmailUser().'+'.$post_username.'@gmail.com'; -// ZEmail::storeEmail($email); -// return $email; -// } -// } -// elseif(str_contains($username, ".")){ -// $check_username = str_replace(".","",$username); -// -// if (in_array($check_username, $gmail_usernames)) { -// $email = $username . '@gmail.com'; -// ZEmail::storeEmail($email); -// return $email; -// } else { -// -// $email = $zemail->generateRandomGmail(); -// ZEmail::storeEmail($email); -// return $email; -// } -// -// } -// else { -// -// $email = $zemail->getRandomGmailUser().'+'.$username.'@gmail.com'; -// ZEmail::storeEmail($email); -// return $email; -// } -// } elseif($domain == "googlemail.com") { -// if(str_contains($username, "+")){ -// $check_username = explode("+", $username)[0]; -// $post_username = explode("+", $username)[1]; -// -// if (in_array($check_username, $gmail_usernames)) { -// $email = $username . '@googlemail.com'; -// ZEmail::storeEmail($email); -// return $email; -// } else { -// -// $email = $zemail->getRandomGmailUser().'+'.$post_username.'@googlemail.com'; -// ZEmail::storeEmail($email); -// return $email; -// } -// } -// elseif(str_contains($username, ".")){ -// $check_username = str_replace(".","",$username); -// -// if (in_array($check_username, $gmail_usernames)) { -// $email = $username . '@googlemail.com'; -// ZEmail::storeEmail($email); -// return $email; -// } else { -// -// $email = $zemail->generateRandomGmail(); -// ZEmail::storeEmail($email); -// return $email; -// } -// } -// else { -// $email = $zemail->getRandomGmailUser().'+'.$username.'@googlemail.com'; -// ZEmail::storeEmail($email); -// return $email; -// } -// } else { -// $domains = json_decode(config('app.settings.configuration_settings'))->domains ?? []; -// if (in_array($domain, $domains)) { -// $email = $username . '@' . $domain; -// ZEmail::storeEmail($email); -// return $email; -// } else { -// $email = $username . '@' . $domains[0]; -// ZEmail::storeEmail($email); -// return $email; -// } -// -// } -// } diff --git a/database/migrations/2025_05_02_215351_create_plans_table.php b/database/migrations/2025_05_02_215351_create_plans_table.php index f0f4ce0..a84ea17 100644 --- a/database/migrations/2025_05_02_215351_create_plans_table.php +++ b/database/migrations/2025_05_02_215351_create_plans_table.php @@ -18,6 +18,7 @@ return new class extends Migration $table->string('product_id')->collation('utf8_bin'); $table->string('pricing_id')->collation('utf8_bin'); $table->integer('price'); + $table->integer('mailbox_limit')->default(15); $table->boolean('monthly_billing')->default(true); $table->longText('details')->nullable(); $table->timestamps(); diff --git a/database/migrations/2025_05_03_082522_create_usage_logs_table.php b/database/migrations/2025_05_03_082522_create_usage_logs_table.php new file mode 100644 index 0000000..2221f5b --- /dev/null +++ b/database/migrations/2025_05_03_082522_create_usage_logs_table.php @@ -0,0 +1,36 @@ +bigIncrements('id'); + $table->unsignedBigInteger('user_id'); + $table->ipAddress('ip_address'); + $table->integer('emails_created_count')->default(0); + $table->integer('emails_received_count')->default(0); + $table->json('emails_created_history')->nullable(); + $table->json('emails_received_history')->nullable(); + $table->timestamps(); + + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('usage_logs'); + } +}; diff --git a/database/migrations/2025_05_03_200503_add_user_id_to_logs_table.php b/database/migrations/2025_05_03_200503_add_user_id_to_logs_table.php new file mode 100644 index 0000000..1436082 --- /dev/null +++ b/database/migrations/2025_05_03_200503_add_user_id_to_logs_table.php @@ -0,0 +1,30 @@ +unsignedBigInteger('user_id')->nullable()->after('id'); + $table->foreign('user_id')->references('id')->on('users'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('logs', function (Blueprint $table) { + $table->dropForeign(['user_id']); + $table->dropColumn('user_id'); + }); + } +}; diff --git a/resources/views/components/layouts/dashboard.blade.php b/resources/views/components/layouts/dashboard.blade.php index 782d609..69d50e8 100644 --- a/resources/views/components/layouts/dashboard.blade.php +++ b/resources/views/components/layouts/dashboard.blade.php @@ -101,8 +101,6 @@ -

© 2020–{{ date('Y') }} – All Rights Reserved {{ config('app.settings.app_name') }} | Coded with ♥️

- @@ -150,16 +148,6 @@ @fluxScripts