chore: code styling via pint
This commit is contained in:
@@ -13,14 +13,15 @@ class Category extends Model
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'slug',
|
||||
'is_active'
|
||||
'is_active',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
public function blogs(): HasMany {
|
||||
public function blogs(): HasMany
|
||||
{
|
||||
return $this->hasMany(Blog::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,19 +2,19 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Ddeboer\Imap\ConnectionInterface;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\ColorPicker;
|
||||
use Carbon\Carbon;
|
||||
use Carbon\CarbonImmutable;
|
||||
use DateTime;
|
||||
use Ddeboer\Imap\ConnectionInterface;
|
||||
use Ddeboer\Imap\Search\Date\Since;
|
||||
use Ddeboer\Imap\Search\Email\To;
|
||||
use Ddeboer\Imap\Server;
|
||||
use Exception;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class Email extends Model
|
||||
|
||||
@@ -13,7 +13,7 @@ class Menu extends Model
|
||||
'name',
|
||||
'url',
|
||||
'new_tab',
|
||||
'parent'
|
||||
'parent',
|
||||
];
|
||||
|
||||
public function parentname()
|
||||
|
||||
@@ -2,17 +2,17 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\ColorPicker;
|
||||
use Carbon\Carbon;
|
||||
use DateTime;
|
||||
use Ddeboer\Imap\Search\Email\Cc;
|
||||
use Ddeboer\Imap\Search\Email\To;
|
||||
use Ddeboer\Imap\SearchExpression;
|
||||
use Exception;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class Message extends Model
|
||||
|
||||
@@ -5,7 +5,8 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Meta extends Model {
|
||||
class Meta extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
@@ -13,9 +14,11 @@ class Meta extends Model {
|
||||
'value',
|
||||
];
|
||||
|
||||
public function incrementMeta($value = 1) {
|
||||
public function incrementMeta($value = 1)
|
||||
{
|
||||
$this->value = $this->value + $value;
|
||||
$this->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -24,8 +27,10 @@ class Meta extends Model {
|
||||
$meta = Meta::where('key', 'email_ids_created')->first();
|
||||
if ($meta) {
|
||||
$meta->incrementMeta($value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -34,24 +39,30 @@ class Meta extends Model {
|
||||
$meta = Meta::where('key', 'messages_received')->first();
|
||||
if ($meta) {
|
||||
$meta->incrementMeta($value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getEmailIdsCreated() {
|
||||
public static function getEmailIdsCreated()
|
||||
{
|
||||
$meta = Meta::where('key', 'email_ids_created')->first();
|
||||
if ($meta) {
|
||||
return $meta->value;
|
||||
}
|
||||
return "NaN";
|
||||
|
||||
return 'NaN';
|
||||
}
|
||||
|
||||
public static function getMessagesReceived() {
|
||||
public static function getMessagesReceived()
|
||||
{
|
||||
$meta = Meta::where('key', 'messages_received')->first();
|
||||
if ($meta) {
|
||||
return $meta->value;
|
||||
}
|
||||
return "NaN";
|
||||
|
||||
return 'NaN';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ class Page extends Model
|
||||
'meta',
|
||||
'custom_header',
|
||||
'page_image',
|
||||
'is_published'
|
||||
'is_published',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
|
||||
@@ -2,23 +2,23 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Ddeboer\Imap\ConnectionInterface;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use Log;
|
||||
use App\ColorPicker;
|
||||
use Carbon\Carbon;
|
||||
use DateTime;
|
||||
use Ddeboer\Imap\ConnectionInterface;
|
||||
use Ddeboer\Imap\Search\Email\Cc;
|
||||
use Ddeboer\Imap\Search\Email\To;
|
||||
use Ddeboer\Imap\SearchExpression;
|
||||
use Ddeboer\Imap\Server;
|
||||
use Exception;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Cookie;
|
||||
use Log;
|
||||
|
||||
class Premium extends Model
|
||||
{
|
||||
use ColorPicker;
|
||||
|
||||
public static function connectMailBox($imap = null): ConnectionInterface
|
||||
{
|
||||
$imapDB = json_decode(config('app.settings.imap_settings'), true);
|
||||
@@ -31,7 +31,7 @@ class Premium extends Model
|
||||
'password' => $imapDB['premium_password'],
|
||||
'default_account' => $imapDB['premium_default_account'],
|
||||
'protocol' => $imapDB['premium_protocol'],
|
||||
'cc_check' => $imapDB['premium_cc_check']
|
||||
'cc_check' => $imapDB['premium_cc_check'],
|
||||
];
|
||||
|
||||
return ZEmail::connectMailBox($imap);
|
||||
@@ -41,15 +41,15 @@ class Premium extends Model
|
||||
{
|
||||
if ($email == null) {
|
||||
return [
|
||||
"data" => [],
|
||||
"notifications" => []
|
||||
'data' => [],
|
||||
'notifications' => [],
|
||||
];
|
||||
}
|
||||
$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();
|
||||
$search = new SearchExpression;
|
||||
if ($type == 'cc') {
|
||||
$search->addCondition(new Cc($email));
|
||||
} else {
|
||||
@@ -60,18 +60,19 @@ class Premium extends Model
|
||||
$count = 1;
|
||||
$response = [
|
||||
'data' => [],
|
||||
'notifications' => []
|
||||
'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 (! $date) {
|
||||
$date = new DateTime;
|
||||
if ($message->getHeaders()->get('udate')) {
|
||||
$date->setTimestamp($message->getHeaders()->get('udate'));
|
||||
}
|
||||
@@ -82,12 +83,12 @@ class Premium extends Model
|
||||
$html = $message->getBodyHtml();
|
||||
$text = $message->getBodyText();
|
||||
if ($text) {
|
||||
$contentText = str_replace('<a', '<a target="blank"', str_replace(array("\r\n", "\n"), '', $text));
|
||||
$contentText = str_replace('<a', '<a target="blank"', str_replace(["\r\n", "\n"], '', $text));
|
||||
}
|
||||
if ($html) {
|
||||
$content = str_replace('<a', '<a target="blank"', $html);
|
||||
} else {
|
||||
$content = str_replace('<a', '<a target="blank"', str_replace(array("\r\n", "\n"), '<br/>', $text));
|
||||
$content = str_replace('<a', '<a target="blank"', str_replace(["\r\n", "\n"], '<br/>', $text));
|
||||
}
|
||||
if (json_decode(config('app.settings.configuration_settings'))->enable_masking_external_link) {
|
||||
$content = str_replace('href="', 'href="http://href.li/?', $content);
|
||||
@@ -106,28 +107,28 @@ class Premium extends Model
|
||||
$obj['contentText'] = $contentText;
|
||||
$obj['attachments'] = [];
|
||||
$obj['is_seen'] = true;
|
||||
$obj['sender_photo'] = self::chooseColor(strtoupper(substr($sender->getName() ?: $sender->getAddress(), 0, 1) ));
|
||||
$obj['sender_photo'] = self::chooseColor(strtoupper(substr($sender->getName() ?: $sender->getAddress(), 0, 1)));
|
||||
|
||||
//Checking if Sender is Blocked
|
||||
// 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');
|
||||
$obj['content'] = __('Emails from').' '.$domain.' '.__('are blocked by Admin');
|
||||
$obj['contentText'] = __('Emails from').' '.$domain.' '.__('are blocked by Admin');
|
||||
}
|
||||
if ($message->hasAttachments() && !$blocked) {
|
||||
if ($message->hasAttachments() && ! $blocked) {
|
||||
$attachments = $message->getAttachments();
|
||||
$directory = './tmp/premium/attachments/' . $obj['id'] . '/';
|
||||
$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())) {
|
||||
if (! file_exists($directory.$attachment->getFilename())) {
|
||||
try {
|
||||
file_put_contents(
|
||||
$directory . $attachment->getFilename(),
|
||||
$directory.$attachment->getFilename(),
|
||||
$attachment->getDecodedContent()
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
@@ -135,28 +136,28 @@ class Premium extends Model
|
||||
}
|
||||
}
|
||||
if ($attachment->getFilename() !== 'undefined') {
|
||||
$url = config('app.settings.app_base_url') . str_replace('./', '/', $directory . $attachment->getFilename());
|
||||
$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['content'] = str_replace('cid:'.trim($structure->id, '<>'), $url, $obj['content']);
|
||||
}
|
||||
$obj['attachments'][] = [
|
||||
'file' => $attachment->getFilename(),
|
||||
'url' => $url
|
||||
'url' => $url,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$response['data'][] = $obj;
|
||||
if (!$message->isSeen()) {
|
||||
if (! $message->isSeen()) {
|
||||
$response['notifications'][] = [
|
||||
'subject' => $obj['subject'],
|
||||
'sender_name' => $obj['sender_name'],
|
||||
'sender_email' => $obj['sender_email']
|
||||
'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);
|
||||
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();
|
||||
@@ -167,6 +168,7 @@ class Premium extends Model
|
||||
|
||||
$response['data'] = array_reverse($response['data']);
|
||||
$connection->expunge();
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
@@ -174,6 +176,7 @@ class Premium extends Model
|
||||
{
|
||||
return self::fetchMessages($email, $type, $deleted);
|
||||
}
|
||||
|
||||
public static function deleteMessage($id): void
|
||||
{
|
||||
$connection = self::connectMailBox();
|
||||
@@ -181,20 +184,25 @@ class Premium extends Model
|
||||
$mailbox->getMessage($id)->delete();
|
||||
$connection->expunge();
|
||||
}
|
||||
public static function getEmail($generate = false) {
|
||||
|
||||
public static function getEmail($generate = false)
|
||||
{
|
||||
if (Cookie::has('p_email')) {
|
||||
return Cookie::get('p_email');
|
||||
} else {
|
||||
return $generate ? self::generateRandomEmail() : null;
|
||||
}
|
||||
}
|
||||
public static function getEmails() {
|
||||
|
||||
public static function getEmails()
|
||||
{
|
||||
if (Cookie::has('p_emails')) {
|
||||
return unserialize(Cookie::get('p_emails'));
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public static function setEmail($email): void
|
||||
{
|
||||
$emails = unserialize(Cookie::get('p_emails'));
|
||||
@@ -211,6 +219,7 @@ class Premium extends Model
|
||||
Cookie::queue('p_email', $email, 43800);
|
||||
}
|
||||
}
|
||||
|
||||
public static function removeEmail($email): void
|
||||
{
|
||||
$emails = self::getEmails();
|
||||
@@ -226,17 +235,20 @@ class Premium extends Model
|
||||
Cookie::queue('p_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();
|
||||
$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));
|
||||
@@ -259,7 +271,7 @@ class Premium extends Model
|
||||
return self::generateRandomOutlook(true);
|
||||
}
|
||||
|
||||
$zemail = new Premium();
|
||||
$zemail = new Premium;
|
||||
|
||||
if ($username === '' && in_array($domain, $domains)) {
|
||||
return $zemail->generateRandomUsername().'@'.$domain;
|
||||
@@ -270,14 +282,15 @@ class Premium extends Model
|
||||
[$check_username, $post_username] = explode('+', $username, 2);
|
||||
|
||||
if (in_array($check_username, $outlook_usernames)) {
|
||||
$email = $username . '@' . $domain;
|
||||
$email = $username.'@'.$domain;
|
||||
} else {
|
||||
$email = $zemail->getRandomOutlookUser() . '+' . $post_username . '@' . $domain;
|
||||
$email = $zemail->getRandomOutlookUser().'+'.$post_username.'@'.$domain;
|
||||
}
|
||||
} else {
|
||||
$email = $zemail->getRandomOutlookUser() . '+' . $username . '@' . $domain;
|
||||
$email = $zemail->getRandomOutlookUser().'+'.$username.'@'.$domain;
|
||||
}
|
||||
self::storeEmail($email);
|
||||
|
||||
return $email;
|
||||
}
|
||||
|
||||
@@ -286,142 +299,152 @@ class Premium extends Model
|
||||
[$check_username, $post_username] = explode('+', $username, 2);
|
||||
|
||||
if (in_array($check_username, $gmail_usernames)) {
|
||||
$email = $username . '@' . $domain;
|
||||
$email = $username.'@'.$domain;
|
||||
} else {
|
||||
$email = $zemail->getRandomGmailUser() . '+' . $post_username . '@' . $domain;
|
||||
$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;
|
||||
$email = $username.'@'.$domain;
|
||||
} else {
|
||||
$email = $zemail->generateRandomGmail() . '@' . $domain;
|
||||
$email = $zemail->generateRandomGmail().'@'.$domain;
|
||||
}
|
||||
|
||||
} else {
|
||||
$email = $zemail->getRandomGmailUser() . '+' . $username . '@' . $domain;
|
||||
$email = $zemail->getRandomGmailUser().'+'.$username.'@'.$domain;
|
||||
}
|
||||
|
||||
self::storeEmail($email);
|
||||
|
||||
return $email;
|
||||
}
|
||||
|
||||
// Handle other custom domains
|
||||
if (!in_array($domain, $domains)) {
|
||||
if (! in_array($domain, $domains)) {
|
||||
return self::generateRandomEmail(true);
|
||||
}
|
||||
|
||||
$finalDomain = in_array($domain, $domains) ? $domain : ($domains[0] ?? 'example.com');
|
||||
$email = $username . '@' . $finalDomain;
|
||||
$email = $username.'@'.$finalDomain;
|
||||
|
||||
self::storeEmail($email);
|
||||
|
||||
return $email;
|
||||
}
|
||||
|
||||
public static function generateRandomEmail($store = true): string
|
||||
{
|
||||
$zemail = new Premium();
|
||||
$zemail = new Premium;
|
||||
$domain = $zemail->getRandomDomain();
|
||||
if ($domain == "gmail.com") {
|
||||
$rd = mt_rand(0,1);
|
||||
if ($domain == 'gmail.com') {
|
||||
$rd = mt_rand(0, 1);
|
||||
if ($rd == 0) {
|
||||
$email = $zemail->generateRandomGmail(false);
|
||||
} else {
|
||||
$email = $zemail->getRandomGmailUser().'+'.$zemail->generateRandomUsername().'@gmail.com';
|
||||
}
|
||||
} elseif ($domain == "googlemail.com") {
|
||||
$rd = mt_rand(0,1);
|
||||
} elseif ($domain == 'googlemail.com') {
|
||||
$rd = mt_rand(0, 1);
|
||||
if ($rd == 0) {
|
||||
$email = $zemail->generateRandomGmail(false);
|
||||
} else {
|
||||
$email = $zemail->getRandomGmailUser().'+'.$zemail->generateRandomUsername().'@googlemail.com';
|
||||
}
|
||||
} elseif ($domain == "outlook.com") {
|
||||
} elseif ($domain == 'outlook.com') {
|
||||
$email = $zemail->getRandomOutlookUser().'+'.$zemail->generateRandomUsername().'@outlook.com';
|
||||
}
|
||||
else {
|
||||
$email = $zemail->generateRandomUsername() . '@' . $domain;
|
||||
} else {
|
||||
$email = $zemail->generateRandomUsername().'@'.$domain;
|
||||
}
|
||||
if ($store) {
|
||||
self::storeEmail($email);
|
||||
}
|
||||
|
||||
return $email;
|
||||
}
|
||||
|
||||
public static function generateRandomGmail($store = true): string
|
||||
{
|
||||
$zemail = new Premium();
|
||||
$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));
|
||||
$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 = intval('');
|
||||
for ($i = 0; $i < $len_power; $i++) {
|
||||
$bin .= mt_rand(0, 1);
|
||||
}
|
||||
$bin = explode(' ', implode(' ',str_split(strval($bin))));
|
||||
$bin = explode(' ', implode(' ', str_split(strval($bin))));
|
||||
|
||||
$email = "";
|
||||
for($i=0; $i<$len_power; $i++) {
|
||||
$email = '';
|
||||
for ($i = 0; $i < $len_power; $i++) {
|
||||
$email .= $uname_exp[$i];
|
||||
if($bin[$i]) {
|
||||
$email .= ".";
|
||||
if ($bin[$i]) {
|
||||
$email .= '.';
|
||||
}
|
||||
}
|
||||
$email .= $uname_exp[$i];
|
||||
$gmail_rand = mt_rand(1,10);
|
||||
if($gmail_rand > 5) {
|
||||
$email .= "@gmail.com";
|
||||
$gmail_rand = mt_rand(1, 10);
|
||||
if ($gmail_rand > 5) {
|
||||
$email .= '@gmail.com';
|
||||
} else {
|
||||
$email .= "@googlemail.com";
|
||||
$email .= '@googlemail.com';
|
||||
}
|
||||
if ($store) {
|
||||
self::storeEmail($email);
|
||||
}
|
||||
|
||||
return $email;
|
||||
}
|
||||
|
||||
public static function generateRandomOutlook($store = true): string
|
||||
{
|
||||
$zemail = new Premium();
|
||||
$zemail = new Premium;
|
||||
$email = $zemail->getRandomOutlookUser().'+'.$zemail->generateRandomUsername().'@outlook.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
|
||||
'email' => $email,
|
||||
]);
|
||||
|
||||
self::storeUsageLog($email);
|
||||
|
||||
Cookie::queue('p_email', $email, 43800);
|
||||
$emails = Cookie::has('p_emails') ? unserialize(Cookie::get('p_emails')) : [];
|
||||
if (!in_array($email, $emails)) {
|
||||
if (! in_array($email, $emails)) {
|
||||
self::incrementEmailStats();
|
||||
$emails[] = $email;
|
||||
Cookie::queue('p_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;
|
||||
@@ -429,41 +452,56 @@ class Premium extends Model
|
||||
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() {
|
||||
|
||||
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() {
|
||||
|
||||
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 getRandomOutlookUser() {
|
||||
|
||||
private function getRandomOutlookUser()
|
||||
{
|
||||
$outlook_username = json_decode(config('app.settings.configuration_settings'))->premium_outlookUsernames ?? [];
|
||||
$count = count($outlook_username);
|
||||
|
||||
return $count > 0 ? $outlook_username[rand(1, $count) - 1] : '';
|
||||
}
|
||||
|
||||
private function generatePronounceableWord(): string
|
||||
{
|
||||
$c = 'bcdfghjklmnprstvwz'; //consonants except hard to speak ones
|
||||
$v = 'aeiou'; //vowels
|
||||
$a = $c . $v; //both
|
||||
$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';
|
||||
@@ -472,18 +510,17 @@ class Premium extends Model
|
||||
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) {
|
||||
if (! $user) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -498,7 +535,7 @@ class Premium extends Model
|
||||
public static function incrementMessagesReceived($count = 1): void
|
||||
{
|
||||
$user = Auth::user();
|
||||
if (!$user) {
|
||||
if (! $user) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -514,7 +551,7 @@ class Premium extends Model
|
||||
{
|
||||
try {
|
||||
$user = Auth::user();
|
||||
if (!$user) {
|
||||
if (! $user) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -525,9 +562,9 @@ class Premium extends Model
|
||||
);
|
||||
|
||||
$history = $usageLog->emails_created_history ?? [];
|
||||
if (!in_array($email, $history)) {
|
||||
if (! in_array($email, $history)) {
|
||||
$history[] = $email;
|
||||
//$usageLog->emails_created_count += 1;
|
||||
// $usageLog->emails_created_count += 1;
|
||||
$usageLog->emails_created_history = $history;
|
||||
$usageLog->save();
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ use Illuminate\Support\Facades\Validator;
|
||||
class RemoteEmail extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'emails';
|
||||
|
||||
public function getConnectionName()
|
||||
@@ -20,7 +21,6 @@ class RemoteEmail extends Model
|
||||
return 'mysql_remote';
|
||||
}
|
||||
|
||||
|
||||
protected $fillable = [
|
||||
'message_id',
|
||||
'subject',
|
||||
@@ -42,12 +42,13 @@ class RemoteEmail extends Model
|
||||
public static function fetchEmailFromDB($email)
|
||||
{
|
||||
$validator = Validator::make(['email' => $email], [
|
||||
'email' => 'required|email'
|
||||
'email' => 'required|email',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return self::whereJsonContains('to', $email)->orderBy('timestamp', 'desc')->get();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Setting extends Model
|
||||
{
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Exception;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -13,7 +13,7 @@ class Ticket extends Model
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id', 'ticket_id', 'subject', 'message', 'status', 'last_response_at', 'ip_address'
|
||||
'user_id', 'ticket_id', 'subject', 'message', 'status', 'last_response_at', 'ip_address',
|
||||
];
|
||||
|
||||
protected static function boot()
|
||||
@@ -22,7 +22,7 @@ class Ticket extends Model
|
||||
|
||||
static::creating(function ($ticket) {
|
||||
if (empty($ticket->ticket_id)) {
|
||||
$ticket->ticket_id = 'TICKET-' . strtoupper(Str::random(6));
|
||||
$ticket->ticket_id = 'TICKET-'.strtoupper(Str::random(6));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -61,6 +61,7 @@ class Ticket extends Model
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
|
||||
@@ -10,7 +10,7 @@ class TicketResponse extends Model
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'ticket_id', 'user_id', 'response', 'ip_address'
|
||||
'ticket_id', 'user_id', 'response', 'ip_address',
|
||||
];
|
||||
|
||||
public function ticket()
|
||||
|
||||
Reference in New Issue
Block a user