Skip to content

Commit

Permalink
Merge pull request #4207 from HDInnovations/8.x.x
Browse files Browse the repository at this point in the history
(Release) v8.3.0
  • Loading branch information
HDVinnie authored Oct 7, 2024
2 parents 5125cd3 + f31ee83 commit ca36a92
Show file tree
Hide file tree
Showing 342 changed files with 9,991 additions and 2,719 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ DEFAULT_OWNER_PASSWORD=UNIT3D
TMDB_API_KEY=
TWITCH_CLIENT_ID=
TWITCH_CLIENT_SECRET=

MEILISEARCH_HOST=http://127.0.0.1:7700
MEILISEARCH_KEY=
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
resources/views/emails
resources/views/rss/show.blade.php
resources/views/vendor
resources/views/components/user_tag.blade.php
4 changes: 1 addition & 3 deletions app/Actions/Fortify/CreateNewUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function create(array $input): RedirectResponse | User
'code' => [
Rule::when(config('other.invite-only') === true, [
'required',
Rule::exists('invites', 'code')->whereNull('accepted_by'),
Rule::exists('invites', 'code')->withoutTrashed()->whereNull('accepted_by'),
]),
]
])->validate();
Expand All @@ -83,8 +83,6 @@ public function create(array $input): RedirectResponse | User
'rsskey' => md5(random_bytes(60)),
'uploaded' => config('other.default_upload'),
'downloaded' => config('other.default_download'),
'style' => config('other.default_style', 0),
'locale' => config('app.locale'),
'group_id' => $validatingGroup[0],
]);

Expand Down
2 changes: 2 additions & 0 deletions app/Actions/Fortify/ResetUserPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,7 @@ public function reset(User $user, array $input): void

$user->active = true;
$user->save();

$user->passwordResetHistories()->create();
}
}
2 changes: 2 additions & 0 deletions app/Actions/Fortify/UpdateUserPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ public function update(User $user, array $input): void
$user->forceFill([
'password' => Hash::make($input['password']),
])->save();

$user->passwordResetHistories()->create();
}
}
7 changes: 4 additions & 3 deletions app/Bots/IRCAnnounceBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@ private function send(string $data): void
public function to(string $recipient): self
{
$this->recipient = $recipient;
$channelKey = config('irc-bot.channel_key', '');

if (config('irc-bot.joinchannel')) {
if ($this->isValidChannelName($recipient)) {
$this->join($recipient);
$this->join($recipient, $channelKey);
$this->isInChannel = true;
} else {
Log::error('Tried to channel with invalid name.', [
Expand Down Expand Up @@ -192,15 +193,15 @@ private function user(string $username, string $hostname, string $servername, st
/**
* @see https://www.rfc-editor.org/rfc/rfc1459#section-4.2.1
*/
private function join(string $channel, string $key = ''): void
private function join(string $channel, string $channelKey = ''): void
{
if (!$this->isValidChannelName($channel)) {
Log::error('Tried to join a channel with invalid name.', ['name' => $channel]);

return;
}

$this->send("JOIN {$channel} {$key}");
$this->send("JOIN {$channel} {$channelKey}");
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Bots/SystemBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SystemBot

public function __construct(private readonly ChatRepository $chatRepository)
{
$this->bot = Bot::where('is_systembot', '=', '1')->sole();
$this->bot = Bot::where('is_systembot', '=', true)->sole();
}

public function replaceVars(string $output): string
Expand Down
78 changes: 41 additions & 37 deletions app/Console/Commands/AutoBanDisposableUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,51 +50,55 @@ class AutoBanDisposableUsers extends Command
*/
final public function handle(): void
{
if (!cache()->has(config('email-blacklist.cache-key'))) {
$this->comment('Email Blacklist Cache Key Not Found. Skipping!');

return;
}

$bannedGroup = cache()->rememberForever('banned_group', fn () => Group::where('slug', '=', 'banned')->pluck('id'));

if (cache()->has(config('email-blacklist.cache-key'))) {
User::where('group_id', '!=', $bannedGroup[0])->chunkById(100, function ($users) use ($bannedGroup): void {
foreach ($users as $user) {
$v = validator([
'email' => $user->email,
], [
'email' => [
'required',
'string',
'email',
'max:70',
new EmailBlacklist(),
],
User::where('group_id', '!=', $bannedGroup[0])->chunkById(100, function ($users) use ($bannedGroup): void {
foreach ($users as $user) {
$v = validator([
'email' => $user->email,
], [
'email' => [
'required',
'string',
'email',
'max:70',
new EmailBlacklist(),
],
]);

if ($v->fails()) {
// If User Is Using A Disposable Email Set The Users Group To Banned
$user->update([
'group_id' => $bannedGroup[0],
'can_download' => 0,
]);

if ($v->fails()) {
// If User Is Using A Disposable Email Set The Users Group To Banned
$user->group_id = $bannedGroup[0];
$user->can_download = 0;
$user->save();
// Log The Ban To Ban Log
$domain = substr((string) strrchr((string) $user->email, '@'), 1);

// Log The Ban To Ban Log
$domain = substr((string) strrchr((string) $user->email, '@'), 1);
$logban = new Ban();
$logban->owned_by = $user->id;
$logban->created_by = User::SYSTEM_USER_ID;
$logban->ban_reason = 'Detected disposable email, '.$domain.' not allowed.';
$logban->unban_reason = '';
$logban->save();
$ban = Ban::create([
'owned_by' => $user->id,
'created_by' => User::SYSTEM_USER_ID,
'ban_reason' => 'Detected disposable email, '.$domain.' not allowed.',
'unban_reason' => '',
]);

// Send Email
$user->notify(new UserBan($logban));
}
// Send Email
$user->notify(new UserBan($ban));
}

cache()->forget('user:'.$user->passkey);
cache()->forget('user:'.$user->passkey);

Unit3dAnnounce::addUser($user);
}
});
Unit3dAnnounce::addUser($user);
}
});

$this->comment('Automated User Banning Command Complete');
} else {
$this->comment('Email Blacklist Cache Key Not Found. Skipping!');
}
$this->comment('Automated User Banning Command Complete');
}
}
20 changes: 11 additions & 9 deletions app/Console/Commands/AutoBonAllocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ class AutoBonAllocation extends Command
*/
public function handle(ByteUnits $byteUnits): void
{
$now = now();

$dyingTorrent = DB::table('peers')
->select(DB::raw('count(DISTINCT(peers.torrent_id)) as value'), 'peers.user_id')
->join('torrents', 'torrents.id', 'peers.torrent_id')
->where('torrents.seeders', 1)
->where('torrents.times_completed', '>', 2)
->where('peers.seeder', 1)
->where('peers.active', 1)
->whereRaw('date_sub(peers.created_at,interval 30 minute) < now()')
->where('peers.created_at', '<', $now->copy()->subMinutes(30))
->groupBy('peers.user_id')
->get()
->toArray();
Expand All @@ -62,8 +64,8 @@ public function handle(ByteUnits $byteUnits): void
->join('torrents', 'torrents.id', 'peers.torrent_id')
->where('peers.seeder', 1)
->where('peers.active', 1)
->whereRaw('torrents.created_at < date_sub(now(), interval 12 month)')
->whereRaw('date_sub(peers.created_at,interval 30 minute) < now()')
->where('torrents.created_at', '<', $now->copy()->subMonths(12))
->where('peers.created_at', '<', $now->copy()->subMinutes(30))
->groupBy('peers.user_id')
->get()
->toArray();
Expand All @@ -73,9 +75,9 @@ public function handle(ByteUnits $byteUnits): void
->join('torrents', 'torrents.id', 'peers.torrent_id')
->where('peers.seeder', 1)
->where('peers.active', 1)
->whereRaw('torrents.created_at < date_sub(now(), Interval 6 month)')
->whereRaw('torrents.created_at > date_sub(now(), interval 12 month)')
->whereRaw('date_sub(peers.created_at,interval 30 minute) < now()')
->where('torrents.created_at', '<', $now->copy()->subMonths(6))
->where('torrents.created_at', '>', $now->copy()->subMonths(12))
->where('peers.created_at', '<', $now->copy()->subMinutes(30))
->groupBy('peers.user_id')
->get()
->toArray();
Expand All @@ -86,7 +88,7 @@ public function handle(ByteUnits $byteUnits): void
->where('peers.seeder', 1)
->where('peers.active', 1)
->where('torrents.size', '>=', $byteUnits->bytesFromUnit('100GiB'))
->whereRaw('date_sub(peers.created_at,interval 30 minute) < now()')
->where('peers.created_at', '<', $now->copy()->subMinutes(30))
->groupBy('peers.user_id')
->get()
->toArray();
Expand All @@ -98,7 +100,7 @@ public function handle(ByteUnits $byteUnits): void
->where('peers.active', 1)
->where('torrents.size', '>=', $byteUnits->bytesFromUnit('25GiB'))
->where('torrents.size', '<', $byteUnits->bytesFromUnit('100GiB'))
->whereRaw('date_sub(peers.created_at,interval 30 minute) < now()')
->where('peers.created_at', '<', $now->copy()->subMinutes(30))
->groupBy('peers.user_id')
->get()
->toArray();
Expand All @@ -110,7 +112,7 @@ public function handle(ByteUnits $byteUnits): void
->where('peers.active', 1)
->where('torrents.size', '>=', $byteUnits->bytesFromUnit('1GiB'))
->where('torrents.size', '<', $byteUnits->bytesFromUnit('25GiB'))
->whereRaw('date_sub(peers.created_at,interval 30 minute) < now()')
->where('peers.created_at', '<', $now->copy()->subMinutes(30))
->groupBy('peers.user_id')
->get()
->toArray();
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/AutoCorrectHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ final public function handle(): void
{
History::query()
->where('active', '=', 1)
->where('updated_at', '<', Carbon::now()->subHours(2)->toDateTimeString())
->where('updated_at', '<', Carbon::now()->subHours(2))
->update([
'active' => 0,
'updated_at' => DB::raw('updated_at'),
Expand Down
54 changes: 32 additions & 22 deletions app/Console/Commands/AutoDeactivateWarning.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,37 +54,47 @@ final public function handle(): void
->where('active', '=', 1)
->get();

foreach ($warnings as $warning) {
if ($warning->expires_on <= $current || ($warning->torrenttitle && $warning->torrenttitle->history()->where('user_id', '=', $warning->warneduser->id)->first()->seedtime >= config('hitrun.seedtime'))) {
// Set Records Active To 0 in warnings table
$warning->active = false;
$warning->save();
Warning::query()
->where('active', '=', true)
->where(
fn ($query) => $query
->where('expires_on', '<=', $current)
->orWhereHas(
'torrenttitle.history',
fn ($query) => $query
->whereColumn('history.user_id', '=', 'warnings.user_id')
->where('history.seedtime', '>=', config('hitrun.seedtime'))
)
)
->chunkById(100, function ($warnings): void {
foreach ($warnings as $warning) {
// Set Records Active To 0 in warnings table
$warning->update(['active' => false]);

// Send Notifications
if ($warning->torrenttitle) {
$warning->warneduser->notify(new UserWarningExpire($warning->warneduser, $warning->torrenttitle));
} else {
$warning->warneduser->notify(new UserManualWarningExpire($warning->warneduser, $warning));
// Send Notifications
if ($warning->torrenttitle) {
$warning->warneduser->notify(new UserWarningExpire($warning->warneduser, $warning->torrenttitle));
} else {
$warning->warneduser->notify(new UserManualWarningExpire($warning->warneduser, $warning));
}
}
}
}
});

// Calculate User Warning Count and Enable DL Priv If Required.
$warnings = Warning::with('warneduser')
Warning::with('warneduser')
->select(DB::raw('user_id, SUM(active = 1) as value'))
->groupBy('user_id')
->having('value', '<', config('hitrun.max_warnings'))
->get();
->whereRelation('warneduser', 'can_download', '=', false)
->chunkById(100, function ($warnings): void {
foreach ($warnings as $warning) {
$warning->warneduser->update(['can_download' => 1]);

foreach ($warnings as $warning) {
if ($warning->warneduser->can_download === false) {
$warning->warneduser->can_download = 1;
$warning->warneduser->save();
cache()->forget('user:'.$warning->warneduser->passkey);

cache()->forget('user:'.$warning->warneduser->passkey);
Unit3dAnnounce::addUser($warning->warneduser);
}
}
Unit3dAnnounce::addUser($warning->warneduser);
}
}, 'user_id');

$this->comment('Automated Warning Deativation Command Complete');
}
Expand Down
34 changes: 18 additions & 16 deletions app/Console/Commands/AutoDisableInactiveUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,26 @@ class AutoDisableInactiveUsers extends Command
*/
final public function handle(): void
{
if (config('pruning.user_pruning')) {
$disabledGroup = cache()->rememberForever('disabled_group', fn () => Group::where('slug', '=', 'disabled')->pluck('id'));

$current = Carbon::now();
if (!config('pruning.user_pruning')) {
return;
}

$matches = User::whereIntegerInRaw('group_id', config('pruning.group_ids'))->get();
$disabledGroup = cache()->rememberForever('disabled_group', fn () => Group::where('slug', '=', 'disabled')->pluck('id'));

$users = $matches->where('created_at', '<', $current->copy()->subDays(config('pruning.account_age'))->toDateTimeString())
->where('last_login', '<', $current->copy()->subDays(config('pruning.last_login'))->toDateTimeString())
->all();
$current = Carbon::now();

foreach ($users as $user) {
if ($user->seedingTorrents()->doesntExist()) {
$user->group_id = $disabledGroup[0];
$user->can_download = false;
$user->disabled_at = Carbon::now();
$user->save();
User::query()
->whereIntegerInRaw('group_id', config('pruning.group_ids'))
->where('created_at', '<', $current->copy()->subDays(config('pruning.account_age')))
->where('last_login', '<', $current->copy()->subDays(config('pruning.last_login')))
->whereDoesntHave('seedingTorrents')
->chunk(100, function ($users) use ($disabledGroup): void {
foreach ($users as $user) {
$user->update([
'group_id' => $disabledGroup[0],
'can_download' => false,
'disabled_at' => Carbon::now(),
]);

cache()->forget('user:'.$user->passkey);

Expand All @@ -73,8 +76,7 @@ final public function handle(): void
// Send Email
dispatch(new SendDisableUserMail($user));
}
}
}
});

$this->comment('Automated User Disable Command Complete');
}
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/AutoFlushPeers.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ final public function handle(): void
{
$carbon = new Carbon();
$peers = Peer::select(['torrent_id', 'user_id', 'peer_id', 'seeder', 'updated_at'])
->where('updated_at', '<', $carbon->copy()->subHours(2)->toDateTimeString())
->where('updated_at', '<', $carbon->copy()->subHours(2))
->where('active', '=', 1)
->get();

Expand Down
Loading

0 comments on commit ca36a92

Please sign in to comment.