Added Create Custom, Random, Gmail Generation
This commit is contained in:
134
app/Livewire/Frontend/Action.php
Normal file
134
app/Livewire/Frontend/Action.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Frontend;
|
||||
|
||||
use App\Models\Log;
|
||||
use App\Models\ZEmail;
|
||||
use Carbon\Carbon;
|
||||
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();
|
||||
$this->emails = ZEmail::getEmails();
|
||||
$this->validateDomainInEmail();
|
||||
}
|
||||
|
||||
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 ') . json_decode(config('app.settings.configuration_settings'))->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 = ZEmail::createCustomEmail($this->username, $this->domain);
|
||||
$this->dispatch('updateEmail');
|
||||
$this->dispatch('closeModal');
|
||||
|
||||
}
|
||||
public function random() {
|
||||
if (!$this->checkEmailLimit()) {
|
||||
return $this->showAlert('error', __('You have reached daily limit of maximum ') . json_decode(config('app.settings.configuration_settings'))->email_limit . __(' temp mail addresses.'));
|
||||
}
|
||||
$this->email = ZEmail::generateRandomEmail();
|
||||
$this->dispatch('updateEmail');
|
||||
$this->dispatch('closeModal');
|
||||
|
||||
//$this->redirect(route('mailbox'));
|
||||
}
|
||||
|
||||
public function gmail() {
|
||||
if (!$this->checkEmailLimit()) {
|
||||
return $this->showAlert('error', __('You have reached daily limit of maximum ') . json_decode(config('app.settings.configuration_settings'))->email_limit . __(' temp mail addresses.'));
|
||||
}
|
||||
$this->email = ZEmail::generateRandomGmail();
|
||||
$this->dispatch('updateEmail');
|
||||
$this->dispatch('closeModal');
|
||||
}
|
||||
|
||||
public function deleteEmail() {
|
||||
ZEmail::removeEmail($this->email);
|
||||
// if (count($this->emails) <= 1 && json_decode(config('app.settings.configuration_settings'))->after_last_email_delete == 'redirect_to_homepage') {
|
||||
// return redirect()->route('home');
|
||||
// }
|
||||
$this->email = ZEmail::getEmail(true);
|
||||
$this->emails = ZEmail::getEmails();
|
||||
|
||||
$this->dispatch('updateEmail');
|
||||
$this->dispatch('closeModal');
|
||||
}
|
||||
|
||||
private function showAlert($type, $message): void
|
||||
{
|
||||
$this->dispatch('showAlert', ['type' => $type, 'message' => $message]);
|
||||
}
|
||||
|
||||
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) >= json_decode(config('app.settings.configuration_settings'))->email_limit) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private function checkUsedEmail() {
|
||||
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() {
|
||||
$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'))->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(config('app.settings.configuration_settings'))->after_last_email_delete == 'redirect_to_homepage') {
|
||||
redirect()->route('home');
|
||||
} else {
|
||||
redirect()->route('mailbox');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public function render() {
|
||||
return view('livewire.frontend.action');
|
||||
}
|
||||
}
|
||||
222
app/Livewire/Frontend/ActionOld.php
Normal file
222
app/Livewire/Frontend/ActionOld.php
Normal file
@@ -0,0 +1,222 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
109
app/Livewire/Frontend/App.php
Normal file
109
app/Livewire/Frontend/App.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Frontend;
|
||||
|
||||
use App\Models\Message;
|
||||
use App\Models\ZEmail;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Component;
|
||||
|
||||
class App extends Component
|
||||
{
|
||||
public $messages = [];
|
||||
public $deleted = [];
|
||||
public $error = '';
|
||||
public $email;
|
||||
public $initial;
|
||||
public $overflow = false;
|
||||
|
||||
protected $listeners = ['fetchMessages' => 'fetch', 'syncEmail'];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->email = ZEmail::getEmails();
|
||||
$this->initial = false;
|
||||
}
|
||||
|
||||
public function syncEmail($email) {
|
||||
$this->email = $email;
|
||||
}
|
||||
|
||||
public function fetch() {
|
||||
try {
|
||||
$count = count($this->messages);
|
||||
$responses = [];
|
||||
if (config('app.beta_feature') || !json_decode(config('app.settings.imap_settings'))->cc_check) {
|
||||
$responses = [
|
||||
'to' => ZEmail::getMessages($this->email, 'to', $this->deleted),
|
||||
'cc' => [
|
||||
'data' => [],
|
||||
'notifications' => []
|
||||
]
|
||||
];
|
||||
} else {
|
||||
$responses = [
|
||||
'to' => ZEmail::getMessages($this->email, 'to', $this->deleted),
|
||||
'cc' => ZEmail::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 == false && count($this->messages) == $count) {
|
||||
$this->overflow = true;
|
||||
}
|
||||
} else {
|
||||
$this->overflow = false;
|
||||
}
|
||||
foreach ($notifications as $notification) {
|
||||
$this->dispatchBrowserEvent('showNewMailNotification', $notification);
|
||||
}
|
||||
ZEmail::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->dispatchBrowserEvent('stopLoader');
|
||||
$this->dispatchBrowserEvent('loadDownload');
|
||||
$this->initial = true;
|
||||
}
|
||||
|
||||
public function delete($messageId) {
|
||||
if (config('app.beta_feature')) {
|
||||
Message::find($messageId)->delete();
|
||||
}
|
||||
$this->deleted[] = $messageId;
|
||||
foreach ($this->messages as $key => $message) {
|
||||
if ($message['id'] == $messageId) {
|
||||
$directory = './tmp/attachments/' . $messageId;
|
||||
$this->rrmdir($directory);
|
||||
unset($this->messages[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.frontend.app');
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
65
app/Livewire/Frontend/Email.php
Normal file
65
app/Livewire/Frontend/Email.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Frontend;
|
||||
|
||||
use App\Models\ZEmail;
|
||||
use Livewire\Component;
|
||||
|
||||
class Email extends Component
|
||||
{
|
||||
public $list = false;
|
||||
public $type, $email, $emails, $initial;
|
||||
|
||||
protected $listeners = ['updateEmail' => 'syncEmail', 'getEmail' => 'generateEmail'];
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->email = ZEmail::getEmail();
|
||||
$this->emails = ZEmail::getEmails();
|
||||
$this->initial = false;
|
||||
$this->checkMultipleEmails();
|
||||
}
|
||||
|
||||
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): void
|
||||
{
|
||||
ZEmail::setEmail($email);
|
||||
$this->email = $email;
|
||||
$this->dispatch('updateEmail');
|
||||
}
|
||||
|
||||
public function syncEmail(): void
|
||||
{
|
||||
$this->email = ZEmail::getEmail();
|
||||
$this->emails = ZEmail::getEmails();
|
||||
if (count($this->emails) == 0) {
|
||||
$this->dispatch('getEmail');
|
||||
}
|
||||
$this->checkMultipleEmails();
|
||||
}
|
||||
|
||||
public function generateEmail(): void
|
||||
{
|
||||
if ($this->email == null) {
|
||||
ZEmail::generateRandomEmail();
|
||||
}
|
||||
$this->checkMultipleEmails();
|
||||
$this->dispatch('updateEmail');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.frontend.email')->with(['email' => $this->email, 'emails' => $this->emails, 'initial' => $this->initial, 'type' => $this->type, 'list' => $this->list]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user