Skip to content

Commit

Permalink
Merge pull request #1001 from HDInnovations/2.x.x
Browse files Browse the repository at this point in the history
v2.2.5
  • Loading branch information
HDVinnie authored Nov 25, 2019
2 parents dc50389 + 9be1bdc commit a2f8b89
Show file tree
Hide file tree
Showing 97 changed files with 1,359 additions and 1,190 deletions.
9 changes: 6 additions & 3 deletions app/Console/Commands/AutoBan.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@ class AutoBan extends Command
*/
public function handle()
{
$bannedGroup = Group::select(['id'])->where('slug', '=', 'banned')->first();
$banned_group = cache()->rememberForever('banned_group', function () {
return Group::where('slug', '=', 'banned')->pluck('id');
});

$bans = Warning::with('warneduser')->select(DB::raw('user_id, count(*) as value'))->where('active', '=', 1)->groupBy('user_id')->having('value', '>=', config('hitrun.max_warnings'))->get();

foreach ($bans as $ban) {
if ($ban->warneduser->group_id != $bannedGroup->id && ! $ban->warneduser->group->is_immune) {
if ($ban->warneduser->group_id != $banned_group[0] && ! $ban->warneduser->group->is_immune) {
// If User Has x or More Active Warnings Ban Set The Users Group To Banned
$ban->warneduser->group_id = $bannedGroup->id;
$ban->warneduser->group_id = $banned_group[0];
$ban->warneduser->can_upload = 0;
$ban->warneduser->can_download = 0;
$ban->warneduser->can_comment = 0;
Expand Down
7 changes: 5 additions & 2 deletions app/Console/Commands/AutoDisableInactiveUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ class AutoDisableInactiveUsers extends Command
public function handle()
{
if (config('pruning.user_pruning') == true) {
$disabledGroup = Group::select(['id'])->where('slug', '=', 'disabled')->first();
$disabled_group = cache()->rememberForever('disabled_group', function () {
return Group::where('slug', '=', 'disabled')->pluck('id');
});

$current = Carbon::now();

$matches = User::whereIn('group_id', [config('pruning.group_ids')]);
Expand All @@ -54,7 +57,7 @@ public function handle()

foreach ($users as $user) {
if ($user->getSeeding() !== 0) {
$user->group_id = $disabledGroup->id;
$user->group_id = $disabled_group[0];
$user->can_upload = 0;
$user->can_download = 0;
$user->can_comment = 0;
Expand Down
24 changes: 17 additions & 7 deletions app/Console/Commands/AutoRevokePermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,24 @@ class AutoRevokePermissions extends Command
*/
public function handle()
{
$bannedGroup = Group::select(['id'])->where('slug', '=', 'banned')->first();
$validatingGroup = Group::select(['id'])->where('slug', '=', 'validating')->first();
$leechGroup = Group::select(['id'])->where('slug', '=', 'leech')->first();
$disabledGroup = Group::select(['id'])->where('slug', '=', 'disabled')->first();
$prunedGroup = Group::select(['id'])->where('slug', '=', 'pruned')->first();
$banned_group = cache()->rememberForever('banned_group', function () {
return Group::where('slug', '=', 'banned')->pluck('id');
});
$validating_group = cache()->rememberForever('validating_group', function () {
return Group::where('slug', '=', 'validating')->pluck('id');
});
$leech_group = cache()->rememberForever('leech_group', function () {
return Group::where('slug', '=', 'leech')->pluck('id');
});
$disabled_group = cache()->rememberForever('disabled_group', function () {
return Group::where('slug', '=', 'disabled')->pluck('id');
});
$pruned_group = cache()->rememberForever('pruned_group', function () {
return Group::where('slug', '=', 'pruned')->pluck('id');
});

User::whereNotIn('group_id', [$bannedGroup->id, $validatingGroup->id, $leechGroup->id, $disabledGroup->id, $prunedGroup->id])->update(['can_download' => '1', 'can_request' => '1']);
User::whereIn('group_id', [$bannedGroup->id, $validatingGroup->id, $leechGroup->id, $disabledGroup->id, $prunedGroup->id])->update(['can_download' => '0', 'can_request' => '0']);
User::whereNotIn('group_id', [$banned_group[0], $validating_group[0], $leech_group[0], $disabled_group[0], $pruned_group[0]])->update(['can_download' => '1', 'can_request' => '1']);
User::whereIn('group_id', [$banned_group[0], $validating_group[0], $leech_group[0], $disabled_group[0], $pruned_group[0]])->update(['can_download' => '0', 'can_request' => '0']);

$warning = Warning::with('warneduser')->select(DB::raw('user_id, count(*) as value'))->where('active', '=', 1)->groupBy('user_id')->having('value', '>=', config('hitrun.revoke'))->get();

Expand Down
12 changes: 8 additions & 4 deletions app/Console/Commands/AutoSoftDeleteDisabledUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ class AutoSoftDeleteDisabledUsers extends Command
public function handle()
{
if (config('pruning.user_pruning') == true) {
$disabledGroup = Group::select(['id'])->where('slug', '=', 'disabled')->first();
$prunedGroup = Group::select(['id'])->where('slug', '=', 'pruned')->first();
$disabled_group = cache()->rememberForever('disabled_group', function () {
return Group::where('slug', '=', 'disabled')->pluck('id');
});
$pruned_group = cache()->rememberForever('pruned_group', function () {
return Group::where('slug', '=', 'pruned')->pluck('id');
});

$current = Carbon::now();
$users = User::where('group_id', '=', $disabledGroup->id)
$users = User::where('group_id', '=', $disabled_group[0])
->where('disabled_at', '<', $current->copy()->subDays(config('pruning.soft_delete'))->toDateTimeString())
->get();

Expand All @@ -61,7 +65,7 @@ public function handle()
$user->can_invite = 0;
$user->can_request = 0;
$user->can_chat = 0;
$user->group = $prunedGroup->id;
$user->group = $pruned_group[0];
$user->deleted_by = 1;
$user->save();
$user->delete();
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/AnnounceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function announce(Request $request, $passkey)
}

// Check Passkey Against Users Table
$user = User::with(['group', 'history'])->where('passkey', '=', $passkey)->first();
$user = User::with(['group'])->where('passkey', '=', $passkey)->first();

// If Passkey Doesn't Exist Return Error to Client
if (! $user) {
Expand Down Expand Up @@ -256,7 +256,7 @@ public function announce(Request $request, $passkey)
}

// Get history information
$history = $user->history->where('info_hash', '=', $info_hash)->first();
$history = History::where('info_hash', '=', $info_hash)->where('user_id', '=', $user->id)->first();

if (! $history) {
$history = new History();
Expand Down
12 changes: 8 additions & 4 deletions app/Http/Controllers/Auth/ActivationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,22 @@ class ActivationController extends Controller
{
public function activate($token)
{
$bannedGroup = Group::select(['id'])->where('slug', '=', 'banned')->first();
$memberGroup = Group::select(['id'])->where('slug', '=', 'user')->first();
$banned_group = cache()->rememberForever('banned_group', function () {
return Group::where('slug', '=', 'banned')->pluck('id');
});
$member_group = cache()->rememberForever('member_group', function () {
return Group::where('slug', '=', 'user')->pluck('id');
});

$activation = UserActivation::with('user')->where('token', '=', $token)->firstOrFail();
if ($activation->user->id && $activation->user->group->id != $bannedGroup->id) {
if ($activation->user->id && $activation->user->group->id != $banned_group[0]) {
$activation->user->active = 1;
$activation->user->can_upload = 1;
$activation->user->can_download = 1;
$activation->user->can_request = 1;
$activation->user->can_comment = 1;
$activation->user->can_invite = 1;
$activation->user->group_id = $memberGroup->id;
$activation->user->group_id = $member_group[0];
$activation->user->save();

$activation->delete();
Expand Down
30 changes: 19 additions & 11 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,37 @@ protected function validateLogin(Request $request)

protected function authenticated(Request $request, $user)
{
$bannedGroup = Group::select(['id'])->where('slug', '=', 'banned')->first();
$validatingGroup = Group::select(['id'])->where('slug', '=', 'validating')->first();
$disabledGroup = Group::select(['id'])->where('slug', '=', 'disabled')->first();
$memberGroup = Group::select(['id'])->where('slug', '=', 'user')->first();

if ($user->active == 0 || $user->group_id == $validatingGroup->id) {
$banned_group = cache()->rememberForever('banned_group', function () {
return Group::where('slug', '=', 'banned')->pluck('id');
});
$validating_group = cache()->rememberForever('validating_group', function () {
return Group::where('slug', '=', 'validating')->pluck('id');
});
$disabled_group = cache()->rememberForever('disabled_group', function () {
return Group::where('slug', '=', 'disabled')->pluck('id');
});
$member_group = cache()->rememberForever('member_group', function () {
return Group::where('slug', '=', 'user')->pluck('id');
});

if ($user->active == 0 || $user->group_id == $validating_group[0]) {
$this->guard()->logout();
$request->session()->invalidate();

return redirect()->route('login')
->withErrors(trans('auth.not-activated'));
}

if ($user->group_id == $bannedGroup->id) {
if ($user->group_id == $banned_group[0]) {
$this->guard()->logout();
$request->session()->invalidate();

return redirect()->route('login')
->withErrors(trans('auth.banned'));
}

if ($user->group_id == $disabledGroup->id) {
$user->group_id = $memberGroup->id;
if ($user->group_id == $disabled_group[0]) {
$user->group_id = $member_group[0];
$user->can_upload = 1;
$user->can_download = 1;
$user->can_comment = 1;
Expand All @@ -103,8 +111,8 @@ protected function authenticated(Request $request, $user)
->withSuccess(trans('auth.welcome-restore'));
}

if (auth()->viaRemember() && $user->group_id == $disabledGroup->id) {
$user->group_id = $memberGroup->id;
if (auth()->viaRemember() && $user->group_id == $disabled_group[0]) {
$user->group_id = $member_group[0];
$user->can_upload = 1;
$user->can_download = 1;
$user->can_comment = 1;
Expand Down
7 changes: 5 additions & 2 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ public function register(Request $request, $code = null)
->withErrors(trans('auth.invalid-key'));
}

$validatingGroup = Group::select(['id'])->where('slug', '=', 'validating')->first();
$validating_group = cache()->rememberForever('validating_group', function () {
return Group::where('slug', '=', 'validating')->pluck('id');
});

$user = new User();
$user->username = $request->input('username');
$user->email = $request->input('email');
Expand All @@ -89,7 +92,7 @@ public function register(Request $request, $code = null)
$user->downloaded = config('other.default_download');
$user->style = config('other.default_style', 0);
$user->locale = config('app.locale');
$user->group_id = $validatingGroup->id;
$user->group_id = $validating_group[0];

if (config('email-white-blacklist.enabled') === 'allow' && config('captcha.enabled') == true) {
$v = validator($request->all(), [
Expand Down
12 changes: 8 additions & 4 deletions app/Http/Controllers/Auth/ResetPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ public function __construct()

protected function resetPassword($user, $password)
{
$validatingGroup = Group::select(['id'])->where('slug', '=', 'validating')->first();
$memberGroup = Group::select(['id'])->where('slug', '=', 'user')->first();
$validating_group = cache()->rememberForever('validating_group', function () {
return Group::where('slug', '=', 'validating')->pluck('id');
});
$member_group = cache()->rememberForever('member_group', function () {
return Group::where('slug', '=', 'user')->pluck('id');
});
$user->password = bcrypt($password);
$user->remember_token = Str::random(60);

if ($user->group_id === $validatingGroup->id) {
$user->group_id = $memberGroup->id;
if ($user->group_id === $validating_group[0]) {
$user->group_id = $member_group[0];
}

$user->active = true;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/PlaylistController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(ChatRepository $chat)
*/
public function index()
{
$playlists = Playlist::with('user')->withCount('torrents')->where('is_private', '=', 0)->orderBy('name', 'ASC')->paginate(25);
$playlists = Playlist::with('user')->withCount('torrents')->where('is_private', '=', 0)->orderBy('name', 'ASC')->paginate(24);

return view('playlist.index', ['playlists' => $playlists]);
}
Expand Down
14 changes: 9 additions & 5 deletions app/Http/Controllers/RssController.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,17 @@ public function show($id, $rsskey)
$user = User::where('rsskey', '=', (string) $rsskey)->firstOrFail();
$rss = Rss::where('id', '=', (int) $id)->whereRaw('(user_id = ? OR is_private != ?)', [$user->id, 1])->firstOrFail();

$bannedGroup = Group::select(['id'])->where('slug', '=', 'banned')->first();
$disabledGroup = Group::select(['id'])->where('slug', '=', 'disabled')->first();

if ($user->group->id == $bannedGroup->id) {
$banned_group = cache()->rememberForever('banned_group', function () {
return Group::where('slug', '=', 'banned')->pluck('id');
});
$disabled_group = cache()->rememberForever('disabled_group', function () {
return Group::where('slug', '=', 'disabled')->pluck('id');
});

if ($user->group->id == $banned_group[0]) {
abort(404);
}
if ($user->group->id == $disabledGroup->id) {
if ($user->group->id == $disabled_group[0]) {
abort(404);
}
if ($user->active == 0) {
Expand Down
6 changes: 4 additions & 2 deletions app/Http/Controllers/Staff/BanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ public function store(Request $request, $username)
{
$user = User::where('username', '=', $username)->firstOrFail();
$staff = $request->user();
$bannedGroup = Group::select(['id'])->where('slug', '=', 'banned')->first();
$banned_group = cache()->rememberForever('banned_group', function () {
return Group::where('slug', '=', 'banned')->pluck('id');
});

abort_if($user->group->is_modo || $request->user()->id == $user->id, 403);

$user->group_id = $bannedGroup->id;
$user->group_id = $banned_group[0];
$user->can_upload = 0;
$user->can_download = 0;
$user->can_comment = 0;
Expand Down
12 changes: 8 additions & 4 deletions app/Http/Controllers/Staff/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ class HomeController extends Controller
public function index(Request $request)
{
// User Info
$bannedGroup = Group::select(['id'])->where('slug', '=', 'banned')->first();
$validatingGroup = Group::select(['id'])->where('slug', '=', 'validating')->first();
$banned_group = cache()->rememberForever('banned_group', function () {
return Group::where('slug', '=', 'banned')->pluck('id');
});
$validating_group = cache()->rememberForever('validating_group', function () {
return Group::where('slug', '=', 'validating')->pluck('id');
});
$num_user = User::count();
$banned = User::where('group_id', '=', $bannedGroup->id)->count();
$validating = User::where('group_id', '=', $validatingGroup->id)->count();
$banned = User::where('group_id', '=', $banned_group[0])->count();
$validating = User::where('group_id', '=', $validating_group[0])->count();

// Torrent Info
$num_torrent = Torrent::count();
Expand Down
13 changes: 8 additions & 5 deletions app/Http/Controllers/Staff/MassActionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public function create()
*/
public function store(Request $request)
{
$staff = $request->user();
$users = User::all();

$sender_id = 1;
Expand Down Expand Up @@ -72,12 +71,16 @@ public function store(Request $request)
*/
public function update()
{
$validatingGroup = Group::select(['id'])->where('slug', '=', 'validating')->first();
$memberGroup = Group::select(['id'])->where('slug', '=', 'user')->first();
$users = User::where('active', '=', 0)->where('group_id', '=', $validatingGroup->id)->get();
$validating_group = cache()->rememberForever('validating_group', function () {
return Group::where('slug', '=', 'validating')->pluck('id');
});
$member_group = cache()->rememberForever('member_group', function () {
return Group::where('slug', '=', 'user')->pluck('id');
});
$users = User::where('active', '=', 0)->where('group_id', '=', $validating_group[0])->get();

foreach ($users as $user) {
$user->group_id = $memberGroup->id;
$user->group_id = $member_group[0];
$user->active = 1;
$user->can_upload = 1;
$user->can_download = 1;
Expand Down
Loading

0 comments on commit a2f8b89

Please sign in to comment.