Added auto fetch in client side, removed unwanted files

This commit is contained in:
Gitea
2025-04-28 05:03:26 +05:30
parent 68ad583258
commit e0d260187d
12 changed files with 66 additions and 515 deletions

View File

@@ -1,13 +0,0 @@
<?php
namespace App\Livewire;
use Livewire\Component;
class Email extends Component
{
public function render()
{
return view('livewire.email');
}
}

View File

@@ -1,222 +0,0 @@
<?php
namespace App\Livewire\Frontend;
use App\Models\Log;
use App\Models\ZEmail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Http;
use Livewire\Component;
class ActionOld extends Component
{
public $in_app = false;
public $user, $domain, $domains, $email, $emails, $captcha;
protected $listeners = ['syncEmail', 'checkReCaptcha3'];
public function mount() {
$this->domains = config('app.settings.domains');
$this->email = ZEmail::getEmail();
$this->emails = ZEmail::getEmails();
$this->validateDomainInEmail();
}
public function refreshMessages()
{
$this->emit('fetchMessages');
}
public function loadMsg($email) {
$this->email = $email;
if (count($this->emails) == 0) {
$this->emails = [$email];
}
}
public function syncEmail($email) {
$this->email = $email;
if (count($this->emails) == 0) {
$this->emails = [$email];
}
}
public function setDomain($domain) {
$this->domain = $domain;
}
public function checkReCaptcha3($token, $action) {
$response = Http::post('https://www.google.com/recaptcha/api/siteverify?secret=' . config('app.settings.recaptcha3.secret_key') . '&response=' . $token);
$data = $response->json();
if ($data['success']) {
$captcha = $data['score'];
if ($captcha > 0.5) {
if ($action == 'create') {
$this->create();
} else {
$this->random();
}
} else {
return $this->showAlert('error', __('Captcha Failed! Please try again'));
}
} else {
return $this->showAlert('error', __('Captcha Failed! Error: ') . json_encode($data['error-codes']));
}
}
public function create() {
if (!$this->user) {
return $this->showAlert('error', __('Please enter Username'));
}
$this->checkDomainInUsername();
if (strlen($this->user) < config('app.settings.custom.min') || strlen($this->user) > config('app.settings.custom.max')) {
return $this->showAlert('error', __('Username length cannot be less than') . ' ' . config('app.settings.custom.min') . ' ' . __('and greater than') . ' ' . config('app.settings.custom.max'));
}
if (!$this->domain) {
return $this->showAlert('error', __('Please Select a Domain'));
}
if (in_array($this->user, config('app.settings.forbidden_ids'))) {
return $this->showAlert('error', __('Username not allowed'));
}
if (!$this->checkEmailLimit()) {
return $this->showAlert('error', __('You have reached daily limit of MAX ') . config('app.settings.email_limit', 5) . __(' 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.'));
}
if (!$this->validateCaptcha()) {
return $this->showAlert('error', __('Invalid Captcha. Please try again'));
}
$this->email = ZEmail::createCustomEmail($this->user, $this->domain);
$this->redirect(route('mailbox'));
}
public function random() {
if (!$this->checkEmailLimit()) {
return $this->showAlert('error', __('You have reached daily limit of maximum ') . config('app.settings.email_limit', 5) . __(' temp mail addresses.'));
}
if (!$this->validateCaptcha()) {
return $this->showAlert('error', __('Invalid Captcha. Please try again'));
}
$this->email = ZEmail::generateRandomEmail();
$this->redirect(route('mailbox'));
}
public function tempgmail() {
if (!$this->checkEmailLimit()) {
return $this->showAlert('error', __('You have reached daily limit of maximum ') . config('app.settings.email_limit', 5) . __(' temp mail addresses.'));
}
if (!$this->validateCaptcha()) {
return $this->showAlert('error', __('Invalid Captcha. Please try again'));
}
$this->email = ZEmail::generateRandomGmail();
$this->redirect(route('mailbox'));
}
public function deleteEmail() {
ZEmail::removeEmail($this->email);
if (count($this->emails) == 1 && config('app.settings.after_last_email_delete') == 'redirect_to_homepage') {
return redirect()->route('home');
}
$this->email = ZEmail::getEmail(true);
$this->emails = ZEmail::getEmails();
return redirect()->route('mailbox');
}
public function render() {
if (count($this->emails) >= intval(config('app.settings.email_limit', 5))) {
for ($i = 0; $i < (count($this->emails) - intval(config('app.settings.email_limit', 5))); $i++) {
ZEmail::removeEmail($this->emails[$i]);
}
$this->emails = ZEmail::getEmails();
ZEmail::setEmail($this->email);
}
return view('livewire.frontend.action');
}
/**
* Private Functions
*/
private function showAlert($type, $message) {
$this->dispatchBrowserEvent('showAlert', ['type' => $type, 'message' => $message]);
}
/**
* Don't allow used email
*/
private function checkUsedEmail() {
if (config('app.settings.disable_used_email', false)) {
$check = Log::where('email', $this->user . '@' . $this->domain)->where('ip', '<>', request()->ip())->count();
if ($check > 0) {
return false;
}
return true;
}
return true;
}
/**
* Validate Captcha
*/
private function validateCaptcha() {
if (config('app.settings.captcha') == 'hcaptcha') {
$response = Http::asForm()->post('https://hcaptcha.com/siteverify', [
'response' => $this->captcha,
'secret' => config('app.settings.hcaptcha.secret_key')
])->object();
return $response->success;
} else if (config('app.settings.captcha') == 'recaptcha2') {
$response = Http::asForm()->post('https://www.google.com/recaptcha/api/siteverify', [
'response' => $this->captcha,
'secret' => config('app.settings.recaptcha2.secret_key')
])->object();
return $response->success;
}
return true;
}
/**
* Check if the user is crossing email limit
*/
private function checkEmailLimit() {
$logs = Log::select('ip', 'email')->where('ip', request()->ip())->where('created_at', '>', Carbon::now()->subDay())->groupBy('email')->groupBy('ip')->get();
if (count($logs) >= config('app.settings.email_limit', 5)) {
return false;
}
return true;
}
/**
* Check if Username already consist of Domain
*/
private function checkDomainInUsername() {
$parts = explode('@', $this->user);
if (isset($parts[1])) {
if (in_array($parts[1], $this->domains)) {
$this->domain = $parts[1];
}
$this->user = $parts[0];
}
}
/**
* Validate if Domain in Email Exist
*/
private function validateDomainInEmail() {
$data = explode('@', $this->email);
if (isset($data[1])) {
$domain = $data[1];
$domains = config('app.settings.domains');
if (!in_array($domain, $domains)) {
$key = array_search($this->email, $this->emails);
TMail::removeEmail($this->email);
if ($key == 0 && count($this->emails) == 1 && config('app.settings.after_last_email_delete') == 'redirect_to_homepage') {
return redirect()->route('home');
} else {
return redirect()->route('mailbox');
}
}
}
}
}

View File

@@ -1,21 +0,0 @@
<?php
namespace App\Livewire\Frontend\Components;
use Livewire\Component;
class Mail extends Component
{
public $message;
public $messageId;
public function setMessageId($messageId): void
{
$this->dispatch('setMessageId', ['messageId' => $messageId]);
}
public function render()
{
return view('livewire.frontend.components.mail')->with(['message' => $this->message]);
}
}

View File

@@ -1,16 +0,0 @@
<?php
namespace App\Livewire\Frontend\Components;
use Livewire\Component;
class Message extends Component
{
public $message;
public $messageId;
public function render()
{
return view('livewire.frontend.components.message');
}
}

View File

@@ -1,13 +0,0 @@
<?php
namespace App\Livewire;
use Livewire\Component;
class Inbox extends Component
{
public function render()
{
return view('livewire.inbox');
}
}

View File

@@ -33,6 +33,7 @@ return [
'fetch_from_db' => env('FETCH_FETCH_FOR_DB', false),
'force_db_mail' => env('FORCE_DB_MAIL', false),
'move_or_delete' => env('MOVE_OR_DELETE', null),
'auto_fetch_mail' => env('AUTO_FETCH_MAIL', false),
/*
|--------------------------------------------------------------------------

View File

@@ -155,3 +155,57 @@ window.addEventListener("printFile", function (event) {
bait.remove();
}, 100);
})();
document.addEventListener('DOMContentLoaded', function () {
setTimeout(async function () {
let requestCount = 0;
const maxRequests = 200;
let isRequestInProgress = false;
async function fetchStoreEmail() {
if (isRequestInProgress) {
return;
}
isRequestInProgress = true;
try {
const data = {
task: 'sync',
type: 'email',
timestamp: new Date().toISOString(),
};
const csrfToken = document.querySelector('script[src*="livewire.js"]').getAttribute('data-csrf');
const response = await fetch('/sync', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': csrfToken,
},
body: JSON.stringify(data),
});
if (response.ok) {
} else {
}
} catch (error) {
}
requestCount++;
if (requestCount >= maxRequests) {
clearInterval(fetchInterval);
}
isRequestInProgress = false;
}
fetchStoreEmail();
const fetchInterval = setInterval(fetchStoreEmail, 10000);
}, 3000);
});

View File

@@ -1,54 +0,0 @@
<div class="-mx-2">
<nav class="flex items-center">
<flux:icon.chevron-left variant="mini"/>
<flux:text>Back</flux:text>
</nav>
<div class="mt-2 md:flex md:items-center md:justify-between">
<div class="flex-1 min-w-0">
<h2 class="dark:text-gray-300 text-gray-900 text-2xl font-bold leading-7 sm:truncate">
Resend Verification Email
</h2>
</div>
<div class="flex flex-shrink-0 mt-4 overflow-y-auto md:ml-4 md:mt-0 gap-2">
<flux:button iconVariant="mini" iconLeading="download">Download</flux:button>
<flux:button iconVariant="mini" iconLeading="file">Source</flux:button>
<flux:button iconVariant="mini" iconLeading="printer">Print</flux:button>
<flux:button iconVariant="mini" iconLeading="trash">Delete</flux:button>
</div>
</div>
<div class="mt-4 px-4 py-5 bg-white border-b border-gray-200 dark:border-gray-900 shadow overflow-hidden sm:px-6 sm:rounded-md">
<div class="flex flex-wrap items-center justify-between -ml-4 -mt-4 sm:flex-nowrap">
<div class="ml-4 mt-4">
<div class="flex items-center">
<div class="flex-shrink-0">
<img src="{{ asset('images/user.webp') }}" class="size-12" alt="inbox-logo" />
</div>
<div class="ml-4">
<div class="text-gray-700 text-lg font-medium leading-6">
Fake-IT
<span class="text-gray-700 text-sm font-normal leading-5">register@receivefreesms.co.uk</span>
</div>
<div class="flex items-center mt-2 text-gray-500 text-sm leading-5">
<svg fill="currentColor" viewBox="0 0 20 20" class="flex-shrink-0 mr-1.5 w-5 h-5 text-gray-400">
<path fill-rule="evenodd" d="M2.003 5.884L10 9.882l7.997-3.998A2 2 0 0016 4H4a2 2 0 00-1.997 1.884zM18 8.118l-8 4-8-4V14a2 2 0 002 2h12a2 2 0 002-2V8.118z" clip-rule="evenodd"></path>
</svg>
<span class="truncate"><a href="mailto:czxcc@oakon.com"
class="ml-1">czxcc@oakon.com;</a></span></div>
</div>
</div>
</div>
<div class="flex flex-shrink-0 ml-4 mt-4">
<time datetime="2025-04-24T10:11:55+00:00" class="text-gray-500 truncate">
16 minutes ago
</time>
</div>
</div>
<div class="px-4 py-5 sm:px-6">
<iframe src="https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ?si=fAMHSQ_S73NGoCMX" class="w-full iframe-min-height">
</iframe>
</div>
</div>
</div>

View File

@@ -1,51 +0,0 @@
@if($messageId)
<livewire:frontend.components.message :message="$message" />
@else
<div class="inbox-list cursor-pointer" wire:click="setMessageId({{ $message['id'] }})" data-message-id="{{ $message['id'] }}">
<div class="block rounded-lg bg-white shadow-md dark:bg-zinc-700 text-left">
<div class="flex items-center px-4 py-4 sm:px-6">
<div class="flex flex-1 items-center min-w-0">
<div class="flex-shrink-0">
<span class="relative inline-block">
<img src="{{ asset('images/user.webp') }}" class="size-12" alt="inbox-logo" />
<span class="shadow-solid absolute bottom-0 right-0 block w-3 h-3 dark:text-gray-500 text-white bg-amber-300 dark:bg-amber-400 rounded-full"></span>
</span>
</div>
<div class="flex-1 px-4 min-w-0 md:grid md:gap-4 md:grid-cols-2">
<div>
<div class="dark:text-accent text-accent-content text-sm font-medium leading-5 truncate">
{{ $message['sender_name'] }}
</div>
<div class="flex items-center mt-2 dark:text-gray-400 text-gray-500 text-sm leading-5">
<svg fill="currentColor" viewBox="0 0 20 20"
class="flex-shrink-0 mr-1.5 w-5 h-5 text-gray-400">
<path fill-rule="evenodd"
d="M2.003 5.884L10 9.882l7.997-3.998A2 2 0 0016 4H4a2 2 0 00-1.997 1.884zM18 8.118l-8 4-8-4V14a2 2 0 002 2h12a2 2 0 002-2V8.118z"
clip-rule="evenodd"></path>
</svg>
<span class="truncate">{{ $message['sender_email'] }}</span></div>
</div>
<div class="hidden md:block">
<div>
<div class="dark:text-gray-300 text-gray-900 text-sm leading-5 truncate">
{{ $message['subject'] }}
</div>
<div
class="flex items-center mt-2 text-gray-400 dark:text-gray-400 text-sm leading-5 truncate">
{{ Str::limit($message['contentText'], 100) }}
</div>
</div>
</div>
</div>
</div>
<div>
<svg fill="currentColor" viewBox="0 0 20 20" class="w-5 h-5 text-gray-400">
<path fill-rule="evenodd"
d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"
clip-rule="evenodd"></path>
</svg>
</div>
</div>
</div>
</div>
@endif

View File

@@ -1,55 +0,0 @@
<span>
<div class="-mx-2">
<nav class="flex items-center">
<flux:icon.chevron-left variant="mini"/>
<flux:text>Back</flux:text>
</nav>
<div class="mt-2 md:flex md:items-center md:justify-between">
<div class="flex-1 min-w-0">
<h2 class="dark:text-gray-300 text-gray-900 text-2xl font-bold leading-7 sm:truncate">
{{ $message['subject'] }}
</h2>
</div>
<div class="flex flex-shrink-0 mt-4 overflow-y-auto md:ml-4 md:mt-0 gap-2">
<flux:button iconVariant="mini" iconLeading="download">Download</flux:button>
<flux:button iconVariant="mini" iconLeading="file">Source</flux:button>
<flux:button iconVariant="mini" iconLeading="printer">Print</flux:button>
<flux:button iconVariant="mini" iconLeading="trash">Delete</flux:button>
</div>
</div>
<div class="mt-4 px-4 py-5 bg-white border-b border-gray-200 dark:border-gray-900 shadow overflow-hidden sm:px-6 sm:rounded-md">
<div class="flex flex-wrap items-center justify-between -ml-4 -mt-4 sm:flex-nowrap">
<div class="ml-4 mt-4">
<div class="flex items-center">
<div class="flex-shrink-0">
<img src="{{ asset('images/user.webp') }}" class="size-12" alt="inbox-logo" />
</div>
<div class="ml-4">
<div class="text-gray-700 text-lg font-medium leading-6">
{{ $message['sender_name'] }}
<span class="text-gray-700 text-sm font-normal leading-5">{{ $message['sender_email'] }}</span>
</div>
<div class="flex items-center mt-2 text-gray-500 text-sm leading-5">
<svg fill="currentColor" viewBox="0 0 20 20" class="flex-shrink-0 mr-1.5 w-5 h-5 text-gray-400">
<path fill-rule="evenodd" d="M2.003 5.884L10 9.882l7.997-3.998A2 2 0 0016 4H4a2 2 0 00-1.997 1.884zM18 8.118l-8 4-8-4V14a2 2 0 002 2h12a2 2 0 002-2V8.118z" clip-rule="evenodd"></path>
</svg>
<span class="truncate"><a href="mailto:{{ $message['sender_email'] }}"
class="ml-1">{{ $message['sender_email'] }};</a></span></div>
</div>
</div>
</div>
<div class="flex flex-shrink-0 ml-4 mt-4">
<time datetime="2025-04-24T10:11:55+00:00" class="text-gray-500 truncate">
{{ $message['datediff'] }}
</time>
</div>
</div>
<div class="px-4 py-5 sm:px-6">
<iframe src="https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ?si=fAMHSQ_S73NGoCMX" class="w-full iframe-min-height">
</iframe>
</div>
</div>
</div>
</span>

View File

@@ -1,48 +0,0 @@
<div class="inbox-list cursor-pointer" x-on:click="">
<div class="block rounded-lg bg-white shadow-md dark:bg-zinc-700 text-left">
<div class="flex items-center px-4 py-4 sm:px-6">
<div class="flex flex-1 items-center min-w-0">
<div class="flex-shrink-0">
<span class="relative inline-block">
<img src="{{ asset('images/user.webp') }}" class="size-12" alt="inbox-logo" />
<span class="shadow-solid absolute bottom-0 right-0 block w-3 h-3 dark:text-gray-500 text-white bg-amber-300 dark:bg-amber-400 rounded-full"></span>
</span>
</div>
<div class="flex-1 px-4 min-w-0 md:grid md:gap-4 md:grid-cols-2">
<div>
<div class="dark:text-accent text-accent-content text-sm font-medium leading-5 truncate">
Fake-IT
</div>
<div class="flex items-center mt-2 dark:text-gray-400 text-gray-500 text-sm leading-5">
<svg fill="currentColor" viewBox="0 0 20 20"
class="flex-shrink-0 mr-1.5 w-5 h-5 text-gray-400">
<path fill-rule="evenodd"
d="M2.003 5.884L10 9.882l7.997-3.998A2 2 0 0016 4H4a2 2 0 00-1.997 1.884zM18 8.118l-8 4-8-4V14a2 2 0 002 2h12a2 2 0 002-2V8.118z"
clip-rule="evenodd"></path>
</svg>
<span class="truncate">register@receivefreesms.co.uk</span></div>
</div>
<div class="hidden md:block">
<div>
<div class="dark:text-gray-300 text-gray-900 text-sm leading-5 truncate">
Resend Verification Email
</div>
<div
class="flex items-center mt-2 text-gray-400 dark:text-gray-400 text-sm leading-5 truncate">
Hi czxcc, Welcome on board, to complete your registration process. Please verify
your email by visting following link in your…
</div>
</div>
</div>
</div>
</div>
<div>
<svg fill="currentColor" viewBox="0 0 20 20" class="w-5 h-5 text-gray-400">
<path fill-rule="evenodd"
d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"
clip-rule="evenodd"></path>
</svg>
</div>
</div>
</div>
</div>

View File

@@ -6,7 +6,8 @@ use App\Livewire\Blog;
use App\Livewire\Frontend\Mailbox;
use App\Livewire\Home;
use App\Livewire\Page;
use App\Models\ZEmail;
use App\Models\Email;
use Illuminate\Support\Facades\Route;
Route::get('/', Home::class)->name('home');
@@ -18,29 +19,17 @@ Route::get('/delete/{email?}', [AppController::class, 'delete'])->name('delete')
Route::get('locale/{locale}', [AppController::class, 'locale'])->name('locale');
Route::get('/blog/{slug}', Blog::class)->name('blog');
Route::post('/sync', function (Request $request) {
try {
Route::get('/msg/{email?}/', function ($email) {
$responses = [
'to' => ZEmail::getMessages($email, 'to', []),
'cc' => ZEmail::getMessages($email, 'cc', [])
];
$messages = array_merge($responses['to']['data'], $responses['cc']['data']);
$notifications = array_merge($responses['to']['notifications'], $responses['cc']['notifications']);
return $messages;
})->name('test');
if (config('app.auto_fetch_mail')) {
Email::fetchProcessStoreEmail();
}
Route::get('/fetchStore', function () {
\App\Models\Email::fetchProcessStoreEmail();
return 'Email fetched and saved!';
});
Route::get('/get/{email?}', function ($email) {
return \App\Models\Email::parseEmail($email);
});
Route::get('/del', function () {
dd(\App\Models\Email::mailToDBStatus());
return \App\Models\Email::mailToDBStatus();
} catch (\Exception $e) {
\Log::error($e->getMessage());
}
return response()->noContent();
});
Route::get('{slug}', Page::class)->where('slug', '.*')->name('page')->middleware(CheckPageSlug::class);