chore: migrate to unified payment system & fix disposable gmail and outlook

This commit is contained in:
idevakk
2025-11-21 12:11:52 -08:00
parent 72b8109a3a
commit 7ca3d44d59
4 changed files with 42 additions and 28 deletions

View File

@@ -2,12 +2,10 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use DateTimeImmutable;
use Illuminate\Support\Facades\Log;
use App\ColorPicker;
use Carbon\Carbon;
use DateTime;
use DateTimeImmutable;
use Ddeboer\Imap\ConnectionInterface;
use Ddeboer\Imap\Search\Email\Cc;
use Ddeboer\Imap\Search\Email\To;
@@ -19,8 +17,6 @@ use Illuminate\Support\Facades\Cookie;
class Premium extends Model
{
use HasFactory;
use HasFactory;
use ColorPicker;
public static function connectMailBox($imap = null): ConnectionInterface
@@ -54,7 +50,7 @@ class Premium extends Model
$mailbox = $connection->getMailbox('INBOX');
$search = new SearchExpression;
if ($type == 'cc') {
if ($type === 'cc') {
$search->addCondition(new Cc($email));
} else {
$search->addCondition(new To($email));
@@ -75,7 +71,7 @@ class Premium extends Model
$blocked = false;
$sender = $message->getFrom();
$date = $message->getDate();
if (!$date instanceof DateTimeImmutable) {
if (! $date instanceof DateTimeImmutable) {
$date = new DateTime;
if ($message->getHeaders()->get('udate')) {
$date->setTimestamp($message->getHeaders()->get('udate'));
@@ -87,12 +83,12 @@ class Premium extends Model
$html = $message->getBodyHtml();
$text = $message->getBodyText();
if ($text) {
$contentText = str_replace('<a', '<a target="blank"', str_replace(["\r\n", "\n"], '', $text));
$contentText = str_replace(["\r\n", "\n", '<a'], ['', '', '<a target="blank"'], $text);
}
if ($html) {
$content = str_replace('<a', '<a target="blank"', $html);
} else {
$content = str_replace('<a', '<a target="blank"', str_replace(["\r\n", "\n"], '<br/>', $text));
$content = str_replace(["\r\n", "\n", '<a'], ['<br/>', '<br/>', '<a target="blank"'], $text);
}
if (json_decode((string) config('app.settings.configuration_settings'))->enable_masking_external_link) {
$content = str_replace('href="', 'href="http://href.li/?', $content);
@@ -124,8 +120,10 @@ class Premium extends Model
if ($message->hasAttachments() && ! $blocked) {
$attachments = $message->getAttachments();
$directory = './tmp/premium/attachments/'.$obj['id'].'/';
if (!is_dir($directory)) {
mkdir($directory, 0777, true);
if (! is_dir($directory)) {
if (! mkdir($directory, 0777, true) && ! is_dir($directory)) {
\Illuminate\Support\Facades\Log::error('Unable to create temporary directory \''.$directory.'\'');
}
}
foreach ($attachments as $attachment) {
$filenameArray = explode('.', (string) $attachment->getFilename());
@@ -196,6 +194,7 @@ class Premium extends Model
if (Cookie::has('p_email')) {
return Cookie::get('p_email');
}
return $generate ? self::generateRandomEmail() : null;
}
@@ -204,6 +203,7 @@ class Premium extends Model
if (Cookie::has('p_emails')) {
return unserialize(Cookie::get('p_emails'));
}
return [];
}
@@ -374,26 +374,27 @@ class Premium extends Model
$zemail = new Premium;
$uname = $zemail->getRandomGmailUser();
$uname_len = strlen((string) $uname);
$len_power = $uname_len - 1;
$combination = 2 ** $len_power;
mt_rand(1, $combination);
$len_power = max(1, $uname_len - 1); // Ensure minimum of 1
$formatted = implode(' ', str_split((string) $uname));
$uname_exp = explode(' ', $formatted);
$bin = intval('');
$bin = '';
for ($i = 0; $i < $len_power; $i++) {
$bin .= mt_rand(0, 1);
}
$bin = explode(' ', implode(' ', str_split(strval($bin))));
$bin_array = str_split($bin);
$email = '';
for ($i = 0; $i < $len_power; $i++) {
for ($i = 0; $i < $len_power && $i < count($uname_exp); $i++) {
$email .= $uname_exp[$i];
if ($bin[$i] !== '' && $bin[$i] !== '0') {
if (isset($bin_array[$i]) && $bin_array[$i] === '1') {
$email .= '.';
}
}
$email .= $uname_exp[$i];
// Add the last character if it exists
if (isset($uname_exp[$len_power])) {
$email .= $uname_exp[$len_power];
}
$gmail_rand = mt_rand(1, 10);
if ($gmail_rand > 5) {
$email .= '@gmail.com';
@@ -480,7 +481,12 @@ class Premium extends Model
$gmailusername = json_decode((string) config('app.settings.configuration_settings'))->premium_gmailUsernames ?? [];
$count = count($gmailusername);
return $count > 0 ? $gmailusername[random_int(1, $count) - 1] : '';
if ($count > 0) {
return $gmailusername[random_int(1, $count) - 1];
}
// Fallback to a default username if none configured
return 'user'.random_int(1000, 9999);
}
private function getRandomOutlookUser()
@@ -488,7 +494,12 @@ class Premium extends Model
$outlook_username = json_decode((string) config('app.settings.configuration_settings'))->premium_outlookUsernames ?? [];
$count = count($outlook_username);
return $count > 0 ? $outlook_username[random_int(1, $count) - 1] : '';
if ($count > 0) {
return $outlook_username[random_int(1, $count) - 1];
}
// Fallback to a default username if none configured
return 'user'.random_int(1000, 9999);
}
private function generatePronounceableWord(): string